blob: 182565f52d22fdffb8ee1307c39914baade5127b [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)
50 file(COPY "${incpath}/${fpath}"
Eric Fiselier1cd196e2017-01-16 20:47:35 +000051 DESTINATION "${LIBCXX_BINARY_INCLUDE_DIR}/${dstdir}"
Eric Fiselier6f9da552014-10-18 01:15:17 +000052 )
Richard Smith564cba92017-01-05 02:55:10 +000053 file(COPY "${incpath}/${fpath}"
54 DESTINATION "${CMAKE_BINARY_DIR}/include/c++/v1/${dstdir}"
55 )
Eric Fiselierd77135f2015-08-26 20:18:21 +000056 if (LIBCXX_INSTALL_HEADERS)
Eric Fiselier1cd196e2017-01-16 20:47:35 +000057 install(FILES "${LIBCXX_BINARY_INCLUDE_DIR}/${fpath}"
Eric Fiselierd77135f2015-08-26 20:18:21 +000058 DESTINATION include/c++/v1/${dstdir}
59 COMPONENT libcxx
60 PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
61 )
62 endif()
Eric Fiselier1cd196e2017-01-16 20:47:35 +000063 list(APPEND abilib_headers "${LIBCXX_BINARY_INCLUDE_DIR}/${fpath}")
Eric Fiselier6f9da552014-10-18 01:15:17 +000064 endif()
65 endforeach()
66 if (NOT found)
Dan Albert86cc60e2015-02-10 18:46:57 +000067 message(WARNING "Failed to find ${fpath}")
Eric Fiselier6f9da552014-10-18 01:15:17 +000068 endif()
69 endforeach()
70
Eric Fiselier1cd196e2017-01-16 20:47:35 +000071 include_directories("${LIBCXX_BINARY_INCLUDE_DIR}")
Eric Fiselier6f9da552014-10-18 01:15:17 +000072endmacro()
73
Eric Fiselier10ed6c32015-07-30 22:30:34 +000074
75# Configure based on the selected ABI library.
Eric Fiselier6f9da552014-10-18 01:15:17 +000076if ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libstdc++" OR
77 "${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libsupc++")
78 set(_LIBSUPCXX_INCLUDE_FILES
79 cxxabi.h bits/c++config.h bits/os_defines.h bits/cpu_defines.h
80 bits/cxxabi_tweaks.h bits/cxxabi_forced.h
81 )
82 if ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libstdc++")
83 set(_LIBSUPCXX_DEFINES "-DLIBSTDCXX")
84 set(_LIBSUPCXX_LIBNAME stdc++)
85 else()
86 set(_LIBSUPCXX_DEFINES "")
87 set(_LIBSUPCXX_LIBNAME supc++)
88 endif()
Eric Fiselier237b6ed2015-03-19 20:59:45 +000089 setup_abi_lib(
Eric Fiselier6f9da552014-10-18 01:15:17 +000090 "-D__GLIBCXX__ ${_LIBSUPCXX_DEFINES}"
91 "${_LIBSUPCXX_LIBNAME}" "${_LIBSUPCXX_INCLUDE_FILES}" "bits"
92 )
93elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libcxxabi")
94 if (LIBCXX_CXX_ABI_INTREE)
95 # Link against just-built "cxxabi" target.
Eric Fiselier03571712015-03-03 15:59:51 +000096 if (LIBCXX_ENABLE_STATIC_ABI_LIBRARY)
97 set(CXXABI_LIBNAME cxxabi_static)
98 else()
99 set(CXXABI_LIBNAME cxxabi_shared)
100 endif()
Eric Fiselierd2852b62015-02-21 02:26:24 +0000101 set(LIBCXX_LIBCPPABI_VERSION "2" PARENT_SCOPE)
Eric Fiselier6f9da552014-10-18 01:15:17 +0000102 else()
103 # Assume c++abi is installed in the system, rely on -lc++abi link flag.
104 set(CXXABI_LIBNAME "c++abi")
105 endif()
Eric Fiselier1f294fd2015-05-20 03:15:01 +0000106 setup_abi_lib("-DLIBCXX_BUILDING_LIBCXXABI"
Dan Albert271e2642015-02-05 23:56:33 +0000107 ${CXXABI_LIBNAME} "cxxabi.h;__cxxabi_config.h" ""
Eric Fiselier6f9da552014-10-18 01:15:17 +0000108 )
109elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libcxxrt")
Eric Fiselier237b6ed2015-03-19 20:59:45 +0000110 setup_abi_lib("-DLIBCXXRT"
Eric Fiselier6f9da552014-10-18 01:15:17 +0000111 "cxxrt" "cxxabi.h;unwind.h;unwind-arm.h;unwind-itanium.h" ""
112 )
Eric Fiselier1cd196e2017-01-16 20:47:35 +0000113elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "vcruntime")
114 # Nothing TODO
Eric Fiselier1285e4d2017-01-03 01:18:48 +0000115elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "none")
116 list(APPEND LIBCXX_COMPILE_FLAGS "-D_LIBCPP_BUILDING_HAS_NO_ABI_LIBRARY")
117elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "default")
118 # Nothing TODO
119else()
Eric Fiselier6f9da552014-10-18 01:15:17 +0000120 message(FATAL_ERROR
Eric Fiselier1285e4d2017-01-03 01:18:48 +0000121 "Unsupported c++ abi: '${LIBCXX_CXX_ABI_LIBNAME}'. \
122 Currently libstdc++, libsupc++, libcxxabi, libcxxrt, default and none are
123 supported for c++ abi."
Eric Fiselier6f9da552014-10-18 01:15:17 +0000124 )
Dan Albert271e2642015-02-05 23:56:33 +0000125endif ()