Merge topic 'cpack-deb-different-package-names'

adbd3985 CPack/Deb possibility to change package name
This commit is contained in:
Brad King 2016-05-24 13:54:03 -04:00 committed by CMake Topic Stage
commit a98a699987
22 changed files with 120 additions and 30 deletions

View File

@ -14,15 +14,19 @@ cpack-deb-imporvements
For backward compatibility this feature is disabled by default. See For backward compatibility this feature is disabled by default. See
:variable:`CPACK_DEBIAN_ENABLE_COMPONENT_DEPENDS`. :variable:`CPACK_DEBIAN_ENABLE_COMPONENT_DEPENDS`.
* The :module:`CPackDeb` module learned how to set the package release number * The :module:`CPackDeb` module learned how to set custom package file names
(``DebianRevisionNumber`` in package file name). See including how to generate properly-named Debian packages::
:variable:`CPACK_DEBIAN_PACKAGE_RELEASE`.
* The :module:`CPackDeb` module now generates properly-named Debian packages::
<PackageName>_<VersionNumber>-<DebianRevisionNumber>_<DebianArchitecture>.deb <PackageName>_<VersionNumber>-<DebianRevisionNumber>_<DebianArchitecture>.deb
This breaks compatibility with previous versions. For backward compatibility this feature is disabled by default. See
:variable:`CPACK_DEBIAN_FILE_NAME` and
:variable:`CPACK_DEBIAN_<COMPONENT>_FILE_NAME`.
* The :module:`CPackDeb` module learned how to set the package release number
(``DebianRevisionNumber`` in package file name when used in combination with
``DEB-DEFAULT`` value set by :variable:`CPACK_DEBIAN_FILE_NAME`). See
:variable:`CPACK_DEBIAN_PACKAGE_RELEASE`.
* The :module:`CPackDeb` module learned how to set the package architecture * The :module:`CPackDeb` module learned how to set the package architecture
per-component. See :variable:`CPACK_DEBIAN_<COMPONENT>_PACKAGE_ARCHITECTURE`. per-component. See :variable:`CPACK_DEBIAN_<COMPONENT>_PACKAGE_ARCHITECTURE`.

View File

@ -42,6 +42,32 @@
# #
# See https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Source # See https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Source
# #
# .. variable:: CPACK_DEBIAN_FILE_NAME
# CPACK_DEBIAN_<COMPONENT>_FILE_NAME
#
# Package file name.
#
# * Mandatory : YES
# * Default : ``<CPACK_PACKAGE_FILE_NAME>[-<component>].deb``
#
# This may be set to ``DEB-DEFAULT`` to allow CPackDeb to generate package file
# name by itself in deb format::
#
# <PackageName>_<VersionNumber>-<DebianRevisionNumber>_<DebianArchitecture>.deb
#
# Alternatively provided package file name must end with ".deb" suffix.
#
# .. note::
#
# Preferred setting of this variable is ``DEB-DEFAULT`` but for backward
# compatibility with CPackDeb in CMake prior to version 3.6 this feature
# is disabled by default.
#
# .. note::
#
# By using non default filenames duplicate names may occur. Duplicate files
# get overwritten and it is up to the packager to set the variables in a
# manner that will prevent such errors.
# #
# .. variable:: CPACK_DEBIAN_PACKAGE_VERSION # .. variable:: CPACK_DEBIAN_PACKAGE_VERSION
# #
@ -473,6 +499,17 @@ if(NOT UNIX)
message(FATAL_ERROR "CPackDeb.cmake may only be used under UNIX.") message(FATAL_ERROR "CPackDeb.cmake may only be used under UNIX.")
endif() endif()
function(cpack_deb_variable_fallback OUTPUT_VAR_NAME)
set(FALLBACK_VAR_NAMES ${ARGN})
foreach(variable_name IN LISTS FALLBACK_VAR_NAMES)
if(${variable_name})
set(${OUTPUT_VAR_NAME} "${${variable_name}}" PARENT_SCOPE)
break()
endif()
endforeach()
endfunction()
function(get_component_package_name var component) function(get_component_package_name var component)
string(TOUPPER "${component}" component_upcase) string(TOUPPER "${component}" component_upcase)
if(CPACK_DEBIAN_${component_upcase}_PACKAGE_NAME) if(CPACK_DEBIAN_${component_upcase}_PACKAGE_NAME)
@ -888,13 +925,32 @@ function(cpack_deb_prepare_package_vars)
set(CPACK_DEBIAN_PACKAGE_RELEASE 1) set(CPACK_DEBIAN_PACKAGE_RELEASE 1)
endif() endif()
# Patch package file name to be in corrent debian format:
# <foo>_<VersionNumber>-<DebianRevisionNumber>_<DebianArchitecture>.deb cpack_deb_variable_fallback("CPACK_DEBIAN_FILE_NAME"
set(CPACK_OUTPUT_FILE_NAME "CPACK_DEBIAN_${_local_component_name}_FILE_NAME"
"${CPACK_DEBIAN_PACKAGE_NAME}_${CPACK_PACKAGE_VERSION}-${CPACK_DEBIAN_PACKAGE_RELEASE}_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}.deb") "CPACK_DEBIAN_FILE_NAME")
set(CPACK_TEMPORARY_PACKAGE_FILE_NAME "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_OUTPUT_FILE_NAME}") if(CPACK_DEBIAN_FILE_NAME)
get_filename_component(BINARY_DIR "${CPACK_OUTPUT_FILE_PATH}" DIRECTORY) if(CPACK_DEBIAN_FILE_NAME STREQUAL "DEB-DEFAULT")
set(CPACK_OUTPUT_FILE_PATH "${BINARY_DIR}/${CPACK_OUTPUT_FILE_NAME}") # Patch package file name to be in corrent debian format:
# <foo>_<VersionNumber>-<DebianRevisionNumber>_<DebianArchitecture>.deb
set(CPACK_OUTPUT_FILE_NAME
"${CPACK_DEBIAN_PACKAGE_NAME}_${CPACK_PACKAGE_VERSION}-${CPACK_DEBIAN_PACKAGE_RELEASE}_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}.deb")
else()
cmake_policy(PUSH)
cmake_policy(SET CMP0010 NEW)
if(NOT CPACK_DEBIAN_FILE_NAME MATCHES ".*\\.deb")
cmake_policy(POP)
message(FATAL_ERROR "'${CPACK_DEBIAN_FILE_NAME}' is not a valid DEB package file name as it must end with '.deb'!")
endif()
cmake_policy(POP)
set(CPACK_OUTPUT_FILE_NAME "${CPACK_DEBIAN_FILE_NAME}")
endif()
set(CPACK_TEMPORARY_PACKAGE_FILE_NAME "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_OUTPUT_FILE_NAME}")
get_filename_component(BINARY_DIR "${CPACK_OUTPUT_FILE_PATH}" DIRECTORY)
set(CPACK_OUTPUT_FILE_PATH "${BINARY_DIR}/${CPACK_OUTPUT_FILE_NAME}")
endif() # else() back compatibility - don't change the name
# Print out some debug information if we were asked for that # Print out some debug information if we were asked for that
if(CPACK_DEBIAN_PACKAGE_DEBUG) if(CPACK_DEBIAN_PACKAGE_DEBUG)

View File

@ -57,8 +57,8 @@ int cmCPackDebGenerator::PackageOnePack(std::string initialTopLevel,
// Begin the archive for this pack // Begin the archive for this pack
std::string localToplevel(initialTopLevel); std::string localToplevel(initialTopLevel);
std::string packageFileName(cmSystemTools::GetParentDirectory(toplevel)); std::string packageFileName(cmSystemTools::GetParentDirectory(toplevel));
std::string outputFileName(cmsys::SystemTools::LowerCase(std::string( std::string outputFileName(std::string(
this->GetOption("CPACK_PACKAGE_FILE_NAME"))) + this->GetOption("CPACK_PACKAGE_FILE_NAME")) +
"-" + packageName + this->GetOutputExtension()); "-" + packageName + this->GetOutputExtension());
localToplevel += "/" + packageName; localToplevel += "/" + packageName;
@ -174,8 +174,8 @@ int cmCPackDebGenerator::PackageComponentsAllInOne(
// The ALL GROUPS in ONE package case // The ALL GROUPS in ONE package case
std::string localToplevel(initialTopLevel); std::string localToplevel(initialTopLevel);
std::string packageFileName(cmSystemTools::GetParentDirectory(toplevel)); std::string packageFileName(cmSystemTools::GetParentDirectory(toplevel));
std::string outputFileName(cmsys::SystemTools::LowerCase(std::string( std::string outputFileName(std::string(
this->GetOption("CPACK_PACKAGE_FILE_NAME"))) + this->GetOption("CPACK_PACKAGE_FILE_NAME")) +
this->GetOutputExtension()); this->GetOutputExtension());
// all GROUP in one vs all COMPONENT in one // all GROUP in one vs all COMPONENT in one
localToplevel += "/" + compInstDirName; localToplevel += "/" + compInstDirName;

View File

@ -130,6 +130,8 @@ configure_file(${CPackComponentsDEB_SOURCE_DIR}/MyLibCPackConfig-${CPackDEBConfi
@ONLY) @ONLY)
set(CPACK_PROJECT_CONFIG_FILE ${CPackComponentsDEB_BINARY_DIR}/MyLibCPackConfig-${CPackDEBConfiguration}.cmake) set(CPACK_PROJECT_CONFIG_FILE ${CPackComponentsDEB_BINARY_DIR}/MyLibCPackConfig-${CPackDEBConfiguration}.cmake)
# set CPACK_DEBIAN_FILE_NAME to use default package name format
set(CPACK_DEBIAN_FILE_NAME "DEB-DEFAULT")
# Include CPack to introduce the appropriate targets # Include CPack to introduce the appropriate targets
include(CPack) include(CPack)

View File

@ -165,6 +165,9 @@ set(CPACK_RPM_RELOCATION_PATHS "${CMAKE_INSTALL_INCLUDEDIR}"
"${CMAKE_INSTALL_LIBDIR}" "${CMAKE_INSTALL_BINDIR}" "other_relocatable" "${CMAKE_INSTALL_LIBDIR}" "${CMAKE_INSTALL_BINDIR}" "other_relocatable"
"${CMAKE_INSTALL_LIBDIR}/inside_relocatable_two/depth_two/different_relocatable") "${CMAKE_INSTALL_LIBDIR}/inside_relocatable_two/depth_two/different_relocatable")
# set CPACK_DEBIAN_FILE_NAME to use default package name format
set(CPACK_DEBIAN_FILE_NAME "DEB-DEFAULT")
# We may use the CPack specific config file in order # We may use the CPack specific config file in order
# to tailor CPack behavior on a CPack generator specific way # to tailor CPack behavior on a CPack generator specific way
# (Behavior would be different for RPM or TGZ or DEB ...) # (Behavior would be different for RPM or TGZ or DEB ...)

View File

@ -1,9 +1,5 @@
set(CPACK_RPM_COMPONENT_INSTALL "ON") set(CPACK_RPM_COMPONENT_INSTALL "ON")
set(CPACK_RPM_FILE_NAME "RPM-DEFAULT")
set(CPACK_RPM_PKG_2_PACKAGE_NAME "second")
set(CPACK_RPM_PKG_3_FILE_NAME "pkg_3_abc.rpm")
install(FILES CMakeLists.txt DESTINATION foo COMPONENT pkg_1) 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_2)
install(FILES CMakeLists.txt DESTINATION foo COMPONENT pkg_3) install(FILES CMakeLists.txt DESTINATION foo COMPONENT pkg_3)

View File

@ -1,2 +1,3 @@
set(CPACK_PACKAGE_CONTACT "someone") set(CPACK_PACKAGE_CONTACT "someone")
set(CPACK_DEB_COMPONENT_INSTALL "ON") set(CPACK_DEB_COMPONENT_INSTALL "ON")
set(CPACK_DEBIAN_FILE_NAME "DEB-DEFAULT")

View File

@ -0,0 +1,9 @@
set(whitespaces_ "[\t\n\r ]*")
set(EXPECTED_FILES_COUNT "3")
set(EXPECTED_FILE_1 "custom_names-pkg_1_0.1.1-1_*.deb")
set(EXPECTED_FILE_CONTENT_1 "^.*/usr/foo${whitespaces_}.*/usr/foo/CMakeLists.txt$")
set(EXPECTED_FILE_2 "second*.deb")
set(EXPECTED_FILE_CONTENT_2 "^.*/usr/foo${whitespaces_}.*/usr/foo/CMakeLists.txt$")
set(EXPECTED_FILE_3 "pkg_3_abc.deb")
set(EXPECTED_FILE_CONTENT_3 "^.*/usr/foo${whitespaces_}.*/usr/foo/CMakeLists.txt$")

View File

@ -0,0 +1,6 @@
set(CPACK_PACKAGE_CONTACT "someone")
set(CPACK_DEB_COMPONENT_INSTALL "ON")
set(CPACK_DEBIAN_FILE_NAME "DEB-DEFAULT")
set(CPACK_DEBIAN_PKG_2_PACKAGE_NAME "second")
set(CPACK_DEBIAN_PKG_3_FILE_NAME "pkg_3_abc.deb")

View File

@ -1,14 +1,14 @@
set(whitespaces_ "[\t\n\r ]*") set(whitespaces_ "[\t\n\r ]*")
set(EXPECTED_FILES_COUNT "5") set(EXPECTED_FILES_COUNT "5")
set(EXPECTED_FILE_1 "dependencies-applications_0.1.1-1_*.deb") set(EXPECTED_FILE_1 "dependencies-0.1.1-*-applications.deb")
set(EXPECTED_FILE_CONTENT_1 "^.*/usr/foo${whitespaces_}.*/usr/foo/test_prog$") set(EXPECTED_FILE_CONTENT_1 "^.*/usr/foo${whitespaces_}.*/usr/foo/test_prog$")
set(EXPECTED_FILE_2 "dependencies-applications_auto_0.1.1-1_*.deb") set(EXPECTED_FILE_2 "dependencies-0.1.1-*-applications_auto.deb")
set(EXPECTED_FILE_CONTENT_2 "^.*/usr/foo_auto${whitespaces_}.*/usr/foo_auto/test_prog$") set(EXPECTED_FILE_CONTENT_2 "^.*/usr/foo_auto${whitespaces_}.*/usr/foo_auto/test_prog$")
set(EXPECTED_FILE_3 "dependencies-headers_0.1.1-1_*.deb") set(EXPECTED_FILE_3 "dependencies-0.1.1-*-headers.deb")
set(EXPECTED_FILE_CONTENT_3 "^.*/usr/bar${whitespaces_}.*/usr/bar/CMakeLists.txt$") set(EXPECTED_FILE_CONTENT_3 "^.*/usr/bar${whitespaces_}.*/usr/bar/CMakeLists.txt$")
set(EXPECTED_FILE_4 "dependencies-libs_0.1.1-1_*.deb") set(EXPECTED_FILE_4 "dependencies-0.1.1-*-libs.deb")
# dynamic lib extension is .so on Linux and .dylib on Mac so we will use a wildcard .* for it # 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_4 "^.*/usr/bas${whitespaces_}.*/usr/bas/libtest_lib\\..*$")
set(EXPECTED_FILE_5 "dependencies-libs_auto_0.1.1-1_*.deb") set(EXPECTED_FILE_5 "dependencies-0.1.1-*-libs_auto.deb")
set(EXPECTED_FILE_CONTENT_5 "^.*/usr/bas_auto${whitespaces_}.*/usr/bas_auto/libtest_lib\\..*$") set(EXPECTED_FILE_CONTENT_5 "^.*/usr/bas_auto${whitespaces_}.*/usr/bas_auto/libtest_lib\\..*$")

View File

@ -1,5 +1,7 @@
set(CPACK_PACKAGE_CONTACT "someone") set(CPACK_PACKAGE_CONTACT "someone")
set(CPACK_DEB_COMPONENT_INSTALL "ON") set(CPACK_DEB_COMPONENT_INSTALL "ON")
#intentionaly commented out to test old file naming
#set(CPACK_DEBIAN_FILE_NAME "DEB-DEFAULT")
# false by default # false by default
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS FALSE) set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS FALSE)

View File

@ -1 +1,2 @@
set(CPACK_PACKAGE_CONTACT "someone") set(CPACK_PACKAGE_CONTACT "someone")
set(CPACK_DEBIAN_FILE_NAME "DEB-DEFAULT")

View File

@ -1 +1,2 @@
set(CPACK_PACKAGE_CONTACT "someone") set(CPACK_PACKAGE_CONTACT "someone")
set(CPACK_DEBIAN_FILE_NAME "DEB-DEFAULT")

View File

@ -1,5 +1,6 @@
set(CPACK_PACKAGE_CONTACT "someone") set(CPACK_PACKAGE_CONTACT "someone")
set(CPACK_DEB_COMPONENT_INSTALL "ON") set(CPACK_DEB_COMPONENT_INSTALL "ON")
set(CPACK_DEBIAN_FILE_NAME "DEB-DEFAULT")
set(CPACK_DEBIAN_PACKAGE_SECTION "default") set(CPACK_DEBIAN_PACKAGE_SECTION "default")
set(CPACK_DEBIAN_PKG_2_PACKAGE_NAME "second") set(CPACK_DEBIAN_PKG_2_PACKAGE_NAME "second")

View File

@ -34,5 +34,6 @@ set(CPACK_DEBIAN_BAR_PACKAGE_CONTROL_EXTRA
set(CPACK_PACKAGE_NAME "deb_extra") set(CPACK_PACKAGE_NAME "deb_extra")
set(CPACK_PACKAGE_CONTACT "someone") set(CPACK_PACKAGE_CONTACT "someone")
set(CPACK_DEBIAN_FILE_NAME "DEB-DEFAULT")
set(CPACK_DEB_COMPONENT_INSTALL ON) set(CPACK_DEB_COMPONENT_INSTALL ON)

View File

@ -1,5 +1,6 @@
set(CPACK_PACKAGE_CONTACT "someone") set(CPACK_PACKAGE_CONTACT "someone")
set(CPACK_DEB_COMPONENT_INSTALL "ON") set(CPACK_DEB_COMPONENT_INSTALL "ON")
set(CPACK_DEBIAN_FILE_NAME "DEB-DEFAULT")
set(CPACK_DEBIAN_PACKAGE_GENERATE_SHLIBS "ON") set(CPACK_DEBIAN_PACKAGE_GENERATE_SHLIBS "ON")

View File

@ -1,5 +1,6 @@
set(CPACK_PACKAGE_CONTACT "someone") set(CPACK_PACKAGE_CONTACT "someone")
set(CPACK_DEB_COMPONENT_INSTALL "ON") set(CPACK_DEB_COMPONENT_INSTALL "ON")
set(CPACK_DEBIAN_FILE_NAME "DEB-DEFAULT")
set(CPACK_DEBIAN_PACKAGE_GENERATE_SHLIBS "ON") set(CPACK_DEBIAN_PACKAGE_GENERATE_SHLIBS "ON")
set(CPACK_DEBIAN_PACKAGE_GENERATE_SHLIBS_POLICY ">=") set(CPACK_DEBIAN_PACKAGE_GENERATE_SHLIBS_POLICY ">=")

View File

@ -0,0 +1,5 @@
set(CPACK_RPM_COMPONENT_INSTALL "ON")
set(CPACK_RPM_FILE_NAME "RPM-DEFAULT")
set(CPACK_RPM_PKG_2_PACKAGE_NAME "second")
set(CPACK_RPM_PKG_3_FILE_NAME "pkg_3_abc.rpm")

View File

@ -0,0 +1,3 @@
^CPackRPM: Will use GENERATED spec file: .*/Tests/RunCMake/RPM/CPack/CUSTOM_NAMES-build/_CPack_Packages/.*/RPM/SPECS/custom_names-pkg_1.spec
CPackRPM: Will use GENERATED spec file: .*/Tests/RunCMake/RPM/CPack/CUSTOM_NAMES-build/_CPack_Packages/.*/RPM/SPECS/second.spec
CPackRPM: Will use GENERATED spec file: .*/Tests/RunCMake/RPM/CPack/CUSTOM_NAMES-build/_CPack_Packages/.*/RPM/SPECS/custom_names-pkg_3.spec$

View File

@ -1,3 +0,0 @@
^CPackRPM: Will use GENERATED spec file: .*/Tests/RunCMake/RPM/CPack/RPM_CUSTOM_NAMES-build/_CPack_Packages/.*/RPM/SPECS/custom_names-pkg_1.spec
CPackRPM: Will use GENERATED spec file: .*/Tests/RunCMake/RPM/CPack/RPM_CUSTOM_NAMES-build/_CPack_Packages/.*/RPM/SPECS/second.spec
CPackRPM: Will use GENERATED spec file: .*/Tests/RunCMake/RPM/CPack/RPM_CUSTOM_NAMES-build/_CPack_Packages/.*/RPM/SPECS/custom_names-pkg_3.spec$

View File

@ -10,7 +10,7 @@ run_cpack_test(DEB_EXTRA "DEB" false)
run_cpack_test(DEPENDENCIES "RPM;DEB" true) run_cpack_test(DEPENDENCIES "RPM;DEB" true)
run_cpack_test(EMPTY_DIR "RPM;DEB;TGZ" true) run_cpack_test(EMPTY_DIR "RPM;DEB;TGZ" true)
run_cpack_test(COMPONENTS_EMPTY_DIR "RPM;DEB;TGZ" true) run_cpack_test(COMPONENTS_EMPTY_DIR "RPM;DEB;TGZ" true)
run_cpack_test(RPM_CUSTOM_NAMES "RPM" true) run_cpack_test(CUSTOM_NAMES "RPM;DEB" true)
run_cpack_test(PER_COMPONENT_FIELDS "RPM;DEB" false) run_cpack_test(PER_COMPONENT_FIELDS "RPM;DEB" false)
run_cpack_test(RPM_DIST "RPM" false) run_cpack_test(RPM_DIST "RPM" false)
run_cpack_test(INSTALL_SCRIPTS "RPM" false) run_cpack_test(INSTALL_SCRIPTS "RPM" false)