Skip to content

Commit 15a0102

Browse files
committed
CMake4.0 Fixes: Only pass sdk to swift when set
CMake 4.0 does not specify CMAKE_OSX_SYSROOT unless it is set explicitly. When this is the case, passing the `-sdk` flag with an empty path confuses the compiler and results in build failures. This patch fixes things to only pass the sdk to the Swift compiler when the SDK is actually set.
1 parent 71d49a1 commit 15a0102

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

3_bidirectional_cxx_interop/cmake/modules/AddSwift.cmake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ function(_swift_generate_cxx_header target header)
3434
list(TRANSFORM ARG_SEARCH_PATHS PREPEND "-I")
3535
endif()
3636

37-
if(APPLE)
37+
if(APPLE AND CMAKE_OSX_SYSROOT)
3838
set(SDK_FLAGS "-sdk" "${CMAKE_OSX_SYSROOT}")
3939
elseif(WIN32)
4040
set(SDK_FLAGS "-sdk" "$ENV{SDKROOT}")
41-
elseif(DEFINED ${CMAKE_SYSROOT})
41+
elseif(CMAKE_SYSROOT)
4242
set(SDK_FLAGS "-sdk" "${CMAKE_SYSROOT}")
4343
endif()
4444

@@ -54,7 +54,7 @@ function(_swift_generate_cxx_header target header)
5454
DEPENDS ${_SwiftSources}
5555
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
5656
COMMAND
57-
${CMAKE_Swift_COMPILER} -frontend -typecheck
57+
${CMAKE_Swift_COMPILER} -typecheck
5858
${ARG_SEARCH_PATHS}
5959
${_SwiftSources}
6060
${SDK_FLAGS}

3_bidirectional_cxx_interop/cmake/modules/InitializeSwift.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ endfunction()
2626
function(_setup_swift_paths)
2727
# If we haven't set the swift library search paths, do that now
2828
if(NOT SWIFT_LIBRARY_SEARCH_PATHS)
29-
if(APPLE)
29+
if(CMAKE_OSX_SYSROOT)
3030
set(SDK_FLAGS "-sdk" "${CMAKE_OSX_SYSROOT}")
3131
endif()
3232

0 commit comments

Comments
 (0)