ENH: Add install(DIRECTORY) option 'OPTIONAL'
This adds the OPTIONAL option to the install(DIRECTORY) command. It tells the installation rule that it is not an error if the source directory does not exist. See issue #8394.
This commit is contained in:
parent
a79f8cd4c1
commit
1595b8e69e
|
@ -855,6 +855,7 @@ cmInstallCommand::HandleDirectoryMode(std::vector<std::string> const& args)
|
||||||
DoingConfigurations, DoingComponent };
|
DoingConfigurations, DoingComponent };
|
||||||
Doing doing = DoingDirs;
|
Doing doing = DoingDirs;
|
||||||
bool in_match_mode = false;
|
bool in_match_mode = false;
|
||||||
|
bool optional = false;
|
||||||
std::vector<std::string> dirs;
|
std::vector<std::string> dirs;
|
||||||
const char* destination = 0;
|
const char* destination = 0;
|
||||||
std::string permissions_file;
|
std::string permissions_file;
|
||||||
|
@ -878,6 +879,21 @@ cmInstallCommand::HandleDirectoryMode(std::vector<std::string> const& args)
|
||||||
// Switch to setting the destination property.
|
// Switch to setting the destination property.
|
||||||
doing = DoingDestination;
|
doing = DoingDestination;
|
||||||
}
|
}
|
||||||
|
else if(args[i] == "OPTIONAL")
|
||||||
|
{
|
||||||
|
if(in_match_mode)
|
||||||
|
{
|
||||||
|
cmOStringStream e;
|
||||||
|
e << args[0] << " does not allow \""
|
||||||
|
<< args[i] << "\" after PATTERN or REGEX.";
|
||||||
|
this->SetError(e.str().c_str());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mark the rule as optional.
|
||||||
|
optional = true;
|
||||||
|
doing = DoingNone;
|
||||||
|
}
|
||||||
else if(args[i] == "PATTERN")
|
else if(args[i] == "PATTERN")
|
||||||
{
|
{
|
||||||
// Switch to a new pattern match rule.
|
// Switch to a new pattern match rule.
|
||||||
|
@ -1144,7 +1160,8 @@ cmInstallCommand::HandleDirectoryMode(std::vector<std::string> const& args)
|
||||||
permissions_dir.c_str(),
|
permissions_dir.c_str(),
|
||||||
configurations,
|
configurations,
|
||||||
component.c_str(),
|
component.c_str(),
|
||||||
literal_args.c_str()));
|
literal_args.c_str(),
|
||||||
|
optional));
|
||||||
|
|
||||||
// Tell the global generator about any installation component names
|
// Tell the global generator about any installation component names
|
||||||
// specified.
|
// specified.
|
||||||
|
|
|
@ -215,7 +215,7 @@ public:
|
||||||
" install(DIRECTORY dirs... DESTINATION <dir>\n"
|
" install(DIRECTORY dirs... DESTINATION <dir>\n"
|
||||||
" [FILE_PERMISSIONS permissions...]\n"
|
" [FILE_PERMISSIONS permissions...]\n"
|
||||||
" [DIRECTORY_PERMISSIONS permissions...]\n"
|
" [DIRECTORY_PERMISSIONS permissions...]\n"
|
||||||
" [USE_SOURCE_PERMISSIONS]\n"
|
" [USE_SOURCE_PERMISSIONS] [OPTIONAL]\n"
|
||||||
" [CONFIGURATIONS [Debug|Release|...]]\n"
|
" [CONFIGURATIONS [Debug|Release|...]]\n"
|
||||||
" [COMPONENT <component>] [FILES_MATCHING]\n"
|
" [COMPONENT <component>] [FILES_MATCHING]\n"
|
||||||
" [[PATTERN <pattern> | REGEX <regex>]\n"
|
" [[PATTERN <pattern> | REGEX <regex>]\n"
|
||||||
|
|
|
@ -26,10 +26,11 @@ cmInstallDirectoryGenerator
|
||||||
const char* dir_permissions,
|
const char* dir_permissions,
|
||||||
std::vector<std::string> const& configurations,
|
std::vector<std::string> const& configurations,
|
||||||
const char* component,
|
const char* component,
|
||||||
const char* literal_args):
|
const char* literal_args,
|
||||||
|
bool optional):
|
||||||
cmInstallGenerator(dest, configurations, component), Directories(dirs),
|
cmInstallGenerator(dest, configurations, component), Directories(dirs),
|
||||||
FilePermissions(file_permissions), DirPermissions(dir_permissions),
|
FilePermissions(file_permissions), DirPermissions(dir_permissions),
|
||||||
LiteralArguments(literal_args)
|
LiteralArguments(literal_args), Optional(optional)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,12 +46,11 @@ cmInstallDirectoryGenerator::GenerateScriptActions(std::ostream& os,
|
||||||
Indent const& indent)
|
Indent const& indent)
|
||||||
{
|
{
|
||||||
// Write code to install the directories.
|
// Write code to install the directories.
|
||||||
bool not_optional = false;
|
|
||||||
const char* no_properties = 0;
|
const char* no_properties = 0;
|
||||||
const char* no_rename = 0;
|
const char* no_rename = 0;
|
||||||
this->AddInstallRule(os, cmTarget::INSTALL_DIRECTORY,
|
this->AddInstallRule(os, cmTarget::INSTALL_DIRECTORY,
|
||||||
this->Directories,
|
this->Directories,
|
||||||
not_optional, no_properties,
|
this->Optional, no_properties,
|
||||||
this->FilePermissions.c_str(),
|
this->FilePermissions.c_str(),
|
||||||
this->DirPermissions.c_str(),
|
this->DirPermissions.c_str(),
|
||||||
no_rename, this->LiteralArguments.c_str(),
|
no_rename, this->LiteralArguments.c_str(),
|
||||||
|
|
|
@ -31,7 +31,8 @@ public:
|
||||||
const char* dir_permissions,
|
const char* dir_permissions,
|
||||||
std::vector<std::string> const& configurations,
|
std::vector<std::string> const& configurations,
|
||||||
const char* component,
|
const char* component,
|
||||||
const char* literal_args);
|
const char* literal_args,
|
||||||
|
bool optional = false);
|
||||||
virtual ~cmInstallDirectoryGenerator();
|
virtual ~cmInstallDirectoryGenerator();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -40,6 +41,7 @@ protected:
|
||||||
std::string FilePermissions;
|
std::string FilePermissions;
|
||||||
std::string DirPermissions;
|
std::string DirPermissions;
|
||||||
std::string LiteralArguments;
|
std::string LiteralArguments;
|
||||||
|
bool Optional;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -270,6 +270,9 @@ ELSE(STAGE2)
|
||||||
# Test empty directory installation.
|
# Test empty directory installation.
|
||||||
INSTALL(DIRECTORY DESTINATION MyTest/share/empty)
|
INSTALL(DIRECTORY DESTINATION MyTest/share/empty)
|
||||||
|
|
||||||
|
# Test optional directory installation.
|
||||||
|
INSTALL(DIRECTORY does-not-exist DESTINATION MyTest/share OPTIONAL)
|
||||||
|
|
||||||
# Test user-specified install scripts, with and without COMPONENT.
|
# Test user-specified install scripts, with and without COMPONENT.
|
||||||
INSTALL(
|
INSTALL(
|
||||||
SCRIPT InstallScript1.cmake
|
SCRIPT InstallScript1.cmake
|
||||||
|
|
|
@ -270,6 +270,9 @@ ELSE(STAGE2)
|
||||||
# Test empty directory installation.
|
# Test empty directory installation.
|
||||||
INSTALL(DIRECTORY DESTINATION MyTest/share/empty)
|
INSTALL(DIRECTORY DESTINATION MyTest/share/empty)
|
||||||
|
|
||||||
|
# Test optional directory installation.
|
||||||
|
INSTALL(DIRECTORY does-not-exist DESTINATION MyTest/share OPTIONAL)
|
||||||
|
|
||||||
# Test user-specified install scripts, with and without COMPONENT.
|
# Test user-specified install scripts, with and without COMPONENT.
|
||||||
INSTALL(
|
INSTALL(
|
||||||
SCRIPT InstallScript1.cmake
|
SCRIPT InstallScript1.cmake
|
||||||
|
|
Loading…
Reference in New Issue