diff options
Diffstat (limited to 'Source/cmMakefile.cxx')
-rw-r--r-- | Source/cmMakefile.cxx | 172 |
1 files changed, 105 insertions, 67 deletions
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 5643c97..4109b90 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -7,6 +7,7 @@ #include <algorithm> #include <assert.h> #include <ctype.h> +#include <iterator> #include <memory> // IWYU pragma: keep #include <sstream> #include <stdlib.h> @@ -122,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(); @@ -562,7 +599,7 @@ void cmMakefile::EnforceDirectoryLevelRules() const << "\"cmake --help-policy CMP0000\"."; switch (this->GetPolicyStatus(cmPolicies::CMP0000)) { case cmPolicies::WARN: - // Warn because the user did not provide a mimimum required + // Warn because the user did not provide a minimum required // version. this->GetCMakeInstance()->IssueMessage(cmake::AUTHOR_WARNING, msg.str(), this->Backtrace); @@ -3186,6 +3223,7 @@ int cmMakefile::TryCompile(const std::string& srcdir, // do a configure cm.SetHomeDirectory(srcdir); cm.SetHomeOutputDirectory(bindir); + cm.SetGeneratorInstance(this->GetSafeDefinition("CMAKE_GENERATOR_INSTANCE")); cm.SetGeneratorPlatform(this->GetSafeDefinition("CMAKE_GENERATOR_PLATFORM")); cm.SetGeneratorToolset(this->GetSafeDefinition("CMAKE_GENERATOR_TOOLSET")); cm.LoadCache(); @@ -3281,6 +3319,13 @@ cmGlobalGenerator* cmMakefile::GetGlobalGenerator() const return this->GlobalGenerator; } +void cmMakefile::GetTestNames(std::vector<std::string>& testNames) +{ + for (const auto& iter : Tests) { + testNames.push_back(iter.first); + } +} + #ifdef CMAKE_BUILD_WITH_CMAKE cmVariableWatch* cmMakefile::GetVariableWatch() const { @@ -3980,7 +4025,7 @@ bool cmMakefile::SetPolicy(cmPolicies::PolicyID id, // Deprecate old policies, especially those that require a lot // of code to maintain the old behavior. - if (status == cmPolicies::OLD && id <= cmPolicies::CMP0036) { + if (status == cmPolicies::OLD && id <= cmPolicies::CMP0054) { this->IssueMessage(cmake::DEPRECATION_WARNING, cmPolicies::GetPolicyDeprecatedWarning(id)); } @@ -4133,15 +4178,15 @@ bool cmMakefile::CompileFeatureKnown(cmTarget const* target, assert(cmGeneratorExpression::Find(feature) == std::string::npos); bool isCFeature = - std::find_if(cmArrayBegin(C_FEATURES) + 1, cmArrayEnd(C_FEATURES), - cmStrCmp(feature)) != cmArrayEnd(C_FEATURES); + std::find_if(cm::cbegin(C_FEATURES) + 1, cm::cend(C_FEATURES), + cmStrCmp(feature)) != cm::cend(C_FEATURES); if (isCFeature) { lang = "C"; return true; } bool isCxxFeature = - std::find_if(cmArrayBegin(CXX_FEATURES) + 1, cmArrayEnd(CXX_FEATURES), - cmStrCmp(feature)) != cmArrayEnd(CXX_FEATURES); + std::find_if(cm::cbegin(CXX_FEATURES) + 1, cm::cend(CXX_FEATURES), + cmStrCmp(feature)) != cm::cend(CXX_FEATURES); if (isCxxFeature) { lang = "CXX"; return true; @@ -4230,8 +4275,8 @@ bool cmMakefile::HaveCStandardAvailable(cmTarget const* target, // Return true so the caller does not try to lookup the default standard. return true; } - if (std::find_if(cmArrayBegin(C_STANDARDS), cmArrayEnd(C_STANDARDS), - cmStrCmp(defaultCStandard)) == cmArrayEnd(C_STANDARDS)) { + if (std::find_if(cm::cbegin(C_STANDARDS), cm::cend(C_STANDARDS), + cmStrCmp(defaultCStandard)) == cm::cend(C_STANDARDS)) { std::ostringstream e; e << "The CMAKE_C_STANDARD_DEFAULT variable contains an " "invalid value: \"" @@ -4251,8 +4296,8 @@ bool cmMakefile::HaveCStandardAvailable(cmTarget const* target, existingCStandard = defaultCStandard; } - if (std::find_if(cmArrayBegin(C_STANDARDS), cmArrayEnd(C_STANDARDS), - cmStrCmp(existingCStandard)) == cmArrayEnd(C_STANDARDS)) { + if (std::find_if(cm::cbegin(C_STANDARDS), cm::cend(C_STANDARDS), + cmStrCmp(existingCStandard)) == cm::cend(C_STANDARDS)) { std::ostringstream e; e << "The C_STANDARD property on target \"" << target->GetName() << "\" contained an invalid value: \"" << existingCStandard << "\"."; @@ -4261,23 +4306,23 @@ bool cmMakefile::HaveCStandardAvailable(cmTarget const* target, } const char* const* existingCIt = existingCStandard - ? std::find_if(cmArrayBegin(C_STANDARDS), cmArrayEnd(C_STANDARDS), + ? std::find_if(cm::cbegin(C_STANDARDS), cm::cend(C_STANDARDS), cmStrCmp(existingCStandard)) - : cmArrayEnd(C_STANDARDS); + : cm::cend(C_STANDARDS); if (needC11 && existingCStandard && - existingCIt < std::find_if(cmArrayBegin(C_STANDARDS), - cmArrayEnd(C_STANDARDS), cmStrCmp("11"))) { + existingCIt < std::find_if(cm::cbegin(C_STANDARDS), + cm::cend(C_STANDARDS), cmStrCmp("11"))) { return false; } if (needC99 && existingCStandard && - existingCIt < std::find_if(cmArrayBegin(C_STANDARDS), - cmArrayEnd(C_STANDARDS), cmStrCmp("99"))) { + existingCIt < std::find_if(cm::cbegin(C_STANDARDS), + cm::cend(C_STANDARDS), cmStrCmp("99"))) { return false; } if (needC90 && existingCStandard && - existingCIt < std::find_if(cmArrayBegin(C_STANDARDS), - cmArrayEnd(C_STANDARDS), cmStrCmp("90"))) { + existingCIt < std::find_if(cm::cbegin(C_STANDARDS), + cm::cend(C_STANDARDS), cmStrCmp("90"))) { return false; } return true; @@ -4289,16 +4334,16 @@ bool cmMakefile::IsLaterStandard(std::string const& lang, { if (lang == "C") { const char* const* rhsIt = std::find_if( - cmArrayBegin(C_STANDARDS), cmArrayEnd(C_STANDARDS), cmStrCmp(rhs)); + cm::cbegin(C_STANDARDS), cm::cend(C_STANDARDS), cmStrCmp(rhs)); - return std::find_if(rhsIt, cmArrayEnd(C_STANDARDS), cmStrCmp(lhs)) != - cmArrayEnd(C_STANDARDS); + return std::find_if(rhsIt, cm::cend(C_STANDARDS), cmStrCmp(lhs)) != + cm::cend(C_STANDARDS); } const char* const* rhsIt = std::find_if( - cmArrayBegin(CXX_STANDARDS), cmArrayEnd(CXX_STANDARDS), cmStrCmp(rhs)); + cm::cbegin(CXX_STANDARDS), cm::cend(CXX_STANDARDS), cmStrCmp(rhs)); - return std::find_if(rhsIt, cmArrayEnd(CXX_STANDARDS), cmStrCmp(lhs)) != - cmArrayEnd(CXX_STANDARDS); + return std::find_if(rhsIt, cm::cend(CXX_STANDARDS), cmStrCmp(lhs)) != + cm::cend(CXX_STANDARDS); } bool cmMakefile::HaveCxxStandardAvailable(cmTarget const* target, @@ -4314,9 +4359,8 @@ bool cmMakefile::HaveCxxStandardAvailable(cmTarget const* target, // Return true so the caller does not try to lookup the default standard. return true; } - if (std::find_if(cmArrayBegin(CXX_STANDARDS), cmArrayEnd(CXX_STANDARDS), - cmStrCmp(defaultCxxStandard)) == - cmArrayEnd(CXX_STANDARDS)) { + if (std::find_if(cm::cbegin(CXX_STANDARDS), cm::cend(CXX_STANDARDS), + cmStrCmp(defaultCxxStandard)) == cm::cend(CXX_STANDARDS)) { std::ostringstream e; e << "The CMAKE_CXX_STANDARD_DEFAULT variable contains an " "invalid value: \"" @@ -4337,9 +4381,8 @@ bool cmMakefile::HaveCxxStandardAvailable(cmTarget const* target, existingCxxStandard = defaultCxxStandard; } - if (std::find_if(cmArrayBegin(CXX_STANDARDS), cmArrayEnd(CXX_STANDARDS), - cmStrCmp(existingCxxStandard)) == - cmArrayEnd(CXX_STANDARDS)) { + if (std::find_if(cm::cbegin(CXX_STANDARDS), cm::cend(CXX_STANDARDS), + cmStrCmp(existingCxxStandard)) == cm::cend(CXX_STANDARDS)) { std::ostringstream e; e << "The CXX_STANDARD property on target \"" << target->GetName() << "\" contained an invalid value: \"" << existingCxxStandard << "\"."; @@ -4348,32 +4391,28 @@ bool cmMakefile::HaveCxxStandardAvailable(cmTarget const* target, } const char* const* existingCxxIt = existingCxxStandard - ? std::find_if(cmArrayBegin(CXX_STANDARDS), cmArrayEnd(CXX_STANDARDS), + ? std::find_if(cm::cbegin(CXX_STANDARDS), cm::cend(CXX_STANDARDS), cmStrCmp(existingCxxStandard)) - : cmArrayEnd(CXX_STANDARDS); + : cm::cend(CXX_STANDARDS); if (needCxx17 && - existingCxxIt < std::find_if(cmArrayBegin(CXX_STANDARDS), - cmArrayEnd(CXX_STANDARDS), - cmStrCmp("17"))) { + existingCxxIt < std::find_if(cm::cbegin(CXX_STANDARDS), + cm::cend(CXX_STANDARDS), cmStrCmp("17"))) { return false; } if (needCxx14 && - existingCxxIt < std::find_if(cmArrayBegin(CXX_STANDARDS), - cmArrayEnd(CXX_STANDARDS), - cmStrCmp("14"))) { + existingCxxIt < std::find_if(cm::cbegin(CXX_STANDARDS), + cm::cend(CXX_STANDARDS), cmStrCmp("14"))) { return false; } if (needCxx11 && - existingCxxIt < std::find_if(cmArrayBegin(CXX_STANDARDS), - cmArrayEnd(CXX_STANDARDS), - cmStrCmp("11"))) { + existingCxxIt < std::find_if(cm::cbegin(CXX_STANDARDS), + cm::cend(CXX_STANDARDS), cmStrCmp("11"))) { return false; } if (needCxx98 && - existingCxxIt < std::find_if(cmArrayBegin(CXX_STANDARDS), - cmArrayEnd(CXX_STANDARDS), - cmStrCmp("98"))) { + existingCxxIt < std::find_if(cm::cbegin(CXX_STANDARDS), + cm::cend(CXX_STANDARDS), cmStrCmp("98"))) { return false; } return true; @@ -4423,9 +4462,9 @@ bool cmMakefile::AddRequiredTargetCxxFeature(cmTarget* target, const char* existingCxxStandard = target->GetProperty("CXX_STANDARD"); if (existingCxxStandard) { - if (std::find_if(cmArrayBegin(CXX_STANDARDS), cmArrayEnd(CXX_STANDARDS), + if (std::find_if(cm::cbegin(CXX_STANDARDS), cm::cend(CXX_STANDARDS), cmStrCmp(existingCxxStandard)) == - cmArrayEnd(CXX_STANDARDS)) { + cm::cend(CXX_STANDARDS)) { std::ostringstream e; e << "The CXX_STANDARD property on target \"" << target->GetName() << "\" contained an invalid value: \"" << existingCxxStandard << "\"."; @@ -4439,9 +4478,9 @@ bool cmMakefile::AddRequiredTargetCxxFeature(cmTarget* target, } } const char* const* existingCxxIt = existingCxxStandard - ? std::find_if(cmArrayBegin(CXX_STANDARDS), cmArrayEnd(CXX_STANDARDS), + ? std::find_if(cm::cbegin(CXX_STANDARDS), cm::cend(CXX_STANDARDS), cmStrCmp(existingCxxStandard)) - : cmArrayEnd(CXX_STANDARDS); + : cm::cend(CXX_STANDARDS); bool setCxx98 = needCxx98 && !existingCxxStandard; bool setCxx11 = needCxx11 && !existingCxxStandard; @@ -4449,23 +4488,22 @@ bool cmMakefile::AddRequiredTargetCxxFeature(cmTarget* target, bool setCxx17 = needCxx17 && !existingCxxStandard; if (needCxx17 && existingCxxStandard && - existingCxxIt < std::find_if(cmArrayBegin(CXX_STANDARDS), - cmArrayEnd(CXX_STANDARDS), - cmStrCmp("17"))) { + existingCxxIt < std::find_if(cm::cbegin(CXX_STANDARDS), + cm::cend(CXX_STANDARDS), cmStrCmp("17"))) { setCxx17 = true; } else if (needCxx14 && existingCxxStandard && - existingCxxIt < std::find_if(cmArrayBegin(CXX_STANDARDS), - cmArrayEnd(CXX_STANDARDS), + existingCxxIt < std::find_if(cm::cbegin(CXX_STANDARDS), + cm::cend(CXX_STANDARDS), cmStrCmp("14"))) { setCxx14 = true; } else if (needCxx11 && existingCxxStandard && - existingCxxIt < std::find_if(cmArrayBegin(CXX_STANDARDS), - cmArrayEnd(CXX_STANDARDS), + existingCxxIt < std::find_if(cm::cbegin(CXX_STANDARDS), + cm::cend(CXX_STANDARDS), cmStrCmp("11"))) { setCxx11 = true; } else if (needCxx98 && existingCxxStandard && - existingCxxIt < std::find_if(cmArrayBegin(CXX_STANDARDS), - cmArrayEnd(CXX_STANDARDS), + existingCxxIt < std::find_if(cm::cbegin(CXX_STANDARDS), + cm::cend(CXX_STANDARDS), cmStrCmp("98"))) { setCxx98 = true; } @@ -4522,8 +4560,8 @@ bool cmMakefile::AddRequiredTargetCFeature(cmTarget* target, const char* existingCStandard = target->GetProperty("C_STANDARD"); if (existingCStandard) { - if (std::find_if(cmArrayBegin(C_STANDARDS), cmArrayEnd(C_STANDARDS), - cmStrCmp(existingCStandard)) == cmArrayEnd(C_STANDARDS)) { + if (std::find_if(cm::cbegin(C_STANDARDS), cm::cend(C_STANDARDS), + cmStrCmp(existingCStandard)) == cm::cend(C_STANDARDS)) { std::ostringstream e; e << "The C_STANDARD property on target \"" << target->GetName() << "\" contained an invalid value: \"" << existingCStandard << "\"."; @@ -4537,26 +4575,26 @@ bool cmMakefile::AddRequiredTargetCFeature(cmTarget* target, } } const char* const* existingCIt = existingCStandard - ? std::find_if(cmArrayBegin(C_STANDARDS), cmArrayEnd(C_STANDARDS), + ? std::find_if(cm::cbegin(C_STANDARDS), cm::cend(C_STANDARDS), cmStrCmp(existingCStandard)) - : cmArrayEnd(C_STANDARDS); + : cm::cend(C_STANDARDS); bool setC90 = needC90 && !existingCStandard; bool setC99 = needC99 && !existingCStandard; bool setC11 = needC11 && !existingCStandard; if (needC11 && existingCStandard && - existingCIt < std::find_if(cmArrayBegin(C_STANDARDS), - cmArrayEnd(C_STANDARDS), cmStrCmp("11"))) { + existingCIt < std::find_if(cm::cbegin(C_STANDARDS), + cm::cend(C_STANDARDS), cmStrCmp("11"))) { setC11 = true; } else if (needC99 && existingCStandard && - existingCIt < std::find_if(cmArrayBegin(C_STANDARDS), - cmArrayEnd(C_STANDARDS), + existingCIt < std::find_if(cm::cbegin(C_STANDARDS), + cm::cend(C_STANDARDS), cmStrCmp("99"))) { setC99 = true; } else if (needC90 && existingCStandard && - existingCIt < std::find_if(cmArrayBegin(C_STANDARDS), - cmArrayEnd(C_STANDARDS), + existingCIt < std::find_if(cm::cbegin(C_STANDARDS), + cm::cend(C_STANDARDS), cmStrCmp("90"))) { setC90 = true; } |