mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-21 06:10:16 +08:00
Xcode: Pass compile definitions to Swift
correct Xcode generator Swift definitions original code was defining GCC_PREPROCESSOR_DEFINITIONS which is valid only for C languages add definitions to SWIFT_ACTIVE_COMPILATION_CONDITIONS when Swift language is used in the target add test in SwiftOnly for old Xcode (<8.0), append defines to cflags so it ends up in OTHER_SWIFT_FLAGS Fixes: #23637
This commit is contained in:
@@ -2423,6 +2423,18 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt,
|
|||||||
this->AppendDefines(ppDefs, targetDefines);
|
this->AppendDefines(ppDefs, targetDefines);
|
||||||
buildSettings->AddAttribute("GCC_PREPROCESSOR_DEFINITIONS",
|
buildSettings->AddAttribute("GCC_PREPROCESSOR_DEFINITIONS",
|
||||||
ppDefs.CreateList());
|
ppDefs.CreateList());
|
||||||
|
if (languages.count("Swift")) {
|
||||||
|
if (this->XcodeVersion < 80) {
|
||||||
|
std::string defineString;
|
||||||
|
std::set<std::string> defines(targetDefines.begin(),
|
||||||
|
targetDefines.end());
|
||||||
|
this->CurrentLocalGenerator->JoinDefines(defines, defineString, "Swift");
|
||||||
|
cflags["Swift"] += " " + defineString;
|
||||||
|
} else {
|
||||||
|
buildSettings->AddAttribute("SWIFT_ACTIVE_COMPILATION_CONDITIONS",
|
||||||
|
ppDefs.CreateList());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::string extraLinkOptionsVar;
|
std::string extraLinkOptionsVar;
|
||||||
std::string extraLinkOptions;
|
std::string extraLinkOptions;
|
||||||
|
@@ -25,6 +25,7 @@ endif()
|
|||||||
set(CMAKE_Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift)
|
set(CMAKE_Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift)
|
||||||
|
|
||||||
add_executable(SwiftOnly main.swift)
|
add_executable(SwiftOnly main.swift)
|
||||||
|
target_compile_definitions(SwiftOnly PRIVATE SWIFTONLY)
|
||||||
|
|
||||||
add_library(L L.swift)
|
add_library(L L.swift)
|
||||||
|
|
||||||
|
@@ -1 +1,7 @@
|
|||||||
dump("SwiftOnly")
|
dump("SwiftOnly")
|
||||||
|
|
||||||
|
#if SWIFTONLY
|
||||||
|
dump("SWIFTONLY defined")
|
||||||
|
#else
|
||||||
|
fatalError("SWIFTONLY NOT defined")
|
||||||
|
#endif
|
||||||
|
Reference in New Issue
Block a user