Xcode: Inherit Swift flags and compilation conditions

Extend the change from commit dfaf55fbfd (Xcode: add extra
'$(inherited)' entries using InheritBuildSettingAttribute, 2021-05-03,
v3.21.0-rc1~182^2) to cover Swift flags and compilation conditions,
allowing CocoaPods and CMake to interoperate when used in the same
project.
This commit is contained in:
Ross Kilgariff
2023-01-25 19:37:08 +00:00
committed by Brad King
parent 950effe434
commit 01c1d81527
5 changed files with 35 additions and 2 deletions

View File

@@ -4536,6 +4536,9 @@ bool cmGlobalXCodeGenerator::CreateXCodeObjects(
this->InheritBuildSettingAttribute(t, "GCC_PREPROCESSOR_DEFINITIONS");
this->InheritBuildSettingAttribute(t, "OTHER_CFLAGS");
this->InheritBuildSettingAttribute(t, "OTHER_LDFLAGS");
this->InheritBuildSettingAttribute(t, "OTHER_SWIFT_FLAGS");
this->InheritBuildSettingAttribute(t,
"SWIFT_ACTIVE_COMPILATION_CONDITIONS");
}
if (this->XcodeBuildSystem == BuildSystem::One) {

View File

@@ -636,7 +636,8 @@ if(CMAKE_GENERATOR MATCHES "^Visual Studio (1[6-9]|[2-9][0-9])")
endif()
if(XCODE_VERSION)
add_RunCMake_test(XcodeProject -DXCODE_VERSION=${XCODE_VERSION})
add_RunCMake_test(XcodeProject -DXCODE_VERSION=${XCODE_VERSION}
-DCMake_TEST_Swift=${CMake_TEST_Swift})
add_RunCMake_test(XcodeProject-Embed -DXCODE_VERSION=${XCODE_VERSION})
# This test can take a very long time due to lots of combinations.

View File

@@ -7,6 +7,8 @@ endif()
set(found_inherited_GCC_PREPROCESSOR_DEFINITIONS 1)
set(found_inherited_OTHER_CFLAGS 1)
set(found_inherited_OTHER_LDFLAGS 1)
set(found_inherited_OTHER_SWIFT_FLAGS 1)
set(found_inherited_SWIFT_ACTIVE_COMPILATION_CONDITIONS 1)
file(STRINGS "${xcProjectFile}" lines)
foreach(line IN LISTS lines)
@@ -32,6 +34,20 @@ foreach(line IN LISTS lines)
endif()
endif()
if(line MATCHES [[OTHER_SWIFT_FLAGS]])
if(NOT line MATCHES [["\$\(inherited\)"]])
string(APPEND relevant_lines " ${line}\n")
set(found_inherited_OTHER_SWIFT_FLAGS 0)
endif()
endif()
if(line MATCHES [[SWIFT_ACTIVE_COMPILATION_CONDITIONS]])
if(NOT line MATCHES [["\$\(inherited\)"]])
string(APPEND relevant_lines " ${line}\n")
set(found_inherited_SWIFT_ACTIVE_COMPILATION_CONDITIONS 0)
endif()
endif()
endforeach()
if(NOT found_inherited_GCC_PREPROCESSOR_DEFINITIONS)
@@ -43,6 +59,14 @@ endif()
if(NOT found_inherited_OTHER_LDFLAGS)
string(APPEND RunCMake_TEST_FAILED "Found missing inherited value for OTHER_LDFLAGS in\n ${xcProjectFile}\n")
endif()
if(CMake_TEST_Swift)
if(NOT found_inherited_OTHER_SWIFT_FLAGS)
string(APPEND RunCMake_TEST_FAILED "Found missing inherited value for OTHER_SWIFT_FLAGS in\n ${xcProjectFile}\n")
endif()
if(NOT found_inherited_SWIFT_ACTIVE_COMPILATION_CONDITIONS)
string(APPEND RunCMake_TEST_FAILED "Found missing inherited value for SWIFT_ACTIVE_COMPILATION_CONDITIONS in\n ${xcProjectFile}\n")
endif()
endif()
if(RunCMake_TEST_FAILED)
string(APPEND RunCMake_TEST_FAILED "Relevant lines include\n${relevant_lines}")

View File

@@ -1,4 +1,9 @@
enable_language(C)
if(CMake_TEST_Swift)
enable_language(Swift)
string(APPEND CMAKE_Swift_FLAGS " -DSWIFTFLAG")
add_executable(swift_inherit_test dummy_main.swift)
endif()
add_compile_definitions(TEST_INHERITTEST)
string(APPEND CMAKE_C_FLAGS " -DTESTFLAG=\\\"TEST_INHERITTEST\\\"")

View File

@@ -13,7 +13,7 @@ run_cmake(ExplicitCMakeLists)
run_cmake(ImplicitCMakeLists)
run_cmake(InterfaceLibSources)
run_cmake_with_options(SearchPaths -DCMAKE_CONFIGURATION_TYPES=Debug)
run_cmake(InheritedParameters)
run_cmake_with_options(InheritedParameters -DCMake_TEST_Swift=${CMake_TEST_Swift})
run_cmake(XcodeFileType)
run_cmake(XcodeAttributeLocation)