install: Allow generator expressions in DIRECTORY

Teach install(DIRECTORY) to support generator expressions in the list
of directories, much like install(FILES) already supports.
This commit is contained in:
Yves Frederix 2016-01-12 21:01:07 +01:00 committed by Brad King
parent b5009720d3
commit 630c8aa843
11 changed files with 50 additions and 13 deletions

View File

@ -271,9 +271,10 @@ will install the ``icons`` directory to ``share/myproj/icons`` and the
file permissions, the scripts will be given specific permissions, and any file permissions, the scripts will be given specific permissions, and any
``CVS`` directories will be excluded. ``CVS`` directories will be excluded.
The install destination given to the directory install ``DESTINATION`` may The list of ``dirs...`` given to ``DIRECTORY`` and the install destination
use "generator expressions" with the syntax ``$<...>``. See the given to the directory install ``DESTINATION`` may use "generator expressions"
:manual:`cmake-generator-expressions(7)` manual for available expressions. with the syntax ``$<...>``. See the :manual:`cmake-generator-expressions(7)`
manual for available expressions.
Custom Installation Logic Custom Installation Logic
^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -0,0 +1,6 @@
install-DIRECTORY-genex
-----------------------
* The :command:`install(DIRECTORY)` command learned to support
:manual:`generator expressions <cmake-generator-expressions(7)>`
in the list of directories.

View File

@ -36,6 +36,16 @@ cmInstallDirectoryGenerator
{ {
this->ActionsPerConfig = true; this->ActionsPerConfig = true;
} }
// We need per-config actions if any directories have generator expressions.
for(std::vector<std::string>::const_iterator i = dirs.begin();
!this->ActionsPerConfig && i != dirs.end(); ++i)
{
if(cmGeneratorExpression::Find(*i) != std::string::npos)
{
this->ActionsPerConfig = true;
}
}
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
@ -60,7 +70,7 @@ cmInstallDirectoryGenerator::GenerateScriptActions(std::ostream& os,
} }
else else
{ {
this->AddDirectoryInstallRule(os, "", indent); this->AddDirectoryInstallRule(os, "", indent, this->Directories);
} }
} }
@ -69,20 +79,30 @@ void cmInstallDirectoryGenerator::GenerateScriptForConfig(
const std::string& config, const std::string& config,
Indent const& indent) Indent const& indent)
{ {
this->AddDirectoryInstallRule(os, config, indent); std::vector<std::string> dirs;
cmGeneratorExpression ge;
for(std::vector<std::string>::const_iterator i = this->Directories.begin();
i != this->Directories.end(); ++i)
{
cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(*i);
cmSystemTools::ExpandListArgument(cge->Evaluate(
this->LocalGenerator, config), dirs);
}
this->AddDirectoryInstallRule(os, config, indent, dirs);
} }
void cmInstallDirectoryGenerator::AddDirectoryInstallRule( void cmInstallDirectoryGenerator::AddDirectoryInstallRule(
std::ostream& os, std::ostream& os,
const std::string& config, const std::string& config,
Indent const& indent) Indent const& indent,
std::vector<std::string> const& dirs)
{ {
// Write code to install the directories. // Write code to install the directories.
const char* no_rename = 0; const char* no_rename = 0;
this->AddInstallRule(os, this->AddInstallRule(os,
this->GetDestination(config), this->GetDestination(config),
cmInstallType_DIRECTORY, cmInstallType_DIRECTORY,
this->Directories, dirs,
this->Optional, this->Optional,
this->FilePermissions.c_str(), this->FilePermissions.c_str(),
this->DirPermissions.c_str(), this->DirPermissions.c_str(),

View File

@ -42,7 +42,8 @@ protected:
Indent const& indent); Indent const& indent);
void AddDirectoryInstallRule(std::ostream& os, void AddDirectoryInstallRule(std::ostream& os,
const std::string& config, const std::string& config,
Indent const& indent); Indent const& indent,
std::vector<std::string> const& dirs);
cmLocalGenerator* LocalGenerator; cmLocalGenerator* LocalGenerator;
std::vector<std::string> Directories; std::vector<std::string> Directories;
std::string FilePermissions; std::string FilePermissions;

View File

@ -551,5 +551,5 @@ install(
ARCHIVE DESTINATION lib ARCHIVE DESTINATION lib
INCLUDES DESTINATION include/abs INCLUDES DESTINATION include/abs
) )
install(DIRECTORY include/abs DESTINATION $<1:include>$<0:/wrong>) install(DIRECTORY $<1:include/abs>$<0:/wrong> DESTINATION $<1:include>$<0:/wrong>)
install(EXPORT expAbs NAMESPACE expAbs_ DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/expAbs) install(EXPORT expAbs NAMESPACE expAbs_ DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/expAbs)

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 @@
install(DIRECTORY $<NOTAGENEX> DESTINATION .)

View File

@ -6,6 +6,7 @@ run_cmake(DIRECTORY-message-lazy)
run_cmake(SkipInstallRulesWarning) run_cmake(SkipInstallRulesWarning)
run_cmake(SkipInstallRulesNoWarning1) run_cmake(SkipInstallRulesNoWarning1)
run_cmake(SkipInstallRulesNoWarning2) run_cmake(SkipInstallRulesNoWarning2)
run_cmake(DIRECTORY-DIRECTORY-bad)
run_cmake(DIRECTORY-DESTINATION-bad) run_cmake(DIRECTORY-DESTINATION-bad)
run_cmake(FILES-DESTINATION-bad) run_cmake(FILES-DESTINATION-bad)
run_cmake(TARGETS-DESTINATION-bad) run_cmake(TARGETS-DESTINATION-bad)

View File

@ -252,7 +252,7 @@ else()
file(REMOVE_RECURSE "${CMAKE_INSTALL_PREFIX}/MyTest/share/CVS") file(REMOVE_RECURSE "${CMAKE_INSTALL_PREFIX}/MyTest/share/CVS")
file(REMOVE_RECURSE "${CMAKE_INSTALL_PREFIX}/MyTest/share/TestSubDir/CVS") file(REMOVE_RECURSE "${CMAKE_INSTALL_PREFIX}/MyTest/share/TestSubDir/CVS")
install( install(
DIRECTORY TestSubDir scripts/ DESTINATION $<1:MyTest/share>$<0:/wrong> DIRECTORY TestSubDir $<1:scripts/>$<0:/wrong> DESTINATION $<1:MyTest/share>$<0:/wrong>
FILE_PERMISSIONS OWNER_READ OWNER_WRITE FILE_PERMISSIONS OWNER_READ OWNER_WRITE
DIRECTORY_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE DIRECTORY_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
GROUP_READ GROUP_EXECUTE GROUP_READ GROUP_EXECUTE
@ -263,7 +263,7 @@ else()
# Alternate directory installation for coverage. # Alternate directory installation for coverage.
install( install(
DIRECTORY scripts/ DESTINATION $<1:MyTest/share/alt>$<0:/wrong> DIRECTORY $<1:scripts/>$<0:/wrong> DESTINATION $<1:MyTest/share/alt>$<0:/wrong>
COMPONENT Development COMPONENT Development
USE_SOURCE_PERMISSIONS USE_SOURCE_PERMISSIONS
PATTERN "CVS" EXCLUDE PATTERN "CVS" EXCLUDE

View File

@ -252,7 +252,7 @@ else()
file(REMOVE_RECURSE "${CMAKE_INSTALL_PREFIX}/MyTest/share/CVS") file(REMOVE_RECURSE "${CMAKE_INSTALL_PREFIX}/MyTest/share/CVS")
file(REMOVE_RECURSE "${CMAKE_INSTALL_PREFIX}/MyTest/share/TestSubDir/CVS") file(REMOVE_RECURSE "${CMAKE_INSTALL_PREFIX}/MyTest/share/TestSubDir/CVS")
install( install(
DIRECTORY TestSubDir scripts/ DESTINATION $<1:MyTest/share>$<0:/wrong> DIRECTORY TestSubDir $<1:scripts/>$<0:/wrong> DESTINATION $<1:MyTest/share>$<0:/wrong>
FILE_PERMISSIONS OWNER_READ OWNER_WRITE FILE_PERMISSIONS OWNER_READ OWNER_WRITE
DIRECTORY_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE DIRECTORY_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
GROUP_READ GROUP_EXECUTE GROUP_READ GROUP_EXECUTE
@ -263,7 +263,7 @@ else()
# Alternate directory installation for coverage. # Alternate directory installation for coverage.
install( install(
DIRECTORY scripts/ DESTINATION $<1:MyTest/share/alt>$<0:/wrong> DIRECTORY $<1:scripts/>$<0:/wrong> DESTINATION $<1:MyTest/share/alt>$<0:/wrong>
COMPONENT Development COMPONENT Development
USE_SOURCE_PERMISSIONS USE_SOURCE_PERMISSIONS
PATTERN "CVS" EXCLUDE PATTERN "CVS" EXCLUDE