summaryrefslogtreecommitdiffstats
path: root/Modules/Internal
diff options
context:
space:
mode:
authorEvan Wilde <etceterawilde@gmail.com>2022-10-14 17:18:52 (GMT)
committerBrad King <brad.king@kitware.com>2022-10-24 16:39:21 (GMT)
commit3fc971c38b3aba4d2b216d31a1e6ced9cda2bf4a (patch)
tree4440d5ec5ce39db1a37014ecc7c65b38f34e24f2 /Modules/Internal
parent2345139ab5b93cea4cf331af8d840ed5f943dbeb (diff)
downloadCMake-3fc971c38b3aba4d2b216d31a1e6ced9cda2bf4a.zip
CMake-3fc971c38b3aba4d2b216d31a1e6ced9cda2bf4a.tar.gz
CMake-3fc971c38b3aba4d2b216d31a1e6ced9cda2bf4a.tar.bz2
CheckSourceCompiles: For Swift executable, name source 'main.swift'
Xcode uses its own heuristics to determine whether or not to accept top-level code in a source file while Ninja uses the swift driver heuristics. With the Swift driver, if the module contains a single file, that file will be parsed as a top-level code context. With Xcode, the single file will only be parsed as top-level code if the name of that file is 'main.swift'. To ensure more consistent behavior between the two generators, if we're building Swift and the try-compile target type is executable or undefined, we name the file `main.swift` to ensure that both will handle the single file as top-level code.
Diffstat (limited to 'Modules/Internal')
-rw-r--r--Modules/Internal/CheckSourceCompiles.cmake8
1 files changed, 6 insertions, 2 deletions
diff --git a/Modules/Internal/CheckSourceCompiles.cmake b/Modules/Internal/CheckSourceCompiles.cmake
index 2d43a76..bf5a82d 100644
--- a/Modules/Internal/CheckSourceCompiles.cmake
+++ b/Modules/Internal/CheckSourceCompiles.cmake
@@ -9,7 +9,7 @@ cmake_policy(SET CMP0057 NEW) # if() supports IN_LIST
function(CMAKE_CHECK_SOURCE_COMPILES _lang _source _var)
if(NOT DEFINED "${_var}")
-
+ set(_lang_filename "src")
if(_lang STREQUAL "C")
set(_lang_textual "C")
set(_lang_ext "c")
@@ -37,6 +37,10 @@ function(CMAKE_CHECK_SOURCE_COMPILES _lang _source _var)
elseif(_lang STREQUAL "Swift")
set(_lang_textual "Swift")
set(_lang_ext "swift")
+ if (NOT DEFINED CMAKE_TRY_COMPILE_TARGET_TYPE
+ OR CMAKE_TRY_COMPILE_TARGET_TYPE STREQUAL "EXECUTABLE")
+ set(_lang_filename "main")
+ endif()
else()
message (SEND_ERROR "check_source_compiles: ${_lang}: unknown language.")
return()
@@ -95,7 +99,7 @@ function(CMAKE_CHECK_SOURCE_COMPILES _lang _source _var)
endif()
string(APPEND _source "\n")
try_compile(${_var}
- SOURCE_FROM_VAR "src.${_SRC_EXT}" _source
+ SOURCE_FROM_VAR "${_lang_filename}.${_SRC_EXT}" _source
COMPILE_DEFINITIONS -D${_var} ${CMAKE_REQUIRED_DEFINITIONS}
${CHECK_${LANG}_SOURCE_COMPILES_ADD_LINK_OPTIONS}
${CHECK_${LANG}_SOURCE_COMPILES_ADD_LIBRARIES}