blob: 851ff9ec19ae4ccb8baac2cd5610077487aae49f [file] [log] [blame]
Eric Fiselier6f9da552014-10-18 01:15:17 +00001
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 Fiseliera63c1492014-10-19 00:42:41 +000011# abilib : The ABI library to link against.
Eric Fiselier6f9da552014-10-18 01:15:17 +000012# abifiles : A list of files (which may be relative paths) to copy into the
Richard Smith564cba92017-01-05 02:55:10 +000013# 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 Fiselier6f9da552014-10-18 01:15:17 +000017# 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 Fiselier1cd196e2017-01-16 20:47:35 +000021
Eric Fiselier237b6ed2015-03-19 20:59:45 +000022macro(setup_abi_lib abidefines abilib abifiles abidirs)
Eric Fiselier382338d2014-11-15 17:25:23 +000023 list(APPEND LIBCXX_COMPILE_FLAGS ${abidefines})
Eric Fiselier237b6ed2015-03-19 20:59:45 +000024 set(LIBCXX_CXX_ABI_INCLUDE_PATHS "${LIBCXX_CXX_ABI_INCLUDE_PATHS}"
Eric Fiselier6f9da552014-10-18 01:15:17 +000025 CACHE PATH
26 "Paths to C++ ABI header directories separated by ';'." FORCE
27 )
Eric Fiselier72a819e2016-05-27 23:05:37 +000028 set(LIBCXX_CXX_ABI_LIBRARY_PATH "${LIBCXX_CXX_ABI_LIBRARY_PATH}"
29 CACHE PATH
30 "Paths to C++ ABI library directory"
31 )
Eric Fiseliera63c1492014-10-19 00:42:41 +000032 set(LIBCXX_CXX_ABI_LIBRARY ${abilib})
Eric Fiselier6f9da552014-10-18 01:15:17 +000033 set(LIBCXX_ABILIB_FILES ${abifiles})
34
Eric Fiselier0ef3b1b2016-12-09 09:31:01 +000035 # The place in the build tree where we store out-of-source headers.
Eric Fiselier0ef3b1b2016-12-09 09:31:01 +000036 file(MAKE_DIRECTORY "${LIBCXX_BUILD_HEADERS_ROOT}")
Richard Smith564cba92017-01-05 02:55:10 +000037 file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/include/c++/v1")
Eric Fiselier6f9da552014-10-18 01:15:17 +000038 foreach(_d ${abidirs})
Eric Fiselier1cd196e2017-01-16 20:47:35 +000039 file(MAKE_DIRECTORY "${LIBCXX_BINARY_INCLUDE_DIR}/${_d}")
Richard Smith564cba92017-01-05 02:55:10 +000040 file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/include/c++/v1/${_d}")
Eric Fiselier6f9da552014-10-18 01:15:17 +000041 endforeach()
42
43 foreach(fpath ${LIBCXX_ABILIB_FILES})
44 set(found FALSE)
Eric Fiselier237b6ed2015-03-19 20:59:45 +000045 foreach(incpath ${LIBCXX_CXX_ABI_INCLUDE_PATHS})
Eric Fiselier6f9da552014-10-18 01:15:17 +000046 if (EXISTS "${incpath}/${fpath}")
47 set(found TRUE)
48 get_filename_component(dstdir ${fpath} PATH)
49 get_filename_component(ifile ${fpath} NAME)
Petr Hosekc20c1822018-06-12 03:10:02 +000050 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 Fiselierd77135f2015-08-26 20:18:21 +000066 if (LIBCXX_INSTALL_HEADERS)
Eric Fiselier1cd196e2017-01-16 20:47:35 +000067 install(FILES "${LIBCXX_BINARY_INCLUDE_DIR}/${fpath}"
Petr Hosek510e70f2017-07-11 02:39:50 +000068 DESTINATION ${LIBCXX_INSTALL_PREFIX}include/c++/v1/${dstdir}
Eric Fiselierb7828a82017-11-25 23:39:17 +000069 COMPONENT cxx-headers
Eric Fiselierd77135f2015-08-26 20:18:21 +000070 PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
71 )
72 endif()
Eric Fiselier6f9da552014-10-18 01:15:17 +000073 endif()
74 endforeach()
75 if (NOT found)
Dan Albert86cc60e2015-02-10 18:46:57 +000076 message(WARNING "Failed to find ${fpath}")
Eric Fiselier6f9da552014-10-18 01:15:17 +000077 endif()
78 endforeach()
79
Eric Fiselier1cd196e2017-01-16 20:47:35 +000080 include_directories("${LIBCXX_BINARY_INCLUDE_DIR}")
Petr Hosekc20c1822018-06-12 03:10:02 +000081 add_custom_target(cxx-abi-headers ALL DEPENDS ${abilib_headers})
Eric Fiselier6f9da552014-10-18 01:15:17 +000082endmacro()
83
Eric Fiselier10ed6c32015-07-30 22:30:34 +000084
85# Configure based on the selected ABI library.
Eric Fiselier6f9da552014-10-18 01:15:17 +000086if ("${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 Fiselier237b6ed2015-03-19 20:59:45 +000099 setup_abi_lib(
Eric Fiselier6f9da552014-10-18 01:15:17 +0000100 "-D__GLIBCXX__ ${_LIBSUPCXX_DEFINES}"
101 "${_LIBSUPCXX_LIBNAME}" "${_LIBSUPCXX_INCLUDE_FILES}" "bits"
102 )
103elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libcxxabi")
104 if (LIBCXX_CXX_ABI_INTREE)
105 # Link against just-built "cxxabi" target.
Eric Fiselier03571712015-03-03 15:59:51 +0000106 if (LIBCXX_ENABLE_STATIC_ABI_LIBRARY)
107 set(CXXABI_LIBNAME cxxabi_static)
108 else()
109 set(CXXABI_LIBNAME cxxabi_shared)
110 endif()
Eric Fiselierd2852b62015-02-21 02:26:24 +0000111 set(LIBCXX_LIBCPPABI_VERSION "2" PARENT_SCOPE)
Eric Fiselier6f9da552014-10-18 01:15:17 +0000112 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 Fiselierd22c9dc2017-02-10 08:57:35 +0000116 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 Fiselier6f9da552014-10-18 01:15:17 +0000121elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libcxxrt")
Eric Fiselier237b6ed2015-03-19 20:59:45 +0000122 setup_abi_lib("-DLIBCXXRT"
Eric Fiselier6f9da552014-10-18 01:15:17 +0000123 "cxxrt" "cxxabi.h;unwind.h;unwind-arm.h;unwind-itanium.h" ""
124 )
Eric Fiselier1cd196e2017-01-16 20:47:35 +0000125elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "vcruntime")
126 # Nothing TODO
Eric Fiselier1285e4d2017-01-03 01:18:48 +0000127elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "none")
128 list(APPEND LIBCXX_COMPILE_FLAGS "-D_LIBCPP_BUILDING_HAS_NO_ABI_LIBRARY")
129elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "default")
130 # Nothing TODO
131else()
Eric Fiselier6f9da552014-10-18 01:15:17 +0000132 message(FATAL_ERROR
Eric Fiselier1285e4d2017-01-03 01:18:48 +0000133 "Unsupported c++ abi: '${LIBCXX_CXX_ABI_LIBNAME}'. \
134 Currently libstdc++, libsupc++, libcxxabi, libcxxrt, default and none are
135 supported for c++ abi."
Eric Fiselier6f9da552014-10-18 01:15:17 +0000136 )
Dan Albert271e2642015-02-05 23:56:33 +0000137endif ()