1*58b9f456SAndroid Build Coastguard Worker 2*58b9f456SAndroid Build Coastguard Worker#=============================================================================== 3*58b9f456SAndroid Build Coastguard Worker# Add an ABI library if appropriate 4*58b9f456SAndroid Build Coastguard Worker#=============================================================================== 5*58b9f456SAndroid Build Coastguard Worker 6*58b9f456SAndroid Build Coastguard Worker# 7*58b9f456SAndroid Build Coastguard Worker# _setup_abi: Set up the build to use an ABI library 8*58b9f456SAndroid Build Coastguard Worker# 9*58b9f456SAndroid Build Coastguard Worker# Parameters: 10*58b9f456SAndroid Build Coastguard Worker# abidefines: A list of defines needed to compile libc++ with the ABI library 11*58b9f456SAndroid Build Coastguard Worker# abilib : The ABI library to link against. 12*58b9f456SAndroid Build Coastguard Worker# abifiles : A list of files (which may be relative paths) to copy into the 13*58b9f456SAndroid Build Coastguard Worker# libc++ build tree for the build. These files will be copied 14*58b9f456SAndroid Build Coastguard Worker# twice: once into include/, so the libc++ build itself can find 15*58b9f456SAndroid Build Coastguard Worker# them, and once into include/c++/v1, so that a clang built into 16*58b9f456SAndroid Build Coastguard Worker# the same build area will find them. These files will also be 17*58b9f456SAndroid Build Coastguard Worker# installed alongside the libc++ headers. 18*58b9f456SAndroid Build Coastguard Worker# abidirs : A list of relative paths to create under an include directory 19*58b9f456SAndroid Build Coastguard Worker# in the libc++ build directory. 20*58b9f456SAndroid Build Coastguard Worker# 21*58b9f456SAndroid Build Coastguard Worker 22*58b9f456SAndroid Build Coastguard Workermacro(setup_abi_lib abidefines abilib abifiles abidirs) 23*58b9f456SAndroid Build Coastguard Worker list(APPEND LIBCXX_COMPILE_FLAGS ${abidefines}) 24*58b9f456SAndroid Build Coastguard Worker set(LIBCXX_CXX_ABI_INCLUDE_PATHS "${LIBCXX_CXX_ABI_INCLUDE_PATHS}" 25*58b9f456SAndroid Build Coastguard Worker CACHE PATH 26*58b9f456SAndroid Build Coastguard Worker "Paths to C++ ABI header directories separated by ';'." FORCE 27*58b9f456SAndroid Build Coastguard Worker ) 28*58b9f456SAndroid Build Coastguard Worker set(LIBCXX_CXX_ABI_LIBRARY_PATH "${LIBCXX_CXX_ABI_LIBRARY_PATH}" 29*58b9f456SAndroid Build Coastguard Worker CACHE PATH 30*58b9f456SAndroid Build Coastguard Worker "Paths to C++ ABI library directory" 31*58b9f456SAndroid Build Coastguard Worker ) 32*58b9f456SAndroid Build Coastguard Worker set(LIBCXX_CXX_ABI_LIBRARY ${abilib}) 33*58b9f456SAndroid Build Coastguard Worker set(LIBCXX_ABILIB_FILES ${abifiles}) 34*58b9f456SAndroid Build Coastguard Worker 35*58b9f456SAndroid Build Coastguard Worker foreach(fpath ${LIBCXX_ABILIB_FILES}) 36*58b9f456SAndroid Build Coastguard Worker set(found FALSE) 37*58b9f456SAndroid Build Coastguard Worker foreach(incpath ${LIBCXX_CXX_ABI_INCLUDE_PATHS}) 38*58b9f456SAndroid Build Coastguard Worker if (EXISTS "${incpath}/${fpath}") 39*58b9f456SAndroid Build Coastguard Worker set(found TRUE) 40*58b9f456SAndroid Build Coastguard Worker get_filename_component(dstdir ${fpath} PATH) 41*58b9f456SAndroid Build Coastguard Worker get_filename_component(ifile ${fpath} NAME) 42*58b9f456SAndroid Build Coastguard Worker set(src ${incpath}/${fpath}) 43*58b9f456SAndroid Build Coastguard Worker 44*58b9f456SAndroid Build Coastguard Worker set(dst ${LIBCXX_BINARY_INCLUDE_DIR}/${dstdir}/${ifile}) 45*58b9f456SAndroid Build Coastguard Worker add_custom_command(OUTPUT ${dst} 46*58b9f456SAndroid Build Coastguard Worker DEPENDS ${src} 47*58b9f456SAndroid Build Coastguard Worker COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src} ${dst} 48*58b9f456SAndroid Build Coastguard Worker COMMENT "Copying C++ ABI header ${fpath}...") 49*58b9f456SAndroid Build Coastguard Worker list(APPEND abilib_headers "${dst}") 50*58b9f456SAndroid Build Coastguard Worker 51*58b9f456SAndroid Build Coastguard Worker if (NOT LIBCXX_USING_INSTALLED_LLVM AND LIBCXX_HEADER_DIR) 52*58b9f456SAndroid Build Coastguard Worker set(dst "${LIBCXX_HEADER_DIR}/include/c++/v1/${dstdir}/${fpath}") 53*58b9f456SAndroid Build Coastguard Worker add_custom_command(OUTPUT ${dst} 54*58b9f456SAndroid Build Coastguard Worker DEPENDS ${src} 55*58b9f456SAndroid Build Coastguard Worker COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src} ${dst} 56*58b9f456SAndroid Build Coastguard Worker COMMENT "Copying C++ ABI header ${fpath}...") 57*58b9f456SAndroid Build Coastguard Worker list(APPEND abilib_headers "${dst}") 58*58b9f456SAndroid Build Coastguard Worker endif() 59*58b9f456SAndroid Build Coastguard Worker 60*58b9f456SAndroid Build Coastguard Worker if (LIBCXX_INSTALL_HEADERS) 61*58b9f456SAndroid Build Coastguard Worker install(FILES "${LIBCXX_BINARY_INCLUDE_DIR}/${fpath}" 62*58b9f456SAndroid Build Coastguard Worker DESTINATION ${LIBCXX_INSTALL_HEADER_PREFIX}include/c++/v1/${dstdir} 63*58b9f456SAndroid Build Coastguard Worker COMPONENT cxx-headers 64*58b9f456SAndroid Build Coastguard Worker PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ 65*58b9f456SAndroid Build Coastguard Worker ) 66*58b9f456SAndroid Build Coastguard Worker endif() 67*58b9f456SAndroid Build Coastguard Worker endif() 68*58b9f456SAndroid Build Coastguard Worker endforeach() 69*58b9f456SAndroid Build Coastguard Worker if (NOT found) 70*58b9f456SAndroid Build Coastguard Worker message(WARNING "Failed to find ${fpath}") 71*58b9f456SAndroid Build Coastguard Worker endif() 72*58b9f456SAndroid Build Coastguard Worker endforeach() 73*58b9f456SAndroid Build Coastguard Worker 74*58b9f456SAndroid Build Coastguard Worker include_directories("${LIBCXX_BINARY_INCLUDE_DIR}") 75*58b9f456SAndroid Build Coastguard Worker add_custom_target(cxx_abi_headers ALL DEPENDS ${abilib_headers}) 76*58b9f456SAndroid Build Coastguard Worker set(LIBCXX_CXX_ABI_HEADER_TARGET "cxx_abi_headers") 77*58b9f456SAndroid Build Coastguard Workerendmacro() 78*58b9f456SAndroid Build Coastguard Worker 79*58b9f456SAndroid Build Coastguard Worker 80*58b9f456SAndroid Build Coastguard Worker# Configure based on the selected ABI library. 81*58b9f456SAndroid Build Coastguard Workerif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libstdc++" OR 82*58b9f456SAndroid Build Coastguard Worker "${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libsupc++") 83*58b9f456SAndroid Build Coastguard Worker set(_LIBSUPCXX_INCLUDE_FILES 84*58b9f456SAndroid Build Coastguard Worker cxxabi.h bits/c++config.h bits/os_defines.h bits/cpu_defines.h 85*58b9f456SAndroid Build Coastguard Worker bits/cxxabi_tweaks.h bits/cxxabi_forced.h 86*58b9f456SAndroid Build Coastguard Worker ) 87*58b9f456SAndroid Build Coastguard Worker if ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libstdc++") 88*58b9f456SAndroid Build Coastguard Worker set(_LIBSUPCXX_DEFINES "-DLIBSTDCXX") 89*58b9f456SAndroid Build Coastguard Worker set(_LIBSUPCXX_LIBNAME stdc++) 90*58b9f456SAndroid Build Coastguard Worker else() 91*58b9f456SAndroid Build Coastguard Worker set(_LIBSUPCXX_DEFINES "") 92*58b9f456SAndroid Build Coastguard Worker set(_LIBSUPCXX_LIBNAME supc++) 93*58b9f456SAndroid Build Coastguard Worker endif() 94*58b9f456SAndroid Build Coastguard Worker setup_abi_lib( 95*58b9f456SAndroid Build Coastguard Worker "-D__GLIBCXX__ ${_LIBSUPCXX_DEFINES}" 96*58b9f456SAndroid Build Coastguard Worker "${_LIBSUPCXX_LIBNAME}" "${_LIBSUPCXX_INCLUDE_FILES}" "bits" 97*58b9f456SAndroid Build Coastguard Worker ) 98*58b9f456SAndroid Build Coastguard Workerelseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libcxxabi") 99*58b9f456SAndroid Build Coastguard Worker if (LIBCXX_CXX_ABI_INTREE) 100*58b9f456SAndroid Build Coastguard Worker # Link against just-built "cxxabi" target. 101*58b9f456SAndroid Build Coastguard Worker if (LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY) 102*58b9f456SAndroid Build Coastguard Worker set(CXXABI_LIBNAME cxxabi_static) 103*58b9f456SAndroid Build Coastguard Worker else() 104*58b9f456SAndroid Build Coastguard Worker set(CXXABI_LIBNAME cxxabi_shared) 105*58b9f456SAndroid Build Coastguard Worker endif() 106*58b9f456SAndroid Build Coastguard Worker set(LIBCXX_LIBCPPABI_VERSION "2" PARENT_SCOPE) 107*58b9f456SAndroid Build Coastguard Worker else() 108*58b9f456SAndroid Build Coastguard Worker # Assume c++abi is installed in the system, rely on -lc++abi link flag. 109*58b9f456SAndroid Build Coastguard Worker set(CXXABI_LIBNAME "c++abi") 110*58b9f456SAndroid Build Coastguard Worker endif() 111*58b9f456SAndroid Build Coastguard Worker set(HEADERS "cxxabi.h;__cxxabi_config.h") 112*58b9f456SAndroid Build Coastguard Worker if (LIBCXX_CXX_ABI_SYSTEM) 113*58b9f456SAndroid Build Coastguard Worker set(HEADERS "") 114*58b9f456SAndroid Build Coastguard Worker endif() 115*58b9f456SAndroid Build Coastguard Worker setup_abi_lib("-DLIBCXX_BUILDING_LIBCXXABI" ${CXXABI_LIBNAME} "${HEADERS}" "") 116*58b9f456SAndroid Build Coastguard Workerelseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libcxxrt") 117*58b9f456SAndroid Build Coastguard Worker setup_abi_lib("-DLIBCXXRT" 118*58b9f456SAndroid Build Coastguard Worker "cxxrt" "cxxabi.h;unwind.h;unwind-arm.h;unwind-itanium.h" "" 119*58b9f456SAndroid Build Coastguard Worker ) 120*58b9f456SAndroid Build Coastguard Workerelseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "vcruntime") 121*58b9f456SAndroid Build Coastguard Worker # Nothing TODO 122*58b9f456SAndroid Build Coastguard Workerelseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "none") 123*58b9f456SAndroid Build Coastguard Worker list(APPEND LIBCXX_COMPILE_FLAGS "-D_LIBCPP_BUILDING_HAS_NO_ABI_LIBRARY") 124*58b9f456SAndroid Build Coastguard Workerelseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "default") 125*58b9f456SAndroid Build Coastguard Worker # Nothing TODO 126*58b9f456SAndroid Build Coastguard Workerelse() 127*58b9f456SAndroid Build Coastguard Worker message(FATAL_ERROR 128*58b9f456SAndroid Build Coastguard Worker "Unsupported c++ abi: '${LIBCXX_CXX_ABI_LIBNAME}'. \ 129*58b9f456SAndroid Build Coastguard Worker Currently libstdc++, libsupc++, libcxxabi, libcxxrt, default and none are 130*58b9f456SAndroid Build Coastguard Worker supported for c++ abi." 131*58b9f456SAndroid Build Coastguard Worker ) 132*58b9f456SAndroid Build Coastguard Workerendif () 133