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 also be 14 # installed alongside the libc++ headers. 15 # abidirs : A list of relative paths to create under an include directory 16 # in the libc++ build directory. 17 # 18 macro(setup_abi_lib abidefines abilib abifiles abidirs) 19 list(APPEND LIBCXX_COMPILE_FLAGS ${abidefines}) 20 set(LIBCXX_CXX_ABI_INCLUDE_PATHS "${LIBCXX_CXX_ABI_INCLUDE_PATHS}" 21 CACHE PATH 22 "Paths to C++ ABI header directories separated by ';'." FORCE 23 ) 24 25 set(LIBCXX_CXX_ABI_LIBRARY ${abilib}) 26 27 set(LIBCXX_ABILIB_FILES ${abifiles}) 28 29 file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/include") 30 foreach(_d ${abidirs}) 31 file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/include/${_d}") 32 endforeach() 33 34 foreach(fpath ${LIBCXX_ABILIB_FILES}) 35 set(found FALSE) 36 foreach(incpath ${LIBCXX_CXX_ABI_INCLUDE_PATHS}) 37 if (EXISTS "${incpath}/${fpath}") 38 set(found TRUE) 39 get_filename_component(dstdir ${fpath} PATH) 40 get_filename_component(ifile ${fpath} NAME) 41 file(COPY "${incpath}/${fpath}" 42 DESTINATION "${CMAKE_BINARY_DIR}/include/${dstdir}" 43 ) 44 if (LIBCXX_INSTALL_HEADERS) 45 install(FILES "${CMAKE_BINARY_DIR}/include/${fpath}" 46 DESTINATION include/c++/v1/${dstdir} 47 COMPONENT libcxx 48 PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ 49 ) 50 endif() 51 list(APPEND abilib_headers "${CMAKE_BINARY_DIR}/include/${fpath}") 52 endif() 53 endforeach() 54 if (NOT found) 55 message(WARNING "Failed to find ${fpath}") 56 endif() 57 endforeach() 58 59 add_custom_target(LIBCXX_CXX_ABI_DEPS DEPENDS ${abilib_headers}) 60 include_directories("${CMAKE_BINARY_DIR}/include") 61 62 endmacro() 63 64 65 # Configure based on the selected ABI library. 66 if ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libstdc++" OR 67 "${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libsupc++") 68 set(_LIBSUPCXX_INCLUDE_FILES 69 cxxabi.h bits/c++config.h bits/os_defines.h bits/cpu_defines.h 70 bits/cxxabi_tweaks.h bits/cxxabi_forced.h 71 ) 72 if ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libstdc++") 73 set(_LIBSUPCXX_DEFINES "-DLIBSTDCXX") 74 set(_LIBSUPCXX_LIBNAME stdc++) 75 else() 76 set(_LIBSUPCXX_DEFINES "") 77 set(_LIBSUPCXX_LIBNAME supc++) 78 endif() 79 setup_abi_lib( 80 "-D__GLIBCXX__ ${_LIBSUPCXX_DEFINES}" 81 "${_LIBSUPCXX_LIBNAME}" "${_LIBSUPCXX_INCLUDE_FILES}" "bits" 82 ) 83 elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libcxxabi") 84 if (LIBCXX_CXX_ABI_INTREE) 85 # Link against just-built "cxxabi" target. 86 if (LIBCXX_ENABLE_STATIC_ABI_LIBRARY) 87 set(CXXABI_LIBNAME cxxabi_static) 88 else() 89 set(CXXABI_LIBNAME cxxabi_shared) 90 endif() 91 set(LIBCXX_LIBCPPABI_VERSION "2" PARENT_SCOPE) 92 else() 93 # Assume c++abi is installed in the system, rely on -lc++abi link flag. 94 set(CXXABI_LIBNAME "c++abi") 95 endif() 96 setup_abi_lib("-DLIBCXX_BUILDING_LIBCXXABI" 97 ${CXXABI_LIBNAME} "cxxabi.h;__cxxabi_config.h" "" 98 ) 99 elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libcxxrt") 100 setup_abi_lib("-DLIBCXXRT" 101 "cxxrt" "cxxabi.h;unwind.h;unwind-arm.h;unwind-itanium.h" "" 102 ) 103 elseif (NOT "${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "none") 104 message(FATAL_ERROR 105 "Currently libstdc++, libsupc++, libcxxabi, libcxxrt and none are " 106 "supported for c++ abi." 107 ) 108 endif () 109