diff options
author | Brad King <brad.king@kitware.com> | 2021-01-25 16:39:31 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2021-01-25 16:39:39 (GMT) |
commit | adaa3931151800aacdd370e514cdba069d521302 (patch) | |
tree | 1594d3f7fa8f5e9260e3b09c383bf81491db9929 | |
parent | 902f0c59fdde27110143370326ee53eef5f018b2 (diff) | |
parent | d586a4ad60f34a14c202a3dd60dbfbf50d69ca7f (diff) | |
download | CMake-adaa3931151800aacdd370e514cdba069d521302.zip CMake-adaa3931151800aacdd370e514cdba069d521302.tar.gz CMake-adaa3931151800aacdd370e514cdba069d521302.tar.bz2 |
Merge topic 'cpack-deb-shlibdeps-private-search-dirs'
d586a4ad60 CPackDeb: dpkg-shlibdeps now supports searching for private shared libs
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !5718
14 files changed, 271 insertions, 5 deletions
diff --git a/Help/cpack_gen/deb.rst b/Help/cpack_gen/deb.rst index 7cae613..42b8392 100644 --- a/Help/cpack_gen/deb.rst +++ b/Help/cpack_gen/deb.rst @@ -329,12 +329,36 @@ List of CPack DEB generator specific variables: may fail to find your own shared libs. See https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/RPATH-handling + .. note:: + + You can also set :variable:`CPACK_DEBIAN_PACKAGE_SHLIBDEPS_PRIVATE_DIRS` + to an appropriate value if you use this feature, in order to please + ``dpkg-shlibdeps``. However, you should only do this for private + shared libraries that could not get resolved otherwise. + .. versionadded:: 3.3 Per-component ``CPACK_DEBIAN_<COMPONENT>_PACKAGE_SHLIBDEPS`` variables. .. versionadded:: 3.6 Correct handling of ``$ORIGIN`` in :variable:`CMAKE_INSTALL_RPATH`. +.. variable:: CPACK_DEBIAN_PACKAGE_SHLIBDEPS_PRIVATE_DIRS + + .. versionadded:: 3.20 + + May be set to a list of directories that will be given to ``dpkg-shlibdeps`` + via its ``-d`` option. These will be searched by ``dpkg-shlibdeps`` in order + to find private shared library dependencies. + + * Mandatory : NO + * Default : + + .. note:: + + You should prefer to set :variable:`CMAKE_INSTALL_RPATH` to an appropriate + value if you use ``dpkg-shlibdeps``. The current option is really only + needed for private shared library dependencies. + .. variable:: CPACK_DEBIAN_PACKAGE_DEBUG May be set when invoking cpack in order to trace debug information diff --git a/Help/release/dev/cpack-deb-shlibdeps-private-search-dirs.rst b/Help/release/dev/cpack-deb-shlibdeps-private-search-dirs.rst new file mode 100644 index 0000000..c4a4797 --- /dev/null +++ b/Help/release/dev/cpack-deb-shlibdeps-private-search-dirs.rst @@ -0,0 +1,8 @@ +cpack-deb-shlibdeps-resolving-private-dependencies +-------------------------------------------------- + +* The :module:`CPackDeb` module learned a new + :variable:`CPACK_DEBIAN_PACKAGE_SHLIBDEPS_PRIVATE_DIRS` + variable to specify additional search directories for + resolving private library dependencies when using + ``dpkg-shlibdeps``. diff --git a/Modules/Internal/CPack/CPackDeb.cmake b/Modules/Internal/CPack/CPackDeb.cmake index 48d451a..2ef0489 100644 --- a/Modules/Internal/CPack/CPackDeb.cmake +++ b/Modules/Internal/CPack/CPackDeb.cmake @@ -310,10 +310,23 @@ function(cpack_deb_prepare_package_vars) set(IGNORE_MISSING_INFO_FLAG "--ignore-missing-info") endif() + if(CPACK_DEBIAN_PACKAGE_SHLIBDEPS_PRIVATE_DIRS) + unset(PRIVATE_SEARCH_DIR_OPTIONS) + # Add -l option if the tool supports it + if(DEFINED SHLIBDEPS_EXECUTABLE_VERSION AND SHLIBDEPS_EXECUTABLE_VERSION VERSION_GREATER_EQUAL 1.17.0) + foreach(dir IN LISTS CPACK_DEBIAN_PACKAGE_SHLIBDEPS_PRIVATE_DIRS) + list(APPEND PRIVATE_SEARCH_DIR_OPTIONS "-l${dir}") + endforeach() + else() + message(WARNING "CPackDeb: dkpg-shlibdeps is too old. \"CPACK_DEBIAN_PACKAGE_SHLIBDEPS_PRIVATE_DIRS\" is therefore ignored.") + endif() + endif() + # Execute dpkg-shlibdeps # --ignore-missing-info : allow dpkg-shlibdeps to run even if some libs do not belong to a package + # -l<dir>: make dpkg-shlibdeps also search in this directory for (private) shared library dependencies # -O : print to STDOUT - execute_process(COMMAND ${SHLIBDEPS_EXECUTABLE} ${IGNORE_MISSING_INFO_FLAG} -O ${CPACK_DEB_BINARY_FILES} + execute_process(COMMAND ${SHLIBDEPS_EXECUTABLE} ${PRIVATE_SEARCH_DIR_OPTIONS} ${IGNORE_MISSING_INFO_FLAG} -O ${CPACK_DEB_BINARY_FILES} WORKING_DIRECTORY "${CPACK_TEMPORARY_DIRECTORY}" OUTPUT_VARIABLE SHLIBDEPS_OUTPUT RESULT_VARIABLE SHLIBDEPS_RESULT @@ -325,7 +338,7 @@ function(cpack_deb_prepare_package_vars) endif() if(NOT SHLIBDEPS_RESULT EQUAL 0) message(FATAL_ERROR "CPackDeb: dpkg-shlibdeps: '${SHLIBDEPS_ERROR}';\n" - "executed command: '${SHLIBDEPS_EXECUTABLE} ${IGNORE_MISSING_INFO_FLAG} -O ${CPACK_DEB_BINARY_FILES}';\n" + "executed command: '${SHLIBDEPS_EXECUTABLE} ${PRIVATE_SEARCH_DIR_OPTIONS} ${IGNORE_MISSING_INFO_FLAG} -O ${CPACK_DEB_BINARY_FILES}';\n" "found files: '${INSTALL_FILE_}';\n" "files info: '${CPACK_DEB_INSTALL_FILES}';\n" "binary files: '${CPACK_DEB_BINARY_FILES}'") diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index 5948911..d28d89f 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -1153,6 +1153,26 @@ if(BUILD_TESTING) "components-depend1" "components-depend2" "compression") + # Run additional tests if dpkg-shlibdeps is available (and is new enough version) + find_program(SHLIBDEPS_EXECUTABLE NAMES dpkg-shlibdeps) + if(SHLIBDEPS_EXECUTABLE) + # Check version of the dpkg-shlibdeps tool + execute_process(COMMAND ${CMAKE_COMMAND} -E env LC_ALL=C ${SHLIBDEPS_EXECUTABLE} --version + OUTPUT_VARIABLE _TMP_VERSION + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) + if(_TMP_VERSION MATCHES "dpkg-shlibdeps version ([0-9]+\\.[0-9]+\\.[0-9]+)") + set(SHLIBDEPS_EXECUTABLE_VERSION "${CMAKE_MATCH_1}") + else() + unset(SHLIBDEPS_EXECUTABLE_VERSION) + endif() + if(NOT SHLIBDEPS_EXECUTABLE_VERSION VERSION_LESS 1.19 OR + (NOT SHLIBDEPS_EXECUTABLE_VERSION VERSION_LESS 1.17 AND NOT CMAKE_BINARY_DIR MATCHES ".*[ ].*")) + list(APPEND DEB_CONFIGURATIONS_TO_TEST "shlibdeps-with-private-lib-failure" + "shlibdeps-with-private-lib-success") + endif() + endif() + set(CPackGen "DEB") set(CPackRun_CPackGen "-DCPackGen=${CPackGen}") diff --git a/Tests/CPackComponentsDEB/CMakeLists.txt b/Tests/CPackComponentsDEB/CMakeLists.txt index 4363f1b..b2e2106 100644 --- a/Tests/CPackComponentsDEB/CMakeLists.txt +++ b/Tests/CPackComponentsDEB/CMakeLists.txt @@ -22,6 +22,13 @@ target_link_libraries(mylibapp mylib) add_executable(mylibapp2 mylibapp.cpp) target_link_libraries(mylibapp2 mylib) +if (CPackDEBConfiguration MATCHES "shlibdeps-with-private-lib") + add_subdirectory("shlibdeps-with-private-lib") + add_executable(mylibapp3 mylibapp.cpp) + target_compile_definitions(mylibapp3 PRIVATE -DSHLIBDEPS_PRIVATE) + target_link_libraries(mylibapp3 myprivatelib) +endif() + # Create installation targets. Note that we put each kind of file # into a different component via COMPONENT. These components will # be used to create the installation components. @@ -39,6 +46,13 @@ install(FILES mylib.h DESTINATION include COMPONENT headers) +if (CPackDEBConfiguration MATCHES "shlibdeps-with-private-lib") + install(TARGETS mylibapp3 + RUNTIME + DESTINATION bin + COMPONENT applications) +endif() + # CPack boilerplate for this project set(CPACK_PACKAGE_NAME "MyLib") set(CPACK_PACKAGE_CONTACT "None") diff --git a/Tests/CPackComponentsDEB/MyLibCPackConfig-shlibdeps-with-private-lib-failure.cmake.in b/Tests/CPackComponentsDEB/MyLibCPackConfig-shlibdeps-with-private-lib-failure.cmake.in new file mode 100644 index 0000000..cfe6df5 --- /dev/null +++ b/Tests/CPackComponentsDEB/MyLibCPackConfig-shlibdeps-with-private-lib-failure.cmake.in @@ -0,0 +1,24 @@ +# +# Activate component packaging +# + +if(CPACK_GENERATOR MATCHES "DEB") + set(CPACK_DEB_COMPONENT_INSTALL "ON") +endif() + +# +# Choose grouping way +# +#set(CPACK_COMPONENTS_ALL_GROUPS_IN_ONE_PACKAGE) +#set(CPACK_COMPONENTS_GROUPING) +set(CPACK_COMPONENTS_IGNORE_GROUPS 1) +#set(CPACK_COMPONENTS_ALL_IN_ONE_PACKAGE 1) + +# we set shlibdeps to on +set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON) +# except for the component "headers" that do not contain any binary. +# the packaging will just fail if this does not work +set(CPACK_DEBIAN_HEADERS_PACKAGE_SHLIBDEPS OFF) + +# Also libraries contains only a static library. +set(CPACK_DEBIAN_LIBRARIES_PACKAGE_SHLIBDEPS OFF) diff --git a/Tests/CPackComponentsDEB/MyLibCPackConfig-shlibdeps-with-private-lib-success.cmake.in b/Tests/CPackComponentsDEB/MyLibCPackConfig-shlibdeps-with-private-lib-success.cmake.in new file mode 100644 index 0000000..76aadc9 --- /dev/null +++ b/Tests/CPackComponentsDEB/MyLibCPackConfig-shlibdeps-with-private-lib-success.cmake.in @@ -0,0 +1,33 @@ +# +# Activate component packaging +# + +if(CPACK_GENERATOR MATCHES "DEB") + set(CPACK_DEB_COMPONENT_INSTALL "ON") +endif() + +# +# Choose grouping way +# +#set(CPACK_COMPONENTS_ALL_GROUPS_IN_ONE_PACKAGE) +#set(CPACK_COMPONENTS_GROUPING) +set(CPACK_COMPONENTS_IGNORE_GROUPS 1) +#set(CPACK_COMPONENTS_ALL_IN_ONE_PACKAGE 1) + +# we set shlibdeps to on +set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON) +# except for the component "headers" that do not contain any binary. +# the packaging will just fail if this does not work +set(CPACK_DEBIAN_HEADERS_PACKAGE_SHLIBDEPS OFF) + +# Also libraries contains only a static library. +set(CPACK_DEBIAN_LIBRARIES_PACKAGE_SHLIBDEPS OFF) + +# Most importantly, we also give a list of additional search directories +# to allow `dpkg-shlibdeps` to find the private dependency. +set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS_PRIVATE_DIRS + "${CPACK_PACKAGE_DIRECTORY}/shlibdeps-with-private-lib" + "${CPACK_PACKAGE_DIRECTORY}/shlibdeps-with-private-lib/Debug" + "${CPACK_PACKAGE_DIRECTORY}/shlibdeps-with-private-lib/Release" + "${CPACK_PACKAGE_DIRECTORY}/shlibdeps-with-private-lib/RelWithDebInfo" + "${CPACK_PACKAGE_DIRECTORY}/shlibdeps-with-private-lib/MinSizeRel") diff --git a/Tests/CPackComponentsDEB/RunCPackVerifyResult-shlibdeps-with-private-lib-failure.cmake b/Tests/CPackComponentsDEB/RunCPackVerifyResult-shlibdeps-with-private-lib-failure.cmake new file mode 100644 index 0000000..547852d7 --- /dev/null +++ b/Tests/CPackComponentsDEB/RunCPackVerifyResult-shlibdeps-with-private-lib-failure.cmake @@ -0,0 +1,19 @@ +if(NOT CPackComponentsDEB_SOURCE_DIR) + message(FATAL_ERROR "CPackComponentsDEB_SOURCE_DIR not set") +endif() + +include(${CPackComponentsDEB_SOURCE_DIR}/RunCPackVerifyResult.cmake) + + +set(actual_output) +run_cpack(actual_output + CPack_output + CPack_error + EXPECT_FAILURE + CONFIG_ARGS ${config_args} + CONFIG_VERBOSE ${config_verbose}) + +string(REGEX MATCH "dpkg-shlibdeps: error: (cannot|couldn't) find library\n[ \t]*libmyprivatelib.so.1 needed by ./usr/bin/mylibapp3" expected_error ${CPack_error}) +if(NOT expected_error) + message(FATAL_ERROR "Did not get the expected error-message!") +endif() diff --git a/Tests/CPackComponentsDEB/RunCPackVerifyResult-shlibdeps-with-private-lib-success.cmake b/Tests/CPackComponentsDEB/RunCPackVerifyResult-shlibdeps-with-private-lib-success.cmake new file mode 100644 index 0000000..6eff3db --- /dev/null +++ b/Tests/CPackComponentsDEB/RunCPackVerifyResult-shlibdeps-with-private-lib-success.cmake @@ -0,0 +1,75 @@ +if(NOT CPackComponentsDEB_SOURCE_DIR) + message(FATAL_ERROR "CPackComponentsDEB_SOURCE_DIR not set") +endif() + +include(${CPackComponentsDEB_SOURCE_DIR}/RunCPackVerifyResult.cmake) + + + +# requirements + +# debian now produces lower case names +set(expected_file_mask "${CPackComponentsDEB_BINARY_DIR}/mylib-*_1.0.3_*.deb") +set(expected_count 3) + + +set(actual_output) +run_cpack(actual_output + CPack_output + CPack_error + EXPECTED_FILE_MASK "${expected_file_mask}" + CONFIG_ARGS ${config_args} + CONFIG_VERBOSE ${config_verbose}) + +message(STATUS "expected_count='${expected_count}'") +message(STATUS "expected_file_mask='${expected_file_mask}'") +message(STATUS "actual_output_files='${actual_output}'") + +if(NOT actual_output) + message(FATAL_ERROR "error: expected_files do not exist: CPackComponentsDEB test fails. (CPack_output=${CPack_output}, CPack_error=${CPack_error}") +endif() + +list(LENGTH actual_output actual_count) +message(STATUS "actual_count='${actual_count}'") +if(NOT actual_count EQUAL expected_count) + message(FATAL_ERROR "error: expected_count=${expected_count} does not match actual_count=${actual_count}: CPackComponents test fails. (CPack_output=${CPack_output}, CPack_error=${CPack_error})") +endif() + + +# dpkg-deb checks for the summary of the packages +find_program(DPKGDEB_EXECUTABLE dpkg-deb) +if(DPKGDEB_EXECUTABLE) + set(dpkgdeb_output_errors_all "") + foreach(_f IN LISTS actual_output) + + # extracts the metadata from the package + run_dpkgdeb(dpkg_output + FILENAME ${_f} + ) + + dpkgdeb_return_specific_metaentry(dpkg_package_name + DPKGDEB_OUTPUT "${dpkg_output}" + METAENTRY "Package:") + + message(STATUS "package='${dpkg_package_name}'") + + if(dpkg_package_name STREQUAL "mylib-applications") + # pass + elseif(dpkg_package_name STREQUAL "mylib-headers") + # pass + elseif(dpkg_package_name STREQUAL "mylib-libraries") + # pass + else() + set(dpkgdeb_output_errors_all ${dpkgdeb_output_errors_all} + "dpkg-deb: ${_f}: component name not found: ${dpkg_package_name}\n") + endif() + + endforeach() + + + if(NOT dpkgdeb_output_errors_all STREQUAL "") + message(FATAL_ERROR "dpkg-deb checks failed:\n${dpkgdeb_output_errors_all}") + endif() +else() + message("dpkg-deb executable not found - skipping dpkg-deb test") +endif() diff --git a/Tests/CPackComponentsDEB/RunCPackVerifyResult.cmake b/Tests/CPackComponentsDEB/RunCPackVerifyResult.cmake index 3bc8d2a..8f7c198 100644 --- a/Tests/CPackComponentsDEB/RunCPackVerifyResult.cmake +++ b/Tests/CPackComponentsDEB/RunCPackVerifyResult.cmake @@ -29,7 +29,7 @@ endif() # run cpack with some options and returns the list of files generated # -output_expected_file: list of files that match the pattern function(run_cpack output_expected_file CPack_output_parent CPack_error_parent) - set(options ) + set(options "EXPECT_FAILURE") set(oneValueArgs "EXPECTED_FILE_MASK" "CONFIG_VERBOSE") set(multiValueArgs "CONFIG_ARGS") cmake_parse_arguments(run_cpack_deb "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} ) @@ -45,17 +45,26 @@ function(run_cpack output_expected_file CPack_output_parent CPack_error_parent) message("config_args = ${run_cpack_deb_CONFIG_ARGS}") message("config_verbose = ${run_cpack_deb_CONFIG_VERBOSE}") + + set(_backup_lang "$ENV{LANG}") + set(_backup_lc_all "$ENV{LC_ALL}") + set(ENV{LANG} "C") + set(ENV{LC_ALL} "C") execute_process(COMMAND ${CMAKE_CPACK_COMMAND} ${run_cpack_deb_CONFIG_VERBOSE} -G ${CPackGen} -C "${CONFIG}" ${run_cpack_deb_CONFIG_ARGS} RESULT_VARIABLE CPack_result OUTPUT_VARIABLE CPack_output ERROR_VARIABLE CPack_error WORKING_DIRECTORY ${CPackComponentsDEB_BINARY_DIR}) + set(ENV{LANG} "${_backup_lang}") + set(ENV{LC_ALL} "${_backup_lc_all}") set(${CPack_output_parent} ${CPack_output} PARENT_SCOPE) set(${CPack_error_parent} ${CPack_error} PARENT_SCOPE) - if (CPack_result) + if (CPack_result AND NOT run_cpack_deb_EXPECT_FAILURE) message(FATAL_ERROR "error: CPack execution went wrong!, CPack_output=${CPack_output}, CPack_error=${CPack_error}") + elseif (NOT CPack_result AND run_cpack_deb_EXPECT_FAILURE) + message(FATAL_ERROR "error: CPack execution succeeded although failure was expected!, CPack_output=${CPack_output}, CPack_error=${CPack_error}") else () message(STATUS "CPack_output=${CPack_output}") message(STATUS "CPack_error=${CPack_error}") diff --git a/Tests/CPackComponentsDEB/mylibapp.cpp b/Tests/CPackComponentsDEB/mylibapp.cpp index a438ac7..bb45831 100644 --- a/Tests/CPackComponentsDEB/mylibapp.cpp +++ b/Tests/CPackComponentsDEB/mylibapp.cpp @@ -1,6 +1,19 @@ -#include "mylib.h" +#ifndef SHLIBDEPS_PRIVATE + +# include "mylib.h" int main() { mylib_function(); } + +#else + +# include "shlibdeps-with-private-lib/myprivatelib.h" + +int main() +{ + myprivatelib_function(); +} + +#endif diff --git a/Tests/CPackComponentsDEB/shlibdeps-with-private-lib/CMakeLists.txt b/Tests/CPackComponentsDEB/shlibdeps-with-private-lib/CMakeLists.txt new file mode 100644 index 0000000..c7ef386 --- /dev/null +++ b/Tests/CPackComponentsDEB/shlibdeps-with-private-lib/CMakeLists.txt @@ -0,0 +1,5 @@ +add_library(myprivatelib SHARED myprivatelib.cpp) +set_target_properties( myprivatelib PROPERTIES + VERSION 1.2.3 + SOVERSION 1 +) diff --git a/Tests/CPackComponentsDEB/shlibdeps-with-private-lib/myprivatelib.cpp b/Tests/CPackComponentsDEB/shlibdeps-with-private-lib/myprivatelib.cpp new file mode 100644 index 0000000..67110e6 --- /dev/null +++ b/Tests/CPackComponentsDEB/shlibdeps-with-private-lib/myprivatelib.cpp @@ -0,0 +1,8 @@ +#include "myprivatelib.h" + +#include "stdio.h" + +void myprivatelib_function() +{ + printf("This is myprivatelib"); +} diff --git a/Tests/CPackComponentsDEB/shlibdeps-with-private-lib/myprivatelib.h b/Tests/CPackComponentsDEB/shlibdeps-with-private-lib/myprivatelib.h new file mode 100644 index 0000000..7e4a42d --- /dev/null +++ b/Tests/CPackComponentsDEB/shlibdeps-with-private-lib/myprivatelib.h @@ -0,0 +1 @@ +void myprivatelib_function(); |