cmIsOn: add overload accepting const std::string*

This commit is contained in:
Vitaly Stakhovsky
2020-07-13 21:00:00 -04:00
parent 2da778664d
commit 7156911242
23 changed files with 60 additions and 88 deletions
+1 -4
View File
@@ -578,10 +578,7 @@ cmProp cmCacheManager::CacheEntry::GetProperty(const std::string& prop) const
bool cmCacheManager::CacheEntry::GetPropertyAsBool( bool cmCacheManager::CacheEntry::GetPropertyAsBool(
const std::string& prop) const const std::string& prop) const
{ {
if (cmProp value = this->GetProperty(prop)) { return cmIsOn(this->GetProperty(prop));
return cmIsOn(*value);
}
return false;
} }
void cmCacheManager::CacheEntry::SetProperty(const std::string& prop, void cmCacheManager::CacheEntry::SetProperty(const std::string& prop,
+2 -2
View File
@@ -515,7 +515,7 @@ bool cmComputeLinkInformation::Compute()
// Restore the target link type so the correct system runtime // Restore the target link type so the correct system runtime
// libraries are found. // libraries are found.
cmProp lss = this->Target->GetProperty("LINK_SEARCH_END_STATIC"); cmProp lss = this->Target->GetProperty("LINK_SEARCH_END_STATIC");
if (lss && cmIsOn(*lss)) { if (cmIsOn(lss)) {
this->SetCurrentLinkType(LinkStatic); this->SetCurrentLinkType(LinkStatic);
} else { } else {
this->SetCurrentLinkType(this->StartLinkType); this->SetCurrentLinkType(this->StartLinkType);
@@ -841,7 +841,7 @@ void cmComputeLinkInformation::ComputeLinkTypeInfo()
// Lookup the starting link type from the target (linked statically?). // Lookup the starting link type from the target (linked statically?).
cmProp lss = this->Target->GetProperty("LINK_SEARCH_START_STATIC"); cmProp lss = this->Target->GetProperty("LINK_SEARCH_START_STATIC");
this->StartLinkType = (lss && cmIsOn(*lss)) ? LinkStatic : LinkShared; this->StartLinkType = cmIsOn(lss) ? LinkStatic : LinkShared;
this->CurrentLinkType = this->StartLinkType; this->CurrentLinkType = this->StartLinkType;
} }
+4 -6
View File
@@ -236,9 +236,8 @@ void cmExtraCodeBlocksGenerator::CreateNewProjectFile(
// //
// Also we can disable external (outside the project) files by setting ON // Also we can disable external (outside the project) files by setting ON
// CMAKE_CODEBLOCKS_EXCLUDE_EXTERNAL_FILES variable. // CMAKE_CODEBLOCKS_EXCLUDE_EXTERNAL_FILES variable.
const bool excludeExternal = const bool excludeExternal = it.second[0]->GetMakefile()->IsOn(
cmIsOn(it.second[0]->GetMakefile()->GetSafeDefinition( "CMAKE_CODEBLOCKS_EXCLUDE_EXTERNAL_FILES");
"CMAKE_CODEBLOCKS_EXCLUDE_EXTERNAL_FILES"));
if (!splitted.empty() && if (!splitted.empty() &&
(!excludeExternal || (relative.find("..") == std::string::npos)) && (!excludeExternal || (relative.find("..") == std::string::npos)) &&
relative.find("CMakeFiles") == std::string::npos) { relative.find("CMakeFiles") == std::string::npos) {
@@ -380,9 +379,8 @@ void cmExtraCodeBlocksGenerator::CreateNewProjectFile(
cmSystemTools::RelativePath(lg->GetSourceDirectory(), fullPath); cmSystemTools::RelativePath(lg->GetSourceDirectory(), fullPath);
// Do not add this file if it has ".." in relative path and // Do not add this file if it has ".." in relative path and
// if CMAKE_CODEBLOCKS_EXCLUDE_EXTERNAL_FILES variable is on. // if CMAKE_CODEBLOCKS_EXCLUDE_EXTERNAL_FILES variable is on.
const bool excludeExternal = const bool excludeExternal = lg->GetMakefile()->IsOn(
cmIsOn(lg->GetMakefile()->GetSafeDefinition( "CMAKE_CODEBLOCKS_EXCLUDE_EXTERNAL_FILES");
"CMAKE_CODEBLOCKS_EXCLUDE_EXTERNAL_FILES"));
if (excludeExternal && if (excludeExternal &&
(relative.find("..") != std::string::npos)) { (relative.find("..") != std::string::npos)) {
continue; continue;
+3 -3
View File
@@ -1166,9 +1166,9 @@ void cmFindPackageCommand::AppendSuccessInformation()
std::string found = cmStrCat(this->Name, "_FOUND"); std::string found = cmStrCat(this->Name, "_FOUND");
std::string upperFound = cmSystemTools::UpperCase(found); std::string upperFound = cmSystemTools::UpperCase(found);
const char* upperResult = this->Makefile->GetDefinition(upperFound); bool upperResult = this->Makefile->IsOn(upperFound);
const char* result = this->Makefile->GetDefinition(found); bool result = this->Makefile->IsOn(found);
bool packageFound = ((cmIsOn(result)) || (cmIsOn(upperResult))); bool packageFound = (result || upperResult);
this->AppendToFoundProperty(packageFound); this->AppendToFoundProperty(packageFound);
+2 -3
View File
@@ -854,9 +854,8 @@ bool cmGeneratorTarget::IsIPOEnabled(std::string const& lang,
std::string const& config) const std::string const& config) const
{ {
cmProp feature = this->GetFeature("INTERPROCEDURAL_OPTIMIZATION", config); cmProp feature = this->GetFeature("INTERPROCEDURAL_OPTIMIZATION", config);
const bool result = feature && cmIsOn(*feature);
if (!result) { if (!cmIsOn(feature)) {
// 'INTERPROCEDURAL_OPTIMIZATION' is off, no need to check policies // 'INTERPROCEDURAL_OPTIMIZATION' is off, no need to check policies
return false; return false;
} }
@@ -1001,7 +1000,7 @@ bool cmGeneratorTarget::GetLanguageStandardRequired(
{ {
cmProp p = cmProp p =
this->GetPropertyWithPairedLanguageSupport(lang, "_STANDARD_REQUIRED"); this->GetPropertyWithPairedLanguageSupport(lang, "_STANDARD_REQUIRED");
return p && cmIsOn(*p); return cmIsOn(p);
} }
void cmGeneratorTarget::GetModuleDefinitionSources( void cmGeneratorTarget::GetModuleDefinitionSources(
+3 -3
View File
@@ -550,9 +550,9 @@ void cmGhsMultiTargetGenerator::WriteSources(std::ostream& fout_proj)
*/ */
for (auto& sg : groupFilesList) { for (auto& sg : groupFilesList) {
std::ostream* fout; std::ostream* fout;
bool useProjectFile = cmIsOn(*this->GeneratorTarget->GetProperty( bool useProjectFile =
"GHS_NO_SOURCE_GROUP_FILE")) || cmIsOn(this->GeneratorTarget->GetProperty("GHS_NO_SOURCE_GROUP_FILE")) ||
cmIsOn(this->Makefile->GetDefinition("CMAKE_GHS_NO_SOURCE_GROUP_FILE")); this->Makefile->IsOn("CMAKE_GHS_NO_SOURCE_GROUP_FILE");
if (useProjectFile || sg.empty()) { if (useProjectFile || sg.empty()) {
fout = &fout_proj; fout = &fout_proj;
} else { } else {
+4 -12
View File
@@ -304,14 +304,10 @@ bool cmGlobalGenerator::CheckTargetsForMissingSources() const
for (const auto& target : localGen->GetGeneratorTargets()) { for (const auto& target : localGen->GetGeneratorTargets()) {
if (target->GetType() == cmStateEnums::TargetType::GLOBAL_TARGET || if (target->GetType() == cmStateEnums::TargetType::GLOBAL_TARGET ||
target->GetType() == cmStateEnums::TargetType::INTERFACE_LIBRARY || target->GetType() == cmStateEnums::TargetType::INTERFACE_LIBRARY ||
target->GetType() == cmStateEnums::TargetType::UTILITY) { target->GetType() == cmStateEnums::TargetType::UTILITY ||
cmIsOn(target->GetProperty("ghs_integrity_app"))) {
continue; continue;
} }
if (cmProp p = target->GetProperty("ghs_integrity_app")) {
if (cmIsOn(*p)) {
continue;
}
}
std::vector<std::string> configs = std::vector<std::string> configs =
target->Makefile->GetGeneratorConfigs(cmMakefile::IncludeEmptyConfig); target->Makefile->GetGeneratorConfigs(cmMakefile::IncludeEmptyConfig);
@@ -374,14 +370,10 @@ bool cmGlobalGenerator::CheckTargetsForPchCompilePdb() const
for (const auto& target : generator->GetGeneratorTargets()) { for (const auto& target : generator->GetGeneratorTargets()) {
if (target->GetType() == cmStateEnums::TargetType::GLOBAL_TARGET || if (target->GetType() == cmStateEnums::TargetType::GLOBAL_TARGET ||
target->GetType() == cmStateEnums::TargetType::INTERFACE_LIBRARY || target->GetType() == cmStateEnums::TargetType::INTERFACE_LIBRARY ||
target->GetType() == cmStateEnums::TargetType::UTILITY) { target->GetType() == cmStateEnums::TargetType::UTILITY ||
cmIsOn(target->GetProperty("ghs_integrity_app"))) {
continue; continue;
} }
if (cmProp p = target->GetProperty("ghs_integrity_app")) {
if (cmIsOn(*p)) {
continue;
}
}
std::string const& reuseFrom = std::string const& reuseFrom =
target->GetSafeProperty("PRECOMPILE_HEADERS_REUSE_FROM"); target->GetSafeProperty("PRECOMPILE_HEADERS_REUSE_FROM");
+1 -2
View File
@@ -470,8 +470,7 @@ void cmGlobalGhsMultiGenerator::WriteAllTarget(
if (t->GetType() == cmStateEnums::INTERFACE_LIBRARY) { if (t->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
continue; continue;
} }
cmProp p = t->GetProperty("EXCLUDE_FROM_ALL"); if (!cmIsOn(t->GetProperty("EXCLUDE_FROM_ALL"))) {
if (!(p && cmIsOn(*p))) {
defaultTargets.push_back(t); defaultTargets.push_back(t);
} }
} }
+1 -2
View File
@@ -694,8 +694,7 @@ std::set<std::string> cmGlobalVisualStudio7Generator::IsPartOfDefaultBuild(
} }
// inspect EXCLUDE_FROM_DEFAULT_BUILD[_<CONFIG>] properties // inspect EXCLUDE_FROM_DEFAULT_BUILD[_<CONFIG>] properties
for (std::string const& i : configs) { for (std::string const& i : configs) {
cmProp propertyValue = target->GetFeature("EXCLUDE_FROM_DEFAULT_BUILD", i); if (cmIsOff(target->GetFeature("EXCLUDE_FROM_DEFAULT_BUILD", i))) {
if (!propertyValue || cmIsOff(*propertyValue)) {
activeConfigs.insert(i); activeConfigs.insert(i);
} }
} }
+11 -14
View File
@@ -191,21 +191,18 @@ bool requireDeviceLinking(cmGeneratorTarget& target, cmLocalGenerator& lg,
target.GetLinkClosure(config); target.GetLinkClosure(config);
if (cm::contains(closure->Languages, "CUDA")) { if (cm::contains(closure->Languages, "CUDA")) {
if (cmProp separableCompilation = if (cmIsOn(target.GetProperty("CUDA_SEPARABLE_COMPILATION"))) {
target.GetProperty("CUDA_SEPARABLE_COMPILATION")) { bool doDeviceLinking = false;
if (cmIsOn(*separableCompilation)) { switch (target.GetType()) {
bool doDeviceLinking = false; case cmStateEnums::SHARED_LIBRARY:
switch (target.GetType()) { case cmStateEnums::MODULE_LIBRARY:
case cmStateEnums::SHARED_LIBRARY: case cmStateEnums::EXECUTABLE:
case cmStateEnums::MODULE_LIBRARY: doDeviceLinking = true;
case cmStateEnums::EXECUTABLE: break;
doDeviceLinking = true; default:
break; break;
default:
break;
}
return doDeviceLinking;
} }
return doDeviceLinking;
} }
cmComputeLinkInformation* pcli = target.GetLinkInformation(config); cmComputeLinkInformation* pcli = target.GetLinkInformation(config);
+3 -4
View File
@@ -130,7 +130,7 @@ cmLocalGenerator::cmLocalGenerator(cmGlobalGenerator* gg, cmMakefile* makefile)
this->LinkerSysroot = this->Makefile->GetSafeDefinition("CMAKE_SYSROOT"); this->LinkerSysroot = this->Makefile->GetSafeDefinition("CMAKE_SYSROOT");
} }
if (std::string const* appleArchSysroots = if (cmProp appleArchSysroots =
this->Makefile->GetDef("CMAKE_APPLE_ARCH_SYSROOTS")) { this->Makefile->GetDef("CMAKE_APPLE_ARCH_SYSROOTS")) {
std::string const& appleArchs = std::string const& appleArchs =
this->Makefile->GetSafeDefinition("CMAKE_OSX_ARCHITECTURES"); this->Makefile->GetSafeDefinition("CMAKE_OSX_ARCHITECTURES");
@@ -1543,9 +1543,8 @@ void cmLocalGenerator::GetTargetFlags(
frameworkPath, linkPath); frameworkPath, linkPath);
} }
if (cmIsOn(this->Makefile->GetDefinition("BUILD_SHARED_LIBS"))) { if (this->Makefile->IsOn("BUILD_SHARED_LIBS")) {
std::string sFlagVar = std::string("CMAKE_SHARED_BUILD_") + std::string sFlagVar = "CMAKE_SHARED_BUILD_" + linkLanguage + "_FLAGS";
linkLanguage + std::string("_FLAGS");
exeFlags += this->Makefile->GetSafeDefinition(sFlagVar); exeFlags += this->Makefile->GetSafeDefinition(sFlagVar);
exeFlags += " "; exeFlags += " ";
} }
+2 -4
View File
@@ -2521,8 +2521,7 @@ void cmMakefile::ExpandVariablesCMP0019()
bool cmMakefile::IsOn(const std::string& name) const bool cmMakefile::IsOn(const std::string& name) const
{ {
const char* value = this->GetDefinition(name); return cmIsOn(this->GetDef(name));
return cmIsOn(value);
} }
bool cmMakefile::IsSet(const std::string& name) const bool cmMakefile::IsSet(const std::string& name) const
@@ -4116,8 +4115,7 @@ cmProp cmMakefile::GetProperty(const std::string& prop, bool chain) const
bool cmMakefile::GetPropertyAsBool(const std::string& prop) const bool cmMakefile::GetPropertyAsBool(const std::string& prop) const
{ {
cmProp p = this->GetProperty(prop); return cmIsOn(this->GetProperty(prop));
return p && cmIsOn(*p);
} }
std::vector<std::string> cmMakefile::GetPropertyKeys() const std::vector<std::string> cmMakefile::GetPropertyKeys() const
+1 -2
View File
@@ -197,8 +197,7 @@ void cmMakefileTargetGenerator::WriteTargetBuildRules()
} }
// add custom commands to the clean rules? // add custom commands to the clean rules?
cmProp clean_no_custom = this->Makefile->GetProperty("CLEAN_NO_CUSTOM"); bool clean = cmIsOff(this->Makefile->GetProperty("CLEAN_NO_CUSTOM"));
bool clean = clean_no_custom ? cmIsOff(*clean_no_custom) : true;
// First generate the object rule files. Save a list of all object // First generate the object rule files. Save a list of all object
// files for this target. // files for this target.
+2 -2
View File
@@ -50,7 +50,7 @@ cmQtAutoGenGlobalInitializer::cmQtAutoGenGlobalInitializer(
{ {
cmMakefile* makefile = localGen->GetMakefile(); cmMakefile* makefile = localGen->GetMakefile();
// Detect global autogen target name // Detect global autogen target name
if (cmIsOn(makefile->GetSafeDefinition("CMAKE_GLOBAL_AUTOGEN_TARGET"))) { if (makefile->IsOn("CMAKE_GLOBAL_AUTOGEN_TARGET")) {
std::string targetName = std::string targetName =
makefile->GetSafeDefinition("CMAKE_GLOBAL_AUTOGEN_TARGET_NAME"); makefile->GetSafeDefinition("CMAKE_GLOBAL_AUTOGEN_TARGET_NAME");
if (targetName.empty()) { if (targetName.empty()) {
@@ -61,7 +61,7 @@ cmQtAutoGenGlobalInitializer::cmQtAutoGenGlobalInitializer(
} }
// Detect global autorcc target name // Detect global autorcc target name
if (cmIsOn(makefile->GetSafeDefinition("CMAKE_GLOBAL_AUTORCC_TARGET"))) { if (makefile->IsOn("CMAKE_GLOBAL_AUTORCC_TARGET")) {
std::string targetName = std::string targetName =
makefile->GetSafeDefinition("CMAKE_GLOBAL_AUTORCC_TARGET_NAME"); makefile->GetSafeDefinition("CMAKE_GLOBAL_AUTORCC_TARGET_NAME");
if (targetName.empty()) { if (targetName.empty()) {
+1 -1
View File
@@ -489,7 +489,7 @@ bool cmQtAutoGenInitializer::InitCustomTargets()
if (this->Moc.Enabled) { if (this->Moc.Enabled) {
// Path prefix // Path prefix
if (cmIsOn(this->GenTarget->GetSafeProperty("AUTOMOC_PATH_PREFIX"))) { if (cmIsOn(this->GenTarget->GetProperty("AUTOMOC_PATH_PREFIX"))) {
this->Moc.PathPrefix = true; this->Moc.PathPrefix = true;
} }
+1 -2
View File
@@ -380,8 +380,7 @@ const char* cmSourceFile::GetSafeProperty(const std::string& prop) const
bool cmSourceFile::GetPropertyAsBool(const std::string& prop) const bool cmSourceFile::GetPropertyAsBool(const std::string& prop) const
{ {
cmProp p = this->GetProperty(prop); return cmIsOn(this->GetProperty(prop));
return p && cmIsOn(*p);
} }
void cmSourceFile::SetProperties(cmPropertyMap properties) void cmSourceFile::SetProperties(cmPropertyMap properties)
+1 -2
View File
@@ -623,8 +623,7 @@ cmProp cmState::GetGlobalProperty(const std::string& prop)
bool cmState::GetGlobalPropertyAsBool(const std::string& prop) bool cmState::GetGlobalPropertyAsBool(const std::string& prop)
{ {
cmProp p = this->GetGlobalProperty(prop); return cmIsOn(this->GetGlobalProperty(prop));
return p && cmIsOn(*p);
} }
void cmState::SetSourceDirectory(std::string const& sourceDirectory) void cmState::SetSourceDirectory(std::string const& sourceDirectory)
+1 -2
View File
@@ -648,8 +648,7 @@ cmProp cmStateDirectory::GetProperty(const std::string& prop, bool chain) const
bool cmStateDirectory::GetPropertyAsBool(const std::string& prop) const bool cmStateDirectory::GetPropertyAsBool(const std::string& prop) const
{ {
cmProp p = this->GetProperty(prop); return cmIsOn(this->GetProperty(prop));
return p && cmIsOn(*p);
} }
std::vector<std::string> cmStateDirectory::GetPropertyKeys() const std::vector<std::string> cmStateDirectory::GetPropertyKeys() const
+1 -1
View File
@@ -323,7 +323,7 @@ void cmStateSnapshot::SetDefaultDefinitions()
#if defined(__CYGWIN__) #if defined(__CYGWIN__)
std::string legacy; std::string legacy;
if (cmSystemTools::GetEnv("CMAKE_LEGACY_CYGWIN_WIN32", legacy) && if (cmSystemTools::GetEnv("CMAKE_LEGACY_CYGWIN_WIN32", legacy) &&
cmIsOn(legacy.c_str())) { cmIsOn(legacy)) {
this->SetDefinition("WIN32", "1"); this->SetDefinition("WIN32", "1");
this->SetDefinition("CMAKE_HOST_WIN32", "1"); this->SetDefinition("CMAKE_HOST_WIN32", "1");
} }
+10 -8
View File
@@ -205,10 +205,11 @@ bool cmIsNOTFOUND(cm::string_view val);
bool cmIsOn(cm::string_view val); bool cmIsOn(cm::string_view val);
inline bool cmIsOn(const char* val) inline bool cmIsOn(const char* val)
{ {
if (!val) { return val && cmIsOn(cm::string_view(val));
return false; }
} inline bool cmIsOn(std::string const* val)
return cmIsOn(cm::string_view(val)); {
return val && cmIsOn(*val);
} }
/** /**
@@ -221,10 +222,11 @@ inline bool cmIsOn(const char* val)
bool cmIsOff(cm::string_view val); bool cmIsOff(cm::string_view val);
inline bool cmIsOff(const char* val) inline bool cmIsOff(const char* val)
{ {
if (!val) { return !val || cmIsOff(cm::string_view(val));
return true; }
} inline bool cmIsOff(std::string const* val)
return cmIsOff(cm::string_view(val)); {
return !val || cmIsOff(*val);
} }
/** Returns true if string @a str starts with the character @a prefix. */ /** Returns true if string @a str starts with the character @a prefix. */
+1 -2
View File
@@ -1884,8 +1884,7 @@ std::string const& cmTarget::GetSafeProperty(std::string const& prop) const
bool cmTarget::GetPropertyAsBool(const std::string& prop) const bool cmTarget::GetPropertyAsBool(const std::string& prop) const
{ {
cmProp p = this->GetProperty(prop); return cmIsOn(this->GetProperty(prop));
return p && cmIsOn(*p);
} }
cmPropertyMap const& cmTarget::GetProperties() const cmPropertyMap const& cmTarget::GetProperties() const
+1 -2
View File
@@ -324,8 +324,7 @@ bool cmXCodeScheme::WriteLaunchActionBooleanAttribute(
bool defaultValue) bool defaultValue)
{ {
cmProp property = Target->GetTarget()->GetProperty(varName); cmProp property = Target->GetTarget()->GetProperty(varName);
bool isOn = bool isOn = (property == nullptr && defaultValue) || cmIsOn(property);
(property == nullptr && defaultValue) || (property && cmIsOn(*property));
if (isOn) { if (isOn) {
xout.Attribute(attrName.c_str(), "YES"); xout.Attribute(attrName.c_str(), "YES");
+3 -5
View File
@@ -1487,10 +1487,10 @@ int cmake::Configure()
this->Messenger->SetSuppressDeprecatedWarnings(value && cmIsOff(*value)); this->Messenger->SetSuppressDeprecatedWarnings(value && cmIsOff(*value));
value = this->State->GetCacheEntryValue("CMAKE_ERROR_DEPRECATED"); value = this->State->GetCacheEntryValue("CMAKE_ERROR_DEPRECATED");
this->Messenger->SetDeprecatedWarningsAsErrors(value && cmIsOn(*value)); this->Messenger->SetDeprecatedWarningsAsErrors(cmIsOn(value));
value = this->State->GetCacheEntryValue("CMAKE_SUPPRESS_DEVELOPER_WARNINGS"); value = this->State->GetCacheEntryValue("CMAKE_SUPPRESS_DEVELOPER_WARNINGS");
this->Messenger->SetSuppressDevWarnings(value && cmIsOn(*value)); this->Messenger->SetSuppressDevWarnings(cmIsOn(value));
value = this->State->GetCacheEntryValue("CMAKE_SUPPRESS_DEVELOPER_ERRORS"); value = this->State->GetCacheEntryValue("CMAKE_SUPPRESS_DEVELOPER_ERRORS");
this->Messenger->SetDevWarningsAsErrors(value && cmIsOff(*value)); this->Messenger->SetDevWarningsAsErrors(value && cmIsOff(*value));
@@ -2742,9 +2742,7 @@ int cmake::Build(int jobs, const std::string& dir,
} }
projName = *cachedProjectName; projName = *cachedProjectName;
cmProp cachedVerbose = if (cmIsOn(this->State->GetCacheEntryValue("CMAKE_VERBOSE_MAKEFILE"))) {
this->State->GetCacheEntryValue("CMAKE_VERBOSE_MAKEFILE");
if (cachedVerbose && cmIsOn(*cachedVerbose)) {
verbose = true; verbose = true;
} }