diff options
author | Mikko Lehtonen <scoopr@iki.fi> | 2024-01-26 12:01:07 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2024-01-30 17:50:40 (GMT) |
commit | 77c4d2f9a213f0c6bda0fb78238d621ecbb3676d (patch) | |
tree | fa0ac15d92900532e45684a49fd69fd153606d0e /Tests/SwiftMixPCH | |
parent | 3cd2c59ecf7104d0b3d6bf5609bf96959bdcdfb0 (diff) | |
download | CMake-77c4d2f9a213f0c6bda0fb78238d621ecbb3676d.zip CMake-77c4d2f9a213f0c6bda0fb78238d621ecbb3676d.tar.gz CMake-77c4d2f9a213f0c6bda0fb78238d621ecbb3676d.tar.bz2 |
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
Diffstat (limited to 'Tests/SwiftMixPCH')
-rw-r--r-- | Tests/SwiftMixPCH/CMain.c | 9 | ||||
-rw-r--r-- | Tests/SwiftMixPCH/CMakeLists.txt | 15 | ||||
-rw-r--r-- | Tests/SwiftMixPCH/SwiftFunc.swift | 4 | ||||
-rw-r--r-- | Tests/SwiftMixPCH/pch.h | 1 |
4 files changed, 29 insertions, 0 deletions
diff --git a/Tests/SwiftMixPCH/CMain.c b/Tests/SwiftMixPCH/CMain.c new file mode 100644 index 0000000..4cd78e6 --- /dev/null +++ b/Tests/SwiftMixPCH/CMain.c @@ -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; +} diff --git a/Tests/SwiftMixPCH/CMakeLists.txt b/Tests/SwiftMixPCH/CMakeLists.txt new file mode 100644 index 0000000..d5704f1 --- /dev/null +++ b/Tests/SwiftMixPCH/CMakeLists.txt @@ -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>") diff --git a/Tests/SwiftMixPCH/SwiftFunc.swift b/Tests/SwiftMixPCH/SwiftFunc.swift new file mode 100644 index 0000000..d49c36f --- /dev/null +++ b/Tests/SwiftMixPCH/SwiftFunc.swift @@ -0,0 +1,4 @@ + +func SwiftFunc() -> Int32 { + return 0; +} diff --git a/Tests/SwiftMixPCH/pch.h b/Tests/SwiftMixPCH/pch.h new file mode 100644 index 0000000..6de0669 --- /dev/null +++ b/Tests/SwiftMixPCH/pch.h @@ -0,0 +1 @@ +#define PCH_VALUE 42 |