2 #===============================================================================
3 # Add an ABI library if appropriate
4 #===============================================================================
7 # _setup_abi: Set up the build to use an ABI library
10 # abidefines: A list of defines needed to compile libc++ with the ABI library
11 # abishared : The shared ABI library to link against.
12 # abistatic : The static ABI library to link against.
13 # abifiles : A list of files (which may be relative paths) to copy into the
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
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.
23 macro(setup_abi_lib abidefines abishared abistatic abifiles abidirs)
24 list(APPEND LIBCXX_COMPILE_FLAGS ${abidefines})
25 set(LIBCXX_CXX_ABI_INCLUDE_PATHS "${LIBCXX_CXX_ABI_INCLUDE_PATHS}"
27 "Paths to C++ ABI header directories separated by ';'." FORCE
29 set(LIBCXX_CXX_ABI_LIBRARY_PATH "${LIBCXX_CXX_ABI_LIBRARY_PATH}"
31 "Paths to C++ ABI library directory"
33 set(LIBCXX_CXX_SHARED_ABI_LIBRARY ${abishared})
34 set(LIBCXX_CXX_STATIC_ABI_LIBRARY ${abistatic})
35 set(LIBCXX_ABILIB_FILES ${abifiles})
37 foreach(fpath ${LIBCXX_ABILIB_FILES})
39 foreach(incpath ${LIBCXX_CXX_ABI_INCLUDE_PATHS})
40 if (EXISTS "${incpath}/${fpath}")
42 get_filename_component(dstdir ${fpath} PATH)
43 get_filename_component(ifile ${fpath} NAME)
44 set(src ${incpath}/${fpath})
46 set(dst ${LIBCXX_BINARY_INCLUDE_DIR}/${dstdir}/${ifile})
47 add_custom_command(OUTPUT ${dst}
49 COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src} ${dst}
50 COMMENT "Copying C++ ABI header ${fpath}...")
51 list(APPEND abilib_headers "${dst}")
53 if (NOT LIBCXX_USING_INSTALLED_LLVM AND LIBCXX_HEADER_DIR)
54 set(dst "${LIBCXX_HEADER_DIR}/include/c++/v1/${dstdir}/${fpath}")
55 add_custom_command(OUTPUT ${dst}
57 COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src} ${dst}
58 COMMENT "Copying C++ ABI header ${fpath}...")
59 list(APPEND abilib_headers "${dst}")
62 if (LIBCXX_INSTALL_HEADERS)
63 install(FILES "${LIBCXX_BINARY_INCLUDE_DIR}/${fpath}"
64 DESTINATION ${LIBCXX_INSTALL_HEADER_PREFIX}include/c++/v1/${dstdir}
66 PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
72 message(WARNING "Failed to find ${fpath}")
76 include_directories("${LIBCXX_BINARY_INCLUDE_DIR}")
77 add_custom_target(cxx_abi_headers ALL DEPENDS ${abilib_headers})
78 set(LIBCXX_CXX_ABI_HEADER_TARGET "cxx_abi_headers")
82 # Configure based on the selected ABI library.
83 if ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libstdc++" OR
84 "${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libsupc++")
85 set(_LIBSUPCXX_INCLUDE_FILES
86 cxxabi.h bits/c++config.h bits/os_defines.h bits/cpu_defines.h
87 bits/cxxabi_tweaks.h bits/cxxabi_forced.h
89 if ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libstdc++")
90 set(_LIBSUPCXX_DEFINES "-DLIBSTDCXX")
91 set(_LIBSUPCXX_LIBNAME stdc++)
93 set(_LIBSUPCXX_DEFINES "")
94 set(_LIBSUPCXX_LIBNAME supc++)
97 "-D__GLIBCXX__ ${_LIBSUPCXX_DEFINES}"
98 "${_LIBSUPCXX_LIBNAME}" "${_LIBSUPCXX_LIBNAME}" "${_LIBSUPCXX_INCLUDE_FILES}" "bits"
100 elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libcxxabi")
101 if (LIBCXX_CXX_ABI_INTREE)
102 # Link against just-built "cxxabi" target.
103 set(CXXABI_SHARED_LIBNAME cxxabi_shared)
104 set(CXXABI_STATIC_LIBNAME cxxabi_static)
106 # Assume c++abi is installed in the system, rely on -lc++abi link flag.
107 set(CXXABI_SHARED_LIBNAME "c++abi")
108 set(CXXABI_STATIC_LIBNAME "c++abi")
110 if (LIBCXX_CXX_ABI_SYSTEM)
113 set(HEADERS "cxxabi.h;__cxxabi_config.h")
116 "-DLIBCXX_BUILDING_LIBCXXABI"
117 "${CXXABI_SHARED_LIBNAME}" "${CXXABI_STATIC_LIBNAME}" "${HEADERS}" "")
118 elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libcxxrt")
121 "cxxrt" "cxxrt" "cxxabi.h;unwind.h;unwind-arm.h;unwind-itanium.h" ""
123 elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "vcruntime")
125 elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "none")
126 list(APPEND LIBCXX_COMPILE_FLAGS "-D_LIBCPP_BUILDING_HAS_NO_ABI_LIBRARY")
127 elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "default")
131 "Unsupported c++ abi: '${LIBCXX_CXX_ABI_LIBNAME}'. \
132 Currently libstdc++, libsupc++, libcxxabi, libcxxrt, default and none are
133 supported for c++ abi."