Eric Fiselier | 6f9da55 | 2014-10-18 01:15:17 +0000 | [diff] [blame^] | 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 | # abilibs : A list of libraries 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 abipathvar abidefines abilibs abifiles abidirs) |
| 19 | list(APPEND LIBCXX_CXX_FEATURE_FLAGS ${abidefines}) |
| 20 | set(${abipathvar} "${${abipathvar}}" |
| 21 | CACHE PATH |
| 22 | "Paths to C++ ABI header directories separated by ';'." FORCE |
| 23 | ) |
| 24 | |
| 25 | # To allow for libraries installed along non-default paths we use find_library |
| 26 | # to locate the ABI libraries we want. Making sure to clean the cache before |
| 27 | # each run of find_library. |
| 28 | set(LIBCXX_CXX_ABI_LIBRARIES "") |
| 29 | foreach(alib ${abilibs}) |
| 30 | unset(_Res CACHE) |
| 31 | find_library(_Res ${alib}) |
| 32 | if (${_Res} STREQUAL "_Res-NOTFOUND") |
| 33 | message(FATAL_ERROR "Failed to find ABI library: ${alib}") |
| 34 | else() |
| 35 | message(STATUS "Adding ABI library: ${_Res}") |
| 36 | list(APPEND LIBCXX_CXX_ABI_LIBRARIES ${_Res}) |
| 37 | endif() |
| 38 | endforeach() |
| 39 | |
| 40 | set(LIBCXX_ABILIB_FILES ${abifiles}) |
| 41 | |
| 42 | file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/include") |
| 43 | foreach(_d ${abidirs}) |
| 44 | file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/include/${_d}") |
| 45 | endforeach() |
| 46 | |
| 47 | foreach(fpath ${LIBCXX_ABILIB_FILES}) |
| 48 | set(found FALSE) |
| 49 | foreach(incpath ${${abipathvar}}) |
| 50 | if (EXISTS "${incpath}/${fpath}") |
| 51 | set(found TRUE) |
| 52 | get_filename_component(dstdir ${fpath} PATH) |
| 53 | get_filename_component(ifile ${fpath} NAME) |
| 54 | file(COPY "${incpath}/${fpath}" |
| 55 | DESTINATION "${CMAKE_BINARY_DIR}/include/${dstdir}" |
| 56 | ) |
| 57 | install(FILES "${CMAKE_BINARY_DIR}/include/${fpath}" |
| 58 | DESTINATION include/c++/v1/${dstdir} |
| 59 | PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ |
| 60 | ) |
| 61 | list(APPEND abilib_headers "${CMAKE_BINARY_DIR}/include/${fpath}") |
| 62 | endif() |
| 63 | endforeach() |
| 64 | if (NOT found) |
| 65 | message(FATAL_ERROR "Failed to find ${fpath}") |
| 66 | endif() |
| 67 | endforeach() |
| 68 | |
| 69 | add_custom_target(LIBCXX_CXX_ABI_DEPS DEPENDS ${abilib_headers}) |
| 70 | include_directories("${CMAKE_BINARY_DIR}/include") |
| 71 | |
| 72 | endmacro() |
| 73 | |
| 74 | if ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libstdc++" OR |
| 75 | "${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libsupc++") |
| 76 | set(_LIBSUPCXX_INCLUDE_FILES |
| 77 | cxxabi.h bits/c++config.h bits/os_defines.h bits/cpu_defines.h |
| 78 | bits/cxxabi_tweaks.h bits/cxxabi_forced.h |
| 79 | ) |
| 80 | if ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libstdc++") |
| 81 | set(_LIBSUPCXX_DEFINES "-DLIBSTDCXX") |
| 82 | set(_LIBSUPCXX_LIBNAME stdc++) |
| 83 | else() |
| 84 | set(_LIBSUPCXX_DEFINES "") |
| 85 | set(_LIBSUPCXX_LIBNAME supc++) |
| 86 | endif() |
| 87 | setup_abi_lib("LIBCXX_LIBSUPCXX_INCLUDE_PATHS" |
| 88 | "-D__GLIBCXX__ ${_LIBSUPCXX_DEFINES}" |
| 89 | "${_LIBSUPCXX_LIBNAME}" "${_LIBSUPCXX_INCLUDE_FILES}" "bits" |
| 90 | ) |
| 91 | elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libcxxabi") |
| 92 | if (LIBCXX_CXX_ABI_INTREE) |
| 93 | # Link against just-built "cxxabi" target. |
| 94 | set(CXXABI_LIBNAME cxxabi) |
| 95 | else() |
| 96 | # Assume c++abi is installed in the system, rely on -lc++abi link flag. |
| 97 | set(CXXABI_LIBNAME "c++abi") |
| 98 | endif() |
| 99 | setup_abi_lib("LIBCXX_LIBCXXABI_INCLUDE_PATHS" "" |
| 100 | ${CXXABI_LIBNAME} "cxxabi.h" "" |
| 101 | ) |
| 102 | elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libcxxrt") |
| 103 | setup_abi_lib("LIBCXX_LIBCXXRT_INCLUDE_PATHS" "-DLIBCXXRT" |
| 104 | "cxxrt" "cxxabi.h;unwind.h;unwind-arm.h;unwind-itanium.h" "" |
| 105 | ) |
| 106 | elseif (NOT "${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "none") |
| 107 | message(FATAL_ERROR |
| 108 | "Currently libstdc++, libsupc++, libcxxabi, libcxxrt and none are " |
| 109 | "supported for c++ abi." |
| 110 | ) |
| 111 | endif () |