blob: e6bd381226c0add657626713124bd5d58fd337bd [file] [log] [blame]
Dan Alberte11c1a72014-07-03 19:35:48 +00001# Get sources
2set(LIBCXXABI_SOURCES
3 abort_message.cpp
4 cxa_aux_runtime.cpp
5 cxa_default_handlers.cpp
6 cxa_demangle.cpp
Dan Alberte11c1a72014-07-03 19:35:48 +00007 cxa_exception_storage.cpp
8 cxa_guard.cpp
9 cxa_handlers.cpp
10 cxa_new_delete.cpp
Dan Alberte11c1a72014-07-03 19:35:48 +000011 cxa_unexpected.cpp
12 cxa_vector.cpp
13 cxa_virtual.cpp
14 exception.cpp
Igor Kudrinace65722016-10-07 08:48:28 +000015 fallback_malloc.cpp
Dan Alberte11c1a72014-07-03 19:35:48 +000016 private_typeinfo.cpp
17 stdexcept.cpp
18 typeinfo.cpp
19)
20
Asiri Rathnayake4174e8b2016-05-31 12:01:32 +000021if (LIBCXXABI_ENABLE_EXCEPTIONS)
22 list(APPEND LIBCXXABI_SOURCES cxa_exception.cpp)
23 list(APPEND LIBCXXABI_SOURCES cxa_personality.cpp)
24else()
25 list(APPEND LIBCXXABI_SOURCES cxa_noexception.cpp)
26endif()
27
Vitaly Bukac3964792016-10-14 23:51:41 +000028if (LIBCXXABI_ENABLE_THREADS AND UNIX AND NOT (APPLE OR CYGWIN))
Dan Albertefa37d12014-12-18 00:03:57 +000029 list(APPEND LIBCXXABI_SOURCES cxa_thread_atexit.cpp)
30endif()
31
Dan Albert000b3c92014-07-11 15:36:02 +000032set(LIBCXXABI_HEADERS ../include/cxxabi.h)
Dan Alberte11c1a72014-07-03 19:35:48 +000033
34# Add all the headers to the project for IDEs.
35if (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()
41endif()
42
Dan Albertfd961bd2014-07-10 02:20:11 +000043include_directories("${LIBCXXABI_LIBCXX_INCLUDES}")
Dan Alberte11c1a72014-07-03 19:35:48 +000044
Dan Albertefa37d12014-12-18 00:03:57 +000045if (LIBCXXABI_HAS_CXA_THREAD_ATEXIT_IMPL)
46 add_definitions(-DHAVE___CXA_THREAD_ATEXIT_IMPL)
47endif()
48
Eric Fiselierf84ec312015-12-14 22:20:04 +000049# Generate library list
Dan Alberte11c1a72014-07-03 19:35:48 +000050set(libraries ${LIBCXXABI_CXX_ABI_LIBRARIES})
Eric Fiselierf84ec312015-12-14 22:20:04 +000051
Eric Fiselierd872a692014-11-24 22:42:03 +000052if (LIBCXXABI_ENABLE_THREADS)
53 append_if(libraries LIBCXXABI_HAS_PTHREAD_LIB pthread)
54endif()
Dan Albertdb8f3352014-07-14 17:00:29 +000055
Eric Fiselierf84ec312015-12-14 22:20:04 +000056append_if(libraries LIBCXXABI_HAS_C_LIB c)
Dan Albertdb8f3352014-07-14 17:00:29 +000057if (LIBCXXABI_USE_LLVM_UNWINDER)
Eric Fiseliere64fce82016-10-09 20:44:48 +000058 # 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 Hoseke1b2d052016-08-09 21:28:52 +000065 else()
66 list(APPEND libraries unwind)
Petr Hosek3f7e85b2016-08-09 00:27:19 +000067 endif()
Dan Albertdb8f3352014-07-14 17:00:29 +000068else()
Eric Fiselierf84ec312015-12-14 22:20:04 +000069 append_if(libraries LIBCXXABI_HAS_GCC_S_LIB gcc_s)
Dan Albertdb8f3352014-07-14 17:00:29 +000070endif()
Dan Alberte11c1a72014-07-03 19:35:48 +000071
Dan Alberte11c1a72014-07-03 19:35:48 +000072# Setup flags.
Eric Fiselierc365bb52014-11-18 20:37:53 +000073append_if(LIBCXXABI_COMPILE_FLAGS LIBCXXABI_HAS_FPIC_FLAG -fPIC)
74append_if(LIBCXXABI_LINK_FLAGS LIBCXXABI_HAS_NODEFAULTLIBS_FLAG -nodefaultlibs)
Dan Alberte11c1a72014-07-03 19:35:48 +000075
Eric Fiselierd95080e2015-03-03 15:59:09 +000076set(LIBCXXABI_SHARED_LINK_FLAGS)
77
Dan Alberte11c1a72014-07-03 19:35:48 +000078if ( APPLE )
79 if ( CMAKE_OSX_DEPLOYMENT_TARGET STREQUAL "10.6" )
Eric Fiselierc365bb52014-11-18 20:37:53 +000080 list(APPEND LIBCXXABI_COMPILE_FLAGS "-U__STRICT_ANSI__")
Eric Fiselierd95080e2015-03-03 15:59:09 +000081 list(APPEND LIBCXXABI_SHARED_LINK_FLAGS
Dan Alberte11c1a72014-07-03 19:35:48 +000082 "-compatibility_version 1"
Hans Wennborg95272d22014-08-12 18:18:07 +000083 "-current_version 1"
Eric Fiselierd95080e2015-03-03 15:59:09 +000084 "-install_name /usr/lib/libc++abi.1.dylib")
Eric Fiselierc365bb52014-11-18 20:37:53 +000085 list(APPEND LIBCXXABI_LINK_FLAGS
Eric Fiselierd95080e2015-03-03 15:59:09 +000086 "/usr/lib/libSystem.B.dylib")
87 else()
88 list(APPEND LIBCXXABI_SHARED_LINK_FLAGS
Dan Alberte11c1a72014-07-03 19:35:48 +000089 "-compatibility_version 1"
90 "-install_name /usr/lib/libc++abi.1.dylib")
91 endif()
92endif()
93
Eric Fiselierc365bb52014-11-18 20:37:53 +000094string(REPLACE ";" " " LIBCXXABI_COMPILE_FLAGS "${LIBCXXABI_COMPILE_FLAGS}")
95string(REPLACE ";" " " LIBCXXABI_LINK_FLAGS "${LIBCXXABI_LINK_FLAGS}")
Eric Fiselierd95080e2015-03-03 15:59:09 +000096string(REPLACE ";" " " LIBCXXABI_SHARED_LINK_FLAGS "${LIBCXXABI_SHARED_LINK_FLAGS}")
Dan Alberte11c1a72014-07-03 19:35:48 +000097
Eric Fiselier4d44c0f2016-10-25 20:07:49 +000098# 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.
100if (LLVM_ENABLE_MODULES)
101 string(REPLACE "-Wl,-z,defs" "" CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
102endif()
103
Eric Fiselierd95080e2015-03-03 15:59:09 +0000104# Add a object library that contains the compiled source files.
105add_library(cxxabi_objects OBJECT ${LIBCXXABI_SOURCES} ${LIBCXXABI_HEADERS})
106
107set_target_properties(cxxabi_objects
Dan Alberte11c1a72014-07-03 19:35:48 +0000108 PROPERTIES
Eric Fiselierc365bb52014-11-18 20:37:53 +0000109 COMPILE_FLAGS "${LIBCXXABI_COMPILE_FLAGS}"
Dan Alberte11c1a72014-07-03 19:35:48 +0000110 )
111
Eric Fiselierd95080e2015-03-03 15:59:09 +0000112set(LIBCXXABI_TARGETS)
113
114# Build the shared library.
115if (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")
126endif()
127
128# Build the static library.
129if (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")
138endif()
139
140# Add a meta-target for both libraries.
141add_custom_target(cxxabi DEPENDS ${LIBCXXABI_TARGETS})
142
143install(TARGETS ${LIBCXXABI_TARGETS}
Eric Fiselier564b6ea2016-08-28 18:28:51 +0000144 LIBRARY DESTINATION lib${LIBCXXABI_LIBDIR_SUFFIX} COMPONENT cxxabi
145 ARCHIVE DESTINATION lib${LIBCXXABI_LIBDIR_SUFFIX} COMPONENT cxxabi
Dan Alberte11c1a72014-07-03 19:35:48 +0000146 )
Eric Fiselier147e19b2015-08-19 17:17:21 +0000147
148if (NOT CMAKE_CONFIGURATION_TYPES)
Eric Fiselier564b6ea2016-08-28 18:28:51 +0000149 add_custom_target(install-cxxabi
Eric Fiselier147e19b2015-08-19 17:17:21 +0000150 DEPENDS cxxabi
151 COMMAND "${CMAKE_COMMAND}"
Eric Fiselier564b6ea2016-08-28 18:28:51 +0000152 -DCMAKE_INSTALL_COMPONENT=cxxabi
Eric Fiselier147e19b2015-08-19 17:17:21 +0000153 -P "${LIBCXXABI_BINARY_DIR}/cmake_install.cmake")
Eric Fiselier564b6ea2016-08-28 18:28:51 +0000154
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 Fiselier147e19b2015-08-19 17:17:21 +0000157endif()