From 18ce97c4a20b7da4e11006ad80f17cb55e128db1 Mon Sep 17 00:00:00 2001 From: Nick Lewis Date: Mon, 1 Feb 2016 10:01:39 +0000 Subject: [PATCH 1/3] install: Add EXCLUDE_FROM_ALL option (#14921) Let us take an example of a project that has some tests in a component that need to be installed into a dedicated test package. The user expectation is that the result could be achieved by typing the following: make make tests make install DESTDIR=/testpkgs make install-tests However this results in test components in the default installation as well as the testpkg. Add an EXCLUDE_FROM_ALL option to the install() command to tell it that the installation rule should not be included unless its component is explicitly specified for installation. --- Help/command/install.rst | 23 ++++++++++++------- Source/cmInstallCommand.cxx | 31 ++++++++++++++++++++++---- Source/cmInstallCommandArguments.cxx | 30 ++++++++++++++++++------- Source/cmInstallCommandArguments.h | 2 ++ Source/cmInstallDirectoryGenerator.cxx | 4 +++- Source/cmInstallDirectoryGenerator.h | 1 + Source/cmInstallExportGenerator.cxx | 4 +++- Source/cmInstallExportGenerator.h | 1 + Source/cmInstallFilesCommand.cxx | 4 +++- Source/cmInstallFilesGenerator.cxx | 4 +++- Source/cmInstallFilesGenerator.h | 1 + Source/cmInstallGenerator.cxx | 18 ++++++++++----- Source/cmInstallGenerator.h | 7 ++++-- Source/cmInstallProgramsCommand.cxx | 4 +++- Source/cmInstallScriptGenerator.cxx | 7 +++--- Source/cmInstallScriptGenerator.h | 2 +- Source/cmInstallTargetGenerator.cxx | 4 +++- Source/cmInstallTargetGenerator.h | 1 + Source/cmLocalGenerator.cxx | 6 ++--- 19 files changed, 113 insertions(+), 41 deletions(-) diff --git a/Help/command/install.rst b/Help/command/install.rst index 5d2add7ed..189b51c91 100644 --- a/Help/command/install.rst +++ b/Help/command/install.rst @@ -45,11 +45,15 @@ signatures that specify them. The common options are: is associated, such as "runtime" or "development". During component-specific installation only install rules associated with the given component name will be executed. During a full installation - all components are installed. If ``COMPONENT`` is not provided a - default component "Unspecified" is created. The default component - name may be controlled with the + all components are installed unless marked with ``EXCLUDE_FROM_ALL``. + If ``COMPONENT`` is not provided a default component "Unspecified" is + created. The default component name may be controlled with the :variable:`CMAKE_INSTALL_DEFAULT_COMPONENT_NAME` variable. +``EXCLUDE_FROM_ALL`` + Specify that the file is excluded from a full installation and only + installed as part of a component-specific installation + ``RENAME`` Specify a name for an installed file that may be different from the original file. Renaming is allowed only when a single file is @@ -76,7 +80,8 @@ Installing Targets [PERMISSIONS permissions...] [CONFIGURATIONS [Debug|Release|...]] [COMPONENT ] - [OPTIONAL] [NAMELINK_ONLY|NAMELINK_SKIP] + [OPTIONAL] [EXCLUDE_FROM_ALL] + [NAMELINK_ONLY|NAMELINK_SKIP] ] [...]) The ``TARGETS`` form specifies rules for installing targets from a @@ -172,7 +177,7 @@ Installing Files [PERMISSIONS permissions...] [CONFIGURATIONS [Debug|Release|...]] [COMPONENT ] - [RENAME ] [OPTIONAL]) + [RENAME ] [OPTIONAL] [EXCLUDE_FROM_ALL]) The ``FILES`` form specifies rules for installing files for a project. File names given as relative paths are interpreted with respect to the @@ -206,7 +211,8 @@ Installing Directories [DIRECTORY_PERMISSIONS permissions...] [USE_SOURCE_PERMISSIONS] [OPTIONAL] [MESSAGE_NEVER] [CONFIGURATIONS [Debug|Release|...]] - [COMPONENT ] [FILES_MATCHING] + [COMPONENT ] [EXCLUDE_FROM_ALL] + [FILES_MATCHING] [[PATTERN | REGEX ] [EXCLUDE] [PERMISSIONS permissions...]] [...]) @@ -282,7 +288,7 @@ Custom Installation Logic :: install([[SCRIPT ] [CODE ]] - [COMPONENT ] [...]) + [COMPONENT ] [EXCLUDE_FROM_ALL] [...]) The ``SCRIPT`` form will invoke the given CMake script files during installation. If the script file name is a relative path it will be @@ -307,7 +313,8 @@ Installing Exports [PERMISSIONS permissions...] [CONFIGURATIONS [Debug|Release|...]] [EXPORT_LINK_INTERFACE_LIBRARIES] - [COMPONENT ]) + [COMPONENT ] + [EXCLUDE_FROM_ALL]) The ``EXPORT`` form generates and installs a CMake file containing code to import targets from the installation tree into another project. diff --git a/Source/cmInstallCommand.cxx b/Source/cmInstallCommand.cxx index 15a83ee01..aa92d749e 100644 --- a/Source/cmInstallCommand.cxx +++ b/Source/cmInstallCommand.cxx @@ -33,6 +33,7 @@ static cmInstallTargetGenerator* CreateInstallTargetGenerator(cmTarget& target, impLib, args.GetPermissions().c_str(), args.GetConfigurations(), args.GetComponent().c_str(), message, + args.GetExcludeFromAll(), args.GetOptional() || forceOpt); } @@ -48,7 +49,8 @@ static cmInstallFilesGenerator* CreateInstallFilesGenerator( programs, args.GetPermissions().c_str(), args.GetConfigurations(), args.GetComponent().c_str(), message, - args.GetRename().c_str(), args.GetOptional()); + args.GetExcludeFromAll(), args.GetRename().c_str(), + args.GetOptional()); } @@ -117,6 +119,7 @@ bool cmInstallCommand::HandleScriptMode(std::vector const& args) int componentCount = 0; bool doing_script = false; bool doing_code = false; + bool exclude_from_all = false; // Scan the args once for COMPONENT. Only allow one. // @@ -128,6 +131,10 @@ bool cmInstallCommand::HandleScriptMode(std::vector const& args) ++i; component = args[i]; } + if(args[i] == "EXCLUDE_FROM_ALL") + { + exclude_from_all = true; + } } if(componentCount>1) @@ -175,7 +182,7 @@ bool cmInstallCommand::HandleScriptMode(std::vector const& args) } this->Makefile->AddInstallGenerator( new cmInstallScriptGenerator(script.c_str(), false, - component.c_str())); + component.c_str(), exclude_from_all)); } else if(doing_code) { @@ -183,7 +190,7 @@ bool cmInstallCommand::HandleScriptMode(std::vector const& args) std::string code = args[i]; this->Makefile->AddInstallGenerator( new cmInstallScriptGenerator(code.c_str(), true, - component.c_str())); + component.c_str(), exclude_from_all)); } } @@ -949,6 +956,7 @@ cmInstallCommand::HandleDirectoryMode(std::vector const& args) Doing doing = DoingDirs; bool in_match_mode = false; bool optional = false; + bool exclude_from_all = false; bool message_never = false; std::vector dirs; const char* destination = 0; @@ -1130,6 +1138,19 @@ cmInstallCommand::HandleDirectoryMode(std::vector const& args) // Switch to setting the component property. doing = DoingComponent; } + else if(args[i] == "EXCLUDE_FROM_ALL") + { + if(in_match_mode) + { + std::ostringstream e; + e << args[0] << " does not allow \"" + << args[i] << "\" after PATTERN or REGEX."; + this->SetError(e.str().c_str()); + return false; + } + exclude_from_all = true; + doing = DoingNone; + } else if(doing == DoingDirs) { // Convert this directory to a full path. @@ -1273,6 +1294,7 @@ cmInstallCommand::HandleDirectoryMode(std::vector const& args) configurations, component.c_str(), message, + exclude_from_all, literal_args.c_str(), optional)); @@ -1401,7 +1423,8 @@ bool cmInstallCommand::HandleExportMode(std::vector const& args) exportSet, ica.GetDestination().c_str(), ica.GetPermissions().c_str(), ica.GetConfigurations(), - ica.GetComponent().c_str(), message, fname.c_str(), + ica.GetComponent().c_str(), message, + ica.GetExcludeFromAll(), fname.c_str(), name_space.GetCString(), exportOld.IsEnabled()); this->Makefile->AddInstallGenerator(exportGenerator); diff --git a/Source/cmInstallCommandArguments.cxx b/Source/cmInstallCommandArguments.cxx index 236ca1feb..6ded365ac 100644 --- a/Source/cmInstallCommandArguments.cxx +++ b/Source/cmInstallCommandArguments.cxx @@ -27,14 +27,15 @@ cmInstallCommandArguments::cmInstallCommandArguments( const std::string& defaultComponent) :Parser() ,ArgumentGroup() -,Destination (&Parser, "DESTINATION" , &ArgumentGroup) -,Component (&Parser, "COMPONENT" , &ArgumentGroup) -,Rename (&Parser, "RENAME" , &ArgumentGroup) -,Permissions (&Parser, "PERMISSIONS" , &ArgumentGroup) -,Configurations(&Parser, "CONFIGURATIONS", &ArgumentGroup) -,Optional (&Parser, "OPTIONAL" , &ArgumentGroup) -,NamelinkOnly (&Parser, "NAMELINK_ONLY" , &ArgumentGroup) -,NamelinkSkip (&Parser, "NAMELINK_SKIP" , &ArgumentGroup) +,Destination (&Parser, "DESTINATION" , &ArgumentGroup) +,Component (&Parser, "COMPONENT" , &ArgumentGroup) +,ExcludeFromAll(&Parser, "EXCLUDE_FROM_ALL", &ArgumentGroup) +,Rename (&Parser, "RENAME" , &ArgumentGroup) +,Permissions (&Parser, "PERMISSIONS" , &ArgumentGroup) +,Configurations(&Parser, "CONFIGURATIONS" , &ArgumentGroup) +,Optional (&Parser, "OPTIONAL" , &ArgumentGroup) +,NamelinkOnly (&Parser, "NAMELINK_ONLY" , &ArgumentGroup) +,NamelinkSkip (&Parser, "NAMELINK_SKIP" , &ArgumentGroup) ,GenericArguments(0) ,DefaultComponentName(defaultComponent) { @@ -110,6 +111,19 @@ bool cmInstallCommandArguments::GetOptional() const return false; } +bool cmInstallCommandArguments::GetExcludeFromAll() const +{ + if (this->ExcludeFromAll.IsEnabled()) + { + return true; + } + if (this->GenericArguments!=0) + { + return this->GenericArguments->GetExcludeFromAll(); + } + return false; +} + bool cmInstallCommandArguments::GetNamelinkOnly() const { if (this->NamelinkOnly.IsEnabled()) diff --git a/Source/cmInstallCommandArguments.h b/Source/cmInstallCommandArguments.h index 90347e668..694f1ed52 100644 --- a/Source/cmInstallCommandArguments.h +++ b/Source/cmInstallCommandArguments.h @@ -30,6 +30,7 @@ class cmInstallCommandArguments const std::string& GetDestination() const; const std::string& GetComponent() const; + bool GetExcludeFromAll() const; const std::string& GetRename() const; const std::string& GetPermissions() const; const std::vector& GetConfigurations() const; @@ -48,6 +49,7 @@ class cmInstallCommandArguments cmInstallCommandArguments(); // disabled cmCAString Destination; cmCAString Component; + cmCAEnabler ExcludeFromAll; cmCAString Rename; cmCAStringVector Permissions; cmCAStringVector Configurations; diff --git a/Source/cmInstallDirectoryGenerator.cxx b/Source/cmInstallDirectoryGenerator.cxx index f2e860915..6ad6c7564 100644 --- a/Source/cmInstallDirectoryGenerator.cxx +++ b/Source/cmInstallDirectoryGenerator.cxx @@ -23,9 +23,11 @@ cmInstallDirectoryGenerator std::vector const& configurations, const char* component, MessageLevel message, + bool exclude_from_all, const char* literal_args, bool optional): - cmInstallGenerator(dest, configurations, component, message), + cmInstallGenerator(dest, configurations, component, message, + exclude_from_all), LocalGenerator(0), Directories(dirs), FilePermissions(file_permissions), DirPermissions(dir_permissions), diff --git a/Source/cmInstallDirectoryGenerator.h b/Source/cmInstallDirectoryGenerator.h index 9b732d3f1..b137f4491 100644 --- a/Source/cmInstallDirectoryGenerator.h +++ b/Source/cmInstallDirectoryGenerator.h @@ -27,6 +27,7 @@ public: std::vector const& configurations, const char* component, MessageLevel message, + bool exclude_from_all, const char* literal_args, bool optional = false); virtual ~cmInstallDirectoryGenerator(); diff --git a/Source/cmInstallExportGenerator.cxx b/Source/cmInstallExportGenerator.cxx index 9570ba3d8..80fc05460 100644 --- a/Source/cmInstallExportGenerator.cxx +++ b/Source/cmInstallExportGenerator.cxx @@ -33,9 +33,11 @@ cmInstallExportGenerator::cmInstallExportGenerator( std::vector const& configurations, const char* component, MessageLevel message, + bool exclude_from_all, const char* filename, const char* name_space, bool exportOld) - :cmInstallGenerator(destination, configurations, component, message) + :cmInstallGenerator(destination, configurations, component, message, + exclude_from_all) ,ExportSet(exportSet) ,FilePermissions(file_permissions) ,FileName(filename) diff --git a/Source/cmInstallExportGenerator.h b/Source/cmInstallExportGenerator.h index 885ed0596..1b1c046c1 100644 --- a/Source/cmInstallExportGenerator.h +++ b/Source/cmInstallExportGenerator.h @@ -31,6 +31,7 @@ public: const std::vector& configurations, const char* component, MessageLevel message, + bool exclude_from_all, const char* filename, const char* name_space, bool exportOld); ~cmInstallExportGenerator(); diff --git a/Source/cmInstallFilesCommand.cxx b/Source/cmInstallFilesCommand.cxx index 68557bd8a..d3d258e71 100644 --- a/Source/cmInstallFilesCommand.cxx +++ b/Source/cmInstallFilesCommand.cxx @@ -122,6 +122,7 @@ void cmInstallFilesCommand::CreateInstallGenerator() const // Use a file install generator. const char* no_permissions = ""; const char* no_rename = ""; + bool no_exclude_from_all = false; std::string no_component = this->Makefile->GetSafeDefinition( "CMAKE_INSTALL_DEFAULT_COMPONENT_NAME"); std::vector no_configurations; @@ -131,7 +132,8 @@ void cmInstallFilesCommand::CreateInstallGenerator() const new cmInstallFilesGenerator(this->Files, destination.c_str(), false, no_permissions, no_configurations, - no_component.c_str(), message, no_rename)); + no_component.c_str(), message, + no_exclude_from_all, no_rename)); } diff --git a/Source/cmInstallFilesGenerator.cxx b/Source/cmInstallFilesGenerator.cxx index 383031b7f..3dd5528af 100644 --- a/Source/cmInstallFilesGenerator.cxx +++ b/Source/cmInstallFilesGenerator.cxx @@ -24,9 +24,11 @@ cmInstallFilesGenerator std::vector const& configurations, const char* component, MessageLevel message, + bool exclude_from_all, const char* rename, bool optional): - cmInstallGenerator(dest, configurations, component, message), + cmInstallGenerator(dest, configurations, component, message, + exclude_from_all), LocalGenerator(0), Files(files), FilePermissions(file_permissions), diff --git a/Source/cmInstallFilesGenerator.h b/Source/cmInstallFilesGenerator.h index bfe403924..efaf62b84 100644 --- a/Source/cmInstallFilesGenerator.h +++ b/Source/cmInstallFilesGenerator.h @@ -26,6 +26,7 @@ public: std::vector const& configurations, const char* component, MessageLevel message, + bool exclude_from_all, const char* rename, bool optional = false); virtual ~cmInstallFilesGenerator(); diff --git a/Source/cmInstallGenerator.cxx b/Source/cmInstallGenerator.cxx index 2e1c5f05f..660e44f14 100644 --- a/Source/cmInstallGenerator.cxx +++ b/Source/cmInstallGenerator.cxx @@ -19,11 +19,13 @@ cmInstallGenerator ::cmInstallGenerator(const char* destination, std::vector const& configurations, const char* component, - MessageLevel message): + MessageLevel message, + bool exclude_from_all): cmScriptGenerator("CMAKE_INSTALL_CONFIG_NAME", configurations), Destination(destination? destination:""), Component(component? component:""), - Message(message) + Message(message), + ExcludeFromAll(exclude_from_all) { } @@ -146,12 +148,16 @@ void cmInstallGenerator //---------------------------------------------------------------------------- std::string -cmInstallGenerator::CreateComponentTest(const char* component) +cmInstallGenerator::CreateComponentTest(const char* component, + bool exclude_from_all) { - std::string result = "NOT CMAKE_INSTALL_COMPONENT OR " - "\"${CMAKE_INSTALL_COMPONENT}\" STREQUAL \""; + std::string result = "\"${CMAKE_INSTALL_COMPONENT}\" STREQUAL \""; result += component; result += "\""; + if(!exclude_from_all) + { + result += " OR NOT CMAKE_INSTALL_COMPONENT"; + } return result; } @@ -163,7 +169,7 @@ void cmInstallGenerator::GenerateScript(std::ostream& os) // Begin this block of installation. std::string component_test = - this->CreateComponentTest(this->Component.c_str()); + this->CreateComponentTest(this->Component.c_str(),this->ExcludeFromAll); os << indent << "if(" << component_test << ")\n"; // Generate the script possibly with per-configuration code. diff --git a/Source/cmInstallGenerator.h b/Source/cmInstallGenerator.h index b8e5b53cb..db8959088 100644 --- a/Source/cmInstallGenerator.h +++ b/Source/cmInstallGenerator.h @@ -36,7 +36,8 @@ public: cmInstallGenerator(const char* destination, std::vector const& configurations, const char* component, - MessageLevel message); + MessageLevel message, + bool exclude_from_all); virtual ~cmInstallGenerator(); void AddInstallRule( @@ -67,12 +68,14 @@ public: protected: virtual void GenerateScript(std::ostream& os); - std::string CreateComponentTest(const char* component); + std::string CreateComponentTest(const char* component, + bool exclude_from_all); // Information shared by most generator types. std::string Destination; std::string Component; MessageLevel Message; + bool ExcludeFromAll; }; #endif diff --git a/Source/cmInstallProgramsCommand.cxx b/Source/cmInstallProgramsCommand.cxx index e6fbe8864..b6d0c453c 100644 --- a/Source/cmInstallProgramsCommand.cxx +++ b/Source/cmInstallProgramsCommand.cxx @@ -85,6 +85,7 @@ void cmInstallProgramsCommand::FinalPass() // Use a file install generator. const char* no_permissions = ""; const char* no_rename = ""; + bool no_exclude_from_all = false; std::string no_component = this->Makefile->GetSafeDefinition( "CMAKE_INSTALL_DEFAULT_COMPONENT_NAME"); std::vector no_configurations; @@ -94,7 +95,8 @@ void cmInstallProgramsCommand::FinalPass() new cmInstallFilesGenerator(this->Files, destination.c_str(), true, no_permissions, no_configurations, - no_component.c_str(), message, no_rename)); + no_component.c_str(), message, + no_exclude_from_all, no_rename)); } /** diff --git a/Source/cmInstallScriptGenerator.cxx b/Source/cmInstallScriptGenerator.cxx index 933aa0782..d58d03954 100644 --- a/Source/cmInstallScriptGenerator.cxx +++ b/Source/cmInstallScriptGenerator.cxx @@ -14,8 +14,9 @@ //---------------------------------------------------------------------------- cmInstallScriptGenerator ::cmInstallScriptGenerator(const char* script, bool code, - const char* component) : - cmInstallGenerator(0, std::vector(), component, MessageDefault), + const char* component, bool exclude_from_all) : + cmInstallGenerator(0, std::vector(), component, MessageDefault, + exclude_from_all), Script(script), Code(code) { } @@ -31,7 +32,7 @@ void cmInstallScriptGenerator::GenerateScript(std::ostream& os) { Indent indent; std::string component_test = - this->CreateComponentTest(this->Component.c_str()); + this->CreateComponentTest(this->Component.c_str(), this->ExcludeFromAll); os << indent << "if(" << component_test << ")\n"; if(this->Code) diff --git a/Source/cmInstallScriptGenerator.h b/Source/cmInstallScriptGenerator.h index 54a7b2195..7e7c0c8ed 100644 --- a/Source/cmInstallScriptGenerator.h +++ b/Source/cmInstallScriptGenerator.h @@ -21,7 +21,7 @@ class cmInstallScriptGenerator: public cmInstallGenerator { public: cmInstallScriptGenerator(const char* script, bool code, - const char* component); + const char* component, bool exclude_from_all); virtual ~cmInstallScriptGenerator(); protected: diff --git a/Source/cmInstallTargetGenerator.cxx b/Source/cmInstallTargetGenerator.cxx index 5e88fa2c7..3d44fe2c3 100644 --- a/Source/cmInstallTargetGenerator.cxx +++ b/Source/cmInstallTargetGenerator.cxx @@ -30,8 +30,10 @@ cmInstallTargetGenerator std::vector const& configurations, const char* component, MessageLevel message, + bool exclude_from_all, bool optional): - cmInstallGenerator(dest, configurations, component, message), + cmInstallGenerator(dest, configurations, component, message, + exclude_from_all), TargetName(targetName), Target(0), FilePermissions(file_permissions), diff --git a/Source/cmInstallTargetGenerator.h b/Source/cmInstallTargetGenerator.h index 18b313082..46b453212 100644 --- a/Source/cmInstallTargetGenerator.h +++ b/Source/cmInstallTargetGenerator.h @@ -28,6 +28,7 @@ public: std::vector const& configurations, const char* component, MessageLevel message, + bool exclude_from_all, bool optional ); virtual ~cmInstallTargetGenerator(); diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 1d17032d8..6b7398703 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -2557,7 +2557,7 @@ public: cmInstallTargetGenerator( t, dest, implib, "", std::vector(), "Unspecified", cmInstallGenerator::SelectMessageLevel(lg->GetMakefile()), - false) + false, false) { this->Compute(lg); } @@ -2584,7 +2584,7 @@ cmLocalGenerator // Include the user-specified pre-install script for this target. if(const char* preinstall = (*l)->GetProperty("PRE_INSTALL_SCRIPT")) { - cmInstallScriptGenerator g(preinstall, false, 0); + cmInstallScriptGenerator g(preinstall, false, 0, false); g.Generate(os, config, configurationTypes); } @@ -2645,7 +2645,7 @@ cmLocalGenerator // Include the user-specified post-install script for this target. if(const char* postinstall = (*l)->GetProperty("POST_INSTALL_SCRIPT")) { - cmInstallScriptGenerator g(postinstall, false, 0); + cmInstallScriptGenerator g(postinstall, false, 0, false); g.Generate(os, config, configurationTypes); } } From d321c196a0bfb58ff8a32ed14552d1b78b24cf8a Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 3 Feb 2016 14:10:55 -0500 Subject: [PATCH 2/3] Tests: Add cases for install() command EXCLUDE_FROM_ALL option --- .../FILES-EXCLUDE_FROM_ALL-all-check.cmake | 1 + .../FILES-EXCLUDE_FROM_ALL-exc-check.cmake | 1 + .../FILES-EXCLUDE_FROM_ALL-uns-check.cmake | 1 + .../install/FILES-EXCLUDE_FROM_ALL.cmake | 3 ++ Tests/RunCMake/install/RunCMakeTest.cmake | 45 +++++++++++++++++++ .../TARGETS-EXCLUDE_FROM_ALL-all-check.cmake | 1 + .../TARGETS-EXCLUDE_FROM_ALL-exc-check.cmake | 1 + .../TARGETS-EXCLUDE_FROM_ALL-uns-check.cmake | 1 + .../install/TARGETS-EXCLUDE_FROM_ALL.cmake | 5 +++ Tests/RunCMake/install/main.c | 1 + 10 files changed, 60 insertions(+) create mode 100644 Tests/RunCMake/install/FILES-EXCLUDE_FROM_ALL-all-check.cmake create mode 100644 Tests/RunCMake/install/FILES-EXCLUDE_FROM_ALL-exc-check.cmake create mode 100644 Tests/RunCMake/install/FILES-EXCLUDE_FROM_ALL-uns-check.cmake create mode 100644 Tests/RunCMake/install/FILES-EXCLUDE_FROM_ALL.cmake create mode 100644 Tests/RunCMake/install/TARGETS-EXCLUDE_FROM_ALL-all-check.cmake create mode 100644 Tests/RunCMake/install/TARGETS-EXCLUDE_FROM_ALL-exc-check.cmake create mode 100644 Tests/RunCMake/install/TARGETS-EXCLUDE_FROM_ALL-uns-check.cmake create mode 100644 Tests/RunCMake/install/TARGETS-EXCLUDE_FROM_ALL.cmake create mode 100644 Tests/RunCMake/install/main.c diff --git a/Tests/RunCMake/install/FILES-EXCLUDE_FROM_ALL-all-check.cmake b/Tests/RunCMake/install/FILES-EXCLUDE_FROM_ALL-all-check.cmake new file mode 100644 index 000000000..0368df119 --- /dev/null +++ b/Tests/RunCMake/install/FILES-EXCLUDE_FROM_ALL-all-check.cmake @@ -0,0 +1 @@ +check_installed([[^src-all;src-all/main\.c$]]) diff --git a/Tests/RunCMake/install/FILES-EXCLUDE_FROM_ALL-exc-check.cmake b/Tests/RunCMake/install/FILES-EXCLUDE_FROM_ALL-exc-check.cmake new file mode 100644 index 000000000..41a816ff0 --- /dev/null +++ b/Tests/RunCMake/install/FILES-EXCLUDE_FROM_ALL-exc-check.cmake @@ -0,0 +1 @@ +check_installed([[^src-exc;src-exc/main\.c$]]) diff --git a/Tests/RunCMake/install/FILES-EXCLUDE_FROM_ALL-uns-check.cmake b/Tests/RunCMake/install/FILES-EXCLUDE_FROM_ALL-uns-check.cmake new file mode 100644 index 000000000..68a1378fc --- /dev/null +++ b/Tests/RunCMake/install/FILES-EXCLUDE_FROM_ALL-uns-check.cmake @@ -0,0 +1 @@ +check_installed([[^src-all;src-all/main\.c;src-uns;src-uns/main\.c$]]) diff --git a/Tests/RunCMake/install/FILES-EXCLUDE_FROM_ALL.cmake b/Tests/RunCMake/install/FILES-EXCLUDE_FROM_ALL.cmake new file mode 100644 index 000000000..720299b94 --- /dev/null +++ b/Tests/RunCMake/install/FILES-EXCLUDE_FROM_ALL.cmake @@ -0,0 +1,3 @@ +install(FILES main.c DESTINATION src-all) +install(FILES main.c DESTINATION src-uns EXCLUDE_FROM_ALL) +install(FILES main.c DESTINATION src-exc EXCLUDE_FROM_ALL COMPONENT exc) diff --git a/Tests/RunCMake/install/RunCMakeTest.cmake b/Tests/RunCMake/install/RunCMakeTest.cmake index 2c1b29d9c..4d91f9283 100644 --- a/Tests/RunCMake/install/RunCMakeTest.cmake +++ b/Tests/RunCMake/install/RunCMakeTest.cmake @@ -1,4 +1,46 @@ +cmake_minimum_required(VERSION 3.4) include(RunCMake) + +# Function to build and install a project. The latter step *-check.cmake +# scripts can check installed files using the check_installed function. +function(run_install_test case) + set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${case}-build) + set(RunCMake_TEST_NO_CLEAN 1) + file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}") + file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}") + run_cmake(${case}) + run_cmake_command(${case}-build ${CMAKE_COMMAND} --build . --config Debug) + # Check "all" components. + set(CMAKE_INSTALL_PREFIX ${RunCMake_TEST_BINARY_DIR}/root-all) + run_cmake_command(${case}-all ${CMAKE_COMMAND} -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX} -DBUILD_TYPE=Debug -P cmake_install.cmake) + # Check unspecified component. + set(CMAKE_INSTALL_PREFIX ${RunCMake_TEST_BINARY_DIR}/root-uns) + run_cmake_command(${case}-uns ${CMAKE_COMMAND} -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX} -DBUILD_TYPE=Debug -DCOMPONENT=Unspecified -P cmake_install.cmake) + # Check explicit component. + set(CMAKE_INSTALL_PREFIX ${RunCMake_TEST_BINARY_DIR}/root-exc) + run_cmake_command(${case}-exc ${CMAKE_COMMAND} -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX} -DBUILD_TYPE=Debug -DCOMPONENT=exc -P cmake_install.cmake) +endfunction() + +# Function called in *-check.cmake scripts to check installed files. +function(check_installed expect) + file(GLOB_RECURSE actual + LIST_DIRECTORIES TRUE + RELATIVE ${CMAKE_INSTALL_PREFIX} + ${CMAKE_INSTALL_PREFIX}/* + ) + if(actual) + list(SORT actual) + endif() + if(NOT "${actual}" MATCHES "${expect}") + set(RunCMake_TEST_FAILED "Installed files: + ${actual} +do not match what we expected: + ${expect} +in directory: + ${CMAKE_INSTALL_PREFIX}" PARENT_SCOPE) + endif() +endfunction() + run_cmake(DIRECTORY-MESSAGE_NEVER) run_cmake(DIRECTORY-PATTERN-MESSAGE_NEVER) run_cmake(DIRECTORY-message) @@ -13,3 +55,6 @@ run_cmake(TARGETS-DESTINATION-bad) run_cmake(CMP0062-OLD) run_cmake(CMP0062-NEW) run_cmake(CMP0062-WARN) + +run_install_test(FILES-EXCLUDE_FROM_ALL) +run_install_test(TARGETS-EXCLUDE_FROM_ALL) diff --git a/Tests/RunCMake/install/TARGETS-EXCLUDE_FROM_ALL-all-check.cmake b/Tests/RunCMake/install/TARGETS-EXCLUDE_FROM_ALL-all-check.cmake new file mode 100644 index 000000000..9b538bb6d --- /dev/null +++ b/Tests/RunCMake/install/TARGETS-EXCLUDE_FROM_ALL-all-check.cmake @@ -0,0 +1 @@ +check_installed([[^bin-all;bin-all/myexe(\.exe)?$]]) diff --git a/Tests/RunCMake/install/TARGETS-EXCLUDE_FROM_ALL-exc-check.cmake b/Tests/RunCMake/install/TARGETS-EXCLUDE_FROM_ALL-exc-check.cmake new file mode 100644 index 000000000..aef0d2797 --- /dev/null +++ b/Tests/RunCMake/install/TARGETS-EXCLUDE_FROM_ALL-exc-check.cmake @@ -0,0 +1 @@ +check_installed([[^bin-exc;bin-exc/myexe(\.exe)?$]]) diff --git a/Tests/RunCMake/install/TARGETS-EXCLUDE_FROM_ALL-uns-check.cmake b/Tests/RunCMake/install/TARGETS-EXCLUDE_FROM_ALL-uns-check.cmake new file mode 100644 index 000000000..56fd26403 --- /dev/null +++ b/Tests/RunCMake/install/TARGETS-EXCLUDE_FROM_ALL-uns-check.cmake @@ -0,0 +1 @@ +check_installed([[^bin-all;bin-all/myexe(\.exe)?;bin-uns;bin-uns/myexe(\.exe)?$]]) diff --git a/Tests/RunCMake/install/TARGETS-EXCLUDE_FROM_ALL.cmake b/Tests/RunCMake/install/TARGETS-EXCLUDE_FROM_ALL.cmake new file mode 100644 index 000000000..6fb2036a6 --- /dev/null +++ b/Tests/RunCMake/install/TARGETS-EXCLUDE_FROM_ALL.cmake @@ -0,0 +1,5 @@ +enable_language(C) +add_executable(myexe main.c) +install(TARGETS myexe DESTINATION bin-all) +install(TARGETS myexe DESTINATION bin-uns EXCLUDE_FROM_ALL) +install(TARGETS myexe DESTINATION bin-exc EXCLUDE_FROM_ALL COMPONENT exc) diff --git a/Tests/RunCMake/install/main.c b/Tests/RunCMake/install/main.c new file mode 100644 index 000000000..78f2de106 --- /dev/null +++ b/Tests/RunCMake/install/main.c @@ -0,0 +1 @@ +int main(void) { return 0; } From 586e56d0ef8c9bda2e5c24371ad7bb0b95a4395f Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 3 Feb 2016 14:12:29 -0500 Subject: [PATCH 3/3] Help: Add notes for topic 'install-EXCLUDE_FROM_ALL' --- Help/release/dev/install-EXCLUDE_FROM_ALL.rst | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 Help/release/dev/install-EXCLUDE_FROM_ALL.rst diff --git a/Help/release/dev/install-EXCLUDE_FROM_ALL.rst b/Help/release/dev/install-EXCLUDE_FROM_ALL.rst new file mode 100644 index 000000000..a611eae49 --- /dev/null +++ b/Help/release/dev/install-EXCLUDE_FROM_ALL.rst @@ -0,0 +1,5 @@ +install-EXCLUDE_FROM_ALL +------------------------ + +* The :command:`install` command learned a new ``EXCLUDE_FROM_ALL`` option + to leave installation rules out of the default installation.