blob: 3af703c58731fb0f6547dda1184c72eec8782a14 [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
15 private_typeinfo.cpp
16 stdexcept.cpp
17 typeinfo.cpp
18)
19
Asiri Rathnayake4174e8b2016-05-31 12:01:32 +000020if (LIBCXXABI_ENABLE_EXCEPTIONS)
21 list(APPEND LIBCXXABI_SOURCES cxa_exception.cpp)
22 list(APPEND LIBCXXABI_SOURCES cxa_personality.cpp)
23else()
24 list(APPEND LIBCXXABI_SOURCES cxa_noexception.cpp)
25endif()
26
Dan Albertefa37d12014-12-18 00:03:57 +000027if (UNIX AND NOT (APPLE OR CYGWIN))
28 list(APPEND LIBCXXABI_SOURCES cxa_thread_atexit.cpp)
29endif()
30
Dan Albert000b3c92014-07-11 15:36:02 +000031set(LIBCXXABI_HEADERS ../include/cxxabi.h)
Dan Alberte11c1a72014-07-03 19:35:48 +000032
33# Add all the headers to the project for IDEs.
34if (MSVC_IDE OR XCODE)
35 # Force them all into the headers dir on MSVC, otherwise they end up at
36 # project scope because they don't have extensions.
37 if (MSVC_IDE)
38 source_group("Header Files" FILES ${LIBCXXABI_HEADERS})
39 endif()
40endif()
41
Dan Albertfd961bd2014-07-10 02:20:11 +000042include_directories("${LIBCXXABI_LIBCXX_INCLUDES}")
Dan Alberte11c1a72014-07-03 19:35:48 +000043
Dan Albertefa37d12014-12-18 00:03:57 +000044if (LIBCXXABI_HAS_CXA_THREAD_ATEXIT_IMPL)
45 add_definitions(-DHAVE___CXA_THREAD_ATEXIT_IMPL)
46endif()
47
Eric Fiselierf84ec312015-12-14 22:20:04 +000048# Generate library list
Dan Alberte11c1a72014-07-03 19:35:48 +000049set(libraries ${LIBCXXABI_CXX_ABI_LIBRARIES})
Eric Fiselierf84ec312015-12-14 22:20:04 +000050
Eric Fiselierd872a692014-11-24 22:42:03 +000051if (LIBCXXABI_ENABLE_THREADS)
52 append_if(libraries LIBCXXABI_HAS_PTHREAD_LIB pthread)
53endif()
Dan Albertdb8f3352014-07-14 17:00:29 +000054
Eric Fiselierf84ec312015-12-14 22:20:04 +000055append_if(libraries LIBCXXABI_HAS_C_LIB c)
56
Dan Albertdb8f3352014-07-14 17:00:29 +000057if (LIBCXXABI_USE_LLVM_UNWINDER)
Petr Hosek3f7e85b2016-08-09 00:27:19 +000058 if (NOT LIBCXXABI_BUILT_STANDALONE)
Petr Hoseke1b2d052016-08-09 21:28:52 +000059 if (LIBUNWIND_ENABLE_SHARED)
60 list(APPEND libraries unwind_shared)
61 else()
62 list(APPEND libraries unwind_static)
63 endif()
64 else()
65 list(APPEND libraries unwind)
Petr Hosek3f7e85b2016-08-09 00:27:19 +000066 endif()
Dan Albertdb8f3352014-07-14 17:00:29 +000067else()
Eric Fiselierf84ec312015-12-14 22:20:04 +000068 append_if(libraries LIBCXXABI_HAS_GCC_S_LIB gcc_s)
Dan Albertdb8f3352014-07-14 17:00:29 +000069endif()
Dan Alberte11c1a72014-07-03 19:35:48 +000070
Dan Alberte11c1a72014-07-03 19:35:48 +000071# Setup flags.
Eric Fiselierc365bb52014-11-18 20:37:53 +000072append_if(LIBCXXABI_COMPILE_FLAGS LIBCXXABI_HAS_FPIC_FLAG -fPIC)
73append_if(LIBCXXABI_LINK_FLAGS LIBCXXABI_HAS_NODEFAULTLIBS_FLAG -nodefaultlibs)
Dan Alberte11c1a72014-07-03 19:35:48 +000074
Eric Fiselierd95080e2015-03-03 15:59:09 +000075set(LIBCXXABI_SHARED_LINK_FLAGS)
76
Dan Alberte11c1a72014-07-03 19:35:48 +000077if ( APPLE )
78 if ( CMAKE_OSX_DEPLOYMENT_TARGET STREQUAL "10.6" )
Eric Fiselierc365bb52014-11-18 20:37:53 +000079 list(APPEND LIBCXXABI_COMPILE_FLAGS "-U__STRICT_ANSI__")
Eric Fiselierd95080e2015-03-03 15:59:09 +000080 list(APPEND LIBCXXABI_SHARED_LINK_FLAGS
Dan Alberte11c1a72014-07-03 19:35:48 +000081 "-compatibility_version 1"
Hans Wennborg95272d22014-08-12 18:18:07 +000082 "-current_version 1"
Eric Fiselierd95080e2015-03-03 15:59:09 +000083 "-install_name /usr/lib/libc++abi.1.dylib")
Eric Fiselierc365bb52014-11-18 20:37:53 +000084 list(APPEND LIBCXXABI_LINK_FLAGS
Eric Fiselierd95080e2015-03-03 15:59:09 +000085 "/usr/lib/libSystem.B.dylib")
86 else()
87 list(APPEND LIBCXXABI_SHARED_LINK_FLAGS
Dan Alberte11c1a72014-07-03 19:35:48 +000088 "-compatibility_version 1"
89 "-install_name /usr/lib/libc++abi.1.dylib")
90 endif()
91endif()
92
Eric Fiselierc365bb52014-11-18 20:37:53 +000093string(REPLACE ";" " " LIBCXXABI_COMPILE_FLAGS "${LIBCXXABI_COMPILE_FLAGS}")
94string(REPLACE ";" " " LIBCXXABI_LINK_FLAGS "${LIBCXXABI_LINK_FLAGS}")
Eric Fiselierd95080e2015-03-03 15:59:09 +000095string(REPLACE ";" " " LIBCXXABI_SHARED_LINK_FLAGS "${LIBCXXABI_SHARED_LINK_FLAGS}")
Dan Alberte11c1a72014-07-03 19:35:48 +000096
Eric Fiselierd95080e2015-03-03 15:59:09 +000097# Add a object library that contains the compiled source files.
98add_library(cxxabi_objects OBJECT ${LIBCXXABI_SOURCES} ${LIBCXXABI_HEADERS})
99
100set_target_properties(cxxabi_objects
Dan Alberte11c1a72014-07-03 19:35:48 +0000101 PROPERTIES
Eric Fiselierc365bb52014-11-18 20:37:53 +0000102 COMPILE_FLAGS "${LIBCXXABI_COMPILE_FLAGS}"
Dan Alberte11c1a72014-07-03 19:35:48 +0000103 )
104
Eric Fiselierd95080e2015-03-03 15:59:09 +0000105set(LIBCXXABI_TARGETS)
106
107# Build the shared library.
108if (LIBCXXABI_ENABLE_SHARED)
109 add_library(cxxabi_shared SHARED $<TARGET_OBJECTS:cxxabi_objects>)
110 target_link_libraries(cxxabi_shared ${libraries})
111 set_target_properties(cxxabi_shared
112 PROPERTIES
113 LINK_FLAGS "${LIBCXXABI_LINK_FLAGS} ${LIBCXXABI_SHARED_LINK_FLAGS}"
114 OUTPUT_NAME "c++abi"
115 VERSION "1.0"
116 SOVERSION "1"
117 )
118 list(APPEND LIBCXXABI_TARGETS "cxxabi_shared")
119endif()
120
121# Build the static library.
122if (LIBCXXABI_ENABLE_STATIC)
123 add_library(cxxabi_static STATIC $<TARGET_OBJECTS:cxxabi_objects>)
124 target_link_libraries(cxxabi_static ${libraries})
125 set_target_properties(cxxabi_static
126 PROPERTIES
127 LINK_FLAGS "${LIBCXXABI_LINK_FLAGS}"
128 OUTPUT_NAME "c++abi"
129 )
130 list(APPEND LIBCXXABI_TARGETS "cxxabi_static")
131endif()
132
133# Add a meta-target for both libraries.
134add_custom_target(cxxabi DEPENDS ${LIBCXXABI_TARGETS})
135
136install(TARGETS ${LIBCXXABI_TARGETS}
Eric Fiselier147e19b2015-08-19 17:17:21 +0000137 LIBRARY DESTINATION lib${LIBCXXABI_LIBDIR_SUFFIX} COMPONENT libcxxabi
138 ARCHIVE DESTINATION lib${LIBCXXABI_LIBDIR_SUFFIX} COMPONENT libcxxabi
Dan Alberte11c1a72014-07-03 19:35:48 +0000139 )
Eric Fiselier147e19b2015-08-19 17:17:21 +0000140
141if (NOT CMAKE_CONFIGURATION_TYPES)
142 add_custom_target(install-libcxxabi
143 DEPENDS cxxabi
144 COMMAND "${CMAKE_COMMAND}"
145 -DCMAKE_INSTALL_COMPONENT=libcxxabi
146 -P "${LIBCXXABI_BINARY_DIR}/cmake_install.cmake")
147endif()