install(files): Support genex in rename option

Fixes: #19903
This commit is contained in:
Asit Dhal
2021-01-13 11:27:56 +01:00
parent 20a7d4485c
commit ac3ccc393e
10 changed files with 44 additions and 2 deletions

View File

@@ -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
^^^^^^^^^^^^^^^^^^^^^^

View File

@@ -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)>`.

View File

@@ -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,

View File

@@ -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;

View File

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

View File

@@ -0,0 +1 @@
1

View File

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

View File

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

View File

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

View File

@@ -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()