From 523f9e04dc84b53dce3c8b30992edc39d1a4e81a Mon Sep 17 00:00:00 2001 From: Max Desiatov Date: Fri, 20 Aug 2021 14:19:48 +0100 Subject: [PATCH] Cherry-pick upstream autolinking changes Cherry-picking upstream https://github.com/apple/swift-corelibs-foundation/pull/3052 --- Sources/Foundation/CMakeLists.txt | 32 ++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/Sources/Foundation/CMakeLists.txt b/Sources/Foundation/CMakeLists.txt index f06166eb41..b7b04bf032 100644 --- a/Sources/Foundation/CMakeLists.txt +++ b/Sources/Foundation/CMakeLists.txt @@ -166,18 +166,28 @@ set_target_properties(Foundation PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_BINARY_DIR}/swift) if(NOT BUILD_SHARED_LIBS) - add_dependencies(Foundation CoreFoundation uuid) - target_compile_options(Foundation - PRIVATE - "SHELL:-Xfrontend -public-autolink-library -Xfrontend icui18n - -Xfrontend -public-autolink-library -Xfrontend BlocksRuntime") + # 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}") - # Merge private dependencies into single static objects archive - set_property(TARGET Foundation PROPERTY STATIC_LIBRARY_OPTIONS - $ - $ - $) -endif() + 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