@@ -20,7 +20,7 @@ include(GNUInstallDirs)
20
20
# since we would end up also adding the system-provided C++ Standard Library to
21
21
# the search path. Instead, what we do is copy just the ABI library headers to
22
22
# a private directory and add just that path when we build libc++.
23
- function (import_private_headers target include_dirs headers)
23
+ function (_import_private_headers target include_dirs headers)
24
24
if (NOT ${include_dirs} )
25
25
message (FATAL_ERROR "Missing include paths for the selected ABI library!" )
26
26
endif ()
@@ -58,15 +58,14 @@ function(import_private_headers target include_dirs headers)
58
58
target_include_directories (${target} INTERFACE "${LIBCXX_BINARY_DIR} /private-abi-headers/${target} " )
59
59
endfunction ()
60
60
61
- # This function creates an imported static library named <target>.
62
- # It imports a library named <name> searched at the given <path>.
63
- function (import_static_library target path name )
64
- add_library (${target} STATIC IMPORTED GLOBAL )
65
- find_library (file
66
- NAMES "${CMAKE_STATIC_LIBRARY_PREFIX}${name}${CMAKE_STATIC_LIBRARY_SUFFIX} "
67
- PATHS "${path} "
68
- NO_CACHE)
69
- set_target_properties (${target} PROPERTIES IMPORTED_LOCATION "${file} " )
61
+ # This function adds linker flags to a <target> appropriate for merging the object
62
+ # files of another static <library> into whoever links against <target>.
63
+ function (_merge_static_library target library)
64
+ if (APPLE )
65
+ target_link_options (${target} INTERFACE "-Wl,-force_load" "${library} " )
66
+ else ()
67
+ target_link_options (${target} INTERFACE "-Wl,--whole-archive" "-Wl,-Bstatic" "${library} " "-Wl,-Bdynamic" "-Wl,--no-whole-archive" )
68
+ endif ()
70
69
endfunction ()
71
70
72
71
# This function creates a library target for linking against an external ABI library.
@@ -75,29 +74,31 @@ endfunction()
75
74
# <name>: The name of the library file to search for (e.g. c++abi, stdc++, cxxrt, supc++)
76
75
# <type>: Whether to set up a static or a shared library (e.g. SHARED or STATIC)
77
76
# <merged>: Whether to include the ABI library's object files directly into libc++. Only makes sense for a static ABI library.
78
- function (import_external_abi_library target name type merged)
77
+ function (_import_external_abi_library target name type merged)
79
78
if (${merged} AND "${type} " STREQUAL "SHARED" )
80
79
message (FATAL_ERROR "Can't import an external ABI library for merging when requesting a shared ABI library." )
81
80
endif ()
82
81
83
82
if ("${type} " STREQUAL "SHARED" )
84
83
add_library (${target} INTERFACE IMPORTED GLOBAL )
85
84
set_target_properties (${target} PROPERTIES IMPORTED_LIBNAME "${name} " )
85
+
86
86
elseif ("${type} " STREQUAL "STATIC" )
87
+ add_library (${target} -imported STATIC IMPORTED GLOBAL )
88
+ find_library (file
89
+ NAMES "${CMAKE_STATIC_LIBRARY_PREFIX}${name}${CMAKE_STATIC_LIBRARY_SUFFIX} "
90
+ PATHS "${LIBCXX_CXX_ABI_LIBRARY_PATH} "
91
+ NO_CACHE)
92
+ if (NOT "${file} " )
93
+ message (FATAL_ERROR "Failed to find static library ${name} at path ${LIBCXX_CXX_ABI_LIBRARY_PATH} " )
94
+ endif ()
95
+ set_target_properties (${target} -imported PROPERTIES IMPORTED_LOCATION "${file} " )
96
+
97
+ add_library (${target} INTERFACE )
87
98
if (${merged} )
88
- import_static_library(${target} -impl "${LIBCXX_CXX_ABI_LIBRARY_PATH} " ${name} )
89
- add_library (${target} INTERFACE )
90
- if (APPLE )
91
- target_link_options (${target} INTERFACE
92
- "-Wl,-force_load" "$<TARGET_PROPERTY:${target} -impl,IMPORTED_LOCATION>" )
93
- else ()
94
- target_link_options (${target} INTERFACE
95
- "-Wl,--whole-archive" "-Wl,-Bstatic"
96
- "$<TARGET_PROPERTY:${target} -impl,IMPORTED_LOCATION>"
97
- "-Wl,-Bdynamic" "-Wl,--no-whole-archive" )
98
- endif ()
99
+ _merge_static_library(${target} "$<TARGET_PROPERTY:${target} -imported,IMPORTED_LOCATION>" )
99
100
else ()
100
- import_static_library (${target} " ${LIBCXX_CXX_ABI_LIBRARY_PATH} " ${name} )
101
+ target_link_libraries (${target} INTERFACE ${target} - imported )
101
102
endif ()
102
103
endif ()
103
104
endfunction ()
@@ -133,22 +134,22 @@ function(setup_abi_library abi_target linked_into input)
133
134
134
135
# Link against a system-provided libstdc++
135
136
if ("${stdlib} " STREQUAL "libstdc++" )
136
- import_external_abi_library (${abi_target} stdc++ ${search_type} ${merged} )
137
- import_private_headers (${abi_target} "${LIBCXX_CXX_ABI_INCLUDE_PATHS} "
137
+ _import_external_abi_library (${abi_target} stdc++ ${search_type} ${merged} )
138
+ _import_private_headers (${abi_target} "${LIBCXX_CXX_ABI_INCLUDE_PATHS} "
138
139
"cxxabi.h;bits/c++config.h;bits/os_defines.h;bits/cpu_defines.h;bits/cxxabi_tweaks.h;bits/cxxabi_forced.h" )
139
140
target_compile_definitions (${abi_target} INTERFACE "-DLIBSTDCXX" "-D__GLIBCXX__" )
140
141
141
142
# Link against a system-provided libsupc++
142
143
elseif ("${stdlib} " STREQUAL "libsupc++" )
143
- import_external_abi_library (${abi_target} supc++ ${search_type} ${merged} )
144
- import_private_headers (${abi_target} "${LIBCXX_CXX_ABI_INCLUDE_PATHS} "
144
+ _import_external_abi_library (${abi_target} supc++ ${search_type} ${merged} )
145
+ _import_private_headers (${abi_target} "${LIBCXX_CXX_ABI_INCLUDE_PATHS} "
145
146
"cxxabi.h;bits/c++config.h;bits/os_defines.h;bits/cpu_defines.h;bits/cxxabi_tweaks.h;bits/cxxabi_forced.h" )
146
147
target_compile_definitions (${abi_target} INTERFACE "-D__GLIBCXX__" )
147
148
148
149
# Link against a system-provided libcxxrt
149
150
elseif ("${stdlib} " STREQUAL "libcxxrt" )
150
- import_external_abi_library (${abi_target} cxxrt ${search_type} ${merged} )
151
- import_private_headers (${abi_target} "${LIBCXX_CXX_ABI_INCLUDE_PATHS} "
151
+ _import_external_abi_library (${abi_target} cxxrt ${search_type} ${merged} )
152
+ _import_private_headers (${abi_target} "${LIBCXX_CXX_ABI_INCLUDE_PATHS} "
152
153
"cxxabi.h;unwind.h;unwind-arm.h;unwind-itanium.h" )
153
154
target_compile_definitions (${abi_target} INTERFACE "-DLIBCXXRT" )
154
155
@@ -159,18 +160,18 @@ function(setup_abi_library abi_target linked_into input)
159
160
160
161
# Link against a system-provided libc++abi
161
162
elseif ("${stdlib} " STREQUAL "system-libcxxabi" )
162
- import_external_abi_library (${abi_target} c++abi ${search_type} ${merged} )
163
- import_private_headers (${abi_target} "${LIBCXX_CXX_ABI_INCLUDE_PATHS} "
163
+ _import_external_abi_library (${abi_target} c++abi ${search_type} ${merged} )
164
+ _import_private_headers (${abi_target} "${LIBCXX_CXX_ABI_INCLUDE_PATHS} "
164
165
"cxxabi.h;__cxxabi_config.h" )
165
166
target_compile_definitions (${abi_target} INTERFACE "-DLIBCXX_BUILDING_LIBCXXABI" )
166
167
167
168
# Link against the in-tree libc++abi.
168
169
elseif ("${stdlib} " STREQUAL "libcxxabi" )
169
170
if (${merged} )
170
- get_target_property (_outdir cxxabi_static ARCHIVE_OUTPUT_DIRECTORY )
171
- get_target_property (_outname cxxabi_static OUTPUT_NAME )
172
- set (LIBCXX_CXX_ABI_LIBRARY_PATH " ${_outdir } " )
173
- import_external_abi_library (${abi_target} " ${_outname} " STATIC TRUE )
171
+ add_library ( ${abi_target} INTERFACE )
172
+ _merge_static_library( ${abi_target}
173
+ "$<TARGET_PROPERTY:cxxabi_static,LIBRARY_OUTPUT_DIRECTORY>/ ${CMAKE_STATIC_LIBRARY_PREFIX} $<TARGET_PROPERTY:cxxabi_static,OUTPUT_NAME> ${CMAKE_STATIC_LIBRARY_SUFFIX } " )
174
+ target_link_libraries (${abi_target} INTERFACE cxxabi-headers )
174
175
else ()
175
176
string (TOLOWER "${search_type} " type )
176
177
add_library (${abi_target} INTERFACE )
0 commit comments