1 #===============================================================================
2 # Add an ABI library if appropriate
3 #===============================================================================
5 include(GNUInstallDirs)
8 # _setup_abi: Set up the build to use an ABI library
11 # abidefines: A list of defines needed to compile libc++ with the ABI library
12 # abishared : The shared ABI library to link against.
13 # abistatic : The static ABI library to link against.
14 # abifiles : A list of files (which may be relative paths) to copy into the
15 # libc++ build tree for the build. These files will be copied
16 # twice: once into include/, so the libc++ build itself can find
17 # them, and once into include/c++/v1, so that a clang built into
18 # the same build area will find them. These files will also be
19 # installed alongside the libc++ headers.
20 # abidirs : A list of relative paths to create under an include directory
21 # in the libc++ build directory.
24 macro(setup_abi_lib abidefines abishared abistatic abifiles abidirs)
25 list(APPEND LIBCXX_COMPILE_FLAGS ${abidefines})
26 set(LIBCXX_CXX_ABI_INCLUDE_PATHS "${LIBCXX_CXX_ABI_INCLUDE_PATHS}"
28 "Paths to C++ ABI header directories separated by ';'." FORCE
30 set(LIBCXX_CXX_ABI_LIBRARY_PATH "${LIBCXX_CXX_ABI_LIBRARY_PATH}"
32 "Paths to C++ ABI library directory"
34 set(LIBCXX_CXX_SHARED_ABI_LIBRARY ${abishared})
35 set(LIBCXX_CXX_STATIC_ABI_LIBRARY ${abistatic})
36 set(LIBCXX_ABILIB_FILES ${abifiles})
38 foreach(fpath ${LIBCXX_ABILIB_FILES})
40 foreach(incpath ${LIBCXX_CXX_ABI_INCLUDE_PATHS})
41 message(STATUS "Looking for ${fpath} in ${incpath}")
42 if (EXISTS "${incpath}/${fpath}")
44 message(STATUS "Looking for ${fpath} in ${incpath} - found")
45 get_filename_component(dstdir ${fpath} PATH)
46 get_filename_component(ifile ${fpath} NAME)
47 set(src ${incpath}/${fpath})
49 set(dst ${LIBCXX_BINARY_INCLUDE_DIR}/${dstdir}/${ifile})
50 add_custom_command(OUTPUT ${dst}
52 COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src} ${dst}
53 COMMENT "Copying C++ ABI header ${fpath}...")
54 list(APPEND abilib_headers "${dst}")
56 # TODO: libc++ shouldn't be responsible for copying the libc++abi
57 # headers into the right location.
58 set(dst "${LIBCXX_GENERATED_INCLUDE_DIR}/${dstdir}/${fpath}")
59 add_custom_command(OUTPUT ${dst}
61 COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src} ${dst}
62 COMMENT "Copying C++ ABI header ${fpath}...")
63 list(APPEND abilib_headers "${dst}")
65 if (LIBCXX_INSTALL_HEADERS)
66 install(FILES "${LIBCXX_BINARY_INCLUDE_DIR}/${fpath}"
67 DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/c++/v1/${dstdir}"
69 PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
73 message(STATUS "Looking for ${fpath} in ${incpath} - not found")
77 message(WARNING "Failed to find ${fpath} in ${LIBCXX_CXX_ABI_INCLUDE_PATHS}")
81 include_directories("${LIBCXX_BINARY_INCLUDE_DIR}")
82 add_custom_target(cxx_abi_headers ALL DEPENDS ${abilib_headers})
83 set(LIBCXX_CXX_ABI_HEADER_TARGET "cxx_abi_headers")
87 # Configure based on the selected ABI library.
88 if ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libstdc++" OR
89 "${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libsupc++")
90 set(_LIBSUPCXX_INCLUDE_FILES
91 cxxabi.h bits/c++config.h bits/os_defines.h bits/cpu_defines.h
92 bits/cxxabi_tweaks.h bits/cxxabi_forced.h
94 if ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libstdc++")
95 set(_LIBSUPCXX_DEFINES "-DLIBSTDCXX")
96 set(_LIBSUPCXX_LIBNAME stdc++)
98 set(_LIBSUPCXX_DEFINES "")
99 set(_LIBSUPCXX_LIBNAME supc++)
102 "-D__GLIBCXX__ ${_LIBSUPCXX_DEFINES}"
103 "${_LIBSUPCXX_LIBNAME}" "${_LIBSUPCXX_LIBNAME}" "${_LIBSUPCXX_INCLUDE_FILES}" "bits"
105 elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libcxxabi")
106 if(NOT LIBCXX_CXX_ABI_INCLUDE_PATHS)
107 set(LIBCXX_CXX_ABI_INCLUDE_PATHS "${LIBCXX_SOURCE_DIR}/../libcxxabi/include")
110 if(LIBCXX_STANDALONE_BUILD AND NOT (LIBCXX_CXX_ABI_INTREE OR HAVE_LIBCXXABI))
114 set(shared cxxabi_shared)
115 set(static cxxabi_static)
119 "-DLIBCXX_BUILDING_LIBCXXABI"
120 "${shared}" "${static}" "cxxabi.h;__cxxabi_config.h" "")
121 elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "system-libcxxabi")
123 "-DLIBCXX_BUILDING_LIBCXXABI"
124 "c++abi" "c++abi" "cxxabi.h;__cxxabi_config.h" "")
125 elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libcxxrt")
126 if(NOT LIBCXX_CXX_ABI_INCLUDE_PATHS)
127 set(LIBCXX_CXX_ABI_INCLUDE_PATHS "/usr/include/c++/v1")
129 # libcxxrt does not provide aligned new and delete operators
130 set(LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS ON)
133 "cxxrt" "cxxrt" "cxxabi.h;unwind.h;unwind-arm.h;unwind-itanium.h" ""
135 elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "vcruntime")
137 elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "none")
138 list(APPEND LIBCXX_COMPILE_FLAGS "-D_LIBCPP_BUILDING_HAS_NO_ABI_LIBRARY")
139 elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "default")
143 "Unsupported c++ abi: '${LIBCXX_CXX_ABI_LIBNAME}'. \
144 Currently libstdc++, libsupc++, libcxxabi, libcxxrt, default and none are
145 supported for c++ abi."