From a9a515dd6b7b96484920a3f0f1202393b91dfd2e Mon Sep 17 00:00:00 2001 From: DongHun Kwak Date: Fri, 8 Oct 2021 09:13:15 +0900 Subject: Imported Upstream version 3.11.0 --- Source/cmMakefile.cxx | 466 ++++++++++++++++++++++++++++---------------------- 1 file changed, 266 insertions(+), 200 deletions(-) (limited to 'Source/cmMakefile.cxx') diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 5643c978d..b46820822 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -7,6 +7,7 @@ #include #include #include +#include #include // IWYU pragma: keep #include #include @@ -19,7 +20,7 @@ #include "cmCustomCommand.h" #include "cmCustomCommandLines.h" #include "cmExecutionStatus.h" -#include "cmExpandedCommandArgument.h" +#include "cmExpandedCommandArgument.h" // IWYU pragma: keep #include "cmFileLockPool.h" #include "cmFunctionBlocker.h" #include "cmGeneratorExpression.h" @@ -94,8 +95,7 @@ cmMakefile::cmMakefile(cmGlobalGenerator* globalGenerator, this->AddSourceGroup("Object Files", "\\.(lo|o|obj)$"); this->ObjectLibrariesSourceGroupIndex = this->SourceGroups.size(); - this->SourceGroups.push_back( - cmSourceGroup("Object Libraries", "^MATCH_NO_SOURCES$")); + this->SourceGroups.emplace_back("Object Libraries", "^MATCH_NO_SOURCES$"); #endif } @@ -122,6 +122,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 +598,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); @@ -627,7 +663,7 @@ struct file_not_persistent bool operator()(const std::string& path) const { return !(path.find("CMakeTmp") == std::string::npos && - cmSystemTools::FileExists(path.c_str())); + cmSystemTools::FileExists(path)); } }; } @@ -718,8 +754,9 @@ void cmMakefile::AddCustomCommandToTarget( return; } + cmTarget& t = ti->second; if (objLibraryCommands == RejectObjectLibraryCommands && - ti->second.GetType() == cmStateEnums::OBJECT_LIBRARY) { + t.GetType() == cmStateEnums::OBJECT_LIBRARY) { std::ostringstream e; e << "Target \"" << target << "\" is an OBJECT library " @@ -727,7 +764,7 @@ void cmMakefile::AddCustomCommandToTarget( this->IssueMessage(cmake::FATAL_ERROR, e.str()); return; } - if (ti->second.GetType() == cmStateEnums::INTERFACE_LIBRARY) { + if (t.GetType() == cmStateEnums::INTERFACE_LIBRARY) { std::ostringstream e; e << "Target \"" << target << "\" is an INTERFACE library " @@ -754,13 +791,13 @@ void cmMakefile::AddCustomCommandToTarget( cc.SetDepfile(depfile); switch (type) { case cmTarget::PRE_BUILD: - ti->second.AddPreBuildCommand(cc); + t.AddPreBuildCommand(cc); break; case cmTarget::PRE_LINK: - ti->second.AddPreLinkCommand(cc); + t.AddPreLinkCommand(cc); break; case cmTarget::POST_BUILD: - ti->second.AddPostBuildCommand(cc); + t.AddPostBuildCommand(cc); break; } } @@ -818,7 +855,7 @@ cmSourceFile* cmMakefile::AddCustomCommandToOutput( std::string outName = gg->GenerateRuleFile(outputs[0]); // Check if the rule file already exists. - file = this->GetSource(outName); + file = this->GetSource(outName, cmSourceFileLocationKind::Known); if (file && file->GetCustomCommand() && !replace) { // The rule file already exists. if (commandLines != file->GetCustomCommand()->GetCommandLines()) { @@ -831,19 +868,22 @@ cmSourceFile* cmMakefile::AddCustomCommandToOutput( // Create a cmSourceFile for the rule file. if (!file) { - file = this->CreateSource(outName, true); + file = + this->CreateSource(outName, true, cmSourceFileLocationKind::Known); } file->SetProperty("__CMAKE_RULE", "1"); } // Always create the output sources and mark them generated. for (std::string const& o : outputs) { - if (cmSourceFile* out = this->GetOrCreateSource(o, true)) { + if (cmSourceFile* out = + this->GetOrCreateSource(o, true, cmSourceFileLocationKind::Known)) { out->SetProperty("GENERATED", "1"); } } for (std::string const& o : byproducts) { - if (cmSourceFile* out = this->GetOrCreateSource(o, true)) { + if (cmSourceFile* out = + this->GetOrCreateSource(o, true, cmSourceFileLocationKind::Known)) { out->SetProperty("GENERATED", "1"); } } @@ -930,7 +970,7 @@ void cmMakefile::AddCustomCommandOldStyle( } // Each output must get its own copy of this rule. - cmsys::RegularExpression sourceFiles("\\.(C|M|c|c\\+\\+|cc|cpp|cxx|m|mm|" + cmsys::RegularExpression sourceFiles("\\.(C|M|c|c\\+\\+|cc|cpp|cxx|cu|m|mm|" "rc|def|r|odl|idl|hpj|bat|h|h\\+\\+|" "hm|hpp|hxx|in|txx|inl)$"); for (std::string const& oi : outputs) { @@ -970,7 +1010,7 @@ void cmMakefile::AddCustomCommandOldStyle( } cmTarget* cmMakefile::AddUtilityCommand( - const std::string& utilityName, bool excludeFromAll, + const std::string& utilityName, TargetOrigin origin, bool excludeFromAll, const std::vector& depends, const char* workingDirectory, const char* command, const char* arg1, const char* arg2, const char* arg3, const char* arg4) @@ -991,28 +1031,28 @@ cmTarget* cmMakefile::AddUtilityCommand( commandLine.push_back(arg4); } cmCustomCommandLines commandLines; - commandLines.push_back(commandLine); + commandLines.push_back(std::move(commandLine)); // Call the real signature of this method. - return this->AddUtilityCommand(utilityName, excludeFromAll, workingDirectory, - depends, commandLines); + return this->AddUtilityCommand(utilityName, origin, excludeFromAll, + workingDirectory, depends, commandLines); } cmTarget* cmMakefile::AddUtilityCommand( - const std::string& utilityName, bool excludeFromAll, + const std::string& utilityName, TargetOrigin origin, bool excludeFromAll, const char* workingDirectory, const std::vector& depends, const cmCustomCommandLines& commandLines, bool escapeOldStyle, const char* comment, bool uses_terminal, bool command_expand_lists) { std::vector no_byproducts; - return this->AddUtilityCommand(utilityName, excludeFromAll, workingDirectory, - no_byproducts, depends, commandLines, - escapeOldStyle, comment, uses_terminal, - command_expand_lists); + return this->AddUtilityCommand(utilityName, origin, excludeFromAll, + workingDirectory, no_byproducts, depends, + commandLines, escapeOldStyle, comment, + uses_terminal, command_expand_lists); } cmTarget* cmMakefile::AddUtilityCommand( - const std::string& utilityName, bool excludeFromAll, + const std::string& utilityName, TargetOrigin origin, bool excludeFromAll, const char* workingDirectory, const std::vector& byproducts, const std::vector& depends, const cmCustomCommandLines& commandLines, bool escapeOldStyle, @@ -1020,6 +1060,7 @@ cmTarget* cmMakefile::AddUtilityCommand( { // Create a target instance for this utility. cmTarget* target = this->AddNewTarget(cmStateEnums::UTILITY, utilityName); + target->SetIsGeneratorProvided(origin == TargetOrigin::Generator); if (excludeFromAll) { target->SetProperty("EXCLUDE_FROM_ALL", "TRUE"); } @@ -1054,7 +1095,8 @@ cmTarget* cmMakefile::AddUtilityCommand( // Always create the byproduct sources and mark them generated. for (std::string const& byproduct : byproducts) { - if (cmSourceFile* out = this->GetOrCreateSource(byproduct, true)) { + if (cmSourceFile* out = this->GetOrCreateSource( + byproduct, true, cmSourceFileLocationKind::Known)) { out->SetProperty("GENERATED", "1"); } } @@ -1062,9 +1104,9 @@ cmTarget* cmMakefile::AddUtilityCommand( return target; } -void cmMakefile::AddDefineFlag(const char* flag) +void cmMakefile::AddDefineFlag(std::string const& flag) { - if (!flag) { + if (flag.empty()) { return; } @@ -1080,7 +1122,7 @@ void cmMakefile::AddDefineFlag(const char* flag) this->AddDefineFlag(flag, this->DefineFlags); } -void cmMakefile::AddDefineFlag(const char* flag, std::string& dflags) +void cmMakefile::AddDefineFlag(std::string const& flag, std::string& dflags) { // remove any \n\r std::string::size_type initSize = dflags.size(); @@ -1090,14 +1132,13 @@ void cmMakefile::AddDefineFlag(const char* flag, std::string& dflags) std::replace(flagStart, dflags.end(), '\r', ' '); } -void cmMakefile::RemoveDefineFlag(const char* flag) +void cmMakefile::RemoveDefineFlag(std::string const& flag) { // Check the length of the flag to remove. - std::string::size_type len = strlen(flag); - if (len < 1) { + if (flag.empty()) { return; } - + std::string::size_type const len = flag.length(); // Update the string used for the old DEFINITIONS property. this->RemoveDefineFlag(flag, len, this->DefineFlagsOrig); @@ -1110,7 +1151,8 @@ void cmMakefile::RemoveDefineFlag(const char* flag) this->RemoveDefineFlag(flag, len, this->DefineFlags); } -void cmMakefile::RemoveDefineFlag(const char* flag, std::string::size_type len, +void cmMakefile::RemoveDefineFlag(std::string const& flag, + std::string::size_type len, std::string& dflags) { // Remove all instances of the flag that are surrounded by @@ -1127,9 +1169,9 @@ void cmMakefile::RemoveDefineFlag(const char* flag, std::string::size_type len, } } -void cmMakefile::AddCompileOption(const char* option) +void cmMakefile::AddCompileOption(std::string const& option) { - this->AppendProperty("COMPILE_OPTIONS", option); + this->AppendProperty("COMPILE_OPTIONS", option.c_str()); } bool cmMakefile::ParseDefineFlag(std::string const& def, bool remove) @@ -1138,14 +1180,14 @@ bool cmMakefile::ParseDefineFlag(std::string const& def, bool remove) static cmsys::RegularExpression valid("^[-/]D[A-Za-z_][A-Za-z0-9_]*(=.*)?$"); // Make sure the definition matches. - if (!valid.find(def.c_str())) { + if (!valid.find(def)) { return false; } // Definitions with non-trivial values require a policy check. static cmsys::RegularExpression trivial( "^[-/]D[A-Za-z_][A-Za-z0-9_]*(=[A-Za-z0-9_.]+)?$"); - if (!trivial.find(def.c_str())) { + if (!trivial.find(def)) { // This definition has a non-trivial value. switch (this->GetPolicyStatus(cmPolicies::CMP0005)) { case cmPolicies::WARN: @@ -1367,9 +1409,9 @@ void cmMakefile::Configure() // make sure the CMakeFiles dir is there std::string filesDir = this->StateSnapshot.GetDirectory().GetCurrentBinary(); filesDir += cmake::GetCMakeFilesDirectory(); - cmSystemTools::MakeDirectory(filesDir.c_str()); + cmSystemTools::MakeDirectory(filesDir); - assert(cmSystemTools::FileExists(currentStart.c_str(), true)); + assert(cmSystemTools::FileExists(currentStart, true)); this->AddDefinition("CMAKE_PARENT_LIST_FILE", currentStart.c_str()); cmListFile listFile; @@ -1437,8 +1479,8 @@ void cmMakefile::Configure() if (!hasProject) { cmListFileFunction project; project.Name = "PROJECT"; - cmListFileArgument prj("Project", cmListFileArgument::Unquoted, 0); - project.Arguments.push_back(prj); + project.Arguments.emplace_back("Project", cmListFileArgument::Unquoted, + 0); listFile.Functions.insert(listFile.Functions.begin(), project); } } @@ -1530,7 +1572,7 @@ void cmMakefile::AddSubDirectory(const std::string& srcPath, newSnapshot.GetDirectory().SetCurrentSource(srcPath); newSnapshot.GetDirectory().SetCurrentBinary(binPath); - cmSystemTools::MakeDirectory(binPath.c_str()); + cmSystemTools::MakeDirectory(binPath); cmMakefile* subMf = new cmMakefile(this->GlobalGenerator, newSnapshot); this->GetGlobalGenerator()->AddMakefile(subMf); @@ -1834,7 +1876,7 @@ cmTarget* cmMakefile::AddLibrary(const std::string& lname, return target; } -cmTarget* cmMakefile::AddExecutable(const char* exeName, +cmTarget* cmMakefile::AddExecutable(const std::string& exeName, const std::vector& srcs, bool excludeFromAll) { @@ -1894,7 +1936,7 @@ cmSourceFile* cmMakefile::GetSourceFileWithOutput( { // If the queried path is not absolute we use the backward compatible // linear-time search for an output with a matching suffix. - if (!cmSystemTools::FileIsFullPath(name.c_str())) { + if (!cmSystemTools::FileIsFullPath(name)) { return this->LinearGetSourceFileWithOutput(name); } // Otherwise we use an efficient lookup map. @@ -1913,7 +1955,7 @@ cmSourceGroup* cmMakefile::GetSourceGroup( // first look for source group starting with the same as the one we want for (cmSourceGroup const& srcGroup : this->SourceGroups) { - std::string sgName = srcGroup.GetName(); + std::string const& sgName = srcGroup.GetName(); if (sgName == name[0]) { sg = const_cast(&srcGroup); break; @@ -1923,7 +1965,7 @@ cmSourceGroup* cmMakefile::GetSourceGroup( if (sg != nullptr) { // iterate through its children to find match source group for (unsigned int i = 1; i < name.size(); ++i) { - sg = sg->LookupChild(name[i].c_str()); + sg = sg->LookupChild(name[i]); if (sg == nullptr) { break; } @@ -1967,7 +2009,7 @@ void cmMakefile::AddSourceGroup(const std::vector& name, if (i == -1) { // group does not exist nor belong to any existing group // add its first component - this->SourceGroups.push_back(cmSourceGroup(name[0].c_str(), regex)); + this->SourceGroups.push_back(cmSourceGroup(name[0], regex)); sg = this->GetSourceGroup(currentName); i = 0; // last component found } @@ -1977,8 +2019,8 @@ void cmMakefile::AddSourceGroup(const std::vector& name, } // build the whole source group path for (++i; i <= lastElement; ++i) { - sg->AddChild(cmSourceGroup(name[i].c_str(), nullptr, sg->GetFullName())); - sg = sg->LookupChild(name[i].c_str()); + sg->AddChild(cmSourceGroup(name[i], nullptr, sg->GetFullName().c_str())); + sg = sg->LookupChild(name[i]); } sg->SetGroupRegex(regex); @@ -2013,7 +2055,7 @@ cmSourceGroup* cmMakefile::GetOrCreateSourceGroup(const std::string& name) * inherited ones. */ cmSourceGroup* cmMakefile::FindSourceGroup( - const char* source, std::vector& groups) const + const std::string& source, std::vector& groups) const { // First search for a group that lists the file explicitly. for (std::vector::reverse_iterator sg = groups.rbegin(); @@ -2205,25 +2247,38 @@ bool cmMakefile::PlatformIsx32() const return false; } -bool cmMakefile::PlatformIsAppleIos() const +cmMakefile::AppleSDK cmMakefile::GetAppleSDKType() const { std::string sdkRoot; sdkRoot = this->GetSafeDefinition("CMAKE_OSX_SYSROOT"); sdkRoot = cmSystemTools::LowerCase(sdkRoot); - const std::string embedded[] = { - "appletvos", "appletvsimulator", "iphoneos", - "iphonesimulator", "watchos", "watchsimulator", + struct + { + std::string name; + AppleSDK sdk; + } const sdkDatabase[]{ + { "appletvos", AppleSDK::AppleTVOS }, + { "appletvsimulator", AppleSDK::AppleTVSimulator }, + { "iphoneos", AppleSDK::IPhoneOS }, + { "iphonesimulator", AppleSDK::IPhoneSimulator }, + { "watchos", AppleSDK::WatchOS }, + { "watchsimulator", AppleSDK::WatchSimulator }, }; - for (std::string const& i : embedded) { - if (sdkRoot.find(i) == 0 || - sdkRoot.find(std::string("/") + i) != std::string::npos) { - return true; + for (auto entry : sdkDatabase) { + if (sdkRoot.find(entry.name) == 0 || + sdkRoot.find(std::string("/") + entry.name) != std::string::npos) { + return entry.sdk; } } - return false; + return AppleSDK::MacOS; +} + +bool cmMakefile::PlatformIsAppleEmbedded() const +{ + return GetAppleSDKType() != AppleSDK::MacOS; } const char* cmMakefile::GetSONameFlag(const std::string& language) const @@ -2237,7 +2292,7 @@ const char* cmMakefile::GetSONameFlag(const std::string& language) const return GetDefinition(name); } -bool cmMakefile::CanIWriteThisFile(const char* fileName) const +bool cmMakefile::CanIWriteThisFile(std::string const& fileName) const { if (!this->IsOn("CMAKE_DISABLE_SOURCE_CHANGES")) { return true; @@ -2977,7 +3032,7 @@ bool cmMakefile::ExpandArguments( for (cmListFileArgument const& i : inArgs) { // No expansion in a bracket argument. if (i.Delim == cmListFileArgument::Bracket) { - outArgs.push_back(cmExpandedCommandArgument(i.Value, true)); + outArgs.emplace_back(i.Value, true); continue; } // Expand the variables in the argument. @@ -2988,12 +3043,12 @@ bool cmMakefile::ExpandArguments( // If the argument is quoted, it should be one argument. // Otherwise, it may be a list of arguments. if (i.Delim == cmListFileArgument::Quoted) { - outArgs.push_back(cmExpandedCommandArgument(value, true)); + outArgs.emplace_back(value, true); } else { std::vector stringArgs; cmSystemTools::ExpandListArgument(value, stringArgs); for (std::string const& stringArg : stringArgs) { - outArgs.push_back(cmExpandedCommandArgument(stringArg, false)); + outArgs.emplace_back(stringArg, false); } } } @@ -3050,19 +3105,19 @@ std::unique_ptr cmMakefile::RemoveFunctionBlocker( return std::unique_ptr(); } -const char* cmMakefile::GetHomeDirectory() const +std::string const& cmMakefile::GetHomeDirectory() const { return this->GetCMakeInstance()->GetHomeDirectory(); } -const char* cmMakefile::GetHomeOutputDirectory() const +std::string const& cmMakefile::GetHomeOutputDirectory() const { return this->GetCMakeInstance()->GetHomeOutputDirectory(); } -void cmMakefile::SetScriptModeFile(const char* scriptfile) +void cmMakefile::SetScriptModeFile(std::string const& scriptfile) { - this->AddDefinition("CMAKE_SCRIPT_MODE_FILE", scriptfile); + this->AddDefinition("CMAKE_SCRIPT_MODE_FILE", scriptfile.c_str()); } void cmMakefile::SetArgcArgv(const std::vector& args) @@ -3080,35 +3135,53 @@ void cmMakefile::SetArgcArgv(const std::vector& args) } } -cmSourceFile* cmMakefile::GetSource(const std::string& sourceName) const +cmSourceFile* cmMakefile::GetSource(const std::string& sourceName, + cmSourceFileLocationKind kind) const { - cmSourceFileLocation sfl(this, sourceName); - for (cmSourceFile* sf : this->SourceFiles) { - if (sf->Matches(sfl)) { - return sf; + cmSourceFileLocation sfl(this, sourceName, kind); + auto name = this->GetCMakeInstance()->StripExtension(sfl.GetName()); +#if defined(_WIN32) || defined(__APPLE__) + name = cmSystemTools::LowerCase(name); +#endif + auto sfsi = this->SourceFileSearchIndex.find(name); + if (sfsi != this->SourceFileSearchIndex.end()) { + for (auto sf : sfsi->second) { + if (sf->Matches(sfl)) { + return sf; + } } } return nullptr; } cmSourceFile* cmMakefile::CreateSource(const std::string& sourceName, - bool generated) + bool generated, + cmSourceFileLocationKind kind) { - cmSourceFile* sf = new cmSourceFile(this, sourceName); + cmSourceFile* sf = new cmSourceFile(this, sourceName, kind); if (generated) { sf->SetProperty("GENERATED", "1"); } this->SourceFiles.push_back(sf); + + auto name = + this->GetCMakeInstance()->StripExtension(sf->GetLocation().GetName()); +#if defined(_WIN32) || defined(__APPLE__) + name = cmSystemTools::LowerCase(name); +#endif + this->SourceFileSearchIndex[name].push_back(sf); + return sf; } cmSourceFile* cmMakefile::GetOrCreateSource(const std::string& sourceName, - bool generated) + bool generated, + cmSourceFileLocationKind kind) { - if (cmSourceFile* esf = this->GetSource(sourceName)) { + if (cmSourceFile* esf = this->GetSource(sourceName, kind)) { return esf; } - return this->CreateSource(sourceName, generated); + return this->CreateSource(sourceName, generated, kind); } void cmMakefile::AddTargetObject(std::string const& tgtName, @@ -3159,7 +3232,7 @@ int cmMakefile::TryCompile(const std::string& srcdir, this->IsSourceFileTryCompile = fast; // does the binary directory exist ? If not create it... if (!cmSystemTools::FileIsDirectory(bindir)) { - cmSystemTools::MakeDirectory(bindir.c_str()); + cmSystemTools::MakeDirectory(bindir); } // change to the tests directory and run cmake @@ -3186,6 +3259,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(); @@ -3336,7 +3410,7 @@ std::string cmMakefile::GetModulesFile(const char* filename) const cmSystemTools::ConvertToUnixSlashes(itempl); itempl += "/"; itempl += filename; - if (cmSystemTools::FileExists(itempl.c_str())) { + if (cmSystemTools::FileExists(itempl)) { moduleInCMakeModulePath = itempl; break; } @@ -3348,7 +3422,7 @@ std::string cmMakefile::GetModulesFile(const char* filename) const moduleInCMakeRoot += "/Modules/"; moduleInCMakeRoot += filename; cmSystemTools::ConvertToUnixSlashes(moduleInCMakeRoot); - if (!cmSystemTools::FileExists(moduleInCMakeRoot.c_str())) { + if (!cmSystemTools::FileExists(moduleInCMakeRoot)) { moduleInCMakeRoot.clear(); } @@ -3480,11 +3554,11 @@ int cmMakefile::ConfigureFile(const char* infile, const char* outfile, this->AddCMakeOutputFile(soutfile); mode_t perm = 0; - cmSystemTools::GetPermissions(sinfile.c_str(), perm); + cmSystemTools::GetPermissions(sinfile, perm); std::string::size_type pos = soutfile.rfind('/'); if (pos != std::string::npos) { std::string path = soutfile.substr(0, pos); - cmSystemTools::MakeDirectory(path.c_str()); + cmSystemTools::MakeDirectory(path); } if (copyonly) { @@ -3544,7 +3618,7 @@ int cmMakefile::ConfigureFile(const char* infile, const char* outfile, soutfile.c_str())) { res = 0; } else { - cmSystemTools::SetPermissions(soutfile.c_str(), perm); + cmSystemTools::SetPermissions(soutfile, perm); } cmSystemTools::RemoveFile(tempOutputFile); } @@ -3616,6 +3690,16 @@ cmTest* cmMakefile::GetTest(const std::string& testName) const return nullptr; } +void cmMakefile::GetTests(const std::string& config, + std::vector& tests) +{ + for (auto generator : this->GetTestGenerators()) { + if (generator->TestsForConfig(config)) { + tests.push_back(generator->GetTest()); + } + } +} + void cmMakefile::AddCMakeDependFilesFromUser() { std::vector deps; @@ -3623,7 +3707,7 @@ void cmMakefile::AddCMakeDependFilesFromUser() cmSystemTools::ExpandListArgument(deps_str, deps); } for (std::string const& dep : deps) { - if (cmSystemTools::FileIsFullPath(dep.c_str())) { + if (cmSystemTools::FileIsFullPath(dep)) { this->AddCMakeDependFile(dep); } else { std::string f = this->GetCurrentSourceDirectory(); @@ -3980,7 +4064,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 +4217,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 +4314,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 +4335,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 +4345,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 +4373,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 +4398,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 +4420,10 @@ bool cmMakefile::HaveCxxStandardAvailable(cmTarget const* target, existingCxxStandard = defaultCxxStandard; } - if (std::find_if(cmArrayBegin(CXX_STANDARDS), cmArrayEnd(CXX_STANDARDS), - cmStrCmp(existingCxxStandard)) == - cmArrayEnd(CXX_STANDARDS)) { + const char* const* existingCxxLevel = + std::find_if(cm::cbegin(CXX_STANDARDS), cm::cend(CXX_STANDARDS), + cmStrCmp(existingCxxStandard)); + if (existingCxxLevel == cm::cend(CXX_STANDARDS)) { std::ostringstream e; e << "The CXX_STANDARD property on target \"" << target->GetName() << "\" contained an invalid value: \"" << existingCxxStandard << "\"."; @@ -4347,36 +4431,16 @@ bool cmMakefile::HaveCxxStandardAvailable(cmTarget const* target, return false; } - const char* const* existingCxxIt = existingCxxStandard - ? std::find_if(cmArrayBegin(CXX_STANDARDS), cmArrayEnd(CXX_STANDARDS), - cmStrCmp(existingCxxStandard)) - : cmArrayEnd(CXX_STANDARDS); + /* clang-format off */ + const char* const* needCxxLevel = + needCxx17 ? &CXX_STANDARDS[3] + : needCxx14 ? &CXX_STANDARDS[2] + : needCxx11 ? &CXX_STANDARDS[1] + : needCxx98 ? &CXX_STANDARDS[0] + : nullptr; + /* clang-format on */ - if (needCxx17 && - existingCxxIt < std::find_if(cmArrayBegin(CXX_STANDARDS), - cmArrayEnd(CXX_STANDARDS), - cmStrCmp("17"))) { - return false; - } - if (needCxx14 && - existingCxxIt < std::find_if(cmArrayBegin(CXX_STANDARDS), - cmArrayEnd(CXX_STANDARDS), - cmStrCmp("14"))) { - return false; - } - if (needCxx11 && - existingCxxIt < std::find_if(cmArrayBegin(CXX_STANDARDS), - cmArrayEnd(CXX_STANDARDS), - cmStrCmp("11"))) { - return false; - } - if (needCxx98 && - existingCxxIt < std::find_if(cmArrayBegin(CXX_STANDARDS), - cmArrayEnd(CXX_STANDARDS), - cmStrCmp("98"))) { - return false; - } - return true; + return !needCxxLevel || needCxxLevel <= existingCxxLevel; } void cmMakefile::CheckNeededCxxLanguage(const std::string& feature, @@ -4422,10 +4486,12 @@ bool cmMakefile::AddRequiredTargetCxxFeature(cmTarget* target, needCxx17); const char* existingCxxStandard = target->GetProperty("CXX_STANDARD"); + const char* const* existingCxxLevel = nullptr; if (existingCxxStandard) { - if (std::find_if(cmArrayBegin(CXX_STANDARDS), cmArrayEnd(CXX_STANDARDS), - cmStrCmp(existingCxxStandard)) == - cmArrayEnd(CXX_STANDARDS)) { + existingCxxLevel = + std::find_if(cm::cbegin(CXX_STANDARDS), cm::cend(CXX_STANDARDS), + cmStrCmp(existingCxxStandard)); + if (existingCxxLevel == cm::cend(CXX_STANDARDS)) { std::ostringstream e; e << "The CXX_STANDARD property on target \"" << target->GetName() << "\" contained an invalid value: \"" << existingCxxStandard << "\"."; @@ -4438,51 +4504,51 @@ bool cmMakefile::AddRequiredTargetCxxFeature(cmTarget* target, return false; } } - const char* const* existingCxxIt = existingCxxStandard - ? std::find_if(cmArrayBegin(CXX_STANDARDS), cmArrayEnd(CXX_STANDARDS), - cmStrCmp(existingCxxStandard)) - : cmArrayEnd(CXX_STANDARDS); - - bool setCxx98 = needCxx98 && !existingCxxStandard; - bool setCxx11 = needCxx11 && !existingCxxStandard; - bool setCxx14 = needCxx14 && !existingCxxStandard; - bool setCxx17 = needCxx17 && !existingCxxStandard; - - if (needCxx17 && existingCxxStandard && - existingCxxIt < std::find_if(cmArrayBegin(CXX_STANDARDS), - cmArrayEnd(CXX_STANDARDS), - cmStrCmp("17"))) { - setCxx17 = true; - } else if (needCxx14 && existingCxxStandard && - existingCxxIt < std::find_if(cmArrayBegin(CXX_STANDARDS), - cmArrayEnd(CXX_STANDARDS), - cmStrCmp("14"))) { - setCxx14 = true; - } else if (needCxx11 && existingCxxStandard && - existingCxxIt < std::find_if(cmArrayBegin(CXX_STANDARDS), - cmArrayEnd(CXX_STANDARDS), - cmStrCmp("11"))) { - setCxx11 = true; - } else if (needCxx98 && existingCxxStandard && - existingCxxIt < std::find_if(cmArrayBegin(CXX_STANDARDS), - cmArrayEnd(CXX_STANDARDS), - cmStrCmp("98"))) { - setCxx98 = true; - } - - if (setCxx17) { - target->SetProperty("CXX_STANDARD", "17"); - target->SetProperty("CUDA_STANDARD", "17"); - } else if (setCxx14) { - target->SetProperty("CXX_STANDARD", "14"); - target->SetProperty("CUDA_STANDARD", "14"); - } else if (setCxx11) { - target->SetProperty("CXX_STANDARD", "11"); - target->SetProperty("CUDA_STANDARD", "11"); - } else if (setCxx98) { - target->SetProperty("CXX_STANDARD", "98"); - target->SetProperty("CUDA_STANDARD", "98"); + + const char* existingCudaStandard = target->GetProperty("CUDA_STANDARD"); + const char* const* existingCudaLevel = nullptr; + if (existingCudaStandard) { + existingCudaLevel = + std::find_if(cm::cbegin(CXX_STANDARDS), cm::cend(CXX_STANDARDS), + cmStrCmp(existingCudaStandard)); + if (existingCudaLevel == cm::cend(CXX_STANDARDS)) { + std::ostringstream e; + e << "The CUDA_STANDARD property on target \"" << target->GetName() + << "\" contained an invalid value: \"" << existingCudaStandard + << "\"."; + if (error) { + *error = e.str(); + } else { + this->GetCMakeInstance()->IssueMessage(cmake::FATAL_ERROR, e.str(), + this->Backtrace); + } + return false; + } + } + + /* clang-format off */ + const char* const* needCxxLevel = + needCxx17 ? &CXX_STANDARDS[3] + : needCxx14 ? &CXX_STANDARDS[2] + : needCxx11 ? &CXX_STANDARDS[1] + : needCxx98 ? &CXX_STANDARDS[0] + : nullptr; + /* clang-format on */ + + if (needCxxLevel) { + // Ensure the C++ language level is high enough to support + // the needed C++ features. + if (!existingCxxLevel || existingCxxLevel < needCxxLevel) { + target->SetProperty("CXX_STANDARD", *needCxxLevel); + } + + // Ensure the CUDA language level is high enough to support + // the needed C++ features. + if (!existingCudaLevel || existingCudaLevel < needCxxLevel) { + target->SetProperty("CUDA_STANDARD", *needCxxLevel); + } } + return true; } @@ -4522,8 +4588,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 +4603,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; } -- cgit v1.2.3