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#   abishared : The shared ABI library to link against.
12#   abistatic : The static ABI library to link against.
13#   abifiles  : A list of files (which may be relative paths) to copy into the
14#               libc++ build tree for the build.  These files will be copied
15#               twice: once into include/, so the libc++ build itself can find
16#               them, and once into include/c++/v1, so that a clang built into
17#               the same build area will find them.  These files will also be
18#               installed alongside the libc++ headers.
19#   abidirs   : A list of relative paths to create under an include directory
20#               in the libc++ build directory.
21#
22
23macro(setup_abi_lib abidefines abishared abistatic abifiles abidirs)
24  list(APPEND LIBCXX_COMPILE_FLAGS ${abidefines})
25  set(LIBCXX_CXX_ABI_INCLUDE_PATHS "${LIBCXX_CXX_ABI_INCLUDE_PATHS}"
26    CACHE PATH
27    "Paths to C++ ABI header directories separated by ';'." FORCE
28    )
29  set(LIBCXX_CXX_ABI_LIBRARY_PATH "${LIBCXX_CXX_ABI_LIBRARY_PATH}"
30    CACHE PATH
31    "Paths to C++ ABI library directory"
32    )
33  set(LIBCXX_CXX_SHARED_ABI_LIBRARY ${abishared})
34  set(LIBCXX_CXX_STATIC_ABI_LIBRARY ${abistatic})
35  set(LIBCXX_ABILIB_FILES ${abifiles})
36
37  foreach(fpath ${LIBCXX_ABILIB_FILES})
38    set(found FALSE)
39    foreach(incpath ${LIBCXX_CXX_ABI_INCLUDE_PATHS})
40      message(STATUS "Looking for ${fpath} in ${incpath}")
41      if (EXISTS "${incpath}/${fpath}")
42        set(found TRUE)
43        message(STATUS "Looking for ${fpath} in ${incpath} - found")
44        get_filename_component(dstdir ${fpath} PATH)
45        get_filename_component(ifile ${fpath} NAME)
46        set(src ${incpath}/${fpath})
47
48        set(dst ${LIBCXX_BINARY_INCLUDE_DIR}/${dstdir}/${ifile})
49        add_custom_command(OUTPUT ${dst}
50            DEPENDS ${src}
51            COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src} ${dst}
52            COMMENT "Copying C++ ABI header ${fpath}...")
53        list(APPEND abilib_headers "${dst}")
54
55        if (LIBCXX_HEADER_DIR)
56          set(dst "${LIBCXX_HEADER_DIR}/include/c++/v1/${dstdir}/${fpath}")
57          add_custom_command(OUTPUT ${dst}
58              DEPENDS ${src}
59              COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src} ${dst}
60              COMMENT "Copying C++ ABI header ${fpath}...")
61          list(APPEND abilib_headers "${dst}")
62        endif()
63
64        if (LIBCXX_INSTALL_HEADERS)
65          install(FILES "${LIBCXX_BINARY_INCLUDE_DIR}/${fpath}"
66            DESTINATION ${LIBCXX_INSTALL_HEADER_PREFIX}include/c++/v1/${dstdir}
67            COMPONENT cxx-headers
68            PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
69            )
70        endif()
71      else()
72        message(STATUS "Looking for ${fpath} in ${incpath} - not found")
73      endif()
74    endforeach()
75    if (NOT found)
76      message(WARNING "Failed to find ${fpath} in ${LIBCXX_CXX_ABI_INCLUDE_PATHS}")
77    endif()
78  endforeach()
79
80  include_directories("${LIBCXX_BINARY_INCLUDE_DIR}")
81  add_custom_target(cxx_abi_headers ALL DEPENDS ${abilib_headers})
82  set(LIBCXX_CXX_ABI_HEADER_TARGET "cxx_abi_headers")
83endmacro()
84
85
86# Configure based on the selected ABI library.
87if ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libstdc++" OR
88    "${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libsupc++")
89  set(_LIBSUPCXX_INCLUDE_FILES
90    cxxabi.h bits/c++config.h bits/os_defines.h bits/cpu_defines.h
91    bits/cxxabi_tweaks.h bits/cxxabi_forced.h
92    )
93  if ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libstdc++")
94    set(_LIBSUPCXX_DEFINES "-DLIBSTDCXX")
95    set(_LIBSUPCXX_LIBNAME stdc++)
96  else()
97    set(_LIBSUPCXX_DEFINES "")
98    set(_LIBSUPCXX_LIBNAME supc++)
99  endif()
100  setup_abi_lib(
101    "-D__GLIBCXX__ ${_LIBSUPCXX_DEFINES}"
102    "${_LIBSUPCXX_LIBNAME}" "${_LIBSUPCXX_LIBNAME}" "${_LIBSUPCXX_INCLUDE_FILES}" "bits"
103    )
104elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libcxxabi")
105  if(NOT LIBCXX_CXX_ABI_INCLUDE_PATHS)
106    set(LIBCXX_CXX_ABI_INCLUDE_PATHS "${LIBCXX_SOURCE_DIR}/../libcxxabi/include")
107  endif()
108
109  if(LIBCXX_STANDALONE_BUILD AND NOT (LIBCXX_CXX_ABI_INTREE OR HAVE_LIBCXXABI))
110    set(shared c++abi)
111    set(static c++abi)
112  else()
113    set(shared cxxabi_shared)
114    set(static cxxabi_static)
115  endif()
116
117  setup_abi_lib(
118    "-DLIBCXX_BUILDING_LIBCXXABI"
119    "${shared}" "${static}" "cxxabi.h;__cxxabi_config.h" "")
120elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libcxxrt")
121  if(NOT LIBCXX_CXX_ABI_INCLUDE_PATHS)
122    set(LIBCXX_CXX_ABI_INCLUDE_PATHS "/usr/include/c++/v1")
123  endif()
124  # libcxxrt does not provide aligned new and delete operators
125  set(LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS ON)
126  setup_abi_lib(
127    "-DLIBCXXRT"
128    "cxxrt" "cxxrt" "cxxabi.h;unwind.h;unwind-arm.h;unwind-itanium.h" ""
129    )
130elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "vcruntime")
131 # Nothing to do
132elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "none")
133  list(APPEND LIBCXX_COMPILE_FLAGS "-D_LIBCPP_BUILDING_HAS_NO_ABI_LIBRARY")
134elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "default")
135  # Nothing to do
136else()
137  message(FATAL_ERROR
138    "Unsupported c++ abi: '${LIBCXX_CXX_ABI_LIBNAME}'. \
139     Currently libstdc++, libsupc++, libcxxabi, libcxxrt, default and none are
140     supported for c++ abi."
141    )
142endif ()
143