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