Eric Fiselier | 9071bc0 | 2014-10-18 01:15:17 +0000 | [diff] [blame] | 1 | |
| 2 | #=============================================================================== |
| 3 | # Add an ABI library if appropriate |
| 4 | #=============================================================================== |
| 5 | |
| 6 | # |
| 7 | # _setup_abi: Set up the build to use an ABI library |
| 8 | # |
| 9 | # Parameters: |
| 10 | # abidefines: A list of defines needed to compile libc++ with the ABI library |
Eric Fiselier | cb7e32c | 2014-10-19 00:42:41 +0000 | [diff] [blame] | 11 | # abilib : The ABI library to link against. |
Eric Fiselier | 9071bc0 | 2014-10-18 01:15:17 +0000 | [diff] [blame] | 12 | # abifiles : A list of files (which may be relative paths) to copy into the |
Richard Smith | 5a60459 | 2017-01-05 02:55:10 +0000 | [diff] [blame] | 13 | # libc++ build tree for the build. These files will be copied |
| 14 | # twice: once into include/, so the libc++ build itself can find |
| 15 | # them, and once into include/c++/v1, so that a clang built into |
| 16 | # the same build area will find them. These files will also be |
Eric Fiselier | 9071bc0 | 2014-10-18 01:15:17 +0000 | [diff] [blame] | 17 | # installed alongside the libc++ headers. |
| 18 | # abidirs : A list of relative paths to create under an include directory |
| 19 | # in the libc++ build directory. |
| 20 | # |
Eric Fiselier | bde2871 | 2017-01-16 20:47:35 +0000 | [diff] [blame] | 21 | |
Eric Fiselier | 02c24c1 | 2015-03-19 20:59:45 +0000 | [diff] [blame] | 22 | macro(setup_abi_lib abidefines abilib abifiles abidirs) |
Eric Fiselier | 9a1468f | 2014-11-15 17:25:23 +0000 | [diff] [blame] | 23 | list(APPEND LIBCXX_COMPILE_FLAGS ${abidefines}) |
Eric Fiselier | 02c24c1 | 2015-03-19 20:59:45 +0000 | [diff] [blame] | 24 | set(LIBCXX_CXX_ABI_INCLUDE_PATHS "${LIBCXX_CXX_ABI_INCLUDE_PATHS}" |
Eric Fiselier | 9071bc0 | 2014-10-18 01:15:17 +0000 | [diff] [blame] | 25 | CACHE PATH |
| 26 | "Paths to C++ ABI header directories separated by ';'." FORCE |
| 27 | ) |
Eric Fiselier | 1eb7445 | 2016-05-27 23:05:37 +0000 | [diff] [blame] | 28 | set(LIBCXX_CXX_ABI_LIBRARY_PATH "${LIBCXX_CXX_ABI_LIBRARY_PATH}" |
| 29 | CACHE PATH |
| 30 | "Paths to C++ ABI library directory" |
| 31 | ) |
Eric Fiselier | cb7e32c | 2014-10-19 00:42:41 +0000 | [diff] [blame] | 32 | set(LIBCXX_CXX_ABI_LIBRARY ${abilib}) |
Eric Fiselier | 9071bc0 | 2014-10-18 01:15:17 +0000 | [diff] [blame] | 33 | set(LIBCXX_ABILIB_FILES ${abifiles}) |
| 34 | |
Eric Fiselier | 9071bc0 | 2014-10-18 01:15:17 +0000 | [diff] [blame] | 35 | foreach(fpath ${LIBCXX_ABILIB_FILES}) |
| 36 | set(found FALSE) |
Eric Fiselier | 02c24c1 | 2015-03-19 20:59:45 +0000 | [diff] [blame] | 37 | foreach(incpath ${LIBCXX_CXX_ABI_INCLUDE_PATHS}) |
Eric Fiselier | 9071bc0 | 2014-10-18 01:15:17 +0000 | [diff] [blame] | 38 | if (EXISTS "${incpath}/${fpath}") |
| 39 | set(found TRUE) |
| 40 | get_filename_component(dstdir ${fpath} PATH) |
| 41 | get_filename_component(ifile ${fpath} NAME) |
Petr Hosek | f48515b | 2018-06-12 03:10:02 +0000 | [diff] [blame] | 42 | set(src ${incpath}/${fpath}) |
| 43 | |
Petr Hosek | 84f9609 | 2018-10-04 05:38:53 +0000 | [diff] [blame] | 44 | set(dst ${LIBCXX_BINARY_INCLUDE_DIR}/${dstdir}/${ifile}) |
Petr Hosek | f48515b | 2018-06-12 03:10:02 +0000 | [diff] [blame] | 45 | add_custom_command(OUTPUT ${dst} |
| 46 | DEPENDS ${src} |
| 47 | COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src} ${dst} |
| 48 | COMMENT "Copying C++ ABI header ${fpath}...") |
| 49 | list(APPEND abilib_headers "${dst}") |
| 50 | |
Petr Hosek | 162ce3f | 2018-07-25 22:57:39 +0000 | [diff] [blame] | 51 | if (NOT LIBCXX_USING_INSTALLED_LLVM AND LIBCXX_HEADER_DIR) |
Petr Hosek | 83f3cdc | 2018-07-24 15:49:29 +0000 | [diff] [blame] | 52 | set(dst "${LIBCXX_HEADER_DIR}/include/c++/v1/${dstdir}/${fpath}") |
| 53 | add_custom_command(OUTPUT ${dst} |
| 54 | DEPENDS ${src} |
| 55 | COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src} ${dst} |
| 56 | COMMENT "Copying C++ ABI header ${fpath}...") |
| 57 | list(APPEND abilib_headers "${dst}") |
| 58 | endif() |
Petr Hosek | f48515b | 2018-06-12 03:10:02 +0000 | [diff] [blame] | 59 | |
Eric Fiselier | 961269d | 2015-08-26 20:18:21 +0000 | [diff] [blame] | 60 | if (LIBCXX_INSTALL_HEADERS) |
Eric Fiselier | bde2871 | 2017-01-16 20:47:35 +0000 | [diff] [blame] | 61 | install(FILES "${LIBCXX_BINARY_INCLUDE_DIR}/${fpath}" |
Petr Hosek | 4d34ec0 | 2018-07-20 22:45:24 +0000 | [diff] [blame] | 62 | DESTINATION ${LIBCXX_INSTALL_HEADER_PREFIX}include/c++/v1/${dstdir} |
Eric Fiselier | 4746c1e | 2017-11-25 23:39:17 +0000 | [diff] [blame] | 63 | COMPONENT cxx-headers |
Eric Fiselier | 961269d | 2015-08-26 20:18:21 +0000 | [diff] [blame] | 64 | PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ |
| 65 | ) |
| 66 | endif() |
Eric Fiselier | 9071bc0 | 2014-10-18 01:15:17 +0000 | [diff] [blame] | 67 | endif() |
| 68 | endforeach() |
| 69 | if (NOT found) |
Dan Albert | f42a8e6 | 2015-02-10 18:46:57 +0000 | [diff] [blame] | 70 | message(WARNING "Failed to find ${fpath}") |
Eric Fiselier | 9071bc0 | 2014-10-18 01:15:17 +0000 | [diff] [blame] | 71 | endif() |
| 72 | endforeach() |
| 73 | |
Eric Fiselier | bde2871 | 2017-01-16 20:47:35 +0000 | [diff] [blame] | 74 | include_directories("${LIBCXX_BINARY_INCLUDE_DIR}") |
Petr Hosek | 204d5ec | 2018-06-12 06:58:06 +0000 | [diff] [blame] | 75 | add_custom_target(cxx_abi_headers ALL DEPENDS ${abilib_headers}) |
| 76 | set(LIBCXX_CXX_ABI_HEADER_TARGET "cxx_abi_headers") |
Eric Fiselier | 9071bc0 | 2014-10-18 01:15:17 +0000 | [diff] [blame] | 77 | endmacro() |
| 78 | |
Eric Fiselier | eb6e2ea | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 79 | |
| 80 | # Configure based on the selected ABI library. |
Eric Fiselier | 9071bc0 | 2014-10-18 01:15:17 +0000 | [diff] [blame] | 81 | if ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libstdc++" OR |
| 82 | "${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libsupc++") |
| 83 | set(_LIBSUPCXX_INCLUDE_FILES |
| 84 | cxxabi.h bits/c++config.h bits/os_defines.h bits/cpu_defines.h |
| 85 | bits/cxxabi_tweaks.h bits/cxxabi_forced.h |
| 86 | ) |
| 87 | if ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libstdc++") |
| 88 | set(_LIBSUPCXX_DEFINES "-DLIBSTDCXX") |
| 89 | set(_LIBSUPCXX_LIBNAME stdc++) |
| 90 | else() |
| 91 | set(_LIBSUPCXX_DEFINES "") |
| 92 | set(_LIBSUPCXX_LIBNAME supc++) |
| 93 | endif() |
Eric Fiselier | 02c24c1 | 2015-03-19 20:59:45 +0000 | [diff] [blame] | 94 | setup_abi_lib( |
Eric Fiselier | 9071bc0 | 2014-10-18 01:15:17 +0000 | [diff] [blame] | 95 | "-D__GLIBCXX__ ${_LIBSUPCXX_DEFINES}" |
| 96 | "${_LIBSUPCXX_LIBNAME}" "${_LIBSUPCXX_INCLUDE_FILES}" "bits" |
| 97 | ) |
| 98 | elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libcxxabi") |
| 99 | if (LIBCXX_CXX_ABI_INTREE) |
| 100 | # Link against just-built "cxxabi" target. |
Petr Hosek | 44ef94a | 2018-07-24 07:06:17 +0000 | [diff] [blame] | 101 | if (LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY) |
| 102 | set(CXXABI_LIBNAME cxxabi_static) |
Eric Fiselier | c0b166e | 2015-03-03 15:59:51 +0000 | [diff] [blame] | 103 | else() |
Petr Hosek | 44ef94a | 2018-07-24 07:06:17 +0000 | [diff] [blame] | 104 | set(CXXABI_LIBNAME cxxabi_shared) |
Eric Fiselier | c0b166e | 2015-03-03 15:59:51 +0000 | [diff] [blame] | 105 | endif() |
Eric Fiselier | 45969ec | 2015-02-21 02:26:24 +0000 | [diff] [blame] | 106 | set(LIBCXX_LIBCPPABI_VERSION "2" PARENT_SCOPE) |
Eric Fiselier | 9071bc0 | 2014-10-18 01:15:17 +0000 | [diff] [blame] | 107 | else() |
| 108 | # Assume c++abi is installed in the system, rely on -lc++abi link flag. |
| 109 | set(CXXABI_LIBNAME "c++abi") |
| 110 | endif() |
Eric Fiselier | 1edf316 | 2017-02-10 08:57:35 +0000 | [diff] [blame] | 111 | set(HEADERS "cxxabi.h;__cxxabi_config.h") |
| 112 | if (LIBCXX_CXX_ABI_SYSTEM) |
| 113 | set(HEADERS "") |
| 114 | endif() |
| 115 | setup_abi_lib("-DLIBCXX_BUILDING_LIBCXXABI" ${CXXABI_LIBNAME} "${HEADERS}" "") |
Eric Fiselier | 9071bc0 | 2014-10-18 01:15:17 +0000 | [diff] [blame] | 116 | elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libcxxrt") |
Eric Fiselier | 02c24c1 | 2015-03-19 20:59:45 +0000 | [diff] [blame] | 117 | setup_abi_lib("-DLIBCXXRT" |
Eric Fiselier | 9071bc0 | 2014-10-18 01:15:17 +0000 | [diff] [blame] | 118 | "cxxrt" "cxxabi.h;unwind.h;unwind-arm.h;unwind-itanium.h" "" |
| 119 | ) |
Eric Fiselier | bde2871 | 2017-01-16 20:47:35 +0000 | [diff] [blame] | 120 | elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "vcruntime") |
| 121 | # Nothing TODO |
Eric Fiselier | cfc5515 | 2017-01-03 01:18:48 +0000 | [diff] [blame] | 122 | elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "none") |
| 123 | list(APPEND LIBCXX_COMPILE_FLAGS "-D_LIBCPP_BUILDING_HAS_NO_ABI_LIBRARY") |
| 124 | elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "default") |
| 125 | # Nothing TODO |
| 126 | else() |
Eric Fiselier | 9071bc0 | 2014-10-18 01:15:17 +0000 | [diff] [blame] | 127 | message(FATAL_ERROR |
Eric Fiselier | cfc5515 | 2017-01-03 01:18:48 +0000 | [diff] [blame] | 128 | "Unsupported c++ abi: '${LIBCXX_CXX_ABI_LIBNAME}'. \ |
| 129 | Currently libstdc++, libsupc++, libcxxabi, libcxxrt, default and none are |
| 130 | supported for c++ abi." |
Eric Fiselier | 9071bc0 | 2014-10-18 01:15:17 +0000 | [diff] [blame] | 131 | ) |
Dan Albert | 062d0a6 | 2015-02-05 23:56:33 +0000 | [diff] [blame] | 132 | endif () |