From 2d0b3e6ed2e6b21bf24050c023215126aa131a60 Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 25 Oct 2017 09:35:22 -0400 Subject: cmGlobalGenerator: Refactor test and package target conditions In `AddGlobalTarget_{Test,Package,PackageSource}`, check conditions up front and return early if the targets are not needed. This reduces the indentation of the main logic. --- Source/cmGlobalGenerator.cxx | 92 ++++++++++++++++++++++++-------------------- 1 file changed, 50 insertions(+), 42 deletions(-) diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 74a089f..a0977ac 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -2235,6 +2235,12 @@ void cmGlobalGenerator::AddGlobalTarget_Package( std::vector& targets) { cmMakefile* mf = this->Makefiles[0]; + std::string configFile = mf->GetCurrentBinaryDirectory(); + configFile += "/CPackConfig.cmake"; + if (!cmSystemTools::FileExists(configFile.c_str())) { + return; + } + const char* cmakeCfgIntDir = this->GetCMakeCFGIntDir(); GlobalTargetInfo gti; gti.Name = this->GetPackageTargetName(); @@ -2248,8 +2254,6 @@ void cmGlobalGenerator::AddGlobalTarget_Package( singleLine.push_back(cmakeCfgIntDir); } singleLine.push_back("--config"); - std::string configFile = mf->GetCurrentBinaryDirectory(); - configFile += "/CPackConfig.cmake"; std::string relConfigFile = "./CPackConfig.cmake"; singleLine.push_back(relConfigFile); gti.CommandLines.push_back(singleLine); @@ -2262,61 +2266,65 @@ void cmGlobalGenerator::AddGlobalTarget_Package( gti.Depends.push_back(this->GetAllTargetName()); } } - if (cmSystemTools::FileExists(configFile.c_str())) { - targets.push_back(gti); - } + targets.push_back(gti); } void cmGlobalGenerator::AddGlobalTarget_PackageSource( std::vector& targets) { - cmMakefile* mf = this->Makefiles[0]; const char* packageSourceTargetName = this->GetPackageSourceTargetName(); - if (packageSourceTargetName) { - GlobalTargetInfo gti; - gti.Name = packageSourceTargetName; - gti.Message = "Run CPack packaging tool for source..."; - gti.WorkingDir = mf->GetCurrentBinaryDirectory(); - gti.UsesTerminal = true; - cmCustomCommandLine singleLine; - singleLine.push_back(cmSystemTools::GetCPackCommand()); - singleLine.push_back("--config"); - std::string configFile = mf->GetCurrentBinaryDirectory(); - configFile += "/CPackSourceConfig.cmake"; - std::string relConfigFile = "./CPackSourceConfig.cmake"; - singleLine.push_back(relConfigFile); - if (cmSystemTools::FileExists(configFile.c_str())) { - singleLine.push_back(configFile); - gti.CommandLines.push_back(singleLine); - targets.push_back(gti); - } + if (!packageSourceTargetName) { + return; + } + + cmMakefile* mf = this->Makefiles[0]; + std::string configFile = mf->GetCurrentBinaryDirectory(); + configFile += "/CPackSourceConfig.cmake"; + if (!cmSystemTools::FileExists(configFile.c_str())) { + return; } + + GlobalTargetInfo gti; + gti.Name = packageSourceTargetName; + gti.Message = "Run CPack packaging tool for source..."; + gti.WorkingDir = mf->GetCurrentBinaryDirectory(); + gti.UsesTerminal = true; + cmCustomCommandLine singleLine; + singleLine.push_back(cmSystemTools::GetCPackCommand()); + singleLine.push_back("--config"); + std::string relConfigFile = "./CPackSourceConfig.cmake"; + singleLine.push_back(relConfigFile); + singleLine.push_back(configFile); + gti.CommandLines.push_back(singleLine); + targets.push_back(gti); } void cmGlobalGenerator::AddGlobalTarget_Test( std::vector& targets) { cmMakefile* mf = this->Makefiles[0]; + if (!mf->IsOn("CMAKE_TESTING_ENABLED")) { + return; + } + const char* cmakeCfgIntDir = this->GetCMakeCFGIntDir(); - if (mf->IsOn("CMAKE_TESTING_ENABLED")) { - GlobalTargetInfo gti; - gti.Name = this->GetTestTargetName(); - gti.Message = "Running tests..."; - gti.UsesTerminal = true; - cmCustomCommandLine singleLine; - singleLine.push_back(cmSystemTools::GetCTestCommand()); - singleLine.push_back("--force-new-ctest-process"); - if (cmakeCfgIntDir && *cmakeCfgIntDir && cmakeCfgIntDir[0] != '.') { - singleLine.push_back("-C"); - singleLine.push_back(cmakeCfgIntDir); - } else // TODO: This is a hack. Should be something to do with the - // generator - { - singleLine.push_back("$(ARGS)"); - } - gti.CommandLines.push_back(singleLine); - targets.push_back(gti); + GlobalTargetInfo gti; + gti.Name = this->GetTestTargetName(); + gti.Message = "Running tests..."; + gti.UsesTerminal = true; + cmCustomCommandLine singleLine; + singleLine.push_back(cmSystemTools::GetCTestCommand()); + singleLine.push_back("--force-new-ctest-process"); + if (cmakeCfgIntDir && *cmakeCfgIntDir && cmakeCfgIntDir[0] != '.') { + singleLine.push_back("-C"); + singleLine.push_back(cmakeCfgIntDir); + } else // TODO: This is a hack. Should be something to do with the + // generator + { + singleLine.push_back("$(ARGS)"); } + gti.CommandLines.push_back(singleLine); + targets.push_back(gti); } void cmGlobalGenerator::AddGlobalTarget_EditCache( -- cgit v0.12 From 103501c4e008a274aae1f25a3c2e2137b9e4c8e5 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 26 Oct 2017 11:47:14 -0400 Subject: Tests: Do not enable languages in all cases of RunCMake.CMP0037 --- Tests/RunCMake/CMP0037/CMP0037-NEW-colon.cmake | 2 +- Tests/RunCMake/CMP0037/CMP0037-NEW-reserved.cmake | 2 +- Tests/RunCMake/CMP0037/CMP0037-NEW-space.cmake | 2 +- Tests/RunCMake/CMP0037/CMP0037-OLD-reserved.cmake | 2 +- Tests/RunCMake/CMP0037/CMP0037-OLD-space.cmake | 2 +- Tests/RunCMake/CMP0037/CMP0037-WARN-colon.cmake | 2 +- Tests/RunCMake/CMP0037/CMP0037-WARN-space.cmake | 2 +- Tests/RunCMake/CMP0037/CMakeLists.txt | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Tests/RunCMake/CMP0037/CMP0037-NEW-colon.cmake b/Tests/RunCMake/CMP0037/CMP0037-NEW-colon.cmake index f4c070d..fd56e75 100644 --- a/Tests/RunCMake/CMP0037/CMP0037-NEW-colon.cmake +++ b/Tests/RunCMake/CMP0037/CMP0037-NEW-colon.cmake @@ -1,4 +1,4 @@ - +enable_language(CXX) cmake_policy(SET CMP0037 NEW) add_library("lib:colon" empty.cpp) diff --git a/Tests/RunCMake/CMP0037/CMP0037-NEW-reserved.cmake b/Tests/RunCMake/CMP0037/CMP0037-NEW-reserved.cmake index e9f6404..83a7119 100644 --- a/Tests/RunCMake/CMP0037/CMP0037-NEW-reserved.cmake +++ b/Tests/RunCMake/CMP0037/CMP0037-NEW-reserved.cmake @@ -1,4 +1,4 @@ - +enable_language(CXX) cmake_policy(SET CMP0037 NEW) add_library(all empty.cpp) diff --git a/Tests/RunCMake/CMP0037/CMP0037-NEW-space.cmake b/Tests/RunCMake/CMP0037/CMP0037-NEW-space.cmake index 9227986..2a288cc 100644 --- a/Tests/RunCMake/CMP0037/CMP0037-NEW-space.cmake +++ b/Tests/RunCMake/CMP0037/CMP0037-NEW-space.cmake @@ -1,4 +1,4 @@ - +enable_language(CXX) cmake_policy(SET CMP0037 NEW) add_library("lib with spaces" empty.cpp) diff --git a/Tests/RunCMake/CMP0037/CMP0037-OLD-reserved.cmake b/Tests/RunCMake/CMP0037/CMP0037-OLD-reserved.cmake index 870a286..f52e4d2 100644 --- a/Tests/RunCMake/CMP0037/CMP0037-OLD-reserved.cmake +++ b/Tests/RunCMake/CMP0037/CMP0037-OLD-reserved.cmake @@ -1,4 +1,4 @@ - +enable_language(CXX) cmake_policy(SET CMP0037 OLD) add_library(all empty.cpp) diff --git a/Tests/RunCMake/CMP0037/CMP0037-OLD-space.cmake b/Tests/RunCMake/CMP0037/CMP0037-OLD-space.cmake index 46193a1..c9fb6c8 100644 --- a/Tests/RunCMake/CMP0037/CMP0037-OLD-space.cmake +++ b/Tests/RunCMake/CMP0037/CMP0037-OLD-space.cmake @@ -1,4 +1,4 @@ - +enable_language(CXX) cmake_policy(SET CMP0037 OLD) add_library("lib with spaces" empty.cpp) diff --git a/Tests/RunCMake/CMP0037/CMP0037-WARN-colon.cmake b/Tests/RunCMake/CMP0037/CMP0037-WARN-colon.cmake index 445e3b2..1b1a405 100644 --- a/Tests/RunCMake/CMP0037/CMP0037-WARN-colon.cmake +++ b/Tests/RunCMake/CMP0037/CMP0037-WARN-colon.cmake @@ -1,4 +1,4 @@ - +enable_language(CXX) add_library("lib:colon" empty.cpp) add_executable("exe:colon" empty.cpp) add_custom_target("custom:colon") diff --git a/Tests/RunCMake/CMP0037/CMP0037-WARN-space.cmake b/Tests/RunCMake/CMP0037/CMP0037-WARN-space.cmake index e50a64d..e01b8e5 100644 --- a/Tests/RunCMake/CMP0037/CMP0037-WARN-space.cmake +++ b/Tests/RunCMake/CMP0037/CMP0037-WARN-space.cmake @@ -1,4 +1,4 @@ - +enable_language(CXX) add_library("lib with spaces" empty.cpp) add_executable("exe with spaces" empty.cpp) add_custom_target("custom with spaces") diff --git a/Tests/RunCMake/CMP0037/CMakeLists.txt b/Tests/RunCMake/CMP0037/CMakeLists.txt index f452db1..12cd3c7 100644 --- a/Tests/RunCMake/CMP0037/CMakeLists.txt +++ b/Tests/RunCMake/CMP0037/CMakeLists.txt @@ -1,3 +1,3 @@ cmake_minimum_required(VERSION 2.8.4) -project(${RunCMake_TEST} CXX) +project(${RunCMake_TEST} NONE) include(${RunCMake_TEST}.cmake) -- cgit v0.12 From a2611d816b49bce8a85678455b6e80ed0f30fb3e Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 26 Oct 2017 11:41:29 -0400 Subject: Tests: Add RunCMake.CMP0037 case for WARN on reserved targets --- .../CMP0037/CMP0037-WARN-reserved-stderr.txt | 36 ++++++++++++++++++++++ Tests/RunCMake/CMP0037/CMP0037-WARN-reserved.cmake | 4 +++ Tests/RunCMake/CMP0037/RunCMakeTest.cmake | 1 + 3 files changed, 41 insertions(+) create mode 100644 Tests/RunCMake/CMP0037/CMP0037-WARN-reserved-stderr.txt create mode 100644 Tests/RunCMake/CMP0037/CMP0037-WARN-reserved.cmake diff --git a/Tests/RunCMake/CMP0037/CMP0037-WARN-reserved-stderr.txt b/Tests/RunCMake/CMP0037/CMP0037-WARN-reserved-stderr.txt new file mode 100644 index 0000000..2d556a7 --- /dev/null +++ b/Tests/RunCMake/CMP0037/CMP0037-WARN-reserved-stderr.txt @@ -0,0 +1,36 @@ +CMake Warning \(dev\) at CMP0037-WARN-reserved.cmake:2 \(add_library\): + Policy CMP0037 is not set: Target names should not be reserved and should + match a validity pattern. Run "cmake --help-policy CMP0037" for policy + details. Use the cmake_policy command to set the policy and suppress this + warning. + + The target name "all" is reserved or not valid for certain CMake features, + such as generator expressions, and may result in undefined behavior. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) +This warning is for project developers. Use -Wno-dev to suppress it. ++ +CMake Warning \(dev\) at CMP0037-WARN-reserved.cmake:3 \(add_executable\): + Policy CMP0037 is not set: Target names should not be reserved and should + match a validity pattern. Run "cmake --help-policy CMP0037" for policy + details. Use the cmake_policy command to set the policy and suppress this + warning. + + The target name "clean" is reserved or not valid for certain CMake + features, such as generator expressions, and may result in undefined + behavior. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) +This warning is for project developers. Use -Wno-dev to suppress it. ++ +CMake Warning \(dev\) at CMP0037-WARN-reserved.cmake:4 \(add_custom_target\): + Policy CMP0037 is not set: Target names should not be reserved and should + match a validity pattern. Run "cmake --help-policy CMP0037" for policy + details. Use the cmake_policy command to set the policy and suppress this + warning. + + The target name "help" is reserved or not valid for certain CMake features, + such as generator expressions, and may result in undefined behavior. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) +This warning is for project developers. Use -Wno-dev to suppress it. diff --git a/Tests/RunCMake/CMP0037/CMP0037-WARN-reserved.cmake b/Tests/RunCMake/CMP0037/CMP0037-WARN-reserved.cmake new file mode 100644 index 0000000..a5e0f10 --- /dev/null +++ b/Tests/RunCMake/CMP0037/CMP0037-WARN-reserved.cmake @@ -0,0 +1,4 @@ +enable_language(CXX) +add_library(all empty.cpp) +add_executable(clean empty.cpp) +add_custom_target(help) diff --git a/Tests/RunCMake/CMP0037/RunCMakeTest.cmake b/Tests/RunCMake/CMP0037/RunCMakeTest.cmake index b7d8d7b..04c1b52 100644 --- a/Tests/RunCMake/CMP0037/RunCMakeTest.cmake +++ b/Tests/RunCMake/CMP0037/RunCMakeTest.cmake @@ -9,5 +9,6 @@ if(NOT (WIN32 AND "${RunCMake_GENERATOR}" MATCHES "Make")) run_cmake(CMP0037-WARN-colon) endif() +run_cmake(CMP0037-WARN-reserved) run_cmake(CMP0037-OLD-reserved) run_cmake(CMP0037-NEW-reserved) -- cgit v0.12 From 409527a03ced550fbc295faf965aebc7b8dbe003 Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 25 Oct 2017 13:54:26 -0400 Subject: CMP0037: De-duplicate check and message generation --- Source/cmAddCustomTargetCommand.cxx | 34 ++++------------------------------ Source/cmAddExecutableCommand.cxx | 34 +++------------------------------- Source/cmAddLibraryCommand.cxx | 32 ++------------------------------ Source/cmMakefile.cxx | 36 ++++++++++++++++++++++++++++++++++++ Source/cmMakefile.h | 3 +++ 5 files changed, 48 insertions(+), 91 deletions(-) diff --git a/Source/cmAddCustomTargetCommand.cxx b/Source/cmAddCustomTargetCommand.cxx index a8d5b2e..f4b4f66 100644 --- a/Source/cmAddCustomTargetCommand.cxx +++ b/Source/cmAddCustomTargetCommand.cxx @@ -8,7 +8,7 @@ #include "cmGeneratorExpression.h" #include "cmGlobalGenerator.h" #include "cmMakefile.h" -#include "cmPolicies.h" +#include "cmStateTypes.h" #include "cmSystemTools.h" #include "cmTarget.h" #include "cmake.h" @@ -160,35 +160,9 @@ bool cmAddCustomTargetCommand::InitialPass( if (nameOk) { nameOk = targetName.find(':') == std::string::npos; } - if (!nameOk) { - cmake::MessageType messageType = cmake::AUTHOR_WARNING; - std::ostringstream e; - bool issueMessage = false; - switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0037)) { - case cmPolicies::WARN: - e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0037) << "\n"; - issueMessage = true; - case cmPolicies::OLD: - break; - case cmPolicies::NEW: - case cmPolicies::REQUIRED_IF_USED: - case cmPolicies::REQUIRED_ALWAYS: - issueMessage = true; - messageType = cmake::FATAL_ERROR; - } - if (issueMessage) { - /* clang-format off */ - e << "The target name \"" << targetName << - "\" is reserved or not valid for certain " - "CMake features, such as generator expressions, and may result " - "in undefined behavior."; - /* clang-format on */ - this->Makefile->IssueMessage(messageType, e.str()); - - if (messageType == cmake::FATAL_ERROR) { - return false; - } - } + if (!nameOk && + !this->Makefile->CheckCMP0037(targetName, cmStateEnums::UTILITY)) { + return false; } // Store the last command line finished. diff --git a/Source/cmAddExecutableCommand.cxx b/Source/cmAddExecutableCommand.cxx index 262e3a1..a95e3da 100644 --- a/Source/cmAddExecutableCommand.cxx +++ b/Source/cmAddExecutableCommand.cxx @@ -7,10 +7,8 @@ #include "cmGeneratorExpression.h" #include "cmGlobalGenerator.h" #include "cmMakefile.h" -#include "cmPolicies.h" #include "cmStateTypes.h" #include "cmTarget.h" -#include "cmake.h" class cmExecutionStatus; @@ -63,35 +61,9 @@ bool cmAddExecutableCommand::InitialPass(std::vector const& args, if (nameOk && !importTarget && !isAlias) { nameOk = exename.find(':') == std::string::npos; } - if (!nameOk) { - cmake::MessageType messageType = cmake::AUTHOR_WARNING; - std::ostringstream e; - bool issueMessage = false; - switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0037)) { - case cmPolicies::WARN: - e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0037) << "\n"; - issueMessage = true; - case cmPolicies::OLD: - break; - case cmPolicies::NEW: - case cmPolicies::REQUIRED_IF_USED: - case cmPolicies::REQUIRED_ALWAYS: - issueMessage = true; - messageType = cmake::FATAL_ERROR; - } - if (issueMessage) { - /* clang-format off */ - e << "The target name \"" << exename << - "\" is reserved or not valid for certain " - "CMake features, such as generator expressions, and may result " - "in undefined behavior."; - /* clang-format on */ - this->Makefile->IssueMessage(messageType, e.str()); - - if (messageType == cmake::FATAL_ERROR) { - return false; - } - } + if (!nameOk && + !this->Makefile->CheckCMP0037(exename, cmStateEnums::EXECUTABLE)) { + return false; } // Special modifiers are not allowed with IMPORTED signature. diff --git a/Source/cmAddLibraryCommand.cxx b/Source/cmAddLibraryCommand.cxx index 31c2ecf..4400f44 100644 --- a/Source/cmAddLibraryCommand.cxx +++ b/Source/cmAddLibraryCommand.cxx @@ -7,7 +7,6 @@ #include "cmGeneratorExpression.h" #include "cmGlobalGenerator.h" #include "cmMakefile.h" -#include "cmPolicies.h" #include "cmState.h" #include "cmStateTypes.h" #include "cmSystemTools.h" @@ -175,35 +174,8 @@ bool cmAddLibraryCommand::InitialPass(std::vector const& args, if (nameOk && !importTarget && !isAlias) { nameOk = libName.find(':') == std::string::npos; } - if (!nameOk) { - cmake::MessageType messageType = cmake::AUTHOR_WARNING; - std::ostringstream e; - bool issueMessage = false; - switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0037)) { - case cmPolicies::WARN: - if (type != cmStateEnums::INTERFACE_LIBRARY) { - e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0037) << "\n"; - issueMessage = true; - } - case cmPolicies::OLD: - break; - case cmPolicies::NEW: - case cmPolicies::REQUIRED_IF_USED: - case cmPolicies::REQUIRED_ALWAYS: - issueMessage = true; - messageType = cmake::FATAL_ERROR; - } - if (issueMessage) { - e << "The target name \"" << libName - << "\" is reserved or not valid for certain " - "CMake features, such as generator expressions, and may result " - "in undefined behavior."; - this->Makefile->IssueMessage(messageType, e.str()); - - if (messageType == cmake::FATAL_ERROR) { - return false; - } - } + if (!nameOk && !this->Makefile->CheckCMP0037(libName, type)) { + return false; } if (isAlias) { diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index fbafbf8..43c529c 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -123,6 +123,42 @@ void cmMakefile::IssueMessage(cmake::MessageType t, this->GetCMakeInstance()->IssueMessage(t, text, this->GetBacktrace()); } +bool cmMakefile::CheckCMP0037(std::string const& targetName, + cmStateEnums::TargetType targetType) const +{ + cmake::MessageType messageType = cmake::AUTHOR_WARNING; + std::ostringstream e; + bool issueMessage = false; + switch (this->GetPolicyStatus(cmPolicies::CMP0037)) { + case cmPolicies::WARN: + if (targetType != cmStateEnums::INTERFACE_LIBRARY) { + e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0037) << "\n"; + issueMessage = true; + } + CM_FALLTHROUGH; + case cmPolicies::OLD: + break; + case cmPolicies::NEW: + case cmPolicies::REQUIRED_IF_USED: + case cmPolicies::REQUIRED_ALWAYS: + issueMessage = true; + messageType = cmake::FATAL_ERROR; + break; + } + if (issueMessage) { + e << "The target name \"" << targetName + << "\" is reserved or not valid for certain " + "CMake features, such as generator expressions, and may result " + "in undefined behavior."; + this->IssueMessage(messageType, e.str()); + + if (messageType == cmake::FATAL_ERROR) { + return false; + } + } + return true; +} + cmStringRange cmMakefile::GetIncludeDirectoriesEntries() const { return this->StateSnapshot.GetDirectory().GetIncludeDirectoriesEntries(); diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index 7c6cca5..5e7a361 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -741,6 +741,9 @@ public: /** Set whether or not to report a CMP0000 violation. */ void SetCheckCMP0000(bool b) { this->CheckCMP0000 = b; } + bool CheckCMP0037(std::string const& targetName, + cmStateEnums::TargetType targetType) const; + cmStringRange GetIncludeDirectoriesEntries() const; cmBacktraceRange GetIncludeDirectoriesBacktraces() const; cmStringRange GetCompileOptionsEntries() const; -- cgit v0.12 From ae5f40696ef6efc62b663457b72184f682a23fe2 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 26 Oct 2017 14:01:51 -0400 Subject: CMP0037: Allow test and package targets when features are not enabled When CMake will not generate a test, package, or package_source target, allow projects to create their own targets with these names. Fixes: #16062 --- Source/cmGlobalGenerator.cxx | 72 ++++++++++++++++++++-- Source/cmGlobalGenerator.h | 3 + Source/cmPolicies.h | 1 + Tests/RunCMake/CMP0037/NEW-cond-package-result.txt | 1 + Tests/RunCMake/CMP0037/NEW-cond-package-stderr.txt | 4 ++ Tests/RunCMake/CMP0037/NEW-cond-package.cmake | 5 ++ .../CMP0037/NEW-cond-package_source-result.txt | 1 + .../CMP0037/NEW-cond-package_source-stderr.txt | 5 ++ .../RunCMake/CMP0037/NEW-cond-package_source.cmake | 5 ++ Tests/RunCMake/CMP0037/NEW-cond-test-result.txt | 1 + Tests/RunCMake/CMP0037/NEW-cond-test-stderr.txt | 4 ++ Tests/RunCMake/CMP0037/NEW-cond-test.cmake | 5 ++ Tests/RunCMake/CMP0037/NEW-cond.cmake | 4 ++ Tests/RunCMake/CMP0037/OLD-cond-package.cmake | 5 ++ .../RunCMake/CMP0037/OLD-cond-package_source.cmake | 5 ++ Tests/RunCMake/CMP0037/OLD-cond-test.cmake | 5 ++ Tests/RunCMake/CMP0037/OLD-cond.cmake | 5 ++ Tests/RunCMake/CMP0037/RunCMakeTest.cmake | 16 +++++ .../RunCMake/CMP0037/WARN-cond-package-stderr.txt | 11 ++++ Tests/RunCMake/CMP0037/WARN-cond-package.cmake | 5 ++ .../CMP0037/WARN-cond-package_source-stderr.txt | 11 ++++ .../CMP0037/WARN-cond-package_source.cmake | 5 ++ Tests/RunCMake/CMP0037/WARN-cond-test-stderr.txt | 11 ++++ Tests/RunCMake/CMP0037/WARN-cond-test.cmake | 5 ++ Tests/RunCMake/CMP0037/WARN-cond.cmake | 4 ++ .../RunCMake/TargetPolicies/PolicyList-stderr.txt | 1 + 26 files changed, 195 insertions(+), 5 deletions(-) create mode 100644 Tests/RunCMake/CMP0037/NEW-cond-package-result.txt create mode 100644 Tests/RunCMake/CMP0037/NEW-cond-package-stderr.txt create mode 100644 Tests/RunCMake/CMP0037/NEW-cond-package.cmake create mode 100644 Tests/RunCMake/CMP0037/NEW-cond-package_source-result.txt create mode 100644 Tests/RunCMake/CMP0037/NEW-cond-package_source-stderr.txt create mode 100644 Tests/RunCMake/CMP0037/NEW-cond-package_source.cmake create mode 100644 Tests/RunCMake/CMP0037/NEW-cond-test-result.txt create mode 100644 Tests/RunCMake/CMP0037/NEW-cond-test-stderr.txt create mode 100644 Tests/RunCMake/CMP0037/NEW-cond-test.cmake create mode 100644 Tests/RunCMake/CMP0037/NEW-cond.cmake create mode 100644 Tests/RunCMake/CMP0037/OLD-cond-package.cmake create mode 100644 Tests/RunCMake/CMP0037/OLD-cond-package_source.cmake create mode 100644 Tests/RunCMake/CMP0037/OLD-cond-test.cmake create mode 100644 Tests/RunCMake/CMP0037/OLD-cond.cmake create mode 100644 Tests/RunCMake/CMP0037/WARN-cond-package-stderr.txt create mode 100644 Tests/RunCMake/CMP0037/WARN-cond-package.cmake create mode 100644 Tests/RunCMake/CMP0037/WARN-cond-package_source-stderr.txt create mode 100644 Tests/RunCMake/CMP0037/WARN-cond-package_source.cmake create mode 100644 Tests/RunCMake/CMP0037/WARN-cond-test-stderr.txt create mode 100644 Tests/RunCMake/CMP0037/WARN-cond-test.cmake create mode 100644 Tests/RunCMake/CMP0037/WARN-cond.cmake diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index a0977ac..11ea46f 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -2220,6 +2220,45 @@ inline std::string removeQuotes(const std::string& s) return s; } +bool cmGlobalGenerator::CheckCMP0037(std::string const& targetName, + std::string const& reason) const +{ + cmTarget* tgt = this->FindTarget(targetName); + if (!tgt) { + return true; + } + cmake::MessageType messageType = cmake::AUTHOR_WARNING; + std::ostringstream e; + bool issueMessage = false; + switch (tgt->GetPolicyStatusCMP0037()) { + case cmPolicies::WARN: + e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0037) << "\n"; + issueMessage = true; + CM_FALLTHROUGH; + case cmPolicies::OLD: + break; + case cmPolicies::NEW: + case cmPolicies::REQUIRED_IF_USED: + case cmPolicies::REQUIRED_ALWAYS: + issueMessage = true; + messageType = cmake::FATAL_ERROR; + break; + } + if (issueMessage) { + e << "The target name \"" << targetName << "\" is reserved " << reason + << "."; + if (messageType == cmake::AUTHOR_WARNING) { + e << " It may result in undefined behavior."; + } + this->GetCMakeInstance()->IssueMessage(messageType, e.str(), + tgt->GetBacktrace()); + if (messageType == cmake::FATAL_ERROR) { + return false; + } + } + return true; +} + void cmGlobalGenerator::CreateDefaultGlobalTargets( std::vector& targets) { @@ -2241,6 +2280,14 @@ void cmGlobalGenerator::AddGlobalTarget_Package( return; } + const char* reservedTargets[] = { "package", "PACKAGE" }; + for (const char* const* tn = cm::cbegin(reservedTargets); + tn != cm::cend(reservedTargets); ++tn) { + if (!this->CheckCMP0037(*tn, "when CPack packaging is enabled")) { + return; + } + } + const char* cmakeCfgIntDir = this->GetCMakeCFGIntDir(); GlobalTargetInfo gti; gti.Name = this->GetPackageTargetName(); @@ -2284,6 +2331,14 @@ void cmGlobalGenerator::AddGlobalTarget_PackageSource( return; } + const char* reservedTargets[] = { "package_source" }; + for (const char* const* tn = cm::cbegin(reservedTargets); + tn != cm::cend(reservedTargets); ++tn) { + if (!this->CheckCMP0037(*tn, "when CPack source packaging is enabled")) { + return; + } + } + GlobalTargetInfo gti; gti.Name = packageSourceTargetName; gti.Message = "Run CPack packaging tool for source..."; @@ -2307,6 +2362,14 @@ void cmGlobalGenerator::AddGlobalTarget_Test( return; } + const char* reservedTargets[] = { "test", "RUN_TESTS" }; + for (const char* const* tn = cm::cbegin(reservedTargets); + tn != cm::cend(reservedTargets); ++tn) { + if (!this->CheckCMP0037(*tn, "when CTest testing is enabled")) { + return; + } + } + const char* cmakeCfgIntDir = this->GetCMakeCFGIntDir(); GlobalTargetInfo gti; gti.Name = this->GetTestTargetName(); @@ -2590,11 +2653,10 @@ bool cmGlobalGenerator::IsReservedTarget(std::string const& name) // by one or more of the cmake generators. // Adding additional targets to this list will require a policy! - const char* reservedTargets[] = { - "all", "ALL_BUILD", "help", "install", "INSTALL", - "preinstall", "clean", "edit_cache", "rebuild_cache", "test", - "RUN_TESTS", "package", "PACKAGE", "package_source", "ZERO_CHECK" - }; + const char* reservedTargets[] = { "all", "ALL_BUILD", "help", + "install", "INSTALL", "preinstall", + "clean", "edit_cache", "rebuild_cache", + "ZERO_CHECK" }; return std::find(cm::cbegin(reservedTargets), cm::cend(reservedTargets), name) != cm::cend(reservedTargets); diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h index c5a5297..8fcb533 100644 --- a/Source/cmGlobalGenerator.h +++ b/Source/cmGlobalGenerator.h @@ -568,6 +568,9 @@ private: void ClearGeneratorMembers(); + bool CheckCMP0037(std::string const& targetName, + std::string const& reason) const; + void IndexMakefile(cmMakefile* mf); virtual const char* GetBuildIgnoreErrorsFlag() const { return nullptr; } diff --git a/Source/cmPolicies.h b/Source/cmPolicies.h index 354011a..7d15ee2 100644 --- a/Source/cmPolicies.h +++ b/Source/cmPolicies.h @@ -225,6 +225,7 @@ class cmMakefile; F(CMP0021) \ F(CMP0022) \ F(CMP0027) \ + F(CMP0037) \ F(CMP0038) \ F(CMP0041) \ F(CMP0042) \ diff --git a/Tests/RunCMake/CMP0037/NEW-cond-package-result.txt b/Tests/RunCMake/CMP0037/NEW-cond-package-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/CMP0037/NEW-cond-package-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CMP0037/NEW-cond-package-stderr.txt b/Tests/RunCMake/CMP0037/NEW-cond-package-stderr.txt new file mode 100644 index 0000000..270fa6d --- /dev/null +++ b/Tests/RunCMake/CMP0037/NEW-cond-package-stderr.txt @@ -0,0 +1,4 @@ +^CMake Error at NEW-cond-package.cmake:4 \(add_custom_target\): + The target name "package" is reserved when CPack packaging is enabled. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\)$ diff --git a/Tests/RunCMake/CMP0037/NEW-cond-package.cmake b/Tests/RunCMake/CMP0037/NEW-cond-package.cmake new file mode 100644 index 0000000..ceea907 --- /dev/null +++ b/Tests/RunCMake/CMP0037/NEW-cond-package.cmake @@ -0,0 +1,5 @@ +cmake_policy(SET CMP0037 NEW) +file(WRITE "${CMAKE_BINARY_DIR}/CPackConfig.cmake" "") +add_custom_target(test) +add_custom_target(package) +add_custom_target(package_source) diff --git a/Tests/RunCMake/CMP0037/NEW-cond-package_source-result.txt b/Tests/RunCMake/CMP0037/NEW-cond-package_source-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/CMP0037/NEW-cond-package_source-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CMP0037/NEW-cond-package_source-stderr.txt b/Tests/RunCMake/CMP0037/NEW-cond-package_source-stderr.txt new file mode 100644 index 0000000..2d32147 --- /dev/null +++ b/Tests/RunCMake/CMP0037/NEW-cond-package_source-stderr.txt @@ -0,0 +1,5 @@ +^CMake Error at NEW-cond-package_source.cmake:5 \(add_custom_target\): + The target name "package_source" is reserved when CPack source packaging is + enabled. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\)$ diff --git a/Tests/RunCMake/CMP0037/NEW-cond-package_source.cmake b/Tests/RunCMake/CMP0037/NEW-cond-package_source.cmake new file mode 100644 index 0000000..3f8883b --- /dev/null +++ b/Tests/RunCMake/CMP0037/NEW-cond-package_source.cmake @@ -0,0 +1,5 @@ +cmake_policy(SET CMP0037 NEW) +file(WRITE "${CMAKE_BINARY_DIR}/CPackSourceConfig.cmake" "") +add_custom_target(test) +add_custom_target(package) +add_custom_target(package_source) diff --git a/Tests/RunCMake/CMP0037/NEW-cond-test-result.txt b/Tests/RunCMake/CMP0037/NEW-cond-test-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/CMP0037/NEW-cond-test-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CMP0037/NEW-cond-test-stderr.txt b/Tests/RunCMake/CMP0037/NEW-cond-test-stderr.txt new file mode 100644 index 0000000..44b4741 --- /dev/null +++ b/Tests/RunCMake/CMP0037/NEW-cond-test-stderr.txt @@ -0,0 +1,4 @@ +^CMake Error at NEW-cond-test.cmake:3 \(add_custom_target\): + The target name "test" is reserved when CTest testing is enabled. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\)$ diff --git a/Tests/RunCMake/CMP0037/NEW-cond-test.cmake b/Tests/RunCMake/CMP0037/NEW-cond-test.cmake new file mode 100644 index 0000000..7eeaffc --- /dev/null +++ b/Tests/RunCMake/CMP0037/NEW-cond-test.cmake @@ -0,0 +1,5 @@ +cmake_policy(SET CMP0037 NEW) +enable_testing() +add_custom_target(test) +add_custom_target(package) +add_custom_target(package_source) diff --git a/Tests/RunCMake/CMP0037/NEW-cond.cmake b/Tests/RunCMake/CMP0037/NEW-cond.cmake new file mode 100644 index 0000000..d0dc77af --- /dev/null +++ b/Tests/RunCMake/CMP0037/NEW-cond.cmake @@ -0,0 +1,4 @@ +cmake_policy(SET CMP0037 NEW) +add_custom_target(test) +add_custom_target(package) +add_custom_target(package_source) diff --git a/Tests/RunCMake/CMP0037/OLD-cond-package.cmake b/Tests/RunCMake/CMP0037/OLD-cond-package.cmake new file mode 100644 index 0000000..7a0afbe --- /dev/null +++ b/Tests/RunCMake/CMP0037/OLD-cond-package.cmake @@ -0,0 +1,5 @@ +cmake_policy(SET CMP0037 OLD) +file(WRITE "${CMAKE_BINARY_DIR}/CPackConfig.cmake" "") +add_custom_target(test) +add_custom_target(package) +add_custom_target(package_source) diff --git a/Tests/RunCMake/CMP0037/OLD-cond-package_source.cmake b/Tests/RunCMake/CMP0037/OLD-cond-package_source.cmake new file mode 100644 index 0000000..95616b6 --- /dev/null +++ b/Tests/RunCMake/CMP0037/OLD-cond-package_source.cmake @@ -0,0 +1,5 @@ +cmake_policy(SET CMP0037 OLD) +file(WRITE "${CMAKE_BINARY_DIR}/CPackSourceConfig.cmake" "") +add_custom_target(test) +add_custom_target(package) +add_custom_target(package_source) diff --git a/Tests/RunCMake/CMP0037/OLD-cond-test.cmake b/Tests/RunCMake/CMP0037/OLD-cond-test.cmake new file mode 100644 index 0000000..bfa32a9 --- /dev/null +++ b/Tests/RunCMake/CMP0037/OLD-cond-test.cmake @@ -0,0 +1,5 @@ +cmake_policy(SET CMP0037 OLD) +enable_testing() +add_custom_target(test) +add_custom_target(package) +add_custom_target(package_source) diff --git a/Tests/RunCMake/CMP0037/OLD-cond.cmake b/Tests/RunCMake/CMP0037/OLD-cond.cmake new file mode 100644 index 0000000..abad680 --- /dev/null +++ b/Tests/RunCMake/CMP0037/OLD-cond.cmake @@ -0,0 +1,5 @@ +cmake_policy(SET CMP0037 OLD) + +add_custom_target(test) +add_custom_target(package) +add_custom_target(package_source) diff --git a/Tests/RunCMake/CMP0037/RunCMakeTest.cmake b/Tests/RunCMake/CMP0037/RunCMakeTest.cmake index 04c1b52..98274f0 100644 --- a/Tests/RunCMake/CMP0037/RunCMakeTest.cmake +++ b/Tests/RunCMake/CMP0037/RunCMakeTest.cmake @@ -12,3 +12,19 @@ endif() run_cmake(CMP0037-WARN-reserved) run_cmake(CMP0037-OLD-reserved) run_cmake(CMP0037-NEW-reserved) + +run_cmake(NEW-cond) +run_cmake(NEW-cond-test) +run_cmake(NEW-cond-package) +run_cmake(OLD-cond) +run_cmake(OLD-cond-test) +run_cmake(OLD-cond-package) +run_cmake(WARN-cond) +run_cmake(WARN-cond-test) +run_cmake(WARN-cond-package) + +if(RunCMake_GENERATOR MATCHES "Make|Ninja") + run_cmake(NEW-cond-package_source) + run_cmake(OLD-cond-package_source) + run_cmake(WARN-cond-package_source) +endif() diff --git a/Tests/RunCMake/CMP0037/WARN-cond-package-stderr.txt b/Tests/RunCMake/CMP0037/WARN-cond-package-stderr.txt new file mode 100644 index 0000000..5960e51 --- /dev/null +++ b/Tests/RunCMake/CMP0037/WARN-cond-package-stderr.txt @@ -0,0 +1,11 @@ +^CMake Warning \(dev\) at WARN-cond-package.cmake:4 \(add_custom_target\): + Policy CMP0037 is not set: Target names should not be reserved and should + match a validity pattern. Run "cmake --help-policy CMP0037" for policy + details. Use the cmake_policy command to set the policy and suppress this + warning. + + The target name "package" is reserved when CPack packaging is enabled. It + may result in undefined behavior. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) +This warning is for project developers. Use -Wno-dev to suppress it.$ diff --git a/Tests/RunCMake/CMP0037/WARN-cond-package.cmake b/Tests/RunCMake/CMP0037/WARN-cond-package.cmake new file mode 100644 index 0000000..61cdc68 --- /dev/null +++ b/Tests/RunCMake/CMP0037/WARN-cond-package.cmake @@ -0,0 +1,5 @@ + +file(WRITE "${CMAKE_BINARY_DIR}/CPackConfig.cmake" "") +add_custom_target(test) +add_custom_target(package) +add_custom_target(package_source) diff --git a/Tests/RunCMake/CMP0037/WARN-cond-package_source-stderr.txt b/Tests/RunCMake/CMP0037/WARN-cond-package_source-stderr.txt new file mode 100644 index 0000000..ae72909 --- /dev/null +++ b/Tests/RunCMake/CMP0037/WARN-cond-package_source-stderr.txt @@ -0,0 +1,11 @@ +^CMake Warning \(dev\) at WARN-cond-package_source.cmake:5 \(add_custom_target\): + Policy CMP0037 is not set: Target names should not be reserved and should + match a validity pattern. Run "cmake --help-policy CMP0037" for policy + details. Use the cmake_policy command to set the policy and suppress this + warning. + + The target name "package_source" is reserved when CPack source packaging is + enabled. It may result in undefined behavior. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) +This warning is for project developers. Use -Wno-dev to suppress it.$ diff --git a/Tests/RunCMake/CMP0037/WARN-cond-package_source.cmake b/Tests/RunCMake/CMP0037/WARN-cond-package_source.cmake new file mode 100644 index 0000000..468380c --- /dev/null +++ b/Tests/RunCMake/CMP0037/WARN-cond-package_source.cmake @@ -0,0 +1,5 @@ + +file(WRITE "${CMAKE_BINARY_DIR}/CPackSourceConfig.cmake" "") +add_custom_target(test) +add_custom_target(package) +add_custom_target(package_source) diff --git a/Tests/RunCMake/CMP0037/WARN-cond-test-stderr.txt b/Tests/RunCMake/CMP0037/WARN-cond-test-stderr.txt new file mode 100644 index 0000000..e7a3ee5 --- /dev/null +++ b/Tests/RunCMake/CMP0037/WARN-cond-test-stderr.txt @@ -0,0 +1,11 @@ +^CMake Warning \(dev\) at WARN-cond-test.cmake:3 \(add_custom_target\): + Policy CMP0037 is not set: Target names should not be reserved and should + match a validity pattern. Run "cmake --help-policy CMP0037" for policy + details. Use the cmake_policy command to set the policy and suppress this + warning. + + The target name "test" is reserved when CTest testing is enabled. It may + result in undefined behavior. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) +This warning is for project developers. Use -Wno-dev to suppress it.$ diff --git a/Tests/RunCMake/CMP0037/WARN-cond-test.cmake b/Tests/RunCMake/CMP0037/WARN-cond-test.cmake new file mode 100644 index 0000000..982af36 --- /dev/null +++ b/Tests/RunCMake/CMP0037/WARN-cond-test.cmake @@ -0,0 +1,5 @@ + +enable_testing() +add_custom_target(test) +add_custom_target(package) +add_custom_target(package_source) diff --git a/Tests/RunCMake/CMP0037/WARN-cond.cmake b/Tests/RunCMake/CMP0037/WARN-cond.cmake new file mode 100644 index 0000000..04a7f9d --- /dev/null +++ b/Tests/RunCMake/CMP0037/WARN-cond.cmake @@ -0,0 +1,4 @@ + +add_custom_target(test) +add_custom_target(package) +add_custom_target(package_source) diff --git a/Tests/RunCMake/TargetPolicies/PolicyList-stderr.txt b/Tests/RunCMake/TargetPolicies/PolicyList-stderr.txt index 5f6be87..8d5139d 100644 --- a/Tests/RunCMake/TargetPolicies/PolicyList-stderr.txt +++ b/Tests/RunCMake/TargetPolicies/PolicyList-stderr.txt @@ -12,6 +12,7 @@ \* CMP0021 \* CMP0022 \* CMP0027 + \* CMP0037 \* CMP0038 \* CMP0041 \* CMP0042 -- cgit v0.12