diff --git a/CMakeLists.txt b/CMakeLists.txt index d8e19d9429..9717dda61c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,6 +42,8 @@ option(NS_CURL_ASSUME_FEATURES_MISSING "Assume that optional libcurl features ar find_package(dispatch CONFIG REQUIRED) +find_package(ICU COMPONENTS uc i18n REQUIRED) + include(SwiftSupport) include(GNUInstallDirs) include(XCTest) diff --git a/CoreFoundation/CMakeLists.txt b/CoreFoundation/CMakeLists.txt index 62569e27db..63b4330269 100644 --- a/CoreFoundation/CMakeLists.txt +++ b/CoreFoundation/CMakeLists.txt @@ -32,7 +32,6 @@ if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin) else() find_package(CURL REQUIRED) endif() - find_package(ICU COMPONENTS uc i18n REQUIRED) endif() include(GNUInstallDirs) diff --git a/Sources/Foundation/CMakeLists.txt b/Sources/Foundation/CMakeLists.txt index 016bf2946f..f7a4458ba8 100644 --- a/Sources/Foundation/CMakeLists.txt +++ b/Sources/Foundation/CMakeLists.txt @@ -160,6 +160,30 @@ set_target_properties(Foundation PROPERTIES Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_BINARY_DIR}/swift) +if(NOT BUILD_SHARED_LIBS) + # ICU_I18N_LIBRARY is set by find_package(ICU) in the top level CMakeLists.txt + # It's an absolute path to the found library file + get_target_property(icui18n_path ICU::i18n IMPORTED_LOCATION) + get_filename_component(icu_i18n_basename "${icui18n_path}" NAME_WE) + get_filename_component(icu_i18n_dir "${icui18n_path}" DIRECTORY) + string(REPLACE "lib" "" icu_i18n_basename "${icu_i18n_basename}") + + target_compile_options(Foundation + PRIVATE + "SHELL:-Xfrontend -public-autolink-library -Xfrontend ${icu_i18n_basename} + -Xfrontend -public-autolink-library -Xfrontend BlocksRuntime") + # ICU libraries are linked by absolute library path in this project, + # but -public-autolink-library forces to resolve library path by + # library search path given by -L, so add a directory of icui18n + # in the search path + target_link_directories(Foundation PUBLIC "${icu_i18n_dir}") + + # Merge private dependencies into single static objects archive + set_property(TARGET Foundation PROPERTY STATIC_LIBRARY_OPTIONS + $ + $) +endif() + if(CMAKE_SYSTEM_NAME STREQUAL Windows) # NOTE: workaround for CMake which doesn't link in OBJECT libraries properly add_dependencies(Foundation CoreFoundationResources) diff --git a/Sources/FoundationNetworking/CMakeLists.txt b/Sources/FoundationNetworking/CMakeLists.txt index 164ef63b91..c1462d1dc0 100644 --- a/Sources/FoundationNetworking/CMakeLists.txt +++ b/Sources/FoundationNetworking/CMakeLists.txt @@ -64,6 +64,17 @@ target_link_libraries(FoundationNetworking CFURLSessionInterface PUBLIC Foundation) + +if(NOT BUILD_SHARED_LIBS) + target_compile_options(FoundationNetworking + PRIVATE + "SHELL:-Xfrontend -public-autolink-library -Xfrontend curl") + + # Merge private dependencies into single static objects archive + set_property(TARGET FoundationNetworking PROPERTY STATIC_LIBRARY_OPTIONS + $) +endif() + set_target_properties(FoundationNetworking PROPERTIES INSTALL_RPATH "$ORIGIN" Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift diff --git a/Sources/FoundationXML/CMakeLists.txt b/Sources/FoundationXML/CMakeLists.txt index cbc1a95ba3..913c8f42b3 100644 --- a/Sources/FoundationXML/CMakeLists.txt +++ b/Sources/FoundationXML/CMakeLists.txt @@ -16,6 +16,17 @@ target_link_libraries(FoundationXML CFXMLInterface PUBLIC Foundation) + +if(NOT BUILD_SHARED_LIBS) + target_compile_options(FoundationXML + PRIVATE + "SHELL:-Xfrontend -public-autolink-library -Xfrontend xml2") + + # Merge private dependencies into single static objects archive + set_property(TARGET FoundationXML PROPERTY STATIC_LIBRARY_OPTIONS + $) +endif() + set_target_properties(FoundationXML PROPERTIES INSTALL_RPATH "$ORIGIN" Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift