diff options
Diffstat (limited to 'Tests/CPackComponentsDEB')
10 files changed, 204 insertions, 3 deletions
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..962a1fb --- /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[ \n\t]+library[ \n\t]+libmyprivatelib.so.1[ \n\t]+needed[ \n\t]+by[ \n\t]+./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(); |