• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 OR FUCHSIA) 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_STATICALLY_LINK_UNWINDER_IN_SHARED_LIBRARY AND (TARGET unwind_shared OR HAVE_LIBUNWIND))
65    list(APPEND LIBCXXABI_SHARED_LIBRARIES unwind_shared)
66  elseif (LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_SHARED_LIBRARY AND (TARGET unwind_static OR HAVE_LIBUNWIND))
67    list(APPEND LIBCXXABI_SHARED_LIBRARIES unwind_static)
68  else()
69    list(APPEND LIBCXXABI_SHARED_LIBRARIES unwind)
70  endif()
71  if (NOT LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_STATIC_LIBRARY AND (TARGET unwind_shared OR HAVE_LIBUNWIND))
72    list(APPEND LIBCXXABI_STATIC_LIBRARIES unwind_shared)
73  elseif (LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_STATIC_LIBRARY AND (TARGET unwind_static OR HAVE_LIBUNWIND))
74      # We handle this by directly merging libunwind objects into libc++abi.
75  else()
76    list(APPEND LIBCXXABI_STATIC_LIBRARIES unwind)
77  endif()
78else()
79  add_library_flags_if(LIBCXXABI_HAS_GCC_S_LIB gcc_s)
80endif()
81if (MINGW)
82  # MINGW_LIBRARIES is defined in config-ix.cmake
83  list(APPEND LIBCXXABI_LIBRARIES ${MINGW_LIBRARIES})
84endif()
85
86# Setup flags.
87add_link_flags_if_supported(-nodefaultlibs)
88
89set(LIBCXXABI_SHARED_LINK_FLAGS)
90
91if ( APPLE )
92  if ( CMAKE_OSX_DEPLOYMENT_TARGET STREQUAL "10.6" )
93    list(APPEND LIBCXXABI_COMPILE_FLAGS "-U__STRICT_ANSI__")
94    list(APPEND LIBCXXABI_SHARED_LINK_FLAGS
95      "-compatibility_version 1"
96      "-current_version 1"
97      "-install_name /usr/lib/libc++abi.1.dylib")
98    list(APPEND LIBCXXABI_LINK_FLAGS
99        "/usr/lib/libSystem.B.dylib")
100  else()
101    list(APPEND LIBCXXABI_SHARED_LINK_FLAGS
102      "-compatibility_version 1"
103      "-install_name /usr/lib/libc++abi.1.dylib")
104  endif()
105
106  if (LLVM_USE_SANITIZER)
107    if (("${LLVM_USE_SANITIZER}" STREQUAL "Address") OR
108        ("${LLVM_USE_SANITIZER}" STREQUAL "Address;Undefined") OR
109        ("${LLVM_USE_SANITIZER}" STREQUAL "Undefined;Address"))
110      set(LIBFILE "libclang_rt.asan_osx_dynamic.dylib")
111    elseif("${LLVM_USE_SANITIZER}" STREQUAL "Undefined")
112      set(LIBFILE "libclang_rt.ubsan_osx_dynamic.dylib")
113    elseif("${LLVM_USE_SANITIZER}" STREQUAL "Thread")
114      set(LIBFILE "libclang_rt.tsan_osx_dynamic.dylib")
115    else()
116      message(WARNING "LLVM_USE_SANITIZER=${LLVM_USE_SANITIZER} is not supported on OS X")
117    endif()
118    if (LIBFILE)
119      find_compiler_rt_dir(LIBDIR)
120      if (NOT IS_DIRECTORY "${LIBDIR}")
121        message(FATAL_ERROR "Cannot find compiler-rt directory on OS X required for LLVM_USE_SANITIZER")
122      endif()
123      set(LIBCXXABI_SANITIZER_LIBRARY "${LIBDIR}/${LIBFILE}")
124      set(LIBCXXABI_SANITIZER_LIBRARY "${LIBCXXABI_SANITIZER_LIBRARY}" PARENT_SCOPE)
125      message(STATUS "Manually linking compiler-rt library: ${LIBCXXABI_SANITIZER_LIBRARY}")
126      add_library_flags("${LIBCXXABI_SANITIZER_LIBRARY}")
127      add_link_flags("-Wl,-rpath,${LIBDIR}")
128    endif()
129  endif()
130endif()
131
132split_list(LIBCXXABI_COMPILE_FLAGS)
133split_list(LIBCXXABI_LINK_FLAGS)
134split_list(LIBCXXABI_SHARED_LINK_FLAGS)
135
136# FIXME: libc++abi.so will not link when modules are enabled because it depends
137# on symbols defined in libc++.so which has not yet been built.
138if (LLVM_ENABLE_MODULES)
139  string(REPLACE "-Wl,-z,defs" "" CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
140endif()
141
142# Add a object library that contains the compiled source files.
143add_library(cxxabi_objects OBJECT ${LIBCXXABI_SOURCES} ${LIBCXXABI_HEADERS})
144set_target_properties(cxxabi_objects
145                      PROPERTIES
146                        CXX_EXTENSIONS
147                          OFF
148                        CXX_STANDARD
149                          11
150                        CXX_STANDARD_REQUIRED
151                          ON
152                        COMPILE_FLAGS
153                          "${LIBCXXABI_COMPILE_FLAGS}"
154                        POSITION_INDEPENDENT_CODE
155                          ON)
156
157# Build the shared library.
158if (LIBCXXABI_ENABLE_SHARED)
159  add_library(cxxabi_shared SHARED $<TARGET_OBJECTS:cxxabi_objects>)
160  if(COMMAND llvm_setup_rpath)
161    llvm_setup_rpath(cxxabi_shared)
162  endif()
163  target_link_libraries(cxxabi_shared ${LIBCXXABI_LIBRARIES} ${LIBCXXABI_SHARED_LIBRARIES})
164  set_target_properties(cxxabi_shared
165                        PROPERTIES
166                          CXX_EXTENSIONS
167                            OFF
168                          CXX_STANDARD
169                            11
170                          CXX_STANDARD_REQUIRED
171                            ON
172                          LINK_FLAGS
173                            "${LIBCXXABI_LINK_FLAGS} ${LIBCXXABI_SHARED_LINK_FLAGS}"
174                          OUTPUT_NAME
175                            "c++abi"
176                          POSITION_INDEPENDENT_CODE
177                            ON
178                          SOVERSION
179                            "1"
180                          VERSION
181                            "1.0")
182  list(APPEND LIBCXXABI_BUILD_TARGETS "cxxabi_shared")
183  if (LIBCXXABI_INSTALL_SHARED_LIBRARY)
184    list(APPEND LIBCXXABI_INSTALL_TARGETS "cxxabi_shared")
185  endif()
186endif()
187
188# Build the static library.
189if (LIBCXXABI_ENABLE_STATIC)
190  set(cxxabi_static_sources $<TARGET_OBJECTS:cxxabi_objects>)
191  if (LIBCXXABI_USE_LLVM_UNWINDER AND LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_STATIC_LIBRARY)
192    if (TARGET unwind_static OR HAVE_LIBUNWIND)
193      list(APPEND cxxabi_static_sources $<TARGET_OBJECTS:unwind_objects>)
194    endif()
195  endif()
196  add_library(cxxabi_static STATIC ${cxxabi_static_sources})
197  target_link_libraries(cxxabi_static ${LIBCXXABI_LIBRARIES} ${LIBCXXABI_STATIC_LIBRARIES})
198  set_target_properties(cxxabi_static
199                        PROPERTIES
200                          CXX_EXTENSIONS
201                            OFF
202                          CXX_STANDARD
203                            11
204                          CXX_STANDARD_REQUIRED
205                            ON
206                          LINK_FLAGS
207                            "${LIBCXXABI_LINK_FLAGS}"
208                          OUTPUT_NAME
209                            "c++abi"
210                          POSITION_INDEPENDENT_CODE
211                            ON)
212  list(APPEND LIBCXXABI_BUILD_TARGETS "cxxabi_static")
213  if (LIBCXXABI_INSTALL_STATIC_LIBRARY)
214    list(APPEND LIBCXXABI_INSTALL_TARGETS "cxxabi_static")
215  endif()
216endif()
217
218# Add a meta-target for both libraries.
219add_custom_target(cxxabi DEPENDS ${LIBCXXABI_BUILD_TARGETS})
220
221if (LIBCXXABI_INSTALL_LIBRARY)
222  install(TARGETS ${LIBCXXABI_INSTALL_TARGETS}
223    LIBRARY DESTINATION ${LIBCXXABI_INSTALL_PREFIX}lib${LIBCXXABI_LIBDIR_SUFFIX} COMPONENT cxxabi
224    ARCHIVE DESTINATION ${LIBCXXABI_INSTALL_PREFIX}lib${LIBCXXABI_LIBDIR_SUFFIX} COMPONENT cxxabi
225    )
226endif()
227
228if (NOT CMAKE_CONFIGURATION_TYPES AND LIBCXXABI_INSTALL_LIBRARY)
229  add_custom_target(install-cxxabi
230    DEPENDS cxxabi
231    COMMAND "${CMAKE_COMMAND}"
232            -DCMAKE_INSTALL_COMPONENT=cxxabi
233            -P "${LIBCXXABI_BINARY_DIR}/cmake_install.cmake")
234  add_custom_target(install-cxxabi-stripped
235    DEPENDS cxxabi
236    COMMAND "${CMAKE_COMMAND}"
237            -DCMAKE_INSTALL_COMPONENT=cxxabi
238            -DCMAKE_INSTALL_DO_STRIP=1
239            -P "${LIBCXXABI_BINARY_DIR}/cmake_install.cmake")
240
241  # TODO: This is a legacy target name and should be removed at some point.
242  add_custom_target(install-libcxxabi DEPENDS install-cxxabi)
243endif()
244