Skip to content

Commit 57fdb6c

Browse files
committed
Workaround lack of -fPIC when building static libcxxabi
1 parent 6a12d61 commit 57fdb6c

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

libcxx/cmake/Modules/HandleLibCXXABI.cmake

+8-2
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,17 @@ function(setup_abi_library abi_target linked_into input)
168168
# Link against the in-tree libc++abi.
169169
elseif ("${stdlib}" STREQUAL "libcxxabi")
170170
if (${merged})
171+
if ("${linked_into}" STREQUAL "STATIC")
172+
set(merge_target "cxxabi_static")
173+
else()
174+
set(merge_target "cxxabi_shared_for_merging")
175+
endif()
176+
message(STATUS "LDIONNE: merge_target=${merge_target}")
171177
add_library(${abi_target} INTERFACE)
172178
_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}")
179+
"$<TARGET_PROPERTY:${merge_target},LIBRARY_OUTPUT_DIRECTORY>/${CMAKE_STATIC_LIBRARY_PREFIX}$<TARGET_PROPERTY:${merge_target},OUTPUT_NAME>${CMAKE_STATIC_LIBRARY_SUFFIX}")
174180
target_link_libraries(${abi_target} INTERFACE cxxabi-headers)
175-
add_dependencies(${abi_target} cxxabi_static)
181+
add_dependencies(${abi_target} ${merge_target})
176182
else()
177183
string(TOLOWER "${search_type}" type)
178184
add_library(${abi_target} INTERFACE)

libcxxabi/src/CMakeLists.txt

+15
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,21 @@ if (CMAKE_POSITION_INDEPENDENT_CODE OR NOT DEFINED CMAKE_POSITION_INDEPENDENT_CO
184184
endif()
185185
target_compile_options(cxxabi_shared_objects PRIVATE "${LIBCXXABI_ADDITIONAL_COMPILE_FLAGS}")
186186

187+
add_library(cxxabi_shared_for_merging STATIC EXCLUDE_FROM_ALL)
188+
target_link_libraries(cxxabi_shared_for_merging
189+
PUBLIC cxxabi_shared_objects
190+
PRIVATE ${LIBCXXABI_LIBRARIES})
191+
set_target_properties(cxxabi_shared_for_merging
192+
PROPERTIES
193+
OUTPUT_NAME "${LIBCXXABI_STATIC_OUTPUT_NAME}-for-merging"
194+
)
195+
if (LIBCXXABI_USE_LLVM_UNWINDER)
196+
if (LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_SHARED_LIBRARY OR
197+
(DEFINED LIBUNWIND_ENABLE_SHARED AND NOT LIBUNWIND_ENABLE_SHARED))
198+
target_sources(cxxabi_shared_for_merging PUBLIC $<TARGET_OBJECTS:unwind_shared_objects>)
199+
endif()
200+
endif()
201+
187202
add_library(cxxabi_shared SHARED)
188203
set_target_properties(cxxabi_shared
189204
PROPERTIES

0 commit comments

Comments
 (0)