summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Help/manual/cmake-generator-expressions.7.rst6
-rw-r--r--Help/release/dev/install-prefix-genex-install-code-script.rst5
-rw-r--r--Source/cmInstallCommand.cxx16
-rw-r--r--Source/cmInstallScriptGenerator.cxx10
-rw-r--r--Tests/RunCMake/install/RunCMakeTest.cmake5
-rw-r--r--Tests/RunCMake/install/SCRIPT-all-check.cmake2
-rw-r--r--Tests/RunCMake/install/SCRIPT.cmake6
-rw-r--r--Tests/RunCMake/install/empty3.cmake1
-rw-r--r--Tests/RunCMake/install/empty4.cmake1
9 files changed, 36 insertions, 16 deletions
diff --git a/Help/manual/cmake-generator-expressions.7.rst b/Help/manual/cmake-generator-expressions.7.rst
index 8a92b4b..ae52ba1 100644
--- a/Help/manual/cmake-generator-expressions.7.rst
+++ b/Help/manual/cmake-generator-expressions.7.rst
@@ -1734,8 +1734,10 @@ Export And Install Expressions
Content of the install prefix when the target is exported via
:command:`install(EXPORT)`, or when evaluated in the
- :prop_tgt:`INSTALL_NAME_DIR` property or the ``INSTALL_NAME_DIR`` argument of
- :command:`install(RUNTIME_DEPENDENCY_SET)`, and empty otherwise.
+ :prop_tgt:`INSTALL_NAME_DIR` property, the ``INSTALL_NAME_DIR`` argument of
+ :command:`install(RUNTIME_DEPENDENCY_SET)`, the code argument of
+ :command:`install(CODE)`, or the file argument of :command:`install(SCRIPT)`,
+ and empty otherwise.
Multi-level Expression Evaluation
---------------------------------
diff --git a/Help/release/dev/install-prefix-genex-install-code-script.rst b/Help/release/dev/install-prefix-genex-install-code-script.rst
new file mode 100644
index 0000000..810f448
--- /dev/null
+++ b/Help/release/dev/install-prefix-genex-install-code-script.rst
@@ -0,0 +1,5 @@
+install-prefix-genex-install-code-script
+----------------------------------------
+
+* The :command:`install(CODE)` and :command:`install(SCRIPT)` commands
+ now support the :genex:`$<INSTALL_PREFIX>` generator expression.
diff --git a/Source/cmInstallCommand.cxx b/Source/cmInstallCommand.cxx
index 82adca8..56c8b26 100644
--- a/Source/cmInstallCommand.cxx
+++ b/Source/cmInstallCommand.cxx
@@ -359,13 +359,15 @@ bool HandleScriptMode(std::vector<std::string> const& args,
} else if (doing_script) {
doing_script = false;
std::string script = arg;
- if (!cmSystemTools::FileIsFullPath(script)) {
- script =
- cmStrCat(helper.Makefile->GetCurrentSourceDirectory(), '/', arg);
- }
- if (cmSystemTools::FileIsDirectory(script)) {
- status.SetError("given a directory as value of SCRIPT argument.");
- return false;
+ if (!cmHasLiteralPrefix(script, "$<INSTALL_PREFIX>")) {
+ if (!cmSystemTools::FileIsFullPath(script)) {
+ script =
+ cmStrCat(helper.Makefile->GetCurrentSourceDirectory(), '/', arg);
+ }
+ if (cmSystemTools::FileIsDirectory(script)) {
+ status.SetError("given a directory as value of SCRIPT argument.");
+ return false;
+ }
}
helper.Makefile->AddInstallGenerator(
cm::make_unique<cmInstallScriptGenerator>(
diff --git a/Source/cmInstallScriptGenerator.cxx b/Source/cmInstallScriptGenerator.cxx
index a5625fe..af531f2 100644
--- a/Source/cmInstallScriptGenerator.cxx
+++ b/Source/cmInstallScriptGenerator.cxx
@@ -56,12 +56,12 @@ bool cmInstallScriptGenerator::Compute(cmLocalGenerator* lg)
std::string cmInstallScriptGenerator::GetScript(
std::string const& config) const
{
- std::string script;
+ std::string script = this->Script;
if (this->AllowGenex && this->ActionsPerConfig) {
- script = cmGeneratorExpression::Evaluate(this->Script,
- this->LocalGenerator, config);
- } else {
- script = this->Script;
+ cmGeneratorExpression::ReplaceInstallPrefix(script,
+ "${CMAKE_INSTALL_PREFIX}");
+ script =
+ cmGeneratorExpression::Evaluate(script, this->LocalGenerator, config);
}
return script;
}
diff --git a/Tests/RunCMake/install/RunCMakeTest.cmake b/Tests/RunCMake/install/RunCMakeTest.cmake
index fa61bdb..e5a0413 100644
--- a/Tests/RunCMake/install/RunCMakeTest.cmake
+++ b/Tests/RunCMake/install/RunCMakeTest.cmake
@@ -166,7 +166,6 @@ unset(RunCMake_TEST_OPTIONS)
run_install_test(Deprecated)
run_install_test(PRE_POST_INSTALL_SCRIPT)
-run_install_test(SCRIPT)
run_install_test(TARGETS-CONFIGURATIONS)
run_install_test(DIRECTORY-PATTERN)
run_install_test(TARGETS-Parts)
@@ -174,6 +173,10 @@ run_install_test(FILES-PERMISSIONS)
run_install_test(TARGETS-RPATH)
run_install_test(InstallRequiredSystemLibraries)
+set(RunCMake_TEST_OPTIONS "-DCMAKE_POLICY_DEFAULT_CMP0087:STRING=NEW")
+run_install_test(SCRIPT)
+unset(RunCMake_TEST_OPTIONS)
+
if(UNIX)
run_install_test(DIRECTORY-symlink-clobber)
endif()
diff --git a/Tests/RunCMake/install/SCRIPT-all-check.cmake b/Tests/RunCMake/install/SCRIPT-all-check.cmake
index 48d8e1a..b9c38e3 100644
--- a/Tests/RunCMake/install/SCRIPT-all-check.cmake
+++ b/Tests/RunCMake/install/SCRIPT-all-check.cmake
@@ -1 +1 @@
-check_installed([[^empty1.txt;empty2.txt$]])
+check_installed([[^empty1.txt;empty2.txt;empty3.cmake;empty3.txt;empty4.cmake;empty4.txt$]])
diff --git a/Tests/RunCMake/install/SCRIPT.cmake b/Tests/RunCMake/install/SCRIPT.cmake
index f857b54..ee0c80e 100644
--- a/Tests/RunCMake/install/SCRIPT.cmake
+++ b/Tests/RunCMake/install/SCRIPT.cmake
@@ -1,4 +1,10 @@
install(
+ FILES ${CMAKE_CURRENT_SOURCE_DIR}/empty3.cmake ${CMAKE_CURRENT_SOURCE_DIR}/empty4.cmake
+ DESTINATION .
+ )
+install(
SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/install_script.cmake"
CODE "write_empty_file(empty2.txt)"
+ SCRIPT "$<INSTALL_PREFIX>/empty3.cmake"
+ CODE [[include($<INSTALL_PREFIX>/empty4.cmake)]]
)
diff --git a/Tests/RunCMake/install/empty3.cmake b/Tests/RunCMake/install/empty3.cmake
new file mode 100644
index 0000000..18c2ac5
--- /dev/null
+++ b/Tests/RunCMake/install/empty3.cmake
@@ -0,0 +1 @@
+write_empty_file(empty3.txt)
diff --git a/Tests/RunCMake/install/empty4.cmake b/Tests/RunCMake/install/empty4.cmake
new file mode 100644
index 0000000..026a4d2
--- /dev/null
+++ b/Tests/RunCMake/install/empty4.cmake
@@ -0,0 +1 @@
+write_empty_file(empty4.txt)