summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorRoman Donchenko <dpb@corrigendum.ru>2015-09-20 21:39:03 (GMT)
committerDomen Vrankar <domen.vrankar@gmail.com>2015-09-20 21:39:03 (GMT)
commitbc2e54db5516ed884f0affe020e52256f0c8b3d5 (patch)
tree997e1a68a082bf6f72cc4e4a4c6e4fc1f1514cfb /Modules
parentba7f7067cafe187d5f95b87c959751cdf1a8b0b6 (diff)
downloadCMake-bc2e54db5516ed884f0affe020e52256f0c8b3d5.zip
CMake-bc2e54db5516ed884f0affe020e52256f0c8b3d5.tar.gz
CMake-bc2e54db5516ed884f0affe020e52256f0c8b3d5.tar.bz2
Introduction of CPACK_VERBATIM_VARIABLES variable
If variable is set to TRUE, values of all variables prefixed with CPACK_ will be escaped so special characters such as dolar sign, quotes or foreward slash will not be lost. By default variable is treated as set to FALSE for back compatibility. The cpack_encode_variables macro is changed into a function to remove scope pollution. There should be no other effects.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/CPack.cmake46
1 files changed, 38 insertions, 8 deletions
diff --git a/Modules/CPack.cmake b/Modules/CPack.cmake
index 7d6d54c..5756001 100644
--- a/Modules/CPack.cmake
+++ b/Modules/CPack.cmake
@@ -182,6 +182,17 @@
# will be a boolean variable which enables stripping of all files (a list
# of files evaluates to TRUE in CMake, so this change is compatible).
#
+# .. variable:: CPACK_VERBATIM_VARIABLES
+#
+# If set to TRUE, values of variables prefixed with CPACK_ will be escaped
+# before being written to the configuration files, so that the cpack program
+# receives them exactly as they were specified. If not, characters like quotes
+# and backslashes can cause parsing errors or alter the value received by the
+# cpack program. Defaults to FALSE for backwards compatibility.
+#
+# * Mandatory : NO
+# * Default : FALSE
+#
# The following CPack variables are specific to source packages, and
# will not affect binary packages:
#
@@ -305,21 +316,28 @@ macro(cpack_set_if_not_set name value)
_cpack_set_default("${name}" "${value}")
endmacro()
-# cpack_encode_variables - Macro to encode variables for the configuration file
+# cpack_encode_variables - Function to encode variables for the configuration file
# find any variable that starts with CPACK and create a variable
# _CPACK_OTHER_VARIABLES_ that contains SET commands for
# each cpack variable. _CPACK_OTHER_VARIABLES_ is then
# used as an @ replacment in configure_file for the CPackConfig.
-macro(cpack_encode_variables)
- set(_CPACK_OTHER_VARIABLES_)
+function(cpack_encode_variables)
+ set(commands "")
get_cmake_property(res VARIABLES)
foreach(var ${res})
if(var MATCHES "^CPACK")
- set(_CPACK_OTHER_VARIABLES_
- "${_CPACK_OTHER_VARIABLES_}\nSET(${var} \"${${var}}\")")
+ if(CPACK_VERBATIM_VARIABLES)
+ _cpack_escape_for_cmake(value "${${var}}")
+ else()
+ set(value "${${var}}")
endif()
+
+ set(commands "${commands}\nSET(${var} \"${value}\")")
+ endif()
endforeach()
-endmacro()
+
+ set(_CPACK_OTHER_VARIABLES_ "${commands}" PARENT_SCOPE)
+endfunction()
# Internal use functions
function(_cpack_set_default name value)
@@ -328,6 +346,11 @@ function(_cpack_set_default name value)
endif()
endfunction()
+function(_cpack_escape_for_cmake var value)
+ string(REGEX REPLACE "([\\\$\"])" "\\\\\\1" escaped "${value}")
+ set("${var}" "${escaped}" PARENT_SCOPE)
+endfunction()
+
# Set the package name
_cpack_set_default(CPACK_PACKAGE_NAME "${CMAKE_PROJECT_NAME}")
_cpack_set_default(CPACK_PACKAGE_VERSION_MAJOR "0")
@@ -608,8 +631,15 @@ _cpack_set_default(CPACK_SOURCE_INSTALLED_DIRECTORIES
_cpack_set_default(CPACK_SOURCE_TOPLEVEL_TAG "${CPACK_SYSTEM_NAME}-Source")
_cpack_set_default(CPACK_SOURCE_PACKAGE_FILE_NAME
"${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-Source")
-_cpack_set_default(CPACK_SOURCE_IGNORE_FILES
- "/CVS/;/\\\\.svn/;/\\\\.bzr/;/\\\\.hg/;/\\\\.git/;\\\\.swp$;\\\\.#;/#")
+
+set(__cpack_source_ignore_files_default
+ "/CVS/;/\\.svn/;/\\.bzr/;/\\.hg/;/\\.git/;\\.swp$;\\.#;/#")
+if(NOT CPACK_VERBATIM_VARIABLES)
+ _cpack_escape_for_cmake(__cpack_source_ignore_files_default
+ "${__cpack_source_ignore_files_default}")
+endif()
+_cpack_set_default(CPACK_SOURCE_IGNORE_FILES "${__cpack_source_ignore_files_default}")
+
set(CPACK_INSTALL_CMAKE_PROJECTS "${CPACK_SOURCE_INSTALL_CMAKE_PROJECTS}")
set(CPACK_INSTALLED_DIRECTORIES "${CPACK_SOURCE_INSTALLED_DIRECTORIES}")
set(CPACK_GENERATOR "${CPACK_SOURCE_GENERATOR}")