Skip to content

Commit 67d407f

Browse files
authored
Fix local CMake build (#5032) (#5034)
1 parent 204bdad commit 67d407f

File tree

5 files changed

+31
-7
lines changed

5 files changed

+31
-7
lines changed

Diff for: CMakeLists.txt

+14-4
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,21 @@ if(NOT SwiftFoundation_MODULE_TRIPLE)
9292
mark_as_advanced(SwiftFoundation_MODULE_TRIPLE)
9393
endif()
9494

95-
# System dependencies (fail fast if dependencies are missing)
95+
# System dependencies
96+
find_package(dispatch CONFIG)
97+
if(NOT dispatch_FOUND)
98+
if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Android")
99+
set(DISPATCH_INCLUDE_PATH "/usr/lib/swift" CACHE STRING "A path to where you can find libdispatch headers")
100+
message("-- dispatch_DIR not found, using dispatch from SDK at ${DISPATCH_INCLUDE_PATH}")
101+
list(APPEND _Foundation_common_build_flags
102+
"-I${DISPATCH_INCLUDE_PATH}"
103+
"-I${DISPATCH_INCLUDE_PATH}/Block")
104+
else()
105+
message(FATAL_ERROR "-- dispatch_DIR is required on this platform")
106+
endif()
107+
endif()
96108
find_package(LibXml2 REQUIRED)
97109
find_package(CURL REQUIRED)
98-
find_package(dispatch CONFIG REQUIRED)
99110

100111
# Common build flags (_CFURLSessionInterface, _CFXMLInterface, CoreFoundation)
101112
list(APPEND _Foundation_common_build_flags
@@ -148,8 +159,7 @@ list(APPEND _Foundation_swift_build_flags
148159

149160
if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Android")
150161
list(APPEND _Foundation_common_build_flags
151-
"-D_GNU_SOURCE"
152-
"-I/usr/lib/swift") # dispatch
162+
"-D_GNU_SOURCE")
153163
endif()
154164

155165
include(GNUInstallDirs)

Diff for: Sources/CoreFoundation/CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ target_include_directories(CoreFoundation
105105
PRIVATE
106106
internalInclude)
107107

108+
target_compile_options(CoreFoundation INTERFACE
109+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xcc -fmodule-map-file=${CMAKE_CURRENT_SOURCE_DIR}/include/module.modulemap>")
110+
108111
target_compile_options(CoreFoundation PRIVATE
109112
"SHELL:$<$<COMPILE_LANGUAGE:C>:${_Foundation_common_build_flags}>")
110113

Diff for: Sources/Foundation/CMakeLists.txt

+6-3
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,14 @@ endif()
166166

167167
set_target_properties(Foundation PROPERTIES
168168
INSTALL_RPATH "$ORIGIN"
169-
BUILD_RPATH "$<TARGET_FILE_DIR:swiftDispatch>"
170169
INSTALL_REMOVE_ENVIRONMENT_RPATH ON)
171170

172-
target_link_libraries(Foundation PUBLIC
173-
swiftDispatch)
171+
if(dispatch_FOUND)
172+
set_target_properties(Foundation PROPERTIES
173+
BUILD_RPATH "$<TARGET_FILE_DIR:swiftDispatch>")
174+
target_link_libraries(Foundation PUBLIC
175+
swiftDispatch)
176+
endif()
174177

175178
if(LINKER_SUPPORTS_BUILD_ID)
176179
target_link_options(Foundation PRIVATE "LINKER:--build-id=sha1")

Diff for: Sources/_CFURLSessionInterface/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ target_include_directories(_CFURLSessionInterface
2323

2424
target_precompile_headers(_CFURLSessionInterface PRIVATE ${CMAKE_SOURCE_DIR}/Sources/CoreFoundation/internalInclude/CoreFoundation_Prefix.h)
2525

26+
target_compile_options(_CFURLSessionInterface INTERFACE
27+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xcc -fmodule-map-file=${CMAKE_CURRENT_SOURCE_DIR}/../CoreFoundation/include/module.modulemap>"
28+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xcc -fmodule-map-file=${CMAKE_CURRENT_SOURCE_DIR}/include/module.modulemap>")
29+
2630
target_compile_options(_CFURLSessionInterface PRIVATE
2731
"SHELL:$<$<COMPILE_LANGUAGE:C>:${_Foundation_common_build_flags}>")
2832

Diff for: Sources/_CFXMLInterface/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ target_include_directories(_CFXMLInterface
2222
../CoreFoundation/internalInclude
2323
/usr/include/libxml2/)
2424

25+
target_compile_options(_CFXMLInterface INTERFACE
26+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xcc -fmodule-map-file=${CMAKE_CURRENT_SOURCE_DIR}/../CoreFoundation/include/module.modulemap>"
27+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xcc -fmodule-map-file=${CMAKE_CURRENT_SOURCE_DIR}/include/module.modulemap>")
28+
2529
target_compile_options(_CFXMLInterface PRIVATE
2630
"SHELL:$<$<COMPILE_LANGUAGE:C>:${_Foundation_common_build_flags}>")
2731

0 commit comments

Comments
 (0)