Clang-CXX.cmake 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. include(Compiler/Clang)
  2. __compiler_clang(CXX)
  3. __compiler_clang_cxx_standards(CXX)
  4. if("x${CMAKE_CXX_COMPILER_FRONTEND_VARIANT}" STREQUAL "xGNU")
  5. if((NOT DEFINED CMAKE_DEPENDS_USE_COMPILER OR CMAKE_DEPENDS_USE_COMPILER)
  6. AND CMAKE_GENERATOR MATCHES "Makefiles|WMake"
  7. AND CMAKE_DEPFILE_FLAGS_CXX)
  8. # dependencies are computed by the compiler itself
  9. set(CMAKE_CXX_DEPFILE_FORMAT gcc)
  10. set(CMAKE_CXX_DEPENDS_USE_COMPILER TRUE)
  11. endif()
  12. set(CMAKE_CXX_COMPILE_OPTIONS_EXPLICIT_LANGUAGE -x c++)
  13. set(CMAKE_CXX_COMPILE_OPTIONS_VISIBILITY_INLINES_HIDDEN "-fvisibility-inlines-hidden")
  14. endif()
  15. cmake_policy(GET CMP0025 appleClangPolicy)
  16. if(APPLE AND NOT appleClangPolicy STREQUAL NEW)
  17. return()
  18. endif()
  19. if("x${CMAKE_CXX_COMPILER_FRONTEND_VARIANT}" STREQUAL "xMSVC")
  20. set(CMAKE_CXX_CLANG_TIDY_DRIVER_MODE "cl")
  21. set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE_DRIVER_MODE "cl")
  22. if((NOT DEFINED CMAKE_DEPENDS_USE_COMPILER OR CMAKE_DEPENDS_USE_COMPILER)
  23. AND CMAKE_GENERATOR MATCHES "Makefiles"
  24. AND CMAKE_DEPFILE_FLAGS_CXX)
  25. set(CMAKE_CXX_DEPENDS_USE_COMPILER TRUE)
  26. endif()
  27. endif()
  28. if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 16.0)
  29. if("x${CMAKE_CXX_COMPILER_FRONTEND_VARIANT}" STREQUAL "xGNU")
  30. if (CMAKE_CXX_COMPILER_CLANG_RESOURCE_DIR)
  31. set(_clang_scan_deps_resource_dir
  32. " -resource-dir \"${CMAKE_CXX_COMPILER_CLANG_RESOURCE_DIR}\"")
  33. else()
  34. set(_clang_scan_deps_resource_dir "")
  35. endif ()
  36. if (CMAKE_HOST_WIN32)
  37. # `rename` doesn't overwrite and doesn't retry in case of "target file is
  38. # busy".
  39. set(_clang_scan_deps_mv "\"${CMAKE_COMMAND}\" -E rename")
  40. else ()
  41. set(_clang_scan_deps_mv "mv")
  42. endif ()
  43. string(CONCAT CMAKE_CXX_SCANDEP_SOURCE
  44. "\"${CMAKE_CXX_COMPILER_CLANG_SCAN_DEPS}\""
  45. " -format=p1689"
  46. " --"
  47. " <CMAKE_CXX_COMPILER> <DEFINES> <INCLUDES> <FLAGS>"
  48. " -x c++ <SOURCE> -c -o <OBJECT>"
  49. "${_clang_scan_deps_resource_dir}"
  50. " -MT <DYNDEP_FILE>"
  51. " -MD -MF <DEP_FILE>"
  52. # Write to a temporary file. If the scan fails, we do not want to update
  53. # the actual output file as `ninja` (at least) assumes that failed
  54. # commands either delete or leave output files alone. See Issue#25419.
  55. " > <DYNDEP_FILE>.tmp"
  56. # We cannot use `copy_if_different` as the rule does not have a feature
  57. # analogous to `ninja`'s `restat = 1`. It would also leave behind the
  58. # `.tmp` file.
  59. " && ${_clang_scan_deps_mv} <DYNDEP_FILE>.tmp <DYNDEP_FILE>")
  60. unset(_clang_scan_deps_resource_dir)
  61. unset(_clang_scan_deps_mv)
  62. set(CMAKE_CXX_MODULE_MAP_FORMAT "clang")
  63. set(CMAKE_CXX_MODULE_MAP_FLAG "@<MODULE_MAP_FILE>")
  64. set(CMAKE_CXX_MODULE_BMI_ONLY_FLAG "--precompile")
  65. endif()
  66. endif()