plugins.example: Make installation relocatable

Fixes "make install" to be relocatable using DESTDIR. For that
we cannot use an absolute path as intallation directory target.
This is useful mostly to implement packaging using CPack.

It is a bit awkward to configure a default CMAKE_INSTALL_PREFIX
using WiresharkConfig.cmake but it seems to be working OK.

The previous non-relocatable behaviour may still be useful. It is
relegated to a custom "copy_plugin" target.
This commit is contained in:
João Valverde 2022-03-28 12:15:47 +01:00 committed by A Wireshark GitLab Utility
parent 842f53c329
commit c451e572e5
2 changed files with 14 additions and 1 deletions

View File

@ -4,9 +4,11 @@ set(Wireshark_PATCH_VERSION @PROJECT_PATCH_VERSION@)
set(Wireshark_VERSION "@PROJECT_VERSION@")
set(Wireshark_PLUGINS_ENABLED @HAVE_PLUGINS@)
set(Wireshark_PLUGIN_LIBDIR "@PLUGIN_INSTALL_VERSION_LIBDIR@")
@PACKAGE_INIT@
set_and_check(Wireshark_INSTALL_PREFIX "${PACKAGE_PREFIX_DIR}")
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)

View File

@ -14,6 +14,12 @@ project(Hello VERSION 0.0.1 DESCRIPTION "Wireshark Hello Plugin" LANGUAGES C)
find_package(Wireshark CONFIG REQUIRED)
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "${Wireshark_INSTALL_PREFIX}"
CACHE PATH "Installation prefix" FORCE
)
endif()
if(NOT Wireshark_PLUGINS_ENABLED)
message(WARNING "Wireshark was compiled without support for plugins")
endif()
@ -36,5 +42,10 @@ set_target_properties(hello PROPERTIES PREFIX "" DEFINE_SYMBOL "")
target_link_libraries(hello epan)
install(TARGETS hello
LIBRARY DESTINATION "${Wireshark_PLUGIN_INSTALL_DIR}/epan" NAMELINK_SKIP
LIBRARY DESTINATION "${Wireshark_PLUGIN_LIBDIR}/epan" NAMELINK_SKIP
)
add_custom_target(copy_plugin
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:hello> ${Wireshark_PLUGIN_INSTALL_DIR}
COMMENT "Installing plugin to: ${Wireshark_PLUGIN_INSTALL_DIR}"
)