xref: /openbsd-src/gnu/llvm/libcxx/cmake/Modules/HandleLibCXXABI.cmake (revision 46035553bfdd96e63c94e32da0210227ec2e3cf1)
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      if (EXISTS "${incpath}/${fpath}")
41        set(found TRUE)
42        get_filename_component(dstdir ${fpath} PATH)
43        get_filename_component(ifile ${fpath} NAME)
44        set(src ${incpath}/${fpath})
45
46        set(dst ${LIBCXX_BINARY_INCLUDE_DIR}/${dstdir}/${ifile})
47        add_custom_command(OUTPUT ${dst}
48            DEPENDS ${src}
49            COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src} ${dst}
50            COMMENT "Copying C++ ABI header ${fpath}...")
51        list(APPEND abilib_headers "${dst}")
52
53        if (NOT LIBCXX_USING_INSTALLED_LLVM AND LIBCXX_HEADER_DIR)
54          set(dst "${LIBCXX_HEADER_DIR}/include/c++/v1/${dstdir}/${fpath}")
55          add_custom_command(OUTPUT ${dst}
56              DEPENDS ${src}
57              COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src} ${dst}
58              COMMENT "Copying C++ ABI header ${fpath}...")
59          list(APPEND abilib_headers "${dst}")
60        endif()
61
62        if (LIBCXX_INSTALL_HEADERS)
63          install(FILES "${LIBCXX_BINARY_INCLUDE_DIR}/${fpath}"
64            DESTINATION ${LIBCXX_INSTALL_HEADER_PREFIX}include/c++/v1/${dstdir}
65            COMPONENT cxx-headers
66            PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
67            )
68        endif()
69      endif()
70    endforeach()
71    if (NOT found)
72      message(WARNING "Failed to find ${fpath}")
73    endif()
74  endforeach()
75
76  include_directories("${LIBCXX_BINARY_INCLUDE_DIR}")
77  add_custom_target(cxx_abi_headers ALL DEPENDS ${abilib_headers})
78  set(LIBCXX_CXX_ABI_HEADER_TARGET "cxx_abi_headers")
79endmacro()
80
81
82# Configure based on the selected ABI library.
83if ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libstdc++" OR
84    "${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libsupc++")
85  set(_LIBSUPCXX_INCLUDE_FILES
86    cxxabi.h bits/c++config.h bits/os_defines.h bits/cpu_defines.h
87    bits/cxxabi_tweaks.h bits/cxxabi_forced.h
88    )
89  if ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libstdc++")
90    set(_LIBSUPCXX_DEFINES "-DLIBSTDCXX")
91    set(_LIBSUPCXX_LIBNAME stdc++)
92  else()
93    set(_LIBSUPCXX_DEFINES "")
94    set(_LIBSUPCXX_LIBNAME supc++)
95  endif()
96  setup_abi_lib(
97    "-D__GLIBCXX__ ${_LIBSUPCXX_DEFINES}"
98    "${_LIBSUPCXX_LIBNAME}" "${_LIBSUPCXX_LIBNAME}" "${_LIBSUPCXX_INCLUDE_FILES}" "bits"
99    )
100elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libcxxabi")
101  if (LIBCXX_CXX_ABI_INTREE)
102    # Link against just-built "cxxabi" target.
103    set(CXXABI_SHARED_LIBNAME cxxabi_shared)
104    set(CXXABI_STATIC_LIBNAME cxxabi_static)
105  else()
106    # Assume c++abi is installed in the system, rely on -lc++abi link flag.
107    set(CXXABI_SHARED_LIBNAME "c++abi")
108    set(CXXABI_STATIC_LIBNAME "c++abi")
109  endif()
110  if (LIBCXX_CXX_ABI_SYSTEM)
111    set(HEADERS "")
112  else()
113    set(HEADERS "cxxabi.h;__cxxabi_config.h")
114  endif()
115  setup_abi_lib(
116    "-DLIBCXX_BUILDING_LIBCXXABI"
117    "${CXXABI_SHARED_LIBNAME}" "${CXXABI_STATIC_LIBNAME}" "${HEADERS}" "")
118elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libcxxrt")
119  setup_abi_lib(
120    "-DLIBCXXRT"
121    "cxxrt" "cxxrt" "cxxabi.h;unwind.h;unwind-arm.h;unwind-itanium.h" ""
122    )
123elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "vcruntime")
124 # Nothing TODO
125elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "none")
126  list(APPEND LIBCXX_COMPILE_FLAGS "-D_LIBCPP_BUILDING_HAS_NO_ABI_LIBRARY")
127elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "default")
128  # Nothing TODO
129else()
130  message(FATAL_ERROR
131    "Unsupported c++ abi: '${LIBCXX_CXX_ABI_LIBNAME}'. \
132     Currently libstdc++, libsupc++, libcxxabi, libcxxrt, default and none are
133     supported for c++ abi."
134    )
135endif ()
136