Merge topic 'xcode-pch-swift-cxx'

77c4d2f9a2 Xcode: Fix PCH support with Swift & C++

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !9203
This commit is contained in:
Brad King
2024-01-31 14:01:36 +00:00
committed by Kitware Robot
6 changed files with 32 additions and 1 deletions

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));

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()

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;
}

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>")

View File

@@ -0,0 +1,4 @@
func SwiftFunc() -> Int32 {
return 0;
}

1
Tests/SwiftMixPCH/pch.h Normal file
View File

@@ -0,0 +1 @@
#define PCH_VALUE 42