CMake: Modernize config-file package support

A CMake config-file package provides support for downstreams using
CMake and Wireshark libraries to easily configure the libwireshark
dependency with:
  find_package(Wireshark CONFIG [REQUIRED])
  target_link_libraries(foo epan)

The FindWireshark.cmake file is no longer needed.

See cmake-package(7) for more details on CMake's package system.

Change-Id: Ie8af1d44417a99dd08d37959f7b2ffca88572ec2
Reviewed-on: https://code.wireshark.org/review/29208
Petri-Dish: João Valverde <j@v6e.pt>
Tested-by: Petri Dish Buildbot
Reviewed-by: João Valverde <j@v6e.pt>
thomas/dect
João Valverde 4 years ago committed by João Valverde
parent e75905a583
commit d0b97a420d
  1. 45
      CMakeLists.txt
  2. 19
      WiresharkConfig.cmake.in
  3. 26
      cmake/modules/FindWireshark.cmake
  4. 25
      cmake/modules/WiresharkConfig.cmake.in
  5. 10
      cmake/modules/WiresharkConfigVersion.cmake.in
  6. 27
      doc/plugins.example/CMakeLists.txt
  7. 60
      epan/CMakeLists.txt
  8. 1
      wiretap/CMakeLists.txt
  9. 1
      wsutil/CMakeLists.txt

@ -2140,6 +2140,7 @@ if(BUILD_wireshark AND QT_FOUND)
ui
capchild
caputils
wiretap
${QT_LIBRARIES}
${GTHREAD2_LIBRARIES}
wscodecs
@ -2261,6 +2262,7 @@ if(BUILD_tshark)
ui
capchild
caputils
wiretap
${LIBEPAN_LIBS}
${APPLE_CORE_FOUNDATION_LIBRARY}
${APPLE_SYSTEM_CONFIGURATION_LIBRARY}
@ -2284,6 +2286,7 @@ endif()
if(BUILD_tfshark)
set(tfshark_LIBS
ui
wiretap
${LIBEPAN_LIBS}
${APPLE_CORE_FOUNDATION_LIBRARY}
${APPLE_SYSTEM_CONFIGURATION_LIBRARY}
@ -2305,6 +2308,7 @@ if(BUILD_rawshark AND PCAP_FOUND)
set(rawshark_LIBS
caputils
ui
wiretap
${LIBEPAN_LIBS}
${APPLE_CORE_FOUNDATION_LIBRARY}
${APPLE_SYSTEM_CONFIGURATION_LIBRARY}
@ -2325,6 +2329,7 @@ if(BUILD_sharkd)
set(sharkd_LIBS
ui
wscodecs
wiretap
${LIBEPAN_LIBS}
${APPLE_CORE_FOUNDATION_LIBRARY}
${APPLE_SYSTEM_CONFIGURATION_LIBRARY}
@ -2345,6 +2350,7 @@ endif()
if(BUILD_dftest)
set(dftest_LIBS
ui
wiretap
${LIBEPAN_LIBS}
)
set(dftest_FILES
@ -2380,6 +2386,7 @@ endif()
if(BUILD_fuzzshark)
set(fuzzshark_LIBS
wiretap
${LIBEPAN_LIBS}
)
set(fuzzshark_FILES
@ -2893,22 +2900,50 @@ install(
)
set(CMAKE_INSTALL_MODULES_DIR "${CMAKE_INSTALL_LIBDIR}/${CPACK_PACKAGE_NAME}/cmake")
configure_file("${CMAKE_MODULE_PATH}/WiresharkConfig.cmake.in" "${CMAKE_BINARY_DIR}/WiresharkConfig.cmake" @ONLY)
configure_file("${CMAKE_MODULE_PATH}/WiresharkConfigVersion.cmake.in" "${CMAKE_BINARY_DIR}/WiresharkConfigVersion.cmake" @ONLY)
install(
FILES
${CMAKE_MODULE_PATH}/FindGLIB2.cmake
${CMAKE_MODULE_PATH}/FindWireshark.cmake
${CMAKE_MODULE_PATH}/FindWSWinLibs.cmake
${CMAKE_MODULE_PATH}/UseAsn2Wrs.cmake
${CMAKE_MODULE_PATH}/LocatePythonModule.cmake
${CMAKE_MODULE_PATH}/UseMakePluginReg.cmake
${CMAKE_BINARY_DIR}/WiresharkConfig.cmake
${CMAKE_BINARY_DIR}/WiresharkConfigVersion.cmake
DESTINATION
${CMAKE_INSTALL_MODULES_DIR}
)
include(CMakePackageConfigHelpers)
configure_package_config_file(WiresharkConfig.cmake.in
${CMAKE_BINARY_DIR}/WiresharkConfig.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_MODULES_DIR}
PATH_VARS
CMAKE_INSTALL_LIBDIR
CMAKE_INSTALL_INCLUDEDIR
PLUGIN_INSTALL_VERSION_LIBDIR
EXTCAP_INSTALL_LIBDIR
)
write_basic_package_version_file(
${CMAKE_BINARY_DIR}/WiresharkConfigVersion.cmake
COMPATIBILITY AnyNewerVersion
)
# XXX On Windows wsutil depends on a CMake zlib target for which there are no
# exports.
if(NOT WIN32)
install(
FILES
${CMAKE_BINARY_DIR}/WiresharkConfig.cmake
${CMAKE_BINARY_DIR}/WiresharkConfigVersion.cmake
DESTINATION
${CMAKE_INSTALL_MODULES_DIR}
)
install(EXPORT WiresharkTargets
DESTINATION ${CMAKE_INSTALL_MODULES_DIR}
)
endif()
if (DOXYGEN_EXECUTABLE)
# API reference
# We don't have a good way of tracking dependencies, so we simply

@ -0,0 +1,19 @@
set(Wireshark_MAJOR_VERSION @PROJECT_MAJOR_VERSION@)
set(Wireshark_MINOR_VERSION @PROJECT_MINOR_VERSION@)
set(Wireshark_PATCH_VERSION @PROJECT_PATCH_VERSION@)
set(Wireshark_VERSION "@PROJECT_VERSION@")
set(Wireshark_PLUGINS_ENABLED @HAVE_PLUGINS@)
@PACKAGE_INIT@
set_and_check(Wireshark_LIB_DIR "@PACKAGE_CMAKE_INSTALL_LIBDIR@")
set_and_check(Wireshark_INCLUDE_DIR "@PACKAGE_CMAKE_INSTALL_INCLUDEDIR@/wireshark")
if(Wireshark_PLUGINS_ENABLED)
set_and_check(Wireshark_PLUGIN_INSTALL_DIR "@PACKAGE_PLUGIN_INSTALL_VERSION_LIBDIR@")
endif()
set_and_check(Wireshark_EXTCAP_INSTALL_DIR "@PACKAGE_EXTCAP_INSTALL_LIBDIR@")
include("${CMAKE_CURRENT_LIST_DIR}/WiresharkTargets.cmake")
check_required_components(Wireshark)

@ -1,26 +0,0 @@
# Locate the Wireshark library.
#
# This file is meant to be copied into projects that want to use Wireshark.
# It will search for WiresharkConfig.cmake, which ships with Wireshark
# and will provide up-to-date buildsystem changes. Thus there should not be
# any need to update FindWiresharkVc.cmake again after you integrated it into
# your project.
#
# This module defines the following variables:
# Wireshark_FOUND
# Wireshark_VERSION_MAJOR
# Wireshark_VERSION_MINOR
# Wireshark_VERSION_PATCH
# Wireshark_VERSION
# Wireshark_VERSION_STRING
# Wireshark_INSTALL_DIR
# Wireshark_PLUGIN_INSTALL_DIR
# Wireshark_LIB_DIR
# Wireshark_LIBRARY
# Wireshark_INCLUDE_DIR
# Wireshark_CMAKE_MODULES_DIR
find_package(Wireshark ${Wireshark_FIND_VERSION} QUIET NO_MODULE PATHS $ENV{HOME} /opt/Wireshark)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Wireshark CONFIG_MODE)

@ -1,25 +0,0 @@
set(Wireshark_MAJOR_VERSION "@PROJECT_MAJOR_VERSION@" )
set(Wireshark_MINOR_VERSION "@PROJECT_MINOR_VERSION@" )
set(Wireshark_PATCH_VERSION "@PROJECT_PATCH_VERSION@" )
set(Wireshark_VERSION @PROJECT_MAJOR_VERSION@.@PROJECT_MINOR_VERSION@.@PROJECT_PATCH_VERSION@)
set(Wireshark_VERSION_STRING "@PROJECT_MAJOR_VERSION@.@PROJECT_MINOR_VERSION@.@PROJECT_PATCH_VERSION@")
set(Wireshark_INSTALL_DIR "@CMAKE_INSTALL_PREFIX@")
set(Wireshark_PLUGIN_INSTALL_DIR "@CMAKE_INSTALL_PREFIX@/@PLUGIN_INSTALL_VERSION_LIBDIR@")
set(Wireshark_EXTCAP_INSTALL_DIR "@CMAKE_INSTALL_PREFIX@/@EXTCAP_INSTALL_LIBDIR@")
set(Wireshark_LIB_DIR "@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@")
set(Wireshark_INCLUDE_DIR "@CMAKE_INSTALL_PREFIX@/include/wireshark")
set(Wireshark_CMAKE_MODULES_DIR "@CMAKE_INSTALL_MODULES_DIR@")
find_library( Wireshark_LIBRARY
NAMES
wireshark
libwireshark
HINTS
${Wireshark_LIB_DIR}
PATHS
/opt/lib/
/usr/lib64
/usr/lib
)

@ -1,10 +0,0 @@
set(PACKAGE_VERSION @PROJECT_MAJOR_VERSION@.@PROJECT_MINOR_VERSION@.@PROJECT_PATCH_VERSION@)
if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}")
set(PACKAGE_VERSION_COMPATIBLE FALSE)
else()
set(PACKAGE_VERSION_COMPATIBLE TRUE)
if("${PACKAGE_FIND_VERSION}" STREQUAL "${PACKAGE_VERSION}")
set(PACKAGE_VERSION_EXACT TRUE)
endif()
endif()

@ -12,25 +12,9 @@ cmake_policy(SET CMP0048 NEW)
project(Hello VERSION 0.0.1 DESCRIPTION "Wireshark Hello Plugin" LANGUAGES C)
find_package(PkgConfig REQUIRED)
find_package(Wireshark CONFIG 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
# Note: If using PKG_CONFIG_PATH the variable needs to be set as exported
# in the execution environment.
pkg_get_variable(WIRESHARK_PLUGIN_DIR wireshark plugindir)
set(PLUGIN_INSTALL_LIBDIR "${WIRESHARK_PLUGIN_DIR}/epan")
include(CMakePushCheckState)
include(CheckFunctionExists)
cmake_push_check_state()
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)
if(NOT Wireshark_PLUGINS_ENABLED)
message(FATAL_ERROR "Wireshark was compiled without support for plugins")
endif()
@ -39,13 +23,12 @@ if (CMAKE_COMPILER_IS_GNUCC)
set(CMAKE_C_FLAGS "-Wall -Wextra ${CMAKE_C_FLAGS}")
endif()
add_definitions(-DHAVE_PLUGINS -DVERSION=\"${PROJECT_VERSION}\")
add_definitions(-DVERSION=\"${PROJECT_VERSION}\")
add_library(hello MODULE hello.c)
set_target_properties(hello PROPERTIES PREFIX "" DEFINE_SYMBOL "")
target_link_libraries(hello ${WIRESHARK_LDFLAGS})
target_compile_options(hello PUBLIC ${WIRESHARK_CFLAGS})
target_link_libraries(hello epan)
install(TARGETS hello
LIBRARY DESTINATION "${PLUGIN_INSTALL_LIBDIR}" NAMELINK_SKIP
LIBRARY DESTINATION "${Wireshark_PLUGIN_INSTALL_DIR}/epan" NAMELINK_SKIP
)

@ -263,29 +263,6 @@ add_lemon_files(LEMON_FILES LIBWIRESHARK_FILES
dtd_grammar.lemon
)
set(epan_LIBS
wiretap
wsutil
${CARES_LIBRARIES}
${GCRYPT_LIBRARIES}
#${GEOIP_LIBRARIES}
${GLIB2_LIBRARIES}
${GIO2_LIBRARIES}
${GTHREAD2_LIBRARIES}
${GNUTLS_LIBRARIES}
${KERBEROS_LIBRARIES}
${LUA_LIBRARIES}
${LZ4_LIBRARIES}
${M_LIBRARIES}
${NGHTTP2_LIBRARIES}
${PCAP_LIBRARIES}
${SMI_LIBRARIES}
${SNAPPY_LIBRARIES}
${WIN_PSAPI_LIBRARY}
${LIBXML2_LIBRARIES}
${JSONGLIB_LIBRARIES}
)
set_source_files_properties(
${LIBWIRESHARK_FILES}
PROPERTIES
@ -306,6 +283,10 @@ add_library(epan
add_dependencies(epan version)
if(ENABLE_PLUGINS)
target_compile_definitions(epan PUBLIC HAVE_PLUGINS)
endif()
set_target_properties(epan PROPERTIES
COMPILE_DEFINITIONS "WS_BUILD_DLL"
LINK_FLAGS "${WS_LINK_FLAGS}"
@ -374,11 +355,42 @@ set_target_properties(epan PROPERTIES
FOLDER "DLLs"
)
target_link_libraries(epan ${epan_LIBS})
target_link_libraries(epan
PUBLIC
wiretap
wsutil
${GLIB2_LIBRARIES}
PRIVATE
${CARES_LIBRARIES}
${GCRYPT_LIBRARIES}
${GIO2_LIBRARIES}
${GTHREAD2_LIBRARIES}
${GNUTLS_LIBRARIES}
${KERBEROS_LIBRARIES}
${LUA_LIBRARIES}
${LZ4_LIBRARIES}
${M_LIBRARIES}
${NGHTTP2_LIBRARIES}
${PCAP_LIBRARIES}
${SMI_LIBRARIES}
${SNAPPY_LIBRARIES}
${WIN_PSAPI_LIBRARY}
${LIBXML2_LIBRARIES}
${JSONGLIB_LIBRARIES}
)
target_include_directories(epan
INTERFACE
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}>
$<INSTALL_INTERFACE:include/wireshark>
PUBLIC
${GLIB2_INCLUDE_DIRS}
)
add_dependencies(epan lemon)
install(TARGETS epan
EXPORT WiresharkTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}

@ -154,6 +154,7 @@ add_custom_command(OUTPUT libwiretap.abi.tar.gz
target_link_libraries(wiretap ${wiretap_LIBS})
install(TARGETS wiretap
EXPORT WiresharkTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}

@ -296,6 +296,7 @@ add_custom_command(OUTPUT libwsutil.abi.tar.gz
target_link_libraries(wsutil ${wsutil_LIBS})
install(TARGETS wsutil
EXPORT WiresharkTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}

Loading…
Cancel
Save