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)
71 add_library_flags_if(LIBCXXABI_HAS_SYSTEM_LIB System)
73 if (LIBCXXABI_ENABLE_THREADS)
74 add_library_flags_if(LIBCXXABI_HAS_PTHREAD_LIB pthread)
77 add_library_flags_if(LIBCXXABI_HAS_C_LIB c)
80 if (LIBCXXABI_USE_COMPILER_RT)
81 find_compiler_rt_library(builtins LIBCXXABI_BUILTINS_LIBRARY)
82 list(APPEND LIBCXXABI_SHARED_LIBRARIES "${LIBCXXABI_BUILTINS_LIBRARY}")
85 if (LIBCXXABI_USE_LLVM_UNWINDER)
86 # Prefer using the in-tree version of libunwind, either shared or static. If
87 # none are found fall back to using -lunwind.
88 # FIXME: Is it correct to prefer the static version of libunwind?
89 if (NOT LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_SHARED_LIBRARY AND (TARGET unwind_shared OR HAVE_LIBUNWIND))
90 list(APPEND LIBCXXABI_SHARED_LIBRARIES unwind_shared)
91 elseif (LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_SHARED_LIBRARY AND (TARGET unwind_static OR HAVE_LIBUNWIND))
92 list(APPEND LIBCXXABI_SHARED_LIBRARIES unwind_static)
94 list(APPEND LIBCXXABI_SHARED_LIBRARIES unwind)
96 if (NOT LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_STATIC_LIBRARY AND (TARGET unwind_shared OR HAVE_LIBUNWIND))
97 list(APPEND LIBCXXABI_STATIC_LIBRARIES unwind_shared)
98 elseif (LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_STATIC_LIBRARY AND (TARGET unwind_static OR HAVE_LIBUNWIND))
99 # We handle this by directly merging libunwind objects into libc++abi.
101 list(APPEND LIBCXXABI_STATIC_LIBRARIES unwind)
104 add_library_flags_if(LIBCXXABI_HAS_GCC_S_LIB gcc_s)
107 # MINGW_LIBRARIES is defined in config-ix.cmake
108 list(APPEND LIBCXXABI_LIBRARIES ${MINGW_LIBRARIES})
110 if (ANDROID AND ANDROID_PLATFORM_LEVEL LESS 21)
111 list(APPEND LIBCXXABI_LIBRARIES android_support)
114 if (NOT LIBCXXABI_USE_COMPILER_RT)
115 add_library_flags_if(LIBCXXABI_HAS_GCC_LIB gcc)
119 if (LIBCXXABI_SUPPORTS_NOSTDLIBXX_FLAG)
120 add_link_flags_if_supported(-nostdlib++)
122 add_link_flags_if_supported(-nodefaultlibs)
126 if (LLVM_USE_SANITIZER)
127 if (("${LLVM_USE_SANITIZER}" STREQUAL "Address") OR
128 ("${LLVM_USE_SANITIZER}" STREQUAL "Address;Undefined") OR
129 ("${LLVM_USE_SANITIZER}" STREQUAL "Undefined;Address"))
130 set(LIBFILE "libclang_rt.asan_osx_dynamic.dylib")
131 elseif("${LLVM_USE_SANITIZER}" STREQUAL "Undefined")
132 set(LIBFILE "libclang_rt.ubsan_osx_dynamic.dylib")
133 elseif("${LLVM_USE_SANITIZER}" STREQUAL "Thread")
134 set(LIBFILE "libclang_rt.tsan_osx_dynamic.dylib")
136 message(WARNING "LLVM_USE_SANITIZER=${LLVM_USE_SANITIZER} is not supported on OS X")
139 find_compiler_rt_library(builtins LIBCXXABI_BUILTINS_LIBRARY)
140 get_filename_component(LIBDIR "${LIBCXXABI_BUILTINS_LIBRARY}" DIRECTORY)
141 if (NOT IS_DIRECTORY "${LIBDIR}")
142 message(FATAL_ERROR "Cannot find compiler-rt directory on OS X required for LLVM_USE_SANITIZER")
144 set(LIBCXXABI_SANITIZER_LIBRARY "${LIBDIR}/${LIBFILE}")
145 set(LIBCXXABI_SANITIZER_LIBRARY "${LIBCXXABI_SANITIZER_LIBRARY}" PARENT_SCOPE)
146 message(STATUS "Manually linking compiler-rt library: ${LIBCXXABI_SANITIZER_LIBRARY}")
147 add_library_flags("${LIBCXXABI_SANITIZER_LIBRARY}")
148 add_link_flags("-Wl,-rpath,${LIBDIR}")
152 # Make sure we link in CrashReporterClient if we find it -- it's used by
153 # abort() on Apple platforms when building the system dylib.
154 find_library(CrashReporterClient NAMES libCrashReporterClient.a
155 PATHS "${CMAKE_OSX_SYSROOT}/usr/local/lib")
156 if (CrashReporterClient)
157 message(STATUS "Linking with CrashReporterClient at ${CrashReporterClient}")
158 add_library_flags("${CrashReporterClient}")
160 message(STATUS "Could not find CrashReporterClient, not linking against it")
164 split_list(LIBCXXABI_COMPILE_FLAGS)
165 split_list(LIBCXXABI_LINK_FLAGS)
167 # FIXME: libc++abi.so will not link when modules are enabled because it depends
168 # on symbols defined in libc++.so which has not yet been built.
169 if (LLVM_ENABLE_MODULES)
170 string(REPLACE "-Wl,-z,defs" "" CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
173 if (NOT TARGET pstl::ParallelSTL)
174 message(STATUS "Could not find ParallelSTL, libc++abi will not attempt to use it but the build may fail if the libc++ in use needs it to be available.")
177 # Build the shared library.
178 if (LIBCXXABI_ENABLE_SHARED)
179 add_library(cxxabi_shared SHARED ${LIBCXXABI_SOURCES} ${LIBCXXABI_HEADERS})
180 target_link_libraries(cxxabi_shared PRIVATE cxx-headers ${LIBCXXABI_SHARED_LIBRARIES} ${LIBCXXABI_LIBRARIES})
181 if (TARGET pstl::ParallelSTL)
182 target_link_libraries(cxxabi_shared PUBLIC pstl::ParallelSTL)
184 set_target_properties(cxxabi_shared
188 CXX_STANDARD_REQUIRED OFF
189 COMPILE_FLAGS "${LIBCXXABI_COMPILE_FLAGS}"
190 LINK_FLAGS "${LIBCXXABI_LINK_FLAGS}"
193 VERSION "${LIBCXXABI_LIBRARY_VERSION}"
197 list(APPEND LIBCXXABI_BUILD_TARGETS "cxxabi_shared")
198 if (LIBCXXABI_INSTALL_SHARED_LIBRARY)
199 list(APPEND LIBCXXABI_INSTALL_TARGETS "cxxabi_shared")
202 add_library(cxxabi-reexports INTERFACE)
204 # -exported_symbols_list is only available on Apple platforms
206 function(export_symbols file)
207 target_link_libraries(cxxabi_shared PRIVATE "-Wl,-exported_symbols_list,${file}")
209 function(reexport_symbols file)
210 export_symbols("${file}")
211 target_link_libraries(cxxabi-reexports INTERFACE "-Wl,-reexported_symbols_list,${file}")
214 export_symbols("${CMAKE_CURRENT_SOURCE_DIR}/../lib/itanium-base.exp")
216 if (LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS)
217 reexport_symbols("${CMAKE_CURRENT_SOURCE_DIR}/../lib/new-delete.exp")
220 if (LIBCXXABI_ENABLE_EXCEPTIONS)
221 reexport_symbols("${CMAKE_CURRENT_SOURCE_DIR}/../lib/exceptions.exp")
223 if ("${CMAKE_OSX_ARCHITECTURES}" MATCHES "^(armv6|armv7|armv7s)$")
224 reexport_symbols("${CMAKE_CURRENT_SOURCE_DIR}/../lib/personality-sjlj.exp")
226 reexport_symbols("${CMAKE_CURRENT_SOURCE_DIR}/../lib/personality-v0.exp")
232 # Build the static library.
233 if (LIBCXXABI_ENABLE_STATIC)
234 add_library(cxxabi_static STATIC ${LIBCXXABI_SOURCES} ${LIBCXXABI_HEADERS})
235 target_link_libraries(cxxabi_static PRIVATE cxx-headers ${LIBCXXABI_STATIC_LIBRARIES} ${LIBCXXABI_LIBRARIES})
236 if (TARGET pstl::ParallelSTL)
237 target_link_libraries(cxxabi_static PUBLIC pstl::ParallelSTL)
239 set_target_properties(cxxabi_static
243 CXX_STANDARD_REQUIRED OFF
244 COMPILE_FLAGS "${LIBCXXABI_COMPILE_FLAGS}"
245 LINK_FLAGS "${LIBCXXABI_LINK_FLAGS}"
249 if(LIBCXXABI_HERMETIC_STATIC_LIBRARY)
250 append_flags_if_supported(CXXABI_STATIC_LIBRARY_FLAGS -fvisibility=hidden)
251 # If the hermetic library doesn't define the operator new/delete functions
252 # then its code shouldn't declare them with hidden visibility. They might
253 # actually be provided by a shared library at link time.
254 if (LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS)
255 append_flags_if_supported(CXXABI_STATIC_LIBRARY_FLAGS -fvisibility-global-new-delete-hidden)
257 target_compile_options(cxxabi_static PRIVATE ${CXXABI_STATIC_LIBRARY_FLAGS})
258 target_compile_definitions(cxxabi_static
260 _LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS
261 _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
264 list(APPEND LIBCXXABI_BUILD_TARGETS "cxxabi_static")
265 if (LIBCXXABI_INSTALL_STATIC_LIBRARY)
266 list(APPEND LIBCXXABI_INSTALL_TARGETS "cxxabi_static")
270 set(MERGE_ARCHIVES_LIBTOOL "--use-libtool" "--libtool" "${CMAKE_LIBTOOL}")
273 # Merge the libc++abi.a and libunwind.a into one.
274 if(LIBCXXABI_USE_LLVM_UNWINDER AND LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_STATIC_LIBRARY)
275 add_custom_command(TARGET cxxabi_static POST_BUILD
276 COMMAND ${Python3_EXECUTABLE} ${LIBCXXABI_LIBCXX_PATH}/utils/merge_archives.py
278 -o "$<TARGET_LINKER_FILE:cxxabi_static>"
280 ${MERGE_ARCHIVES_LIBTOOL}
281 "$<TARGET_LINKER_FILE:cxxabi_static>"
282 "$<TARGET_LINKER_FILE:unwind_static>"
283 WORKING_DIRECTORY ${LIBCXXABI_BUILD_DIR}
284 DEPENDS unwind_static
289 # Add a meta-target for both libraries.
290 add_custom_target(cxxabi DEPENDS ${LIBCXXABI_BUILD_TARGETS})
292 if (LIBCXXABI_INSTALL_LIBRARY)
293 install(TARGETS ${LIBCXXABI_INSTALL_TARGETS}
294 LIBRARY DESTINATION ${LIBCXXABI_INSTALL_LIBRARY_DIR} COMPONENT cxxabi
295 ARCHIVE DESTINATION ${LIBCXXABI_INSTALL_LIBRARY_DIR} COMPONENT cxxabi
296 RUNTIME DESTINATION ${LIBCXXABI_INSTALL_RUNTIME_DIR} COMPONENT cxxabi
300 if (NOT CMAKE_CONFIGURATION_TYPES AND LIBCXXABI_INSTALL_LIBRARY)
301 add_custom_target(install-cxxabi
303 COMMAND "${CMAKE_COMMAND}"
304 -DCMAKE_INSTALL_COMPONENT=cxxabi
305 -P "${LIBCXXABI_BINARY_DIR}/cmake_install.cmake")
306 add_custom_target(install-cxxabi-stripped
308 COMMAND "${CMAKE_COMMAND}"
309 -DCMAKE_INSTALL_COMPONENT=cxxabi
310 -DCMAKE_INSTALL_DO_STRIP=1
311 -P "${LIBCXXABI_BINARY_DIR}/cmake_install.cmake")