Skip to content

Commit bb8e7d2

Browse files
authored
Merge pull request #3052 from kateinoigakukun/revert-revert-katei/merge-private-libs
Revert "Revert "Fix autolink mechanism for static libraries on Linux""
2 parents 08f2025 + f1a5aa7 commit bb8e7d2

File tree

5 files changed

+48
-1
lines changed

5 files changed

+48
-1
lines changed

CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ if(HAS_LIBDISPATCH_API)
4747
find_package(dispatch CONFIG REQUIRED)
4848
endif()
4949

50+
find_package(ICU COMPONENTS uc i18n REQUIRED)
51+
5052
include(SwiftSupport)
5153
include(GNUInstallDirs)
5254
include(XCTest)

CoreFoundation/CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
3232
else()
3333
find_package(CURL REQUIRED)
3434
endif()
35-
find_package(ICU COMPONENTS uc i18n REQUIRED)
3635
endif()
3736

3837
include(GNUInstallDirs)

Sources/Foundation/CMakeLists.txt

+24
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,30 @@ set_target_properties(Foundation PROPERTIES
160160
Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift
161161
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_BINARY_DIR}/swift)
162162

163+
if(NOT BUILD_SHARED_LIBS)
164+
# ICU_I18N_LIBRARY is set by find_package(ICU) in the top level CMakeLists.txt
165+
# It's an absolute path to the found library file
166+
get_target_property(icui18n_path ICU::i18n IMPORTED_LOCATION)
167+
get_filename_component(icu_i18n_basename "${icui18n_path}" NAME_WE)
168+
get_filename_component(icu_i18n_dir "${icui18n_path}" DIRECTORY)
169+
string(REPLACE "lib" "" icu_i18n_basename "${icu_i18n_basename}")
170+
171+
target_compile_options(Foundation
172+
PRIVATE
173+
"SHELL:-Xfrontend -public-autolink-library -Xfrontend ${icu_i18n_basename}
174+
-Xfrontend -public-autolink-library -Xfrontend BlocksRuntime")
175+
# ICU libraries are linked by absolute library path in this project,
176+
# but -public-autolink-library forces to resolve library path by
177+
# library search path given by -L, so add a directory of icui18n
178+
# in the search path
179+
target_link_directories(Foundation PUBLIC "${icu_i18n_dir}")
180+
181+
# Merge private dependencies into single static objects archive
182+
set_property(TARGET Foundation PROPERTY STATIC_LIBRARY_OPTIONS
183+
$<TARGET_OBJECTS:CoreFoundation>
184+
$<TARGET_OBJECTS:uuid>)
185+
endif()
186+
163187
if(CMAKE_SYSTEM_NAME STREQUAL Windows)
164188
# NOTE: workaround for CMake which doesn't link in OBJECT libraries properly
165189
add_dependencies(Foundation CoreFoundationResources)

Sources/FoundationNetworking/CMakeLists.txt

+11
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,17 @@ target_link_libraries(FoundationNetworking
6464
CFURLSessionInterface
6565
PUBLIC
6666
Foundation)
67+
68+
if(NOT BUILD_SHARED_LIBS)
69+
target_compile_options(FoundationNetworking
70+
PRIVATE
71+
"SHELL:-Xfrontend -public-autolink-library -Xfrontend curl")
72+
73+
# Merge private dependencies into single static objects archive
74+
set_property(TARGET FoundationNetworking PROPERTY STATIC_LIBRARY_OPTIONS
75+
$<TARGET_OBJECTS:CFURLSessionInterface>)
76+
endif()
77+
6778
set_target_properties(FoundationNetworking PROPERTIES
6879
INSTALL_RPATH "$ORIGIN"
6980
Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift

Sources/FoundationXML/CMakeLists.txt

+11
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,17 @@ target_link_libraries(FoundationXML
1616
CFXMLInterface
1717
PUBLIC
1818
Foundation)
19+
20+
if(NOT BUILD_SHARED_LIBS)
21+
target_compile_options(FoundationXML
22+
PRIVATE
23+
"SHELL:-Xfrontend -public-autolink-library -Xfrontend xml2")
24+
25+
# Merge private dependencies into single static objects archive
26+
set_property(TARGET FoundationXML PROPERTY STATIC_LIBRARY_OPTIONS
27+
$<TARGET_OBJECTS:CFXMLInterface>)
28+
endif()
29+
1930
set_target_properties(FoundationXML PROPERTIES
2031
INSTALL_RPATH "$ORIGIN"
2132
Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift

0 commit comments

Comments
 (0)