5 cxa_default_handlers.cpp
7 cxa_exception_storage.cpp
22 if (LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS)
23 list(APPEND LIBCXXABI_SOURCES
28 if (LIBCXXABI_ENABLE_EXCEPTIONS)
29 list(APPEND LIBCXXABI_SOURCES
34 list(APPEND LIBCXXABI_SOURCES
39 if (LIBCXXABI_ENABLE_THREADS AND (UNIX OR FUCHSIA) AND NOT (APPLE OR CYGWIN)
40 AND NOT (${CMAKE_SYSTEM_NAME} MATCHES "AIX"))
41 list(APPEND LIBCXXABI_SOURCES
50 # Add all the headers to the project for IDEs.
51 if (MSVC_IDE OR XCODE)
52 # Force them all into the headers dir on MSVC, otherwise they end up at
53 # project scope because they don't have extensions.
55 source_group("Header Files" FILES ${LIBCXXABI_HEADERS})
59 # Some files depend on libc++ internals.
60 include_directories("${LIBCXXABI_LIBCXX_PATH}/src")
62 if (LIBCXXABI_HAS_CXA_THREAD_ATEXIT_IMPL)
63 add_definitions(-DHAVE___CXA_THREAD_ATEXIT_IMPL)
66 if (LIBCXXABI_ENABLE_FORGIVING_DYNAMIC_CAST)
67 add_definitions(-D_LIBCXXABI_FORGIVING_DYNAMIC_CAST)
70 if (NOT APPLE) # On Apple platforms, we always use -nostdlib++ so we don't need to re-add other libraries
71 if (LIBCXXABI_ENABLE_THREADS)
72 add_library_flags_if(LIBCXXABI_HAS_PTHREAD_LIB pthread)
75 add_library_flags_if(LIBCXXABI_HAS_C_LIB c)
79 # TODO: Use CMAKE_LINK_LIBRARY_USING_FEATURE once our minimum CMake is at least 3.24
80 # https://cmake.org/cmake/help/latest/variable/CMAKE_LINK_LIBRARY_USING_FEATURE.html
81 add_link_flags("-Wl,--push-state,--as-needed,-lzircon,--pop-state")
84 if (NOT LIBCXXABI_USE_COMPILER_RT)
85 add_library_flags_if(LIBCXXABI_HAS_GCC_LIB gcc)
87 if (NOT LIBCXXABI_USE_LLVM_UNWINDER)
88 add_library_flags_if(LIBCXXABI_HAS_GCC_S_LIB gcc_s)
92 # MINGW_LIBRARIES is defined in config-ix.cmake
93 list(APPEND LIBCXXABI_LIBRARIES ${MINGW_LIBRARIES})
95 if (ANDROID AND ANDROID_PLATFORM_LEVEL LESS 21)
96 list(APPEND LIBCXXABI_LIBRARIES android_support)
100 if (CXX_SUPPORTS_NOSTDLIBXX_FLAG)
101 add_link_flags_if_supported(-nostdlib++)
103 add_link_flags_if_supported(-nodefaultlibs)
106 if (CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG AND LIBCXXABI_USE_LLVM_UNWINDER)
107 # If we're linking directly against the libunwind that we're building
108 # in the same invocation, don't try to link in the toolchain's
109 # default libunwind (which may be missing still).
110 add_link_flags_if_supported(--unwindlib=none)
114 if (LLVM_USE_SANITIZER)
115 if (("${LLVM_USE_SANITIZER}" STREQUAL "Address") OR
116 ("${LLVM_USE_SANITIZER}" STREQUAL "Address;Undefined") OR
117 ("${LLVM_USE_SANITIZER}" STREQUAL "Undefined;Address"))
118 set(LIBFILE "libclang_rt.asan_osx_dynamic.dylib")
119 elseif("${LLVM_USE_SANITIZER}" STREQUAL "Undefined")
120 set(LIBFILE "libclang_rt.ubsan_osx_dynamic.dylib")
121 elseif("${LLVM_USE_SANITIZER}" STREQUAL "Thread")
122 set(LIBFILE "libclang_rt.tsan_osx_dynamic.dylib")
124 message(WARNING "LLVM_USE_SANITIZER=${LLVM_USE_SANITIZER} is not supported on OS X")
127 find_compiler_rt_library(builtins LIBCXXABI_BUILTINS_LIBRARY)
128 get_filename_component(LIBDIR "${LIBCXXABI_BUILTINS_LIBRARY}" DIRECTORY)
129 if (NOT IS_DIRECTORY "${LIBDIR}")
130 message(FATAL_ERROR "Cannot find compiler-rt directory on OS X required for LLVM_USE_SANITIZER")
132 set(LIBCXXABI_SANITIZER_LIBRARY "${LIBDIR}/${LIBFILE}")
133 set(LIBCXXABI_SANITIZER_LIBRARY "${LIBCXXABI_SANITIZER_LIBRARY}" PARENT_SCOPE)
134 message(STATUS "Manually linking compiler-rt library: ${LIBCXXABI_SANITIZER_LIBRARY}")
135 add_library_flags("${LIBCXXABI_SANITIZER_LIBRARY}")
136 add_link_flags("-Wl,-rpath,${LIBDIR}")
140 # Make sure we link in CrashReporterClient if we find it -- it's used by
141 # abort() on Apple platforms when building the system dylib.
142 find_library(CrashReporterClient NAMES libCrashReporterClient.a
143 PATHS "${CMAKE_OSX_SYSROOT}/usr/local/lib")
144 if (CrashReporterClient)
145 message(STATUS "Linking with CrashReporterClient at ${CrashReporterClient}")
146 add_library_flags("${CrashReporterClient}")
148 message(STATUS "Could not find CrashReporterClient, not linking against it")
152 split_list(LIBCXXABI_COMPILE_FLAGS)
153 split_list(LIBCXXABI_LINK_FLAGS)
155 # FIXME: libc++abi.so will not link when modules are enabled because it depends
156 # on symbols defined in libc++.so which has not yet been built.
157 if (LLVM_ENABLE_MODULES)
158 string(REPLACE "-Wl,-z,defs" "" CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
161 include(WarningFlags)
163 # Build the shared library.
164 add_library(cxxabi_shared_objects OBJECT EXCLUDE_FROM_ALL ${LIBCXXABI_SOURCES} ${LIBCXXABI_HEADERS})
165 cxx_add_warning_flags(cxxabi_shared_objects ${LIBCXXABI_ENABLE_WERROR} ${LIBCXXABI_ENABLE_PEDANTIC})
166 if (LIBCXXABI_USE_LLVM_UNWINDER)
167 if (LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_SHARED_LIBRARY OR
168 (DEFINED LIBUNWIND_ENABLE_SHARED AND NOT LIBUNWIND_ENABLE_SHARED))
169 target_link_libraries(cxxabi_shared_objects PUBLIC unwind_shared_objects) # propagate usage requirements
170 target_sources(cxxabi_shared_objects PUBLIC $<TARGET_OBJECTS:unwind_shared_objects>)
172 target_link_libraries(cxxabi_shared_objects PUBLIC unwind_shared)
175 target_link_libraries(cxxabi_shared_objects PRIVATE cxx-headers ${LIBCXXABI_LIBRARIES})
176 if (NOT CXX_SUPPORTS_NOSTDLIBXX_FLAG)
177 target_link_libraries(cxxabi_shared_objects PRIVATE ${LIBCXXABI_BUILTINS_LIBRARY})
179 target_link_libraries(cxxabi_shared_objects PUBLIC cxxabi-headers)
180 set_target_properties(cxxabi_shared_objects
184 CXX_STANDARD_REQUIRED OFF # TODO: Make this REQUIRED once we don't need to accommodate the LLVM documentation builders using an ancient CMake
185 COMPILE_FLAGS "${LIBCXXABI_COMPILE_FLAGS}"
188 if (CMAKE_POSITION_INDEPENDENT_CODE OR NOT DEFINED CMAKE_POSITION_INDEPENDENT_CODE)
189 set_target_properties(cxxabi_shared_objects PROPERTIES POSITION_INDEPENDENT_CODE ON) # must set manually because it's an object library
191 target_compile_options(cxxabi_shared_objects PRIVATE "${LIBCXXABI_ADDITIONAL_COMPILE_FLAGS}")
193 add_library(cxxabi_shared SHARED)
194 set_target_properties(cxxabi_shared
196 EXCLUDE_FROM_ALL "$<IF:$<BOOL:${LIBCXXABI_ENABLE_SHARED}>,FALSE,TRUE>"
197 LINK_FLAGS "${LIBCXXABI_LINK_FLAGS}"
198 OUTPUT_NAME "${LIBCXXABI_SHARED_OUTPUT_NAME}"
200 VERSION "${LIBCXXABI_LIBRARY_VERSION}"
204 add_custom_command(TARGET cxxabi_shared POST_BUILD
206 ${LIBCXXABI_LIBCXX_PATH}/utils/zos_rename_dll_side_deck.sh
207 $<TARGET_LINKER_FILE_NAME:cxxabi_shared> $<TARGET_FILE_NAME:cxxabi_shared> "${LIBCXXABI_DLL_NAME}"
208 COMMENT "Rename dll name inside the side deck file"
209 WORKING_DIRECTORY $<TARGET_FILE_DIR:cxxabi_shared>
213 target_link_libraries(cxxabi_shared
214 PUBLIC cxxabi_shared_objects
215 PRIVATE ${LIBCXXABI_LIBRARIES})
217 if (LIBCXXABI_ENABLE_SHARED)
218 list(APPEND LIBCXXABI_BUILD_TARGETS "cxxabi_shared")
220 if (LIBCXXABI_INSTALL_SHARED_LIBRARY)
221 list(APPEND LIBCXXABI_INSTALL_TARGETS "cxxabi_shared")
224 # TODO: Move this to libc++'s HandleLibCXXABI.cmake since this is effectively trying to control
225 # what libc++ re-exports.
226 add_library(cxxabi-reexports INTERFACE)
227 function(export_symbols file)
228 # -exported_symbols_list is only available on Apple platforms
230 target_link_libraries(cxxabi_shared PRIVATE "-Wl,-exported_symbols_list,${file}")
234 function(reexport_symbols file)
235 export_symbols("${file}")
236 # -reexported_symbols_list is only available on Apple platforms
238 target_link_libraries(cxxabi-reexports INTERFACE "-Wl,-reexported_symbols_list,${file}")
242 export_symbols("${CMAKE_CURRENT_SOURCE_DIR}/../lib/symbols-not-reexported.exp")
243 reexport_symbols("${CMAKE_CURRENT_SOURCE_DIR}/../lib/cxxabiv1.exp")
244 reexport_symbols("${CMAKE_CURRENT_SOURCE_DIR}/../lib/fundamental-types.exp")
245 reexport_symbols("${CMAKE_CURRENT_SOURCE_DIR}/../lib/itanium-base.exp")
246 reexport_symbols("${CMAKE_CURRENT_SOURCE_DIR}/../lib/std-misc.exp")
248 if (LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS)
249 reexport_symbols("${CMAKE_CURRENT_SOURCE_DIR}/../lib/new-delete.exp")
252 # Note that std:: exception types are always defined by the library regardless of
253 # whether the exception runtime machinery is provided.
254 reexport_symbols("${CMAKE_CURRENT_SOURCE_DIR}/../lib/std-exceptions.exp")
256 if (LIBCXXABI_ENABLE_EXCEPTIONS)
257 reexport_symbols("${CMAKE_CURRENT_SOURCE_DIR}/../lib/itanium-exceptions.exp")
259 if ("${CMAKE_OSX_ARCHITECTURES}" MATCHES "^(armv6|armv7|armv7s)$")
260 reexport_symbols("${CMAKE_CURRENT_SOURCE_DIR}/../lib/personality-sjlj.exp")
262 reexport_symbols("${CMAKE_CURRENT_SOURCE_DIR}/../lib/personality-v0.exp")
266 # Build the static library.
267 add_library(cxxabi_static_objects OBJECT EXCLUDE_FROM_ALL ${LIBCXXABI_SOURCES} ${LIBCXXABI_HEADERS})
268 cxx_add_warning_flags(cxxabi_static_objects ${LIBCXXABI_ENABLE_WERROR} ${LIBCXXABI_ENABLE_PEDANTIC})
269 if (LIBCXXABI_USE_LLVM_UNWINDER AND LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_STATIC_LIBRARY)
270 target_link_libraries(cxxabi_static_objects PUBLIC unwind_static_objects) # propagate usage requirements
271 target_sources(cxxabi_static_objects PUBLIC $<TARGET_OBJECTS:unwind_static_objects>)
273 target_link_libraries(cxxabi_static_objects PRIVATE cxx-headers ${LIBCXXABI_STATIC_LIBRARIES} ${LIBCXXABI_LIBRARIES})
274 target_link_libraries(cxxabi_static_objects PUBLIC cxxabi-headers)
275 set_target_properties(cxxabi_static_objects
279 CXX_STANDARD_REQUIRED OFF # TODO: Make this REQUIRED once we don't need to accommodate the LLVM documentation builders using an ancient CMake
280 COMPILE_FLAGS "${LIBCXXABI_COMPILE_FLAGS}"
282 target_compile_options(cxxabi_static_objects PRIVATE "${LIBCXXABI_ADDITIONAL_COMPILE_FLAGS}")
284 if(LIBCXXABI_HERMETIC_STATIC_LIBRARY)
285 target_add_compile_flags_if_supported(cxxabi_static_objects PRIVATE -fvisibility=hidden)
286 # If the hermetic library doesn't define the operator new/delete functions
287 # then its code shouldn't declare them with hidden visibility. They might
288 # actually be provided by a shared library at link time.
289 if (LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS)
290 target_add_compile_flags_if_supported(cxxabi_static_objects PRIVATE -fvisibility-global-new-delete=force-hidden)
291 if (NOT CXX_SUPPORTS_FVISIBILITY_GLOBAL_NEW_DELETE_EQ_FORCE_HIDDEN_FLAG)
292 target_add_compile_flags_if_supported(cxxabi_static_objects PRIVATE -fvisibility-global-new-delete-hidden)
295 # _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS can be defined in libcxx's
296 # __config_site too. Define it in the same way here, to avoid redefinition
298 target_compile_definitions(cxxabi_static_objects
300 _LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS
301 _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS=)
304 add_library(cxxabi_static STATIC)
305 if (LIBCXXABI_USE_LLVM_UNWINDER AND NOT LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_STATIC_LIBRARY)
306 target_link_libraries(cxxabi_static PUBLIC unwind_static)
308 set_target_properties(cxxabi_static
310 EXCLUDE_FROM_ALL "$<IF:$<BOOL:${LIBCXXABI_ENABLE_STATIC}>,FALSE,TRUE>"
311 LINK_FLAGS "${LIBCXXABI_LINK_FLAGS}"
312 OUTPUT_NAME "${LIBCXXABI_STATIC_OUTPUT_NAME}"
314 target_link_libraries(cxxabi_static
315 PUBLIC cxxabi_static_objects
316 PRIVATE ${LIBCXXABI_STATIC_LIBRARIES} ${LIBCXXABI_LIBRARIES})
318 if (LIBCXXABI_ENABLE_STATIC)
319 list(APPEND LIBCXXABI_BUILD_TARGETS "cxxabi_static")
321 if (LIBCXXABI_INSTALL_STATIC_LIBRARY)
322 list(APPEND LIBCXXABI_INSTALL_TARGETS "cxxabi_static")
325 # Add a meta-target for both libraries.
326 add_custom_target(cxxabi DEPENDS ${LIBCXXABI_BUILD_TARGETS})
328 if (LIBCXXABI_INSTALL_LIBRARY)
329 install(TARGETS ${LIBCXXABI_INSTALL_TARGETS}
330 LIBRARY DESTINATION ${LIBCXXABI_INSTALL_LIBRARY_DIR} COMPONENT cxxabi
331 ARCHIVE DESTINATION ${LIBCXXABI_INSTALL_LIBRARY_DIR} COMPONENT cxxabi
332 RUNTIME DESTINATION ${LIBCXXABI_INSTALL_RUNTIME_DIR} COMPONENT cxxabi
336 if (NOT CMAKE_CONFIGURATION_TYPES AND LIBCXXABI_INSTALL_LIBRARY)
337 add_custom_target(install-cxxabi
338 DEPENDS cxxabi install-cxxabi-headers
339 COMMAND "${CMAKE_COMMAND}"
340 -DCMAKE_INSTALL_COMPONENT=cxxabi
341 -P "${LIBCXXABI_BINARY_DIR}/cmake_install.cmake")
342 add_custom_target(install-cxxabi-stripped
344 COMMAND "${CMAKE_COMMAND}"
345 -DCMAKE_INSTALL_COMPONENT=cxxabi
346 -DCMAKE_INSTALL_DO_STRIP=1
347 -P "${LIBCXXABI_BINARY_DIR}/cmake_install.cmake")