diff --git a/CMakeLists.txt b/CMakeLists.txt index 011b2f108e..d293164e34 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -92,10 +92,21 @@ if(NOT SwiftFoundation_MODULE_TRIPLE) mark_as_advanced(SwiftFoundation_MODULE_TRIPLE) endif() -# System dependencies (fail fast if dependencies are missing) +# System dependencies +find_package(dispatch CONFIG) +if(NOT dispatch_FOUND) + if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Android") + set(DISPATCH_INCLUDE_PATH "/usr/lib/swift" CACHE STRING "A path to where you can find libdispatch headers") + message("-- dispatch_DIR not found, using dispatch from SDK at ${DISPATCH_INCLUDE_PATH}") + list(APPEND _Foundation_common_build_flags + "-I${DISPATCH_INCLUDE_PATH}" + "-I${DISPATCH_INCLUDE_PATH}/Block") + else() + message(FATAL_ERROR "-- dispatch_DIR is required on this platform") + endif() +endif() find_package(LibXml2 REQUIRED) find_package(CURL REQUIRED) -find_package(dispatch CONFIG REQUIRED) # Common build flags (_CFURLSessionInterface, _CFXMLInterface, CoreFoundation) list(APPEND _Foundation_common_build_flags @@ -148,8 +159,7 @@ list(APPEND _Foundation_swift_build_flags if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Android") list(APPEND _Foundation_common_build_flags - "-D_GNU_SOURCE" - "-I/usr/lib/swift") # dispatch + "-D_GNU_SOURCE") endif() include(GNUInstallDirs) diff --git a/Sources/CoreFoundation/CMakeLists.txt b/Sources/CoreFoundation/CMakeLists.txt index 23586ad73d..7444abd573 100644 --- a/Sources/CoreFoundation/CMakeLists.txt +++ b/Sources/CoreFoundation/CMakeLists.txt @@ -105,6 +105,9 @@ target_include_directories(CoreFoundation PRIVATE internalInclude) +target_compile_options(CoreFoundation INTERFACE + "$<$:SHELL:-Xcc -fmodule-map-file=${CMAKE_CURRENT_SOURCE_DIR}/include/module.modulemap>") + target_compile_options(CoreFoundation PRIVATE "SHELL:$<$:${_Foundation_common_build_flags}>") diff --git a/Sources/Foundation/CMakeLists.txt b/Sources/Foundation/CMakeLists.txt index 6c5426b1f6..108dfb1c19 100644 --- a/Sources/Foundation/CMakeLists.txt +++ b/Sources/Foundation/CMakeLists.txt @@ -166,11 +166,14 @@ endif() set_target_properties(Foundation PROPERTIES INSTALL_RPATH "$ORIGIN" - BUILD_RPATH "$" INSTALL_REMOVE_ENVIRONMENT_RPATH ON) -target_link_libraries(Foundation PUBLIC - swiftDispatch) +if(dispatch_FOUND) + set_target_properties(Foundation PROPERTIES + BUILD_RPATH "$") + target_link_libraries(Foundation PUBLIC + swiftDispatch) +endif() if(LINKER_SUPPORTS_BUILD_ID) target_link_options(Foundation PRIVATE "LINKER:--build-id=sha1") diff --git a/Sources/_CFURLSessionInterface/CMakeLists.txt b/Sources/_CFURLSessionInterface/CMakeLists.txt index 47fe6a39a4..5ae7da27ff 100644 --- a/Sources/_CFURLSessionInterface/CMakeLists.txt +++ b/Sources/_CFURLSessionInterface/CMakeLists.txt @@ -23,6 +23,10 @@ target_include_directories(_CFURLSessionInterface target_precompile_headers(_CFURLSessionInterface PRIVATE ${CMAKE_SOURCE_DIR}/Sources/CoreFoundation/internalInclude/CoreFoundation_Prefix.h) +target_compile_options(_CFURLSessionInterface INTERFACE + "$<$:SHELL:-Xcc -fmodule-map-file=${CMAKE_CURRENT_SOURCE_DIR}/../CoreFoundation/include/module.modulemap>" + "$<$:SHELL:-Xcc -fmodule-map-file=${CMAKE_CURRENT_SOURCE_DIR}/include/module.modulemap>") + target_compile_options(_CFURLSessionInterface PRIVATE "SHELL:$<$:${_Foundation_common_build_flags}>") diff --git a/Sources/_CFXMLInterface/CMakeLists.txt b/Sources/_CFXMLInterface/CMakeLists.txt index 41b1f08364..d6e63a3f59 100644 --- a/Sources/_CFXMLInterface/CMakeLists.txt +++ b/Sources/_CFXMLInterface/CMakeLists.txt @@ -22,6 +22,10 @@ target_include_directories(_CFXMLInterface ../CoreFoundation/internalInclude /usr/include/libxml2/) +target_compile_options(_CFXMLInterface INTERFACE + "$<$:SHELL:-Xcc -fmodule-map-file=${CMAKE_CURRENT_SOURCE_DIR}/../CoreFoundation/include/module.modulemap>" + "$<$:SHELL:-Xcc -fmodule-map-file=${CMAKE_CURRENT_SOURCE_DIR}/include/module.modulemap>") + target_compile_options(_CFXMLInterface PRIVATE "SHELL:$<$:${_Foundation_common_build_flags}>")