Eric Fiselier | f234855 | 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 |
Petr Hosek | 5f81a59 | 2019-04-03 01:33:14 +0000 | [diff] [blame] | 11 | # abishared : The shared ABI library to link against. |
| 12 | # abistatic : The static ABI library to link against. |
Eric Fiselier | f234855 | 2014-10-18 01:15:17 +0000 | [diff] [blame] | 13 | # abifiles : A list of files (which may be relative paths) to copy into the |
Richard Smith | d0cd872 | 2017-01-05 02:55:10 +0000 | [diff] [blame] | 14 | # libc++ build tree for the build. These files will be copied |
| 15 | # twice: once into include/, so the libc++ build itself can find |
| 16 | # them, and once into include/c++/v1, so that a clang built into |
| 17 | # the same build area will find them. These files will also be |
Eric Fiselier | f234855 | 2014-10-18 01:15:17 +0000 | [diff] [blame] | 18 | # installed alongside the libc++ headers. |
| 19 | # abidirs : A list of relative paths to create under an include directory |
| 20 | # in the libc++ build directory. |
| 21 | # |
Eric Fiselier | 830c792 | 2017-01-16 20:47:35 +0000 | [diff] [blame] | 22 | |
Petr Hosek | 5f81a59 | 2019-04-03 01:33:14 +0000 | [diff] [blame] | 23 | macro(setup_abi_lib abidefines abishared abistatic abifiles abidirs) |
Eric Fiselier | d0e4e10 | 2014-11-15 17:25:23 +0000 | [diff] [blame] | 24 | list(APPEND LIBCXX_COMPILE_FLAGS ${abidefines}) |
Eric Fiselier | 828d6c4 | 2015-03-19 20:59:45 +0000 | [diff] [blame] | 25 | set(LIBCXX_CXX_ABI_INCLUDE_PATHS "${LIBCXX_CXX_ABI_INCLUDE_PATHS}" |
Eric Fiselier | f234855 | 2014-10-18 01:15:17 +0000 | [diff] [blame] | 26 | CACHE PATH |
| 27 | "Paths to C++ ABI header directories separated by ';'." FORCE |
| 28 | ) |
Eric Fiselier | 5c467ab | 2016-05-27 23:05:37 +0000 | [diff] [blame] | 29 | set(LIBCXX_CXX_ABI_LIBRARY_PATH "${LIBCXX_CXX_ABI_LIBRARY_PATH}" |
| 30 | CACHE PATH |
| 31 | "Paths to C++ ABI library directory" |
| 32 | ) |
Petr Hosek | 5f81a59 | 2019-04-03 01:33:14 +0000 | [diff] [blame] | 33 | set(LIBCXX_CXX_SHARED_ABI_LIBRARY ${abishared}) |
| 34 | set(LIBCXX_CXX_STATIC_ABI_LIBRARY ${abistatic}) |
Eric Fiselier | f234855 | 2014-10-18 01:15:17 +0000 | [diff] [blame] | 35 | set(LIBCXX_ABILIB_FILES ${abifiles}) |
| 36 | |
Eric Fiselier | f234855 | 2014-10-18 01:15:17 +0000 | [diff] [blame] | 37 | foreach(fpath ${LIBCXX_ABILIB_FILES}) |
| 38 | set(found FALSE) |
Eric Fiselier | 828d6c4 | 2015-03-19 20:59:45 +0000 | [diff] [blame] | 39 | foreach(incpath ${LIBCXX_CXX_ABI_INCLUDE_PATHS}) |
Sergej Jaskiewicz | 3092192 | 2020-03-11 21:00:46 +0300 | [diff] [blame] | 40 | message(STATUS "Looking for ${fpath} in ${incpath}") |
Eric Fiselier | f234855 | 2014-10-18 01:15:17 +0000 | [diff] [blame] | 41 | if (EXISTS "${incpath}/${fpath}") |
| 42 | set(found TRUE) |
Sergej Jaskiewicz | 3092192 | 2020-03-11 21:00:46 +0300 | [diff] [blame] | 43 | message(STATUS "Looking for ${fpath} in ${incpath} - found") |
Eric Fiselier | f234855 | 2014-10-18 01:15:17 +0000 | [diff] [blame] | 44 | get_filename_component(dstdir ${fpath} PATH) |
| 45 | get_filename_component(ifile ${fpath} NAME) |
Petr Hosek | 76f569a | 2018-06-12 03:10:02 +0000 | [diff] [blame] | 46 | set(src ${incpath}/${fpath}) |
| 47 | |
Petr Hosek | f9bb1d7 | 2018-10-04 05:38:53 +0000 | [diff] [blame] | 48 | set(dst ${LIBCXX_BINARY_INCLUDE_DIR}/${dstdir}/${ifile}) |
Petr Hosek | 76f569a | 2018-06-12 03:10:02 +0000 | [diff] [blame] | 49 | add_custom_command(OUTPUT ${dst} |
| 50 | DEPENDS ${src} |
| 51 | COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src} ${dst} |
| 52 | COMMENT "Copying C++ ABI header ${fpath}...") |
| 53 | list(APPEND abilib_headers "${dst}") |
| 54 | |
Louis Dionne | 94870d8 | 2020-06-26 12:08:59 -0400 | [diff] [blame] | 55 | # TODO: libc++ shouldn't be responsible for copying the libc++abi |
| 56 | # headers into the right location. |
Petr Hosek | 8003892 | 2021-04-27 23:30:53 -0700 | [diff] [blame] | 57 | set(dst "${LIBCXX_GENERATED_INCLUDE_DIR}/${dstdir}/${fpath}") |
Louis Dionne | 94870d8 | 2020-06-26 12:08:59 -0400 | [diff] [blame] | 58 | add_custom_command(OUTPUT ${dst} |
| 59 | DEPENDS ${src} |
| 60 | COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src} ${dst} |
| 61 | COMMENT "Copying C++ ABI header ${fpath}...") |
| 62 | list(APPEND abilib_headers "${dst}") |
Petr Hosek | 76f569a | 2018-06-12 03:10:02 +0000 | [diff] [blame] | 63 | |
Eric Fiselier | 68205ee | 2015-08-26 20:18:21 +0000 | [diff] [blame] | 64 | if (LIBCXX_INSTALL_HEADERS) |
Eric Fiselier | 830c792 | 2017-01-16 20:47:35 +0000 | [diff] [blame] | 65 | install(FILES "${LIBCXX_BINARY_INCLUDE_DIR}/${fpath}" |
Petr Hosek | 1756ac6 | 2021-03-31 17:34:05 -0700 | [diff] [blame] | 66 | DESTINATION include/c++/v1/${dstdir} |
Eric Fiselier | da175a9 | 2017-11-25 23:39:17 +0000 | [diff] [blame] | 67 | COMPONENT cxx-headers |
Eric Fiselier | 68205ee | 2015-08-26 20:18:21 +0000 | [diff] [blame] | 68 | PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ |
| 69 | ) |
| 70 | endif() |
Sergej Jaskiewicz | 3092192 | 2020-03-11 21:00:46 +0300 | [diff] [blame] | 71 | else() |
| 72 | message(STATUS "Looking for ${fpath} in ${incpath} - not found") |
Eric Fiselier | f234855 | 2014-10-18 01:15:17 +0000 | [diff] [blame] | 73 | endif() |
| 74 | endforeach() |
| 75 | if (NOT found) |
Sergej Jaskiewicz | 3092192 | 2020-03-11 21:00:46 +0300 | [diff] [blame] | 76 | message(WARNING "Failed to find ${fpath} in ${LIBCXX_CXX_ABI_INCLUDE_PATHS}") |
Eric Fiselier | f234855 | 2014-10-18 01:15:17 +0000 | [diff] [blame] | 77 | endif() |
| 78 | endforeach() |
| 79 | |
Eric Fiselier | 830c792 | 2017-01-16 20:47:35 +0000 | [diff] [blame] | 80 | include_directories("${LIBCXX_BINARY_INCLUDE_DIR}") |
Petr Hosek | c70331a | 2018-06-12 06:58:06 +0000 | [diff] [blame] | 81 | add_custom_target(cxx_abi_headers ALL DEPENDS ${abilib_headers}) |
| 82 | set(LIBCXX_CXX_ABI_HEADER_TARGET "cxx_abi_headers") |
Eric Fiselier | f234855 | 2014-10-18 01:15:17 +0000 | [diff] [blame] | 83 | endmacro() |
| 84 | |
Eric Fiselier | 156a46d | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 85 | |
| 86 | # Configure based on the selected ABI library. |
Eric Fiselier | f234855 | 2014-10-18 01:15:17 +0000 | [diff] [blame] | 87 | if ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libstdc++" OR |
| 88 | "${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libsupc++") |
| 89 | set(_LIBSUPCXX_INCLUDE_FILES |
| 90 | cxxabi.h bits/c++config.h bits/os_defines.h bits/cpu_defines.h |
| 91 | bits/cxxabi_tweaks.h bits/cxxabi_forced.h |
| 92 | ) |
| 93 | if ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libstdc++") |
| 94 | set(_LIBSUPCXX_DEFINES "-DLIBSTDCXX") |
| 95 | set(_LIBSUPCXX_LIBNAME stdc++) |
| 96 | else() |
| 97 | set(_LIBSUPCXX_DEFINES "") |
| 98 | set(_LIBSUPCXX_LIBNAME supc++) |
| 99 | endif() |
Eric Fiselier | 828d6c4 | 2015-03-19 20:59:45 +0000 | [diff] [blame] | 100 | setup_abi_lib( |
Eric Fiselier | f234855 | 2014-10-18 01:15:17 +0000 | [diff] [blame] | 101 | "-D__GLIBCXX__ ${_LIBSUPCXX_DEFINES}" |
Petr Hosek | 5f81a59 | 2019-04-03 01:33:14 +0000 | [diff] [blame] | 102 | "${_LIBSUPCXX_LIBNAME}" "${_LIBSUPCXX_LIBNAME}" "${_LIBSUPCXX_INCLUDE_FILES}" "bits" |
Eric Fiselier | f234855 | 2014-10-18 01:15:17 +0000 | [diff] [blame] | 103 | ) |
| 104 | elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libcxxabi") |
Alex Richardson | 91fb06a | 2020-06-18 17:07:49 +0100 | [diff] [blame] | 105 | if(NOT LIBCXX_CXX_ABI_INCLUDE_PATHS) |
| 106 | set(LIBCXX_CXX_ABI_INCLUDE_PATHS "${LIBCXX_SOURCE_DIR}/../libcxxabi/include") |
| 107 | endif() |
Raul Tambre | 28a1105 | 2020-04-02 09:34:02 -0400 | [diff] [blame] | 108 | |
Louis Dionne | 590edd2 | 2020-04-03 14:08:53 -0400 | [diff] [blame] | 109 | if(LIBCXX_STANDALONE_BUILD AND NOT (LIBCXX_CXX_ABI_INTREE OR HAVE_LIBCXXABI)) |
Raul Tambre | 28a1105 | 2020-04-02 09:34:02 -0400 | [diff] [blame] | 110 | set(shared c++abi) |
| 111 | set(static c++abi) |
| 112 | else() |
| 113 | set(shared cxxabi_shared) |
| 114 | set(static cxxabi_static) |
| 115 | endif() |
| 116 | |
Petr Hosek | 5f81a59 | 2019-04-03 01:33:14 +0000 | [diff] [blame] | 117 | setup_abi_lib( |
| 118 | "-DLIBCXX_BUILDING_LIBCXXABI" |
Raul Tambre | 28a1105 | 2020-04-02 09:34:02 -0400 | [diff] [blame] | 119 | "${shared}" "${static}" "cxxabi.h;__cxxabi_config.h" "") |
Eric Fiselier | f234855 | 2014-10-18 01:15:17 +0000 | [diff] [blame] | 120 | elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libcxxrt") |
Alex Richardson | 91fb06a | 2020-06-18 17:07:49 +0100 | [diff] [blame] | 121 | if(NOT LIBCXX_CXX_ABI_INCLUDE_PATHS) |
| 122 | set(LIBCXX_CXX_ABI_INCLUDE_PATHS "/usr/include/c++/v1") |
| 123 | endif() |
Dimitry Andric | 8ffa7b9 | 2021-02-15 18:22:01 +0100 | [diff] [blame] | 124 | # libcxxrt does not provide aligned new and delete operators |
| 125 | set(LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS ON) |
Petr Hosek | 5f81a59 | 2019-04-03 01:33:14 +0000 | [diff] [blame] | 126 | setup_abi_lib( |
| 127 | "-DLIBCXXRT" |
| 128 | "cxxrt" "cxxrt" "cxxabi.h;unwind.h;unwind-arm.h;unwind-itanium.h" "" |
Eric Fiselier | f234855 | 2014-10-18 01:15:17 +0000 | [diff] [blame] | 129 | ) |
Eric Fiselier | 830c792 | 2017-01-16 20:47:35 +0000 | [diff] [blame] | 130 | elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "vcruntime") |
Louis Dionne | 091da9f | 2020-05-01 13:10:06 -0400 | [diff] [blame] | 131 | # Nothing to do |
Eric Fiselier | b0da5fa | 2017-01-03 01:18:48 +0000 | [diff] [blame] | 132 | elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "none") |
| 133 | list(APPEND LIBCXX_COMPILE_FLAGS "-D_LIBCPP_BUILDING_HAS_NO_ABI_LIBRARY") |
| 134 | elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "default") |
Louis Dionne | 091da9f | 2020-05-01 13:10:06 -0400 | [diff] [blame] | 135 | # Nothing to do |
Eric Fiselier | b0da5fa | 2017-01-03 01:18:48 +0000 | [diff] [blame] | 136 | else() |
Eric Fiselier | f234855 | 2014-10-18 01:15:17 +0000 | [diff] [blame] | 137 | message(FATAL_ERROR |
Eric Fiselier | b0da5fa | 2017-01-03 01:18:48 +0000 | [diff] [blame] | 138 | "Unsupported c++ abi: '${LIBCXX_CXX_ABI_LIBNAME}'. \ |
| 139 | Currently libstdc++, libsupc++, libcxxabi, libcxxrt, default and none are |
| 140 | supported for c++ abi." |
Eric Fiselier | f234855 | 2014-10-18 01:15:17 +0000 | [diff] [blame] | 141 | ) |
Dan Albert | b7edb6b | 2015-02-05 23:56:33 +0000 | [diff] [blame] | 142 | endif () |