diff options
author | Ben Boeckel <ben.boeckel@kitware.com> | 2023-01-30 20:14:07 (GMT) |
---|---|---|
committer | Ben Boeckel <ben.boeckel@kitware.com> | 2023-02-02 17:43:13 (GMT) |
commit | 23bed98a2068114e322ac7e36404a153401b6218 (patch) | |
tree | 07bc074f7a09cfa2191931ac1186d61e92d7c5fa /Source/cmTarget.cxx | |
parent | 9caa9c8ace13030894abd9d20a264c99f82835ae (diff) | |
download | CMake-23bed98a2068114e322ac7e36404a153401b6218.zip CMake-23bed98a2068114e322ac7e36404a153401b6218.tar.gz CMake-23bed98a2068114e322ac7e36404a153401b6218.tar.bz2 |
cmTarget: create a `TargetProperty` structure
This structure will encapsulate when properties are initialized within a
target.
Diffstat (limited to 'Source/cmTarget.cxx')
-rw-r--r-- | Source/cmTarget.cxx | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index debf593..d04e1ac 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -273,6 +273,64 @@ struct UsageRequirementProperty std::vector<BT<std::string>> Entries; }; + +struct TargetProperty +{ + enum class InitCondition + { + // Always initialize the property. + Always, + // Never initialize the property. + Never, + }; + + enum class Repetition + { + Once, + PerConfig, + PerConfigPrefix, + }; + + TargetProperty(cm::static_string_view name) + : Name(name) + { + } + + TargetProperty(cm::static_string_view name, cm::static_string_view dflt) + : Name(name) + , Default(dflt) + { + } + + TargetProperty(cm::static_string_view name, InitCondition init) + : Name(name) + , InitConditional(init) + { + } + + TargetProperty(cm::static_string_view name, InitCondition init, + Repetition repeat) + : Name(name) + , InitConditional(init) + , Repeat(repeat) + { + } + + cm::static_string_view const Name; + cm::optional<cm::static_string_view> const Default = {}; + InitCondition const InitConditional = InitCondition::Always; + Repetition const Repeat = Repetition::Once; +}; + +#define IC TargetProperty::InitCondition +#define R TargetProperty::Repetition + +TargetProperty const StaticTargetProperties[] = {}; + +#undef COMMON_LANGUAGE_PROPERTIES +#undef IC +#undef R + } class cmTargetInternals @@ -958,6 +1016,54 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type, initProp("DOTNET_TARGET_FRAMEWORK_VERSION"); } + std::set<TargetProperty::InitCondition> metConditions; + metConditions.insert(TargetProperty::InitCondition::Always); + + std::vector<std::string> configNames = + mf->GetGeneratorConfigs(cmMakefile::ExcludeEmptyConfig); + for (auto& config : configNames) { + config = cmSystemTools::UpperCase(config); + } + + auto initProperty = [this, mf, &defKey](const std::string& property, + const char* default_value) { + // Replace everything after "CMAKE_" + defKey.replace(defKey.begin() + 6, defKey.end(), property); + if (cmValue value = mf->GetDefinition(defKey)) { + this->SetProperty(property, value); + } else if (default_value) { + this->SetProperty(property, default_value); + } + }; + + std::string dflt_storage; + for (auto const& tp : StaticTargetProperties) { + // Ignore properties that we have not met the condition for. + if (!metConditions.count(tp.InitConditional)) { + continue; + } + + const char* dflt = nullptr; + if (tp.Default) { + dflt_storage = std::string(*tp.Default); + dflt = dflt_storage.c_str(); + } + + if (tp.Repeat == TargetProperty::Repetition::Once) { + initProperty(std::string(tp.Name), dflt); + } else { + std::string propertyName; + for (auto const& configName : configNames) { + if (tp.Repeat == TargetProperty::Repetition::PerConfig) { + propertyName = cmStrCat(tp.Name, configName); + } else if (tp.Repeat == TargetProperty::Repetition::PerConfigPrefix) { + propertyName = cmStrCat(configName, tp.Name); + } + initProperty(propertyName, dflt); + } + } + } + // check for "CMAKE_VS_GLOBALS" variable and set up target properties // if any cmValue globals = mf->GetDefinition("CMAKE_VS_GLOBALS"); |