HandleLibCXXABI.cmake 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. #===============================================================================
  2. # Add an ABI library if appropriate
  3. #===============================================================================
  4. #
  5. # _setup_abi: Set up the build to use an ABI library
  6. #
  7. # Parameters:
  8. # abidefines: A list of defines needed to compile libc++ with the ABI library
  9. # abilib : The ABI library to link against.
  10. # abifiles : A list of files (which may be relative paths) to copy into the
  11. # libc++ build tree for the build. These files will be copied
  12. # twice: once into include/, so the libc++ build itself can find
  13. # them, and once into include/c++/v1, so that a clang built into
  14. # the same build area will find them. These files will also be
  15. # installed alongside the libc++ headers.
  16. # abidirs : A list of relative paths to create under an include directory
  17. # in the libc++ build directory.
  18. #
  19. macro(setup_abi_lib abidefines abilib abifiles abidirs)
  20. list(APPEND LIBCXX_COMPILE_FLAGS ${abidefines})
  21. set(LIBCXX_CXX_ABI_INCLUDE_PATHS "${LIBCXX_CXX_ABI_INCLUDE_PATHS}"
  22. CACHE PATH
  23. "Paths to C++ ABI header directories separated by ';'." FORCE
  24. )
  25. set(LIBCXX_CXX_ABI_LIBRARY_PATH "${LIBCXX_CXX_ABI_LIBRARY_PATH}"
  26. CACHE PATH
  27. "Paths to C++ ABI library directory"
  28. )
  29. set(LIBCXX_CXX_ABI_LIBRARY ${abilib})
  30. set(LIBCXX_ABILIB_FILES ${abifiles})
  31. # The place in the build tree where we store out-of-source headers.
  32. file(MAKE_DIRECTORY "${LIBCXX_BUILD_HEADERS_ROOT}")
  33. file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/include/c++/v1")
  34. foreach(_d ${abidirs})
  35. file(MAKE_DIRECTORY "${LIBCXX_BINARY_INCLUDE_DIR}/${_d}")
  36. file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/include/c++/v1/${_d}")
  37. endforeach()
  38. foreach(fpath ${LIBCXX_ABILIB_FILES})
  39. set(found FALSE)
  40. foreach(incpath ${LIBCXX_CXX_ABI_INCLUDE_PATHS})
  41. if (EXISTS "${incpath}/${fpath}")
  42. set(found TRUE)
  43. get_filename_component(dstdir ${fpath} PATH)
  44. get_filename_component(ifile ${fpath} NAME)
  45. set(src ${incpath}/${fpath})
  46. set(dst ${LIBCXX_BINARY_INCLUDE_DIR}/${dstdir}/${fpath})
  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. set(dst "${CMAKE_BINARY_DIR}/include/c++/v1/${dstdir}/${fpath}")
  53. add_custom_command(OUTPUT ${dst}
  54. DEPENDS ${src}
  55. COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src} ${dst}
  56. COMMENT "Copying C++ ABI header ${fpath}...")
  57. list(APPEND abilib_headers "${dst}")
  58. if (LIBCXX_INSTALL_HEADERS)
  59. install(FILES "${LIBCXX_BINARY_INCLUDE_DIR}/${fpath}"
  60. DESTINATION ${LIBCXX_INSTALL_PREFIX}include/c++/v1/${dstdir}
  61. COMPONENT cxx-headers
  62. PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
  63. )
  64. endif()
  65. endif()
  66. endforeach()
  67. if (NOT found)
  68. message(WARNING "Failed to find ${fpath}")
  69. endif()
  70. endforeach()
  71. include_directories("${LIBCXX_BINARY_INCLUDE_DIR}")
  72. add_custom_target(cxx-abi-headers ALL DEPENDS ${abilib_headers})
  73. endmacro()
  74. # Configure based on the selected ABI library.
  75. if ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libstdc++" OR
  76. "${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libsupc++")
  77. set(_LIBSUPCXX_INCLUDE_FILES
  78. cxxabi.h bits/c++config.h bits/os_defines.h bits/cpu_defines.h
  79. bits/cxxabi_tweaks.h bits/cxxabi_forced.h
  80. )
  81. if ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libstdc++")
  82. set(_LIBSUPCXX_DEFINES "-DLIBSTDCXX")
  83. set(_LIBSUPCXX_LIBNAME stdc++)
  84. else()
  85. set(_LIBSUPCXX_DEFINES "")
  86. set(_LIBSUPCXX_LIBNAME supc++)
  87. endif()
  88. setup_abi_lib(
  89. "-D__GLIBCXX__ ${_LIBSUPCXX_DEFINES}"
  90. "${_LIBSUPCXX_LIBNAME}" "${_LIBSUPCXX_INCLUDE_FILES}" "bits"
  91. )
  92. elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libcxxabi")
  93. if (LIBCXX_CXX_ABI_INTREE)
  94. # Link against just-built "cxxabi" target.
  95. if (LIBCXX_ENABLE_STATIC_ABI_LIBRARY)
  96. set(CXXABI_LIBNAME cxxabi_static)
  97. else()
  98. set(CXXABI_LIBNAME cxxabi_shared)
  99. endif()
  100. set(LIBCXX_LIBCPPABI_VERSION "2" PARENT_SCOPE)
  101. else()
  102. # Assume c++abi is installed in the system, rely on -lc++abi link flag.
  103. set(CXXABI_LIBNAME "c++abi")
  104. endif()
  105. set(HEADERS "cxxabi.h;__cxxabi_config.h")
  106. if (LIBCXX_CXX_ABI_SYSTEM)
  107. set(HEADERS "")
  108. endif()
  109. setup_abi_lib("-DLIBCXX_BUILDING_LIBCXXABI" ${CXXABI_LIBNAME} "${HEADERS}" "")
  110. elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libcxxrt")
  111. setup_abi_lib("-DLIBCXXRT"
  112. "cxxrt" "cxxabi.h;unwind.h;unwind-arm.h;unwind-itanium.h" ""
  113. )
  114. elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "vcruntime")
  115. # Nothing TODO
  116. elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "none")
  117. list(APPEND LIBCXX_COMPILE_FLAGS "-D_LIBCPP_BUILDING_HAS_NO_ABI_LIBRARY")
  118. elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "default")
  119. # Nothing TODO
  120. else()
  121. message(FATAL_ERROR
  122. "Unsupported c++ abi: '${LIBCXX_CXX_ABI_LIBNAME}'. \
  123. Currently libstdc++, libsupc++, libcxxabi, libcxxrt, default and none are
  124. supported for c++ abi."
  125. )
  126. endif ()