[PowerPC][NFC] Cleanup PPCCTRLoopsVerify pass
[llvm-project.git] / libcxx / cmake / Modules / HandleLibCXXABI.cmake
blobc5aa26739e3672d9b901b91be5f4cc6bc2789dbd
2 #===============================================================================
3 # Add an ABI library if appropriate
4 #===============================================================================
7 # _setup_abi: Set up the build to use an ABI library
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.
23 macro(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})
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})
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}")
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()
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()
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")
83 endmacro()
86 # Configure based on the selected ABI library.
87 if ("${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     )
104 elseif ("${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()
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()
117   setup_abi_lib(
118     "-DLIBCXX_BUILDING_LIBCXXABI"
119     "${shared}" "${static}" "cxxabi.h;__cxxabi_config.h" "")
120 elseif ("${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   setup_abi_lib(
125     "-DLIBCXXRT"
126     "cxxrt" "cxxrt" "cxxabi.h;unwind.h;unwind-arm.h;unwind-itanium.h" ""
127     )
128 elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "vcruntime")
129  # Nothing to do
130 elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "none")
131   list(APPEND LIBCXX_COMPILE_FLAGS "-D_LIBCPP_BUILDING_HAS_NO_ABI_LIBRARY")
132 elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "default")
133   # Nothing to do
134 else()
135   message(FATAL_ERROR
136     "Unsupported c++ abi: '${LIBCXX_CXX_ABI_LIBNAME}'. \
137      Currently libstdc++, libsupc++, libcxxabi, libcxxrt, default and none are
138      supported for c++ abi."
139     )
140 endif ()