Eric Fiselier | 6f9da55 | 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 | a63c149 | 2014-10-19 00:42:41 +0000 | [diff] [blame] | 11 | # abilib : The ABI library to link against. |
Eric Fiselier | 6f9da55 | 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 | 564cba9 | 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 | 6f9da55 | 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 | 1cd196e | 2017-01-16 20:47:35 +0000 | [diff] [blame] | 21 | |
Eric Fiselier | 237b6ed | 2015-03-19 20:59:45 +0000 | [diff] [blame] | 22 | macro(setup_abi_lib abidefines abilib abifiles abidirs) |
Eric Fiselier | 382338d | 2014-11-15 17:25:23 +0000 | [diff] [blame] | 23 | list(APPEND LIBCXX_COMPILE_FLAGS ${abidefines}) |
Eric Fiselier | 237b6ed | 2015-03-19 20:59:45 +0000 | [diff] [blame] | 24 | set(LIBCXX_CXX_ABI_INCLUDE_PATHS "${LIBCXX_CXX_ABI_INCLUDE_PATHS}" |
Eric Fiselier | 6f9da55 | 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 | 72a819e | 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 | a63c149 | 2014-10-19 00:42:41 +0000 | [diff] [blame] | 32 | set(LIBCXX_CXX_ABI_LIBRARY ${abilib}) |
Eric Fiselier | 6f9da55 | 2014-10-18 01:15:17 +0000 | [diff] [blame] | 33 | set(LIBCXX_ABILIB_FILES ${abifiles}) |
| 34 | |
Eric Fiselier | 0ef3b1b | 2016-12-09 09:31:01 +0000 | [diff] [blame] | 35 | # The place in the build tree where we store out-of-source headers. |
Eric Fiselier | 0ef3b1b | 2016-12-09 09:31:01 +0000 | [diff] [blame] | 36 | file(MAKE_DIRECTORY "${LIBCXX_BUILD_HEADERS_ROOT}") |
Richard Smith | 564cba9 | 2017-01-05 02:55:10 +0000 | [diff] [blame] | 37 | file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/include/c++/v1") |
Eric Fiselier | 6f9da55 | 2014-10-18 01:15:17 +0000 | [diff] [blame] | 38 | foreach(_d ${abidirs}) |
Eric Fiselier | 1cd196e | 2017-01-16 20:47:35 +0000 | [diff] [blame] | 39 | file(MAKE_DIRECTORY "${LIBCXX_BINARY_INCLUDE_DIR}/${_d}") |
Richard Smith | 564cba9 | 2017-01-05 02:55:10 +0000 | [diff] [blame] | 40 | file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/include/c++/v1/${_d}") |
Eric Fiselier | 6f9da55 | 2014-10-18 01:15:17 +0000 | [diff] [blame] | 41 | endforeach() |
| 42 | |
| 43 | foreach(fpath ${LIBCXX_ABILIB_FILES}) |
| 44 | set(found FALSE) |
Eric Fiselier | 237b6ed | 2015-03-19 20:59:45 +0000 | [diff] [blame] | 45 | foreach(incpath ${LIBCXX_CXX_ABI_INCLUDE_PATHS}) |
Eric Fiselier | 6f9da55 | 2014-10-18 01:15:17 +0000 | [diff] [blame] | 46 | if (EXISTS "${incpath}/${fpath}") |
| 47 | set(found TRUE) |
| 48 | get_filename_component(dstdir ${fpath} PATH) |
| 49 | get_filename_component(ifile ${fpath} NAME) |
Petr Hosek | c20c182 | 2018-06-12 03:10:02 +0000 | [diff] [blame^] | 50 | set(src ${incpath}/${fpath}) |
| 51 | |
| 52 | set(dst ${LIBCXX_BINARY_INCLUDE_DIR}/${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 | |
| 59 | set(dst "${CMAKE_BINARY_DIR}/include/c++/v1/${dstdir}/${fpath}") |
| 60 | add_custom_command(OUTPUT ${dst} |
| 61 | DEPENDS ${src} |
| 62 | COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src} ${dst} |
| 63 | COMMENT "Copying C++ ABI header ${fpath}...") |
| 64 | list(APPEND abilib_headers "${dst}") |
| 65 | |
Eric Fiselier | d77135f | 2015-08-26 20:18:21 +0000 | [diff] [blame] | 66 | if (LIBCXX_INSTALL_HEADERS) |
Eric Fiselier | 1cd196e | 2017-01-16 20:47:35 +0000 | [diff] [blame] | 67 | install(FILES "${LIBCXX_BINARY_INCLUDE_DIR}/${fpath}" |
Petr Hosek | 510e70f | 2017-07-11 02:39:50 +0000 | [diff] [blame] | 68 | DESTINATION ${LIBCXX_INSTALL_PREFIX}include/c++/v1/${dstdir} |
Eric Fiselier | b7828a8 | 2017-11-25 23:39:17 +0000 | [diff] [blame] | 69 | COMPONENT cxx-headers |
Eric Fiselier | d77135f | 2015-08-26 20:18:21 +0000 | [diff] [blame] | 70 | PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ |
| 71 | ) |
| 72 | endif() |
Eric Fiselier | 6f9da55 | 2014-10-18 01:15:17 +0000 | [diff] [blame] | 73 | endif() |
| 74 | endforeach() |
| 75 | if (NOT found) |
Dan Albert | 86cc60e | 2015-02-10 18:46:57 +0000 | [diff] [blame] | 76 | message(WARNING "Failed to find ${fpath}") |
Eric Fiselier | 6f9da55 | 2014-10-18 01:15:17 +0000 | [diff] [blame] | 77 | endif() |
| 78 | endforeach() |
| 79 | |
Eric Fiselier | 1cd196e | 2017-01-16 20:47:35 +0000 | [diff] [blame] | 80 | include_directories("${LIBCXX_BINARY_INCLUDE_DIR}") |
Petr Hosek | c20c182 | 2018-06-12 03:10:02 +0000 | [diff] [blame^] | 81 | add_custom_target(cxx-abi-headers ALL DEPENDS ${abilib_headers}) |
Eric Fiselier | 6f9da55 | 2014-10-18 01:15:17 +0000 | [diff] [blame] | 82 | endmacro() |
| 83 | |
Eric Fiselier | 10ed6c3 | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 84 | |
| 85 | # Configure based on the selected ABI library. |
Eric Fiselier | 6f9da55 | 2014-10-18 01:15:17 +0000 | [diff] [blame] | 86 | if ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libstdc++" OR |
| 87 | "${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libsupc++") |
| 88 | set(_LIBSUPCXX_INCLUDE_FILES |
| 89 | cxxabi.h bits/c++config.h bits/os_defines.h bits/cpu_defines.h |
| 90 | bits/cxxabi_tweaks.h bits/cxxabi_forced.h |
| 91 | ) |
| 92 | if ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libstdc++") |
| 93 | set(_LIBSUPCXX_DEFINES "-DLIBSTDCXX") |
| 94 | set(_LIBSUPCXX_LIBNAME stdc++) |
| 95 | else() |
| 96 | set(_LIBSUPCXX_DEFINES "") |
| 97 | set(_LIBSUPCXX_LIBNAME supc++) |
| 98 | endif() |
Eric Fiselier | 237b6ed | 2015-03-19 20:59:45 +0000 | [diff] [blame] | 99 | setup_abi_lib( |
Eric Fiselier | 6f9da55 | 2014-10-18 01:15:17 +0000 | [diff] [blame] | 100 | "-D__GLIBCXX__ ${_LIBSUPCXX_DEFINES}" |
| 101 | "${_LIBSUPCXX_LIBNAME}" "${_LIBSUPCXX_INCLUDE_FILES}" "bits" |
| 102 | ) |
| 103 | elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libcxxabi") |
| 104 | if (LIBCXX_CXX_ABI_INTREE) |
| 105 | # Link against just-built "cxxabi" target. |
Eric Fiselier | 0357171 | 2015-03-03 15:59:51 +0000 | [diff] [blame] | 106 | if (LIBCXX_ENABLE_STATIC_ABI_LIBRARY) |
| 107 | set(CXXABI_LIBNAME cxxabi_static) |
| 108 | else() |
| 109 | set(CXXABI_LIBNAME cxxabi_shared) |
| 110 | endif() |
Eric Fiselier | d2852b6 | 2015-02-21 02:26:24 +0000 | [diff] [blame] | 111 | set(LIBCXX_LIBCPPABI_VERSION "2" PARENT_SCOPE) |
Eric Fiselier | 6f9da55 | 2014-10-18 01:15:17 +0000 | [diff] [blame] | 112 | else() |
| 113 | # Assume c++abi is installed in the system, rely on -lc++abi link flag. |
| 114 | set(CXXABI_LIBNAME "c++abi") |
| 115 | endif() |
Eric Fiselier | d22c9dc | 2017-02-10 08:57:35 +0000 | [diff] [blame] | 116 | set(HEADERS "cxxabi.h;__cxxabi_config.h") |
| 117 | if (LIBCXX_CXX_ABI_SYSTEM) |
| 118 | set(HEADERS "") |
| 119 | endif() |
| 120 | setup_abi_lib("-DLIBCXX_BUILDING_LIBCXXABI" ${CXXABI_LIBNAME} "${HEADERS}" "") |
Eric Fiselier | 6f9da55 | 2014-10-18 01:15:17 +0000 | [diff] [blame] | 121 | elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libcxxrt") |
Eric Fiselier | 237b6ed | 2015-03-19 20:59:45 +0000 | [diff] [blame] | 122 | setup_abi_lib("-DLIBCXXRT" |
Eric Fiselier | 6f9da55 | 2014-10-18 01:15:17 +0000 | [diff] [blame] | 123 | "cxxrt" "cxxabi.h;unwind.h;unwind-arm.h;unwind-itanium.h" "" |
| 124 | ) |
Eric Fiselier | 1cd196e | 2017-01-16 20:47:35 +0000 | [diff] [blame] | 125 | elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "vcruntime") |
| 126 | # Nothing TODO |
Eric Fiselier | 1285e4d | 2017-01-03 01:18:48 +0000 | [diff] [blame] | 127 | elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "none") |
| 128 | list(APPEND LIBCXX_COMPILE_FLAGS "-D_LIBCPP_BUILDING_HAS_NO_ABI_LIBRARY") |
| 129 | elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "default") |
| 130 | # Nothing TODO |
| 131 | else() |
Eric Fiselier | 6f9da55 | 2014-10-18 01:15:17 +0000 | [diff] [blame] | 132 | message(FATAL_ERROR |
Eric Fiselier | 1285e4d | 2017-01-03 01:18:48 +0000 | [diff] [blame] | 133 | "Unsupported c++ abi: '${LIBCXX_CXX_ABI_LIBNAME}'. \ |
| 134 | Currently libstdc++, libsupc++, libcxxabi, libcxxrt, default and none are |
| 135 | supported for c++ abi." |
Eric Fiselier | 6f9da55 | 2014-10-18 01:15:17 +0000 | [diff] [blame] | 136 | ) |
Dan Albert | 271e264 | 2015-02-05 23:56:33 +0000 | [diff] [blame] | 137 | endif () |