Clang-CXX.cmake 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. include(Compiler/Clang)
  2. __compiler_clang(CXX)
  3. if("x${CMAKE_CXX_COMPILER_FRONTEND_VARIANT}" STREQUAL "xGNU")
  4. set(CMAKE_CXX_COMPILE_OPTIONS_VISIBILITY_INLINES_HIDDEN "-fvisibility-inlines-hidden")
  5. endif()
  6. cmake_policy(GET CMP0025 appleClangPolicy)
  7. if(APPLE AND NOT appleClangPolicy STREQUAL NEW)
  8. return()
  9. endif()
  10. if("x${CMAKE_CXX_COMPILER_FRONTEND_VARIANT}" STREQUAL "xGNU")
  11. if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 2.1)
  12. set(CMAKE_CXX98_STANDARD_COMPILE_OPTION "-std=c++98")
  13. set(CMAKE_CXX98_EXTENSION_COMPILE_OPTION "-std=gnu++98")
  14. endif()
  15. if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.1)
  16. set(CMAKE_CXX98_STANDARD__HAS_FULL_SUPPORT ON)
  17. set(CMAKE_CXX11_STANDARD_COMPILE_OPTION "-std=c++11")
  18. set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "-std=gnu++11")
  19. set(CMAKE_CXX11_STANDARD__HAS_FULL_SUPPORT ON)
  20. elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 2.1)
  21. set(CMAKE_CXX11_STANDARD_COMPILE_OPTION "-std=c++0x")
  22. set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "-std=gnu++0x")
  23. endif()
  24. if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.5)
  25. set(CMAKE_CXX14_STANDARD_COMPILE_OPTION "-std=c++14")
  26. set(CMAKE_CXX14_EXTENSION_COMPILE_OPTION "-std=gnu++14")
  27. set(CMAKE_CXX14_STANDARD__HAS_FULL_SUPPORT ON)
  28. elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.4)
  29. set(CMAKE_CXX14_STANDARD_COMPILE_OPTION "-std=c++1y")
  30. set(CMAKE_CXX14_EXTENSION_COMPILE_OPTION "-std=gnu++1y")
  31. set(CMAKE_CXX14_STANDARD__HAS_FULL_SUPPORT ON)
  32. endif()
  33. set(_clang_version_std17 5.0)
  34. if(CMAKE_SYSTEM_NAME STREQUAL "Android")
  35. set(_clang_version_std17 6.0)
  36. endif()
  37. if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "${_clang_version_std17}")
  38. set(CMAKE_CXX17_STANDARD_COMPILE_OPTION "-std=c++17")
  39. set(CMAKE_CXX17_EXTENSION_COMPILE_OPTION "-std=gnu++17")
  40. elseif (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.5)
  41. set(CMAKE_CXX17_STANDARD_COMPILE_OPTION "-std=c++1z")
  42. set(CMAKE_CXX17_EXTENSION_COMPILE_OPTION "-std=gnu++1z")
  43. endif()
  44. if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "${_clang_version_std17}")
  45. set(CMAKE_CXX20_STANDARD_COMPILE_OPTION "-std=c++2a")
  46. set(CMAKE_CXX20_EXTENSION_COMPILE_OPTION "-std=gnu++2a")
  47. endif()
  48. unset(_clang_version_std17)
  49. if("x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC")
  50. # The MSVC standard library requires C++14, and MSVC itself has no
  51. # notion of operating in a mode not aware of at least that standard.
  52. set(CMAKE_CXX98_STANDARD_COMPILE_OPTION "-std=c++14")
  53. set(CMAKE_CXX98_EXTENSION_COMPILE_OPTION "-std=gnu++14")
  54. set(CMAKE_CXX11_STANDARD_COMPILE_OPTION "-std=c++14")
  55. set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "-std=gnu++14")
  56. # This clang++ is missing some features because of MSVC compatibility.
  57. unset(CMAKE_CXX11_STANDARD__HAS_FULL_SUPPORT)
  58. unset(CMAKE_CXX14_STANDARD__HAS_FULL_SUPPORT)
  59. unset(CMAKE_CXX17_STANDARD__HAS_FULL_SUPPORT)
  60. unset(CMAKE_CXX20_STANDARD__HAS_FULL_SUPPORT)
  61. endif()
  62. __compiler_check_default_language_standard(CXX 2.1 98)
  63. elseif(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 3.9
  64. AND CMAKE_CXX_SIMULATE_VERSION VERSION_GREATER_EQUAL 19.0)
  65. # This version of clang-cl and the MSVC version it simulates have
  66. # support for -std: flags.
  67. set(CMAKE_CXX98_STANDARD_COMPILE_OPTION "")
  68. set(CMAKE_CXX98_EXTENSION_COMPILE_OPTION "")
  69. set(CMAKE_CXX98_STANDARD__HAS_FULL_SUPPORT ON)
  70. set(CMAKE_CXX11_STANDARD_COMPILE_OPTION "")
  71. set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "")
  72. set(CMAKE_CXX14_STANDARD_COMPILE_OPTION "-std:c++14")
  73. set(CMAKE_CXX14_EXTENSION_COMPILE_OPTION "-std:c++14")
  74. if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 6.0)
  75. set(CMAKE_CXX17_STANDARD_COMPILE_OPTION "-std:c++17")
  76. set(CMAKE_CXX17_EXTENSION_COMPILE_OPTION "-std:c++17")
  77. set(CMAKE_CXX20_STANDARD_COMPILE_OPTION "-std:c++latest")
  78. set(CMAKE_CXX20_EXTENSION_COMPILE_OPTION "-std:c++latest")
  79. else()
  80. set(CMAKE_CXX17_STANDARD_COMPILE_OPTION "-std:c++latest")
  81. set(CMAKE_CXX17_EXTENSION_COMPILE_OPTION "-std:c++latest")
  82. endif()
  83. __compiler_check_default_language_standard(CXX 3.9 14)
  84. else()
  85. # This version of clang-cl, or the MSVC version it simulates, does not have
  86. # language standards. Set these options as empty strings so the feature
  87. # test infrastructure can at least check to see if they are defined.
  88. set(CMAKE_CXX98_STANDARD_COMPILE_OPTION "")
  89. set(CMAKE_CXX98_EXTENSION_COMPILE_OPTION "")
  90. set(CMAKE_CXX11_STANDARD_COMPILE_OPTION "")
  91. set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "")
  92. set(CMAKE_CXX14_STANDARD_COMPILE_OPTION "")
  93. set(CMAKE_CXX14_EXTENSION_COMPILE_OPTION "")
  94. set(CMAKE_CXX17_STANDARD_COMPILE_OPTION "")
  95. set(CMAKE_CXX17_EXTENSION_COMPILE_OPTION "")
  96. set(CMAKE_CXX20_STANDARD_COMPILE_OPTION "")
  97. set(CMAKE_CXX20_EXTENSION_COMPILE_OPTION "")
  98. # There is no meaningful default for this
  99. set(CMAKE_CXX_STANDARD_DEFAULT "")
  100. # There are no compiler modes so we only need to test features once.
  101. # Override the default macro for this special case. Pretend that
  102. # all language standards are available so that at least compilation
  103. # can be attempted.
  104. macro(cmake_record_cxx_compile_features)
  105. list(APPEND CMAKE_CXX_COMPILE_FEATURES
  106. cxx_std_98
  107. cxx_std_11
  108. cxx_std_14
  109. cxx_std_17
  110. cxx_std_20
  111. )
  112. _record_compiler_features(CXX "" CMAKE_CXX_COMPILE_FEATURES)
  113. endmacro()
  114. endif()