plugins: Fix CMake build example

Fix combination of pkg-config and CMake variables for feature
detection.

Remove non-system installation option. Just copy it manually for now.

Change-Id: Ia80c703c6ec3df0a49f8d56f1bd6da69471c523f
Reviewed-on: https://code.wireshark.org/review/29223
Petri-Dish: João Valverde <j@v6e.pt>
Tested-by: Petri Dish Buildbot
Reviewed-by: João Valverde <j@v6e.pt>
This commit is contained in:
João Valverde 2018-08-21 16:49:28 +01:00 committed by João Valverde
parent d99ef1f9fa
commit 319186125c
1 changed files with 12 additions and 15 deletions

View File

@ -12,22 +12,25 @@ cmake_policy(SET CMP0048 NEW)
project(Hello VERSION 0.0.1 DESCRIPTION "Wireshark Hello Plugin" LANGUAGES C)
option(SYSTEM_INSTALLATION "Install to system plugin directory" ON)
find_package(PkgConfig REQUIRED)
pkg_check_modules(WIRESHARK REQUIRED wireshark>=2.5)
### CMake Bug: Use PKG_CONFIG_PATH instead of CMAKE_PREFIX_PATH
# https://gitlab.kitware.com/cmake/cmake/issues/15805
### CMake Bug: If you run into problems please use the "Unix Makefiles" generator.
### Ninja just wipes the pkg-config variables.
# https://gitlab.kitware.com/cmake/cmake/issues/17531 (and probably others)
pkg_get_variable(WIRESHARK_VERSION_RELEASE wireshark VERSION_RELEASE)
pkg_get_variable(WIRESHARK_PLUGIN_DIR wireshark plugindir)
set(PLUGIN_INSTALL_LIBDIR "${WIRESHARK_PLUGIN_DIR}/epan")
include(CMakePushCheckState)
include(CheckSymbolExists)
include(CheckFunctionExists)
cmake_push_check_state()
set(CMAKE_REQUIRED_INCLUDES ${WIRESHARK_INCLUDE_DIRS})
set(CMAKE_REQUIRED_LIBRARIES ${WIRESHARK_LIBRARIES})
set(CMAKE_REQUIRED_DEFINITIONS -DHAVE_PLUGINS)
check_symbol_exists("proto_register_plugin" "epan/proto.h" HAVE_PROTO_REGISTER_PLUGIN)
set(CMAKE_REQUIRED_LIBRARIES ${WIRESHARK_LDFLAGS})
check_function_exists("proto_register_plugin" HAVE_PROTO_REGISTER_PLUGIN)
cmake_pop_check_state()
if(NOT HAVE_PROTO_REGISTER_PLUGIN)
message(FATAL_ERROR "Wireshark was compiled without support for plugins")
@ -42,15 +45,9 @@ add_definitions(-DHAVE_PLUGINS -DVERSION=\"${PROJECT_VERSION}\" -DVERSION_RELEAS
add_library(hello MODULE hello.c)
set_target_properties(hello PROPERTIES PREFIX "" DEFINE_SYMBOL "")
target_link_libraries(hello ${WIRESHARK_LIBRARIES})
target_link_libraries(hello ${WIRESHARK_LDFLAGS})
target_compile_options(hello PUBLIC ${WIRESHARK_CFLAGS})
if(SYSTEM_INSTALLATION)
set(PLUGIN_INSTALL_LIBDIR "${WIRESHARK_PLUGIN_DIR}/epan")
else()
set(PLUGIN_INSTALL_LIBDIR "$ENV{HOME}/.local/lib/wireshark/plugins/${WIRESHARK_VERSION_RELEASE}/epan")
endif()
install(TARGETS hello
LIBRARY DESTINATION ${PLUGIN_INSTALL_LIBDIR} NAMELINK_SKIP
LIBRARY DESTINATION "${PLUGIN_INSTALL_LIBDIR}" NAMELINK_SKIP
)