Sfoglia il codice sorgente

install(files): Support genex in rename option

Fixes: #19903
Asit Dhal 4 anni fa
parent
commit
ac3ccc393e

+ 5 - 0
Help/command/install.rst

@@ -473,6 +473,11 @@ this advice while installing headers to a project-specific subdirectory:
   use "generator expressions" with the syntax ``$<...>``.  See the
   :manual:`cmake-generator-expressions(7)` manual for available expressions.
 
+.. versionadded:: 3.20
+  An install rename given as a ``RENAME`` argument may
+  use "generator expressions" with the syntax ``$<...>``.  See the
+  :manual:`cmake-generator-expressions(7)` manual for available expressions.
+
 Installing Directories
 ^^^^^^^^^^^^^^^^^^^^^^
 

+ 5 - 0
Help/release/dev/install-files-rename-genex.rst

@@ -0,0 +1,5 @@
+install-files-rename-genex
+--------------------------
+
+* The :command:`install(FILES)` command ``RENAME`` option learned to
+  support :manual:`generator expressions <cmake-generator-expressions(7)>`.

+ 12 - 2
Source/cmInstallFilesGenerator.cxx

@@ -25,10 +25,14 @@ cmInstallFilesGenerator::cmInstallFilesGenerator(
   , Programs(programs)
   , Optional(optional)
 {
-  // We need per-config actions if the destination has generator expressions.
+  // We need per-config actions if the destination and rename have generator
+  // expressions.
   if (cmGeneratorExpression::Find(this->Destination) != std::string::npos) {
     this->ActionsPerConfig = true;
   }
+  if (cmGeneratorExpression::Find(this->Rename) != std::string::npos) {
+    this->ActionsPerConfig = true;
+  }
 
   // We need per-config actions if any directories have generator expressions.
   if (!this->ActionsPerConfig) {
@@ -56,6 +60,12 @@ std::string cmInstallFilesGenerator::GetDestination(
                                          this->LocalGenerator, config);
 }
 
+std::string cmInstallFilesGenerator::GetRename(std::string const& config) const
+{
+  return cmGeneratorExpression::Evaluate(this->Rename, this->LocalGenerator,
+                                         config);
+}
+
 void cmInstallFilesGenerator::AddFilesInstallRule(
   std::ostream& os, std::string const& config, Indent indent,
   std::vector<std::string> const& files)
@@ -66,7 +76,7 @@ void cmInstallFilesGenerator::AddFilesInstallRule(
     os, this->GetDestination(config),
     (this->Programs ? cmInstallType_PROGRAMS : cmInstallType_FILES), files,
     this->Optional, this->FilePermissions.c_str(), no_dir_permissions,
-    this->Rename.c_str(), nullptr, indent);
+    this->GetRename(config).c_str(), nullptr, indent);
 }
 
 void cmInstallFilesGenerator::GenerateScriptActions(std::ostream& os,

+ 1 - 0
Source/cmInstallFilesGenerator.h

@@ -31,6 +31,7 @@ public:
   bool Compute(cmLocalGenerator* lg) override;
 
   std::string GetDestination(std::string const& config) const;
+  std::string GetRename(std::string const& config) const;
 
 protected:
   void GenerateScriptActions(std::ostream& os, Indent indent) override;

+ 1 - 0
Tests/RunCMake/install/FILES-RENAME-all-check.cmake

@@ -0,0 +1 @@
+check_installed([[^src;src/script_Debug\.ps]])

+ 1 - 0
Tests/RunCMake/install/FILES-RENAME-bad-result.txt

@@ -0,0 +1 @@
+1

+ 6 - 0
Tests/RunCMake/install/FILES-RENAME-bad-stderr.txt

@@ -0,0 +1,6 @@
+CMake Error:
+  Error evaluating generator expression:
+
+    \$<NOTAGENEX>
+
+  Expression did not evaluate to a known generator expression

+ 4 - 0
Tests/RunCMake/install/FILES-RENAME-bad.cmake

@@ -0,0 +1,4 @@
+install(FILES empty.c
+  DESTINATION mybin
+  RENAME $<NOTAGENEX>
+  )

+ 4 - 0
Tests/RunCMake/install/FILES-RENAME.cmake

@@ -0,0 +1,4 @@
+install(FILES script.bat
+  DESTINATION src
+  RENAME script_$<CONFIG>.ps
+  )

+ 5 - 0
Tests/RunCMake/install/RunCMakeTest.cmake

@@ -74,6 +74,7 @@ run_cmake(SkipInstallRulesNoWarning2)
 run_cmake(DIRECTORY-DIRECTORY-bad)
 run_cmake(DIRECTORY-DESTINATION-bad)
 run_cmake(FILES-DESTINATION-bad)
+run_cmake(FILES-RENAME-bad)
 run_cmake(TARGETS-DESTINATION-bad)
 run_cmake(EXPORT-OldIFace)
 run_cmake(EXPORT-UnknownExport)
@@ -91,6 +92,10 @@ run_cmake(TARGETS-NAMELINK_COMPONENT-bad-exc)
 run_cmake(FILES-DESTINATION-TYPE)
 run_cmake(DIRECTORY-DESTINATION-TYPE)
 
+set(RunCMake_TEST_OPTIONS "-DCMAKE_BUILD_TYPE:STRING=Debug")
+run_install_test(FILES-RENAME)
+unset(RunCMake_TEST_OPTIONS)
+
 if(APPLE)
   run_cmake(TARGETS-Apple-Defaults)
 endif()