150
|
1 # See www/CMake.html for instructions on how to build libcxxabi with CMake.
|
|
2
|
173
|
3 if (NOT IS_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/../libcxx")
|
|
4 message(FATAL_ERROR "libc++abi now requires being built in a monorepo layout with libcxx available")
|
|
5 endif()
|
|
6
|
150
|
7 #===============================================================================
|
|
8 # Setup Project
|
|
9 #===============================================================================
|
|
10
|
|
11 cmake_minimum_required(VERSION 3.4.3)
|
|
12
|
|
13 if(POLICY CMP0042)
|
|
14 cmake_policy(SET CMP0042 NEW) # Set MACOSX_RPATH=YES by default
|
|
15 endif()
|
|
16
|
|
17 # Add path for custom modules
|
|
18 set(CMAKE_MODULE_PATH
|
|
19 "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
|
|
20 "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules"
|
|
21 ${CMAKE_MODULE_PATH}
|
|
22 )
|
|
23
|
|
24 if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR LIBCXXABI_STANDALONE_BUILD)
|
|
25 project(libcxxabi CXX C)
|
|
26
|
|
27 set(PACKAGE_NAME libcxxabi)
|
|
28 set(PACKAGE_VERSION 11.0.0git)
|
|
29 set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
|
|
30 set(PACKAGE_BUGREPORT "llvm-bugs@lists.llvm.org")
|
|
31
|
|
32 # Find the LLVM sources and simulate LLVM CMake options.
|
|
33 include(HandleOutOfTreeLLVM)
|
|
34 endif()
|
|
35
|
|
36 # Require out of source build.
|
|
37 include(MacroEnsureOutOfSourceBuild)
|
|
38 MACRO_ENSURE_OUT_OF_SOURCE_BUILD(
|
|
39 "${PROJECT_NAME} requires an out of source build. Please create a separate
|
|
40 build directory and run 'cmake /path/to/${PROJECT_NAME} [options]' there."
|
|
41 )
|
|
42
|
|
43 #===============================================================================
|
|
44 # Setup CMake Options
|
|
45 #===============================================================================
|
|
46 include(CMakeDependentOption)
|
|
47 include(HandleCompilerRT)
|
|
48
|
|
49 # Define options.
|
|
50 option(LIBCXXABI_ENABLE_EXCEPTIONS
|
|
51 "Provide support for exceptions in the runtime.
|
|
52 When disabled, libc++abi does not support stack unwinding and other exceptions-related features." ON)
|
|
53 option(LIBCXXABI_ENABLE_ASSERTIONS "Enable assertions independent of build mode." ON)
|
|
54 option(LIBCXXABI_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
|
|
55 option(LIBCXXABI_ENABLE_PIC "Build Position-Independent Code, even in static library" ON)
|
|
56 option(LIBCXXABI_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
|
|
57 option(LIBCXXABI_USE_LLVM_UNWINDER "Build and use the LLVM unwinder." OFF)
|
|
58 option(LIBCXXABI_ENABLE_STATIC_UNWINDER "Statically link the LLVM unwinder." OFF)
|
|
59 option(LIBCXXABI_USE_COMPILER_RT "Use compiler-rt instead of libgcc" OFF)
|
|
60 option(LIBCXXABI_ENABLE_THREADS "Build with threads enabled" ON)
|
|
61 option(LIBCXXABI_HAS_PTHREAD_API "Ignore auto-detection and force use of pthread API" OFF)
|
|
62 option(LIBCXXABI_HAS_EXTERNAL_THREAD_API
|
|
63 "Build libc++abi with an externalized threading API.
|
|
64 This option may only be set to ON when LIBCXXABI_ENABLE_THREADS=ON." OFF)
|
|
65 option(LIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY
|
|
66 "Build libc++abi with an externalized threading library.
|
|
67 This option may only be set to ON when LIBCXXABI_ENABLE_THREADS=ON" OFF)
|
173
|
68 option(LIBCXXABI_ENABLE_FORGIVING_DYNAMIC_CAST
|
|
69 "Make dynamic_cast more forgiving when type_info's mistakenly have hidden \
|
|
70 visibility, and thus multiple type_infos can exist for a single type. \
|
|
71 When the dynamic_cast would normally fail, this option will cause the \
|
|
72 library to try comparing the type_info names to see if they are equal \
|
|
73 instead." OFF)
|
150
|
74
|
|
75 # FIXME: This option should default to off. Unfortunatly GCC 4.9 fails to link
|
|
76 # programs to due undefined references to new/delete in libc++abi. Once this
|
|
77 # has been fixed or worked around the default value should be changed.
|
173
|
78 # See https://reviews.llvm.org/D68269 for more details.
|
150
|
79 option(LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS
|
|
80 "Build libc++abi with definitions for operator new/delete. Normally libc++
|
|
81 provides these definitions" ON)
|
|
82 option(LIBCXXABI_BUILD_32_BITS "Build 32 bit libc++abi." ${LLVM_BUILD_32_BITS})
|
|
83 option(LIBCXXABI_INCLUDE_TESTS "Generate build targets for the libc++abi unit tests." ${LLVM_INCLUDE_TESTS})
|
|
84 set(LIBCXXABI_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING
|
|
85 "Define suffix of library directory name (32/64)")
|
|
86 option(LIBCXXABI_INSTALL_LIBRARY "Install the libc++abi library." ON)
|
|
87 set(LIBCXXABI_TARGET_TRIPLE "" CACHE STRING "Target triple for cross compiling.")
|
|
88 set(LIBCXXABI_GCC_TOOLCHAIN "" CACHE PATH "GCC toolchain for cross compiling.")
|
|
89 set(LIBCXXABI_SYSROOT "" CACHE PATH "Sysroot for cross compiling.")
|
|
90 set(LIBCXXABI_LIBCXX_LIBRARY_PATH "" CACHE PATH "The path to libc++ library.")
|
|
91 set(LIBCXXABI_LIBRARY_VERSION "1.0" CACHE STRING
|
|
92 "Version of libc++abi. This will be reflected in the name of the shared \
|
|
93 library produced. For example, -DLIBCXXABI_LIBRARY_VERSION=x.y will \
|
|
94 result in the library being named libc++abi.x.y.dylib, along with the \
|
|
95 usual symlinks pointing to that.")
|
|
96
|
|
97 # Default to building a shared library so that the default options still test
|
|
98 # the libc++abi that is being built. There are two problems with testing a
|
|
99 # static libc++abi. In the case of a standalone build, the tests will link the
|
|
100 # system's libc++, which might not have been built against our libc++abi. In the
|
|
101 # case of an in tree build, libc++ will prefer a dynamic libc++abi from the
|
|
102 # system over a static libc++abi from the output directory.
|
|
103 option(LIBCXXABI_ENABLE_SHARED "Build libc++abi as a shared library." ON)
|
|
104 option(LIBCXXABI_ENABLE_STATIC "Build libc++abi as a static library." ON)
|
|
105
|
|
106 cmake_dependent_option(LIBCXXABI_INSTALL_STATIC_LIBRARY
|
|
107 "Install the static libc++abi library." ON
|
|
108 "LIBCXXABI_ENABLE_STATIC;LIBCXXABI_INSTALL_LIBRARY" OFF)
|
|
109 cmake_dependent_option(LIBCXXABI_INSTALL_SHARED_LIBRARY
|
|
110 "Install the shared libc++abi library." ON
|
|
111 "LIBCXXABI_ENABLE_SHARED;LIBCXXABI_INSTALL_LIBRARY" OFF)
|
|
112
|
|
113 cmake_dependent_option(LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_STATIC_LIBRARY
|
|
114 "Statically link the LLVM unwinder to static library" ON
|
|
115 "LIBCXXABI_ENABLE_STATIC_UNWINDER;LIBCXXABI_ENABLE_STATIC" OFF)
|
|
116 cmake_dependent_option(LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_SHARED_LIBRARY
|
|
117 "Statically link the LLVM unwinder to shared library" ON
|
|
118 "LIBCXXABI_ENABLE_STATIC_UNWINDER;LIBCXXABI_ENABLE_SHARED" OFF)
|
|
119
|
|
120 option(LIBCXXABI_BAREMETAL "Build libc++abi for baremetal targets." OFF)
|
|
121 # The default terminate handler attempts to demangle uncaught exceptions, which
|
|
122 # causes extra I/O and demangling code to be pulled in.
|
|
123 option(LIBCXXABI_SILENT_TERMINATE "Set this to make the terminate handler default to a silent alternative" OFF)
|
|
124
|
|
125 if (NOT LIBCXXABI_ENABLE_SHARED AND NOT LIBCXXABI_ENABLE_STATIC)
|
|
126 message(FATAL_ERROR "libc++abi must be built as either a shared or static library.")
|
|
127 endif()
|
|
128
|
|
129 if (LLVM_EXTERNAL_LIBCXX_SOURCE_DIR)
|
|
130 set(LIBCXXABI_LIBCXX_SRC_DIRS ${LLVM_EXTERNAL_LIBCXX_SOURCE_DIR})
|
|
131 else()
|
|
132 set(LIBCXXABI_LIBCXX_SRC_DIRS
|
|
133 "${LLVM_MAIN_SRC_DIR}/projects/libcxx"
|
|
134 "${LLVM_MAIN_SRC_DIR}/runtimes/libcxx"
|
|
135 "${LLVM_MAIN_SRC_DIR}/../libcxx"
|
|
136 )
|
|
137 endif()
|
|
138
|
|
139 set(LIBCXXABI_LIBCXX_INCLUDE_DIRS "")
|
|
140 foreach(dir ${LIBCXXABI_LIBCXX_SRC_DIRS})
|
|
141 list(APPEND LIBCXXABI_LIBCXX_INCLUDE_DIRS "${dir}/include")
|
|
142 endforeach()
|
|
143
|
|
144 find_path(
|
|
145 LIBCXXABI_LIBCXX_INCLUDES
|
|
146 __config
|
|
147 PATHS ${LIBCXXABI_LIBCXX_INCLUDES}
|
|
148 ${LIBCXXABI_LIBCXX_PATH}/include
|
|
149 ${CMAKE_BINARY_DIR}/${LIBCXXABI_LIBCXX_INCLUDES}
|
|
150 ${LIBCXXABI_LIBCXX_INCLUDE_DIRS}
|
|
151 ${LLVM_INCLUDE_DIR}/c++/v1
|
|
152 NO_DEFAULT_PATH
|
|
153 NO_CMAKE_FIND_ROOT_PATH
|
|
154 )
|
|
155
|
|
156 set(LIBCXXABI_LIBCXX_INCLUDES "${LIBCXXABI_LIBCXX_INCLUDES}" CACHE PATH
|
|
157 "Specify path to libc++ includes." FORCE)
|
|
158
|
|
159 find_path(
|
|
160 LIBCXXABI_LIBCXX_PATH
|
|
161 utils/libcxx/test/__init__.py
|
|
162 PATHS ${LIBCXXABI_LIBCXX_PATH}
|
|
163 ${LIBCXXABI_LIBCXX_INCLUDES}/../
|
|
164 ${LIBCXXABI_LIBCXX_SRC_DIRS}
|
|
165 NO_DEFAULT_PATH
|
|
166 NO_CMAKE_FIND_ROOT_PATH
|
|
167 )
|
|
168
|
|
169 if (LIBCXXABI_LIBCXX_PATH STREQUAL "LIBCXXABI_LIBCXX_PATH-NOTFOUND")
|
|
170 message(WARNING "LIBCXXABI_LIBCXX_PATH was not specified and couldn't be infered.")
|
|
171 set(LIBCXXABI_LIBCXX_PATH "")
|
|
172 endif()
|
|
173
|
|
174 set(LIBCXXABI_LIBCXX_PATH "${LIBCXXABI_LIBCXX_PATH}" CACHE PATH
|
|
175 "Specify path to libc++ source." FORCE)
|
|
176
|
|
177 option(LIBCXXABI_HERMETIC_STATIC_LIBRARY
|
|
178 "Do not export any symbols from the static library." OFF)
|
|
179
|
|
180 #===============================================================================
|
|
181 # Configure System
|
|
182 #===============================================================================
|
|
183
|
|
184 # Add path for custom modules
|
|
185 set(CMAKE_MODULE_PATH
|
|
186 "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
|
|
187 "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules"
|
|
188 ${CMAKE_MODULE_PATH}
|
|
189 )
|
|
190
|
|
191 set(LIBCXXABI_COMPILER ${CMAKE_CXX_COMPILER})
|
|
192 set(LIBCXXABI_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
|
|
193 set(LIBCXXABI_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
|
|
194
|
|
195 string(REGEX MATCH "[0-9]+\\.[0-9]+(\\.[0-9]+)?" CLANG_VERSION
|
|
196 ${PACKAGE_VERSION})
|
|
197
|
|
198 if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
|
|
199 set(LIBCXXABI_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE}/c++)
|
|
200 set(LIBCXXABI_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE}/c++)
|
|
201 if(LIBCXX_LIBDIR_SUBDIR)
|
|
202 string(APPEND LIBCXXABI_LIBRARY_DIR /${LIBCXXABI_LIBDIR_SUBDIR})
|
|
203 string(APPEND LIBCXXABI_INSTALL_LIBRARY_DIR /${LIBCXXABI_LIBDIR_SUBDIR})
|
|
204 endif()
|
|
205 elseif(LLVM_LIBRARY_OUTPUT_INTDIR)
|
|
206 set(LIBCXXABI_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
|
|
207 set(LIBCXXABI_INSTALL_LIBRARY_DIR lib${LIBCXXABI_LIBDIR_SUFFIX})
|
|
208 else()
|
|
209 set(LIBCXXABI_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXXABI_LIBDIR_SUFFIX})
|
|
210 set(LIBCXXABI_INSTALL_LIBRARY_DIR lib${LIBCXXABI_LIBDIR_SUFFIX})
|
|
211 endif()
|
|
212
|
|
213 set(LIBCXXABI_INSTALL_PREFIX "" CACHE STRING "Define libc++abi destination prefix.")
|
|
214
|
|
215 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIBCXXABI_LIBRARY_DIR})
|
|
216 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIBCXXABI_LIBRARY_DIR})
|
|
217 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LIBCXXABI_LIBRARY_DIR})
|
|
218
|
|
219 # By default, for non-standalone builds, libcxx and libcxxabi share a library
|
|
220 # directory.
|
|
221 if (NOT LIBCXXABI_LIBCXX_LIBRARY_PATH)
|
|
222 set(LIBCXXABI_LIBCXX_LIBRARY_PATH "${LIBCXXABI_LIBRARY_DIR}" CACHE PATH
|
|
223 "The path to libc++ library." FORCE)
|
|
224 endif()
|
|
225
|
|
226 # Check that we can build with 32 bits if requested.
|
|
227 if (CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32)
|
|
228 if (LIBCXXABI_BUILD_32_BITS AND NOT LLVM_BUILD_32_BITS) # Don't duplicate the output from LLVM
|
|
229 message(STATUS "Building 32 bits executables and libraries.")
|
|
230 endif()
|
|
231 elseif(LIBCXXABI_BUILD_32_BITS)
|
|
232 message(FATAL_ERROR "LIBCXXABI_BUILD_32_BITS=ON is not supported on this platform.")
|
|
233 endif()
|
|
234
|
|
235 # Declare libc++abi configuration variables.
|
|
236 # They are intended for use as follows:
|
|
237 # LIBCXXABI_C_FLAGS: General flags for both the c++ compiler and linker.
|
|
238 # LIBCXXABI_CXX_FLAGS: General flags for both the c++ compiler and linker.
|
|
239 # LIBCXXABI_COMPILE_FLAGS: Compile only flags.
|
|
240 # LIBCXXABI_LINK_FLAGS: Linker only flags.
|
|
241 # LIBCXXABI_LIBRARIES: libraries libc++abi is linked to.
|
|
242
|
|
243 set(LIBCXXABI_C_FLAGS "")
|
|
244 set(LIBCXXABI_CXX_FLAGS "")
|
|
245 set(LIBCXXABI_COMPILE_FLAGS "")
|
|
246 set(LIBCXXABI_LINK_FLAGS "")
|
|
247 set(LIBCXXABI_LIBRARIES "")
|
|
248
|
|
249 # Include macros for adding and removing libc++abi flags.
|
|
250 include(HandleLibcxxabiFlags)
|
|
251
|
|
252 #===============================================================================
|
|
253 # Setup Compiler Flags
|
|
254 #===============================================================================
|
|
255
|
|
256 # Configure target flags
|
|
257 add_target_flags_if(LIBCXXABI_BUILD_32_BITS "-m32")
|
|
258
|
|
259 if(LIBCXXABI_TARGET_TRIPLE)
|
|
260 add_target_flags("--target=${LIBCXXABI_TARGET_TRIPLE}")
|
|
261 elseif(CMAKE_CXX_COMPILER_TARGET)
|
|
262 set(LIBCXXABI_TARGET_TRIPLE "${CMAKE_CXX_COMPILER_TARGET}")
|
|
263 endif()
|
|
264 if(LIBCXX_GCC_TOOLCHAIN)
|
|
265 add_target_flags("--gcc-toolchain=${LIBCXXABI_GCC_TOOLCHAIN}")
|
|
266 elseif(CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN)
|
|
267 set(LIBCXXABI_GCC_TOOLCHAIN "${CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN}")
|
|
268 endif()
|
|
269 if(LIBCXXABI_SYSROOT)
|
|
270 add_target_flags("--sysroot=${LIBCXXABI_SYSROOT}")
|
|
271 elseif(CMAKE_SYSROOT)
|
|
272 set(LIBCXXABI_SYSROOT "${CMAKE_SYSROOT}")
|
|
273 endif()
|
|
274
|
|
275 if (LIBCXXABI_TARGET_TRIPLE)
|
|
276 set(TARGET_TRIPLE "${LIBCXXABI_TARGET_TRIPLE}")
|
|
277 endif()
|
|
278
|
|
279 # Configure compiler. Must happen after setting the target flags.
|
|
280 include(config-ix)
|
|
281
|
|
282 if (LIBCXXABI_HAS_NOSTDINCXX_FLAG)
|
|
283 list(APPEND LIBCXXABI_COMPILE_FLAGS -nostdinc++)
|
|
284 # cmake 3.14 and above remove system include paths that are explicitly
|
|
285 # passed on the command line. We build with -nostdinc++ and explicitly add
|
|
286 # just the libcxx system include paths with -I on the command line.
|
|
287 # Setting CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES effectively prevents cmake
|
|
288 # from removing these.
|
|
289 # See: https://gitlab.kitware.com/cmake/cmake/issues/19227
|
|
290 set(CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES "")
|
|
291 # Remove -stdlib flags to prevent them from causing an unused flag warning.
|
|
292 string(REPLACE "-stdlib=libc++" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
|
293 string(REPLACE "-stdlib=libstdc++" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
|
294 endif()
|
|
295
|
|
296 # Let the library headers know they are currently being used to build the
|
|
297 # library.
|
|
298 add_definitions(-D_LIBCXXABI_BUILDING_LIBRARY)
|
|
299
|
|
300 # Disable DLL annotations on Windows for static builds.
|
|
301 if (WIN32 AND LIBCXXABI_ENABLE_STATIC AND NOT LIBCXXABI_ENABLE_SHARED)
|
|
302 add_definitions(-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS)
|
|
303 endif()
|
|
304
|
|
305 add_compile_flags_if_supported(-Werror=return-type)
|
|
306
|
|
307 # Get warning flags
|
|
308 add_compile_flags_if_supported(-W)
|
|
309 add_compile_flags_if_supported(-Wall)
|
|
310 add_compile_flags_if_supported(-Wchar-subscripts)
|
|
311 add_compile_flags_if_supported(-Wconversion)
|
|
312 add_compile_flags_if_supported(-Wmismatched-tags)
|
|
313 add_compile_flags_if_supported(-Wmissing-braces)
|
|
314 add_compile_flags_if_supported(-Wnewline-eof)
|
|
315 add_compile_flags_if_supported(-Wunused-function)
|
|
316 add_compile_flags_if_supported(-Wshadow)
|
|
317 add_compile_flags_if_supported(-Wshorten-64-to-32)
|
|
318 add_compile_flags_if_supported(-Wsign-compare)
|
|
319 add_compile_flags_if_supported(-Wsign-conversion)
|
|
320 add_compile_flags_if_supported(-Wstrict-aliasing=2)
|
|
321 add_compile_flags_if_supported(-Wstrict-overflow=4)
|
|
322 add_compile_flags_if_supported(-Wunused-parameter)
|
|
323 add_compile_flags_if_supported(-Wunused-variable)
|
|
324 add_compile_flags_if_supported(-Wwrite-strings)
|
|
325 add_compile_flags_if_supported(-Wundef)
|
|
326
|
|
327 if (LIBCXXABI_ENABLE_WERROR)
|
|
328 add_compile_flags_if_supported(-Werror)
|
|
329 add_compile_flags_if_supported(-WX)
|
|
330 else()
|
|
331 add_compile_flags_if_supported(-Wno-error)
|
|
332 add_compile_flags_if_supported(-WX-)
|
|
333 endif()
|
|
334 if (LIBCXXABI_ENABLE_PEDANTIC)
|
|
335 add_compile_flags_if_supported(-pedantic)
|
|
336 endif()
|
|
337
|
|
338 # Get feature flags.
|
|
339 add_compile_flags_if_supported(-fstrict-aliasing)
|
|
340
|
|
341 # Exceptions
|
|
342 if (LIBCXXABI_ENABLE_EXCEPTIONS)
|
|
343 # Catches C++ exceptions only and tells the compiler to assume that extern C
|
|
344 # functions never throw a C++ exception.
|
|
345 add_compile_flags_if_supported(-EHsc)
|
|
346 # Do we really need to be run through the C compiler ?
|
|
347 add_c_compile_flags_if_supported(-funwind-tables)
|
|
348 else()
|
|
349 add_definitions(-D_LIBCXXABI_NO_EXCEPTIONS)
|
|
350 add_compile_flags_if_supported(-fno-exceptions)
|
|
351 add_compile_flags_if_supported(-EHs-)
|
|
352 add_compile_flags_if_supported(-EHa-)
|
|
353 endif()
|
|
354
|
|
355 # Assert
|
|
356 string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
|
|
357 if (LIBCXXABI_ENABLE_ASSERTIONS)
|
|
358 # MSVC doesn't like _DEBUG on release builds. See PR 4379.
|
|
359 if (NOT MSVC)
|
|
360 list(APPEND LIBCXXABI_COMPILE_FLAGS -D_DEBUG)
|
|
361 endif()
|
|
362 # On Release builds cmake automatically defines NDEBUG, so we
|
|
363 # explicitly undefine it:
|
|
364 if (uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE")
|
|
365 list(APPEND LIBCXXABI_COMPILE_FLAGS -UNDEBUG)
|
|
366 endif()
|
|
367 else()
|
|
368 if (NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE")
|
|
369 list(APPEND LIBCXXABI_COMPILE_FLAGS -DNDEBUG)
|
|
370 endif()
|
|
371 endif()
|
|
372 # Static library
|
|
373 if (NOT LIBCXXABI_ENABLE_SHARED)
|
|
374 list(APPEND LIBCXXABI_COMPILE_FLAGS -D_LIBCPP_BUILD_STATIC)
|
|
375 endif()
|
|
376
|
|
377 # Threading
|
|
378 if (NOT LIBCXXABI_ENABLE_THREADS)
|
|
379 if (LIBCXXABI_HAS_PTHREAD_API)
|
|
380 message(FATAL_ERROR "LIBCXXABI_HAS_PTHREAD_API can only"
|
|
381 " be set to ON when LIBCXXABI_ENABLE_THREADS"
|
|
382 " is also set to ON.")
|
|
383 endif()
|
|
384 if (LIBCXXABI_HAS_EXTERNAL_THREAD_API)
|
|
385 message(FATAL_ERROR "LIBCXXABI_HAS_EXTERNAL_THREAD_API can only"
|
|
386 " be set to ON when LIBCXXABI_ENABLE_THREADS"
|
|
387 " is also set to ON.")
|
|
388 endif()
|
|
389 if (LIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY)
|
|
390 message(FATAL_ERROR "LIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY can only"
|
|
391 " be set to ON when LIBCXXABI_ENABLE_THREADS"
|
|
392 " is also set to ON.")
|
|
393 endif()
|
|
394 add_definitions(-D_LIBCXXABI_HAS_NO_THREADS)
|
|
395 endif()
|
|
396
|
|
397 if (LIBCXXABI_HAS_EXTERNAL_THREAD_API)
|
|
398 if (LIBCXXABI_HAS_PTHREAD_API)
|
|
399 message(FATAL_ERROR "The options LIBCXXABI_HAS_EXTERNAL_THREAD_API"
|
|
400 " and LIBCXXABI_HAS_PTHREAD_API cannot be both"
|
|
401 " set to ON at the same time.")
|
|
402 endif()
|
|
403 if (LIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY)
|
|
404 message(FATAL_ERROR "The options LIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY"
|
|
405 " and LIBCXXABI_HAS_EXTERNAL_THREAD_API cannot be both"
|
|
406 " set to ON at the same time.")
|
|
407 endif()
|
|
408 endif()
|
|
409
|
|
410 if (LLVM_ENABLE_MODULES)
|
|
411 # Ignore that the rest of the modules flags are now unused.
|
|
412 add_compile_flags_if_supported(-Wno-unused-command-line-argument)
|
|
413 add_compile_flags(-fno-modules)
|
|
414 endif()
|
|
415
|
|
416 set(LIBCXXABI_HAS_UNDEFINED_SYMBOLS OFF)
|
|
417 if ((NOT LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS)
|
|
418 OR (LIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY AND LIBCXXABI_ENABLE_SHARED)
|
|
419 OR MINGW)
|
|
420 set(LIBCXXABI_HAS_UNDEFINED_SYMBOLS ON)
|
|
421 endif()
|
|
422
|
|
423 if (LIBCXXABI_HAS_UNDEFINED_SYMBOLS)
|
|
424 # Need to allow unresolved symbols if this is to work with shared library builds
|
|
425 if (APPLE)
|
|
426 list(APPEND LIBCXXABI_LINK_FLAGS "-undefined dynamic_lookup")
|
|
427 else()
|
|
428 # Relax this restriction from HandleLLVMOptions
|
|
429 string(REPLACE "-Wl,-z,defs" "" CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
|
|
430 endif()
|
|
431 endif()
|
|
432
|
|
433 if (LIBCXXABI_HAS_PTHREAD_API)
|
|
434 add_definitions(-D_LIBCPP_HAS_THREAD_API_PTHREAD)
|
|
435 endif()
|
|
436
|
|
437 if (LIBCXXABI_HAS_EXTERNAL_THREAD_API)
|
|
438 add_definitions(-D_LIBCPP_HAS_THREAD_API_EXTERNAL)
|
|
439 endif()
|
|
440
|
|
441 if (LIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY)
|
|
442 add_definitions(-D_LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL)
|
|
443 endif()
|
|
444
|
|
445 # Prevent libc++abi from having library dependencies on libc++
|
|
446 add_definitions(-D_LIBCPP_DISABLE_EXTERN_TEMPLATE)
|
|
447
|
|
448 # Bring back `std::unexpected`, which is removed in C++17, to support
|
|
449 # pre-C++17.
|
|
450 add_definitions(-D_LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS)
|
|
451
|
|
452 if (MSVC)
|
|
453 add_definitions(-D_CRT_SECURE_NO_WARNINGS)
|
|
454 endif()
|
|
455
|
|
456 # Define LIBCXXABI_USE_LLVM_UNWINDER for conditional compilation.
|
|
457 if (LIBCXXABI_USE_LLVM_UNWINDER)
|
|
458 add_definitions(-DLIBCXXABI_USE_LLVM_UNWINDER)
|
|
459 endif()
|
|
460
|
|
461 if (LIBCXXABI_SILENT_TERMINATE)
|
|
462 add_definitions(-DLIBCXXABI_SILENT_TERMINATE)
|
|
463 endif()
|
|
464
|
|
465 if (LIBCXXABI_BAREMETAL)
|
|
466 add_definitions(-DLIBCXXABI_BAREMETAL)
|
|
467 endif()
|
|
468
|
|
469 if (LIBCXXABI_HAS_COMMENT_LIB_PRAGMA)
|
|
470 if (LIBCXXABI_HAS_PTHREAD_LIB)
|
|
471 add_definitions(-D_LIBCXXABI_LINK_PTHREAD_LIB)
|
|
472 endif()
|
|
473 endif()
|
|
474
|
|
475 string(REPLACE ";" " " LIBCXXABI_CXX_FLAGS "${LIBCXXABI_CXX_FLAGS}")
|
|
476 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LIBCXXABI_CXX_FLAGS}")
|
|
477 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${LIBCXXABI_C_FLAGS}")
|
|
478
|
|
479 #===============================================================================
|
|
480 # Setup Source Code
|
|
481 #===============================================================================
|
|
482
|
|
483 set(LIBCXXABI_LIBUNWIND_INCLUDES "${LIBCXXABI_LIBUNWIND_INCLUDES}" CACHE PATH
|
|
484 "Specify path to libunwind includes." FORCE)
|
|
485 set(LIBCXXABI_LIBUNWIND_PATH "${LIBCXXABI_LIBUNWIND_PATH}" CACHE PATH
|
|
486 "Specify path to libunwind source." FORCE)
|
|
487
|
|
488 include_directories(include)
|
|
489 if (LIBCXXABI_USE_LLVM_UNWINDER OR LLVM_NATIVE_ARCH MATCHES ARM)
|
|
490 find_path(LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL libunwind.h
|
|
491 PATHS ${LIBCXXABI_LIBUNWIND_INCLUDES}
|
|
492 ${LIBCXXABI_LIBUNWIND_PATH}/include
|
|
493 ${CMAKE_BINARY_DIR}/${LIBCXXABI_LIBUNWIND_INCLUDES}
|
|
494 ${LLVM_MAIN_SRC_DIR}/projects/libunwind/include
|
|
495 ${LLVM_MAIN_SRC_DIR}/runtimes/libunwind/include
|
|
496 ${LLVM_MAIN_SRC_DIR}/../libunwind/include
|
|
497 NO_DEFAULT_PATH
|
|
498 NO_CMAKE_FIND_ROOT_PATH
|
|
499 )
|
|
500
|
|
501 if (LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL STREQUAL "LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL-NOTFOUND")
|
|
502 set(LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL "")
|
|
503 endif()
|
|
504
|
|
505 if (NOT LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL STREQUAL "")
|
|
506 include_directories("${LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL}")
|
|
507 endif()
|
|
508 endif()
|
|
509
|
|
510 # Add source code. This also contains all of the logic for deciding linker flags
|
|
511 # soname, etc...
|
|
512 add_subdirectory(src)
|
|
513
|
|
514 if (LIBCXXABI_INCLUDE_TESTS)
|
|
515 if (LIBCXXABI_STANDALONE_BUILD AND NOT LIBCXXABI_ENABLE_SHARED)
|
|
516 # We can't reasonably test the system C++ library with a static
|
|
517 # libc++abi. We either need to be able to replace libc++abi at
|
|
518 # run time (with a shared libc++abi), or we need to be able to
|
|
519 # replace the C++ runtime (with a non- standalone build).
|
|
520 message(WARNING "The libc++abi tests aren't valid when libc++abi "
|
|
521 "is built standalone (i.e. outside of "
|
|
522 "llvm/projects/libcxxabi ) and is built without "
|
|
523 "a shared library. Either build a shared "
|
|
524 "library, build libc++abi at the same time as "
|
|
525 "you build libc++, or do without testing. No "
|
|
526 "check target will be available!")
|
|
527 else()
|
|
528 add_subdirectory(test)
|
|
529 add_subdirectory(fuzz)
|
|
530 endif()
|
|
531 endif()
|