cxx14.cmake 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # C++14 feature support detection
  2. include(CheckCXXCompilerFlag)
  3. function (fmt_check_cxx_compiler_flag flag result)
  4. if (NOT MSVC)
  5. check_cxx_compiler_flag("${flag}" ${result})
  6. endif ()
  7. endfunction ()
  8. if (NOT CMAKE_CXX_STANDARD)
  9. set(CMAKE_CXX_STANDARD 11)
  10. endif()
  11. message(STATUS "CXX_STANDARD: ${CMAKE_CXX_STANDARD}")
  12. if (CMAKE_CXX_STANDARD EQUAL 20)
  13. fmt_check_cxx_compiler_flag(-std=c++20 has_std_20_flag)
  14. fmt_check_cxx_compiler_flag(-std=c++2a has_std_2a_flag)
  15. if (has_std_20_flag)
  16. set(CXX_STANDARD_FLAG -std=c++20)
  17. elseif (has_std_2a_flag)
  18. set(CXX_STANDARD_FLAG -std=c++2a)
  19. endif ()
  20. elseif (CMAKE_CXX_STANDARD EQUAL 17)
  21. fmt_check_cxx_compiler_flag(-std=c++17 has_std_17_flag)
  22. fmt_check_cxx_compiler_flag(-std=c++1z has_std_1z_flag)
  23. if (has_std_17_flag)
  24. set(CXX_STANDARD_FLAG -std=c++17)
  25. elseif (has_std_1z_flag)
  26. set(CXX_STANDARD_FLAG -std=c++1z)
  27. endif ()
  28. elseif (CMAKE_CXX_STANDARD EQUAL 14)
  29. fmt_check_cxx_compiler_flag(-std=c++14 has_std_14_flag)
  30. fmt_check_cxx_compiler_flag(-std=c++1y has_std_1y_flag)
  31. if (has_std_14_flag)
  32. set(CXX_STANDARD_FLAG -std=c++14)
  33. elseif (has_std_1y_flag)
  34. set(CXX_STANDARD_FLAG -std=c++1y)
  35. endif ()
  36. elseif (CMAKE_CXX_STANDARD EQUAL 11)
  37. fmt_check_cxx_compiler_flag(-std=c++11 has_std_11_flag)
  38. fmt_check_cxx_compiler_flag(-std=c++0x has_std_0x_flag)
  39. if (has_std_11_flag)
  40. set(CXX_STANDARD_FLAG -std=c++11)
  41. elseif (has_std_0x_flag)
  42. set(CXX_STANDARD_FLAG -std=c++0x)
  43. endif ()
  44. endif ()