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 22macro(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 foreach(fpath ${LIBCXX_ABILIB_FILES}) 36 set(found FALSE) 37 foreach(incpath ${LIBCXX_CXX_ABI_INCLUDE_PATHS}) 38 if (EXISTS "${incpath}/${fpath}") 39 set(found TRUE) 40 get_filename_component(dstdir ${fpath} PATH) 41 get_filename_component(ifile ${fpath} NAME) 42 set(src ${incpath}/${fpath}) 43 44 set(dst ${LIBCXX_BINARY_INCLUDE_DIR}/${dstdir}/${ifile}) 45 add_custom_command(OUTPUT ${dst} 46 DEPENDS ${src} 47 COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src} ${dst} 48 COMMENT "Copying C++ ABI header ${fpath}...") 49 list(APPEND abilib_headers "${dst}") 50 51 if (NOT LIBCXX_USING_INSTALLED_LLVM AND LIBCXX_HEADER_DIR) 52 set(dst "${LIBCXX_HEADER_DIR}/include/c++/v1/${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 endif() 59 60 if (LIBCXX_INSTALL_HEADERS) 61 install(FILES "${LIBCXX_BINARY_INCLUDE_DIR}/${fpath}" 62 DESTINATION ${LIBCXX_INSTALL_HEADER_PREFIX}include/c++/v1/${dstdir} 63 COMPONENT cxx-headers 64 PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ 65 ) 66 endif() 67 endif() 68 endforeach() 69 if (NOT found) 70 message(WARNING "Failed to find ${fpath}") 71 endif() 72 endforeach() 73 74 include_directories("${LIBCXX_BINARY_INCLUDE_DIR}") 75 add_custom_target(cxx_abi_headers ALL DEPENDS ${abilib_headers}) 76 set(LIBCXX_CXX_ABI_HEADER_TARGET "cxx_abi_headers") 77endmacro() 78 79 80# Configure based on the selected ABI library. 81if ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libstdc++" OR 82 "${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libsupc++") 83 set(_LIBSUPCXX_INCLUDE_FILES 84 cxxabi.h bits/c++config.h bits/os_defines.h bits/cpu_defines.h 85 bits/cxxabi_tweaks.h bits/cxxabi_forced.h 86 ) 87 if ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libstdc++") 88 set(_LIBSUPCXX_DEFINES "-DLIBSTDCXX") 89 set(_LIBSUPCXX_LIBNAME stdc++) 90 else() 91 set(_LIBSUPCXX_DEFINES "") 92 set(_LIBSUPCXX_LIBNAME supc++) 93 endif() 94 setup_abi_lib( 95 "-D__GLIBCXX__ ${_LIBSUPCXX_DEFINES}" 96 "${_LIBSUPCXX_LIBNAME}" "${_LIBSUPCXX_INCLUDE_FILES}" "bits" 97 ) 98elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libcxxabi") 99 if (LIBCXX_CXX_ABI_INTREE) 100 # Link against just-built "cxxabi" target. 101 if (LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY) 102 set(CXXABI_LIBNAME cxxabi_static) 103 else() 104 set(CXXABI_LIBNAME cxxabi_shared) 105 endif() 106 set(LIBCXX_LIBCPPABI_VERSION "2" PARENT_SCOPE) 107 else() 108 # Assume c++abi is installed in the system, rely on -lc++abi link flag. 109 set(CXXABI_LIBNAME "c++abi") 110 endif() 111 set(HEADERS "cxxabi.h;__cxxabi_config.h") 112 if (LIBCXX_CXX_ABI_SYSTEM) 113 set(HEADERS "") 114 endif() 115 setup_abi_lib("-DLIBCXX_BUILDING_LIBCXXABI" ${CXXABI_LIBNAME} "${HEADERS}" "") 116elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libcxxrt") 117 setup_abi_lib("-DLIBCXXRT" 118 "cxxrt" "cxxabi.h;unwind.h;unwind-arm.h;unwind-itanium.h" "" 119 ) 120elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "vcruntime") 121 # Nothing TODO 122elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "none") 123 list(APPEND LIBCXX_COMPILE_FLAGS "-D_LIBCPP_BUILDING_HAS_NO_ABI_LIBRARY") 124elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "default") 125 # Nothing TODO 126else() 127 message(FATAL_ERROR 128 "Unsupported c++ abi: '${LIBCXX_CXX_ABI_LIBNAME}'. \ 129 Currently libstdc++, libsupc++, libcxxabi, libcxxrt, default and none are 130 supported for c++ abi." 131 ) 132endif () 133