Commit 72edfe80 authored by Marc Chevrier's avatar Marc Chevrier
Browse files

XCode generator: Manage 'GCC_DYNAMIC_NO_PIC' attribute

parent 0d8d7a68
......@@ -497,6 +497,26 @@ const char* cmGeneratorTarget::GetFeature(const std::string& feature,
return this->LocalGenerator->GetFeature(feature, config);
}
const char* cmGeneratorTarget::GetCompilePICProperty(
const std::string& config) const
{
if (this->GetType() == cmStateEnums::OBJECT_LIBRARY) {
return this->GetProperty("POSITION_INDEPENDENT_CODE");
} else {
static std::string PICValue;
PICValue = this->GetLinkInterfaceDependentStringAsBoolProperty(
"POSITION_INDEPENDENT_CODE", config);
if (PICValue == "(unset)") {
// POSITION_INDEPENDENT_CODE is not set
return nullptr;
} else {
return PICValue.c_str();
}
}
}
const char* cmGeneratorTarget::GetLinkPIEProperty(
const std::string& config) const
{
......
......@@ -170,6 +170,7 @@ public:
const char* GetFeature(const std::string& feature,
const std::string& config) const;
const char* GetCompilePICProperty(const std::string& config) const;
const char* GetLinkPIEProperty(const std::string& config) const;
bool IsIPOEnabled(std::string const& lang, std::string const& config) const;
......
......@@ -1771,6 +1771,21 @@ void cmGlobalXCodeGenerator::CreateCustomRulesMakefile(
}
}
void cmGlobalXCodeGenerator::AddPositionIndependentCompileAttribute(
cmGeneratorTarget* target, cmXCodeObject* buildSettings,
const std::string& configName)
{
const char* PICValue = target->GetCompilePICProperty(configName);
if (PICValue == nullptr) {
// POSITION_INDEPENDENT_CODE is not set
return;
}
buildSettings->AddAttribute(
"GCC_DYNAMIC_NO_PIC",
this->CreateString(cmSystemTools::IsOn(PICValue) ? "NO" : "YES"));
}
void cmGlobalXCodeGenerator::AddPositionIndependentLinkAttribute(
cmGeneratorTarget* target, cmXCodeObject* buildSettings,
const std::string& configName)
......@@ -1827,6 +1842,10 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt,
configName);
}
// Handle PIC compiler configuration
this->AddPositionIndependentCompileAttribute(gtgt, buildSettings,
configName);
std::string llang = gtgt->GetLinkerLanguage(configName);
if (binary && llang.empty()) {
cmSystemTools::Error(
......
......@@ -171,6 +171,9 @@ private:
const std::string& configName);
cmXCodeObject* CreateUtilityTarget(cmGeneratorTarget* gtgt);
void AddDependAndLinkInformation(cmXCodeObject* target);
void AddPositionIndependentCompileAttribute(cmGeneratorTarget* target,
cmXCodeObject* buildSettings,
const std::string& configName);
void AddPositionIndependentLinkAttribute(cmGeneratorTarget* target,
cmXCodeObject* buildSettings,
const std::string& configName);
......
add_library(iface INTERFACE)
set_property(TARGET iface PROPERTY INTERFACE_POSITION_INDEPENDENT_CODE ON)
set_property(TARGET iface PROPERTY INTERFACE_POSITION_INDEPENDENT_CODE TRUE)
set(CMAKE_DEBUG_TARGET_PROPERTIES POSITION_INDEPENDENT_CODE)
add_library(foo main.cpp)
target_link_libraries(foo iface)
set_property(TARGET foo PROPERTY POSITION_INDEPENDENT_CODE ON)
set_property(TARGET foo PROPERTY POSITION_INDEPENDENT_CODE TRUE)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment