Merge topic 'cpack-cmake-special-characters-mangling'

2a7772ff CPack: don't mangle CMake-special characters when applying default settings
This commit is contained in:
Brad King 2015-09-10 11:29:58 -04:00 committed by CMake Topic Stage
commit 72797dec8f
6 changed files with 68 additions and 43 deletions

View File

@ -0,0 +1,6 @@
CPack-updates
-------------
* The :module:`CPack` module no longer mangles settings with CMake-special
characters when they're used as defaults for other settings. The macro
``cpack_set_if_not_set``, which was responsible for this, is now deprecated.

View File

@ -299,10 +299,10 @@ endif()
include(CPackComponent) include(CPackComponent)
# Macro for setting values if a user did not overwrite them # Macro for setting values if a user did not overwrite them
# Mangles CMake-special characters. Only kept for backwards compatibility.
macro(cpack_set_if_not_set name value) macro(cpack_set_if_not_set name value)
if(NOT DEFINED "${name}") message(DEPRECATION "cpack_set_if_not_set is obsolete; do not use.")
set(${name} "${value}") _cpack_set_default("${name}" "${value}")
endif()
endmacro() endmacro()
# cpack_encode_variables - Macro to encode variables for the configuration file # cpack_encode_variables - Macro to encode variables for the configuration file
@ -321,27 +321,34 @@ macro(cpack_encode_variables)
endforeach() endforeach()
endmacro() endmacro()
# Internal use functions
function(_cpack_set_default name value)
if(NOT DEFINED "${name}")
set("${name}" "${value}" PARENT_SCOPE)
endif()
endfunction()
# Set the package name # Set the package name
cpack_set_if_not_set(CPACK_PACKAGE_NAME "${CMAKE_PROJECT_NAME}") _cpack_set_default(CPACK_PACKAGE_NAME "${CMAKE_PROJECT_NAME}")
cpack_set_if_not_set(CPACK_PACKAGE_VERSION_MAJOR "0") _cpack_set_default(CPACK_PACKAGE_VERSION_MAJOR "0")
cpack_set_if_not_set(CPACK_PACKAGE_VERSION_MINOR "1") _cpack_set_default(CPACK_PACKAGE_VERSION_MINOR "1")
cpack_set_if_not_set(CPACK_PACKAGE_VERSION_PATCH "1") _cpack_set_default(CPACK_PACKAGE_VERSION_PATCH "1")
cpack_set_if_not_set(CPACK_PACKAGE_VERSION _cpack_set_default(CPACK_PACKAGE_VERSION
"${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}") "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
cpack_set_if_not_set(CPACK_PACKAGE_VENDOR "Humanity") _cpack_set_default(CPACK_PACKAGE_VENDOR "Humanity")
cpack_set_if_not_set(CPACK_PACKAGE_DESCRIPTION_SUMMARY _cpack_set_default(CPACK_PACKAGE_DESCRIPTION_SUMMARY
"${CMAKE_PROJECT_NAME} built using CMake") "${CMAKE_PROJECT_NAME} built using CMake")
cpack_set_if_not_set(CPACK_PACKAGE_DESCRIPTION_FILE _cpack_set_default(CPACK_PACKAGE_DESCRIPTION_FILE
"${CMAKE_ROOT}/Templates/CPack.GenericDescription.txt") "${CMAKE_ROOT}/Templates/CPack.GenericDescription.txt")
cpack_set_if_not_set(CPACK_RESOURCE_FILE_LICENSE _cpack_set_default(CPACK_RESOURCE_FILE_LICENSE
"${CMAKE_ROOT}/Templates/CPack.GenericLicense.txt") "${CMAKE_ROOT}/Templates/CPack.GenericLicense.txt")
cpack_set_if_not_set(CPACK_RESOURCE_FILE_README _cpack_set_default(CPACK_RESOURCE_FILE_README
"${CMAKE_ROOT}/Templates/CPack.GenericDescription.txt") "${CMAKE_ROOT}/Templates/CPack.GenericDescription.txt")
cpack_set_if_not_set(CPACK_RESOURCE_FILE_WELCOME _cpack_set_default(CPACK_RESOURCE_FILE_WELCOME
"${CMAKE_ROOT}/Templates/CPack.GenericWelcome.txt") "${CMAKE_ROOT}/Templates/CPack.GenericWelcome.txt")
cpack_set_if_not_set(CPACK_MODULE_PATH "${CMAKE_MODULE_PATH}") _cpack_set_default(CPACK_MODULE_PATH "${CMAKE_MODULE_PATH}")
if(CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL) if(CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL)
set(CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL ON) set(CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL ON)
@ -359,7 +366,7 @@ if(__cpack_system_name MATCHES "Windows")
set(__cpack_system_name win32) set(__cpack_system_name win32)
endif() endif()
endif() endif()
cpack_set_if_not_set(CPACK_SYSTEM_NAME "${__cpack_system_name}") _cpack_set_default(CPACK_SYSTEM_NAME "${__cpack_system_name}")
# Root dir: default value should be the string literal "$PROGRAMFILES" # Root dir: default value should be the string literal "$PROGRAMFILES"
# for backwards compatibility. Projects may set this value to anything. # for backwards compatibility. Projects may set this value to anything.
@ -369,17 +376,17 @@ if("x${__cpack_system_name}" STREQUAL "xwin64")
else() else()
set(__cpack_root_default "$PROGRAMFILES") set(__cpack_root_default "$PROGRAMFILES")
endif() endif()
cpack_set_if_not_set(CPACK_NSIS_INSTALL_ROOT "${__cpack_root_default}") _cpack_set_default(CPACK_NSIS_INSTALL_ROOT "${__cpack_root_default}")
# <project>-<major>.<minor>.<patch>-<release>-<platform>.<pkgtype> # <project>-<major>.<minor>.<patch>-<release>-<platform>.<pkgtype>
cpack_set_if_not_set(CPACK_PACKAGE_FILE_NAME _cpack_set_default(CPACK_PACKAGE_FILE_NAME
"${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CPACK_SYSTEM_NAME}") "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CPACK_SYSTEM_NAME}")
cpack_set_if_not_set(CPACK_PACKAGE_INSTALL_DIRECTORY _cpack_set_default(CPACK_PACKAGE_INSTALL_DIRECTORY
"${CPACK_PACKAGE_NAME} ${CPACK_PACKAGE_VERSION}") "${CPACK_PACKAGE_NAME} ${CPACK_PACKAGE_VERSION}")
cpack_set_if_not_set(CPACK_PACKAGE_INSTALL_REGISTRY_KEY _cpack_set_default(CPACK_PACKAGE_INSTALL_REGISTRY_KEY
"${CPACK_PACKAGE_INSTALL_DIRECTORY}") "${CPACK_PACKAGE_INSTALL_DIRECTORY}")
cpack_set_if_not_set(CPACK_PACKAGE_DEFAULT_LOCATION "/") _cpack_set_default(CPACK_PACKAGE_DEFAULT_LOCATION "/")
cpack_set_if_not_set(CPACK_PACKAGE_RELOCATABLE "true") _cpack_set_default(CPACK_PACKAGE_RELOCATABLE "true")
# always force to exactly "true" or "false" for CPack.Info.plist.in: # always force to exactly "true" or "false" for CPack.Info.plist.in:
if(CPACK_PACKAGE_RELOCATABLE) if(CPACK_PACKAGE_RELOCATABLE)
@ -519,10 +526,10 @@ mark_as_advanced(
) )
# Set some other variables # Set some other variables
cpack_set_if_not_set(CPACK_INSTALL_CMAKE_PROJECTS _cpack_set_default(CPACK_INSTALL_CMAKE_PROJECTS
"${CMAKE_BINARY_DIR};${CMAKE_PROJECT_NAME};ALL;/") "${CMAKE_BINARY_DIR};${CMAKE_PROJECT_NAME};ALL;/")
cpack_set_if_not_set(CPACK_CMAKE_GENERATOR "${CMAKE_GENERATOR}") _cpack_set_default(CPACK_CMAKE_GENERATOR "${CMAKE_GENERATOR}")
cpack_set_if_not_set(CPACK_TOPLEVEL_TAG "${CPACK_SYSTEM_NAME}") _cpack_set_default(CPACK_TOPLEVEL_TAG "${CPACK_SYSTEM_NAME}")
# if the user has set CPACK_NSIS_DISPLAY_NAME remember it # if the user has set CPACK_NSIS_DISPLAY_NAME remember it
if(DEFINED CPACK_NSIS_DISPLAY_NAME) if(DEFINED CPACK_NSIS_DISPLAY_NAME)
set(CPACK_NSIS_DISPLAY_NAME_SET TRUE) set(CPACK_NSIS_DISPLAY_NAME_SET TRUE)
@ -531,34 +538,32 @@ endif()
# explicitly, then use that as the default # explicitly, then use that as the default
# value of CPACK_NSIS_PACKAGE_NAME instead # value of CPACK_NSIS_PACKAGE_NAME instead
# of CPACK_PACKAGE_INSTALL_DIRECTORY # of CPACK_PACKAGE_INSTALL_DIRECTORY
cpack_set_if_not_set(CPACK_NSIS_DISPLAY_NAME "${CPACK_PACKAGE_INSTALL_DIRECTORY}") _cpack_set_default(CPACK_NSIS_DISPLAY_NAME "${CPACK_PACKAGE_INSTALL_DIRECTORY}")
if(CPACK_NSIS_DISPLAY_NAME_SET) if(CPACK_NSIS_DISPLAY_NAME_SET)
string(REPLACE "\\" "\\\\" _cpack_set_default(CPACK_NSIS_PACKAGE_NAME "${CPACK_NSIS_DISPLAY_NAME}")
_NSIS_DISPLAY_NAME_TMP "${CPACK_NSIS_DISPLAY_NAME}")
cpack_set_if_not_set(CPACK_NSIS_PACKAGE_NAME "${_NSIS_DISPLAY_NAME_TMP}")
else() else()
cpack_set_if_not_set(CPACK_NSIS_PACKAGE_NAME "${CPACK_PACKAGE_INSTALL_DIRECTORY}") _cpack_set_default(CPACK_NSIS_PACKAGE_NAME "${CPACK_PACKAGE_INSTALL_DIRECTORY}")
endif() endif()
cpack_set_if_not_set(CPACK_OUTPUT_CONFIG_FILE _cpack_set_default(CPACK_OUTPUT_CONFIG_FILE
"${CMAKE_BINARY_DIR}/CPackConfig.cmake") "${CMAKE_BINARY_DIR}/CPackConfig.cmake")
cpack_set_if_not_set(CPACK_SOURCE_OUTPUT_CONFIG_FILE _cpack_set_default(CPACK_SOURCE_OUTPUT_CONFIG_FILE
"${CMAKE_BINARY_DIR}/CPackSourceConfig.cmake") "${CMAKE_BINARY_DIR}/CPackSourceConfig.cmake")
cpack_set_if_not_set(CPACK_SET_DESTDIR OFF) _cpack_set_default(CPACK_SET_DESTDIR OFF)
cpack_set_if_not_set(CPACK_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}") _cpack_set_default(CPACK_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
cpack_set_if_not_set(CPACK_NSIS_INSTALLER_ICON_CODE "") _cpack_set_default(CPACK_NSIS_INSTALLER_ICON_CODE "")
cpack_set_if_not_set(CPACK_NSIS_INSTALLER_MUI_ICON_CODE "") _cpack_set_default(CPACK_NSIS_INSTALLER_MUI_ICON_CODE "")
# WiX specific variables # WiX specific variables
cpack_set_if_not_set(CPACK_WIX_SIZEOF_VOID_P "${CMAKE_SIZEOF_VOID_P}") _cpack_set_default(CPACK_WIX_SIZEOF_VOID_P "${CMAKE_SIZEOF_VOID_P}")
# set sysroot so SDK tools can be used # set sysroot so SDK tools can be used
if(CMAKE_OSX_SYSROOT) if(CMAKE_OSX_SYSROOT)
cpack_set_if_not_set(CPACK_OSX_SYSROOT "${CMAKE_OSX_SYSROOT}") _cpack_set_default(CPACK_OSX_SYSROOT "${CMAKE_OSX_SYSROOT}")
endif() endif()
if(DEFINED CPACK_COMPONENTS_ALL) if(DEFINED CPACK_COMPONENTS_ALL)
@ -598,13 +603,13 @@ cpack_encode_variables()
configure_file("${cpack_input_file}" "${CPACK_OUTPUT_CONFIG_FILE}" @ONLY) configure_file("${cpack_input_file}" "${CPACK_OUTPUT_CONFIG_FILE}" @ONLY)
# Generate source file # Generate source file
cpack_set_if_not_set(CPACK_SOURCE_INSTALLED_DIRECTORIES _cpack_set_default(CPACK_SOURCE_INSTALLED_DIRECTORIES
"${CMAKE_SOURCE_DIR};/") "${CMAKE_SOURCE_DIR};/")
cpack_set_if_not_set(CPACK_SOURCE_TOPLEVEL_TAG "${CPACK_SYSTEM_NAME}-Source") _cpack_set_default(CPACK_SOURCE_TOPLEVEL_TAG "${CPACK_SYSTEM_NAME}-Source")
cpack_set_if_not_set(CPACK_SOURCE_PACKAGE_FILE_NAME _cpack_set_default(CPACK_SOURCE_PACKAGE_FILE_NAME
"${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-Source") "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-Source")
cpack_set_if_not_set(CPACK_SOURCE_IGNORE_FILES _cpack_set_default(CPACK_SOURCE_IGNORE_FILES
"/CVS/;/\\\\\\\\.svn/;/\\\\\\\\.bzr/;/\\\\\\\\.hg/;/\\\\\\\\.git/;\\\\\\\\.swp$;\\\\\\\\.#;/#") "/CVS/;/\\\\.svn/;/\\\\.bzr/;/\\\\.hg/;/\\\\.git/;\\\\.swp$;\\\\.#;/#")
set(CPACK_INSTALL_CMAKE_PROJECTS "${CPACK_SOURCE_INSTALL_CMAKE_PROJECTS}") set(CPACK_INSTALL_CMAKE_PROJECTS "${CPACK_SOURCE_INSTALL_CMAKE_PROJECTS}")
set(CPACK_INSTALLED_DIRECTORIES "${CPACK_SOURCE_INSTALLED_DIRECTORIES}") set(CPACK_INSTALLED_DIRECTORIES "${CPACK_SOURCE_INSTALLED_DIRECTORIES}")
set(CPACK_GENERATOR "${CPACK_SOURCE_GENERATOR}") set(CPACK_GENERATOR "${CPACK_SOURCE_GENERATOR}")

View File

@ -0,0 +1,7 @@
include(${RunCMake_SOURCE_DIR}/check.cmake)
test_variable(CPACK_PACKAGE_INSTALL_REGISTRY_KEY "Foo\\Bar")
test_variable(CPACK_NSIS_PACKAGE_NAME "Bar\\Foo")
test_variable(CPACK_SOURCE_IGNORE_FILES
"/CVS/;/\\.svn/;/\\.bzr/;/\\.hg/;/\\.git/;\\.swp$;\\.#;/#")

View File

@ -0,0 +1,3 @@
# two levels of escaping to pass through CPackConfig.cmake
set(CPACK_PACKAGE_INSTALL_DIRECTORY "Foo\\\\Bar")
set(CPACK_NSIS_DISPLAY_NAME "Bar\\\\Foo")

View File

@ -1,3 +1,4 @@
include(RunCMake) include(RunCMake)
run_cmake(Simple) run_cmake(Simple)
run_cmake(Default)

View File

@ -1,3 +1,5 @@
cmake_minimum_required(VERSION ${CMAKE_VERSION} FATAL_ERROR)
function(test_variable NAME EXPECTED_VALUE) function(test_variable NAME EXPECTED_VALUE)
if(NOT "${${NAME}}" STREQUAL "${EXPECTED_VALUE}") if(NOT "${${NAME}}" STREQUAL "${EXPECTED_VALUE}")
message(FATAL_ERROR "${NAME}: variable mismatch; expected [${EXPECTED_VALUE}] actual [${${NAME}}]") message(FATAL_ERROR "${NAME}: variable mismatch; expected [${EXPECTED_VALUE}] actual [${${NAME}}]")
@ -5,3 +7,4 @@ function(test_variable NAME EXPECTED_VALUE)
endfunction() endfunction()
include(${RunCMake_TEST_BINARY_DIR}/CPackConfig.cmake) include(${RunCMake_TEST_BINARY_DIR}/CPackConfig.cmake)
include(${RunCMake_TEST_BINARY_DIR}/CPackSourceConfig.cmake)