Dan Albert | e11c1a7 | 2014-07-03 19:35:48 +0000 | [diff] [blame] | 1 | # Get sources |
| 2 | set(LIBCXXABI_SOURCES |
| 3 | abort_message.cpp |
| 4 | cxa_aux_runtime.cpp |
| 5 | cxa_default_handlers.cpp |
| 6 | cxa_demangle.cpp |
Dan Albert | e11c1a7 | 2014-07-03 19:35:48 +0000 | [diff] [blame] | 7 | cxa_exception_storage.cpp |
| 8 | cxa_guard.cpp |
| 9 | cxa_handlers.cpp |
| 10 | cxa_new_delete.cpp |
Dan Albert | e11c1a7 | 2014-07-03 19:35:48 +0000 | [diff] [blame] | 11 | cxa_unexpected.cpp |
| 12 | cxa_vector.cpp |
| 13 | cxa_virtual.cpp |
| 14 | exception.cpp |
Igor Kudrin | ace6572 | 2016-10-07 08:48:28 +0000 | [diff] [blame] | 15 | fallback_malloc.cpp |
Dan Albert | e11c1a7 | 2014-07-03 19:35:48 +0000 | [diff] [blame] | 16 | private_typeinfo.cpp |
| 17 | stdexcept.cpp |
| 18 | typeinfo.cpp |
| 19 | ) |
| 20 | |
Asiri Rathnayake | 4174e8b | 2016-05-31 12:01:32 +0000 | [diff] [blame] | 21 | if (LIBCXXABI_ENABLE_EXCEPTIONS) |
| 22 | list(APPEND LIBCXXABI_SOURCES cxa_exception.cpp) |
| 23 | list(APPEND LIBCXXABI_SOURCES cxa_personality.cpp) |
| 24 | else() |
| 25 | list(APPEND LIBCXXABI_SOURCES cxa_noexception.cpp) |
| 26 | endif() |
| 27 | |
Vitaly Buka | c396479 | 2016-10-14 23:51:41 +0000 | [diff] [blame] | 28 | if (LIBCXXABI_ENABLE_THREADS AND UNIX AND NOT (APPLE OR CYGWIN)) |
Dan Albert | efa37d1 | 2014-12-18 00:03:57 +0000 | [diff] [blame] | 29 | list(APPEND LIBCXXABI_SOURCES cxa_thread_atexit.cpp) |
| 30 | endif() |
| 31 | |
Dan Albert | 000b3c9 | 2014-07-11 15:36:02 +0000 | [diff] [blame] | 32 | set(LIBCXXABI_HEADERS ../include/cxxabi.h) |
Dan Albert | e11c1a7 | 2014-07-03 19:35:48 +0000 | [diff] [blame] | 33 | |
| 34 | # Add all the headers to the project for IDEs. |
| 35 | if (MSVC_IDE OR XCODE) |
| 36 | # Force them all into the headers dir on MSVC, otherwise they end up at |
| 37 | # project scope because they don't have extensions. |
| 38 | if (MSVC_IDE) |
| 39 | source_group("Header Files" FILES ${LIBCXXABI_HEADERS}) |
| 40 | endif() |
| 41 | endif() |
| 42 | |
Dan Albert | fd961bd | 2014-07-10 02:20:11 +0000 | [diff] [blame] | 43 | include_directories("${LIBCXXABI_LIBCXX_INCLUDES}") |
Dan Albert | e11c1a7 | 2014-07-03 19:35:48 +0000 | [diff] [blame] | 44 | |
Dan Albert | efa37d1 | 2014-12-18 00:03:57 +0000 | [diff] [blame] | 45 | if (LIBCXXABI_HAS_CXA_THREAD_ATEXIT_IMPL) |
| 46 | add_definitions(-DHAVE___CXA_THREAD_ATEXIT_IMPL) |
| 47 | endif() |
| 48 | |
Eric Fiselier | f84ec31 | 2015-12-14 22:20:04 +0000 | [diff] [blame] | 49 | # Generate library list |
Dan Albert | e11c1a7 | 2014-07-03 19:35:48 +0000 | [diff] [blame] | 50 | set(libraries ${LIBCXXABI_CXX_ABI_LIBRARIES}) |
Eric Fiselier | f84ec31 | 2015-12-14 22:20:04 +0000 | [diff] [blame] | 51 | |
Eric Fiselier | d872a69 | 2014-11-24 22:42:03 +0000 | [diff] [blame] | 52 | if (LIBCXXABI_ENABLE_THREADS) |
| 53 | append_if(libraries LIBCXXABI_HAS_PTHREAD_LIB pthread) |
| 54 | endif() |
Dan Albert | db8f335 | 2014-07-14 17:00:29 +0000 | [diff] [blame] | 55 | |
Eric Fiselier | f84ec31 | 2015-12-14 22:20:04 +0000 | [diff] [blame] | 56 | append_if(libraries LIBCXXABI_HAS_C_LIB c) |
Dan Albert | db8f335 | 2014-07-14 17:00:29 +0000 | [diff] [blame] | 57 | if (LIBCXXABI_USE_LLVM_UNWINDER) |
Eric Fiselier | e64fce8 | 2016-10-09 20:44:48 +0000 | [diff] [blame] | 58 | # Prefer using the in-tree version of libunwind, either shared or static. If |
| 59 | # none are found fall back to using -lunwind. |
| 60 | # FIXME: Is it correct to prefer the static version of libunwind? |
| 61 | if (TARGET unwind_shared) |
| 62 | list(APPEND libraries unwind_shared) |
| 63 | elseif(TARGET unwind_static) |
| 64 | list(APPEND libraries unwind_static) |
Petr Hosek | e1b2d05 | 2016-08-09 21:28:52 +0000 | [diff] [blame] | 65 | else() |
| 66 | list(APPEND libraries unwind) |
Petr Hosek | 3f7e85b | 2016-08-09 00:27:19 +0000 | [diff] [blame] | 67 | endif() |
Dan Albert | db8f335 | 2014-07-14 17:00:29 +0000 | [diff] [blame] | 68 | else() |
Eric Fiselier | f84ec31 | 2015-12-14 22:20:04 +0000 | [diff] [blame] | 69 | append_if(libraries LIBCXXABI_HAS_GCC_S_LIB gcc_s) |
Dan Albert | db8f335 | 2014-07-14 17:00:29 +0000 | [diff] [blame] | 70 | endif() |
Dan Albert | e11c1a7 | 2014-07-03 19:35:48 +0000 | [diff] [blame] | 71 | |
Dan Albert | e11c1a7 | 2014-07-03 19:35:48 +0000 | [diff] [blame] | 72 | # Setup flags. |
Eric Fiselier | c365bb5 | 2014-11-18 20:37:53 +0000 | [diff] [blame] | 73 | append_if(LIBCXXABI_COMPILE_FLAGS LIBCXXABI_HAS_FPIC_FLAG -fPIC) |
| 74 | append_if(LIBCXXABI_LINK_FLAGS LIBCXXABI_HAS_NODEFAULTLIBS_FLAG -nodefaultlibs) |
Dan Albert | e11c1a7 | 2014-07-03 19:35:48 +0000 | [diff] [blame] | 75 | |
Eric Fiselier | d95080e | 2015-03-03 15:59:09 +0000 | [diff] [blame] | 76 | set(LIBCXXABI_SHARED_LINK_FLAGS) |
| 77 | |
Dan Albert | e11c1a7 | 2014-07-03 19:35:48 +0000 | [diff] [blame] | 78 | if ( APPLE ) |
| 79 | if ( CMAKE_OSX_DEPLOYMENT_TARGET STREQUAL "10.6" ) |
Eric Fiselier | c365bb5 | 2014-11-18 20:37:53 +0000 | [diff] [blame] | 80 | list(APPEND LIBCXXABI_COMPILE_FLAGS "-U__STRICT_ANSI__") |
Eric Fiselier | d95080e | 2015-03-03 15:59:09 +0000 | [diff] [blame] | 81 | list(APPEND LIBCXXABI_SHARED_LINK_FLAGS |
Dan Albert | e11c1a7 | 2014-07-03 19:35:48 +0000 | [diff] [blame] | 82 | "-compatibility_version 1" |
Hans Wennborg | 95272d2 | 2014-08-12 18:18:07 +0000 | [diff] [blame] | 83 | "-current_version 1" |
Eric Fiselier | d95080e | 2015-03-03 15:59:09 +0000 | [diff] [blame] | 84 | "-install_name /usr/lib/libc++abi.1.dylib") |
Eric Fiselier | c365bb5 | 2014-11-18 20:37:53 +0000 | [diff] [blame] | 85 | list(APPEND LIBCXXABI_LINK_FLAGS |
Eric Fiselier | d95080e | 2015-03-03 15:59:09 +0000 | [diff] [blame] | 86 | "/usr/lib/libSystem.B.dylib") |
| 87 | else() |
| 88 | list(APPEND LIBCXXABI_SHARED_LINK_FLAGS |
Dan Albert | e11c1a7 | 2014-07-03 19:35:48 +0000 | [diff] [blame] | 89 | "-compatibility_version 1" |
| 90 | "-install_name /usr/lib/libc++abi.1.dylib") |
| 91 | endif() |
| 92 | endif() |
| 93 | |
Eric Fiselier | c365bb5 | 2014-11-18 20:37:53 +0000 | [diff] [blame] | 94 | string(REPLACE ";" " " LIBCXXABI_COMPILE_FLAGS "${LIBCXXABI_COMPILE_FLAGS}") |
| 95 | string(REPLACE ";" " " LIBCXXABI_LINK_FLAGS "${LIBCXXABI_LINK_FLAGS}") |
Eric Fiselier | d95080e | 2015-03-03 15:59:09 +0000 | [diff] [blame] | 96 | string(REPLACE ";" " " LIBCXXABI_SHARED_LINK_FLAGS "${LIBCXXABI_SHARED_LINK_FLAGS}") |
Dan Albert | e11c1a7 | 2014-07-03 19:35:48 +0000 | [diff] [blame] | 97 | |
Eric Fiselier | 4d44c0f | 2016-10-25 20:07:49 +0000 | [diff] [blame] | 98 | # FIXME: libc++abi.so will not link when modules are enabled because it depends |
| 99 | # on symbols defined in libc++.so which has not yet been built. |
| 100 | if (LLVM_ENABLE_MODULES) |
| 101 | string(REPLACE "-Wl,-z,defs" "" CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}") |
| 102 | endif() |
| 103 | |
Eric Fiselier | d95080e | 2015-03-03 15:59:09 +0000 | [diff] [blame] | 104 | # Add a object library that contains the compiled source files. |
| 105 | add_library(cxxabi_objects OBJECT ${LIBCXXABI_SOURCES} ${LIBCXXABI_HEADERS}) |
| 106 | |
| 107 | set_target_properties(cxxabi_objects |
Dan Albert | e11c1a7 | 2014-07-03 19:35:48 +0000 | [diff] [blame] | 108 | PROPERTIES |
Eric Fiselier | c365bb5 | 2014-11-18 20:37:53 +0000 | [diff] [blame] | 109 | COMPILE_FLAGS "${LIBCXXABI_COMPILE_FLAGS}" |
Dan Albert | e11c1a7 | 2014-07-03 19:35:48 +0000 | [diff] [blame] | 110 | ) |
| 111 | |
Eric Fiselier | d95080e | 2015-03-03 15:59:09 +0000 | [diff] [blame] | 112 | set(LIBCXXABI_TARGETS) |
| 113 | |
| 114 | # Build the shared library. |
| 115 | if (LIBCXXABI_ENABLE_SHARED) |
| 116 | add_library(cxxabi_shared SHARED $<TARGET_OBJECTS:cxxabi_objects>) |
| 117 | target_link_libraries(cxxabi_shared ${libraries}) |
| 118 | set_target_properties(cxxabi_shared |
| 119 | PROPERTIES |
| 120 | LINK_FLAGS "${LIBCXXABI_LINK_FLAGS} ${LIBCXXABI_SHARED_LINK_FLAGS}" |
| 121 | OUTPUT_NAME "c++abi" |
| 122 | VERSION "1.0" |
| 123 | SOVERSION "1" |
| 124 | ) |
| 125 | list(APPEND LIBCXXABI_TARGETS "cxxabi_shared") |
| 126 | endif() |
| 127 | |
| 128 | # Build the static library. |
| 129 | if (LIBCXXABI_ENABLE_STATIC) |
| 130 | add_library(cxxabi_static STATIC $<TARGET_OBJECTS:cxxabi_objects>) |
| 131 | target_link_libraries(cxxabi_static ${libraries}) |
| 132 | set_target_properties(cxxabi_static |
| 133 | PROPERTIES |
| 134 | LINK_FLAGS "${LIBCXXABI_LINK_FLAGS}" |
| 135 | OUTPUT_NAME "c++abi" |
| 136 | ) |
| 137 | list(APPEND LIBCXXABI_TARGETS "cxxabi_static") |
| 138 | endif() |
| 139 | |
| 140 | # Add a meta-target for both libraries. |
| 141 | add_custom_target(cxxabi DEPENDS ${LIBCXXABI_TARGETS}) |
| 142 | |
| 143 | install(TARGETS ${LIBCXXABI_TARGETS} |
Eric Fiselier | 564b6ea | 2016-08-28 18:28:51 +0000 | [diff] [blame] | 144 | LIBRARY DESTINATION lib${LIBCXXABI_LIBDIR_SUFFIX} COMPONENT cxxabi |
| 145 | ARCHIVE DESTINATION lib${LIBCXXABI_LIBDIR_SUFFIX} COMPONENT cxxabi |
Dan Albert | e11c1a7 | 2014-07-03 19:35:48 +0000 | [diff] [blame] | 146 | ) |
Eric Fiselier | 147e19b | 2015-08-19 17:17:21 +0000 | [diff] [blame] | 147 | |
| 148 | if (NOT CMAKE_CONFIGURATION_TYPES) |
Eric Fiselier | 564b6ea | 2016-08-28 18:28:51 +0000 | [diff] [blame] | 149 | add_custom_target(install-cxxabi |
Eric Fiselier | 147e19b | 2015-08-19 17:17:21 +0000 | [diff] [blame] | 150 | DEPENDS cxxabi |
| 151 | COMMAND "${CMAKE_COMMAND}" |
Eric Fiselier | 564b6ea | 2016-08-28 18:28:51 +0000 | [diff] [blame] | 152 | -DCMAKE_INSTALL_COMPONENT=cxxabi |
Eric Fiselier | 147e19b | 2015-08-19 17:17:21 +0000 | [diff] [blame] | 153 | -P "${LIBCXXABI_BINARY_DIR}/cmake_install.cmake") |
Eric Fiselier | 564b6ea | 2016-08-28 18:28:51 +0000 | [diff] [blame] | 154 | |
| 155 | # TODO: This is a legacy target name and should be removed at some point. |
| 156 | add_custom_target(install-libcxxabi DEPENDS install-cxxabi) |
Eric Fiselier | 147e19b | 2015-08-19 17:17:21 +0000 | [diff] [blame] | 157 | endif() |