diff options
Diffstat (limited to 'Source/cmGlobalGenerator.cxx')
| -rw-r--r-- | Source/cmGlobalGenerator.cxx | 128 |
1 files changed, 65 insertions, 63 deletions
diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 9193778..97ad7ab 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -44,12 +44,12 @@ #include "cmMakefile.h" #include "cmMessageType.h" #include "cmPolicies.h" -#include "cmProperty.h" #include "cmRange.h" #include "cmSourceFile.h" #include "cmState.h" #include "cmStateDirectory.h" #include "cmStateTypes.h" +#include "cmValue.h" #include "cmVersion.h" #include "cmWorkingDirectory.h" #include "cmake.h" @@ -199,7 +199,7 @@ std::string cmGlobalGenerator::SelectMakeProgram( { std::string makeProgram = inMakeProgram; if (cmIsOff(makeProgram)) { - cmProp makeProgramCSTR = + cmValue makeProgramCSTR = this->CMakeInstance->GetCacheDefinition("CMAKE_MAKE_PROGRAM"); if (cmIsOff(makeProgramCSTR)) { makeProgram = makeDefault; @@ -235,14 +235,14 @@ void cmGlobalGenerator::ResolveLanguageCompiler(const std::string& lang, if (!optional && (path.empty() || !cmSystemTools::FileExists(path))) { return; } - cmProp cname = + cmValue cname = this->GetCMakeInstance()->GetState()->GetInitializedCacheValue(langComp); // Split compiler from arguments std::vector<std::string> cnameArgVec; if (cname && !cname->empty()) { cmExpandList(*cname, cnameArgVec); - cname = &cnameArgVec.front(); + cname = cmValue(cnameArgVec.front()); } std::string changeVars; @@ -258,7 +258,7 @@ void cmGlobalGenerator::ResolveLanguageCompiler(const std::string& lang, cmSystemTools::ConvertToUnixSlashes(cnameString); cmSystemTools::ConvertToUnixSlashes(pathString); if (cnameString != pathString) { - cmProp cvars = this->GetCMakeInstance()->GetState()->GetGlobalProperty( + cmValue cvars = this->GetCMakeInstance()->GetState()->GetGlobalProperty( "__CMAKE_DELETE_CACHE_CHANGE_VARS_"); if (cvars) { changeVars += *cvars; @@ -498,6 +498,19 @@ bool cmGlobalGenerator::CheckLanguages( void cmGlobalGenerator::EnableLanguage( std::vector<std::string> const& languages, cmMakefile* mf, bool optional) { + if (!this->IsMultiConfig() && + !this->GetCMakeInstance()->GetIsInTryCompile()) { + std::string envBuildType; + if (!mf->GetDefinition("CMAKE_BUILD_TYPE") && + cmSystemTools::GetEnv("CMAKE_BUILD_TYPE", envBuildType)) { + mf->AddCacheDefinition( + "CMAKE_BUILD_TYPE", envBuildType, + "Choose the type of build. Options include: empty, " + "Debug, Release, RelWithDebInfo, MinSizeRel.", + cmStateEnums::STRING); + } + } + if (languages.empty()) { cmSystemTools::Error("EnableLanguage must have a lang specified!"); cmSystemTools::SetFatalErrorOccured(); @@ -581,16 +594,6 @@ void cmGlobalGenerator::EnableLanguage( } } - if (readCMakeSystem) { - // Find the native build tool for this generator. - // This has to be done early so that MSBuild can be used to examine the - // cross-compilation environment. - if (this->GetFindMakeProgramStage() == FindMakeProgramStage::Early && - !this->FindMakeProgram(mf)) { - return; - } - } - // Load the CMakeDetermineSystem.cmake file and find out // what platform we are running on if (!mf->GetDefinition("CMAKE_SYSTEM")) { @@ -664,8 +667,7 @@ void cmGlobalGenerator::EnableLanguage( } // Find the native build tool for this generator. - if (this->GetFindMakeProgramStage() == FindMakeProgramStage::Late && - !this->FindMakeProgram(mf)) { + if (!this->FindMakeProgram(mf)) { return; } } @@ -789,7 +791,7 @@ void cmGlobalGenerator::EnableLanguage( std::string compilerName = cmStrCat("CMAKE_", lang, "_COMPILER"); std::string compilerEnv = cmStrCat("CMAKE_", lang, "_COMPILER_ENV_VAR"); std::ostringstream noCompiler; - cmProp compilerFile = mf->GetDefinition(compilerName); + cmValue compilerFile = mf->GetDefinition(compilerName); if (!cmNonempty(compilerFile) || cmIsNOTFOUND(*compilerFile)) { /* clang-format off */ noCompiler << @@ -826,7 +828,7 @@ void cmGlobalGenerator::EnableLanguage( cmSystemTools::RemoveFile(compilerLangFile); if (!this->CMakeInstance->GetIsInTryCompile()) { this->PrintCompilerAdvice(noCompiler, lang, - cmToCStr(mf->GetDefinition(compilerEnv))); + mf->GetDefinition(compilerEnv)); mf->IssueMessage(MessageType::FATAL_ERROR, noCompiler.str()); fatalError = true; } @@ -910,7 +912,7 @@ void cmGlobalGenerator::EnableLanguage( void cmGlobalGenerator::PrintCompilerAdvice(std::ostream& os, std::string const& lang, - const char* envVar) const + cmValue envVar) const { // Subclasses override this method if they do not support this advice. os << "Tell CMake where to find the compiler by setting "; @@ -953,6 +955,7 @@ void cmGlobalGenerator::CheckCompilerIdCompatibility( mf->IssueMessage( MessageType::FATAL_ERROR, cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0025)); + break; case cmPolicies::NEW: // NEW behavior is to keep AppleClang. break; @@ -1019,6 +1022,7 @@ void cmGlobalGenerator::CheckCompilerIdCompatibility( mf->IssueMessage( MessageType::FATAL_ERROR, cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0089)); + break; case cmPolicies::NEW: // NEW behavior is to keep AppleClang. break; @@ -1105,7 +1109,7 @@ void cmGlobalGenerator::SetLanguageEnabledMaps(const std::string& l, } std::string linkerPrefVar = "CMAKE_" + l + "_LINKER_PREFERENCE"; - cmProp linkerPref = mf->GetDefinition(linkerPrefVar); + cmValue linkerPref = mf->GetDefinition(linkerPrefVar); int preference = 0; if (cmNonempty(linkerPref)) { if (sscanf(linkerPref->c_str(), "%d", &preference) != 1) { @@ -1131,7 +1135,7 @@ void cmGlobalGenerator::SetLanguageEnabledMaps(const std::string& l, this->LanguageToLinkerPreference[l] = preference; std::string outputExtensionVar = "CMAKE_" + l + "_OUTPUT_EXTENSION"; - if (cmProp p = mf->GetDefinition(outputExtensionVar)) { + if (cmValue p = mf->GetDefinition(outputExtensionVar)) { std::string outputExtension = *p; this->LanguageToOutputExtension[l] = outputExtension; this->OutputExtensions[outputExtension] = outputExtension; @@ -1167,10 +1171,10 @@ void cmGlobalGenerator::FillExtensionToLanguageMap(const std::string& l, } } -const char* cmGlobalGenerator::GetGlobalSetting(std::string const& name) const +cmValue cmGlobalGenerator::GetGlobalSetting(std::string const& name) const { assert(!this->Makefiles.empty()); - return cmToCStr(this->Makefiles[0]->GetDefinition(name)); + return this->Makefiles[0]->GetDefinition(name); } bool cmGlobalGenerator::GlobalSettingIsOn(std::string const& name) const @@ -1183,7 +1187,7 @@ std::string cmGlobalGenerator::GetSafeGlobalSetting( std::string const& name) const { assert(!this->Makefiles.empty()); - return this->Makefiles[0]->GetSafeDefinition(name); + return this->Makefiles[0]->GetDefinition(name); } bool cmGlobalGenerator::IgnoreFile(const char* ext) const @@ -1251,10 +1255,8 @@ void cmGlobalGenerator::Configure() this->CreateDefaultGlobalTargets(globalTargets); for (const auto& mf : this->Makefiles) { - auto& targets = mf->GetTargets(); for (GlobalTargetInfo const& globalTarget : globalTargets) { - targets.emplace(globalTarget.Name, - this->CreateGlobalTarget(globalTarget, mf.get())); + this->CreateGlobalTarget(globalTarget, mf.get()); } } } @@ -1401,6 +1403,9 @@ bool cmGlobalGenerator::Compute() this->SupportsDefaultConfigs())) { return false; } + if (!this->InspectConfigTypeVariables()) { + return false; + } // Some generators track files replaced during the Generate. // Start with an empty vector: @@ -1708,10 +1713,8 @@ void cmGlobalGenerator::FinalizeTargetCompileInfo() // Construct per-target generator information. for (const auto& mf : this->Makefiles) { - const cmStringRange noconfig_compile_definitions = + const cmBTStringRange noconfig_compile_definitions = mf->GetCompileDefinitionsEntries(); - const cmBacktraceRange noconfig_compile_definitions_bts = - mf->GetCompileDefinitionsBacktraces(); for (auto& target : mf->GetTargets()) { cmTarget* t = &target.second; @@ -1725,12 +1728,8 @@ void cmGlobalGenerator::FinalizeTargetCompileInfo() continue; } - { - auto btIt = noconfig_compile_definitions_bts.begin(); - auto it = noconfig_compile_definitions.begin(); - for (; it != noconfig_compile_definitions.end(); ++it, ++btIt) { - t->InsertCompileDefinition(*it, *btIt); - } + for (auto const& def : noconfig_compile_definitions) { + t->InsertCompileDefinition(def); } cmPolicies::PolicyStatus polSt = @@ -1742,7 +1741,7 @@ void cmGlobalGenerator::FinalizeTargetCompileInfo() for (std::string const& c : configs) { std::string defPropName = cmStrCat("COMPILE_DEFINITIONS_", cmSystemTools::UpperCase(c)); - if (cmProp val = mf->GetProperty(defPropName)) { + if (cmValue val = mf->GetProperty(defPropName)) { t->AppendProperty(defPropName, *val); } } @@ -1771,9 +1770,8 @@ void cmGlobalGenerator::CreateGeneratorTargets( std::map<cmTarget*, cmGeneratorTarget*> const& importedMap) { if (targetTypes == AllTargets) { - for (auto& target : mf->GetTargets()) { - cmTarget* t = &target.second; - lg->AddGeneratorTarget(cm::make_unique<cmGeneratorTarget>(t, lg)); + for (cmTarget* target : mf->GetOrderedTargets()) { + lg->AddGeneratorTarget(cm::make_unique<cmGeneratorTarget>(target, lg)); } } @@ -1857,7 +1855,7 @@ void cmGlobalGenerator::CheckTargetProperties() } } std::vector<std::string> incs; - cmProp incDirProp = target.second.GetProperty("INCLUDE_DIRECTORIES"); + cmValue incDirProp = target.second.GetProperty("INCLUDE_DIRECTORIES"); if (!incDirProp) { continue; } @@ -2121,7 +2119,7 @@ void cmGlobalGenerator::AddMakefile(std::unique_ptr<cmMakefile> mf) // update progress // estimate how many lg there will be - cmProp numGenC = this->CMakeInstance->GetState()->GetInitializedCacheValue( + cmValue numGenC = this->CMakeInstance->GetState()->GetInitializedCacheValue( "CMAKE_NUMBER_OF_MAKEFILES"); if (!numGenC) { @@ -2180,11 +2178,10 @@ void cmGlobalGenerator::EnableLanguagesFromGenerator(cmGlobalGenerator* gen, { this->SetConfiguredFilesPath(gen); this->TryCompileOuterMakefile = mf; - cmProp make = + cmValue make = gen->GetCMakeInstance()->GetCacheDefinition("CMAKE_MAKE_PROGRAM"); - this->GetCMakeInstance()->AddCacheEntry("CMAKE_MAKE_PROGRAM", cmToCStr(make), - "make program", - cmStateEnums::FILEPATH); + this->GetCMakeInstance()->AddCacheEntry( + "CMAKE_MAKE_PROGRAM", make, "make program", cmStateEnums::FILEPATH); // copy the enabled languages this->GetCMakeInstance()->GetState()->SetEnabledLanguages( gen->GetCMakeInstance()->GetState()->GetEnabledLanguages()); @@ -2244,7 +2241,7 @@ bool cmGlobalGenerator::IsExcluded(cmLocalGenerator* root, } cmMakefile* mf = root->GetMakefile(); const std::string EXCLUDE_FROM_ALL = "EXCLUDE_FROM_ALL"; - if (cmProp exclude = target->GetProperty(EXCLUDE_FROM_ALL)) { + if (cmValue exclude = target->GetProperty(EXCLUDE_FROM_ALL)) { // Expand the property value per configuration. unsigned int trueCount = 0; unsigned int falseCount = 0; @@ -2538,7 +2535,7 @@ void cmGlobalGenerator::AddGlobalTarget_Package( if (this->GetPreinstallTargetName()) { gti.Depends.emplace_back(this->GetPreinstallTargetName()); } else { - cmProp noPackageAll = + cmValue noPackageAll = mf->GetDefinition("CMAKE_SKIP_PACKAGE_ALL_DEPENDENCY"); if (cmIsOff(noPackageAll)) { gti.Depends.emplace_back(this->GetAllTargetName()); @@ -2719,7 +2716,7 @@ void cmGlobalGenerator::AddGlobalTarget_Install( if (this->GetPreinstallTargetName()) { gti.Depends.emplace_back(this->GetPreinstallTargetName()); } else { - cmProp noall = mf->GetDefinition("CMAKE_SKIP_INSTALL_ALL_DEPENDENCY"); + cmValue noall = mf->GetDefinition("CMAKE_SKIP_INSTALL_ALL_DEPENDENCY"); if (cmIsOff(noall)) { gti.Depends.emplace_back(this->GetAllTargetName()); } @@ -2740,7 +2737,7 @@ void cmGlobalGenerator::AddGlobalTarget_Install( singleLine.push_back(cfgArg); cfgArg = "-DEFFECTIVE_PLATFORM_NAME=$(EFFECTIVE_PLATFORM_NAME)"; } else { - cfgArg += cmToCStr(mf->GetDefinition("CMAKE_CFG_INTDIR")); + cfgArg += *mf->GetDefinition("CMAKE_CFG_INTDIR"); } singleLine.push_back(cfgArg); } @@ -2785,7 +2782,7 @@ void cmGlobalGenerator::AddGlobalTarget_Install( std::string cmGlobalGenerator::GetPredefinedTargetsFolder() const { - cmProp prop = this->GetCMakeInstance()->GetState()->GetGlobalProperty( + cmValue prop = this->GetCMakeInstance()->GetState()->GetGlobalProperty( "PREDEFINED_TARGETS_FOLDER"); if (prop) { @@ -2797,7 +2794,7 @@ std::string cmGlobalGenerator::GetPredefinedTargetsFolder() const bool cmGlobalGenerator::UseFolderProperty() const { - cmProp prop = + cmValue prop = this->GetCMakeInstance()->GetState()->GetGlobalProperty("USE_FOLDERS"); // If this property is defined, let the setter turn this on or off... @@ -2812,12 +2809,19 @@ bool cmGlobalGenerator::UseFolderProperty() const return false; } -cmTarget cmGlobalGenerator::CreateGlobalTarget(GlobalTargetInfo const& gti, - cmMakefile* mf) +void cmGlobalGenerator::CreateGlobalTarget(GlobalTargetInfo const& gti, + cmMakefile* mf) { // Package - cmTarget target(gti.Name, cmStateEnums::GLOBAL_TARGET, - cmTarget::VisibilityNormal, mf, gti.PerConfig); + auto tb = + mf->CreateNewTarget(gti.Name, cmStateEnums::GLOBAL_TARGET, gti.PerConfig); + + // Do nothing if gti.Name is already used + if (!tb.second) { + return; + } + + cmTarget& target = tb.first; target.SetProperty("EXCLUDE_FROM_ALL", "TRUE"); std::vector<std::string> no_outputs; @@ -2841,8 +2845,6 @@ cmTarget cmGlobalGenerator::CreateGlobalTarget(GlobalTargetInfo const& gti, if (this->UseFolderProperty()) { target.SetProperty("FOLDER", this->GetPredefinedTargetsFolder()); } - - return target; } std::string cmGlobalGenerator::GenerateRuleFile( @@ -3143,10 +3145,10 @@ void cmGlobalGenerator::WriteSummary(cmGeneratorTarget* target) #ifndef CMAKE_BOOTSTRAP // Check whether labels are enabled for this target. - cmProp targetLabels = target->GetProperty("LABELS"); - cmProp directoryLabels = + cmValue targetLabels = target->GetProperty("LABELS"); + cmValue directoryLabels = target->Target->GetMakefile()->GetProperty("LABELS"); - cmProp cmakeDirectoryLabels = + cmValue cmakeDirectoryLabels = target->Target->GetMakefile()->GetDefinition("CMAKE_DIRECTORY_LABELS"); if (targetLabels || directoryLabels || cmakeDirectoryLabels) { Json::Value lj_root(Json::objectValue); @@ -3214,7 +3216,7 @@ void cmGlobalGenerator::WriteSummary(cmGeneratorTarget* target) std::string const& sfp = sf->ResolveFullPath(); fout << sfp << "\n"; lj_source["file"] = sfp; - if (cmProp svalue = sf->GetProperty("LABELS")) { + if (cmValue svalue = sf->GetProperty("LABELS")) { labels.clear(); Json::Value& lj_source_labels = lj_source["labels"] = Json::arrayValue; cmExpandList(*svalue, labels); |
