summaryrefslogtreecommitdiffstats
path: root/Source/cmTarget.cxx
diff options
context:
space:
mode:
authorBen Boeckel <ben.boeckel@kitware.com>2023-02-01 16:53:04 (GMT)
committerBen Boeckel <ben.boeckel@kitware.com>2023-02-02 17:43:14 (GMT)
commitb69fba7cd747c4b7a7a2887aac98a4a214fa82d1 (patch)
treeaf68a18266e5e28d28aa8c8cc089d0a8e68fe860 /Source/cmTarget.cxx
parent42575a660f3d9bd331d55b358ea781de4044aedc (diff)
downloadCMake-b69fba7cd747c4b7a7a2887aac98a4a214fa82d1.zip
CMake-b69fba7cd747c4b7a7a2887aac98a4a214fa82d1.tar.gz
CMake-b69fba7cd747c4b7a7a2887aac98a4a214fa82d1.tar.bz2
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.
Diffstat (limited to 'Source/cmTarget.cxx')
-rw-r--r--Source/cmTarget.cxx22
1 files changed, 8 insertions, 14 deletions
diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx
index 09d0b80..8b06031 100644
--- a/Source/cmTarget.cxx
+++ b/Source/cmTarget.cxx
@@ -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");