cmTarget: factor out POSITION_INDEPENDENT_CODE initialization

This property is initialized using the common framework, but then forced
on SHARED and MODULE targets, so just post-process the property in this
case.
This commit is contained in:
Ben Boeckel
2023-02-01 11:53:04 -05:00
parent 42575a660f
commit b69fba7cd7

View File

@@ -372,6 +372,8 @@ TargetProperty const StaticTargetProperties[] = {
{ "INTERPROCEDURAL_OPTIMIZATION"_s, IC::CanCompileSources },
{ "INTERPROCEDURAL_OPTIMIZATION_"_s, IC::TargetWithArtifact, R::PerConfig },
{ "NO_SYSTEM_FROM_IMPORTED"_s, IC::CanCompileSources },
// Set to `True` for `SHARED` and `MODULE` targets.
{ "POSITION_INDEPENDENT_CODE"_s, IC::CanCompileSources },
{ "VISIBILITY_INLINES_HIDDEN"_s, IC::CanCompileSources },
// -- Features
// ---- PCH
@@ -937,13 +939,6 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type,
std::string defKey;
defKey.reserve(128);
defKey += "CMAKE_";
auto initProp = [this, mf, &defKey](const std::string& property) {
// Replace everything after "CMAKE_"
defKey.replace(defKey.begin() + 6, defKey.end(), property);
if (cmValue value = mf->GetDefinition(defKey)) {
this->SetProperty(property, value);
}
};
auto initPropValue = [this, mf, &defKey](const std::string& property,
const char* default_value) {
// Replace everything after "CMAKE_"
@@ -978,13 +973,6 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type,
this->impl->Makefile->GetLinkDirectoriesEntries());
}
if (this->impl->TargetType == cmStateEnums::SHARED_LIBRARY ||
this->impl->TargetType == cmStateEnums::MODULE_LIBRARY) {
this->SetProperty("POSITION_INDEPENDENT_CODE", "True");
} else if (this->CanCompileSources()) {
initProp("POSITION_INDEPENDENT_CODE");
}
// Record current policies for later use.
this->impl->Makefile->RecordPolicies(this->impl->PolicyMap);
@@ -1088,6 +1076,12 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type,
}
}
// Clean up some property defaults.
if (this->impl->TargetType == cmStateEnums::SHARED_LIBRARY ||
this->impl->TargetType == cmStateEnums::MODULE_LIBRARY) {
this->SetProperty("POSITION_INDEPENDENT_CODE", "True");
}
// check for "CMAKE_VS_GLOBALS" variable and set up target properties
// if any
cmValue globals = mf->GetDefinition("CMAKE_VS_GLOBALS");