ENH: Simplify Xcode CreateBuildSettings method
The cmGlobalXCodeGenerator::CreateBuildSettings had the three arguments productName, productType, and fileType that returned information used by only one of the call sites. This change refactors that information into separate methods named accordingly.
This commit is contained in:
parent
f952ead857
commit
6bd9d5ab8a
@ -1375,9 +1375,6 @@ void cmGlobalXCodeGenerator
|
|||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
|
void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
|
||||||
cmXCodeObject* buildSettings,
|
cmXCodeObject* buildSettings,
|
||||||
std::string& fileType,
|
|
||||||
std::string& productType,
|
|
||||||
std::string& productName,
|
|
||||||
const char* configName)
|
const char* configName)
|
||||||
{
|
{
|
||||||
std::string flags;
|
std::string flags;
|
||||||
@ -1457,9 +1454,6 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
|
|||||||
extraLinkOptions += targetLinkFlags;
|
extraLinkOptions += targetLinkFlags;
|
||||||
}
|
}
|
||||||
|
|
||||||
// The product name is the full name of the target for this configuration.
|
|
||||||
productName = target.GetFullName(configName);
|
|
||||||
|
|
||||||
// Get the product name components.
|
// Get the product name components.
|
||||||
std::string pnprefix;
|
std::string pnprefix;
|
||||||
std::string pnbase;
|
std::string pnbase;
|
||||||
@ -1490,9 +1484,6 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
|
|||||||
{
|
{
|
||||||
case cmTarget::STATIC_LIBRARY:
|
case cmTarget::STATIC_LIBRARY:
|
||||||
{
|
{
|
||||||
fileType = "archive.ar";
|
|
||||||
productType = "com.apple.product-type.library.static";
|
|
||||||
|
|
||||||
buildSettings->AddAttribute("LIBRARY_STYLE",
|
buildSettings->AddAttribute("LIBRARY_STYLE",
|
||||||
this->CreateString("STATIC"));
|
this->CreateString("STATIC"));
|
||||||
break;
|
break;
|
||||||
@ -1504,9 +1495,6 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
|
|||||||
this->CreateString("BUNDLE"));
|
this->CreateString("BUNDLE"));
|
||||||
if(this->XcodeVersion >= 22)
|
if(this->XcodeVersion >= 22)
|
||||||
{
|
{
|
||||||
fileType = "compiled.mach-o.executable";
|
|
||||||
productType = "com.apple.product-type.tool";
|
|
||||||
|
|
||||||
buildSettings->AddAttribute("MACH_O_TYPE",
|
buildSettings->AddAttribute("MACH_O_TYPE",
|
||||||
this->CreateString("mh_bundle"));
|
this->CreateString("mh_bundle"));
|
||||||
buildSettings->AddAttribute("GCC_DYNAMIC_NO_PIC",
|
buildSettings->AddAttribute("GCC_DYNAMIC_NO_PIC",
|
||||||
@ -1522,9 +1510,6 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fileType = "compiled.mach-o.dylib";
|
|
||||||
productType = "com.apple.product-type.library.dynamic";
|
|
||||||
|
|
||||||
// Add the flags to create a module.
|
// Add the flags to create a module.
|
||||||
std::string createFlags =
|
std::string createFlags =
|
||||||
this->LookupFlags("CMAKE_SHARED_MODULE_CREATE_", lang, "_FLAGS",
|
this->LookupFlags("CMAKE_SHARED_MODULE_CREATE_", lang, "_FLAGS",
|
||||||
@ -1541,9 +1526,6 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
|
|||||||
{
|
{
|
||||||
if(target.GetPropertyAsBool("FRAMEWORK"))
|
if(target.GetPropertyAsBool("FRAMEWORK"))
|
||||||
{
|
{
|
||||||
fileType = "wrapper.framework";
|
|
||||||
productType = "com.apple.product-type.framework";
|
|
||||||
|
|
||||||
std::string version = target.GetFrameworkVersion();
|
std::string version = target.GetFrameworkVersion();
|
||||||
buildSettings->AddAttribute("FRAMEWORK_VERSION",
|
buildSettings->AddAttribute("FRAMEWORK_VERSION",
|
||||||
this->CreateString(version.c_str()));
|
this->CreateString(version.c_str()));
|
||||||
@ -1562,9 +1544,6 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fileType = "compiled.mach-o.dylib";
|
|
||||||
productType = "com.apple.product-type.library.dynamic";
|
|
||||||
|
|
||||||
// Add the flags to create a shared library.
|
// Add the flags to create a shared library.
|
||||||
std::string createFlags =
|
std::string createFlags =
|
||||||
this->LookupFlags("CMAKE_SHARED_LIBRARY_CREATE_", lang, "_FLAGS",
|
this->LookupFlags("CMAKE_SHARED_LIBRARY_CREATE_", lang, "_FLAGS",
|
||||||
@ -1582,8 +1561,6 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
|
|||||||
}
|
}
|
||||||
case cmTarget::EXECUTABLE:
|
case cmTarget::EXECUTABLE:
|
||||||
{
|
{
|
||||||
fileType = "compiled.mach-o.executable";
|
|
||||||
|
|
||||||
// Add the flags to create an executable.
|
// Add the flags to create an executable.
|
||||||
std::string createFlags =
|
std::string createFlags =
|
||||||
this->LookupFlags("CMAKE_", lang, "_LINK_FLAGS", "");
|
this->LookupFlags("CMAKE_", lang, "_LINK_FLAGS", "");
|
||||||
@ -1596,7 +1573,6 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
|
|||||||
// Handle bundles and normal executables separately.
|
// Handle bundles and normal executables separately.
|
||||||
if(target.GetPropertyAsBool("MACOSX_BUNDLE"))
|
if(target.GetPropertyAsBool("MACOSX_BUNDLE"))
|
||||||
{
|
{
|
||||||
productType = "com.apple.product-type.application";
|
|
||||||
std::string plist = this->ComputeInfoPListLocation(target);
|
std::string plist = this->ComputeInfoPListLocation(target);
|
||||||
// Xcode will create the final version of Info.plist at build time,
|
// Xcode will create the final version of Info.plist at build time,
|
||||||
// so let it replace the executable name. This avoids creating
|
// so let it replace the executable name. This avoids creating
|
||||||
@ -1610,10 +1586,6 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
|
|||||||
this->CreateString(path.c_str()));
|
this->CreateString(path.c_str()));
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
productType = "com.apple.product-type.tool";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -1754,7 +1726,7 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
|
|||||||
// is not given or is empty. We must explicitly put the flag in the
|
// is not given or is empty. We must explicitly put the flag in the
|
||||||
// link flags to create an install_name with just the library soname.
|
// link flags to create an install_name with just the library soname.
|
||||||
extraLinkOptions += " -install_name ";
|
extraLinkOptions += " -install_name ";
|
||||||
extraLinkOptions += productName;
|
extraLinkOptions += target.GetFullName(configName);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -1869,9 +1841,6 @@ cmGlobalXCodeGenerator::CreateUtilityTarget(cmTarget& cmtarget)
|
|||||||
target->AddAttribute("buildPhases", buildPhases);
|
target->AddAttribute("buildPhases", buildPhases);
|
||||||
cmXCodeObject* buildSettings =
|
cmXCodeObject* buildSettings =
|
||||||
this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
|
this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
|
||||||
std::string fileTypeString;
|
|
||||||
std::string productTypeString;
|
|
||||||
std::string productName;
|
|
||||||
const char* globalConfig = 0;
|
const char* globalConfig = 0;
|
||||||
if(this->XcodeVersion > 20)
|
if(this->XcodeVersion > 20)
|
||||||
{
|
{
|
||||||
@ -1881,9 +1850,7 @@ cmGlobalXCodeGenerator::CreateUtilityTarget(cmTarget& cmtarget)
|
|||||||
{
|
{
|
||||||
globalConfig = this->CurrentMakefile->GetDefinition("CMAKE_BUILD_TYPE");
|
globalConfig = this->CurrentMakefile->GetDefinition("CMAKE_BUILD_TYPE");
|
||||||
}
|
}
|
||||||
this->CreateBuildSettings(cmtarget,
|
this->CreateBuildSettings(cmtarget, buildSettings, globalConfig);
|
||||||
buildSettings, fileTypeString,
|
|
||||||
productTypeString, productName, globalConfig);
|
|
||||||
target->AddAttribute("buildSettings", buildSettings);
|
target->AddAttribute("buildSettings", buildSettings);
|
||||||
cmXCodeObject* dependencies =
|
cmXCodeObject* dependencies =
|
||||||
this->CreateObject(cmXCodeObject::OBJECT_LIST);
|
this->CreateObject(cmXCodeObject::OBJECT_LIST);
|
||||||
@ -1939,12 +1906,7 @@ void cmGlobalXCodeGenerator::AddConfigurations(cmXCodeObject* target,
|
|||||||
buildConfigurations->AddObject(config);
|
buildConfigurations->AddObject(config);
|
||||||
cmXCodeObject* buildSettings =
|
cmXCodeObject* buildSettings =
|
||||||
this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
|
this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
|
||||||
std::string fileTypeString;
|
this->CreateBuildSettings(cmtarget, buildSettings,
|
||||||
std::string productTypeString;
|
|
||||||
std::string productName;
|
|
||||||
this->CreateBuildSettings(cmtarget,
|
|
||||||
buildSettings, fileTypeString,
|
|
||||||
productTypeString, productName,
|
|
||||||
configVector[i].c_str());
|
configVector[i].c_str());
|
||||||
config->AddAttribute("name", this->CreateString(configVector[i].c_str()));
|
config->AddAttribute("name", this->CreateString(configVector[i].c_str()));
|
||||||
config->SetComment(configVector[i].c_str());
|
config->SetComment(configVector[i].c_str());
|
||||||
@ -1959,6 +1921,49 @@ void cmGlobalXCodeGenerator::AddConfigurations(cmXCodeObject* target,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
const char* cmGlobalXCodeGenerator::GetTargetFileType(cmTarget& cmtarget)
|
||||||
|
{
|
||||||
|
switch(cmtarget.GetType())
|
||||||
|
{
|
||||||
|
case cmTarget::STATIC_LIBRARY:
|
||||||
|
return "archive.ar";
|
||||||
|
case cmTarget::MODULE_LIBRARY:
|
||||||
|
return ((this->XcodeVersion >= 22)?
|
||||||
|
"compiled.mach-o.executable" : "compiled.mach-o.dylib");
|
||||||
|
case cmTarget::SHARED_LIBRARY:
|
||||||
|
return (cmtarget.GetPropertyAsBool("FRAMEWORK")?
|
||||||
|
"wrapper.framework" : "compiled.mach-o.dylib");
|
||||||
|
case cmTarget::EXECUTABLE:
|
||||||
|
return "compiled.mach-o.executable";
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
const char* cmGlobalXCodeGenerator::GetTargetProductType(cmTarget& cmtarget)
|
||||||
|
{
|
||||||
|
switch(cmtarget.GetType())
|
||||||
|
{
|
||||||
|
case cmTarget::STATIC_LIBRARY:
|
||||||
|
return "com.apple.product-type.library.static";
|
||||||
|
case cmTarget::MODULE_LIBRARY:
|
||||||
|
return ((this->XcodeVersion >= 22)? "com.apple.product-type.tool" :
|
||||||
|
"com.apple.product-type.library.dynamic");
|
||||||
|
case cmTarget::SHARED_LIBRARY:
|
||||||
|
return (cmtarget.GetPropertyAsBool("FRAMEWORK")?
|
||||||
|
"com.apple.product-type.framework" :
|
||||||
|
"com.apple.product-type.library.dynamic");
|
||||||
|
case cmTarget::EXECUTABLE:
|
||||||
|
return (cmtarget.GetPropertyAsBool("MACOSX_BUNDLE")?
|
||||||
|
"com.apple.product-type.application" :
|
||||||
|
"com.apple.product-type.tool");
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
cmXCodeObject*
|
cmXCodeObject*
|
||||||
cmGlobalXCodeGenerator::CreateXCodeTarget(cmTarget& cmtarget,
|
cmGlobalXCodeGenerator::CreateXCodeTarget(cmTarget& cmtarget,
|
||||||
@ -1971,9 +1976,6 @@ cmGlobalXCodeGenerator::CreateXCodeTarget(cmTarget& cmtarget,
|
|||||||
target->AddAttribute("buildRules", buildRules);
|
target->AddAttribute("buildRules", buildRules);
|
||||||
cmXCodeObject* buildSettings =
|
cmXCodeObject* buildSettings =
|
||||||
this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
|
this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
|
||||||
std::string fileTypeString;
|
|
||||||
std::string productTypeString;
|
|
||||||
std::string productName;
|
|
||||||
const char* globalConfig = 0;
|
const char* globalConfig = 0;
|
||||||
if(this->XcodeVersion > 20)
|
if(this->XcodeVersion > 20)
|
||||||
{
|
{
|
||||||
@ -1983,9 +1985,7 @@ cmGlobalXCodeGenerator::CreateXCodeTarget(cmTarget& cmtarget,
|
|||||||
{
|
{
|
||||||
globalConfig = this->CurrentMakefile->GetDefinition("CMAKE_BUILD_TYPE");
|
globalConfig = this->CurrentMakefile->GetDefinition("CMAKE_BUILD_TYPE");
|
||||||
}
|
}
|
||||||
this->CreateBuildSettings(cmtarget,
|
this->CreateBuildSettings(cmtarget, buildSettings, globalConfig);
|
||||||
buildSettings, fileTypeString,
|
|
||||||
productTypeString, productName, globalConfig);
|
|
||||||
target->AddAttribute("buildSettings", buildSettings);
|
target->AddAttribute("buildSettings", buildSettings);
|
||||||
cmXCodeObject* dependencies =
|
cmXCodeObject* dependencies =
|
||||||
this->CreateObject(cmXCodeObject::OBJECT_LIST);
|
this->CreateObject(cmXCodeObject::OBJECT_LIST);
|
||||||
@ -1995,17 +1995,22 @@ cmGlobalXCodeGenerator::CreateXCodeTarget(cmTarget& cmtarget,
|
|||||||
|
|
||||||
cmXCodeObject* fileRef =
|
cmXCodeObject* fileRef =
|
||||||
this->CreateObject(cmXCodeObject::PBXFileReference);
|
this->CreateObject(cmXCodeObject::PBXFileReference);
|
||||||
fileRef->AddAttribute("explicitFileType",
|
if(const char* fileType = this->GetTargetFileType(cmtarget))
|
||||||
this->CreateString(fileTypeString.c_str()));
|
{
|
||||||
fileRef->AddAttribute("path", this->CreateString(productName.c_str()));
|
fileRef->AddAttribute("explicitFileType", this->CreateString(fileType));
|
||||||
|
}
|
||||||
|
std::string fullName = cmtarget.GetFullName(globalConfig);
|
||||||
|
fileRef->AddAttribute("path", this->CreateString(fullName.c_str()));
|
||||||
fileRef->AddAttribute("refType", this->CreateString("0"));
|
fileRef->AddAttribute("refType", this->CreateString("0"));
|
||||||
fileRef->AddAttribute("sourceTree",
|
fileRef->AddAttribute("sourceTree",
|
||||||
this->CreateString("BUILT_PRODUCTS_DIR"));
|
this->CreateString("BUILT_PRODUCTS_DIR"));
|
||||||
fileRef->SetComment(cmtarget.GetName());
|
fileRef->SetComment(cmtarget.GetName());
|
||||||
target->AddAttribute("productReference",
|
target->AddAttribute("productReference",
|
||||||
this->CreateObjectReference(fileRef));
|
this->CreateObjectReference(fileRef));
|
||||||
target->AddAttribute("productType",
|
if(const char* productType = this->GetTargetProductType(cmtarget))
|
||||||
this->CreateString(productTypeString.c_str()));
|
{
|
||||||
|
target->AddAttribute("productType", this->CreateString(productType));
|
||||||
|
}
|
||||||
target->SetTarget(&cmtarget);
|
target->SetTarget(&cmtarget);
|
||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
|
@ -128,6 +128,8 @@ private:
|
|||||||
cmXCodeObject* CreateObjectReference(cmXCodeObject*);
|
cmXCodeObject* CreateObjectReference(cmXCodeObject*);
|
||||||
cmXCodeObject* CreateXCodeTarget(cmTarget& target,
|
cmXCodeObject* CreateXCodeTarget(cmTarget& target,
|
||||||
cmXCodeObject* buildPhases);
|
cmXCodeObject* buildPhases);
|
||||||
|
const char* GetTargetFileType(cmTarget& cmtarget);
|
||||||
|
const char* GetTargetProductType(cmTarget& cmtarget);
|
||||||
void AddConfigurations(cmXCodeObject* target,
|
void AddConfigurations(cmXCodeObject* target,
|
||||||
cmTarget& cmtarget);
|
cmTarget& cmtarget);
|
||||||
void AppendOrAddBuildSetting(cmXCodeObject* settings, const char* attr,
|
void AppendOrAddBuildSetting(cmXCodeObject* settings, const char* attr,
|
||||||
@ -138,9 +140,6 @@ private:
|
|||||||
void AddDependAndLinkInformation(cmXCodeObject* target);
|
void AddDependAndLinkInformation(cmXCodeObject* target);
|
||||||
void CreateBuildSettings(cmTarget& target,
|
void CreateBuildSettings(cmTarget& target,
|
||||||
cmXCodeObject* buildSettings,
|
cmXCodeObject* buildSettings,
|
||||||
std::string& fileType,
|
|
||||||
std::string& productType,
|
|
||||||
std::string& projectName,
|
|
||||||
const char* buildType);
|
const char* buildType);
|
||||||
std::string ExtractFlag(const char* flag, std::string& flags);
|
std::string ExtractFlag(const char* flag, std::string& flags);
|
||||||
// delete all objects in the this->XCodeObjects vector.
|
// delete all objects in the this->XCodeObjects vector.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user