mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-11 16:32:14 -06:00
Xcode: De-duplicate -dynamiclib/-bundle flags for SHARED/MODULE libraries
Xcode automatically adds a flag matching the generated `LIBRARY_STYLE`:
* For SHARED libraries we've been duplicating `-dynamiclib` with a copy
in `CMAKE_SHARED_LIBRARY_CREATE_<LANG>_FLAGS`. Remove it for Xcode.
* For MODULE libraries we've been not duplicating `-bundle` only by accident.
Since commit 586a9427d3 (ENH: Created target property INSTALL_NAME_DIR...,
2006-02-24, v2.4.0~418) we've looked up `CMAKE_<LANG>_LINK_FLAGS`, meant
for EXECUTABLEs, instead of `CMAKE_SHARED_MODULE_CREATE_<LANG>_FLAGS`.
Switch to the latter, but remove `-bundle` for Xcode.
This commit is contained in:
@@ -2721,16 +2721,20 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt,
|
||||
case cmStateEnums::MODULE_LIBRARY: {
|
||||
buildSettings->AddAttribute("LIBRARY_STYLE",
|
||||
this->CreateString("BUNDLE"));
|
||||
// Add the flags to create a module library (bundle).
|
||||
std::string createFlags = this->LookupFlags(
|
||||
"CMAKE_SHARED_MODULE_CREATE_", llang, "_FLAGS", gtgt, "");
|
||||
if (this->GetTargetProductType(gtgt) !=
|
||||
"com.apple.product-type.app-extension"_s) {
|
||||
// Xcode passes -bundle automatically.
|
||||
cmSystemTools::ReplaceString(createFlags, "-bundle", "");
|
||||
}
|
||||
createFlags = cmTrimWhitespace(createFlags);
|
||||
if (!createFlags.empty()) {
|
||||
extraLinkOptions += ' ';
|
||||
extraLinkOptions += createFlags;
|
||||
}
|
||||
if (gtgt->IsCFBundleOnApple()) {
|
||||
// It turns out that a BUNDLE is basically the same
|
||||
// in many ways as an application bundle, as far as
|
||||
// link flags go
|
||||
std::string createFlags = this->LookupFlags(
|
||||
"CMAKE_SHARED_MODULE_CREATE_", llang, "_FLAGS", gtgt, "-bundle");
|
||||
if (!createFlags.empty()) {
|
||||
extraLinkOptions += ' ';
|
||||
extraLinkOptions += createFlags;
|
||||
}
|
||||
cmValue ext = gtgt->GetProperty("BUNDLE_EXTENSION");
|
||||
if (ext) {
|
||||
buildSettings->AddAttribute("WRAPPER_EXTENSION",
|
||||
@@ -2750,13 +2754,6 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt,
|
||||
this->CreateString("mh_bundle"));
|
||||
buildSettings->AddAttribute("GCC_DYNAMIC_NO_PIC",
|
||||
this->CreateString("NO"));
|
||||
// Add the flags to create an executable.
|
||||
std::string createFlags =
|
||||
this->LookupFlags("CMAKE_", llang, "_LINK_FLAGS", gtgt, "");
|
||||
if (!createFlags.empty()) {
|
||||
extraLinkOptions += ' ';
|
||||
extraLinkOptions += createFlags;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -2781,9 +2778,11 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt,
|
||||
this->CreateString(plist));
|
||||
} else {
|
||||
// Add the flags to create a shared library.
|
||||
std::string createFlags =
|
||||
this->LookupFlags("CMAKE_SHARED_LIBRARY_CREATE_", llang, "_FLAGS",
|
||||
gtgt, "-dynamiclib");
|
||||
std::string createFlags = this->LookupFlags(
|
||||
"CMAKE_SHARED_LIBRARY_CREATE_", llang, "_FLAGS", gtgt, "");
|
||||
// Xcode passes -dynamiclib automatically.
|
||||
cmSystemTools::ReplaceString(createFlags, "-dynamiclib", "");
|
||||
createFlags = cmTrimWhitespace(createFlags);
|
||||
if (!createFlags.empty()) {
|
||||
extraLinkOptions += ' ';
|
||||
extraLinkOptions += createFlags;
|
||||
|
||||
Reference in New Issue
Block a user