Xcode: Fix PCH support with Swift & C++

Previously, when a mixed language target ends up with `Swift` as the
`LINKER_LANGUAGE`, the PCH file was not set for the target at all.

Fixes: #21224
This commit is contained in:
Mikko Lehtonen authored and Brad King committed 2024-01-30 12:50:40 -05:00
1 parent 3cd2c59ecf
commit 77c4d2f9a2
6 files changed
+32 -1

No files matched your search

+2 -1
View File
@@ -3067,7 +3067,8 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt,
}
// Precompile Headers
std::string pchHeader = gtgt->GetPchHeader(configName, llang);
std::string pchHeader =
gtgt->GetPchHeader(configName, langForPreprocessorDefinitions);
if (!pchHeader.empty()) {
buildSettings->AddAttribute("GCC_PREFIX_HEADER",
this->CreateString(pchHeader));
+1
View File
@@ -412,6 +412,7 @@ if(BUILD_TESTING)
PASS_REGULAR_EXPRESSION "CMake Error at CMakeLists.txt:3 \\(add_executable\\):[ \r\n]*Cannot find source file:[ \r\n]*DoesNotExist/MissingSourceFile.c")
if(CMake_TEST_Swift)
ADD_TEST_MACRO(SwiftOnly SwiftOnly)
ADD_TEST_MACRO(SwiftMixPCH SwiftMixPCH)
if(CMake_TEST_XCODE_SWIFT)
ADD_TEST_MACRO(SwiftMix SwiftMix)
endif()
+9
View File
@@ -0,0 +1,9 @@
#ifndef PCH_VALUE
# error "PCH_VALUE not defined"
#endif
int main(void)
{
const int value = PCH_VALUE;
return value == 42 ? 0 : 1;
}
+15
View File
@@ -0,0 +1,15 @@
cmake_minimum_required(VERSION 3.15)
if(POLICY CMP0157)
cmake_policy(SET CMP0157 NEW)
endif()
project(SwiftMixPCH C Swift)
# Swift on Windows only provides a release runtime.
set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreadedDLL)
add_executable(SwiftMixPCH CMain.c SwiftFunc.swift)
target_precompile_headers(SwiftMixPCH PRIVATE pch.h)
# We don't want swift to emit main()
target_compile_options(SwiftMixPCH PRIVATE "$<$<COMPILE_LANGUAGE:Swift>:-parse-as-library>")
+4
View File
@@ -0,0 +1,4 @@
func SwiftFunc() -> Int32 {
return 0;
}
+1
View File
@@ -0,0 +1 @@
#define PCH_VALUE 42