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 11 # abilib : The ABI library to link against. 12 # abifiles : A list of files (which may be relative paths) to copy into the 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 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 # 21 22 macro(setup_abi_lib abidefines abilib abifiles abidirs) 23 list(APPEND LIBCXX_COMPILE_FLAGS ${abidefines}) 24 set(LIBCXX_CXX_ABI_INCLUDE_PATHS "${LIBCXX_CXX_ABI_INCLUDE_PATHS}" 25 CACHE PATH 26 "Paths to C++ ABI header directories separated by ';'." FORCE 27 ) 28 set(LIBCXX_CXX_ABI_LIBRARY_PATH "${LIBCXX_CXX_ABI_LIBRARY_PATH}" 29 CACHE PATH 30 "Paths to C++ ABI library directory" 31 ) 32 set(LIBCXX_CXX_ABI_LIBRARY ${abilib}) 33 set(LIBCXX_ABILIB_FILES ${abifiles}) 34 35 # The place in the build tree where we store out-of-source headers. 36 file(MAKE_DIRECTORY "${LIBCXX_BUILD_HEADERS_ROOT}") 37 file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/include/c++/v1") 38 foreach(_d ${abidirs}) 39 file(MAKE_DIRECTORY "${LIBCXX_BINARY_INCLUDE_DIR}/${_d}") 40 file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/include/c++/v1/${_d}") 41 endforeach() 42 43 foreach(fpath ${LIBCXX_ABILIB_FILES}) 44 set(found FALSE) 45 foreach(incpath ${LIBCXX_CXX_ABI_INCLUDE_PATHS}) 46 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}" 51 DESTINATION "${LIBCXX_BINARY_INCLUDE_DIR}/${dstdir}" 52 ) 53 file(COPY "${incpath}/${fpath}" 54 DESTINATION "${CMAKE_BINARY_DIR}/include/c++/v1/${dstdir}" 55 ) 56 if (LIBCXX_INSTALL_HEADERS) 57 install(FILES "${LIBCXX_BINARY_INCLUDE_DIR}/${fpath}" 58 DESTINATION include/c++/v1/${dstdir} 59 COMPONENT libcxx 60 PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ 61 ) 62 endif() 63 list(APPEND abilib_headers "${LIBCXX_BINARY_INCLUDE_DIR}/${fpath}") 64 endif() 65 endforeach() 66 if (NOT found) 67 message(WARNING "Failed to find ${fpath}") 68 endif() 69 endforeach() 70 71 include_directories("${LIBCXX_BINARY_INCLUDE_DIR}") 72 endmacro() 73 74 75 # Configure based on the selected ABI library. 76 if ("${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() 89 setup_abi_lib( 90 "-D__GLIBCXX__ ${_LIBSUPCXX_DEFINES}" 91 "${_LIBSUPCXX_LIBNAME}" "${_LIBSUPCXX_INCLUDE_FILES}" "bits" 92 ) 93 elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libcxxabi") 94 if (LIBCXX_CXX_ABI_INTREE) 95 # Link against just-built "cxxabi" target. 96 if (LIBCXX_ENABLE_STATIC_ABI_LIBRARY) 97 set(CXXABI_LIBNAME cxxabi_static) 98 else() 99 set(CXXABI_LIBNAME cxxabi_shared) 100 endif() 101 set(LIBCXX_LIBCPPABI_VERSION "2" PARENT_SCOPE) 102 else() 103 # Assume c++abi is installed in the system, rely on -lc++abi link flag. 104 set(CXXABI_LIBNAME "c++abi") 105 endif() 106 set(HEADERS "cxxabi.h;__cxxabi_config.h") 107 if (LIBCXX_CXX_ABI_SYSTEM) 108 set(HEADERS "") 109 endif() 110 setup_abi_lib("-DLIBCXX_BUILDING_LIBCXXABI" ${CXXABI_LIBNAME} "${HEADERS}" "") 111 elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libcxxrt") 112 setup_abi_lib("-DLIBCXXRT" 113 "cxxrt" "cxxabi.h;unwind.h;unwind-arm.h;unwind-itanium.h" "" 114 ) 115 elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "vcruntime") 116 # Nothing TODO 117 elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "none") 118 list(APPEND LIBCXX_COMPILE_FLAGS "-D_LIBCPP_BUILDING_HAS_NO_ABI_LIBRARY") 119 elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "default") 120 # Nothing TODO 121 else() 122 message(FATAL_ERROR 123 "Unsupported c++ abi: '${LIBCXX_CXX_ABI_LIBNAME}'. \ 124 Currently libstdc++, libsupc++, libcxxabi, libcxxrt, default and none are 125 supported for c++ abi." 126 ) 127 endif () 128