Commit d586a4ad authored by Deniz Bahadir's avatar Deniz Bahadir Committed by Brad King

CPackDeb: dpkg-shlibdeps now supports searching for private shared libs

The new CPack variable `CPACK_DEBIAN_PACKAGE_SHLIBDEPS_PRIVATE_DIRS`
can be set to a list of directories. If `CPACK_DEBIAN_PACKAGE_SHLIBDEPS`
or `CPACK_DEBIAN_<component>_PACKAGE_SHLIBDEPS` are set to `ON` these
directories will be searched by `dpkg-shlibdeps` in order to find
private shared library dependencies of the libraries/executables that
shall be packed.
parent 2740cc45
Pipeline #210353 waiting for manual action with stages
in 6 minutes and 6 seconds
......@@ -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
......
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``.
......@@ -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}'")
......
......@@ -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}")
......
......@@ -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")
......
#
# 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)
#
# 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")
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()
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()
......@@ -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}")
......
#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
add_library(myprivatelib SHARED myprivatelib.cpp)
set_target_properties( myprivatelib PROPERTIES
VERSION 1.2.3
SOVERSION 1
)
#include "myprivatelib.h"
#include "stdio.h"
void myprivatelib_function()
{
printf("This is myprivatelib");
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment