From 1595b8e69eac0d2dbab6ac29663a85d8d486a5cc Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 24 Feb 2009 11:41:40 -0500 Subject: 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. --- Source/cmInstallCommand.cxx | 19 ++++++++++++++++++- Source/cmInstallCommand.h | 2 +- Source/cmInstallDirectoryGenerator.cxx | 8 ++++---- Source/cmInstallDirectoryGenerator.h | 4 +++- Tests/SimpleInstall/CMakeLists.txt | 3 +++ Tests/SimpleInstallS2/CMakeLists.txt | 3 +++ 6 files changed, 32 insertions(+), 7 deletions(-) diff --git a/Source/cmInstallCommand.cxx b/Source/cmInstallCommand.cxx index 001bd95..37c0f9b 100644 --- a/Source/cmInstallCommand.cxx +++ b/Source/cmInstallCommand.cxx @@ -855,6 +855,7 @@ cmInstallCommand::HandleDirectoryMode(std::vector const& args) DoingConfigurations, DoingComponent }; Doing doing = DoingDirs; bool in_match_mode = false; + bool optional = false; std::vector dirs; const char* destination = 0; std::string permissions_file; @@ -878,6 +879,21 @@ cmInstallCommand::HandleDirectoryMode(std::vector const& args) // Switch to setting the destination property. 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") { // Switch to a new pattern match rule. @@ -1144,7 +1160,8 @@ cmInstallCommand::HandleDirectoryMode(std::vector const& args) permissions_dir.c_str(), configurations, component.c_str(), - literal_args.c_str())); + literal_args.c_str(), + optional)); // Tell the global generator about any installation component names // specified. diff --git a/Source/cmInstallCommand.h b/Source/cmInstallCommand.h index 0b7ae7a..b8b01bc 100644 --- a/Source/cmInstallCommand.h +++ b/Source/cmInstallCommand.h @@ -215,7 +215,7 @@ public: " install(DIRECTORY dirs... DESTINATION \n" " [FILE_PERMISSIONS permissions...]\n" " [DIRECTORY_PERMISSIONS permissions...]\n" - " [USE_SOURCE_PERMISSIONS]\n" + " [USE_SOURCE_PERMISSIONS] [OPTIONAL]\n" " [CONFIGURATIONS [Debug|Release|...]]\n" " [COMPONENT ] [FILES_MATCHING]\n" " [[PATTERN | REGEX ]\n" diff --git a/Source/cmInstallDirectoryGenerator.cxx b/Source/cmInstallDirectoryGenerator.cxx index 110e6b6..6f46d29 100644 --- a/Source/cmInstallDirectoryGenerator.cxx +++ b/Source/cmInstallDirectoryGenerator.cxx @@ -26,10 +26,11 @@ cmInstallDirectoryGenerator const char* dir_permissions, std::vector const& configurations, const char* component, - const char* literal_args): + const char* literal_args, + bool optional): cmInstallGenerator(dest, configurations, component), Directories(dirs), 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) { // Write code to install the directories. - bool not_optional = false; const char* no_properties = 0; const char* no_rename = 0; this->AddInstallRule(os, cmTarget::INSTALL_DIRECTORY, this->Directories, - not_optional, no_properties, + this->Optional, no_properties, this->FilePermissions.c_str(), this->DirPermissions.c_str(), no_rename, this->LiteralArguments.c_str(), diff --git a/Source/cmInstallDirectoryGenerator.h b/Source/cmInstallDirectoryGenerator.h index 9810d56..a1166e1 100644 --- a/Source/cmInstallDirectoryGenerator.h +++ b/Source/cmInstallDirectoryGenerator.h @@ -31,7 +31,8 @@ public: const char* dir_permissions, std::vector const& configurations, const char* component, - const char* literal_args); + const char* literal_args, + bool optional = false); virtual ~cmInstallDirectoryGenerator(); protected: @@ -40,6 +41,7 @@ protected: std::string FilePermissions; std::string DirPermissions; std::string LiteralArguments; + bool Optional; }; #endif diff --git a/Tests/SimpleInstall/CMakeLists.txt b/Tests/SimpleInstall/CMakeLists.txt index c204e64..1a87c56 100644 --- a/Tests/SimpleInstall/CMakeLists.txt +++ b/Tests/SimpleInstall/CMakeLists.txt @@ -270,6 +270,9 @@ ELSE(STAGE2) # Test empty directory installation. 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. INSTALL( SCRIPT InstallScript1.cmake diff --git a/Tests/SimpleInstallS2/CMakeLists.txt b/Tests/SimpleInstallS2/CMakeLists.txt index c204e64..1a87c56 100644 --- a/Tests/SimpleInstallS2/CMakeLists.txt +++ b/Tests/SimpleInstallS2/CMakeLists.txt @@ -270,6 +270,9 @@ ELSE(STAGE2) # Test empty directory installation. 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. INSTALL( SCRIPT InstallScript1.cmake -- cgit v0.12