Home | History | Annotate | Download | only in Modules
      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         install(FILES "${CMAKE_BINARY_DIR}/include/${fpath}"
     45           DESTINATION include/c++/v1/${dstdir}
     46           PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
     47           )
     48         list(APPEND abilib_headers "${CMAKE_BINARY_DIR}/include/${fpath}")
     49       endif()
     50     endforeach()
     51     if (NOT found)
     52       message(WARNING "Failed to find ${fpath}")
     53     endif()
     54   endforeach()
     55 
     56   add_custom_target(LIBCXX_CXX_ABI_DEPS DEPENDS ${abilib_headers})
     57   include_directories("${CMAKE_BINARY_DIR}/include")
     58 
     59 endmacro()
     60 
     61 # Setup the default options if LIBCXX_CXX_ABI is not specified.
     62 if (NOT LIBCXX_CXX_ABI)
     63   if (NOT DEFINED LIBCXX_BUILT_STANDALONE AND
     64       IS_DIRECTORY "${CMAKE_SOURCE_DIR}/projects/libcxxabi")
     65     set(LIBCXX_CXX_ABI_LIBNAME "libcxxabi")
     66     set(LIBCXX_CXX_ABI_INCLUDE_PATHS "${CMAKE_SOURCE_DIR}/projects/libcxxabi/include")
     67     set(LIBCXX_CXX_ABI_INTREE 1)
     68   else ()
     69     set(LIBCXX_CXX_ABI_LIBNAME "none")
     70   endif ()
     71 else ()
     72   set(LIBCXX_CXX_ABI_LIBNAME "${LIBCXX_CXX_ABI}")
     73 endif ()
     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   setup_abi_lib("-DLIBCXX_BUILDING_LIBCXXABI"
    107     ${CXXABI_LIBNAME} "cxxabi.h;__cxxabi_config.h" ""
    108     )
    109 elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libcxxrt")
    110   setup_abi_lib("-DLIBCXXRT"
    111     "cxxrt" "cxxabi.h;unwind.h;unwind-arm.h;unwind-itanium.h" ""
    112     )
    113 elseif (NOT "${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "none")
    114   message(FATAL_ERROR
    115     "Currently libstdc++, libsupc++, libcxxabi, libcxxrt and none are "
    116     "supported for c++ abi."
    117     )
    118 endif ()
    119