summaryrefslogtreecommitdiffstats
path: root/Tests/RunCMake/CPack
diff options
context:
space:
mode:
Diffstat (limited to 'Tests/RunCMake/CPack')
-rw-r--r--Tests/RunCMake/CPack/7Z/Helpers.cmake3
-rw-r--r--Tests/RunCMake/CPack/7Z/Prerequirements.cmake4
-rw-r--r--Tests/RunCMake/CPack/7Z/packaging_COMPONENT_default.cmake1
-rw-r--r--Tests/RunCMake/CPack/ArchiveCommon/common_helpers.cmake71
-rw-r--r--Tests/RunCMake/CPack/CMakeLists.txt21
-rw-r--r--Tests/RunCMake/CPack/CPackTestHelpers.cmake151
-rw-r--r--Tests/RunCMake/CPack/DEB/Helpers.cmake176
-rw-r--r--Tests/RunCMake/CPack/DEB/Prerequirements.cmake22
-rw-r--r--Tests/RunCMake/CPack/DEB/packaging_COMPONENT_default.cmake2
-rw-r--r--Tests/RunCMake/CPack/DEB/packaging_MONOLITHIC_default.cmake1
-rw-r--r--Tests/RunCMake/CPack/DragNDrop/Helpers.cmake54
-rw-r--r--Tests/RunCMake/CPack/DragNDrop/Prerequirements.cmake8
-rw-r--r--Tests/RunCMake/CPack/DragNDrop/packaging_COMPONENT_default.cmake3
-rw-r--r--Tests/RunCMake/CPack/External/Helpers.cmake31
-rw-r--r--Tests/RunCMake/CPack/External/Prerequirements.cmake0
-rw-r--r--Tests/RunCMake/CPack/README.txt256
-rw-r--r--Tests/RunCMake/CPack/RPM/Helpers.cmake94
-rw-r--r--Tests/RunCMake/CPack/RPM/Prerequirements.cmake16
-rw-r--r--Tests/RunCMake/CPack/RPM/default_expected_stderr.txt1
-rw-r--r--Tests/RunCMake/CPack/RPM/packaging_COMPONENT_default.cmake1
-rw-r--r--Tests/RunCMake/CPack/RunCMakeTest.cmake48
-rw-r--r--Tests/RunCMake/CPack/STGZ/Helpers.cmake75
-rw-r--r--Tests/RunCMake/CPack/STGZ/Prerequirements.cmake11
-rw-r--r--Tests/RunCMake/CPack/STGZ/packaging_COMPONENT_default.cmake1
-rw-r--r--Tests/RunCMake/CPack/TBZ2/Helpers.cmake3
-rw-r--r--Tests/RunCMake/CPack/TBZ2/Prerequirements.cmake4
-rw-r--r--Tests/RunCMake/CPack/TBZ2/packaging_COMPONENT_default.cmake1
-rw-r--r--Tests/RunCMake/CPack/TGZ/Helpers.cmake3
-rw-r--r--Tests/RunCMake/CPack/TGZ/Prerequirements.cmake4
-rw-r--r--Tests/RunCMake/CPack/TGZ/packaging_COMPONENT_default.cmake1
-rw-r--r--Tests/RunCMake/CPack/TXZ/Helpers.cmake3
-rw-r--r--Tests/RunCMake/CPack/TXZ/Prerequirements.cmake4
-rw-r--r--Tests/RunCMake/CPack/TXZ/packaging_COMPONENT_default.cmake1
-rw-r--r--Tests/RunCMake/CPack/TZ/Helpers.cmake3
-rw-r--r--Tests/RunCMake/CPack/TZ/Prerequirements.cmake4
-rw-r--r--Tests/RunCMake/CPack/TZ/packaging_COMPONENT_default.cmake1
-rw-r--r--Tests/RunCMake/CPack/VerifyResult.cmake137
-rw-r--r--Tests/RunCMake/CPack/ZIP/Helpers.cmake3
-rw-r--r--Tests/RunCMake/CPack/ZIP/Prerequirements.cmake4
-rw-r--r--Tests/RunCMake/CPack/ZIP/packaging_COMPONENT_default.cmake1
-rw-r--r--Tests/RunCMake/CPack/tests/CPACK_INSTALL_SCRIPTS/ExpectedFiles.cmake3
-rw-r--r--Tests/RunCMake/CPack/tests/CPACK_INSTALL_SCRIPTS/both-stderr.txt1
-rw-r--r--Tests/RunCMake/CPack/tests/CPACK_INSTALL_SCRIPTS/test.cmake26
-rw-r--r--Tests/RunCMake/CPack/tests/CUSTOM_BINARY_SPEC_FILE/ExpectedFiles.cmake9
-rw-r--r--Tests/RunCMake/CPack/tests/CUSTOM_BINARY_SPEC_FILE/RPM-COMPONENT-stderr.txt2
-rw-r--r--Tests/RunCMake/CPack/tests/CUSTOM_BINARY_SPEC_FILE/RPM-MONOLITHIC-stderr.txt1
-rw-r--r--Tests/RunCMake/CPack/tests/CUSTOM_BINARY_SPEC_FILE/custom.spec.in80
-rw-r--r--Tests/RunCMake/CPack/tests/CUSTOM_BINARY_SPEC_FILE/test.cmake9
-rw-r--r--Tests/RunCMake/CPack/tests/CUSTOM_NAMES/ExpectedFiles.cmake18
-rw-r--r--Tests/RunCMake/CPack/tests/CUSTOM_NAMES/test.cmake20
-rw-r--r--Tests/RunCMake/CPack/tests/DEBUGINFO/ExpectedFiles.cmake41
-rw-r--r--Tests/RunCMake/CPack/tests/DEBUGINFO/test.cmake48
-rw-r--r--Tests/RunCMake/CPack/tests/DEB_DESCRIPTION/ExpectedFiles.cmake16
-rw-r--r--Tests/RunCMake/CPack/tests/DEB_DESCRIPTION/VerifyResult.cmake69
-rw-r--r--Tests/RunCMake/CPack/tests/DEB_DESCRIPTION/test.cmake55
-rw-r--r--Tests/RunCMake/CPack/tests/DEB_PACKAGE_VERSION_BACK_COMPATIBILITY/ExpectedFiles.cmake2
-rw-r--r--Tests/RunCMake/CPack/tests/DEB_PACKAGE_VERSION_BACK_COMPATIBILITY/VerifyResult.cmake11
-rw-r--r--Tests/RunCMake/CPack/tests/DEB_PACKAGE_VERSION_BACK_COMPATIBILITY/test.cmake7
-rw-r--r--Tests/RunCMake/CPack/tests/DEFAULT_PERMISSIONS/ExpectedFiles.cmake6
-rw-r--r--Tests/RunCMake/CPack/tests/DEFAULT_PERMISSIONS/VerifyResult.cmake39
-rw-r--r--Tests/RunCMake/CPack/tests/DEFAULT_PERMISSIONS/invalid_CMAKE_var-stderr.txt1
-rw-r--r--Tests/RunCMake/CPack/tests/DEFAULT_PERMISSIONS/invalid_CPACK_var-stderr.txt1
-rw-r--r--Tests/RunCMake/CPack/tests/DEFAULT_PERMISSIONS/test.cmake34
-rw-r--r--Tests/RunCMake/CPack/tests/DEPENDENCIES/DEB-stderr.txt1
-rw-r--r--Tests/RunCMake/CPack/tests/DEPENDENCIES/ExpectedFiles.cmake18
-rw-r--r--Tests/RunCMake/CPack/tests/DEPENDENCIES/VerifyResult.cmake82
-rw-r--r--Tests/RunCMake/CPack/tests/DEPENDENCIES/test.cmake60
-rw-r--r--Tests/RunCMake/CPack/tests/DIST/ExpectedFiles.cmake2
-rw-r--r--Tests/RunCMake/CPack/tests/DIST/VerifyResult.cmake16
-rw-r--r--Tests/RunCMake/CPack/tests/DIST/test.cmake3
-rw-r--r--Tests/RunCMake/CPack/tests/EMPTY_DIR/ExpectedFiles.cmake7
-rw-r--r--Tests/RunCMake/CPack/tests/EMPTY_DIR/test.cmake14
-rw-r--r--Tests/RunCMake/CPack/tests/EXTERNAL/ExpectedFiles.cmake7
-rw-r--r--Tests/RunCMake/CPack/tests/EXTERNAL/VerifyResult.cmake3
-rw-r--r--Tests/RunCMake/CPack/tests/EXTERNAL/bad_major-stderr.txt6
-rw-r--r--Tests/RunCMake/CPack/tests/EXTERNAL/bad_minor-stderr.txt6
-rw-r--r--Tests/RunCMake/CPack/tests/EXTERNAL/create_package.cmake31
-rw-r--r--Tests/RunCMake/CPack/tests/EXTERNAL/expected-json-1.0.txt177
-rw-r--r--Tests/RunCMake/CPack/tests/EXTERNAL/invalid_bad-stderr.txt6
-rw-r--r--Tests/RunCMake/CPack/tests/EXTERNAL/stage_and_package-stderr.txt1
-rw-r--r--Tests/RunCMake/CPack/tests/EXTERNAL/stage_and_package-stdout.txt1
-rw-r--r--Tests/RunCMake/CPack/tests/EXTERNAL/test.cmake86
-rw-r--r--Tests/RunCMake/CPack/tests/EXTRA/ExpectedFiles.cmake8
-rw-r--r--Tests/RunCMake/CPack/tests/EXTRA/VerifyResult.cmake18
-rw-r--r--Tests/RunCMake/CPack/tests/EXTRA/test.cmake35
-rw-r--r--Tests/RunCMake/CPack/tests/EXTRA_SLASH_IN_PATH/ExpectedFiles.cmake17
-rw-r--r--Tests/RunCMake/CPack/tests/EXTRA_SLASH_IN_PATH/VerifyResult.cmake7
-rw-r--r--Tests/RunCMake/CPack/tests/EXTRA_SLASH_IN_PATH/test.cmake41
-rw-r--r--Tests/RunCMake/CPack/tests/GENERATE_SHLIBS/DEB-Prerequirements.cmake7
-rw-r--r--Tests/RunCMake/CPack/tests/GENERATE_SHLIBS/ExpectedFiles.cmake6
-rw-r--r--Tests/RunCMake/CPack/tests/GENERATE_SHLIBS/VerifyResult.cmake9
-rw-r--r--Tests/RunCMake/CPack/tests/GENERATE_SHLIBS/test.cmake19
-rw-r--r--Tests/RunCMake/CPack/tests/GENERATE_SHLIBS_LDCONFIG/DEB-Prerequirements.cmake7
-rw-r--r--Tests/RunCMake/CPack/tests/GENERATE_SHLIBS_LDCONFIG/ExpectedFiles.cmake6
-rw-r--r--Tests/RunCMake/CPack/tests/GENERATE_SHLIBS_LDCONFIG/VerifyResult.cmake8
-rw-r--r--Tests/RunCMake/CPack/tests/GENERATE_SHLIBS_LDCONFIG/test.cmake15
-rw-r--r--Tests/RunCMake/CPack/tests/INSTALL_SCRIPTS/ExpectedFiles.cmake5
-rw-r--r--Tests/RunCMake/CPack/tests/INSTALL_SCRIPTS/VerifyResult.cmake29
-rw-r--r--Tests/RunCMake/CPack/tests/INSTALL_SCRIPTS/test.cmake60
-rw-r--r--Tests/RunCMake/CPack/tests/LONG_FILENAMES/DEB-Prerequirements.cmake7
-rw-r--r--Tests/RunCMake/CPack/tests/LONG_FILENAMES/ExpectedFiles.cmake3
-rw-r--r--Tests/RunCMake/CPack/tests/LONG_FILENAMES/VerifyResult.cmake26
-rw-r--r--Tests/RunCMake/CPack/tests/LONG_FILENAMES/test.cmake13
-rw-r--r--Tests/RunCMake/CPack/tests/MAIN_COMPONENT/ExpectedFiles.cmake11
-rw-r--r--Tests/RunCMake/CPack/tests/MAIN_COMPONENT/RPM-invalid-stderr.txt1
-rw-r--r--Tests/RunCMake/CPack/tests/MAIN_COMPONENT/test.cmake10
-rw-r--r--Tests/RunCMake/CPack/tests/MD5SUMS/ExpectedFiles.cmake2
-rw-r--r--Tests/RunCMake/CPack/tests/MD5SUMS/VerifyResult.cmake3
-rw-r--r--Tests/RunCMake/CPack/tests/MD5SUMS/test.cmake5
-rw-r--r--Tests/RunCMake/CPack/tests/MINIMAL/ExpectedFiles.cmake2
-rw-r--r--Tests/RunCMake/CPack/tests/MINIMAL/test.cmake5
-rw-r--r--Tests/RunCMake/CPack/tests/PACKAGE_CHECKSUM/ExpectedFiles.cmake6
-rw-r--r--Tests/RunCMake/CPack/tests/PACKAGE_CHECKSUM/TGZ-invalid-stderr.txt2
-rw-r--r--Tests/RunCMake/CPack/tests/PACKAGE_CHECKSUM/VerifyResult.cmake11
-rw-r--r--Tests/RunCMake/CPack/tests/PACKAGE_CHECKSUM/test.cmake3
-rw-r--r--Tests/RunCMake/CPack/tests/PARTIALLY_RELOCATABLE_WARNING/ExpectedFiles.cmake4
-rw-r--r--Tests/RunCMake/CPack/tests/PARTIALLY_RELOCATABLE_WARNING/RPM-stderr.txt1
-rw-r--r--Tests/RunCMake/CPack/tests/PARTIALLY_RELOCATABLE_WARNING/test.cmake4
-rw-r--r--Tests/RunCMake/CPack/tests/PER_COMPONENT_FIELDS/ExpectedFiles.cmake8
-rw-r--r--Tests/RunCMake/CPack/tests/PER_COMPONENT_FIELDS/VerifyResult.cmake38
-rw-r--r--Tests/RunCMake/CPack/tests/PER_COMPONENT_FIELDS/test.cmake25
-rw-r--r--Tests/RunCMake/CPack/tests/PROJECT_META/ExpectedFiles.cmake9
-rw-r--r--Tests/RunCMake/CPack/tests/PROJECT_META/VerifyResult.cmake30
-rw-r--r--Tests/RunCMake/CPack/tests/PROJECT_META/test.cmake11
-rw-r--r--Tests/RunCMake/CPack/tests/SINGLE_DEBUGINFO/ExpectedFiles.cmake30
-rw-r--r--Tests/RunCMake/CPack/tests/SINGLE_DEBUGINFO/RPM-no_main_component-stderr.txt1
-rw-r--r--Tests/RunCMake/CPack/tests/SINGLE_DEBUGINFO/test.cmake54
-rw-r--r--Tests/RunCMake/CPack/tests/SOURCE_PACKAGE/ExpectedFiles.cmake3
-rw-r--r--Tests/RunCMake/CPack/tests/SOURCE_PACKAGE/VerifyResult.cmake67
-rw-r--r--Tests/RunCMake/CPack/tests/SOURCE_PACKAGE/test.cmake7
-rw-r--r--Tests/RunCMake/CPack/tests/SUGGESTS/ExpectedFiles.cmake2
-rw-r--r--Tests/RunCMake/CPack/tests/SUGGESTS/RPM-stderr.txt1
-rw-r--r--Tests/RunCMake/CPack/tests/SUGGESTS/VerifyResult.cmake31
-rw-r--r--Tests/RunCMake/CPack/tests/SUGGESTS/test.cmake3
-rw-r--r--Tests/RunCMake/CPack/tests/SYMLINKS/ExpectedFiles.cmake12
-rw-r--r--Tests/RunCMake/CPack/tests/SYMLINKS/TGZ-Prerequirements.cmake5
-rw-r--r--Tests/RunCMake/CPack/tests/SYMLINKS/VerifyResult.cmake26
-rw-r--r--Tests/RunCMake/CPack/tests/SYMLINKS/test.cmake14
-rw-r--r--Tests/RunCMake/CPack/tests/THREADED/ExpectedFiles.cmake2
-rw-r--r--Tests/RunCMake/CPack/tests/THREADED/test.cmake7
-rw-r--r--Tests/RunCMake/CPack/tests/THREADED_ALL/ExpectedFiles.cmake2
-rw-r--r--Tests/RunCMake/CPack/tests/THREADED_ALL/test.cmake7
-rw-r--r--Tests/RunCMake/CPack/tests/TIMESTAMPS/ExpectedFiles.cmake2
-rw-r--r--Tests/RunCMake/CPack/tests/TIMESTAMPS/VerifyResult.cmake58
-rw-r--r--Tests/RunCMake/CPack/tests/TIMESTAMPS/test.cmake3
-rw-r--r--Tests/RunCMake/CPack/tests/USER_FILELIST/ExpectedFiles.cmake2
-rw-r--r--Tests/RunCMake/CPack/tests/USER_FILELIST/VerifyResult.cmake12
-rw-r--r--Tests/RunCMake/CPack/tests/USER_FILELIST/test.cmake13
-rw-r--r--Tests/RunCMake/CPack/tests/VERSION/ExpectedFiles.cmake3
-rw-r--r--Tests/RunCMake/CPack/tests/VERSION/VerifyResult.cmake17
-rw-r--r--Tests/RunCMake/CPack/tests/VERSION/test.cmake14
151 files changed, 3189 insertions, 0 deletions
diff --git a/Tests/RunCMake/CPack/7Z/Helpers.cmake b/Tests/RunCMake/CPack/7Z/Helpers.cmake
new file mode 100644
index 0000000..f256a42
--- /dev/null
+++ b/Tests/RunCMake/CPack/7Z/Helpers.cmake
@@ -0,0 +1,3 @@
+set(cpack_archive_extension_ "7z")
+
+include("${CMAKE_CURRENT_LIST_DIR}/../ArchiveCommon/common_helpers.cmake")
diff --git a/Tests/RunCMake/CPack/7Z/Prerequirements.cmake b/Tests/RunCMake/CPack/7Z/Prerequirements.cmake
new file mode 100644
index 0000000..dbaf682
--- /dev/null
+++ b/Tests/RunCMake/CPack/7Z/Prerequirements.cmake
@@ -0,0 +1,4 @@
+function(get_test_prerequirements found_var config_file)
+ file(WRITE "${config_file}" "")
+ set(${found_var} true PARENT_SCOPE)
+endfunction()
diff --git a/Tests/RunCMake/CPack/7Z/packaging_COMPONENT_default.cmake b/Tests/RunCMake/CPack/7Z/packaging_COMPONENT_default.cmake
new file mode 100644
index 0000000..81a5035
--- /dev/null
+++ b/Tests/RunCMake/CPack/7Z/packaging_COMPONENT_default.cmake
@@ -0,0 +1 @@
+set(CPACK_ARCHIVE_COMPONENT_INSTALL "ON")
diff --git a/Tests/RunCMake/CPack/ArchiveCommon/common_helpers.cmake b/Tests/RunCMake/CPack/ArchiveCommon/common_helpers.cmake
new file mode 100644
index 0000000..948c6ab
--- /dev/null
+++ b/Tests/RunCMake/CPack/ArchiveCommon/common_helpers.cmake
@@ -0,0 +1,71 @@
+set(ALL_FILES_GLOB "*.${cpack_archive_extension_}")
+
+function(getPackageContent FILE RESULT_VAR)
+ # TODO for some types this only works because libarchive handles it... (not
+ # part of for e.g. gnu tar)
+ execute_process(COMMAND ${CMAKE_COMMAND} -E tar -xtf ${FILE}
+ OUTPUT_VARIABLE package_content_
+ ERROR_QUIET
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+ set(${RESULT_VAR} "${package_content_}" PARENT_SCOPE)
+endfunction()
+
+function(getPackageNameGlobexpr NAME COMPONENT VERSION REVISION FILE_NO RESULT_VAR)
+ if(COMPONENT)
+ set(COMPONENT "-${COMPONENT}")
+ endif()
+
+ set(${RESULT_VAR}
+ "${NAME}-${VERSION}-*${COMPONENT}.${cpack_archive_extension_}" PARENT_SCOPE)
+endfunction()
+
+function(getPackageContentList FILE RESULT_VAR)
+ getPackageContent("${FILE}" package_content_)
+
+ string(REPLACE "\n" ";" package_content_ "${package_content_}")
+ foreach(i_ IN LISTS package_content_)
+ string(REGEX REPLACE "/$" "" result_ "${i_}")
+ list(APPEND items_ "${result_}")
+ endforeach()
+
+ set(${RESULT_VAR} "${items_}" PARENT_SCOPE)
+endfunction()
+
+function(toExpectedContentList FILE_NO CONTENT_VAR)
+ findExpectedFile("${FILE_NO}" "file_" "glob_expr_")
+
+ # component and monolithic packages differ for some reason by either having
+ # package filename prefix in path or not
+ if(PACKAGING_TYPE STREQUAL "MONOLITHIC")
+ get_filename_component(prefix_ "${file_}" NAME)
+ # NAME_WE removes everything after the dot and dot is in version so replace instead
+ string(REPLACE ".${cpack_archive_extension_}" "/" prefix_ "${prefix_}")
+ else()
+ unset(prefix_)
+ endif()
+
+ # add install prefix to expected paths
+ if(DEFINED EXPECTED_FILE_${FILE_NO}_PACKAGING_PREFIX)
+ set(EXPECTED_FILE_PACKAGING_PREFIX
+ "${EXPECTED_FILE_${FILE_NO}_PACKAGING_PREFIX}")
+ elseif(NOT DEFINED EXPECTED_FILE_PACKAGING_PREFIX)
+ # default CPack Archive packaging install prefix
+ set(EXPECTED_FILE_PACKAGING_PREFIX "/")
+ endif()
+ set(prepared_ "${EXPECTED_FILE_PACKAGING_PREFIX}")
+ foreach(part_ IN LISTS ${CONTENT_VAR})
+ list(APPEND prepared_ "${EXPECTED_FILE_PACKAGING_PREFIX}${part_}")
+ endforeach()
+
+ unset(filtered_)
+ foreach(part_ IN LISTS prepared_)
+ string(REGEX REPLACE "^/" "" part_ "${part_}")
+
+ if(part_)
+ list(APPEND filtered_ "${prefix_}${part_}")
+ endif()
+ endforeach()
+
+ set(${CONTENT_VAR} "${filtered_}" PARENT_SCOPE)
+endfunction()
diff --git a/Tests/RunCMake/CPack/CMakeLists.txt b/Tests/RunCMake/CPack/CMakeLists.txt
new file mode 100644
index 0000000..1b3dbb2
--- /dev/null
+++ b/Tests/RunCMake/CPack/CMakeLists.txt
@@ -0,0 +1,21 @@
+cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
+
+set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "")
+
+project(${RunCMake_TEST} CXX)
+
+if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${GENERATOR_TYPE}/packaging_${PACKAGING_TYPE}_default.cmake")
+ include(${GENERATOR_TYPE}/packaging_${PACKAGING_TYPE}_default.cmake)
+endif()
+
+# set default test name (can be overwritten in test.cmake or specifics.cmake)
+string(TOLOWER "${RunCMake_TEST_FILE_PREFIX}" CPACK_PACKAGE_NAME)
+
+include(tests/${RunCMake_TEST_FILE_PREFIX}/test.cmake)
+
+set(CPACK_GENERATOR "${GENERATOR_TYPE}")
+include(CPack)
+
+if(COMMAND run_after_include_cpack)
+ run_after_include_cpack()
+endif()
diff --git a/Tests/RunCMake/CPack/CPackTestHelpers.cmake b/Tests/RunCMake/CPack/CPackTestHelpers.cmake
new file mode 100644
index 0000000..24f54c6
--- /dev/null
+++ b/Tests/RunCMake/CPack/CPackTestHelpers.cmake
@@ -0,0 +1,151 @@
+cmake_policy(SET CMP0057 NEW)
+
+function(run_cpack_test_common_ TEST_NAME types build SUBTEST_SUFFIX source PACKAGING_TYPE package_target)
+ if(TEST_TYPE IN_LIST types)
+ string(REGEX MATCH "^[^.]*" GENERATOR_TYPE "${TEST_TYPE}")
+ set(RunCMake_TEST_NO_CLEAN TRUE)
+ if(package_target)
+ set(full_test_name_ "${TEST_NAME}-package-target")
+ else()
+ set(full_test_name_ "${TEST_NAME}")
+ endif()
+ set(RunCMake_TEST_BINARY_DIR "${RunCMake_BINARY_DIR}/${full_test_name_}-build")
+
+ if(SUBTEST_SUFFIX)
+ set(RunCMake_TEST_BINARY_DIR "${RunCMake_TEST_BINARY_DIR}-${SUBTEST_SUFFIX}-subtest")
+ set(full_test_name_ "${full_test_name_}-${SUBTEST_SUFFIX}-subtest")
+ endif()
+
+ string(APPEND full_test_name_ "-${PACKAGING_TYPE}-type")
+
+ # TODO this should be executed only once per ctest run (not per generator)
+ file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
+ file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
+
+ if(EXISTS "${RunCMake_SOURCE_DIR}/tests/${TEST_NAME}/${GENERATOR_TYPE}-Prerequirements.cmake")
+ include("${RunCMake_SOURCE_DIR}/tests/${TEST_NAME}/${GENERATOR_TYPE}-Prerequirements.cmake")
+
+ set(FOUND_PREREQUIREMENTS false)
+ get_test_prerequirements("FOUND_PREREQUIREMENTS" "${config_file}")
+
+ # skip the test if prerequirements are not met
+ if(NOT FOUND_PREREQUIREMENTS)
+ message(STATUS "${TEST_NAME} - SKIPPED")
+ return()
+ endif()
+ endif()
+
+ # execute cmake
+ set(RunCMake_TEST_OPTIONS "-DGENERATOR_TYPE=${GENERATOR_TYPE}"
+ "-DRunCMake_TEST_FILE_PREFIX=${TEST_NAME}"
+ "-DRunCMake_SUBTEST_SUFFIX=${SUBTEST_SUFFIX}"
+ "-DPACKAGING_TYPE=${PACKAGING_TYPE}")
+
+ foreach(o out err)
+ if(SUBTEST_SUFFIX AND EXISTS ${RunCMake_SOURCE_DIR}/tests/${TEST_NAME}/configure-${PACKAGING_TYPE}-${SUBTEST_SUFFIX}-std${o}.txt)
+ set(RunCMake-std${o}-file "tests/${TEST_NAME}/configure-${PACKAGING_TYPE}-${SUBTEST_SUFFIX}-std${o}.txt")
+ elseif(SUBTEST_SUFFIX AND EXISTS ${RunCMake_SOURCE_DIR}/tests/${TEST_NAME}/configure-${SUBTEST_SUFFIX}-std${o}.txt)
+ set(RunCMake-std${o}-file "tests/${TEST_NAME}/configure-${SUBTEST_SUFFIX}-std${o}.txt")
+ elseif(EXISTS ${RunCMake_SOURCE_DIR}/tests/${TEST_NAME}/configure-${PACKAGING_TYPE}-std${o}.txt)
+ set(RunCMake-std${o}-file "tests/${TEST_NAME}/configure-${PACKAGING_TYPE}-std${o}.txt")
+ elseif(EXISTS ${RunCMake_SOURCE_DIR}/tests/${TEST_NAME}/configure-std${o}.txt)
+ set(RunCMake-std${o}-file "tests/${TEST_NAME}/configure-std${o}.txt")
+ else()
+ unset(RunCMake-std${o}-file)
+ endif()
+ endforeach()
+
+ run_cmake(${full_test_name_})
+
+ # execute optional build step
+ if(build)
+ unset(RunCMake-stdout-file)
+ unset(RunCMake-stderr-file)
+ run_cmake_command(${full_test_name_}-Build "${CMAKE_COMMAND}" --build "${RunCMake_TEST_BINARY_DIR}")
+ endif()
+
+ if(source)
+ set(pack_params_ -G ${GENERATOR_TYPE} --config ./CPackSourceConfig.cmake)
+ FILE(APPEND ${RunCMake_TEST_BINARY_DIR}/CPackSourceConfig.cmake
+ "\nset(CPACK_RPM_SOURCE_PKG_BUILD_PARAMS \"-DRunCMake_TEST:STRING=${full_test_name_} -DRunCMake_TEST_FILE_PREFIX:STRING=${TEST_NAME} -DGENERATOR_TYPE:STRING=${GENERATOR_TYPE}\")")
+ else()
+ unset(pack_params_)
+ endif()
+
+ if(package_target)
+ set(cpack_command_ ${CMAKE_COMMAND} --build "${RunCMake_TEST_BINARY_DIR}" --target package)
+ else()
+ set(cpack_command_ ${CMAKE_CPACK_COMMAND} ${pack_params_} -C Debug)
+ endif()
+
+ # execute cpack
+ set(SETENV)
+ if(ENVIRONMENT)
+ set(SETENV ${CMAKE_COMMAND} -E env "${ENVIRONMENT}")
+ endif()
+ execute_process(
+ COMMAND ${SETENV} ${cpack_command_}
+ WORKING_DIRECTORY "${RunCMake_TEST_BINARY_DIR}"
+ RESULT_VARIABLE "result_"
+ OUTPUT_FILE "${RunCMake_TEST_BINARY_DIR}/test_output.txt"
+ ERROR_FILE "${RunCMake_TEST_BINARY_DIR}/test_error.txt"
+ )
+
+ foreach(o out err)
+ if(SUBTEST_SUFFIX AND EXISTS ${RunCMake_SOURCE_DIR}/tests/${TEST_NAME}/${GENERATOR_TYPE}-${PACKAGING_TYPE}-${SUBTEST_SUFFIX}-std${o}.txt)
+ set(RunCMake-std${o}-file "tests/${TEST_NAME}/${GENERATOR_TYPE}-${PACKAGING_TYPE}-${SUBTEST_SUFFIX}-std${o}.txt")
+ elseif(EXISTS ${RunCMake_SOURCE_DIR}/tests/${TEST_NAME}/${GENERATOR_TYPE}-${PACKAGING_TYPE}-std${o}.txt)
+ set(RunCMake-std${o}-file "tests/${TEST_NAME}/${GENERATOR_TYPE}-${PACKAGING_TYPE}-std${o}.txt")
+ elseif(SUBTEST_SUFFIX AND EXISTS ${RunCMake_SOURCE_DIR}/tests/${TEST_NAME}/${GENERATOR_TYPE}-${SUBTEST_SUFFIX}-std${o}.txt)
+ set(RunCMake-std${o}-file "tests/${TEST_NAME}/${GENERATOR_TYPE}-${SUBTEST_SUFFIX}-std${o}.txt")
+ elseif(EXISTS ${RunCMake_SOURCE_DIR}/tests/${TEST_NAME}/${GENERATOR_TYPE}-std${o}.txt)
+ set(RunCMake-std${o}-file "tests/${TEST_NAME}/${GENERATOR_TYPE}-std${o}.txt")
+ elseif(SUBTEST_SUFFIX AND EXISTS ${RunCMake_SOURCE_DIR}/tests/${TEST_NAME}/${SUBTEST_SUFFIX}-std${o}.txt)
+ set(RunCMake-std${o}-file "tests/${TEST_NAME}/${SUBTEST_SUFFIX}-std${o}.txt")
+ elseif(EXISTS ${RunCMake_SOURCE_DIR}/${GENERATOR_TYPE}/default_expected_std${o}.txt)
+ set(RunCMake-std${o}-file "${GENERATOR_TYPE}/default_expected_std${o}.txt")
+ else()
+ unset(RunCMake-std${o}-file)
+ endif()
+ endforeach()
+
+ # verify result
+ run_cmake_command(
+ ${GENERATOR_TYPE}/${full_test_name_}
+ "${CMAKE_COMMAND}"
+ -DRunCMake_TEST=${full_test_name_}
+ -DRunCMake_TEST_FILE_PREFIX=${TEST_NAME}
+ -DRunCMake_SUBTEST_SUFFIX=${SUBTEST_SUFFIX}
+ -DGENERATOR_TYPE=${GENERATOR_TYPE}
+ -DPACKAGING_TYPE=${PACKAGING_TYPE}
+ "-Dsrc_dir=${RunCMake_SOURCE_DIR}"
+ "-Dbin_dir=${RunCMake_TEST_BINARY_DIR}"
+ "-Dconfig_file=${config_file}"
+ -P "${RunCMake_SOURCE_DIR}/VerifyResult.cmake"
+ )
+ endif()
+endfunction()
+
+function(run_cpack_test TEST_NAME types build PACKAGING_TYPES)
+ foreach(packaging_type_ IN LISTS PACKAGING_TYPES)
+ run_cpack_test_common_("${TEST_NAME}" "${types}" "${build}" "" false "${packaging_type_}" false)
+ endforeach()
+endfunction()
+
+function(run_cpack_test_package_target TEST_NAME types build PACKAGING_TYPES)
+ foreach(packaging_type_ IN LISTS PACKAGING_TYPES)
+ run_cpack_test_common_("${TEST_NAME}" "${types}" "${build}" "" false "${packaging_type_}" true)
+ endforeach()
+endfunction()
+
+function(run_cpack_test_subtests TEST_NAME SUBTEST_SUFFIXES types build PACKAGING_TYPES)
+ foreach(suffix_ IN LISTS SUBTEST_SUFFIXES)
+ foreach(packaging_type_ IN LISTS PACKAGING_TYPES)
+ run_cpack_test_common_("${TEST_NAME}" "${types}" "${build}" "${suffix_}" false "${packaging_type_}" false)
+ endforeach()
+ endforeach()
+endfunction()
+
+function(run_cpack_source_test TEST_NAME types)
+ run_cpack_test_common_("${TEST_NAME}" "${types}" false "" true "" false)
+endfunction()
diff --git a/Tests/RunCMake/CPack/DEB/Helpers.cmake b/Tests/RunCMake/CPack/DEB/Helpers.cmake
new file mode 100644
index 0000000..9b98ed4
--- /dev/null
+++ b/Tests/RunCMake/CPack/DEB/Helpers.cmake
@@ -0,0 +1,176 @@
+set(ALL_FILES_GLOB "*.deb" "*.ddeb")
+
+function(getPackageContent FILE RESULT_VAR)
+ execute_process(COMMAND ${CMAKE_COMMAND} -E env TZ=Etc/UTC ${DPKG_EXECUTABLE} -c "${FILE}"
+ OUTPUT_VARIABLE package_content_
+ ERROR_QUIET
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+ set(${RESULT_VAR} "${package_content_}" PARENT_SCOPE)
+endfunction()
+
+function(getPackageNameGlobexpr NAME COMPONENT VERSION REVISION FILE_NO RESULT_VAR)
+ if(COMPONENT)
+ set(COMPONENT "-${COMPONENT}")
+ endif()
+
+ if(DEFINED EXPECTED_FILE_${FILE_NO}_FILENAME_GENERATOR_SPECIFIC_FORMAT)
+ set(GENERATOR_SPECIFIC_FORMAT "${EXPECTED_FILE_${FILE_NO}_FILENAME_GENERATOR_SPECIFIC_FORMAT}")
+ elseif(DEFINED EXPECTED_FILES_NAME_GENERATOR_SPECIFIC_FORMAT)
+ set(GENERATOR_SPECIFIC_FORMAT "${EXPECTED_FILES_NAME_GENERATOR_SPECIFIC_FORMAT}")
+ else()
+ set(GENERATOR_SPECIFIC_FORMAT FALSE)
+ endif()
+
+ if(GENERATOR_SPECIFIC_FORMAT)
+ set(${RESULT_VAR} "${NAME}${COMPONENT}_${VERSION}_*.deb" PARENT_SCOPE)
+ else()
+ set(${RESULT_VAR} "${NAME}-${VERSION}-*${COMPONENT}.deb" PARENT_SCOPE)
+ endif()
+endfunction()
+
+function(getPackageContentList FILE RESULT_VAR)
+ execute_process(COMMAND ${DPKG_EXECUTABLE} -c "${FILE}"
+ OUTPUT_VARIABLE package_content_
+ ERROR_QUIET
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+ unset(items_)
+ string(REPLACE "\n" ";" package_content_ "${package_content_}")
+ foreach(i_ IN LISTS package_content_)
+ string(REGEX REPLACE "^.* \.(/[^$]*)$" "\\1" result_ "${i_}")
+ string(REGEX REPLACE "/$" "" result_ "${result_}")
+ list(APPEND items_ "${result_}")
+ endforeach()
+
+ set(${RESULT_VAR} "${items_}" PARENT_SCOPE)
+endfunction()
+
+function(toExpectedContentList FILE_NO CONTENT_VAR)
+ # add install prefix to expected paths
+ if(DEFINED EXPECTED_FILE_${FILE_NO}_PACKAGING_PREFIX)
+ set(EXPECTED_FILE_PACKAGING_PREFIX
+ "${EXPECTED_FILE_${FILE_NO}_PACKAGING_PREFIX}")
+ elseif(NOT DEFINED EXPECTED_FILE_PACKAGING_PREFIX)
+ # default CPackDeb packaging install prefix
+ set(EXPECTED_FILE_PACKAGING_PREFIX "/usr")
+ endif()
+ set(prepared_ "${EXPECTED_FILE_PACKAGING_PREFIX}")
+ foreach(part_ IN LISTS ${CONTENT_VAR})
+ list(APPEND prepared_ "${EXPECTED_FILE_PACKAGING_PREFIX}${part_}")
+ endforeach()
+
+ set(${CONTENT_VAR} "${prepared_}" PARENT_SCOPE)
+endfunction()
+
+function(getMissingShlibsErrorExtra FILE RESULT_VAR)
+ execute_process(COMMAND ${DPKG_EXECUTABLE} -x "${FILE}" data_${PREFIX}
+ ERROR_VARIABLE err_)
+
+ if(err_)
+ set(error_extra " Extra: Could not unpack package content: '${err}'")
+ else()
+ cmake_policy(PUSH)
+ # Tell file(GLOB_RECURSE) not to follow directory symlinks
+ # even if the project does not set this policy to NEW.
+ cmake_policy(SET CMP0009 NEW)
+ file(GLOB_RECURSE FILE_PATHS_ LIST_DIRECTORIES false "${CMAKE_CURRENT_BINARY_DIR}/data_${PREFIX}/*")
+ cmake_policy(POP)
+
+ # get file info so that we can determine if file is executable or not
+ foreach(FILE_ IN LISTS FILE_PATHS_)
+ execute_process(COMMAND file "${FILE_}"
+ WORKING_DIRECTORY "${WDIR}"
+ OUTPUT_VARIABLE INSTALL_FILE_
+ ERROR_VARIABLE err_)
+
+ if(NOT err_)
+ list(APPEND deb_install_files "${INSTALL_FILE_}")
+ else()
+ list(APPEND deb_install_files_errors "'${FILE_}': '${err_}'\n")
+ endif()
+ endforeach()
+
+ set(error_extra " Extra: install files '${deb_install_files}'")
+
+ if(deb_install_files_errors)
+ string(APPEND error_extra "; errors \"${deb_install_files_errors}\"")
+ endif()
+
+ if(READELF_EXECUTABLE)
+ string(APPEND error_extra "; readelf \"\n")
+
+ # Only dynamically linked ELF files are included
+ # Extract only file name infront of ":"
+ foreach(_FILE IN LISTS deb_install_files)
+ if(_FILE MATCHES "ELF.*shared object")
+ string(REGEX MATCH "(^.*):" _FILE_NAME "${_FILE}")
+
+ execute_process(COMMAND ${READELF_EXECUTABLE} -d "${CMAKE_MATCH_1}"
+ WORKING_DIRECTORY "${CPACK_TEMPORARY_DIRECTORY}"
+ RESULT_VARIABLE result
+ OUTPUT_VARIABLE output
+ ERROR_VARIABLE err_
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+ string(APPEND error_extra " name '${CMAKE_MATCH_1}'\n result '${result}'\n output '${output}'\n error '${err_}'\n")
+ endif()
+ endforeach()
+
+ string(APPEND error_extra "\"")
+ else()
+ string(APPEND error_extra "; error readelf missing")
+ endif()
+ endif()
+
+ set(${RESULT_VAR} "${error_extra}" PARENT_SCOPE)
+endfunction()
+
+function(verifyDebControl FILE PREFIX VERIFY_FILES)
+ execute_process(COMMAND ${DPKG_EXECUTABLE} --control "${FILE}" control_${PREFIX}
+ ERROR_VARIABLE err_)
+
+ if(err_)
+ message(FATAL_ERROR "Debian control verification failed for file: "
+ "'${FILE}'; error output: '${err_}'")
+ endif()
+
+ foreach(FILE_ IN LISTS VERIFY_FILES)
+ if(NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}/control_${PREFIX}/${FILE_}")
+ if(FILE_ STREQUAL "shlibs")
+ getMissingShlibsErrorExtra("${FILE}" error_extra)
+ endif()
+
+ message(FATAL_ERROR "Expected Debian control file does not exist: '${FILE_}'${error_extra}")
+ endif()
+
+ file(READ "${CMAKE_CURRENT_BINARY_DIR}/control_${PREFIX}/${FILE_}" content_)
+ if(NOT content_ MATCHES "${${PREFIX}_${FILE_}}")
+ message(FATAL_ERROR "Unexpected content in for '${PREFIX}_${FILE_}'!"
+ " Content: '${content_}'")
+ endif()
+
+ execute_process(COMMAND ls -l "${CMAKE_CURRENT_BINARY_DIR}/control_${PREFIX}/${FILE_}"
+ OUTPUT_VARIABLE package_permissions_
+ ERROR_VARIABLE package_permissions_error_
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+ if(NOT package_permissions_error_)
+ if(NOT package_permissions_ MATCHES "${${PREFIX}_${FILE_}_permissions_regex}")
+ message(FATAL_ERROR "Unexpected file permissions for ${PREFIX}_${FILE_}: '${package_permissions_}'!")
+ endif()
+ else()
+ message(FATAL_ERROR "Listing file permissions failed (${package_permissions_error_})!")
+ endif()
+ endforeach()
+endfunction()
+
+function(getPackageInfo FILE RESULT_VAR)
+ execute_process(COMMAND ${DPKG_EXECUTABLE} -I ${FILE}
+ WORKING_DIRECTORY "${CPACK_TEMPORARY_DIRECTORY}"
+ OUTPUT_VARIABLE package_info_
+ ERROR_QUIET
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+ set(${RESULT_VAR} "${package_info_}" PARENT_SCOPE)
+endfunction()
diff --git a/Tests/RunCMake/CPack/DEB/Prerequirements.cmake b/Tests/RunCMake/CPack/DEB/Prerequirements.cmake
new file mode 100644
index 0000000..60d02e7
--- /dev/null
+++ b/Tests/RunCMake/CPack/DEB/Prerequirements.cmake
@@ -0,0 +1,22 @@
+function(get_test_prerequirements found_var config_file)
+ find_program(DPKG_EXECUTABLE dpkg)
+
+ if(DPKG_EXECUTABLE)
+ file(WRITE "${config_file}" "set(DPKG_EXECUTABLE \"${DPKG_EXECUTABLE}\")")
+ set(${found_var} true PARENT_SCOPE)
+ endif()
+
+ # optional tool for some tests
+ find_program(FAKEROOT_EXECUTABLE fakeroot)
+ if(FAKEROOT_EXECUTABLE)
+ file(APPEND "${config_file}"
+ "\nset(FAKEROOT_EXECUTABLE \"${FAKEROOT_EXECUTABLE}\")")
+ endif()
+
+ # optional tool for some tests
+ find_program(READELF_EXECUTABLE NAMES readelf)
+ if(READELF_EXECUTABLE)
+ file(APPEND "${config_file}"
+ "\nset(READELF_EXECUTABLE \"${READELF_EXECUTABLE}\")")
+ endif()
+endfunction()
diff --git a/Tests/RunCMake/CPack/DEB/packaging_COMPONENT_default.cmake b/Tests/RunCMake/CPack/DEB/packaging_COMPONENT_default.cmake
new file mode 100644
index 0000000..4219b0c
--- /dev/null
+++ b/Tests/RunCMake/CPack/DEB/packaging_COMPONENT_default.cmake
@@ -0,0 +1,2 @@
+set(CPACK_DEB_COMPONENT_INSTALL "ON")
+set(CPACK_PACKAGE_CONTACT "someone")
diff --git a/Tests/RunCMake/CPack/DEB/packaging_MONOLITHIC_default.cmake b/Tests/RunCMake/CPack/DEB/packaging_MONOLITHIC_default.cmake
new file mode 100644
index 0000000..8821ab9
--- /dev/null
+++ b/Tests/RunCMake/CPack/DEB/packaging_MONOLITHIC_default.cmake
@@ -0,0 +1 @@
+set(CPACK_PACKAGE_CONTACT "someone")
diff --git a/Tests/RunCMake/CPack/DragNDrop/Helpers.cmake b/Tests/RunCMake/CPack/DragNDrop/Helpers.cmake
new file mode 100644
index 0000000..023e597
--- /dev/null
+++ b/Tests/RunCMake/CPack/DragNDrop/Helpers.cmake
@@ -0,0 +1,54 @@
+set(ALL_FILES_GLOB "*.dmg")
+
+function(getPackageContent FILE RESULT_VAR)
+ get_filename_component(path_ "${FILE}" DIRECTORY)
+ file(REMOVE_RECURSE "${path_}/content")
+ file(MAKE_DIRECTORY "${path_}/content")
+ execute_process(COMMAND ${HDIUTIL_EXECUTABLE} attach -mountroot ${path_}/content -nobrowse ${FILE}
+ RESULT_VARIABLE attach_result_
+ ERROR_VARIABLE attach_error_
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+ if(attach_result_)
+ message(FATAL_ERROR "Failed to attach DMG: '${attach_result_}';"
+ " '${attach_error_}'.")
+ endif()
+
+ file(GLOB_RECURSE package_content_ LIST_DIRECTORIES true RELATIVE
+ "${path_}/content" "${path_}/content/*")
+ # Some versions of macOS have .Trashes, others do not.
+ list(FILTER package_content_ EXCLUDE REGEX "/.Trashes$")
+ set(${RESULT_VAR} "${package_content_}" PARENT_SCOPE)
+
+ execute_process(COMMAND ${HDIUTIL_EXECUTABLE} detach ${path_}/content/volume-name
+ RESULT_VARIABLE detach_result_
+ ERROR_VARIABLE detach_error_
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+ if(detach_result_)
+ message(FATAL_ERROR "Failed to detach DMG: '${detach_result_}';"
+ " '${detach_error_}'.")
+ endif()
+endfunction()
+
+function(getPackageNameGlobexpr NAME COMPONENT VERSION REVISION FILE_NO RESULT_VAR)
+ if(COMPONENT)
+ set(COMPONENT "-${COMPONENT}")
+ endif()
+
+ set(${RESULT_VAR} "${NAME}-${VERSION}-Darwin${COMPONENT}.dmg" PARENT_SCOPE)
+endfunction()
+
+function(getPackageContentList FILE RESULT_VAR)
+ getPackageContent("${FILE}" package_content_)
+
+ set(${RESULT_VAR} "${package_content_}" PARENT_SCOPE)
+endfunction()
+
+function(toExpectedContentList FILE_NO CONTENT_VAR)
+ set(prefix_ "volume-name")
+ list(TRANSFORM ${CONTENT_VAR} PREPEND "${prefix_}" OUTPUT_VARIABLE prepared_)
+ list(APPEND prepared_ "${prefix_}")
+
+ set(${CONTENT_VAR} "${prepared_}" PARENT_SCOPE)
+endfunction()
diff --git a/Tests/RunCMake/CPack/DragNDrop/Prerequirements.cmake b/Tests/RunCMake/CPack/DragNDrop/Prerequirements.cmake
new file mode 100644
index 0000000..f0aaf2c
--- /dev/null
+++ b/Tests/RunCMake/CPack/DragNDrop/Prerequirements.cmake
@@ -0,0 +1,8 @@
+function(get_test_prerequirements found_var config_file)
+ find_program(HDIUTIL_EXECUTABLE hdiutil)
+
+ if(HDIUTIL_EXECUTABLE)
+ file(WRITE "${config_file}" "set(HDIUTIL_EXECUTABLE \"${HDIUTIL_EXECUTABLE}\")")
+ set(${found_var} true PARENT_SCOPE)
+ endif()
+endfunction()
diff --git a/Tests/RunCMake/CPack/DragNDrop/packaging_COMPONENT_default.cmake b/Tests/RunCMake/CPack/DragNDrop/packaging_COMPONENT_default.cmake
new file mode 100644
index 0000000..aa6c8ff
--- /dev/null
+++ b/Tests/RunCMake/CPack/DragNDrop/packaging_COMPONENT_default.cmake
@@ -0,0 +1,3 @@
+set(CPACK_COMPONENTS_GROUPING "IGNORE")
+set(CPACK_DMG_DISABLE_APPLICATIONS_SYMLINK ON)
+set(CPACK_DMG_VOLUME_NAME "volume-name")
diff --git a/Tests/RunCMake/CPack/External/Helpers.cmake b/Tests/RunCMake/CPack/External/Helpers.cmake
new file mode 100644
index 0000000..2c67e06
--- /dev/null
+++ b/Tests/RunCMake/CPack/External/Helpers.cmake
@@ -0,0 +1,31 @@
+function(getPackageNameGlobexpr NAME COMPONENT VERSION REVISION FILE_NO RESULT_VAR)
+ set(${RESULT_VAR} "${NAME}-${VERSION}-*.json" PARENT_SCOPE)
+endfunction()
+
+function(getPackageContentList FILE RESULT_VAR)
+ set("${RESULT_VAR}" "" PARENT_SCOPE)
+endfunction()
+
+function(toExpectedContentList FILE_NO CONTENT_VAR)
+ set("${CONTENT_VAR}" "" PARENT_SCOPE)
+endfunction()
+
+set(ALL_FILES_GLOB "*.json")
+
+function(check_ext_json EXPECTED_FILE ACTUAL_FILE)
+ file(READ "${EXPECTED_FILE}" _expected_regex)
+ file(READ "${ACTUAL_FILE}" _actual_contents)
+
+ string(REGEX REPLACE "\n+$" "" _expected_regex "${_expected_regex}")
+ string(REGEX REPLACE "\n+$" "" _actual_contents "${_actual_contents}")
+
+ if(NOT "${_actual_contents}" MATCHES "${_expected_regex}")
+ message(FATAL_ERROR
+ "Output JSON does not match expected regex.\n"
+ "Expected regex:\n"
+ "${_expected_regex}\n"
+ "Actual output:\n"
+ "${_actual_contents}\n"
+ )
+ endif()
+endfunction()
diff --git a/Tests/RunCMake/CPack/External/Prerequirements.cmake b/Tests/RunCMake/CPack/External/Prerequirements.cmake
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Tests/RunCMake/CPack/External/Prerequirements.cmake
diff --git a/Tests/RunCMake/CPack/README.txt b/Tests/RunCMake/CPack/README.txt
new file mode 100644
index 0000000..2165125
--- /dev/null
+++ b/Tests/RunCMake/CPack/README.txt
@@ -0,0 +1,256 @@
+RunCMake.CPack is a test module that is intended for testing of package
+generators that can be validated from command line.
+
+-------------
+Adding a test
+-------------
+
+CPack test root directory: 'Tests/RunCMake/CPack/tests'.
+
+All phases are executed separately for each generator that is bound to a test.
+Tests for each generator are subtests of test 'RunCMake.CPack_<generator_name>'.
+
+Each test must also be added to 'RunCMakeTest.cmake' script located in CPack
+test root directory.
+
+Line that adds a test is:
+run_cpack_test(<test_name> "<generator_name_list>" <compile_stage>
+ "<packaging_type_list>")
+
+<generator_name_list> may be one generator e.g. "RPM" or multiple e.g. "RPM;DEB"
+and will be run for all listed generators. In test and verification scripts
+current generator can be accessed through GENERATOR_TYPE variable.
+
+<compile_stage> is a boolean variable that enables or disables compile stage -
+most tests don't require compilation as a non binary file can be used for
+package content but sometimes an executable or a library has to be created
+before the packaging stage.
+
+<packaging_type_list> can be a list of one or more packaging types: MONOLITHIC,
+COMPONENT or GROUP - each type sets per generator default variables which can
+be overwritten in the test if needed
+(see <generator_type>/packaging_<packaging_type>_default.cmake for the variables
+that are set by default for each packaging type).
+Alternatively CUSTOM value can be set which means that default values will not
+be set and that values will be set manually in the test itself.
+
+Alternatively a test with subtests can be added:
+run_cpack_test_subtests(<test_name> "<subtests_list>" "<generator_name_list>"
+ <compile_stage> "<packaging_type_list>")
+
+<subtests_list> is the only new parameter and it is a list of names that will
+be used for subtests. In test and verification scripts subtest name can be
+accessed through RunCMake_SUBTEST_SUFFIX variable.
+
+Also source package tests can be added:
+run_cpack_source_test(<test_name> "<generator_name_list>" true)
+
+Test consists of
+- test prerequirements phase (optional)
+- CMake execution phase
+- build phase (optional and not available for source package tests)
+- CPack execution phase
+- verification of generated files
+
+The phases are executed once per specified generator, packaging type and subtest
+combinatiion.
+
+test prerequirements phase (optional):
+--------------------------------------
+
+In some cases individual tests for certain generator need additional
+prerequirements met.
+
+In such cases '<test_name>/<generator_name>-Prerequirements.cmake' file
+containing 'function(get_test_prerequirements found_var config_file)' should be
+created. Function should return true in found_var if all prerequirements are
+met. config_file variable contains the location of config file generated by the
+generator so that this function can check if prerequired variable is set in the
+file.
+NOTE: All required programs should be searched for in generator prerequirements
+function and only checked for the variable in configure file in per test
+function.
+
+If prerequirements are not met test will be skipped outputting
+'<test_name> - SKIPPED' string. Note that this doesn't fail the entire test
+group.
+
+TODO: skipped tests should provide expected error string so test should fail
+ if error string is not found in the output of run test (this would add
+ 'EXPECTED FAIL' string on success and 'ERROR' on failure).
+
+CMake execution phase:
+----------------------
+
+To add a new CPack test we first create a '<test_name>/test.cmake' script that
+contains CMake commands that should be used as a preparation script for
+generation of different types of packages. This script is placed into CPack
+test root directory.
+
+If test will be used for multiple generators but some of them require some
+generator specific commands then those commands should be added to 'test.cmake'
+script wrapped with 'if(GENERATOR_TYPE STREQUAL <name_of_the_generator>)'.
+
+NOTE: In some cases (for example when testing CPackComponent.cmake functions)
+the test has to run some functions after CPack.cmake is included. In such cases
+a function run_after_include_cpack can be declared in test.cmake file and that
+function will run after the inclusion of CPack.cmake.
+
+NOTE: During CMake configure stage developer warnings may be expected. In such
+cases an expected output regular expression can be provided by creating
+'<test_name>/configure-stdout.txt' and/or '<test_name>/configure-stderr.txt'
+file. There are also more specialized versions of the file available:
+- configure-${PACKAGING_TYPE}-${SUBTEST_SUFFIX}-std${o}.txt
+- configure-${SUBTEST_SUFFIX}-std${o}.txt
+- configure-${PACKAGING_TYPE}-std${o}.txt
+
+build phase (optional and not available for source package tests)
+-----------------------------------------------------------------
+
+This phase only runs make command.
+
+NOTE: By default all tests have CMAKE_BUILD_TYPE variable set to Debug.
+
+CPack execution phase:
+----------------------
+
+Only executes CPack for content that was generated during CMake execution
+phase.
+
+NOTE: By default CPACK_PACKAGE_NAME variable is set to lower case test name.
+
+Verification of generated files:
+--------------------------------
+
+Verification of generated files consists of two phases
+- mandatory verification phase
+- optional verification phase
+
+Mandatory verification phase checks that expected files were generated and
+contain expected files.
+Mandatory verification phase also checks that no other unexpected package files
+were generated (this is executed even if EXPECTED_FILES_COUNT contains 0 in
+order to verify that no files were generated).
+CMake script '<test_name>/ExpectedFiles.cmake' is required by
+this step and must contain
+- EXPECTED_FILES_COUNT variable that contains the number of expected files that
+ will be generated (0 or more)
+
+- EXPECTED_FILE_<file_number_starting_with_1> that contains globing expression
+ that uniquely defines expected file name (will be used to find expected file)
+ and should be present once for each expected file.
+ NOTE: This variable should be used only as last resort as it sets generator
+ specific globbing expression. Each generator can recreate file name from
+ parts that are already populated by default but can always be
+ overwritten if needed:
+ - EXPECTED_FILE_<file_number_starting_with_1>_NAME is the name component of
+ the file (by default it is set to package name that is same as test name
+ in lowercase)
+ - EXPECTED_FILE_<file_number_starting_with_1>_VERSION is the version of the
+ package (by default it is set to '0.1.1')
+ - EXPECTED_FILE_<file_number_starting_with_1>_REVISION is the revision of the
+ package (by default it is set to '1')
+
+- EXPECTED_FILE_CONTENT_<file_number_starting_with_1> that contains regular
+ expression of files that should be present in generated file and should be
+ present once for each expected file
+ NOTE: This variable should be used only as last resort as it sets generator
+ specific regular expression.
+ EXPECTED_FILE_CONTENT_<file_number_starting_with_1>_LIST should be
+ preferred as it requires a list of expected files and directories that
+ is later changed automatically depending on the generator so expected
+ package content can be written only once per test for all generators.
+
+- EXPECTED_FILE_PACKAGING_PREFIX and
+ EXPECTED_FILE_<file_number_starting_with_1>_PACKAGING_PREFIX variables can be
+ set to explicitly specified CPACK_PACKAGING_PREFIX value. By default this
+ variable does not need to be set as it is implicitly set to package generator
+ specific prefix.
+
+Optional verification phase is generator specific and is optionally executed.
+This phase is executed if '<test_name>/VerifyResult.cmake' script exists.
+
+VerifyResult.cmake script also automatically prints out standard output and
+standard error from CPack execution phase that is compared with
+'<test_name>/<generator_name>-stdout.txt' regular expression and
+'<test_name>/<generator_name>-stderr.txt' regular expresson respectively.
+NOTE: For subtests generator name can also be suffixed with subtest name and/or
+ packaging type (MONOLITHIC, COMPONENT, GROUP) and in such cases the
+ preferences of which file will be used are as follows:
+ - generator name + packaging type + subtest name
+ - generator name + packaging type
+ - generator name + subtest name
+ - generator name
+ - subtest name
+ - default generator
+ File name format: '<generator_name>-<packaging_type>-<subtest_name>-std<type>.txt'
+ where <type> can either be 'out' or 'err'.
+ File name format: '<generator_name>-<packaging_type>-std<type>.txt'
+ where <type> can either be 'out' or 'err'.
+ File name format: '<generator_name>-<subtest_name>-std<type>.txt' where
+ <type> can either be 'out' or 'err'.
+NOTE: If none of the comparison files are present then the default generator
+ file is used if present.
+
+----------------------
+Adding a new generator
+----------------------
+
+To add a new generator we must
+- add new generator directory (e.g. RPM for RPM generator) to CPack test root
+ directory that contains 'Helpers.cmake' script.
+ - In this script some functions must exist:
+ - getPackageContent: This function should list files that are contained in
+ a package.
+ Function parameters:
+ + FILE variable that will contain path to file for which the content
+ should be listed
+ + RESULT_VAR that will tell the function which variable in parent scope
+ should contain the result (list of files inside package file)
+ - getPackageNameGlobexpr: This function should generate package name
+ globbing expression.
+ Function parameters:
+ + NAME that will contain the expected package name
+ + COMPONENT that will contain the expected package component
+ + VERSION that will contain the expected package version
+ + REVISION that will contain the expected package revision number
+ + FILE_NO that will contain the file number for which the globbing
+ expression is generated
+ + RESULT_VAR that will tell the function which variable in parent scope
+ should contain the result (file name globbing expression)
+ - getPackageContentList: This function should return a list of files and
+ directories that are in the provided package.
+ Function parameters:
+ + FILE that will contain the package file for which the package content
+ should be returned.
+ + RESULT_VAR that will tell the function which variable in parent scope
+ should contain the result (list of package content)
+ - toExpectedContentList: This function should convert an expected package
+ content list into one that is expected for the
+ generator (e.g. rpm packages have install/relocate
+ path prefixes which aren't part of the package so
+ those paths have to be removed from the expected
+ content list).
+ Function parameters:
+ + FILE_NO that will contain the file number for which the conversion
+ should be performed
+ + CONTENT_VAR that will contain the input list and is also the variable
+ in parent scope which should contain the result (converted content list)
+- add 'Prerequirements.cmake' script to generator directory. In this script a
+ function named 'get_test_prerequirements' must exist. This function should
+ set a variable in parent scope (name of the variable is the first parameter)
+ that tells if prerequirements for test execution are met (certain programs,
+ OS specifics, ...) and create a config file (name of the variable which
+ contains file name and path is provided with the second parameter) that
+ should contain 'set' commands for variables that will later be used in tests
+ (e.g. location of dpkg program for DEB packages)
+- add tests the same way as described above
+- add generator to 'add_RunCMake_test_group' function call that is located in
+ RunCMake CMakeLists.txt file
+- if needed add 'packaging_<packaging_type>_default.cmake' scripts that define
+ default variables that will be set for each packaging type (MONOLITHIC,
+ COMPONENT and GROUP)
+- if needed add 'default_expected_std<type>.txt' files where <type> is either
+ 'out' or 'err' which will contain default expected output of package
+ generation regular expression.
+- add generator to list of other CPack generators in RunCMake/CMakeLists.txt
diff --git a/Tests/RunCMake/CPack/RPM/Helpers.cmake b/Tests/RunCMake/CPack/RPM/Helpers.cmake
new file mode 100644
index 0000000..a29c020
--- /dev/null
+++ b/Tests/RunCMake/CPack/RPM/Helpers.cmake
@@ -0,0 +1,94 @@
+set(ALL_FILES_GLOB "*.rpm")
+
+function(getPackageContent FILE RESULT_VAR)
+ execute_process(COMMAND ${RPM_EXECUTABLE} -pql ${FILE}
+ OUTPUT_VARIABLE package_content_
+ ERROR_QUIET
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+ set(${RESULT_VAR} "${package_content_}" PARENT_SCOPE)
+endfunction()
+
+function(getPackageNameGlobexpr NAME COMPONENT VERSION REVISION FILE_NO RESULT_VAR)
+ if(COMPONENT)
+ set(COMPONENT "-${COMPONENT}")
+ endif()
+
+ if(DEFINED EXPECTED_FILE_${FILE_NO}_FILENAME_GENERATOR_SPECIFIC_FORMAT)
+ set(GENERATOR_SPECIFIC_FORMAT "${EXPECTED_FILE_${FILE_NO}_FILENAME_GENERATOR_SPECIFIC_FORMAT}")
+ elseif(DEFINED EXPECTED_FILES_NAME_GENERATOR_SPECIFIC_FORMAT)
+ set(GENERATOR_SPECIFIC_FORMAT "${EXPECTED_FILES_NAME_GENERATOR_SPECIFIC_FORMAT}")
+ else()
+ set(GENERATOR_SPECIFIC_FORMAT FALSE)
+ endif()
+
+ if(GENERATOR_SPECIFIC_FORMAT)
+ if(NOT REVISION)
+ set(REVISION "1")
+ endif()
+ set(${RESULT_VAR} "${NAME}${COMPONENT}-${VERSION}-${REVISION}.*.rpm" PARENT_SCOPE)
+ else()
+ set(${RESULT_VAR} "${NAME}-${VERSION}-*${COMPONENT}.rpm" PARENT_SCOPE)
+ endif()
+endfunction()
+
+function(getPackageContentList FILE RESULT_VAR)
+ execute_process(COMMAND ${RPM_EXECUTABLE} -pql ${FILE}
+ OUTPUT_VARIABLE package_content_
+ ERROR_QUIET
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+ string(REGEX REPLACE "\n" ";" package_content_ "${package_content_}")
+
+ # never versions of rpmbuild (introduced in rpm 4.13.0.1) add build_id links
+ # to packages - tests should ignore them
+ list(FILTER package_content_ EXCLUDE REGEX ".*\.build-id.*")
+
+ set(${RESULT_VAR} "${package_content_}" PARENT_SCOPE)
+endfunction()
+
+function(toExpectedContentList FILE_NO CONTENT_VAR)
+ # add install prefix to expected paths
+ if(DEFINED EXPECTED_FILE_${FILE_NO}_PACKAGING_PREFIX)
+ set(EXPECTED_FILE_PACKAGING_PREFIX
+ "${EXPECTED_FILE_${FILE_NO}_PACKAGING_PREFIX}")
+ elseif(NOT DEFINED EXPECTED_FILE_PACKAGING_PREFIX)
+ # default CPackRPM packaging install prefix
+ set(EXPECTED_FILE_PACKAGING_PREFIX "/usr")
+ endif()
+ set(prepared_ "${EXPECTED_FILE_PACKAGING_PREFIX}")
+ foreach(part_ IN LISTS ${CONTENT_VAR})
+ list(APPEND prepared_ "${EXPECTED_FILE_PACKAGING_PREFIX}${part_}")
+ endforeach()
+
+ # remove paths that are excluded from auto packaging
+ if(NOT DEFINED CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST)
+ set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST
+ /etc /etc/init.d /usr /usr/bin /usr/include /usr/lib
+ /usr/libx32 /usr/lib64 /usr/share /usr/share/aclocal /usr/share/doc)
+ endif()
+ unset(filtered_)
+ foreach(part_ IN LISTS prepared_)
+ unset(dont_add_)
+ foreach(for_removal_ IN LISTS CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST)
+ if(part_ STREQUAL for_removal_)
+ set(dont_add_ TRUE)
+ break()
+ endif()
+ endforeach()
+
+ if(NOT dont_add_)
+ list(APPEND filtered_ "${part_}")
+ endif()
+ endforeach()
+
+ set(${CONTENT_VAR} "${filtered_}" PARENT_SCOPE)
+endfunction()
+
+function(getPackageInfo FILE RESULT_VAR)
+ execute_process(COMMAND ${RPM_EXECUTABLE} -pqi ${FILE}
+ OUTPUT_VARIABLE info_content
+ ERROR_QUIET
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+ set(${RESULT_VAR} "${info_content}" PARENT_SCOPE)
+endfunction()
diff --git a/Tests/RunCMake/CPack/RPM/Prerequirements.cmake b/Tests/RunCMake/CPack/RPM/Prerequirements.cmake
new file mode 100644
index 0000000..3416205
--- /dev/null
+++ b/Tests/RunCMake/CPack/RPM/Prerequirements.cmake
@@ -0,0 +1,16 @@
+function(get_test_prerequirements found_var config_file)
+ if(CMAKE_CURRENT_BINARY_DIR MATCHES " ")
+ # rpmbuild can't handle spaces in path
+ return()
+ endif()
+
+ find_program(RPM_EXECUTABLE rpm)
+ find_program(RPMBUILD_EXECUTABLE rpmbuild)
+
+ if(RPM_EXECUTABLE AND RPMBUILD_EXECUTABLE)
+ file(WRITE "${config_file}" "set(RPM_EXECUTABLE \"${RPM_EXECUTABLE}\")")
+ file(APPEND "${config_file}"
+ "\nset(RPMBUILD_EXECUTABLE \"${RPMBUILD_EXECUTABLE}\")")
+ set(${found_var} true PARENT_SCOPE)
+ endif()
+endfunction()
diff --git a/Tests/RunCMake/CPack/RPM/default_expected_stderr.txt b/Tests/RunCMake/CPack/RPM/default_expected_stderr.txt
new file mode 100644
index 0000000..6c87ca0
--- /dev/null
+++ b/Tests/RunCMake/CPack/RPM/default_expected_stderr.txt
@@ -0,0 +1 @@
+^(CPackRPM: Will use GENERATED spec file: (/[^/]*)*/Tests/RunCMake/RPM\.[^/]*/CPack/[^-]*(-package-target)?-build((-[^-]*-subtest/)|/)_CPack_Packages/.*/RPM/SPECS/[^\.]*\.spec(\n|$))*$
diff --git a/Tests/RunCMake/CPack/RPM/packaging_COMPONENT_default.cmake b/Tests/RunCMake/CPack/RPM/packaging_COMPONENT_default.cmake
new file mode 100644
index 0000000..c8b93e9
--- /dev/null
+++ b/Tests/RunCMake/CPack/RPM/packaging_COMPONENT_default.cmake
@@ -0,0 +1 @@
+set(CPACK_RPM_COMPONENT_INSTALL "ON")
diff --git a/Tests/RunCMake/CPack/RunCMakeTest.cmake b/Tests/RunCMake/CPack/RunCMakeTest.cmake
new file mode 100644
index 0000000..064b4dc
--- /dev/null
+++ b/Tests/RunCMake/CPack/RunCMakeTest.cmake
@@ -0,0 +1,48 @@
+cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
+
+include(RunCMake)
+include("${RunCMake_SOURCE_DIR}/CPackTestHelpers.cmake")
+
+# run_cpack_test args: TEST_NAME "GENERATORS" RUN_CMAKE_BUILD_STEP "PACKAGING_TYPES"
+run_cpack_test(CUSTOM_BINARY_SPEC_FILE "RPM.CUSTOM_BINARY_SPEC_FILE" false "MONOLITHIC;COMPONENT")
+run_cpack_test(CUSTOM_NAMES "RPM.CUSTOM_NAMES;DEB.CUSTOM_NAMES;TGZ;DragNDrop" true "COMPONENT")
+run_cpack_test(DEBUGINFO "RPM.DEBUGINFO;DEB.DEBUGINFO" true "COMPONENT")
+run_cpack_test_subtests(DEFAULT_PERMISSIONS "CMAKE_var_set;CPACK_var_set;both_set;invalid_CMAKE_var;invalid_CPACK_var" "RPM.DEFAULT_PERMISSIONS;DEB.DEFAULT_PERMISSIONS" false "MONOLITHIC;COMPONENT")
+run_cpack_test(DEPENDENCIES "RPM.DEPENDENCIES;DEB.DEPENDENCIES" true "COMPONENT")
+run_cpack_test(DIST "RPM.DIST" false "MONOLITHIC")
+run_cpack_test(EMPTY_DIR "RPM.EMPTY_DIR;DEB.EMPTY_DIR;TGZ" true "MONOLITHIC;COMPONENT")
+run_cpack_test(VERSION "RPM.VERSION;DEB.VERSION" false "MONOLITHIC;COMPONENT")
+run_cpack_test(EXTRA "DEB.EXTRA" false "COMPONENT")
+run_cpack_test_subtests(GENERATE_SHLIBS "soversion_not_zero;soversion_zero" "DEB.GENERATE_SHLIBS" true "COMPONENT")
+run_cpack_test(GENERATE_SHLIBS_LDCONFIG "DEB.GENERATE_SHLIBS_LDCONFIG" true "COMPONENT")
+run_cpack_test(INSTALL_SCRIPTS "RPM.INSTALL_SCRIPTS" false "COMPONENT")
+run_cpack_test(LONG_FILENAMES "DEB.LONG_FILENAMES" false "MONOLITHIC")
+run_cpack_test_subtests(MAIN_COMPONENT "invalid;found" "RPM.MAIN_COMPONENT" false "COMPONENT")
+run_cpack_test(MINIMAL "RPM.MINIMAL;DEB.MINIMAL;7Z;TBZ2;TGZ;TXZ;TZ;ZIP;STGZ;External" false "MONOLITHIC;COMPONENT")
+run_cpack_test_package_target(MINIMAL "RPM.MINIMAL;DEB.MINIMAL;7Z;TBZ2;TGZ;TXZ;TZ;ZIP;STGZ;External" false "MONOLITHIC;COMPONENT")
+run_cpack_test_package_target(THREADED_ALL "TXZ" false "MONOLITHIC;COMPONENT")
+run_cpack_test_package_target(THREADED "TXZ" false "MONOLITHIC;COMPONENT")
+run_cpack_test_subtests(PACKAGE_CHECKSUM "invalid;MD5;SHA1;SHA224;SHA256;SHA384;SHA512" "TGZ" false "MONOLITHIC")
+run_cpack_test(PARTIALLY_RELOCATABLE_WARNING "RPM.PARTIALLY_RELOCATABLE_WARNING" false "COMPONENT")
+run_cpack_test(PER_COMPONENT_FIELDS "RPM.PER_COMPONENT_FIELDS;DEB.PER_COMPONENT_FIELDS" false "COMPONENT")
+run_cpack_test_subtests(SINGLE_DEBUGINFO "no_main_component;one_component;one_component_main;no_debuginfo;one_component_no_debuginfo;no_components;valid" "RPM.SINGLE_DEBUGINFO" true "CUSTOM")
+run_cpack_test(EXTRA_SLASH_IN_PATH "RPM.EXTRA_SLASH_IN_PATH" true "COMPONENT")
+run_cpack_source_test(SOURCE_PACKAGE "RPM.SOURCE_PACKAGE")
+run_cpack_test(SUGGESTS "RPM.SUGGESTS" false "MONOLITHIC")
+run_cpack_test(SYMLINKS "RPM.SYMLINKS;TGZ" false "MONOLITHIC;COMPONENT")
+set(ENVIRONMENT "SOURCE_DATE_EPOCH=123456789")
+run_cpack_test(TIMESTAMPS "DEB.TIMESTAMPS;TGZ" false "COMPONENT")
+unset(ENVIRONMENT)
+run_cpack_test(USER_FILELIST "RPM.USER_FILELIST" false "MONOLITHIC")
+run_cpack_test(MD5SUMS "DEB.MD5SUMS" false "MONOLITHIC;COMPONENT")
+run_cpack_test_subtests(CPACK_INSTALL_SCRIPTS "singular;plural;both" "ZIP" false "MONOLITHIC")
+run_cpack_test(DEB_PACKAGE_VERSION_BACK_COMPATIBILITY "DEB.DEB_PACKAGE_VERSION_BACK_COMPATIBILITY" false "MONOLITHIC;COMPONENT")
+run_cpack_test_subtests(EXTERNAL "none;good;good_multi;bad_major;bad_minor;invalid_good;invalid_bad;stage_and_package" "External" false "MONOLITHIC;COMPONENT")
+run_cpack_test_subtests(
+ DEB_DESCRIPTION
+ "CPACK_DEBIAN_PACKAGE_DESCRIPTION;CPACK_PACKAGE_DESCRIPTION;CPACK_COMPONENT_COMP_DESCRIPTION;CPACK_PACKAGE_DESCRIPTION_FILE;CPACK_NO_PACKAGE_DESCRIPTION"
+ "DEB.DEB_DESCRIPTION"
+ false
+ "MONOLITHIC;COMPONENT"
+)
+run_cpack_test(PROJECT_META "RPM.PROJECT_META;DEB.PROJECT_META" false "MONOLITHIC;COMPONENT")
diff --git a/Tests/RunCMake/CPack/STGZ/Helpers.cmake b/Tests/RunCMake/CPack/STGZ/Helpers.cmake
new file mode 100644
index 0000000..1756645
--- /dev/null
+++ b/Tests/RunCMake/CPack/STGZ/Helpers.cmake
@@ -0,0 +1,75 @@
+set(ALL_FILES_GLOB "*.sh")
+
+function(getPackageContent FILE RESULT_VAR)
+ get_filename_component(path_ "${FILE}" DIRECTORY)
+ file(REMOVE_RECURSE "${path_}/content")
+ file(MAKE_DIRECTORY "${path_}/content")
+ execute_process(COMMAND ${FILE} --prefix=${path_}/content --include-subdir
+ RESULT_VARIABLE extract_result_
+ ERROR_VARIABLE extract_error_
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+ if(extract_result_)
+ message(FATAL_ERROR "Extracting STGZ archive failed: '${extract_result_}';"
+ " '${extract_error_}'.")
+ endif()
+
+ file(GLOB_RECURSE package_content_ LIST_DIRECTORIES true RELATIVE
+ "${path_}/content" "${path_}/content/*")
+
+ set(${RESULT_VAR} "${package_content_}" PARENT_SCOPE)
+endfunction()
+
+function(getPackageNameGlobexpr NAME COMPONENT VERSION REVISION FILE_NO RESULT_VAR)
+ if(COMPONENT)
+ set(COMPONENT "-${COMPONENT}")
+ endif()
+
+ set(${RESULT_VAR} "${NAME}-${VERSION}-*${COMPONENT}.sh" PARENT_SCOPE)
+endfunction()
+
+function(getPackageContentList FILE RESULT_VAR)
+ getPackageContent("${FILE}" package_content_)
+
+ set(${RESULT_VAR} "${package_content_}" PARENT_SCOPE)
+endfunction()
+
+function(toExpectedContentList FILE_NO CONTENT_VAR)
+ findExpectedFile("${FILE_NO}" "file_" "glob_expr_")
+
+ get_filename_component(prefix_ "${file_}" NAME)
+ # NAME_WE removes everything after the dot and dot is in version so replace instead
+ string(REPLACE ".sh" "" prefix_ "${prefix_}")
+
+ if(NOT PACKAGING_TYPE STREQUAL "MONOLITHIC")
+ # STGZ packages don't have component dir prefix in subdir
+ string(FIND "${prefix_}" "-" pos_ REVERSE)
+ string(SUBSTRING "${prefix_}" 0 ${pos_} prefix_)
+ endif()
+
+ # add install prefix to expected paths
+ if(DEFINED EXPECTED_FILE_${FILE_NO}_PACKAGING_PREFIX)
+ set(EXPECTED_FILE_PACKAGING_PREFIX
+ "${EXPECTED_FILE_${FILE_NO}_PACKAGING_PREFIX}")
+ elseif(NOT DEFINED EXPECTED_FILE_PACKAGING_PREFIX)
+ # default CPack Archive packaging install prefix
+ set(EXPECTED_FILE_PACKAGING_PREFIX "/")
+ endif()
+
+ # remove trailing slash otherwise path concatenation will cause double slashes
+ string(REGEX REPLACE "/$" "" EXPECTED_FILE_PACKAGING_PREFIX
+ "${EXPECTED_FILE_PACKAGING_PREFIX}")
+
+ if(EXPECTED_FILE_PACKAGING_PREFIX)
+ set(prepared_ "${prefix_}")
+ else()
+ unset(prepared_)
+ endif()
+
+ list(APPEND prepared_ "${prefix_}${EXPECTED_FILE_PACKAGING_PREFIX}")
+ foreach(part_ IN LISTS ${CONTENT_VAR})
+ list(APPEND prepared_ "${prefix_}${EXPECTED_FILE_PACKAGING_PREFIX}${part_}")
+ endforeach()
+
+ set(${CONTENT_VAR} "${prepared_}" PARENT_SCOPE)
+endfunction()
diff --git a/Tests/RunCMake/CPack/STGZ/Prerequirements.cmake b/Tests/RunCMake/CPack/STGZ/Prerequirements.cmake
new file mode 100644
index 0000000..3b015ca
--- /dev/null
+++ b/Tests/RunCMake/CPack/STGZ/Prerequirements.cmake
@@ -0,0 +1,11 @@
+function(get_test_prerequirements found_var config_file)
+ if(EXISTS "/bin/sh")
+ #gunzip is not part of posix so we should not rely on it being installed
+ find_program(GUNZIP_EXECUTABLE gunzip)
+
+ if(GUNZIP_EXECUTABLE)
+ file(WRITE "${config_file}" "")
+ set(${found_var} true PARENT_SCOPE)
+ endif()
+ endif()
+endfunction()
diff --git a/Tests/RunCMake/CPack/STGZ/packaging_COMPONENT_default.cmake b/Tests/RunCMake/CPack/STGZ/packaging_COMPONENT_default.cmake
new file mode 100644
index 0000000..81a5035
--- /dev/null
+++ b/Tests/RunCMake/CPack/STGZ/packaging_COMPONENT_default.cmake
@@ -0,0 +1 @@
+set(CPACK_ARCHIVE_COMPONENT_INSTALL "ON")
diff --git a/Tests/RunCMake/CPack/TBZ2/Helpers.cmake b/Tests/RunCMake/CPack/TBZ2/Helpers.cmake
new file mode 100644
index 0000000..292b691
--- /dev/null
+++ b/Tests/RunCMake/CPack/TBZ2/Helpers.cmake
@@ -0,0 +1,3 @@
+set(cpack_archive_extension_ "tar.bz2")
+
+include("${CMAKE_CURRENT_LIST_DIR}/../ArchiveCommon/common_helpers.cmake")
diff --git a/Tests/RunCMake/CPack/TBZ2/Prerequirements.cmake b/Tests/RunCMake/CPack/TBZ2/Prerequirements.cmake
new file mode 100644
index 0000000..dbaf682
--- /dev/null
+++ b/Tests/RunCMake/CPack/TBZ2/Prerequirements.cmake
@@ -0,0 +1,4 @@
+function(get_test_prerequirements found_var config_file)
+ file(WRITE "${config_file}" "")
+ set(${found_var} true PARENT_SCOPE)
+endfunction()
diff --git a/Tests/RunCMake/CPack/TBZ2/packaging_COMPONENT_default.cmake b/Tests/RunCMake/CPack/TBZ2/packaging_COMPONENT_default.cmake
new file mode 100644
index 0000000..81a5035
--- /dev/null
+++ b/Tests/RunCMake/CPack/TBZ2/packaging_COMPONENT_default.cmake
@@ -0,0 +1 @@
+set(CPACK_ARCHIVE_COMPONENT_INSTALL "ON")
diff --git a/Tests/RunCMake/CPack/TGZ/Helpers.cmake b/Tests/RunCMake/CPack/TGZ/Helpers.cmake
new file mode 100644
index 0000000..4357a59
--- /dev/null
+++ b/Tests/RunCMake/CPack/TGZ/Helpers.cmake
@@ -0,0 +1,3 @@
+set(cpack_archive_extension_ "tar.gz")
+
+include("${CMAKE_CURRENT_LIST_DIR}/../ArchiveCommon/common_helpers.cmake")
diff --git a/Tests/RunCMake/CPack/TGZ/Prerequirements.cmake b/Tests/RunCMake/CPack/TGZ/Prerequirements.cmake
new file mode 100644
index 0000000..dbaf682
--- /dev/null
+++ b/Tests/RunCMake/CPack/TGZ/Prerequirements.cmake
@@ -0,0 +1,4 @@
+function(get_test_prerequirements found_var config_file)
+ file(WRITE "${config_file}" "")
+ set(${found_var} true PARENT_SCOPE)
+endfunction()
diff --git a/Tests/RunCMake/CPack/TGZ/packaging_COMPONENT_default.cmake b/Tests/RunCMake/CPack/TGZ/packaging_COMPONENT_default.cmake
new file mode 100644
index 0000000..81a5035
--- /dev/null
+++ b/Tests/RunCMake/CPack/TGZ/packaging_COMPONENT_default.cmake
@@ -0,0 +1 @@
+set(CPACK_ARCHIVE_COMPONENT_INSTALL "ON")
diff --git a/Tests/RunCMake/CPack/TXZ/Helpers.cmake b/Tests/RunCMake/CPack/TXZ/Helpers.cmake
new file mode 100644
index 0000000..f390cb4
--- /dev/null
+++ b/Tests/RunCMake/CPack/TXZ/Helpers.cmake
@@ -0,0 +1,3 @@
+set(cpack_archive_extension_ "tar.xz")
+
+include("${CMAKE_CURRENT_LIST_DIR}/../ArchiveCommon/common_helpers.cmake")
diff --git a/Tests/RunCMake/CPack/TXZ/Prerequirements.cmake b/Tests/RunCMake/CPack/TXZ/Prerequirements.cmake
new file mode 100644
index 0000000..dbaf682
--- /dev/null
+++ b/Tests/RunCMake/CPack/TXZ/Prerequirements.cmake
@@ -0,0 +1,4 @@
+function(get_test_prerequirements found_var config_file)
+ file(WRITE "${config_file}" "")
+ set(${found_var} true PARENT_SCOPE)
+endfunction()
diff --git a/Tests/RunCMake/CPack/TXZ/packaging_COMPONENT_default.cmake b/Tests/RunCMake/CPack/TXZ/packaging_COMPONENT_default.cmake
new file mode 100644
index 0000000..81a5035
--- /dev/null
+++ b/Tests/RunCMake/CPack/TXZ/packaging_COMPONENT_default.cmake
@@ -0,0 +1 @@
+set(CPACK_ARCHIVE_COMPONENT_INSTALL "ON")
diff --git a/Tests/RunCMake/CPack/TZ/Helpers.cmake b/Tests/RunCMake/CPack/TZ/Helpers.cmake
new file mode 100644
index 0000000..117cd24
--- /dev/null
+++ b/Tests/RunCMake/CPack/TZ/Helpers.cmake
@@ -0,0 +1,3 @@
+set(cpack_archive_extension_ "tar.Z")
+
+include("${CMAKE_CURRENT_LIST_DIR}/../ArchiveCommon/common_helpers.cmake")
diff --git a/Tests/RunCMake/CPack/TZ/Prerequirements.cmake b/Tests/RunCMake/CPack/TZ/Prerequirements.cmake
new file mode 100644
index 0000000..dbaf682
--- /dev/null
+++ b/Tests/RunCMake/CPack/TZ/Prerequirements.cmake
@@ -0,0 +1,4 @@
+function(get_test_prerequirements found_var config_file)
+ file(WRITE "${config_file}" "")
+ set(${found_var} true PARENT_SCOPE)
+endfunction()
diff --git a/Tests/RunCMake/CPack/TZ/packaging_COMPONENT_default.cmake b/Tests/RunCMake/CPack/TZ/packaging_COMPONENT_default.cmake
new file mode 100644
index 0000000..81a5035
--- /dev/null
+++ b/Tests/RunCMake/CPack/TZ/packaging_COMPONENT_default.cmake
@@ -0,0 +1 @@
+set(CPACK_ARCHIVE_COMPONENT_INSTALL "ON")
diff --git a/Tests/RunCMake/CPack/VerifyResult.cmake b/Tests/RunCMake/CPack/VerifyResult.cmake
new file mode 100644
index 0000000..345b37f
--- /dev/null
+++ b/Tests/RunCMake/CPack/VerifyResult.cmake
@@ -0,0 +1,137 @@
+cmake_minimum_required(VERSION ${CMAKE_VERSION} FATAL_ERROR)
+
+function(findExpectedFile FILE_NO RESULT_VAR GLOBING_EXPR_VAR)
+ if(NOT DEFINED EXPECTED_FILE_${FILE_NO}) # explicit file name regex was not provided - construct one from other data
+ # set defaults if parameters are not provided
+ if(NOT DEFINED EXPECTED_FILE_${FILE_NO}_NAME)
+ string(TOLOWER "${RunCMake_TEST_FILE_PREFIX}" EXPECTED_FILE_${FILE_NO}_NAME)
+ endif()
+ if(NOT DEFINED EXPECTED_FILE_${FILE_NO}_VERSION)
+ set(EXPECTED_FILE_${FILE_NO}_VERSION "0.1.1")
+ set(EXPECTED_FILE_${FILE_NO}_VERSION "0.1.1" PARENT_SCOPE)
+ endif()
+
+ getPackageNameGlobexpr("${EXPECTED_FILE_${FILE_NO}_NAME}"
+ "${EXPECTED_FILE_${FILE_NO}_COMPONENT}" "${EXPECTED_FILE_${FILE_NO}_VERSION}"
+ "${EXPECTED_FILE_${FILE_NO}_REVISION}" "${FILE_NO}" "EXPECTED_FILE_${FILE_NO}")
+ endif()
+
+ file(GLOB found_file_ RELATIVE "${bin_dir}" "${EXPECTED_FILE_${FILE_NO}}")
+
+ set(${RESULT_VAR} "${found_file_}" PARENT_SCOPE)
+ set(${GLOBING_EXPR_VAR} "${EXPECTED_FILE_${FILE_NO}}" PARENT_SCOPE)
+endfunction()
+
+include("${config_file}")
+include("${src_dir}/${GENERATOR_TYPE}/Helpers.cmake")
+
+file(READ "${bin_dir}/test_output.txt" output)
+file(READ "${bin_dir}/test_error.txt" error)
+file(READ "${config_file}" config_file_content)
+
+set(output_error_message
+ "\nCPack output: '${output}'\nCPack error: '${error}';\nCPack result: '${PACKAGING_RESULT}';\nconfig file: '${config_file_content}'")
+
+# generate default expected files data
+include("${src_dir}/tests/${RunCMake_TEST_FILE_PREFIX}/ExpectedFiles.cmake")
+
+# check that expected generated files exist and contain expected content
+if(NOT EXPECTED_FILES_COUNT EQUAL 0)
+ foreach(file_no_ RANGE 1 ${EXPECTED_FILES_COUNT})
+ findExpectedFile("${file_no_}" "FOUND_FILE_${file_no_}"
+ "EXPECTED_FILE_${file_no_}")
+ list(APPEND foundFiles_ "${FOUND_FILE_${file_no_}}")
+ list(LENGTH FOUND_FILE_${file_no_} foundFilesCount_)
+
+ if(foundFilesCount_ EQUAL 1)
+ unset(PACKAGE_CONTENT)
+
+ if(DEFINED EXPECTED_FILE_CONTENT_${file_no_})
+ getPackageContent("${bin_dir}/${FOUND_FILE_${file_no_}}" "PACKAGE_CONTENT")
+
+ string(REGEX MATCH "${EXPECTED_FILE_CONTENT_${file_no_}}"
+ expected_content_list "${PACKAGE_CONTENT}")
+ else() # use content list
+ getPackageContentList("${bin_dir}/${FOUND_FILE_${file_no_}}" "PACKAGE_CONTENT")
+ set(EXPECTED_FILE_CONTENT_${file_no_} "${EXPECTED_FILE_CONTENT_${file_no_}_LIST}")
+ toExpectedContentList("${file_no_}" "EXPECTED_FILE_CONTENT_${file_no_}")
+
+ if(NOT PACKAGE_CONTENT STREQUAL "")
+ list(SORT PACKAGE_CONTENT)
+ endif()
+ if(NOT EXPECTED_FILE_CONTENT_${file_no_} STREQUAL "")
+ list(SORT EXPECTED_FILE_CONTENT_${file_no_})
+ endif()
+
+ if(PACKAGE_CONTENT STREQUAL EXPECTED_FILE_CONTENT_${file_no_})
+ set(expected_content_list TRUE)
+ else()
+ set(expected_content_list FALSE)
+ endif()
+ endif()
+
+ if(NOT expected_content_list)
+ string(REPLACE "\n" "\n actual> " msg_actual "\n${PACKAGE_CONTENT}")
+ string(REPLACE "\n" "\n expect> " msg_expected "\n${EXPECTED_FILE_CONTENT_${file_no_}}")
+ message(FATAL_ERROR
+ "Unexpected file content for file No. '${file_no_}'!\n"
+ "The content was:${msg_actual}\n"
+ "which does not match:${msg_expected}\n"
+ "${output_error_message}")
+ endif()
+ else()
+ message(FATAL_ERROR
+ "Found more than one file for file No. '${file_no_}'!"
+ " Found files count '${foundFilesCount_}'."
+ " Files: '${FOUND_FILE_${file_no_}}'"
+ " Globbing expression: '${EXPECTED_FILE_${file_no_}}'"
+ "${output_error_message}")
+ endif()
+ endforeach()
+
+ # check that there were no extra files generated
+ foreach(all_files_glob_ IN LISTS ALL_FILES_GLOB)
+ file(GLOB foundAll_ RELATIVE "${bin_dir}" "${all_files_glob_}")
+ list(APPEND allFoundFiles_ ${foundAll_})
+ endforeach()
+
+ list(LENGTH foundFiles_ foundFilesCount_)
+ list(LENGTH allFoundFiles_ allFoundFilesCount_)
+
+ if(NOT foundFilesCount_ EQUAL allFoundFilesCount_)
+ message(FATAL_ERROR
+ "Found more files than expected! Found files: '${allFoundFiles_}'"
+ "${output_error_message}")
+ endif()
+
+ # sanity check that we didn't accidentally list wrong files with our regular
+ # expressions
+ foreach(expected_ IN LISTS allFoundFiles_)
+ list(FIND foundFiles_ "${expected_}" found_)
+
+ if(found_ EQUAL -1)
+ message(FATAL_ERROR
+ "Expected files don't match found files! Found files:"
+ " '${allFoundFiles_}'"
+ "${output_error_message}")
+ endif()
+ endforeach()
+else()
+ # there should be no generated files present
+ foreach(missing_file_glob_ IN LISTS ALL_FILES_GLOB)
+ file(GLOB checkMissingFiles_ RELATIVE "${bin_dir}" "${missing_file_glob_}")
+
+ if(checkMissingFiles_)
+ message(FATAL_ERROR "Unexpected files found: '${checkMissingFiles_}'"
+ "${output_error_message}")
+ endif()
+ endforeach()
+endif()
+
+# handle additional result verifications
+if(EXISTS "${src_dir}/tests/${RunCMake_TEST_FILE_PREFIX}/VerifyResult.cmake")
+ include("${src_dir}/tests/${RunCMake_TEST_FILE_PREFIX}/VerifyResult.cmake")
+endif()
+
+message(STATUS "${output}")
+message("${error}")
diff --git a/Tests/RunCMake/CPack/ZIP/Helpers.cmake b/Tests/RunCMake/CPack/ZIP/Helpers.cmake
new file mode 100644
index 0000000..3710bcf
--- /dev/null
+++ b/Tests/RunCMake/CPack/ZIP/Helpers.cmake
@@ -0,0 +1,3 @@
+set(cpack_archive_extension_ "zip")
+
+include("${CMAKE_CURRENT_LIST_DIR}/../ArchiveCommon/common_helpers.cmake")
diff --git a/Tests/RunCMake/CPack/ZIP/Prerequirements.cmake b/Tests/RunCMake/CPack/ZIP/Prerequirements.cmake
new file mode 100644
index 0000000..dbaf682
--- /dev/null
+++ b/Tests/RunCMake/CPack/ZIP/Prerequirements.cmake
@@ -0,0 +1,4 @@
+function(get_test_prerequirements found_var config_file)
+ file(WRITE "${config_file}" "")
+ set(${found_var} true PARENT_SCOPE)
+endfunction()
diff --git a/Tests/RunCMake/CPack/ZIP/packaging_COMPONENT_default.cmake b/Tests/RunCMake/CPack/ZIP/packaging_COMPONENT_default.cmake
new file mode 100644
index 0000000..81a5035
--- /dev/null
+++ b/Tests/RunCMake/CPack/ZIP/packaging_COMPONENT_default.cmake
@@ -0,0 +1 @@
+set(CPACK_ARCHIVE_COMPONENT_INSTALL "ON")
diff --git a/Tests/RunCMake/CPack/tests/CPACK_INSTALL_SCRIPTS/ExpectedFiles.cmake b/Tests/RunCMake/CPack/tests/CPACK_INSTALL_SCRIPTS/ExpectedFiles.cmake
new file mode 100644
index 0000000..02a7821
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/CPACK_INSTALL_SCRIPTS/ExpectedFiles.cmake
@@ -0,0 +1,3 @@
+set(EXPECTED_FILES_COUNT "1")
+
+set(EXPECTED_FILE_CONTENT_1_LIST "/foo;/foo/abc.txt")
diff --git a/Tests/RunCMake/CPack/tests/CPACK_INSTALL_SCRIPTS/both-stderr.txt b/Tests/RunCMake/CPack/tests/CPACK_INSTALL_SCRIPTS/both-stderr.txt
new file mode 100644
index 0000000..666030e
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/CPACK_INSTALL_SCRIPTS/both-stderr.txt
@@ -0,0 +1 @@
+CPack Warning: Both CPACK_INSTALL_SCRIPTS and CPACK_INSTALL_SCRIPT are set, the latter will be ignored.
diff --git a/Tests/RunCMake/CPack/tests/CPACK_INSTALL_SCRIPTS/test.cmake b/Tests/RunCMake/CPack/tests/CPACK_INSTALL_SCRIPTS/test.cmake
new file mode 100644
index 0000000..249d2e6
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/CPACK_INSTALL_SCRIPTS/test.cmake
@@ -0,0 +1,26 @@
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/abc.txt" "test content")
+set(user_script_ "${CMAKE_CURRENT_BINARY_DIR}/user-script.cmake")
+file(WRITE "${user_script_}"
+ "file(INSTALL DESTINATION \"\${CMAKE_INSTALL_PREFIX}/foo\"
+ TYPE FILE FILES \"${CMAKE_CURRENT_BINARY_DIR}/abc.txt\")")
+
+if(RunCMake_SUBTEST_SUFFIX STREQUAL "both")
+ set(CPACK_INSTALL_SCRIPT "${user_script_}")
+ set(CPACK_INSTALL_SCRIPTS "${CPACK_INSTALL_SCRIPT}")
+
+elseif(RunCMake_SUBTEST_SUFFIX STREQUAL "singular")
+ set(CPACK_INSTALL_SCRIPT "${user_script_}")
+
+elseif(RunCMake_SUBTEST_SUFFIX STREQUAL "plural")
+ set(CPACK_INSTALL_SCRIPTS "${user_script_}")
+
+else()
+ message(FATAL_ERROR "Unexpected subtest name: ${RunCMake_SUBTEST_SUFFIX}")
+
+endif()
+
+function(run_after_include_cpack)
+ file(READ "${CPACK_OUTPUT_CONFIG_FILE}" conf_file_)
+ string(REGEX REPLACE "SET\\(CPACK_INSTALL_CMAKE_PROJECTS [^)]*\\)" "" conf_file_ "${conf_file_}")
+ file(WRITE "${CPACK_OUTPUT_CONFIG_FILE}" "${conf_file_}")
+endfunction()
diff --git a/Tests/RunCMake/CPack/tests/CUSTOM_BINARY_SPEC_FILE/ExpectedFiles.cmake b/Tests/RunCMake/CPack/tests/CUSTOM_BINARY_SPEC_FILE/ExpectedFiles.cmake
new file mode 100644
index 0000000..6d895ec
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/CUSTOM_BINARY_SPEC_FILE/ExpectedFiles.cmake
@@ -0,0 +1,9 @@
+set(EXPECTED_FILES_COUNT "1")
+set(EXPECTED_FILE_CONTENT_1_LIST "/foo;/foo/CMakeLists.txt")
+
+if(PACKAGING_TYPE STREQUAL "COMPONENT")
+ set(EXPECTED_FILES_COUNT "2")
+ set(EXPECTED_FILE_1_COMPONENT "test")
+ set(EXPECTED_FILE_2_COMPONENT "test2")
+ set(EXPECTED_FILE_CONTENT_2_LIST "/bar;/bar/CMakeLists.txt")
+endif()
diff --git a/Tests/RunCMake/CPack/tests/CUSTOM_BINARY_SPEC_FILE/RPM-COMPONENT-stderr.txt b/Tests/RunCMake/CPack/tests/CUSTOM_BINARY_SPEC_FILE/RPM-COMPONENT-stderr.txt
new file mode 100644
index 0000000..b050262
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/CUSTOM_BINARY_SPEC_FILE/RPM-COMPONENT-stderr.txt
@@ -0,0 +1,2 @@
+^CPackRPM: Will use USER specified spec file: (/[^/]*)*/CUSTOM_BINARY_SPEC_FILE/custom\.spec\.in
+CPackRPM: Will use GENERATED spec file:.*/Tests/RunCMake/RPM\.CUSTOM_BINARY_SPEC_FILE/CPack/CUSTOM_BINARY_SPEC_FILE-build/_CPack_Packages/.*/RPM/SPECS/custom_binary_spec_file-test2\.spec$
diff --git a/Tests/RunCMake/CPack/tests/CUSTOM_BINARY_SPEC_FILE/RPM-MONOLITHIC-stderr.txt b/Tests/RunCMake/CPack/tests/CUSTOM_BINARY_SPEC_FILE/RPM-MONOLITHIC-stderr.txt
new file mode 100644
index 0000000..d7bb7af
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/CUSTOM_BINARY_SPEC_FILE/RPM-MONOLITHIC-stderr.txt
@@ -0,0 +1 @@
+CPackRPM: Will use USER specified spec file: (/[^/]*)*/CUSTOM_BINARY_SPEC_FILE/custom\.spec\.in
diff --git a/Tests/RunCMake/CPack/tests/CUSTOM_BINARY_SPEC_FILE/custom.spec.in b/Tests/RunCMake/CPack/tests/CUSTOM_BINARY_SPEC_FILE/custom.spec.in
new file mode 100644
index 0000000..db0ac6f
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/CUSTOM_BINARY_SPEC_FILE/custom.spec.in
@@ -0,0 +1,80 @@
+# -*- rpm-spec -*-
+BuildRoot: %_topdir/@CPACK_PACKAGE_FILE_NAME@@CPACK_RPM_PACKAGE_COMPONENT_PART_PATH@
+Summary: @CPACK_RPM_PACKAGE_SUMMARY@
+Name: @CPACK_RPM_PACKAGE_NAME@
+Version: @CPACK_RPM_PACKAGE_VERSION@
+Release: @CPACK_RPM_PACKAGE_RELEASE@
+License: @CPACK_RPM_PACKAGE_LICENSE@
+Group: @CPACK_RPM_PACKAGE_GROUP@
+Vendor: @CPACK_RPM_PACKAGE_VENDOR@
+
+@TMP_RPM_URL@
+@TMP_RPM_REQUIRES@
+@TMP_RPM_REQUIRES_PRE@
+@TMP_RPM_REQUIRES_POST@
+@TMP_RPM_REQUIRES_PREUN@
+@TMP_RPM_REQUIRES_POSTUN@
+@TMP_RPM_PROVIDES@
+@TMP_RPM_OBSOLETES@
+@TMP_RPM_CONFLICTS@
+@TMP_RPM_SUGGESTS@
+@TMP_RPM_AUTOPROV@
+@TMP_RPM_AUTOREQ@
+@TMP_RPM_AUTOREQPROV@
+@TMP_RPM_BUILDARCH@
+@TMP_RPM_PREFIXES@
+
+@TMP_RPM_DEBUGINFO@
+
+%define _rpmdir %_topdir/RPMS
+%define _srcrpmdir %_topdir/SRPMS
+@FILE_NAME_DEFINE@
+%define _unpackaged_files_terminate_build 0
+@TMP_RPM_SPEC_INSTALL_POST@
+@CPACK_RPM_SPEC_MORE_DEFINE@
+@CPACK_RPM_COMPRESSION_TYPE_TMP@
+
+%description
+@CPACK_RPM_PACKAGE_DESCRIPTION@
+
+# This is a shortcutted spec file generated by CMake RPM generator
+# we skip _install step because CPack does that for us.
+# We do only save CPack installed tree in _prepr
+# and then restore it in build.
+%prep
+mv $RPM_BUILD_ROOT %_topdir/tmpBBroot
+
+%install
+if [ -e $RPM_BUILD_ROOT ];
+then
+ rm -rf $RPM_BUILD_ROOT
+fi
+mv %_topdir/tmpBBroot $RPM_BUILD_ROOT
+
+@TMP_RPM_DEBUGINFO_INSTALL@
+
+%clean
+
+%post
+@RPM_SYMLINK_POSTINSTALL@
+@CPACK_RPM_SPEC_POSTINSTALL@
+
+%postun
+@CPACK_RPM_SPEC_POSTUNINSTALL@
+
+%pre
+@CPACK_RPM_SPEC_PREINSTALL@
+
+%preun
+@CPACK_RPM_SPEC_PREUNINSTALL@
+
+%files
+%defattr(@TMP_DEFAULT_FILE_PERMISSIONS@,@TMP_DEFAULT_USER@,@TMP_DEFAULT_GROUP@,@TMP_DEFAULT_DIR_PERMISSIONS@)
+@CPACK_RPM_INSTALL_FILES@
+@CPACK_RPM_ABSOLUTE_INSTALL_FILES@
+@CPACK_RPM_USER_INSTALL_FILES@
+
+%changelog
+@CPACK_RPM_SPEC_CHANGELOG@
+
+@TMP_OTHER_COMPONENTS@
diff --git a/Tests/RunCMake/CPack/tests/CUSTOM_BINARY_SPEC_FILE/test.cmake b/Tests/RunCMake/CPack/tests/CUSTOM_BINARY_SPEC_FILE/test.cmake
new file mode 100644
index 0000000..a604863
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/CUSTOM_BINARY_SPEC_FILE/test.cmake
@@ -0,0 +1,9 @@
+install(FILES CMakeLists.txt DESTINATION foo COMPONENT test)
+
+if(PACKAGING_TYPE STREQUAL "MONOLITHIC")
+ set(CPACK_RPM_USER_BINARY_SPECFILE "${CMAKE_CURRENT_LIST_DIR}/custom.spec.in")
+elseif(PACKAGING_TYPE STREQUAL "COMPONENT")
+ install(FILES CMakeLists.txt DESTINATION bar COMPONENT test2)
+ set(CPACK_RPM_TEST_USER_BINARY_SPECFILE
+ "${CMAKE_CURRENT_LIST_DIR}/custom.spec.in")
+endif()
diff --git a/Tests/RunCMake/CPack/tests/CUSTOM_NAMES/ExpectedFiles.cmake b/Tests/RunCMake/CPack/tests/CUSTOM_NAMES/ExpectedFiles.cmake
new file mode 100644
index 0000000..9ac19e2
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/CUSTOM_NAMES/ExpectedFiles.cmake
@@ -0,0 +1,18 @@
+set(EXPECTED_FILES_COUNT "3")
+set(EXPECTED_FILES_NAME_GENERATOR_SPECIFIC_FORMAT TRUE)
+set(EXPECTED_FILE_1_COMPONENT "pkg_1")
+set(EXPECTED_FILE_CONTENT_1_LIST "/foo;/foo/CMakeLists.txt")
+set(EXPECTED_FILE_2_NAME "second")
+set(EXPECTED_FILE_CONTENT_2_LIST "/foo;/foo/CMakeLists.txt")
+set(EXPECTED_FILE_CONTENT_3_LIST "/foo;/foo/CMakeLists.txt")
+
+if(GENERATOR_TYPE STREQUAL "DEB" OR GENERATOR_TYPE STREQUAL "RPM")
+ string(TOLOWER "${GENERATOR_TYPE}" file_extension_)
+ set(EXPECTED_FILE_3 "pkg_3_abc.${file_extension_}")
+elseif(GENERATOR_TYPE STREQUAL "TGZ")
+ set(EXPECTED_FILE_2 "second.tar.gz")
+ set(EXPECTED_FILE_3 "pkg_3_abc.tar.gz")
+elseif(GENERATOR_TYPE STREQUAL "DragNDrop")
+ set(EXPECTED_FILE_2 "second.dmg")
+ set(EXPECTED_FILE_3 "pkg_3_abc.dmg")
+endif()
diff --git a/Tests/RunCMake/CPack/tests/CUSTOM_NAMES/test.cmake b/Tests/RunCMake/CPack/tests/CUSTOM_NAMES/test.cmake
new file mode 100644
index 0000000..899258e
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/CUSTOM_NAMES/test.cmake
@@ -0,0 +1,20 @@
+if(GENERATOR_TYPE STREQUAL "DEB" OR GENERATOR_TYPE STREQUAL "RPM")
+ if(GENERATOR_TYPE STREQUAL "DEB")
+ set(generator_type_suffix_ "IAN") # not entirely compatible...
+ endif()
+
+ set(CPACK_${GENERATOR_TYPE}${generator_type_suffix_}_FILE_NAME "${GENERATOR_TYPE}-DEFAULT")
+ set(CPACK_${GENERATOR_TYPE}${generator_type_suffix_}_PKG_2_PACKAGE_NAME "second")
+ string(TOLOWER "${GENERATOR_TYPE}" file_extension_)
+ set(CPACK_${GENERATOR_TYPE}${generator_type_suffix_}_PKG_3_FILE_NAME "pkg_3_abc.${file_extension_}")
+elseif(GENERATOR_TYPE STREQUAL "TGZ")
+ set(CPACK_ARCHIVE_PKG_2_FILE_NAME "second")
+ set(CPACK_ARCHIVE_PKG_3_FILE_NAME "pkg_3_abc")
+elseif(GENERATOR_TYPE STREQUAL "DragNDrop")
+ set(CPACK_DMG_PKG_2_FILE_NAME "second")
+ set(CPACK_DMG_PKG_3_FILE_NAME "pkg_3_abc")
+endif()
+
+install(FILES CMakeLists.txt DESTINATION foo COMPONENT pkg_1)
+install(FILES CMakeLists.txt DESTINATION foo COMPONENT pkg_2)
+install(FILES CMakeLists.txt DESTINATION foo COMPONENT pkg_3)
diff --git a/Tests/RunCMake/CPack/tests/DEBUGINFO/ExpectedFiles.cmake b/Tests/RunCMake/CPack/tests/DEBUGINFO/ExpectedFiles.cmake
new file mode 100644
index 0000000..cf2e8ac
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/DEBUGINFO/ExpectedFiles.cmake
@@ -0,0 +1,41 @@
+set(whitespaces_ "[\t\n\r ]*")
+
+set(EXPECTED_FILES_COUNT "5")
+set(EXPECTED_FILES_NAME_GENERATOR_SPECIFIC_FORMAT TRUE)
+
+if(GENERATOR_TYPE STREQUAL "RPM")
+ set(NAME "Debuginfo")
+ set(DEBUG_SUFFIX "debuginfo")
+ set(PKG "rpm")
+ set(DEBUG_PKG "rpm")
+elseif(GENERATOR_TYPE STREQUAL "DEB")
+ set(NAME "debuginfo")
+ set(DEBUG_SUFFIX "dbgsym")
+ set(PKG "deb")
+ set(DEBUG_PKG "ddeb")
+endif()
+
+set(EXPECTED_FILE_1_NAME "${NAME}")
+set(EXPECTED_FILE_1_COMPONENT "applications")
+set(EXPECTED_FILE_CONTENT_1_LIST "/foo;/foo/test_prog")
+
+set(EXPECTED_FILE_2 "TestDinfo-pkg*-headers.${PKG}")
+set(EXPECTED_FILE_CONTENT_2_LIST "/bar;/bar/CMakeLists.txt")
+
+set(EXPECTED_FILE_3 "TestDinfo-pkg*-libs.${PKG}")
+set(EXPECTED_FILE_CONTENT_3_LIST "/bas;/bas/libtest_lib.so")
+
+set(EXPECTED_FILE_4 "${NAME}-applications-${DEBUG_SUFFIX}*.${DEBUG_PKG}")
+if(GENERATOR_TYPE STREQUAL "RPM")
+ set(EXPECTED_FILE_CONTENT_4 ".*/src${whitespaces_}/src/src_1${whitespaces_}/src/src_1/main.cpp.*\.debug.*")
+elseif(GENERATOR_TYPE STREQUAL "DEB")
+ set(EXPECTED_FILE_CONTENT_4 ".*/usr/lib/debug/.build-id/.*\.debug.*")
+endif()
+
+if(GENERATOR_TYPE STREQUAL "RPM")
+ set(EXPECTED_FILE_5 "libs-DebugInfoPackage.rpm")
+ set(EXPECTED_FILE_CONTENT_5 ".*/src${whitespaces_}/src/src_1${whitespaces_}/src/src_1/test_lib.cpp.*\.debug.*")
+elseif(GENERATOR_TYPE STREQUAL "DEB")
+ set(EXPECTED_FILE_5 "TestDinfo-pkg-libs-dbgsym.ddeb")
+ set(EXPECTED_FILE_CONTENT_5 ".*/usr/lib/debug/.build-id/.*\.debug.*")
+endif()
diff --git a/Tests/RunCMake/CPack/tests/DEBUGINFO/test.cmake b/Tests/RunCMake/CPack/tests/DEBUGINFO/test.cmake
new file mode 100644
index 0000000..161a36a
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/DEBUGINFO/test.cmake
@@ -0,0 +1,48 @@
+set(CMAKE_BUILD_WITH_INSTALL_RPATH 1)
+
+# PGI compiler doesn't add build id to binaries by default
+if(CMAKE_CXX_COMPILER_ID STREQUAL "PGI")
+ string(APPEND CMAKE_EXE_LINKER_FLAGS "-Wl,--build-id")
+ string(APPEND CMAKE_SHARED_LINKER_FLAGS "-Wl,--build-id")
+endif()
+
+set(CMAKE_BUILD_TYPE Debug)
+
+# for rpm packages execute flag must be set for shared libs if debuginfo
+# packages are generated
+set(CPACK_RPM_INSTALL_WITH_EXEC TRUE)
+
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/test_lib.hpp"
+ "int test_lib();\n")
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/test_lib.cpp"
+ "#include \"test_lib.hpp\"\nint test_lib() {return 0;}\n")
+add_library(test_lib SHARED "${CMAKE_CURRENT_BINARY_DIR}/test_lib.cpp")
+
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/main.cpp"
+ "#include \"test_lib.hpp\"\nint main() {return test_lib();}\n")
+add_executable(test_prog "${CMAKE_CURRENT_BINARY_DIR}/main.cpp")
+target_link_libraries(test_prog test_lib)
+
+install(TARGETS test_prog DESTINATION foo COMPONENT applications)
+install(FILES CMakeLists.txt DESTINATION bar COMPONENT headers)
+install(TARGETS test_lib DESTINATION bas COMPONENT libs)
+
+set(CPACK_RPM_APPLICATIONS_FILE_NAME "RPM-DEFAULT")
+set(CPACK_RPM_APPLICATIONS_DEBUGINFO_PACKAGE ON)
+set(CPACK_DEBIAN_APPLICATIONS_FILE_NAME "DEB-DEFAULT")
+set(CPACK_DEBIAN_APPLICATIONS_DEBUGINFO_PACKAGE ON)
+
+# test that components with debuginfo enabled still honor
+# CPACK_PACKAGE_FILE_NAME setting
+set(CPACK_RPM_PACKAGE_NAME "Debuginfo")
+set(CPACK_PACKAGE_FILE_NAME "TestDinfo-pkg")
+set(CPACK_RPM_LIBS_DEBUGINFO_PACKAGE ON)
+set(CPACK_DEBIAN_PACKAGE_NAME "Debuginfo")
+set(CPACK_DEBIAN_LIBS_DEBUGINFO_PACKAGE ON)
+
+# test debuginfo package rename
+set(CPACK_RPM_DEBUGINFO_FILE_NAME
+ "@cpack_component@-DebugInfoPackage.rpm")
+set(CPACK_RPM_APPLICATIONS_DEBUGINFO_FILE_NAME "RPM-DEFAULT")
+
+set(CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX "/src")
diff --git a/Tests/RunCMake/CPack/tests/DEB_DESCRIPTION/ExpectedFiles.cmake b/Tests/RunCMake/CPack/tests/DEB_DESCRIPTION/ExpectedFiles.cmake
new file mode 100644
index 0000000..39f18a3
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/DEB_DESCRIPTION/ExpectedFiles.cmake
@@ -0,0 +1,16 @@
+set(EXPECTED_FILES_COUNT_MONOLITHIC "1")
+set(EXPECTED_FILES_COUNT_COMPONENT "2")
+set(EXPECTED_FILES_COUNT "${EXPECTED_FILES_COUNT_${PACKAGING_TYPE}}")
+
+if(PACKAGING_TYPE STREQUAL "COMPONENT")
+ set(EXPECTED_FILE_1 "deb_description-0.1.1-*-satu.deb")
+ set(EXPECTED_FILE_2 "deb_description-0.1.1-*-dua.deb")
+ set(EXPECTED_FILE_CONTENT_1_LIST "/satu;/satu/CMakeLists.txt")
+ set(EXPECTED_FILE_CONTENT_2_LIST "/dua;/dua/CMakeLists.txt")
+
+elseif(PACKAGING_TYPE STREQUAL "MONOLITHIC")
+ set(EXPECTED_FILE_CONTENT_1_LIST "/dua;/dua/CMakeLists.txt;/satu;/satu/CMakeLists.txt")
+
+endif()
+
+# kate: indent-width 2;
diff --git a/Tests/RunCMake/CPack/tests/DEB_DESCRIPTION/VerifyResult.cmake b/Tests/RunCMake/CPack/tests/DEB_DESCRIPTION/VerifyResult.cmake
new file mode 100644
index 0000000..bfe2059
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/DEB_DESCRIPTION/VerifyResult.cmake
@@ -0,0 +1,69 @@
+function(checkPackageDescription FILE EXPECTED_DESCRIPTION)
+ getPackageInfo("${FILE}" "_file_info")
+ string(UUID uuid NAMESPACE 00000000-0000-0000-0000-000000000000 TYPE SHA1)
+ string(REPLACE ";" "${uuid}" _file_info "${_file_info}")
+ string(REPLACE ";" "${uuid}" EXPECTED_DESCRIPTION "${EXPECTED_DESCRIPTION}")
+ string(REPLACE "\n" ";" _file_info "${_file_info}")
+
+ set(_actual_description)
+ set(_parse_description FALSE)
+ foreach(_line IN LISTS _file_info)
+ if(_line MATCHES " Description:.*")
+ set(_parse_description TRUE)
+ list(APPEND _actual_description "${_line}")
+ elseif(_parse_description)
+ if(_line MATCHES " [A-Z][A-Za-z\-]+: .*")
+ set(_parse_description FALSE)
+ else()
+ list(APPEND _actual_description "${_line}")
+ endif()
+ endif()
+ endforeach()
+ list(JOIN _actual_description "\n" _actual_description)
+
+ if(NOT _actual_description STREQUAL EXPECTED_DESCRIPTION)
+ set(_error "---[BEGIN Expected description]---\n${EXPECTED_DESCRIPTION}---[END Expected description]---\n")
+ string(APPEND _error "---[BEGIN Actual description]---\n${_actual_description}---[END Actual description]---\n")
+ string(REPLACE "${uuid}" ";" _error "${_error}")
+ message(FATAL_ERROR "${_error}")
+ endif()
+endfunction()
+
+# ALERT The output of `dpkg -I *.deb` indented by one space
+set(_expected_description [[ Description: This is the summary line
+ This is the Debian package multiline description.
+ .
+ It must be formatted properly! Otherwise, the result `*.deb`
+ package become broken and cant be installed!
+ .
+ It may contains `;` characters (even like this `;;;;`). Example:
+ .
+ - one;
+ - two;
+ - three;
+ .
+ ... and they are properly handled by the automatic description formatter!
+ .
+ See also: https://www.debian.org/doc/debian-policy/ch-controlfields.html#description]])
+
+# ATTENTION The code in `cmCPackGenerator.cxx` to read `CPACK_PACKAGE_DESCRIPTION_FILE`
+# has a BUG: it appends the `\n` character to every line of the
+# input, even if there was no EOL (e.g. at the last line of the file).
+# That is WHY for this sub-test the one more pre-formatted "empty"
+# line required!
+# NOTE For component based installers content of the file gonna read by
+# `CPackDeb` module and the `file(READ...)` command so no the mentioned
+# workaround required!
+if(RunCMake_SUBTEST_SUFFIX STREQUAL "CPACK_PACKAGE_DESCRIPTION_FILE" AND PACKAGING_TYPE STREQUAL "MONOLITHIC")
+ string(APPEND _expected_description "\n ." )
+elseif(RunCMake_SUBTEST_SUFFIX STREQUAL "CPACK_NO_PACKAGE_DESCRIPTION")
+ set(_expected_description [[ Description: This is the summary line]])
+elseif(RunCMake_SUBTEST_SUFFIX STREQUAL "CPACK_COMPONENT_COMP_DESCRIPTION")
+ set(_expected_description [[ Description: One line description]])
+endif()
+
+foreach(_file_no RANGE 1 ${EXPECTED_FILES_COUNT})
+ checkPackageDescription("${FOUND_FILE_${_file_no}}" "${_expected_description}")
+endforeach()
+
+# kate: indent-width 2;
diff --git a/Tests/RunCMake/CPack/tests/DEB_DESCRIPTION/test.cmake b/Tests/RunCMake/CPack/tests/DEB_DESCRIPTION/test.cmake
new file mode 100644
index 0000000..893eb01
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/DEB_DESCRIPTION/test.cmake
@@ -0,0 +1,55 @@
+install(FILES CMakeLists.txt DESTINATION satu COMPONENT satu)
+install(FILES CMakeLists.txt DESTINATION dua COMPONENT dua)
+
+set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "This is the summary line")
+set(_description [[This is the Debian package multiline description.
+
+It must be formatted properly! Otherwise, the result `*.deb`
+package become broken and cant be installed!
+
+It may contains `;` characters (even like this `;;;;`). Example:
+
+ - one;
+ - two;
+ - three;
+
+... and they are properly handled by the automatic description formatter!
+
+See also: https://www.debian.org/doc/debian-policy/ch-controlfields.html#description]])
+
+if(RunCMake_SUBTEST_SUFFIX STREQUAL "CPACK_DEBIAN_PACKAGE_DESCRIPTION")
+ if(PACKAGING_TYPE STREQUAL "COMPONENT")
+ set(CPACK_DEBIAN_SATU_DESCRIPTION "${_description}")
+ set(CPACK_DEBIAN_DUA_DESCRIPTION "${_description}")
+ else()
+ set(CPACK_DEBIAN_PACKAGE_DESCRIPTION "${_description}")
+ endif()
+
+elseif(RunCMake_SUBTEST_SUFFIX STREQUAL "CPACK_PACKAGE_DESCRIPTION")
+ # NOTE Documented fallback variable
+ if(PACKAGING_TYPE STREQUAL "COMPONENT")
+ set(CPACK_COMPONENT_SATU_DESCRIPTION "${_description}")
+ set(CPACK_COMPONENT_DUA_DESCRIPTION "${_description}")
+ else()
+ set(CPACK_PACKAGE_DESCRIPTION "${_description}")
+ endif()
+
+elseif(RunCMake_SUBTEST_SUFFIX STREQUAL "CPACK_COMPONENT_COMP_DESCRIPTION")
+ # NOTE Documented fallback variable without CPACK_PACKAGE_DESCRIPTION_SUMMARY
+ if(PACKAGING_TYPE STREQUAL "COMPONENT")
+ set(CPACK_COMPONENT_SATU_DESCRIPTION "One line description")
+ set(CPACK_COMPONENT_DUA_DESCRIPTION "One line description")
+ else()
+ set(CPACK_PACKAGE_DESCRIPTION "One line description")
+ endif()
+ unset(CPACK_PACKAGE_DESCRIPTION_SUMMARY)
+
+elseif(RunCMake_SUBTEST_SUFFIX STREQUAL "CPACK_PACKAGE_DESCRIPTION_FILE")
+ # NOTE Getting the description from the file
+ set(_file "${CMAKE_CURRENT_BINARY_DIR}/description.txt")
+ file(WRITE "${_file}" "${_description}")
+ set(CPACK_PACKAGE_DESCRIPTION_FILE "${_file}")
+
+endif()
+
+# kate: indent-width 2;
diff --git a/Tests/RunCMake/CPack/tests/DEB_PACKAGE_VERSION_BACK_COMPATIBILITY/ExpectedFiles.cmake b/Tests/RunCMake/CPack/tests/DEB_PACKAGE_VERSION_BACK_COMPATIBILITY/ExpectedFiles.cmake
new file mode 100644
index 0000000..d1a3a5f
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/DEB_PACKAGE_VERSION_BACK_COMPATIBILITY/ExpectedFiles.cmake
@@ -0,0 +1,2 @@
+set(EXPECTED_FILES_COUNT "1")
+set(EXPECTED_FILE_CONTENT_1_LIST "/foo;/foo/CMakeLists.txt")
diff --git a/Tests/RunCMake/CPack/tests/DEB_PACKAGE_VERSION_BACK_COMPATIBILITY/VerifyResult.cmake b/Tests/RunCMake/CPack/tests/DEB_PACKAGE_VERSION_BACK_COMPATIBILITY/VerifyResult.cmake
new file mode 100644
index 0000000..771cc10
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/DEB_PACKAGE_VERSION_BACK_COMPATIBILITY/VerifyResult.cmake
@@ -0,0 +1,11 @@
+function(checkPackageInfo_ TYPE FILE REGEX)
+ getPackageInfo("${FILE}" "FILE_INFO_")
+ if(NOT FILE_INFO_ MATCHES "${REGEX}")
+ message(FATAL_ERROR "Unexpected ${TYPE} in '${FILE}' ${EXPECTED_FILE_1_VERSION} ${EXPECTED_FILE_1_REVISION}; file info: '${FILE_INFO_}'")
+ endif()
+endfunction()
+
+set(whitespaces_ "[\t\n\r ]*")
+
+checkPackageInfo_("version" "${FOUND_FILE_1}"
+ ".*Version${whitespaces_}:${whitespaces_}5.0.1-71-g884852e")
diff --git a/Tests/RunCMake/CPack/tests/DEB_PACKAGE_VERSION_BACK_COMPATIBILITY/test.cmake b/Tests/RunCMake/CPack/tests/DEB_PACKAGE_VERSION_BACK_COMPATIBILITY/test.cmake
new file mode 100644
index 0000000..403e60d
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/DEB_PACKAGE_VERSION_BACK_COMPATIBILITY/test.cmake
@@ -0,0 +1,7 @@
+install(FILES CMakeLists.txt DESTINATION foo COMPONENT test)
+
+set(CPACK_DEBIAN_PACKAGE_VERSION "5.0.1-71-g884852e")
+
+if(PACKAGING_TYPE STREQUAL "COMPONENT")
+ set(CPACK_COMPONENTS_ALL test)
+endif()
diff --git a/Tests/RunCMake/CPack/tests/DEFAULT_PERMISSIONS/ExpectedFiles.cmake b/Tests/RunCMake/CPack/tests/DEFAULT_PERMISSIONS/ExpectedFiles.cmake
new file mode 100644
index 0000000..b6fcc17
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/DEFAULT_PERMISSIONS/ExpectedFiles.cmake
@@ -0,0 +1,6 @@
+if(${RunCMake_SUBTEST_SUFFIX} MATCHES "invalid_.*_var")
+ set(EXPECTED_FILES_COUNT "0")
+else()
+ set(EXPECTED_FILES_COUNT "1")
+ set(EXPECTED_FILE_CONTENT_1_LIST "/foo;/foo/CMakeLists.txt")
+endif()
diff --git a/Tests/RunCMake/CPack/tests/DEFAULT_PERMISSIONS/VerifyResult.cmake b/Tests/RunCMake/CPack/tests/DEFAULT_PERMISSIONS/VerifyResult.cmake
new file mode 100644
index 0000000..16ebcdc
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/DEFAULT_PERMISSIONS/VerifyResult.cmake
@@ -0,0 +1,39 @@
+if(NOT ${RunCMake_SUBTEST_SUFFIX} MATCHES "invalid_.*_var")
+ if(GENERATOR_TYPE STREQUAL "RPM")
+ function(checkContentPermissions_ FILE REGEX)
+ execute_process(COMMAND ${RPM_EXECUTABLE} -qp --dump ${FILE}
+ WORKING_DIRECTORY "${CPACK_TEMPORARY_DIRECTORY}"
+ OUTPUT_VARIABLE PERMISSIONS_
+ ERROR_QUIET
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+ if(NOT PERMISSIONS_ MATCHES "${REGEX}")
+ message(FATAL_ERROR "Permissions in '${FILE}'. Permissions: '${PERMISSIONS_}'")
+ endif()
+ endfunction()
+
+ if(${RunCMake_SUBTEST_SUFFIX} MATCHES "CMAKE_var_set")
+ checkContentPermissions_("${FOUND_FILE_1}"
+ "/usr/foo .*740 root root.*")
+ else()
+ checkContentPermissions_("${FOUND_FILE_1}"
+ "/usr/foo .*700 root root.*")
+ endif()
+ else() # DEB
+ function(checkContentPermissions_ FILE REGEX)
+ getPackageContent("${FILE}" PERMISSIONS_)
+
+ if(NOT PERMISSIONS_ MATCHES "${REGEX}")
+ message(FATAL_ERROR "Permissions in '${FILE}'. Permissions: '${PERMISSIONS_}'")
+ endif()
+ endfunction()
+
+ if(${RunCMake_SUBTEST_SUFFIX} MATCHES "CMAKE_var_set")
+ checkContentPermissions_("${FOUND_FILE_1}"
+ "drwxr----- root/root .* ./usr/\ndrwxr----- root/root .* ./usr/foo/\n.*")
+ else()
+ checkContentPermissions_("${FOUND_FILE_1}"
+ "drwx------ root/root .* ./usr/\ndrwx------ root/root .* ./usr/foo/\n.*")
+ endif()
+ endif()
+endif()
diff --git a/Tests/RunCMake/CPack/tests/DEFAULT_PERMISSIONS/invalid_CMAKE_var-stderr.txt b/Tests/RunCMake/CPack/tests/DEFAULT_PERMISSIONS/invalid_CMAKE_var-stderr.txt
new file mode 100644
index 0000000..541763a
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/DEFAULT_PERMISSIONS/invalid_CMAKE_var-stderr.txt
@@ -0,0 +1 @@
+.*CPACK_INSTALL_DEFAULT_DIRECTORY_PERMISSIONS value is invalid.*
diff --git a/Tests/RunCMake/CPack/tests/DEFAULT_PERMISSIONS/invalid_CPACK_var-stderr.txt b/Tests/RunCMake/CPack/tests/DEFAULT_PERMISSIONS/invalid_CPACK_var-stderr.txt
new file mode 100644
index 0000000..541763a
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/DEFAULT_PERMISSIONS/invalid_CPACK_var-stderr.txt
@@ -0,0 +1 @@
+.*CPACK_INSTALL_DEFAULT_DIRECTORY_PERMISSIONS value is invalid.*
diff --git a/Tests/RunCMake/CPack/tests/DEFAULT_PERMISSIONS/test.cmake b/Tests/RunCMake/CPack/tests/DEFAULT_PERMISSIONS/test.cmake
new file mode 100644
index 0000000..afe9390
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/DEFAULT_PERMISSIONS/test.cmake
@@ -0,0 +1,34 @@
+if(${RunCMake_SUBTEST_SUFFIX} MATCHES "CMAKE_var_set" OR
+ ${RunCMake_SUBTEST_SUFFIX} MATCHES "both_set")
+
+ set(CMAKE_INSTALL_DEFAULT_DIRECTORY_PERMISSIONS
+ OWNER_READ
+ OWNER_WRITE
+ OWNER_EXECUTE
+ GROUP_READ
+ )
+endif()
+
+if(${RunCMake_SUBTEST_SUFFIX} MATCHES "invalid_CMAKE_var")
+ list(APPEND CMAKE_INSTALL_DEFAULT_DIRECTORY_PERMISSIONS "INVALID")
+endif()
+
+if(${RunCMake_SUBTEST_SUFFIX} MATCHES "CPACK_var_set" OR
+ ${RunCMake_SUBTEST_SUFFIX} MATCHES "both_set")
+
+ set(CPACK_INSTALL_DEFAULT_DIRECTORY_PERMISSIONS
+ OWNER_READ
+ OWNER_WRITE
+ OWNER_EXECUTE
+ )
+endif()
+
+if(${RunCMake_SUBTEST_SUFFIX} MATCHES "invalid_CPACK_var")
+ list(APPEND CPACK_INSTALL_DEFAULT_DIRECTORY_PERMISSIONS "INVALID")
+endif()
+
+install(FILES CMakeLists.txt DESTINATION foo COMPONENT test)
+
+if(PACKAGING_TYPE STREQUAL "COMPONENT")
+ set(CPACK_COMPONENTS_ALL test)
+endif()
diff --git a/Tests/RunCMake/CPack/tests/DEPENDENCIES/DEB-stderr.txt b/Tests/RunCMake/CPack/tests/DEPENDENCIES/DEB-stderr.txt
new file mode 100644
index 0000000..5df274a
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/DEPENDENCIES/DEB-stderr.txt
@@ -0,0 +1 @@
+^CPackDeb: ((- Generating dependency list)|(Using only user-provided dependencies because dpkg-shlibdeps is not found\.))$
diff --git a/Tests/RunCMake/CPack/tests/DEPENDENCIES/ExpectedFiles.cmake b/Tests/RunCMake/CPack/tests/DEPENDENCIES/ExpectedFiles.cmake
new file mode 100644
index 0000000..be7ba07
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/DEPENDENCIES/ExpectedFiles.cmake
@@ -0,0 +1,18 @@
+set(EXPECTED_FILES_COUNT "5")
+set(EXPECTED_FILE_1_COMPONENT "applications")
+set(EXPECTED_FILE_CONTENT_1_LIST "/foo;/foo/test_prog")
+set(EXPECTED_FILE_2_COMPONENT "applications_auto")
+set(EXPECTED_FILE_CONTENT_2_LIST "/foo_auto;/foo_auto/test_prog")
+set(EXPECTED_FILE_3_COMPONENT "headers")
+set(EXPECTED_FILE_CONTENT_3_LIST "/bar;/bar/CMakeLists.txt")
+set(EXPECTED_FILE_4_COMPONENT "libs")
+set(EXPECTED_FILE_CONTENT_4_LIST "/bas;/bas/libtest_lib.so")
+set(EXPECTED_FILE_5_COMPONENT "libs_auto")
+set(EXPECTED_FILE_CONTENT_5_LIST "/bas_auto;/bas_auto/libtest_lib.so")
+
+if(GENERATOR_TYPE STREQUAL "DEB")
+ set(whitespaces_ "[\t\n\r ]*")
+ # dynamic lib extension is .so on Linux and .dylib on Mac so we will use a wildcard .* for it
+ set(EXPECTED_FILE_CONTENT_4 "^.*/usr/bas${whitespaces_}.*/usr/bas/libtest_lib\\..*$")
+ set(EXPECTED_FILE_CONTENT_5 "^.*/usr/bas_auto${whitespaces_}.*/usr/bas_auto/libtest_lib\\..*$")
+endif()
diff --git a/Tests/RunCMake/CPack/tests/DEPENDENCIES/VerifyResult.cmake b/Tests/RunCMake/CPack/tests/DEPENDENCIES/VerifyResult.cmake
new file mode 100644
index 0000000..7923148
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/DEPENDENCIES/VerifyResult.cmake
@@ -0,0 +1,82 @@
+if(GENERATOR_TYPE STREQUAL "DEB")
+ function(checkDependencies_ FILE REGEX)
+ set(whitespaces_ "[\t\n\r ]*")
+
+ getPackageInfo("${FILE}" "FILE_INFO_")
+ if(NOT FILE_INFO_ MATCHES "${REGEX}")
+ message(FATAL_ERROR "Unexpected dependencies in '${FILE}'; file info: '${FILE_INFO_}'")
+ endif()
+ endfunction()
+
+ foreach(dependency_type_ DEPENDS CONFLICTS ENHANCES BREAKS REPLACES RECOMMENDS SUGGESTS)
+ string(TOLOWER "${dependency_type_}" lower_dependency_type_)
+ string(SUBSTRING ${lower_dependency_type_} 1 -1 lower_dependency_type_tail_)
+ string(SUBSTRING ${dependency_type_} 0 1 dependency_type_head_)
+ set(dependency_type_name_ "${dependency_type_head_}${lower_dependency_type_tail_}")
+
+ checkDependencies_("${FOUND_FILE_1}" ".*${dependency_type_name_}${whitespaces_}:${whitespaces_}${lower_dependency_type_}-application, ${lower_dependency_type_}-application-b.*")
+ checkDependencies_("${FOUND_FILE_2}" ".*${dependency_type_name_}${whitespaces_}:${whitespaces_}.*${lower_dependency_type_}-application, ${lower_dependency_type_}-application-b.*")
+ checkDependencies_("${FOUND_FILE_3}" ".*${dependency_type_name_}${whitespaces_}:${whitespaces_}${lower_dependency_type_}-headers.*")
+ checkDependencies_("${FOUND_FILE_4}" ".*${dependency_type_name_}${whitespaces_}:${whitespaces_}${lower_dependency_type_}-default, ${lower_dependency_type_}-default-b.*")
+ checkDependencies_("${FOUND_FILE_5}" ".*${dependency_type_name_}${whitespaces_}:${whitespaces_}${lower_dependency_type_}-default, ${lower_dependency_type_}-default-b.*")
+ endforeach()
+
+ checkDependencies_("${FOUND_FILE_1}" ".*Provides${whitespaces_}:${whitespaces_}provided-default, provided-default-b")
+ checkDependencies_("${FOUND_FILE_2}" ".*Provides${whitespaces_}:${whitespaces_}provided-default, provided-default-b")
+ checkDependencies_("${FOUND_FILE_3}" ".*Provides${whitespaces_}:${whitespaces_}provided-default, provided-default-b")
+ checkDependencies_("${FOUND_FILE_4}" ".*Provides${whitespaces_}:${whitespaces_}provided-lib.*")
+ checkDependencies_("${FOUND_FILE_5}" ".*Provides${whitespaces_}:${whitespaces_}provided-lib_auto.*, provided-lib_auto-b.*")
+
+ # PREDEPENDS
+ checkDependencies_("${FOUND_FILE_1}" ".*Pre-Depends${whitespaces_}:${whitespaces_}predepends-application, predepends-application-b.*")
+ checkDependencies_("${FOUND_FILE_2}" ".*Pre-Depends${whitespaces_}:${whitespaces_}.*predepends-application, predepends-application-b.*")
+ checkDependencies_("${FOUND_FILE_3}" ".*Pre-Depends${whitespaces_}:${whitespaces_}predepends-headers.*")
+ checkDependencies_("${FOUND_FILE_4}" ".*Pre-Depends${whitespaces_}:${whitespaces_}predepends-default, predepends-default-b.*")
+ checkDependencies_("${FOUND_FILE_5}" ".*Pre-Depends${whitespaces_}:${whitespaces_}predepends-default, predepends-default-b.*")
+elseif(GENERATOR_TYPE STREQUAL "RPM")
+ function(checkDependencies_ FILE TYPE COMPARE_LIST)
+ set(whitespaces_ "[\t\n\r ]*")
+
+ execute_process(COMMAND ${RPM_EXECUTABLE} -qp --${TYPE} ${FILE}
+ WORKING_DIRECTORY "${CPACK_TEMPORARY_DIRECTORY}"
+ OUTPUT_VARIABLE FILE_DEPENDENCIES_
+ ERROR_QUIET
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+ string(REPLACE "\n" ";" FILE_DEPENDENCIES_LIST_ "${FILE_DEPENDENCIES_}")
+
+ foreach(COMPARE_REGEX_ IN LISTS COMPARE_LIST)
+ unset(FOUND_)
+
+ foreach(COMPARE_ IN LISTS FILE_DEPENDENCIES_LIST_)
+ if(COMPARE_ MATCHES "${COMPARE_REGEX_}")
+ set(FOUND_ true)
+ break()
+ endif()
+ endforeach()
+
+ if(NOT FOUND_)
+ message(FATAL_ERROR "Missing dependencies in '${FILE}'; check type: '${TYPE}'; file info: '${FILE_DEPENDENCIES_}'; missing: '${COMPARE_REGEX_}'")
+ endif()
+ endforeach()
+ endfunction()
+
+ # TODO add tests for what should not be present in lists
+ checkDependencies_("${FOUND_FILE_1}" "requires" "depend-application;depend-application-b")
+ checkDependencies_("${FOUND_FILE_2}" "requires" "depend-application;depend-application-b;libtest_lib\\.so.*")
+ checkDependencies_("${FOUND_FILE_3}" "requires" "depend-headers")
+ checkDependencies_("${FOUND_FILE_4}" "requires" "depend-default;depend-default-b")
+ checkDependencies_("${FOUND_FILE_5}" "requires" "depend-default;depend-default-b")
+
+ checkDependencies_("${FOUND_FILE_1}" "conflicts" "conflicts-application;conflicts-application-b")
+ checkDependencies_("${FOUND_FILE_2}" "conflicts" "conflicts-application;conflicts-application-b")
+ checkDependencies_("${FOUND_FILE_3}" "conflicts" "conflicts-headers")
+ checkDependencies_("${FOUND_FILE_4}" "conflicts" "conflicts-default;conflicts-default-b")
+ checkDependencies_("${FOUND_FILE_5}" "conflicts" "conflicts-default;conflicts-default-b")
+
+ checkDependencies_("${FOUND_FILE_1}" "provides" "provided-default;provided-default-b")
+ checkDependencies_("${FOUND_FILE_2}" "provides" "provided-default;provided-default-b")
+ checkDependencies_("${FOUND_FILE_3}" "provides" "provided-default;provided-default-b")
+ checkDependencies_("${FOUND_FILE_4}" "provides" "provided-lib")
+ checkDependencies_("${FOUND_FILE_5}" "provides" "provided-lib_auto;provided-lib_auto-b")
+endif()
diff --git a/Tests/RunCMake/CPack/tests/DEPENDENCIES/test.cmake b/Tests/RunCMake/CPack/tests/DEPENDENCIES/test.cmake
new file mode 100644
index 0000000..fbd786e
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/DEPENDENCIES/test.cmake
@@ -0,0 +1,60 @@
+if(GENERATOR_TYPE STREQUAL "DEB" OR GENERATOR_TYPE STREQUAL "RPM")
+ if(GENERATOR_TYPE STREQUAL "DEB")
+ # false by default
+ set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS FALSE)
+ # FIXME can not be tested as libraries first have to be part of a package in order
+ # to determine their dependencies and we can not be certain if there will be any
+ set(CPACK_DEBIAN_APPLICATIONS_AUTO_PACKAGE_SHLIBDEPS TRUE)
+
+ foreach(dependency_type_ DEPENDS PREDEPENDS ENHANCES BREAKS REPLACES RECOMMENDS SUGGESTS)
+ string(TOLOWER "${dependency_type_}" lower_dependency_type_)
+
+ set(CPACK_DEBIAN_PACKAGE_${dependency_type_} "${lower_dependency_type_}-default, ${lower_dependency_type_}-default-b")
+ set(CPACK_DEBIAN_APPLICATIONS_PACKAGE_${dependency_type_} "${lower_dependency_type_}-application, ${lower_dependency_type_}-application-b")
+ set(CPACK_DEBIAN_APPLICATIONS_AUTO_PACKAGE_${dependency_type_} "${lower_dependency_type_}-application, ${lower_dependency_type_}-application-b")
+ set(CPACK_DEBIAN_HEADERS_PACKAGE_${dependency_type_} "${lower_dependency_type_}-headers")
+ endforeach()
+
+ set(generator_type_suffix_ "IAN") # not entirely compatible...
+ else() # RPM
+ # FIXME auto autoprov is not tested at the moment as Ubuntu 15.04 rpmbuild
+ # does not use them correctly: https://bugs.launchpad.net/rpm/+bug/1475755
+ set(CPACK_RPM_PACKAGE_AUTOREQ "no")
+ set(CPACK_RPM_PACKAGE_AUTOPROV "no")
+ set(CPACK_RPM_APPLICATIONS_AUTO_PACKAGE_AUTOREQPROV "yes")
+ set(CPACK_RPM_LIBS_AUTO_PACKAGE_AUTOREQPROV "yes")
+
+ set(CPACK_RPM_PACKAGE_REQUIRES "depend-default, depend-default-b")
+ set(CPACK_RPM_APPLICATIONS_PACKAGE_REQUIRES "depend-application, depend-application-b")
+ set(CPACK_RPM_APPLICATIONS_AUTO_PACKAGE_REQUIRES "depend-application, depend-application-b")
+ set(CPACK_RPM_HEADERS_PACKAGE_REQUIRES "depend-headers")
+ endif()
+
+ set(CPACK_${GENERATOR_TYPE}${generator_type_suffix_}_PACKAGE_CONFLICTS "conflicts-default, conflicts-default-b")
+ set(CPACK_${GENERATOR_TYPE}${generator_type_suffix_}_APPLICATIONS_PACKAGE_CONFLICTS "conflicts-application, conflicts-application-b")
+ set(CPACK_${GENERATOR_TYPE}${generator_type_suffix_}_APPLICATIONS_AUTO_PACKAGE_CONFLICTS "conflicts-application, conflicts-application-b")
+ set(CPACK_${GENERATOR_TYPE}${generator_type_suffix_}_HEADERS_PACKAGE_CONFLICTS "conflicts-headers")
+
+ set(CPACK_${GENERATOR_TYPE}${generator_type_suffix_}_PACKAGE_PROVIDES "provided-default, provided-default-b")
+ set(CPACK_${GENERATOR_TYPE}${generator_type_suffix_}_LIBS_PACKAGE_PROVIDES "provided-lib")
+ set(CPACK_${GENERATOR_TYPE}${generator_type_suffix_}_LIBS_AUTO_PACKAGE_PROVIDES "provided-lib_auto, provided-lib_auto-b")
+endif()
+
+set(CMAKE_BUILD_WITH_INSTALL_RPATH 1)
+
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/test_lib.hpp"
+ "int test_lib();\n")
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/test_lib.cpp"
+ "#include \"test_lib.hpp\"\nint test_lib() {return 0;}\n")
+add_library(test_lib SHARED "${CMAKE_CURRENT_BINARY_DIR}/test_lib.cpp")
+
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/main.cpp"
+ "#include \"test_lib.hpp\"\nint main() {return test_lib();}\n")
+add_executable(test_prog "${CMAKE_CURRENT_BINARY_DIR}/main.cpp")
+target_link_libraries(test_prog test_lib)
+
+install(TARGETS test_prog DESTINATION foo COMPONENT applications)
+install(TARGETS test_prog DESTINATION foo_auto COMPONENT applications_auto)
+install(FILES CMakeLists.txt DESTINATION bar COMPONENT headers)
+install(TARGETS test_lib DESTINATION bas COMPONENT libs)
+install(TARGETS test_lib DESTINATION bas_auto COMPONENT libs_auto)
diff --git a/Tests/RunCMake/CPack/tests/DIST/ExpectedFiles.cmake b/Tests/RunCMake/CPack/tests/DIST/ExpectedFiles.cmake
new file mode 100644
index 0000000..d1a3a5f
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/DIST/ExpectedFiles.cmake
@@ -0,0 +1,2 @@
+set(EXPECTED_FILES_COUNT "1")
+set(EXPECTED_FILE_CONTENT_1_LIST "/foo;/foo/CMakeLists.txt")
diff --git a/Tests/RunCMake/CPack/tests/DIST/VerifyResult.cmake b/Tests/RunCMake/CPack/tests/DIST/VerifyResult.cmake
new file mode 100644
index 0000000..1b2eb48
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/DIST/VerifyResult.cmake
@@ -0,0 +1,16 @@
+execute_process(COMMAND ${RPMBUILD_EXECUTABLE} -E %{?dist}
+ OUTPUT_VARIABLE DIST_TAG
+ ERROR_QUIET
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+set(whitespaces_ "[\t\n\r ]*")
+
+# since we have no control over dist tag value we should try to escape
+# the content for use as a regular expression
+string(REPLACE "+" "\\+" DIST_TAG "${DIST_TAG}")
+string(REPLACE "." "\\." DIST_TAG "${DIST_TAG}")
+
+getPackageInfo("${FOUND_FILE_1}" "FILE_INFO_")
+if(NOT FILE_INFO_ MATCHES ".*Release${whitespaces_}:${whitespaces_}1${DIST_TAG}")
+ message(FATAL_ERROR "Unexpected Release in '${FOUND_FILE_1}'; file info: '${FILE_INFO_}'")
+endif()
diff --git a/Tests/RunCMake/CPack/tests/DIST/test.cmake b/Tests/RunCMake/CPack/tests/DIST/test.cmake
new file mode 100644
index 0000000..6bdd2c0
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/DIST/test.cmake
@@ -0,0 +1,3 @@
+install(FILES CMakeLists.txt DESTINATION foo COMPONENT test)
+
+set(CPACK_RPM_PACKAGE_RELEASE_DIST ON)
diff --git a/Tests/RunCMake/CPack/tests/EMPTY_DIR/ExpectedFiles.cmake b/Tests/RunCMake/CPack/tests/EMPTY_DIR/ExpectedFiles.cmake
new file mode 100644
index 0000000..8df6831
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/EMPTY_DIR/ExpectedFiles.cmake
@@ -0,0 +1,7 @@
+set(EXPECTED_FILES_COUNT "1")
+set(EXPECTED_FILES_NAME_GENERATOR_SPECIFIC_FORMAT TRUE)
+set(EXPECTED_FILE_CONTENT_1_LIST "/empty")
+
+if(PACKAGING_TYPE STREQUAL "COMPONENT")
+ set(EXPECTED_FILE_1_COMPONENT "test")
+endif()
diff --git a/Tests/RunCMake/CPack/tests/EMPTY_DIR/test.cmake b/Tests/RunCMake/CPack/tests/EMPTY_DIR/test.cmake
new file mode 100644
index 0000000..cd2c9fd
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/EMPTY_DIR/test.cmake
@@ -0,0 +1,14 @@
+if(GENERATOR_TYPE STREQUAL "DEB" OR GENERATOR_TYPE STREQUAL "RPM")
+ if(GENERATOR_TYPE STREQUAL "DEB")
+ set(generator_type_suffix_ "IAN") # not entirely compatible...
+ endif()
+
+ set(CPACK_${GENERATOR_TYPE}${generator_type_suffix_}_FILE_NAME "${GENERATOR_TYPE}-DEFAULT")
+endif()
+
+install(DIRECTORY DESTINATION empty
+ COMPONENT test)
+
+if(PACKAGING_TYPE STREQUAL "COMPONENT")
+ set(CPACK_COMPONENTS_ALL test)
+endif()
diff --git a/Tests/RunCMake/CPack/tests/EXTERNAL/ExpectedFiles.cmake b/Tests/RunCMake/CPack/tests/EXTERNAL/ExpectedFiles.cmake
new file mode 100644
index 0000000..91608c9
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/EXTERNAL/ExpectedFiles.cmake
@@ -0,0 +1,7 @@
+if(RunCMake_SUBTEST_SUFFIX MATCHES "^(none|good(_multi)?|invalid_good)$"
+ OR RunCMake_SUBTEST_SUFFIX STREQUAL "stage_and_package")
+ set(EXPECTED_FILES_COUNT "1")
+ set(EXPECTED_FILE_CONTENT_1_LIST "/share;/share/cpack-test;/share/cpack-test/f1.txt;/share/cpack-test/f2.txt;/share/cpack-test/f3.txt;/share/cpack-test/f4.txt")
+else()
+ set(EXPECTED_FILES_COUNT "0")
+endif()
diff --git a/Tests/RunCMake/CPack/tests/EXTERNAL/VerifyResult.cmake b/Tests/RunCMake/CPack/tests/EXTERNAL/VerifyResult.cmake
new file mode 100644
index 0000000..bc19d7e
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/EXTERNAL/VerifyResult.cmake
@@ -0,0 +1,3 @@
+if(RunCMake_SUBTEST_SUFFIX MATCHES "^(none|good(_multi)?|invalid_good)")
+ check_ext_json("${src_dir}/tests/EXTERNAL/expected-json-1.0.txt" "${FOUND_FILE_1}")
+endif()
diff --git a/Tests/RunCMake/CPack/tests/EXTERNAL/bad_major-stderr.txt b/Tests/RunCMake/CPack/tests/EXTERNAL/bad_major-stderr.txt
new file mode 100644
index 0000000..f2e160e
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/EXTERNAL/bad_major-stderr.txt
@@ -0,0 +1,6 @@
+CMake Error at .*/Modules/Internal/CPack/CPackExternal\.cmake:[0-9]+ \(message\):
+ Could not find a suitable version in CPACK_EXTERNAL_REQUESTED_VERSIONS
+
+
+CPack Error: Error while executing CPackExternal\.cmake
+CPack Error: Cannot initialize the generator External
diff --git a/Tests/RunCMake/CPack/tests/EXTERNAL/bad_minor-stderr.txt b/Tests/RunCMake/CPack/tests/EXTERNAL/bad_minor-stderr.txt
new file mode 100644
index 0000000..f2e160e
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/EXTERNAL/bad_minor-stderr.txt
@@ -0,0 +1,6 @@
+CMake Error at .*/Modules/Internal/CPack/CPackExternal\.cmake:[0-9]+ \(message\):
+ Could not find a suitable version in CPACK_EXTERNAL_REQUESTED_VERSIONS
+
+
+CPack Error: Error while executing CPackExternal\.cmake
+CPack Error: Cannot initialize the generator External
diff --git a/Tests/RunCMake/CPack/tests/EXTERNAL/create_package.cmake b/Tests/RunCMake/CPack/tests/EXTERNAL/create_package.cmake
new file mode 100644
index 0000000..6f7c4c2
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/EXTERNAL/create_package.cmake
@@ -0,0 +1,31 @@
+message("This script could run an external packaging tool")
+
+get_property(role GLOBAL PROPERTY CMAKE_ROLE)
+if(NOT role STREQUAL "CPACK")
+ message(SEND_ERROR "CMAKE_ROLE property is \"${role}\", should be \"CPACK\"")
+endif()
+
+function(expect_variable VAR)
+ if(NOT ${VAR})
+ message(FATAL_ERROR "${VAR} is unexpectedly not set")
+ endif()
+endfunction()
+
+function(expect_file FILE)
+ if(NOT EXISTS "${FILE}")
+ message(FATAL_ERROR "${FILE} is unexpectedly missing")
+ endif()
+endfunction()
+
+expect_variable(CPACK_COMPONENTS_ALL)
+expect_variable(CPACK_TOPLEVEL_DIRECTORY)
+expect_variable(CPACK_TEMPORARY_DIRECTORY)
+expect_variable(CPACK_PACKAGE_DIRECTORY)
+expect_variable(CPACK_PACKAGE_FILE_NAME)
+
+expect_file(${CPACK_TEMPORARY_DIRECTORY}/f1/share/cpack-test/f1.txt)
+expect_file(${CPACK_TEMPORARY_DIRECTORY}/f2/share/cpack-test/f2.txt)
+expect_file(${CPACK_TEMPORARY_DIRECTORY}/f3/share/cpack-test/f3.txt)
+expect_file(${CPACK_TEMPORARY_DIRECTORY}/f4/share/cpack-test/f4.txt)
+
+message(STATUS "This status message is expected to be visible")
diff --git a/Tests/RunCMake/CPack/tests/EXTERNAL/expected-json-1.0.txt b/Tests/RunCMake/CPack/tests/EXTERNAL/expected-json-1.0.txt
new file mode 100644
index 0000000..ca25b1e
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/EXTERNAL/expected-json-1.0.txt
@@ -0,0 +1,177 @@
+^\{
+ ("buildConfig" : "Debug",
+)? "componentGroups" :[ ]
+ \{
+ "f12" :[ ]
+ \{
+ "components" :[ ]
+ \[
+ "f1",
+ "f2"
+ \],
+ "description" : "Component group for files 1 and 2",
+ "displayName" : "Files 1 and 2",
+ "isBold" : false,
+ "isExpandedByDefault" : false,
+ "name" : "f12",
+ "parentGroup" : "f1234",
+ "subgroups" : \[\]
+ \},
+ "f1234" :[ ]
+ \{
+ "components" : \[\],
+ "description" : "Component group for all files",
+ "displayName" : "Files 1-4",
+ "isBold" : false,
+ "isExpandedByDefault" : false,
+ "name" : "f1234",
+ "subgroups" :[ ]
+ \[
+ "f12",
+ "f34"
+ \]
+ \},
+ "f34" :[ ]
+ \{
+ "components" :[ ]
+ \[
+ "f3",
+ "f4"
+ \],
+ "description" : "Component group for files 3 and 4",
+ "displayName" : "Files 3 and 4",
+ "isBold" : false,
+ "isExpandedByDefault" : false,
+ "name" : "f34",
+ "parentGroup" : "f1234",
+ "subgroups" : \[\]
+ \}
+ \},
+ "components" :[ ]
+ \{
+ "f1" :[ ]
+ \{
+ "archiveFile" : "",
+ "dependencies" : \[\],
+ "description" : "Component for file 1",
+ "displayName" : "File 1",
+ "group" : "f12",
+ "installationTypes" :[ ]
+ \[
+ "full",
+ "f12"
+ \],
+ "isDisabledByDefault" : false,
+ "isDownloaded" : false,
+ "isHidden" : false,
+ "isRequired" : false,
+ "name" : "f1"
+ \},
+ "f2" :[ ]
+ \{
+ "archiveFile" : "",
+ "dependencies" :[ ]
+ \[
+ "f1"
+ \],
+ "description" : "Component for file 2",
+ "displayName" : "File 2",
+ "group" : "f12",
+ "installationTypes" :[ ]
+ \[
+ "full",
+ "f12"
+ \],
+ "isDisabledByDefault" : false,
+ "isDownloaded" : false,
+ "isHidden" : false,
+ "isRequired" : false,
+ "name" : "f2"
+ \},
+ "f3" :[ ]
+ \{
+ "archiveFile" : "",
+ "dependencies" :[ ]
+ \[
+ "f1",
+ "f2"
+ \],
+ "description" : "Component for file 3",
+ "displayName" : "File 3",
+ "group" : "f34",
+ "installationTypes" :[ ]
+ \[
+ "full"
+ \],
+ "isDisabledByDefault" : false,
+ "isDownloaded" : false,
+ "isHidden" : false,
+ "isRequired" : false,
+ "name" : "f3"
+ \},
+ "f4" :[ ]
+ \{
+ "archiveFile" : "",
+ "dependencies" :[ ]
+ \[
+ "f2",
+ "f3",
+ "f1"
+ \],
+ "description" : "Component for file 4",
+ "displayName" : "File 4",
+ "group" : "f34",
+ "installationTypes" :[ ]
+ \[
+ "full"
+ \],
+ "isDisabledByDefault" : false,
+ "isDownloaded" : false,
+ "isHidden" : false,
+ "isRequired" : false,
+ "name" : "f4"
+ \}
+ \},
+ "errorOnAbsoluteInstallDestination" : false,
+ "formatVersionMajor" : 1,
+ "formatVersionMinor" : 0,
+ "installationTypes" :[ ]
+ \{
+ "f12" :[ ]
+ \{
+ "displayName" : "Only files 1 and 2",
+ "index" : 2,
+ "name" : "f12"
+ \},
+ "full" :[ ]
+ \{
+ "displayName" : "Full installation",
+ "index" : 1,
+ "name" : "full"
+ \}
+ \},
+ "packageDescriptionFile" : ".*/Templates/CPack\.GenericDescription\.txt",
+ "packageDescriptionSummary" : "EXTERNAL-(none|good(_multi)?|invalid_good)-subtest-(MONOLITHIC|COMPONENT)-type built using CMake",
+ "packageName" : "external",
+ "packageVersion" : "0\.1\.1",
+ "projects" :[ ]
+ \[
+ \{
+ "component" : "ALL",
+ "components" :[ ]
+ \[
+ "f1",
+ "f2",
+ "f3",
+ "f4"
+ \],
+ "directory" : ".*/Tests/RunCMake/External/CPack/EXTERNAL-build-(none|good(_multi)?|invalid_good)-subtest",
+ "installationTypes" : \[\],
+ "projectName" : "EXTERNAL-(none|good(_multi)?|invalid_good)-subtest-(MONOLITHIC|COMPONENT)-type",
+ "subDirectory" : "/"
+ \}
+ \],
+ "setDestdir" : false,
+ "stripFiles" : false,
+ "warnOnAbsoluteInstallDestination" : false
+\}$
diff --git a/Tests/RunCMake/CPack/tests/EXTERNAL/invalid_bad-stderr.txt b/Tests/RunCMake/CPack/tests/EXTERNAL/invalid_bad-stderr.txt
new file mode 100644
index 0000000..f2e160e
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/EXTERNAL/invalid_bad-stderr.txt
@@ -0,0 +1,6 @@
+CMake Error at .*/Modules/Internal/CPack/CPackExternal\.cmake:[0-9]+ \(message\):
+ Could not find a suitable version in CPACK_EXTERNAL_REQUESTED_VERSIONS
+
+
+CPack Error: Error while executing CPackExternal\.cmake
+CPack Error: Cannot initialize the generator External
diff --git a/Tests/RunCMake/CPack/tests/EXTERNAL/stage_and_package-stderr.txt b/Tests/RunCMake/CPack/tests/EXTERNAL/stage_and_package-stderr.txt
new file mode 100644
index 0000000..40f2743
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/EXTERNAL/stage_and_package-stderr.txt
@@ -0,0 +1 @@
+^This script could run an external packaging tool$
diff --git a/Tests/RunCMake/CPack/tests/EXTERNAL/stage_and_package-stdout.txt b/Tests/RunCMake/CPack/tests/EXTERNAL/stage_and_package-stdout.txt
new file mode 100644
index 0000000..37d635f
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/EXTERNAL/stage_and_package-stdout.txt
@@ -0,0 +1 @@
+-- This status message is expected to be visible
diff --git a/Tests/RunCMake/CPack/tests/EXTERNAL/test.cmake b/Tests/RunCMake/CPack/tests/EXTERNAL/test.cmake
new file mode 100644
index 0000000..bc9766b
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/EXTERNAL/test.cmake
@@ -0,0 +1,86 @@
+include(CPackComponent)
+
+if(RunCMake_SUBTEST_SUFFIX STREQUAL "none")
+ unset(CPACK_EXTERNAL_REQUESTED_VERSIONS)
+elseif(RunCMake_SUBTEST_SUFFIX STREQUAL "good")
+ set(CPACK_EXTERNAL_REQUESTED_VERSIONS "1.0")
+elseif(RunCMake_SUBTEST_SUFFIX STREQUAL "good_multi")
+ set(CPACK_EXTERNAL_REQUESTED_VERSIONS "1.0;2.0")
+elseif(RunCMake_SUBTEST_SUFFIX STREQUAL "bad_major")
+ set(CPACK_EXTERNAL_REQUESTED_VERSIONS "2.0")
+elseif(RunCMake_SUBTEST_SUFFIX STREQUAL "bad_minor")
+ set(CPACK_EXTERNAL_REQUESTED_VERSIONS "1.1")
+elseif(RunCMake_SUBTEST_SUFFIX STREQUAL "invalid_good")
+ set(CPACK_EXTERNAL_REQUESTED_VERSIONS "1;1.0")
+elseif(RunCMake_SUBTEST_SUFFIX STREQUAL "invalid_bad")
+ set(CPACK_EXTERNAL_REQUESTED_VERSIONS "1")
+elseif(RunCMake_SUBTEST_SUFFIX STREQUAL "stage_and_package")
+ set(CPACK_EXTERNAL_ENABLE_STAGING 1)
+ set(CPACK_EXTERNAL_PACKAGE_SCRIPT "${CMAKE_CURRENT_LIST_DIR}/create_package.cmake")
+endif()
+
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/f1.txt" test1)
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/f2.txt" test2)
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/f3.txt" test3)
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/f4.txt" test4)
+
+install(FILES "${CMAKE_CURRENT_BINARY_DIR}/f1.txt" DESTINATION share/cpack-test COMPONENT f1)
+install(FILES "${CMAKE_CURRENT_BINARY_DIR}/f2.txt" DESTINATION share/cpack-test COMPONENT f2)
+install(FILES "${CMAKE_CURRENT_BINARY_DIR}/f3.txt" DESTINATION share/cpack-test COMPONENT f3)
+install(FILES "${CMAKE_CURRENT_BINARY_DIR}/f4.txt" DESTINATION share/cpack-test COMPONENT f4)
+
+cpack_add_component(f1
+ DISPLAY_NAME "File 1"
+ DESCRIPTION "Component for file 1"
+ GROUP f12
+ INSTALL_TYPES full f12
+)
+
+cpack_add_component(f2
+ DISPLAY_NAME "File 2"
+ DESCRIPTION "Component for file 2"
+ GROUP f12
+ DEPENDS f1
+ INSTALL_TYPES full f12
+)
+
+cpack_add_component(f3
+ DISPLAY_NAME "File 3"
+ DESCRIPTION "Component for file 3"
+ GROUP f34
+ DEPENDS f1 f2
+ INSTALL_TYPES full
+)
+
+cpack_add_component(f4
+ DISPLAY_NAME "File 4"
+ DESCRIPTION "Component for file 4"
+ GROUP f34
+ DEPENDS f2 f3 f1
+ INSTALL_TYPES full
+)
+
+cpack_add_component_group(f12
+ DISPLAY_NAME "Files 1 and 2"
+ DESCRIPTION "Component group for files 1 and 2"
+ PARENT_GROUP f1234
+)
+
+cpack_add_component_group(f34
+ DISPLAY_NAME "Files 3 and 4"
+ DESCRIPTION "Component group for files 3 and 4"
+ PARENT_GROUP f1234
+)
+
+cpack_add_component_group(f1234
+ DISPLAY_NAME "Files 1-4"
+ DESCRIPTION "Component group for all files"
+)
+
+cpack_add_install_type(full
+ DISPLAY_NAME "Full installation"
+)
+
+cpack_add_install_type(f12
+ DISPLAY_NAME "Only files 1 and 2"
+)
diff --git a/Tests/RunCMake/CPack/tests/EXTRA/ExpectedFiles.cmake b/Tests/RunCMake/CPack/tests/EXTRA/ExpectedFiles.cmake
new file mode 100644
index 0000000..407cbe6
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/EXTRA/ExpectedFiles.cmake
@@ -0,0 +1,8 @@
+set(EXPECTED_FILES_COUNT "3")
+set(EXPECTED_FILES_NAME_GENERATOR_SPECIFIC_FORMAT TRUE)
+set(EXPECTED_FILE_1_COMPONENT "foo")
+set(EXPECTED_FILE_CONTENT_1_LIST "/foo;/foo/CMakeLists.txt")
+set(EXPECTED_FILE_2_COMPONENT "bar")
+set(EXPECTED_FILE_CONTENT_2_LIST "/bar;/bar/CMakeLists.txt")
+set(EXPECTED_FILE_3_COMPONENT "bas")
+set(EXPECTED_FILE_CONTENT_3_LIST "/bas;/bas/CMakeLists.txt")
diff --git a/Tests/RunCMake/CPack/tests/EXTRA/VerifyResult.cmake b/Tests/RunCMake/CPack/tests/EXTRA/VerifyResult.cmake
new file mode 100644
index 0000000..85e137f
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/EXTRA/VerifyResult.cmake
@@ -0,0 +1,18 @@
+set(foo_preinst "^echo default_preinst$")
+# NOTE: optional dot at the end of permissions regex is for SELinux enabled systems
+set(foo_preinst_permissions_regex "-rwxr-xr-x\.? .*")
+set(foo_prerm "^echo default_prerm$")
+set(foo_prerm_permissions_regex "-rwxr-xr-x\.? .*")
+verifyDebControl("${FOUND_FILE_1}" "foo" "preinst;prerm")
+
+set(bar_preinst "^echo bar_preinst$")
+set(bar_preinst_permissions_regex "-rwx------\.? .*")
+set(bar_prerm "^echo bar_prerm$")
+set(bar_prerm_permissions_regex "-rwx------\.? .*")
+verifyDebControl("${FOUND_FILE_2}" "bar" "preinst;prerm")
+
+set(bas_preinst "^echo default_preinst$")
+set(bas_preinst_permissions_regex "-rwxr-xr-x\.? .*")
+set(bas_prerm "^echo default_prerm$")
+set(bas_prerm_permissions_regex "-rwxr-xr-x\.? .*")
+verifyDebControl("${FOUND_FILE_3}" "bas" "preinst;prerm")
diff --git a/Tests/RunCMake/CPack/tests/EXTRA/test.cmake b/Tests/RunCMake/CPack/tests/EXTRA/test.cmake
new file mode 100644
index 0000000..efa6dac
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/EXTRA/test.cmake
@@ -0,0 +1,35 @@
+install(FILES CMakeLists.txt DESTINATION foo COMPONENT foo)
+install(FILES CMakeLists.txt DESTINATION bar COMPONENT bar)
+install(FILES CMakeLists.txt DESTINATION bas COMPONENT bas)
+
+file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/tmp/preinst "echo default_preinst")
+file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/tmp/prerm "echo default_prerm")
+
+foreach(file_ preinst prerm)
+ file(COPY ${CMAKE_CURRENT_BINARY_DIR}/tmp/${file_}
+ DESTINATION ${CMAKE_CURRENT_BINARY_DIR}
+ FILE_PERMISSIONS
+ OWNER_READ OWNER_WRITE OWNER_EXECUTE
+ GROUP_READ GROUP_EXECUTE
+ WORLD_READ WORLD_EXECUTE)
+endforeach()
+
+set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA
+ "${CMAKE_CURRENT_BINARY_DIR}/preinst;${CMAKE_CURRENT_BINARY_DIR}/prerm;${CMAKE_CURRENT_BINARY_DIR}/conffiles")
+
+file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/bar_tmp/preinst "echo bar_preinst")
+file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/bar_tmp/prerm "echo bar_prerm")
+
+foreach(file_ preinst prerm)
+ # not acceptable permissions for lintian but we need to check that
+ # permissions are preserved
+ file(COPY ${CMAKE_CURRENT_BINARY_DIR}/bar_tmp/${file_}
+ DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/bar
+ FILE_PERMISSIONS
+ OWNER_READ OWNER_WRITE OWNER_EXECUTE)
+endforeach()
+
+set(CPACK_DEBIAN_BAR_PACKAGE_CONTROL_EXTRA
+ "${CMAKE_CURRENT_BINARY_DIR}/bar/preinst;${CMAKE_CURRENT_BINARY_DIR}/bar/prerm")
+
+set(CPACK_DEBIAN_FILE_NAME "DEB-DEFAULT")
diff --git a/Tests/RunCMake/CPack/tests/EXTRA_SLASH_IN_PATH/ExpectedFiles.cmake b/Tests/RunCMake/CPack/tests/EXTRA_SLASH_IN_PATH/ExpectedFiles.cmake
new file mode 100644
index 0000000..3fb0534
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/EXTRA_SLASH_IN_PATH/ExpectedFiles.cmake
@@ -0,0 +1,17 @@
+set(whitespaces_ "[\t\n\r ]*")
+
+set(EXPECTED_FILES_COUNT "5")
+set(EXPECTED_FILES_NAME_GENERATOR_SPECIFIC_FORMAT TRUE)
+set(EXPECTED_FILE_PACKAGING_PREFIX "")
+
+set(EXPECTED_FILE_1_COMPONENT "applications")
+set(EXPECTED_FILE_CONTENT_1_LIST "/foo;/foo/test_prog")
+set(EXPECTED_FILE_2 "extra_slash_in_path*-headers.rpm")
+set(EXPECTED_FILE_CONTENT_2_LIST "/bar;/bar/CMakeLists.txt")
+set(EXPECTED_FILE_3 "extra_slash_in_path*-libs.rpm")
+set(EXPECTED_FILE_CONTENT_3_LIST "/bas;/bas/libtest_lib.so")
+
+set(EXPECTED_FILE_4_COMPONENT "applications-debuginfo")
+set(EXPECTED_FILE_CONTENT_4 ".*/src${whitespaces_}/src/src_1${whitespaces_}/src/src_1/main.cpp.*\.debug.*")
+set(EXPECTED_FILE_5_COMPONENT "libs-debuginfo")
+set(EXPECTED_FILE_CONTENT_5 ".*/src${whitespaces_}/src/src_1${whitespaces_}/src/src_1/test_lib.cpp.*\.debug.*")
diff --git a/Tests/RunCMake/CPack/tests/EXTRA_SLASH_IN_PATH/VerifyResult.cmake b/Tests/RunCMake/CPack/tests/EXTRA_SLASH_IN_PATH/VerifyResult.cmake
new file mode 100644
index 0000000..bfef720
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/EXTRA_SLASH_IN_PATH/VerifyResult.cmake
@@ -0,0 +1,7 @@
+# check that relocation path is /foo and not //foo
+getPackageInfo("${FOUND_FILE_1}" "FILE_INFO_")
+set(whitespaces_ "[\t\n\r ]*")
+if(NOT FILE_INFO_ MATCHES "Relocations${whitespaces_}:${whitespaces_}/${whitespaces_}/foo")
+ message(FATAL_ERROR "Unexpected relocation path in file '${FOUND_FILE_1}';"
+ " file info: '${FILE_INFO_}'")
+endif()
diff --git a/Tests/RunCMake/CPack/tests/EXTRA_SLASH_IN_PATH/test.cmake b/Tests/RunCMake/CPack/tests/EXTRA_SLASH_IN_PATH/test.cmake
new file mode 100644
index 0000000..7cee188
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/EXTRA_SLASH_IN_PATH/test.cmake
@@ -0,0 +1,41 @@
+set(CMAKE_BUILD_WITH_INSTALL_RPATH 1)
+
+# PGI compiler doesn't add build id to binaries by default
+if(CMAKE_CXX_COMPILER_ID STREQUAL "PGI")
+ string(APPEND CMAKE_EXE_LINKER_FLAGS "-Wl,--build-id")
+ string(APPEND CMAKE_SHARED_LINKER_FLAGS "-Wl,--build-id")
+endif()
+
+set(CMAKE_BUILD_TYPE Debug)
+
+# for rpm packages execute flag must be set for shared libs if debuginfo
+# packages are generated
+set(CPACK_RPM_INSTALL_WITH_EXEC TRUE)
+
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/test_lib.hpp"
+ "int test_lib();\n")
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/test_lib.cpp"
+ "#include \"test_lib.hpp\"\nint test_lib() {return 0;}\n")
+add_library(test_lib SHARED "${CMAKE_CURRENT_BINARY_DIR}/test_lib.cpp")
+
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/main.cpp"
+ "#include \"test_lib.hpp\"\nint main() {return test_lib();}\n")
+add_executable(test_prog "${CMAKE_CURRENT_BINARY_DIR}/main.cpp")
+target_link_libraries(test_prog test_lib)
+
+install(TARGETS test_prog DESTINATION foo COMPONENT applications)
+install(FILES CMakeLists.txt DESTINATION bar COMPONENT headers)
+install(TARGETS test_lib DESTINATION bas COMPONENT libs)
+
+set(CPACK_RPM_APPLICATIONS_FILE_NAME "RPM-DEFAULT")
+set(CPACK_RPM_APPLICATIONS_DEBUGINFO_PACKAGE ON)
+set(CPACK_RPM_LIBS_DEBUGINFO_PACKAGE ON)
+
+# extra trailing slash at the end that should be removed
+set(CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX "/src/")
+
+# combination should not cause //foo to apper as an relocation path
+# should be only /foo (extra slashes cause path comparisons to fail)
+set(CPACK_PACKAGING_INSTALL_PREFIX "/")
+# extra trailing slash at the end that should be removed
+set(CPACK_RPM_RELOCATION_PATHS "foo/")
diff --git a/Tests/RunCMake/CPack/tests/GENERATE_SHLIBS/DEB-Prerequirements.cmake b/Tests/RunCMake/CPack/tests/GENERATE_SHLIBS/DEB-Prerequirements.cmake
new file mode 100644
index 0000000..be44b2e
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/GENERATE_SHLIBS/DEB-Prerequirements.cmake
@@ -0,0 +1,7 @@
+function(get_test_prerequirements found_var config_file)
+ include(${config_file})
+
+ if(READELF_EXECUTABLE)
+ set(${found_var} true PARENT_SCOPE)
+ endif()
+endfunction()
diff --git a/Tests/RunCMake/CPack/tests/GENERATE_SHLIBS/ExpectedFiles.cmake b/Tests/RunCMake/CPack/tests/GENERATE_SHLIBS/ExpectedFiles.cmake
new file mode 100644
index 0000000..ccb5ef0
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/GENERATE_SHLIBS/ExpectedFiles.cmake
@@ -0,0 +1,6 @@
+set(whitespaces_ "[\t\n\r ]*")
+
+set(EXPECTED_FILES_COUNT "1")
+set(EXPECTED_FILES_NAME_GENERATOR_SPECIFIC_FORMAT TRUE)
+# dynamic lib extension is .so on Linux and .dylib on Mac so we will use a wildcard .* for it
+set(EXPECTED_FILE_CONTENT_1 "^.*/usr/foo${whitespaces_}.*/usr/foo/libtest_lib\\..*$")
diff --git a/Tests/RunCMake/CPack/tests/GENERATE_SHLIBS/VerifyResult.cmake b/Tests/RunCMake/CPack/tests/GENERATE_SHLIBS/VerifyResult.cmake
new file mode 100644
index 0000000..8cefeea
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/GENERATE_SHLIBS/VerifyResult.cmake
@@ -0,0 +1,9 @@
+if(RunCMake_SUBTEST_SUFFIX STREQUAL "soversion_not_zero")
+ set(shlibs_shlibs "^libtest_lib 0\\.8 generate_shlibs \\(\\= 0\\.1\\.1\\)\n$")
+else() # soversion_zero
+ set(shlibs_shlibs "^libtest_lib 0 generate_shlibs \\(\\= 0\\.1\\.1\\)\n$")
+endif()
+
+# optional dot at the end of permissions regex is for SELinux enabled systems
+set(shlibs_shlibs_permissions_regex "-rw-r--r--\.? .*")
+verifyDebControl("${FOUND_FILE_1}" "shlibs" "shlibs")
diff --git a/Tests/RunCMake/CPack/tests/GENERATE_SHLIBS/test.cmake b/Tests/RunCMake/CPack/tests/GENERATE_SHLIBS/test.cmake
new file mode 100644
index 0000000..e0eb67b
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/GENERATE_SHLIBS/test.cmake
@@ -0,0 +1,19 @@
+set(CPACK_DEBIAN_FILE_NAME "DEB-DEFAULT")
+
+set(CPACK_DEBIAN_PACKAGE_GENERATE_SHLIBS "ON")
+
+set(CMAKE_BUILD_WITH_INSTALL_RPATH 1)
+
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/test_lib.hpp"
+ "int test_lib();\n")
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/test_lib.cpp"
+ "#include \"test_lib.hpp\"\nint test_lib() {return 0;}\n")
+add_library(test_lib SHARED "${CMAKE_CURRENT_BINARY_DIR}/test_lib.cpp")
+
+if(RunCMake_SUBTEST_SUFFIX STREQUAL "soversion_not_zero")
+ set_target_properties(test_lib PROPERTIES SOVERSION "0.8")
+else() # soversion_zero
+ set_target_properties(test_lib PROPERTIES SOVERSION "0")
+endif()
+
+install(TARGETS test_lib DESTINATION foo COMPONENT libs)
diff --git a/Tests/RunCMake/CPack/tests/GENERATE_SHLIBS_LDCONFIG/DEB-Prerequirements.cmake b/Tests/RunCMake/CPack/tests/GENERATE_SHLIBS_LDCONFIG/DEB-Prerequirements.cmake
new file mode 100644
index 0000000..be44b2e
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/GENERATE_SHLIBS_LDCONFIG/DEB-Prerequirements.cmake
@@ -0,0 +1,7 @@
+function(get_test_prerequirements found_var config_file)
+ include(${config_file})
+
+ if(READELF_EXECUTABLE)
+ set(${found_var} true PARENT_SCOPE)
+ endif()
+endfunction()
diff --git a/Tests/RunCMake/CPack/tests/GENERATE_SHLIBS_LDCONFIG/ExpectedFiles.cmake b/Tests/RunCMake/CPack/tests/GENERATE_SHLIBS_LDCONFIG/ExpectedFiles.cmake
new file mode 100644
index 0000000..d66c044
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/GENERATE_SHLIBS_LDCONFIG/ExpectedFiles.cmake
@@ -0,0 +1,6 @@
+set(whitespaces_ "[\t\n\r ]*")
+
+set(EXPECTED_FILES_COUNT "1")
+set(EXPECTED_FILES_NAME_GENERATOR_SPECIFIC_FORMAT TRUE)
+# dynamic lib extension is .so on Linux and .dylib on Mac so we will use a wildcard .* for it
+set(EXPECTED_FILE_CONTENT_1 "^.*/usr/lib${whitespaces_}.*/usr/lib/libtest_lib\\..*$")
diff --git a/Tests/RunCMake/CPack/tests/GENERATE_SHLIBS_LDCONFIG/VerifyResult.cmake b/Tests/RunCMake/CPack/tests/GENERATE_SHLIBS_LDCONFIG/VerifyResult.cmake
new file mode 100644
index 0000000..422cfbe
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/GENERATE_SHLIBS_LDCONFIG/VerifyResult.cmake
@@ -0,0 +1,8 @@
+set(shlibs_shlibs "^libtest_lib 0\\.8 generate_shlibs_ldconfig \\(>\\= 0\\.1\\.1\\)\n$")
+# NOTE: optional dot at the end of permissions regex is for SELinux enabled systems
+set(shlibs_shlibs_permissions_regex "-rw-r--r--\.? .*")
+set(shlibs_postinst ".*ldconfig.*")
+set(shlibs_postinst_permissions_regex "-rwxr-xr-x\.? .*")
+set(shlibs_postrm ".*ldconfig.*")
+set(shlibs_postrm_permissions_regex "-rwxr-xr-x\.? .*")
+verifyDebControl("${FOUND_FILE_1}" "shlibs" "shlibs;postinst;postrm")
diff --git a/Tests/RunCMake/CPack/tests/GENERATE_SHLIBS_LDCONFIG/test.cmake b/Tests/RunCMake/CPack/tests/GENERATE_SHLIBS_LDCONFIG/test.cmake
new file mode 100644
index 0000000..15c496b
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/GENERATE_SHLIBS_LDCONFIG/test.cmake
@@ -0,0 +1,15 @@
+set(CPACK_DEBIAN_FILE_NAME "DEB-DEFAULT")
+
+set(CPACK_DEBIAN_PACKAGE_GENERATE_SHLIBS "ON")
+set(CPACK_DEBIAN_PACKAGE_GENERATE_SHLIBS_POLICY ">=")
+
+set(CMAKE_BUILD_WITH_INSTALL_RPATH 1)
+
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/test_lib.hpp"
+ "int test_lib();\n")
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/test_lib.cpp"
+ "#include \"test_lib.hpp\"\nint test_lib() {return 0;}\n")
+add_library(test_lib SHARED "${CMAKE_CURRENT_BINARY_DIR}/test_lib.cpp")
+set_target_properties(test_lib PROPERTIES SOVERSION "0.8")
+
+install(TARGETS test_lib LIBRARY DESTINATION lib COMPONENT libs NAMELINK_SKIP)
diff --git a/Tests/RunCMake/CPack/tests/INSTALL_SCRIPTS/ExpectedFiles.cmake b/Tests/RunCMake/CPack/tests/INSTALL_SCRIPTS/ExpectedFiles.cmake
new file mode 100644
index 0000000..de38df9
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/INSTALL_SCRIPTS/ExpectedFiles.cmake
@@ -0,0 +1,5 @@
+set(EXPECTED_FILES_COUNT "2")
+set(EXPECTED_FILE_1_COMPONENT "foo")
+set(EXPECTED_FILE_CONTENT_1_LIST "/foo;/foo/CMakeLists.txt")
+set(EXPECTED_FILE_2_COMPONENT "bar")
+set(EXPECTED_FILE_CONTENT_2_LIST "/bar;/bar/CMakeLists.txt")
diff --git a/Tests/RunCMake/CPack/tests/INSTALL_SCRIPTS/VerifyResult.cmake b/Tests/RunCMake/CPack/tests/INSTALL_SCRIPTS/VerifyResult.cmake
new file mode 100644
index 0000000..1a1e983
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/INSTALL_SCRIPTS/VerifyResult.cmake
@@ -0,0 +1,29 @@
+function(checkScripts_ FILE COMPARE_LIST)
+ set(whitespaces_ "[\t\n\r ]*")
+
+ execute_process(COMMAND ${RPM_EXECUTABLE} -qp --scripts ${FILE}
+ WORKING_DIRECTORY "${CPACK_TEMPORARY_DIRECTORY}"
+ OUTPUT_VARIABLE FILE_SCRIPTS_
+ ERROR_QUIET
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+ string(REPLACE "\n" ";" FILE_SCRIPTS_LIST_ "${FILE_SCRIPTS_}")
+
+ foreach(COMPARE_REGEX_ IN LISTS COMPARE_LIST)
+ unset(FOUND_)
+
+ foreach(COMPARE_ IN LISTS FILE_SCRIPTS_LIST_)
+ if(COMPARE_ MATCHES "${COMPARE_REGEX_}")
+ set(FOUND_ true)
+ break()
+ endif()
+ endforeach()
+
+ if(NOT FOUND_)
+ message(FATAL_ERROR "Missing scripts in '${FILE}'; file info: '${FILE_SCRIPTS_}'; missing: '${COMPARE_REGEX_}'")
+ endif()
+ endforeach()
+endfunction()
+
+checkScripts_("${FOUND_FILE_1}" "echo \"pre install foo\";echo \"post install foo\";echo \"pre uninstall foo\";echo \"post uninstall foo\";echo \"pre trans foo\";echo \"post trans foo\"")
+checkScripts_("${FOUND_FILE_2}" "echo \"pre install\";echo \"post install\";echo \"pre uninstall\";echo \"post uninstall\";echo \"pre trans\";echo \"post trans\"")
diff --git a/Tests/RunCMake/CPack/tests/INSTALL_SCRIPTS/test.cmake b/Tests/RunCMake/CPack/tests/INSTALL_SCRIPTS/test.cmake
new file mode 100644
index 0000000..c200fa5
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/INSTALL_SCRIPTS/test.cmake
@@ -0,0 +1,60 @@
+if(GENERATOR_TYPE STREQUAL "RPM")
+ set(CPACK_RPM_PRE_INSTALL_SCRIPT_FILE
+ "${CMAKE_CURRENT_BINARY_DIR}/pre_install.sh")
+ set(CPACK_RPM_POST_INSTALL_SCRIPT_FILE
+ "${CMAKE_CURRENT_BINARY_DIR}/post_install.sh")
+ set(CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE
+ "${CMAKE_CURRENT_BINARY_DIR}/pre_uninstall.sh")
+ set(CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE
+ "${CMAKE_CURRENT_BINARY_DIR}/post_uninstall.sh")
+ set(CPACK_RPM_PRE_TRANS_SCRIPT_FILE
+ "${CMAKE_CURRENT_BINARY_DIR}/pre_trans.sh")
+ set(CPACK_RPM_POST_TRANS_SCRIPT_FILE
+ "${CMAKE_CURRENT_BINARY_DIR}/post_trans.sh")
+
+ set(CPACK_RPM_foo_PRE_INSTALL_SCRIPT_FILE
+ "${CMAKE_CURRENT_BINARY_DIR}/pre_install_foo.sh")
+ set(CPACK_RPM_foo_POST_INSTALL_SCRIPT_FILE
+ "${CMAKE_CURRENT_BINARY_DIR}/post_install_foo.sh")
+ set(CPACK_RPM_foo_PRE_UNINSTALL_SCRIPT_FILE
+ "${CMAKE_CURRENT_BINARY_DIR}/pre_uninstall_foo.sh")
+ set(CPACK_RPM_foo_POST_UNINSTALL_SCRIPT_FILE
+ "${CMAKE_CURRENT_BINARY_DIR}/post_uninstall_foo.sh")
+ set(CPACK_RPM_foo_PRE_TRANS_SCRIPT_FILE
+ "${CMAKE_CURRENT_BINARY_DIR}/pre_trans_foo.sh")
+ set(CPACK_RPM_foo_POST_TRANS_SCRIPT_FILE
+ "${CMAKE_CURRENT_BINARY_DIR}/post_trans_foo.sh")
+endif()
+
+set(CMAKE_BUILD_WITH_INSTALL_RPATH 1)
+
+# default
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/pre_install.sh"
+ "echo \"pre install\"\n")
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/post_install.sh"
+ "echo \"post install\"\n")
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/pre_uninstall.sh"
+ "echo \"pre uninstall\"\n")
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/post_uninstall.sh"
+ "echo \"post uninstall\"\n")
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/pre_trans.sh"
+ "echo \"pre trans\"\n")
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/post_trans.sh"
+ "echo \"post trans\"\n")
+
+# specific
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/pre_install_foo.sh"
+ "echo \"pre install foo\"\n")
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/post_install_foo.sh"
+ "echo \"post install foo\"\n")
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/pre_uninstall_foo.sh"
+ "echo \"pre uninstall foo\"\n")
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/post_uninstall_foo.sh"
+ "echo \"post uninstall foo\"\n")
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/pre_trans_foo.sh"
+ "echo \"pre trans foo\"\n")
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/post_trans_foo.sh"
+ "echo \"post trans foo\"\n")
+
+install(FILES CMakeLists.txt DESTINATION foo COMPONENT foo)
+install(FILES CMakeLists.txt DESTINATION bar COMPONENT bar)
diff --git a/Tests/RunCMake/CPack/tests/LONG_FILENAMES/DEB-Prerequirements.cmake b/Tests/RunCMake/CPack/tests/LONG_FILENAMES/DEB-Prerequirements.cmake
new file mode 100644
index 0000000..ddd16e5
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/LONG_FILENAMES/DEB-Prerequirements.cmake
@@ -0,0 +1,7 @@
+function(get_test_prerequirements found_var config_file)
+ include(${config_file})
+
+ if(FAKEROOT_EXECUTABLE)
+ set(${found_var} true PARENT_SCOPE)
+ endif()
+endfunction()
diff --git a/Tests/RunCMake/CPack/tests/LONG_FILENAMES/ExpectedFiles.cmake b/Tests/RunCMake/CPack/tests/LONG_FILENAMES/ExpectedFiles.cmake
new file mode 100644
index 0000000..4cb8dd0
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/LONG_FILENAMES/ExpectedFiles.cmake
@@ -0,0 +1,3 @@
+set(EXPECTED_FILES_COUNT "1")
+set(EXPECTED_FILES_NAME_GENERATOR_SPECIFIC_FORMAT TRUE)
+set(EXPECTED_FILE_CONTENT_1_LIST "/foo;/foo/llllllllll_oooooooooo_nnnnnnnnnn_gggggggggg_ffffffffff_iiiiiiiiii_llllllllll_eeeeeeeeee_nnnnnnnnnn_aaaaaaaaaa_mmmmmmmmmm_eeeeeeeeee.txt")
diff --git a/Tests/RunCMake/CPack/tests/LONG_FILENAMES/VerifyResult.cmake b/Tests/RunCMake/CPack/tests/LONG_FILENAMES/VerifyResult.cmake
new file mode 100644
index 0000000..0452343
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/LONG_FILENAMES/VerifyResult.cmake
@@ -0,0 +1,26 @@
+# create structure required by non root dpkg install
+file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/root_dir")
+file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/root_dir/admindir")
+file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/root_dir/admindir/updates")
+file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/root_dir/admindir/info")
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/root_dir/admindir/available" "")
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/root_dir/admindir/status" "")
+
+# some programs used by fakeroot require sbin in path so we should not
+# leave this to chance (programs: ldconfig and start-stop-daemon)
+set(ENV{PATH} "$ENV{PATH}:/usr/local/sbin:/usr/sbin:/sbin")
+
+execute_process(COMMAND ${FAKEROOT_EXECUTABLE} ${DPKG_EXECUTABLE}
+ -i --force-not-root --root=${CMAKE_CURRENT_BINARY_DIR}/root_dir
+ --admindir=${CMAKE_CURRENT_BINARY_DIR}/root_dir/admindir
+ --log=${CMAKE_CURRENT_BINARY_DIR}/root_dir/dpkg.log
+ ${FOUND_FILE_1}
+ RESULT_VARIABLE install_result_
+ ERROR_VARIABLE install_error_
+ OUTPUT_QUIET
+ )
+
+if(install_result_)
+ message(FATAL_ERROR "LONG_FILENAMES package error - result:"
+ " '${install_result_}'; text: '${install_error_}'")
+endif()
diff --git a/Tests/RunCMake/CPack/tests/LONG_FILENAMES/test.cmake b/Tests/RunCMake/CPack/tests/LONG_FILENAMES/test.cmake
new file mode 100644
index 0000000..f235d47
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/LONG_FILENAMES/test.cmake
@@ -0,0 +1,13 @@
+if(GENERATOR_TYPE STREQUAL "DEB")
+ set(CPACK_DEBIAN_FILE_NAME "DEB-DEFAULT")
+ set(CPACK_DEBIAN_ARCHIVE_TYPE "gnutar")
+endif()
+
+set(LONG_FILENAME
+ "${CMAKE_CURRENT_BINARY_DIR}/llllllllll_oooooooooo_nnnnnnnnnn_gggggggggg_ffffffffff_iiiiiiiiii_llllllllll_eeeeeeeeee_nnnnnnnnnn_aaaaaaaaaa_mmmmmmmmmm_eeeeeeeeee.txt")
+
+file(WRITE
+ "${LONG_FILENAME}"
+ "long_filename_test")
+
+install(FILES ${LONG_FILENAME} DESTINATION foo)
diff --git a/Tests/RunCMake/CPack/tests/MAIN_COMPONENT/ExpectedFiles.cmake b/Tests/RunCMake/CPack/tests/MAIN_COMPONENT/ExpectedFiles.cmake
new file mode 100644
index 0000000..629be9e
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/MAIN_COMPONENT/ExpectedFiles.cmake
@@ -0,0 +1,11 @@
+set(EXPECTED_FILES_COUNT "0")
+
+if(NOT RunCMake_SUBTEST_SUFFIX STREQUAL "invalid")
+ set(EXPECTED_FILES_COUNT "3")
+ set(EXPECTED_FILE_1 "main_component-0.1.1-1.*.rpm")
+ set(EXPECTED_FILE_CONTENT_1_LIST "/foo;/foo/CMakeLists.txt")
+ set(EXPECTED_FILE_2_COMPONENT "headers")
+ set(EXPECTED_FILE_CONTENT_2_LIST "/bar;/bar/CMakeLists.txt")
+ set(EXPECTED_FILE_3_COMPONENT "libs")
+ set(EXPECTED_FILE_CONTENT_3_LIST "/bas;/bas/CMakeLists.txt")
+endif()
diff --git a/Tests/RunCMake/CPack/tests/MAIN_COMPONENT/RPM-invalid-stderr.txt b/Tests/RunCMake/CPack/tests/MAIN_COMPONENT/RPM-invalid-stderr.txt
new file mode 100644
index 0000000..4d8ac6e
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/MAIN_COMPONENT/RPM-invalid-stderr.txt
@@ -0,0 +1 @@
+CPACK_RPM_MAIN_COMPONENT set to non existing component.
diff --git a/Tests/RunCMake/CPack/tests/MAIN_COMPONENT/test.cmake b/Tests/RunCMake/CPack/tests/MAIN_COMPONENT/test.cmake
new file mode 100644
index 0000000..791c586
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/MAIN_COMPONENT/test.cmake
@@ -0,0 +1,10 @@
+install(FILES CMakeLists.txt DESTINATION foo COMPONENT applications)
+install(FILES CMakeLists.txt DESTINATION bar COMPONENT headers)
+install(FILES CMakeLists.txt DESTINATION bas COMPONENT libs)
+
+if(RunCMake_SUBTEST_SUFFIX STREQUAL "invalid")
+ set(CPACK_RPM_MAIN_COMPONENT "")
+else()
+ set(CPACK_RPM_MAIN_COMPONENT "applications")
+ set(CPACK_RPM_APPLICATIONS_FILE_NAME "RPM-DEFAULT")
+endif()
diff --git a/Tests/RunCMake/CPack/tests/MD5SUMS/ExpectedFiles.cmake b/Tests/RunCMake/CPack/tests/MD5SUMS/ExpectedFiles.cmake
new file mode 100644
index 0000000..d1a3a5f
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/MD5SUMS/ExpectedFiles.cmake
@@ -0,0 +1,2 @@
+set(EXPECTED_FILES_COUNT "1")
+set(EXPECTED_FILE_CONTENT_1_LIST "/foo;/foo/CMakeLists.txt")
diff --git a/Tests/RunCMake/CPack/tests/MD5SUMS/VerifyResult.cmake b/Tests/RunCMake/CPack/tests/MD5SUMS/VerifyResult.cmake
new file mode 100644
index 0000000..fbdda9c
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/MD5SUMS/VerifyResult.cmake
@@ -0,0 +1,3 @@
+set(whitespaces_ "[\t\n\r ]*")
+set(md5sums_md5sums "^.* usr/foo/CMakeLists\.txt${whitespaces_}$")
+verifyDebControl("${FOUND_FILE_1}" "md5sums" "md5sums")
diff --git a/Tests/RunCMake/CPack/tests/MD5SUMS/test.cmake b/Tests/RunCMake/CPack/tests/MD5SUMS/test.cmake
new file mode 100644
index 0000000..15c5892
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/MD5SUMS/test.cmake
@@ -0,0 +1,5 @@
+install(FILES CMakeLists.txt DESTINATION foo COMPONENT test)
+
+if(PACKAGING_TYPE STREQUAL "COMPONENT")
+ set(CPACK_COMPONENTS_ALL test)
+endif()
diff --git a/Tests/RunCMake/CPack/tests/MINIMAL/ExpectedFiles.cmake b/Tests/RunCMake/CPack/tests/MINIMAL/ExpectedFiles.cmake
new file mode 100644
index 0000000..d1a3a5f
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/MINIMAL/ExpectedFiles.cmake
@@ -0,0 +1,2 @@
+set(EXPECTED_FILES_COUNT "1")
+set(EXPECTED_FILE_CONTENT_1_LIST "/foo;/foo/CMakeLists.txt")
diff --git a/Tests/RunCMake/CPack/tests/MINIMAL/test.cmake b/Tests/RunCMake/CPack/tests/MINIMAL/test.cmake
new file mode 100644
index 0000000..15c5892
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/MINIMAL/test.cmake
@@ -0,0 +1,5 @@
+install(FILES CMakeLists.txt DESTINATION foo COMPONENT test)
+
+if(PACKAGING_TYPE STREQUAL "COMPONENT")
+ set(CPACK_COMPONENTS_ALL test)
+endif()
diff --git a/Tests/RunCMake/CPack/tests/PACKAGE_CHECKSUM/ExpectedFiles.cmake b/Tests/RunCMake/CPack/tests/PACKAGE_CHECKSUM/ExpectedFiles.cmake
new file mode 100644
index 0000000..c375aca
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/PACKAGE_CHECKSUM/ExpectedFiles.cmake
@@ -0,0 +1,6 @@
+set(EXPECTED_FILES_COUNT "0")
+
+if(NOT ${RunCMake_SUBTEST_SUFFIX} MATCHES "invalid")
+ set(EXPECTED_FILES_COUNT "1")
+ set(EXPECTED_FILE_CONTENT_1_LIST "/foo;/foo/CMakeLists.txt")
+endif()
diff --git a/Tests/RunCMake/CPack/tests/PACKAGE_CHECKSUM/TGZ-invalid-stderr.txt b/Tests/RunCMake/CPack/tests/PACKAGE_CHECKSUM/TGZ-invalid-stderr.txt
new file mode 100644
index 0000000..abf6d8c
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/PACKAGE_CHECKSUM/TGZ-invalid-stderr.txt
@@ -0,0 +1,2 @@
+^CPack Error: Cannot recognize algorithm: invalid
+CPack Error: Error when generating package: package_checksum$
diff --git a/Tests/RunCMake/CPack/tests/PACKAGE_CHECKSUM/VerifyResult.cmake b/Tests/RunCMake/CPack/tests/PACKAGE_CHECKSUM/VerifyResult.cmake
new file mode 100644
index 0000000..2bb4d3f
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/PACKAGE_CHECKSUM/VerifyResult.cmake
@@ -0,0 +1,11 @@
+if(NOT ${RunCMake_SUBTEST_SUFFIX} MATCHES "invalid")
+ string(TOLOWER ${RunCMake_SUBTEST_SUFFIX} CHECKSUM_EXTENSION)
+ file(GLOB PACKAGE RELATIVE ${bin_dir} "*.tar.gz")
+ file(STRINGS ${PACKAGE}.${CHECKSUM_EXTENSION} CHSUM_VALUE)
+ file(${RunCMake_SUBTEST_SUFFIX} ${PACKAGE} expected_value )
+ set(expected_value "${expected_value} ${PACKAGE}")
+
+ if(NOT expected_value STREQUAL CHSUM_VALUE)
+ message(FATAL_ERROR "Generated checksum is not valid! Expected [${expected_value}] Got [${CHSUM_VALUE}]")
+ endif()
+endif()
diff --git a/Tests/RunCMake/CPack/tests/PACKAGE_CHECKSUM/test.cmake b/Tests/RunCMake/CPack/tests/PACKAGE_CHECKSUM/test.cmake
new file mode 100644
index 0000000..0838063
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/PACKAGE_CHECKSUM/test.cmake
@@ -0,0 +1,3 @@
+install(FILES CMakeLists.txt DESTINATION foo)
+
+set(CPACK_PACKAGE_CHECKSUM ${RunCMake_SUBTEST_SUFFIX})
diff --git a/Tests/RunCMake/CPack/tests/PARTIALLY_RELOCATABLE_WARNING/ExpectedFiles.cmake b/Tests/RunCMake/CPack/tests/PARTIALLY_RELOCATABLE_WARNING/ExpectedFiles.cmake
new file mode 100644
index 0000000..137da47
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/PARTIALLY_RELOCATABLE_WARNING/ExpectedFiles.cmake
@@ -0,0 +1,4 @@
+set(EXPECTED_FILES_COUNT "1")
+# don't set the prefix here as we have absolute paths that should not be prefixed
+set(EXPECTED_FILE_PACKAGING_PREFIX "")
+set(EXPECTED_FILE_CONTENT_1_LIST "/not_relocatable;/not_relocatable/CMakeLists.txt;/opt")
diff --git a/Tests/RunCMake/CPack/tests/PARTIALLY_RELOCATABLE_WARNING/RPM-stderr.txt b/Tests/RunCMake/CPack/tests/PARTIALLY_RELOCATABLE_WARNING/RPM-stderr.txt
new file mode 100644
index 0000000..3b63d5b
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/PARTIALLY_RELOCATABLE_WARNING/RPM-stderr.txt
@@ -0,0 +1 @@
+CPackRPM:Warning: Path /not_relocatable/CMakeLists.txt is not on one of the.*relocatable paths! Package will be partially relocatable.
diff --git a/Tests/RunCMake/CPack/tests/PARTIALLY_RELOCATABLE_WARNING/test.cmake b/Tests/RunCMake/CPack/tests/PARTIALLY_RELOCATABLE_WARNING/test.cmake
new file mode 100644
index 0000000..4698fb3
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/PARTIALLY_RELOCATABLE_WARNING/test.cmake
@@ -0,0 +1,4 @@
+install(FILES CMakeLists.txt DESTINATION /not_relocatable COMPONENT static)
+
+set(CPACK_PACKAGE_RELOCATABLE TRUE)
+set(CPACK_PACKAGING_INSTALL_PREFIX "/opt")
diff --git a/Tests/RunCMake/CPack/tests/PER_COMPONENT_FIELDS/ExpectedFiles.cmake b/Tests/RunCMake/CPack/tests/PER_COMPONENT_FIELDS/ExpectedFiles.cmake
new file mode 100644
index 0000000..26fa1df
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/PER_COMPONENT_FIELDS/ExpectedFiles.cmake
@@ -0,0 +1,8 @@
+set(EXPECTED_FILES_COUNT "3")
+set(EXPECTED_FILES_NAME_GENERATOR_SPECIFIC_FORMAT TRUE)
+set(EXPECTED_FILE_1_COMPONENT "pkg_1")
+set(EXPECTED_FILE_CONTENT_1_LIST "/foo;/foo/CMakeLists.txt")
+set(EXPECTED_FILE_2_NAME "second")
+set(EXPECTED_FILE_CONTENT_2_LIST "/foo;/foo/CMakeLists.txt")
+set(EXPECTED_FILE_3_COMPONENT "pkg_3")
+set(EXPECTED_FILE_CONTENT_3_LIST "/foo;/foo/CMakeLists.txt")
diff --git a/Tests/RunCMake/CPack/tests/PER_COMPONENT_FIELDS/VerifyResult.cmake b/Tests/RunCMake/CPack/tests/PER_COMPONENT_FIELDS/VerifyResult.cmake
new file mode 100644
index 0000000..b4bdb61
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/PER_COMPONENT_FIELDS/VerifyResult.cmake
@@ -0,0 +1,38 @@
+function(checkPackageInfo_ TYPE FILE REGEX)
+ getPackageInfo("${FILE}" "FILE_INFO_")
+ if(NOT FILE_INFO_ MATCHES "${REGEX}")
+ message(FATAL_ERROR "Unexpected ${TYPE} in '${FILE}'; file info: '${FILE_INFO_}'; does not match '${REGEX}'")
+ endif()
+endfunction()
+
+if(GENERATOR_TYPE STREQUAL "DEB")
+ set(name_ "Package")
+ set(group_ "Section")
+elseif(GENERATOR_TYPE STREQUAL "RPM")
+ set(name_ "Name")
+ set(group_ "Group")
+endif()
+
+set(whitespaces_ "[\t\n\r ]*")
+
+# check package name
+checkPackageInfo_("name" "${FOUND_FILE_1}" ".*${name_}${whitespaces_}:${whitespaces_}per_component_fields-pkg_1")
+checkPackageInfo_("name" "${FOUND_FILE_2}" ".*${name_}${whitespaces_}:${whitespaces_}second")
+checkPackageInfo_("name" "${FOUND_FILE_3}" ".*${name_}${whitespaces_}:${whitespaces_}per_component_fields-pkg_3")
+
+# check package group
+checkPackageInfo_("group" "${FOUND_FILE_1}" ".*${group_}${whitespaces_}:${whitespaces_}default")
+checkPackageInfo_("group" "${FOUND_FILE_2}" ".*${group_}${whitespaces_}:${whitespaces_}second_group")
+checkPackageInfo_("group" "${FOUND_FILE_3}" ".*${group_}${whitespaces_}:${whitespaces_}default")
+
+# check package summaries (not available in DEB)
+if(GENERATOR_TYPE STREQUAL "RPM")
+ checkPackageInfo_("summary" "${FOUND_FILE_1}" ".*Summary${whitespaces_}:${whitespaces_}Global summary")
+ checkPackageInfo_("summary" "${FOUND_FILE_2}" ".*Summary${whitespaces_}:${whitespaces_}Summary for pkg_2")
+ checkPackageInfo_("summary" "${FOUND_FILE_3}" ".*Summary${whitespaces_}:${whitespaces_}Global summary")
+endif()
+
+# check package description
+checkPackageInfo_("description" "${FOUND_FILE_1}" ".*Description${whitespaces_}:${whitespaces_}Description for pkg_1")
+checkPackageInfo_("description" "${FOUND_FILE_2}" ".*Description${whitespaces_}:${whitespaces_}Description for pkg_2")
+checkPackageInfo_("description" "${FOUND_FILE_3}" ".*Description${whitespaces_}:${whitespaces_}Description for pkg_3")
diff --git a/Tests/RunCMake/CPack/tests/PER_COMPONENT_FIELDS/test.cmake b/Tests/RunCMake/CPack/tests/PER_COMPONENT_FIELDS/test.cmake
new file mode 100644
index 0000000..dc61d0a
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/PER_COMPONENT_FIELDS/test.cmake
@@ -0,0 +1,25 @@
+if(GENERATOR_TYPE STREQUAL "DEB" OR GENERATOR_TYPE STREQUAL "RPM")
+ if(GENERATOR_TYPE STREQUAL "DEB")
+ set(generator_type_suffix_ "IAN") # not entirely compatible...
+ set(group_ "SECTION")
+ else()
+ set(group_ "GROUP")
+ endif()
+
+ set(CPACK_${GENERATOR_TYPE}${generator_type_suffix_}_FILE_NAME "${GENERATOR_TYPE}-DEFAULT")
+
+ set(CPACK_${GENERATOR_TYPE}${generator_type_suffix_}_PACKAGE_${group_} "default")
+ set(CPACK_${GENERATOR_TYPE}${generator_type_suffix_}_PKG_2_PACKAGE_NAME "second")
+ set(CPACK_${GENERATOR_TYPE}${generator_type_suffix_}_PKG_2_PACKAGE_${group_} "second_group")
+
+ set(CPACK_${GENERATOR_TYPE}${generator_type_suffix_}_PACKAGE_SUMMARY "Global summary") # not used for DEB
+ set(CPACK_${GENERATOR_TYPE}${generator_type_suffix_}_PKG_2_PACKAGE_SUMMARY "Summary for pkg_2") # not used for DEB
+
+ set(CPACK_COMPONENT_PKG_1_DESCRIPTION "Description for pkg_1")
+ set(CPACK_COMPONENT_PKG_2_DESCRIPTION "Description for pkg_2")
+ set(CPACK_COMPONENT_PKG_3_DESCRIPTION "Description for pkg_3")
+endif()
+
+install(FILES CMakeLists.txt DESTINATION foo COMPONENT pkg_1)
+install(FILES CMakeLists.txt DESTINATION foo COMPONENT pkg_2)
+install(FILES CMakeLists.txt DESTINATION foo COMPONENT pkg_3)
diff --git a/Tests/RunCMake/CPack/tests/PROJECT_META/ExpectedFiles.cmake b/Tests/RunCMake/CPack/tests/PROJECT_META/ExpectedFiles.cmake
new file mode 100644
index 0000000..448ed2b
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/PROJECT_META/ExpectedFiles.cmake
@@ -0,0 +1,9 @@
+if(GENERATOR_TYPE STREQUAL DEB)
+ set(EXPECTED_FILE_1 "project_meta-1.2.3*.deb")
+elseif(GENERATOR_TYPE STREQUAL RPM)
+ set(EXPECTED_FILE_1 "project_meta-1.2.3*.rpm")
+else()
+ message(FATAL_ERROR "Unexpected CPack generator")
+endif()
+set(EXPECTED_FILES_COUNT "1")
+set(EXPECTED_FILE_CONTENT_1_LIST "/foo;/foo/CMakeLists.txt")
diff --git a/Tests/RunCMake/CPack/tests/PROJECT_META/VerifyResult.cmake b/Tests/RunCMake/CPack/tests/PROJECT_META/VerifyResult.cmake
new file mode 100644
index 0000000..b3accb5
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/PROJECT_META/VerifyResult.cmake
@@ -0,0 +1,30 @@
+function(checkPackageURL FILE TAG EXPECTED_URL)
+ getPackageInfo("${FILE}" "_file_info")
+ string(REPLACE "\n" ";" _file_info "${_file_info}")
+
+ set(_seen_url FALSE)
+ foreach(_line IN LISTS _file_info)
+ if(_line MATCHES "${TAG}: (.*)")
+ set(_seen_url TRUE)
+ if(NOT CMAKE_MATCH_1 STREQUAL EXPECTED_URL)
+ message(FATAL_ERROR "Unexpected `Homepage` URL: `${CMAKE_MATCH_1}` != `${EXPECTED_URL}`")
+ endif()
+ break()
+ endif()
+ endforeach()
+ if(NOT _seen_url)
+ message(FATAL_ERROR "The packge `${FILE}` do not have URL as expected")
+ endif()
+endfunction()
+
+if(GENERATOR_TYPE STREQUAL DEB)
+ set(_tag " Homepage") # NOTE The leading space
+elseif(GENERATOR_TYPE STREQUAL RPM)
+ set(_tag "URL.*")
+else()
+ message(FATAL_ERROR "Unexpected CPack generator")
+endif()
+
+checkPackageURL("${FOUND_FILE_1}" "${_tag}" "https://meta.test.info")
+
+# kate: indent-width 2;
diff --git a/Tests/RunCMake/CPack/tests/PROJECT_META/test.cmake b/Tests/RunCMake/CPack/tests/PROJECT_META/test.cmake
new file mode 100644
index 0000000..9c5266a
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/PROJECT_META/test.cmake
@@ -0,0 +1,11 @@
+project(
+ MetaInfoTest
+ VERSION 1.2.3
+ DESCRIPTION "This is going to be a summary"
+ HOMEPAGE_URL "https://meta.test.info"
+)
+install(FILES CMakeLists.txt DESTINATION foo COMPONENT test)
+
+if(PACKAGING_TYPE STREQUAL "COMPONENT")
+ set(CPACK_COMPONENTS_ALL test)
+endif()
diff --git a/Tests/RunCMake/CPack/tests/SINGLE_DEBUGINFO/ExpectedFiles.cmake b/Tests/RunCMake/CPack/tests/SINGLE_DEBUGINFO/ExpectedFiles.cmake
new file mode 100644
index 0000000..936e4ed
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/SINGLE_DEBUGINFO/ExpectedFiles.cmake
@@ -0,0 +1,30 @@
+set(whitespaces_ "[\t\n\r ]*")
+set(EXPECTED_FILES_COUNT "0")
+set(EXPECTED_FILES_NAME_GENERATOR_SPECIFIC_FORMAT TRUE)
+
+if(RunCMake_SUBTEST_SUFFIX STREQUAL "valid" OR RunCMake_SUBTEST_SUFFIX STREQUAL "no_debuginfo")
+ set(EXPECTED_FILES_COUNT "4")
+ set(EXPECTED_FILE_1 "single_debuginfo-0.1.1-1.*.rpm")
+ set(EXPECTED_FILE_CONTENT_1_LIST "/foo;/foo/test_prog")
+ set(EXPECTED_FILE_2 "single_debuginfo*-headers.rpm")
+ set(EXPECTED_FILE_CONTENT_2_LIST "/bar;/bar/CMakeLists.txt")
+ set(EXPECTED_FILE_3 "single_debuginfo*-libs.rpm")
+ set(EXPECTED_FILE_CONTENT_3_LIST "/bas;/bas/libtest_lib.so")
+
+ set(EXPECTED_FILE_4_COMPONENT "debuginfo")
+ set(EXPECTED_FILE_CONTENT_4 ".*/src${whitespaces_}/src/src_1${whitespaces_}/src/src_1/main.cpp${whitespaces_}/src/src_1/test_lib.cpp.*\.debug.*")
+elseif(RunCMake_SUBTEST_SUFFIX STREQUAL "one_component" OR RunCMake_SUBTEST_SUFFIX STREQUAL "one_component_no_debuginfo")
+ set(EXPECTED_FILES_COUNT "2")
+ set(EXPECTED_FILE_1 "single_debuginfo-0*-applications.rpm")
+ set(EXPECTED_FILE_CONTENT_1_LIST "/foo;/foo/test_prog")
+
+ set(EXPECTED_FILE_2 "single_debuginfo-applications-debuginfo*.rpm")
+ set(EXPECTED_FILE_CONTENT_2 ".*/src${whitespaces_}/src/src_1${whitespaces_}/src/src_1/main.cpp.*\.debug.*")
+elseif(RunCMake_SUBTEST_SUFFIX STREQUAL "one_component_main" OR RunCMake_SUBTEST_SUFFIX STREQUAL "no_components")
+ set(EXPECTED_FILES_COUNT "2")
+ set(EXPECTED_FILE_1 "single_debuginfo-0*.rpm")
+ set(EXPECTED_FILE_CONTENT_1_LIST "/foo;/foo/test_prog")
+
+ set(EXPECTED_FILE_2 "single_debuginfo-debuginfo*.rpm")
+ set(EXPECTED_FILE_CONTENT_2 ".*/src${whitespaces_}/src/src_1${whitespaces_}/src/src_1/main.cpp.*\.debug.*")
+endif()
diff --git a/Tests/RunCMake/CPack/tests/SINGLE_DEBUGINFO/RPM-no_main_component-stderr.txt b/Tests/RunCMake/CPack/tests/SINGLE_DEBUGINFO/RPM-no_main_component-stderr.txt
new file mode 100644
index 0000000..454283c
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/SINGLE_DEBUGINFO/RPM-no_main_component-stderr.txt
@@ -0,0 +1 @@
+CPack Error: CPACK_RPM_MAIN_COMPONENT not set but it is mandatory with CPACK_RPM_DEBUGINFO_SINGLE_PACKAGE being set.
diff --git a/Tests/RunCMake/CPack/tests/SINGLE_DEBUGINFO/test.cmake b/Tests/RunCMake/CPack/tests/SINGLE_DEBUGINFO/test.cmake
new file mode 100644
index 0000000..60e9038
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/SINGLE_DEBUGINFO/test.cmake
@@ -0,0 +1,54 @@
+set(CMAKE_BUILD_WITH_INSTALL_RPATH 1)
+
+# PGI compiler doesn't add build id to binaries by default
+if(CMAKE_CXX_COMPILER_ID STREQUAL "PGI")
+ string(APPEND CMAKE_EXE_LINKER_FLAGS "-Wl,--build-id")
+ string(APPEND CMAKE_SHARED_LINKER_FLAGS "-Wl,--build-id")
+endif()
+
+if(NOT RunCMake_SUBTEST_SUFFIX STREQUAL "no_components")
+ set(CPACK_RPM_COMPONENT_INSTALL "ON")
+endif()
+
+set(CMAKE_BUILD_TYPE Debug)
+
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/test_lib.hpp"
+ "int test_lib();\n")
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/test_lib.cpp"
+ "#include \"test_lib.hpp\"\nint test_lib() {return 0;}\n")
+add_library(test_lib SHARED "${CMAKE_CURRENT_BINARY_DIR}/test_lib.cpp")
+
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/main.cpp"
+ "#include \"test_lib.hpp\"\nint main() {return test_lib();}\n")
+add_executable(test_prog "${CMAKE_CURRENT_BINARY_DIR}/main.cpp")
+target_link_libraries(test_prog test_lib)
+
+install(TARGETS test_prog DESTINATION foo COMPONENT applications)
+
+if(RunCMake_SUBTEST_SUFFIX STREQUAL "valid"
+ OR RunCMake_SUBTEST_SUFFIX STREQUAL "no_main_component"
+ OR RunCMake_SUBTEST_SUFFIX STREQUAL "no_debuginfo")
+ install(FILES CMakeLists.txt DESTINATION bar COMPONENT headers)
+ install(TARGETS test_lib DESTINATION bas COMPONENT libs)
+elseif(RunCMake_SUBTEST_SUFFIX STREQUAL "one_component"
+ OR RunCMake_SUBTEST_SUFFIX STREQUAL "one_component_no_debuginfo")
+ set(CPACK_COMPONENTS_ALL applications)
+endif()
+
+set(CPACK_RPM_DEBUGINFO_SINGLE_PACKAGE ON)
+
+if(RunCMake_SUBTEST_SUFFIX STREQUAL "valid"
+ OR RunCMake_SUBTEST_SUFFIX STREQUAL "one_component_main"
+ OR RunCMake_SUBTEST_SUFFIX STREQUAL "no_debuginfo")
+ set(CPACK_RPM_MAIN_COMPONENT "applications")
+ set(CPACK_RPM_APPLICATIONS_FILE_NAME "RPM-DEFAULT")
+endif()
+
+if(RunCMake_SUBTEST_SUFFIX STREQUAL "valid"
+ OR RunCMake_SUBTEST_SUFFIX STREQUAL "no_main_component"
+ OR RunCMake_SUBTEST_SUFFIX STREQUAL "one_component")
+ set(CPACK_RPM_APPLICATIONS_DEBUGINFO_PACKAGE ON)
+ set(CPACK_RPM_LIBS_DEBUGINFO_PACKAGE ON)
+endif()
+
+set(CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX "/src")
diff --git a/Tests/RunCMake/CPack/tests/SOURCE_PACKAGE/ExpectedFiles.cmake b/Tests/RunCMake/CPack/tests/SOURCE_PACKAGE/ExpectedFiles.cmake
new file mode 100644
index 0000000..d78f222
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/SOURCE_PACKAGE/ExpectedFiles.cmake
@@ -0,0 +1,3 @@
+set(EXPECTED_FILES_COUNT "1")
+set(EXPECTED_FILE_PACKAGING_PREFIX "")
+set(EXPECTED_FILE_CONTENT_1_LIST "source_package-0.1.1.tar.gz;source_package.spec")
diff --git a/Tests/RunCMake/CPack/tests/SOURCE_PACKAGE/VerifyResult.cmake b/Tests/RunCMake/CPack/tests/SOURCE_PACKAGE/VerifyResult.cmake
new file mode 100644
index 0000000..73d7481
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/SOURCE_PACKAGE/VerifyResult.cmake
@@ -0,0 +1,67 @@
+set(whitespaces_ "[\t\n\r ]*")
+
+file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/test_rpm")
+file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/test_rpm/BUILD")
+file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/test_rpm/BUILDROOT")
+file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/test_rpm/RPMS")
+file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/test_rpm/SOURCES")
+file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/test_rpm/SPECS")
+file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/test_rpm/SRPMS")
+
+# make sure that we are using the version of cmake and cpack that we are testing
+get_filename_component(cpack_path_ "${CMAKE_CPACK_COMMAND}" DIRECTORY)
+set(ENV{PATH} "${cpack_path_}:$ENV{PATH}")
+
+execute_process(COMMAND ${RPMBUILD_EXECUTABLE} --define "_topdir ${CMAKE_CURRENT_BINARY_DIR}/test_rpm" --rebuild ${FOUND_FILE_1}
+ RESULT_VARIABLE result_
+ ERROR_VARIABLE error_
+ OUTPUT_QUIET
+ )
+
+set(output_error_message_
+ "\n${RPMBUILD_EXECUTABLE} error: '${error_}';\nresult: '${result_}';\n${output_error_message}")
+
+# expected file content are test_prog and optional build-id links that are
+# generated by rpmbuild (introduced in rpm 4.13.0.1)
+set(EXPECTED_FILE_CONTENT_ "^/foo${whitespaces_}/foo/test_prog(${whitespaces_}.*\.build-id.*)*$")
+
+file(GLOB_RECURSE FOUND_FILE_ RELATIVE "${CMAKE_CURRENT_BINARY_DIR}/test_rpm/RPMS" "${CMAKE_CURRENT_BINARY_DIR}/test_rpm/RPMS/*.rpm")
+list(APPEND foundFiles_ "${FOUND_FILE_}")
+list(LENGTH FOUND_FILE_ foundFilesCount_)
+
+if(foundFilesCount_ EQUAL 1)
+ unset(PACKAGE_CONTENT)
+ getPackageContent("${CMAKE_CURRENT_BINARY_DIR}/test_rpm/RPMS/${FOUND_FILE_}" "PACKAGE_CONTENT")
+
+ string(REGEX MATCH "${EXPECTED_FILE_CONTENT_}"
+ expected_content_list "${PACKAGE_CONTENT}")
+
+ if(NOT expected_content_list)
+ message(FATAL_ERROR
+ "Unexpected file content!\n"
+ " Content: '${PACKAGE_CONTENT}'\n\n"
+ " Expected: '${EXPECTED_FILE_CONTENT_}'"
+ "${output_error_message_}")
+ endif()
+else()
+ message(FATAL_ERROR
+ "Found more than one file!"
+ " Found files count '${foundFilesCount_}'."
+ " Files: '${FOUND_FILE_}'"
+ "${output_error_message_}")
+endif()
+
+# check that there were no extra files generated
+foreach(all_files_glob_ IN LISTS ALL_FILES_GLOB)
+ file(GLOB foundAll_ RELATIVE "${CMAKE_CURRENT_BINARY_DIR}/test_rpm/RPMS" "${all_files_glob_}")
+ list(APPEND allFoundFiles_ "${foundAll_}")
+endforeach()
+
+list(LENGTH foundFiles_ foundFilesCount_)
+list(LENGTH allFoundFiles_ allFoundFilesCount_)
+
+if(NOT foundFilesCount_ EQUAL allFoundFilesCount_)
+ message(FATAL_ERROR
+ "Found more files than expected! Found files: '${allFoundFiles_}'"
+ "${output_error_message_}")
+endif()
diff --git a/Tests/RunCMake/CPack/tests/SOURCE_PACKAGE/test.cmake b/Tests/RunCMake/CPack/tests/SOURCE_PACKAGE/test.cmake
new file mode 100644
index 0000000..359b98f
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/SOURCE_PACKAGE/test.cmake
@@ -0,0 +1,7 @@
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/main.cpp"
+ "int main() {return 0;}\n")
+add_executable(test_prog "${CMAKE_CURRENT_BINARY_DIR}/main.cpp")
+
+install(TARGETS test_prog DESTINATION foo COMPONENT applications)
+
+set(CPACK_RPM_FILE_NAME "RPM-DEFAULT")
diff --git a/Tests/RunCMake/CPack/tests/SUGGESTS/ExpectedFiles.cmake b/Tests/RunCMake/CPack/tests/SUGGESTS/ExpectedFiles.cmake
new file mode 100644
index 0000000..d1a3a5f
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/SUGGESTS/ExpectedFiles.cmake
@@ -0,0 +1,2 @@
+set(EXPECTED_FILES_COUNT "1")
+set(EXPECTED_FILE_CONTENT_1_LIST "/foo;/foo/CMakeLists.txt")
diff --git a/Tests/RunCMake/CPack/tests/SUGGESTS/RPM-stderr.txt b/Tests/RunCMake/CPack/tests/SUGGESTS/RPM-stderr.txt
new file mode 100644
index 0000000..53d71d9
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/SUGGESTS/RPM-stderr.txt
@@ -0,0 +1 @@
+^(.*CPackRPM:Warning: SUGGESTS not supported in provided rpmbuild.*)?CPackRPM: Will use GENERATED spec file: (/[^/]*)*/Tests/RunCMake/RPM\.SUGGESTS/CPack/[^-]*-build/_CPack_Packages/.*/RPM/SPECS/[^\.]*\.spec$
diff --git a/Tests/RunCMake/CPack/tests/SUGGESTS/VerifyResult.cmake b/Tests/RunCMake/CPack/tests/SUGGESTS/VerifyResult.cmake
new file mode 100644
index 0000000..61ce752
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/SUGGESTS/VerifyResult.cmake
@@ -0,0 +1,31 @@
+execute_process(COMMAND ${RPMBUILD_EXECUTABLE} --querytags
+ OUTPUT_VARIABLE RPMBUILD_CAPS
+ RESULT_VARIABLE RPMBUILD_CAPS_RESULT)
+
+if(NOT RPMBUILD_CAPS_RESULT)
+ string(REPLACE "\n" ";" RPMBUILD_CAPS "${RPMBUILD_CAPS}")
+ cmake_policy(PUSH)
+ cmake_policy(SET CMP0057 NEW)
+ if(SUGGESTS IN_LIST RPMBUILD_CAPS)
+ set(should_contain_suggests_tag_ true)
+ endif()
+ cmake_policy(POP)
+endif()
+
+# Only verify that suggests tag is present only if that tag is supported.
+# If it is not supported the rpm package was correctly generated by ignoring
+# that tag and that was already checked by expected files test.
+if(should_contain_suggests_tag_)
+ execute_process(COMMAND ${RPM_EXECUTABLE} -q --suggests -p "${FOUND_FILE_1}"
+ WORKING_DIRECTORY "${CPACK_TEMPORARY_DIRECTORY}"
+ RESULT_VARIABLE rpm_result_
+ OUTPUT_VARIABLE rpm_output_
+ ERROR_VARIABLE error_variable_
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+ if(rpm_result_ OR NOT rpm_output_ STREQUAL "libsuggested")
+ message(FATAL_ERROR "RPM_SUGGESTED package error: no suggested packages"
+ " (result: '${rpm_result_}'; output: '${rpm_output_}';"
+ " error: '${error_variable_}')")
+ endif()
+endif()
diff --git a/Tests/RunCMake/CPack/tests/SUGGESTS/test.cmake b/Tests/RunCMake/CPack/tests/SUGGESTS/test.cmake
new file mode 100644
index 0000000..dc90ae8
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/SUGGESTS/test.cmake
@@ -0,0 +1,3 @@
+install(FILES CMakeLists.txt DESTINATION foo)
+
+set(CPACK_RPM_PACKAGE_SUGGESTS "libsuggested")
diff --git a/Tests/RunCMake/CPack/tests/SYMLINKS/ExpectedFiles.cmake b/Tests/RunCMake/CPack/tests/SYMLINKS/ExpectedFiles.cmake
new file mode 100644
index 0000000..e8281a8
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/SYMLINKS/ExpectedFiles.cmake
@@ -0,0 +1,12 @@
+set(EXPECTED_FILES_COUNT "1")
+
+set(EXPECTED_FILE_CONTENT_1_LIST
+ "/empty_dir"
+ "/non_empty_dir"
+ "/non_empty_dir/CMakeLists.txt"
+ "/symlink_to_empty_dir"
+ "/symlink_to_non_empty_dir")
+
+if(PACKAGING_TYPE STREQUAL "COMPONENT")
+ set(EXPECTED_FILE_1_COMPONENT "links")
+endif()
diff --git a/Tests/RunCMake/CPack/tests/SYMLINKS/TGZ-Prerequirements.cmake b/Tests/RunCMake/CPack/tests/SYMLINKS/TGZ-Prerequirements.cmake
new file mode 100644
index 0000000..f3df46b
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/SYMLINKS/TGZ-Prerequirements.cmake
@@ -0,0 +1,5 @@
+function(get_test_prerequirements found_var config_file)
+ if(UNIX) # limit test to platforms that support symlinks
+ set(${found_var} true PARENT_SCOPE)
+ endif()
+endfunction()
diff --git a/Tests/RunCMake/CPack/tests/SYMLINKS/VerifyResult.cmake b/Tests/RunCMake/CPack/tests/SYMLINKS/VerifyResult.cmake
new file mode 100644
index 0000000..0632319
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/SYMLINKS/VerifyResult.cmake
@@ -0,0 +1,26 @@
+set(whitespaces "[\\t\\n\\r ]*")
+
+#######################
+# verify generated symbolic links
+#######################
+file(GLOB_RECURSE symlink_files RELATIVE "${bin_dir}" "${bin_dir}/*/symlink_*")
+
+foreach(check_symlink IN LISTS symlink_files)
+ get_filename_component(symlink_name "${check_symlink}" NAME)
+ execute_process(COMMAND ls -la "${check_symlink}"
+ WORKING_DIRECTORY "${bin_dir}"
+ OUTPUT_VARIABLE SYMLINK_POINT_
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+ if("${symlink_name}" STREQUAL "symlink_to_empty_dir")
+ string(REGEX MATCH "^.*${whitespaces}->${whitespaces}empty_dir$" check_symlink "${SYMLINK_POINT_}")
+ elseif("${symlink_name}" STREQUAL "symlink_to_non_empty_dir")
+ string(REGEX MATCH "^.*${whitespaces}->${whitespaces}non_empty_dir$" check_symlink "${SYMLINK_POINT_}")
+ else()
+ message(FATAL_ERROR "error: unexpected rpm symbolic link '${check_symlink}'")
+ endif()
+
+ if(NOT check_symlink)
+ message(FATAL_ERROR "symlink points to unexpected location '${SYMLINK_POINT_}'")
+ endif()
+endforeach()
diff --git a/Tests/RunCMake/CPack/tests/SYMLINKS/test.cmake b/Tests/RunCMake/CPack/tests/SYMLINKS/test.cmake
new file mode 100644
index 0000000..fef765c
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/SYMLINKS/test.cmake
@@ -0,0 +1,14 @@
+install(DIRECTORY DESTINATION empty_dir COMPONENT links)
+install(FILES CMakeLists.txt DESTINATION non_empty_dir COMPONENT links)
+
+# test symbolic link to an empty dir
+execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink empty_dir symlink_to_empty_dir)
+install(FILES ${CMAKE_CURRENT_BINARY_DIR}/symlink_to_empty_dir DESTINATION "." COMPONENT links)
+
+# test symbolic link to a non empty dir
+execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink non_empty_dir symlink_to_non_empty_dir)
+install(FILES ${CMAKE_CURRENT_BINARY_DIR}/symlink_to_non_empty_dir DESTINATION "." COMPONENT links)
+
+if(PACKAGING_TYPE STREQUAL "COMPONENT")
+ set(CPACK_COMPONENTS_ALL links)
+endif()
diff --git a/Tests/RunCMake/CPack/tests/THREADED/ExpectedFiles.cmake b/Tests/RunCMake/CPack/tests/THREADED/ExpectedFiles.cmake
new file mode 100644
index 0000000..d1a3a5f
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/THREADED/ExpectedFiles.cmake
@@ -0,0 +1,2 @@
+set(EXPECTED_FILES_COUNT "1")
+set(EXPECTED_FILE_CONTENT_1_LIST "/foo;/foo/CMakeLists.txt")
diff --git a/Tests/RunCMake/CPack/tests/THREADED/test.cmake b/Tests/RunCMake/CPack/tests/THREADED/test.cmake
new file mode 100644
index 0000000..78fc9e9
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/THREADED/test.cmake
@@ -0,0 +1,7 @@
+install(FILES CMakeLists.txt DESTINATION foo COMPONENT test)
+
+set(CPACK_ARCHIVE_THREADS 2)
+
+if(PACKAGING_TYPE STREQUAL "COMPONENT")
+ set(CPACK_COMPONENTS_ALL test)
+endif()
diff --git a/Tests/RunCMake/CPack/tests/THREADED_ALL/ExpectedFiles.cmake b/Tests/RunCMake/CPack/tests/THREADED_ALL/ExpectedFiles.cmake
new file mode 100644
index 0000000..d1a3a5f
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/THREADED_ALL/ExpectedFiles.cmake
@@ -0,0 +1,2 @@
+set(EXPECTED_FILES_COUNT "1")
+set(EXPECTED_FILE_CONTENT_1_LIST "/foo;/foo/CMakeLists.txt")
diff --git a/Tests/RunCMake/CPack/tests/THREADED_ALL/test.cmake b/Tests/RunCMake/CPack/tests/THREADED_ALL/test.cmake
new file mode 100644
index 0000000..34051b8
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/THREADED_ALL/test.cmake
@@ -0,0 +1,7 @@
+install(FILES CMakeLists.txt DESTINATION foo COMPONENT test)
+
+set(CPACK_ARCHIVE_THREADS 0)
+
+if(PACKAGING_TYPE STREQUAL "COMPONENT")
+ set(CPACK_COMPONENTS_ALL test)
+endif()
diff --git a/Tests/RunCMake/CPack/tests/TIMESTAMPS/ExpectedFiles.cmake b/Tests/RunCMake/CPack/tests/TIMESTAMPS/ExpectedFiles.cmake
new file mode 100644
index 0000000..d1a3a5f
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/TIMESTAMPS/ExpectedFiles.cmake
@@ -0,0 +1,2 @@
+set(EXPECTED_FILES_COUNT "1")
+set(EXPECTED_FILE_CONTENT_1_LIST "/foo;/foo/CMakeLists.txt")
diff --git a/Tests/RunCMake/CPack/tests/TIMESTAMPS/VerifyResult.cmake b/Tests/RunCMake/CPack/tests/TIMESTAMPS/VerifyResult.cmake
new file mode 100644
index 0000000..e7e2645
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/TIMESTAMPS/VerifyResult.cmake
@@ -0,0 +1,58 @@
+macro(getFileMetadata_ FILE RESULT_VAR)
+ if(GENERATOR_TYPE STREQUAL "TGZ")
+ # getPackageContent defined for archives omit the metadata (non-verbose)
+ execute_process(COMMAND ${CMAKE_COMMAND} -E env TZ=Etc/UTC ${CMAKE_COMMAND} -E tar -xtvf ${FILE}
+ OUTPUT_VARIABLE ${RESULT_VAR}
+ ERROR_QUIET
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+ else()
+ getPackageContent("${FILE}" ${RESULT_VAR})
+ endif()
+endmacro()
+
+function(checkContentTimestamp FILE REGEX)
+ getFileMetadata_("${FILE}" METADATA_)
+
+ if(NOT METADATA_ MATCHES "${REGEX}")
+ string(REPLACE "\n" "\n " metadata_indented "${METADATA_}")
+ message(FATAL_ERROR
+ "Wrong timestamps in file:\n"
+ " ${FILE}\n"
+ "Expected timestamps to match:\n"
+ " ${REGEX}\n"
+ "Actual timestamps:\n"
+ " ${metadata_indented}")
+ endif()
+endfunction()
+
+function(checkTimestamp FILE_NAME)
+ file(READ ${FILE_NAME} ACTUAL_TIMESTAMP OFFSET 4 LIMIT 4 HEX)
+
+ if(NOT ACTUAL_TIMESTAMP STREQUAL "00000000")
+ message(FATAL_ERROR "${FILE_NAME} contains a timestamp [0x${ACTUAL_TIMESTAMP}]")
+ endif()
+endfunction()
+
+# Expected timestamp is UNIX time 123456789
+if(GENERATOR_TYPE STREQUAL "TGZ")
+ set(EXPECTED_TIMESTAMP "29 Nov +1973")
+ set(EXPECTED_FILES foo/ foo/CMakeLists.txt)
+else()
+ set(EXPECTED_TIMESTAMP "1973-11-29 21:33")
+ set(EXPECTED_FILES ./usr/ ./usr/foo/ ./usr/foo/CMakeLists.txt)
+endif()
+
+set(EXPECTED_METADATA)
+foreach(FILE ${EXPECTED_FILES})
+ list(APPEND EXPECTED_METADATA ".* ${EXPECTED_TIMESTAMP} ${FILE}")
+endforeach()
+list(JOIN EXPECTED_METADATA ".*" EXPECTED_REGEX)
+checkContentTimestamp("${FOUND_FILE_1}" "${EXPECTED_REGEX}")
+
+if(GENERATOR_TYPE STREQUAL "TGZ")
+ checkTimestamp("${FOUND_FILE_1}")
+else()
+ execute_process(COMMAND ${CMAKE_COMMAND} -E tar xf "${FOUND_FILE_1}")
+ checkTimestamp("data.tar.gz")
+ checkTimestamp("control.tar.gz")
+endif()
diff --git a/Tests/RunCMake/CPack/tests/TIMESTAMPS/test.cmake b/Tests/RunCMake/CPack/tests/TIMESTAMPS/test.cmake
new file mode 100644
index 0000000..a193852
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/TIMESTAMPS/test.cmake
@@ -0,0 +1,3 @@
+install(FILES CMakeLists.txt DESTINATION foo COMPONENT test)
+
+set(CPACK_COMPONENTS_ALL test)
diff --git a/Tests/RunCMake/CPack/tests/USER_FILELIST/ExpectedFiles.cmake b/Tests/RunCMake/CPack/tests/USER_FILELIST/ExpectedFiles.cmake
new file mode 100644
index 0000000..8420986
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/USER_FILELIST/ExpectedFiles.cmake
@@ -0,0 +1,2 @@
+set(EXPECTED_FILES_COUNT "1")
+set(EXPECTED_FILE_CONTENT_1_LIST "/one;/one/foo.txt;/one/two;/one/two/bar.txt;/three;/three/baz.txt;/three/qux.txt")
diff --git a/Tests/RunCMake/CPack/tests/USER_FILELIST/VerifyResult.cmake b/Tests/RunCMake/CPack/tests/USER_FILELIST/VerifyResult.cmake
new file mode 100644
index 0000000..57444ed
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/USER_FILELIST/VerifyResult.cmake
@@ -0,0 +1,12 @@
+execute_process(COMMAND ${RPM_EXECUTABLE} -qpd ${FOUND_FILE_1}
+ WORKING_DIRECTORY "${CPACK_TEMPORARY_DIRECTORY}"
+ OUTPUT_VARIABLE DOC_FILES_
+ ERROR_QUIET
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+string(REPLACE "\n" ";" DOC_FILES_ "${DOC_FILES_}")
+
+set(DOC_FILES_WANTED_ "/usr/one/foo.txt;/usr/one/two/bar.txt;/usr/three/baz.txt")
+if (NOT "${DOC_FILES_}" STREQUAL "${DOC_FILES_WANTED_}")
+ message(FATAL_ERROR "USER_FILELIST handling error: Check filelist in spec file. Doc files were: ${DOC_FILES_}. Should have been ${DOC_FILES_WANTED_}")
+endif()
diff --git a/Tests/RunCMake/CPack/tests/USER_FILELIST/test.cmake b/Tests/RunCMake/CPack/tests/USER_FILELIST/test.cmake
new file mode 100644
index 0000000..acfee42
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/USER_FILELIST/test.cmake
@@ -0,0 +1,13 @@
+install(FILES CMakeLists.txt DESTINATION one RENAME foo.txt)
+install(FILES CMakeLists.txt DESTINATION one/two RENAME bar.txt)
+install(FILES CMakeLists.txt DESTINATION three RENAME baz.txt)
+install(FILES CMakeLists.txt DESTINATION three RENAME qux.txt)
+
+# We are verifying the USER_FILELIST works by comparing what
+# ends up with a %doc tag in the final rpm with what we expect
+# from this USER_FILELIST.
+set(CPACK_RPM_USER_FILELIST
+ "%doc /usr/one/foo.txt"
+ "%doc %attr(640,root,root) /usr/one/two/bar.txt"
+ "%attr(600, -, root) %doc /usr/three/baz.txt"
+)
diff --git a/Tests/RunCMake/CPack/tests/VERSION/ExpectedFiles.cmake b/Tests/RunCMake/CPack/tests/VERSION/ExpectedFiles.cmake
new file mode 100644
index 0000000..372f71b
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/VERSION/ExpectedFiles.cmake
@@ -0,0 +1,3 @@
+set(EXPECTED_FILES_COUNT "1")
+set(EXPECTED_FILE_CONTENT_1_LIST "/foo;/foo/CMakeLists.txt")
+set(EXPECTED_FILE_1_REVISION "1")
diff --git a/Tests/RunCMake/CPack/tests/VERSION/VerifyResult.cmake b/Tests/RunCMake/CPack/tests/VERSION/VerifyResult.cmake
new file mode 100644
index 0000000..eed9696
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/VERSION/VerifyResult.cmake
@@ -0,0 +1,17 @@
+function(checkPackageInfo_ TYPE FILE REGEX)
+ getPackageInfo("${FILE}" "FILE_INFO_")
+ if(NOT FILE_INFO_ MATCHES "${REGEX}")
+ message(FATAL_ERROR "Unexpected ${TYPE} in '${FILE}' ${EXPECTED_FILE_1_VERSION} ${EXPECTED_FILE_1_REVISION}; file info: '${FILE_INFO_}'")
+ endif()
+endfunction()
+
+set(whitespaces_ "[\t\n\r ]*")
+
+if(GENERATOR_TYPE STREQUAL "RPM")
+ checkPackageInfo_("package version" "${FOUND_FILE_1}" "Version${whitespaces_}:${whitespaces_}${EXPECTED_FILE_1_VERSION}")
+ checkPackageInfo_("package revision" "${FOUND_FILE_1}" "Release${whitespaces_}:${whitespaces_}${EXPECTED_FILE_1_REVISION}")
+ checkPackageInfo_("epoch version" "${FOUND_FILE_1}" "Epoch${whitespaces_}:${whitespaces_}3")
+else() # DEB
+ checkPackageInfo_("version" "${FOUND_FILE_1}"
+ ".*Version${whitespaces_}:${whitespaces_}3:${EXPECTED_FILE_1_VERSION}-${EXPECTED_FILE_1_REVISION}")
+endif()
diff --git a/Tests/RunCMake/CPack/tests/VERSION/test.cmake b/Tests/RunCMake/CPack/tests/VERSION/test.cmake
new file mode 100644
index 0000000..301ab61
--- /dev/null
+++ b/Tests/RunCMake/CPack/tests/VERSION/test.cmake
@@ -0,0 +1,14 @@
+install(FILES CMakeLists.txt DESTINATION foo COMPONENT test)
+
+if(GENERATOR_TYPE STREQUAL "DEB")
+ set(package_type_ "DEBIAN")
+ set(CPACK_DEBIAN_PACKAGE_RELEASE "1")
+else()
+ set(package_type_ "${GENERATOR_TYPE}")
+endif()
+
+set(CPACK_${package_type_}_PACKAGE_EPOCH "3")
+
+if(PACKAGING_TYPE STREQUAL "COMPONENT")
+ set(CPACK_COMPONENTS_ALL test)
+endif()