1# Get sources 2set(LIBCXXABI_SOURCES 3 # C++ABI files 4 cxa_aux_runtime.cpp 5 cxa_default_handlers.cpp 6 cxa_demangle.cpp 7 cxa_exception_storage.cpp 8 cxa_guard.cpp 9 cxa_handlers.cpp 10 cxa_unexpected.cpp 11 cxa_vector.cpp 12 cxa_virtual.cpp 13 # C++ STL files 14 stdlib_exception.cpp 15 stdlib_stdexcept.cpp 16 stdlib_typeinfo.cpp 17 # Internal files 18 abort_message.cpp 19 fallback_malloc.cpp 20 private_typeinfo.cpp 21) 22 23if (LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS) 24 list(APPEND LIBCXXABI_SOURCES stdlib_new_delete.cpp) 25endif() 26 27if (LIBCXXABI_ENABLE_EXCEPTIONS) 28 list(APPEND LIBCXXABI_SOURCES cxa_exception.cpp) 29 list(APPEND LIBCXXABI_SOURCES cxa_personality.cpp) 30else() 31 list(APPEND LIBCXXABI_SOURCES cxa_noexception.cpp) 32endif() 33 34if (LIBCXXABI_ENABLE_THREADS AND UNIX AND NOT (APPLE OR CYGWIN)) 35 list(APPEND LIBCXXABI_SOURCES cxa_thread_atexit.cpp) 36endif() 37 38set(LIBCXXABI_HEADERS ../include/cxxabi.h) 39 40# Add all the headers to the project for IDEs. 41if (MSVC_IDE OR XCODE) 42 # Force them all into the headers dir on MSVC, otherwise they end up at 43 # project scope because they don't have extensions. 44 if (MSVC_IDE) 45 source_group("Header Files" FILES ${LIBCXXABI_HEADERS}) 46 endif() 47endif() 48 49include_directories("${LIBCXXABI_LIBCXX_INCLUDES}") 50 51if (LIBCXXABI_HAS_CXA_THREAD_ATEXIT_IMPL) 52 add_definitions(-DHAVE___CXA_THREAD_ATEXIT_IMPL) 53endif() 54 55if (LIBCXXABI_ENABLE_THREADS) 56 add_library_flags_if(LIBCXXABI_HAS_PTHREAD_LIB pthread) 57endif() 58 59add_library_flags_if(LIBCXXABI_HAS_C_LIB c) 60if (LIBCXXABI_USE_LLVM_UNWINDER) 61 # Prefer using the in-tree version of libunwind, either shared or static. If 62 # none are found fall back to using -lunwind. 63 # FIXME: Is it correct to prefer the static version of libunwind? 64 if (NOT LIBCXXABI_ENABLE_STATIC_UNWINDER AND (TARGET unwind_shared OR HAVE_LIBUNWIND)) 65 list(APPEND LIBCXXABI_LIBRARIES unwind_shared) 66 elseif (LIBCXXABI_ENABLE_STATIC_UNWINDER AND (TARGET unwind_static OR HAVE_LIBUNWIND)) 67 list(APPEND LIBCXXABI_LIBRARIES unwind_static) 68 else() 69 list(APPEND LIBCXXABI_LIBRARIES unwind) 70 endif() 71else() 72 add_library_flags_if(LIBCXXABI_HAS_GCC_S_LIB gcc_s) 73endif() 74if (MINGW) 75 # MINGW_LIBRARIES is defined in config-ix.cmake 76 list(APPEND LIBCXXABI_LIBRARIES ${MINGW_LIBRARIES}) 77endif() 78 79# Setup flags. 80add_link_flags_if_supported(-nodefaultlibs) 81 82set(LIBCXXABI_SHARED_LINK_FLAGS) 83 84if ( APPLE ) 85 if ( CMAKE_OSX_DEPLOYMENT_TARGET STREQUAL "10.6" ) 86 list(APPEND LIBCXXABI_COMPILE_FLAGS "-U__STRICT_ANSI__") 87 list(APPEND LIBCXXABI_SHARED_LINK_FLAGS 88 "-compatibility_version 1" 89 "-current_version 1" 90 "-install_name /usr/lib/libc++abi.1.dylib") 91 list(APPEND LIBCXXABI_LINK_FLAGS 92 "/usr/lib/libSystem.B.dylib") 93 else() 94 list(APPEND LIBCXXABI_SHARED_LINK_FLAGS 95 "-compatibility_version 1" 96 "-install_name /usr/lib/libc++abi.1.dylib") 97 endif() 98endif() 99 100split_list(LIBCXXABI_COMPILE_FLAGS) 101split_list(LIBCXXABI_LINK_FLAGS) 102split_list(LIBCXXABI_SHARED_LINK_FLAGS) 103 104# FIXME: libc++abi.so will not link when modules are enabled because it depends 105# on symbols defined in libc++.so which has not yet been built. 106if (LLVM_ENABLE_MODULES) 107 string(REPLACE "-Wl,-z,defs" "" CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}") 108endif() 109 110# Add a object library that contains the compiled source files. 111add_library(cxxabi_objects OBJECT ${LIBCXXABI_SOURCES} ${LIBCXXABI_HEADERS}) 112set_target_properties(cxxabi_objects 113 PROPERTIES 114 CXX_EXTENSIONS 115 OFF 116 CXX_STANDARD 117 11 118 CXX_STANDARD_REQUIRED 119 ON 120 COMPILE_FLAGS 121 "${LIBCXXABI_COMPILE_FLAGS}" 122 POSITION_INDEPENDENT_CODE 123 ON) 124 125set(LIBCXXABI_TARGETS) 126 127# Build the shared library. 128if (LIBCXXABI_ENABLE_SHARED) 129 add_library(cxxabi_shared SHARED $<TARGET_OBJECTS:cxxabi_objects>) 130 if(COMMAND llvm_setup_rpath) 131 llvm_setup_rpath(cxxabi_shared) 132 endif() 133 target_link_libraries(cxxabi_shared ${LIBCXXABI_LIBRARIES}) 134 set_target_properties(cxxabi_shared 135 PROPERTIES 136 CXX_EXTENSIONS 137 OFF 138 CXX_STANDARD 139 11 140 CXX_STANDARD_REQUIRED 141 ON 142 LINK_FLAGS 143 "${LIBCXXABI_LINK_FLAGS} ${LIBCXXABI_SHARED_LINK_FLAGS}" 144 OUTPUT_NAME 145 "c++abi" 146 POSITION_INDEPENDENT_CODE 147 ON 148 SOVERSION 149 "1" 150 VERSION 151 "1.0") 152 list(APPEND LIBCXXABI_TARGETS "cxxabi_shared") 153endif() 154 155# Build the static library. 156if (LIBCXXABI_ENABLE_STATIC) 157 set(cxxabi_static_sources $<TARGET_OBJECTS:cxxabi_objects>) 158 if (LIBCXXABI_USE_LLVM_UNWINDER AND LIBCXXABI_ENABLE_STATIC_UNWINDER) 159 if (TARGET unwind_static OR HAVE_LIBUNWIND) 160 list(APPEND cxxabi_static_sources $<TARGET_OBJECTS:unwind_objects>) 161 endif() 162 endif() 163 add_library(cxxabi_static STATIC ${cxxabi_static_sources}) 164 target_link_libraries(cxxabi_static ${LIBCXXABI_LIBRARIES}) 165 set_target_properties(cxxabi_static 166 PROPERTIES 167 CXX_EXTENSIONS 168 OFF 169 CXX_STANDARD 170 11 171 CXX_STANDARD_REQUIRED 172 ON 173 LINK_FLAGS 174 "${LIBCXXABI_LINK_FLAGS}" 175 OUTPUT_NAME 176 "c++abi" 177 POSITION_INDEPENDENT_CODE 178 ON) 179 list(APPEND LIBCXXABI_TARGETS "cxxabi_static") 180endif() 181 182# Add a meta-target for both libraries. 183add_custom_target(cxxabi DEPENDS ${LIBCXXABI_TARGETS}) 184 185if (LIBCXXABI_INSTALL_LIBRARY) 186 install(TARGETS ${LIBCXXABI_TARGETS} 187 LIBRARY DESTINATION ${LIBCXXABI_INSTALL_PREFIX}lib${LIBCXXABI_LIBDIR_SUFFIX} COMPONENT cxxabi 188 ARCHIVE DESTINATION ${LIBCXXABI_INSTALL_PREFIX}lib${LIBCXXABI_LIBDIR_SUFFIX} COMPONENT cxxabi 189 ) 190endif() 191 192if (NOT CMAKE_CONFIGURATION_TYPES AND LIBCXXABI_INSTALL_LIBRARY) 193 add_custom_target(install-cxxabi 194 DEPENDS cxxabi 195 COMMAND "${CMAKE_COMMAND}" 196 -DCMAKE_INSTALL_COMPONENT=cxxabi 197 -P "${LIBCXXABI_BINARY_DIR}/cmake_install.cmake") 198 add_custom_target(install-cxxabi-stripped 199 DEPENDS cxxabi 200 COMMAND "${CMAKE_COMMAND}" 201 -DCMAKE_INSTALL_COMPONENT=cxxabi 202 -DCMAKE_INSTALL_DO_STRIP=1 203 -P "${LIBCXXABI_BINARY_DIR}/cmake_install.cmake") 204 205 # TODO: This is a legacy target name and should be removed at some point. 206 add_custom_target(install-libcxxabi DEPENDS install-cxxabi) 207endif() 208