summaryrefslogtreecommitdiffstats
path: root/libcxx/cmake/Modules/HandleLibCXXABI.cmake
blob: 131941a078c5f4a44611a4cc6b1a9fbc6b7ab97c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99

#===============================================================================
# Add an ABI library if appropriate
#===============================================================================

#
# _setup_abi: Set up the build to use an ABI library
#
# Parameters:
#   abidefines: A list of defines needed to compile libc++ with the ABI library
#   abilib    : The ABI library to link against.
#   abifiles  : A list of files (which may be relative paths) to copy into the
#               libc++ build tree for the build.  These files will also be
#               installed alongside the libc++ headers.
#   abidirs   : A list of relative paths to create under an include directory
#               in the libc++ build directory.
#
macro(setup_abi_lib abipathvar abidefines abilib abifiles abidirs)
  list(APPEND LIBCXX_COMPILE_FLAGS ${abidefines})
  set(${abipathvar} "${${abipathvar}}"
    CACHE PATH
    "Paths to C++ ABI header directories separated by ';'." FORCE
    )

  set(LIBCXX_CXX_ABI_LIBRARY ${abilib})

  set(LIBCXX_ABILIB_FILES ${abifiles})

  file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/include")
  foreach(_d ${abidirs})
    file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/include/${_d}")
  endforeach()

  foreach(fpath ${LIBCXX_ABILIB_FILES})
    set(found FALSE)
    foreach(incpath ${${abipathvar}})
      if (EXISTS "${incpath}/${fpath}")
        set(found TRUE)
        get_filename_component(dstdir ${fpath} PATH)
        get_filename_component(ifile ${fpath} NAME)
        file(COPY "${incpath}/${fpath}"
          DESTINATION "${CMAKE_BINARY_DIR}/include/${dstdir}"
          )
        install(FILES "${CMAKE_BINARY_DIR}/include/${fpath}"
          DESTINATION include/c++/v1/${dstdir}
          PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
          )
        list(APPEND abilib_headers "${CMAKE_BINARY_DIR}/include/${fpath}")
      endif()
    endforeach()
    if (NOT found)
      message(WARNING "Failed to find ${fpath}")
    endif()
  endforeach()

  add_custom_target(LIBCXX_CXX_ABI_DEPS DEPENDS ${abilib_headers})
  include_directories("${CMAKE_BINARY_DIR}/include")

endmacro()

if ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libstdc++" OR
    "${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libsupc++")
  set(_LIBSUPCXX_INCLUDE_FILES
    cxxabi.h bits/c++config.h bits/os_defines.h bits/cpu_defines.h
    bits/cxxabi_tweaks.h bits/cxxabi_forced.h
    )
  if ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libstdc++")
    set(_LIBSUPCXX_DEFINES "-DLIBSTDCXX")
    set(_LIBSUPCXX_LIBNAME stdc++)
  else()
    set(_LIBSUPCXX_DEFINES "")
    set(_LIBSUPCXX_LIBNAME supc++)
  endif()
  setup_abi_lib("LIBCXX_LIBSUPCXX_INCLUDE_PATHS"
    "-D__GLIBCXX__ ${_LIBSUPCXX_DEFINES}"
    "${_LIBSUPCXX_LIBNAME}" "${_LIBSUPCXX_INCLUDE_FILES}" "bits"
    )
elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libcxxabi")
  if (LIBCXX_CXX_ABI_INTREE)
    # Link against just-built "cxxabi" target.
    set(CXXABI_LIBNAME cxxabi)
    set(LIBCXX_LIBCPPABI_VERSION "2" PARENT_SCOPE)
  else()
    # Assume c++abi is installed in the system, rely on -lc++abi link flag.
    set(CXXABI_LIBNAME "c++abi")
  endif()
  setup_abi_lib("LIBCXX_LIBCXXABI_INCLUDE_PATHS" ""
    ${CXXABI_LIBNAME} "cxxabi.h;__cxxabi_config.h" ""
    )
elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libcxxrt")
  setup_abi_lib("LIBCXX_LIBCXXRT_INCLUDE_PATHS" "-DLIBCXXRT"
    "cxxrt" "cxxabi.h;unwind.h;unwind-arm.h;unwind-itanium.h" ""
    )
elseif (NOT "${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "none")
  message(FATAL_ERROR
    "Currently libstdc++, libsupc++, libcxxabi, libcxxrt and none are "
    "supported for c++ abi."
    )
endif ()
OpenPOWER on IntegriCloud