CMakeDetermineCompileFeatures.cmake 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. function(cmake_determine_compile_features lang)
  4. if(lang STREQUAL C AND COMMAND cmake_record_c_compile_features)
  5. message(STATUS "Detecting ${lang} compile features")
  6. set(CMAKE_C90_COMPILE_FEATURES)
  7. set(CMAKE_C99_COMPILE_FEATURES)
  8. set(CMAKE_C11_COMPILE_FEATURES)
  9. include("${CMAKE_ROOT}/Modules/Internal/FeatureTesting.cmake")
  10. cmake_record_c_compile_features()
  11. if(NOT _result EQUAL 0)
  12. message(STATUS "Detecting ${lang} compile features - failed")
  13. return()
  14. endif()
  15. if (CMAKE_C99_COMPILE_FEATURES AND CMAKE_C11_COMPILE_FEATURES)
  16. list(REMOVE_ITEM CMAKE_C11_COMPILE_FEATURES ${CMAKE_C99_COMPILE_FEATURES})
  17. endif()
  18. if (CMAKE_C90_COMPILE_FEATURES AND CMAKE_C99_COMPILE_FEATURES)
  19. list(REMOVE_ITEM CMAKE_C99_COMPILE_FEATURES ${CMAKE_C90_COMPILE_FEATURES})
  20. endif()
  21. if(NOT CMAKE_C_COMPILE_FEATURES)
  22. set(CMAKE_C_COMPILE_FEATURES
  23. ${CMAKE_C90_COMPILE_FEATURES}
  24. ${CMAKE_C99_COMPILE_FEATURES}
  25. ${CMAKE_C11_COMPILE_FEATURES}
  26. )
  27. endif()
  28. set(CMAKE_C_COMPILE_FEATURES ${CMAKE_C_COMPILE_FEATURES} PARENT_SCOPE)
  29. set(CMAKE_C90_COMPILE_FEATURES ${CMAKE_C90_COMPILE_FEATURES} PARENT_SCOPE)
  30. set(CMAKE_C99_COMPILE_FEATURES ${CMAKE_C99_COMPILE_FEATURES} PARENT_SCOPE)
  31. set(CMAKE_C11_COMPILE_FEATURES ${CMAKE_C11_COMPILE_FEATURES} PARENT_SCOPE)
  32. message(STATUS "Detecting ${lang} compile features - done")
  33. elseif(lang STREQUAL CXX AND COMMAND cmake_record_cxx_compile_features)
  34. message(STATUS "Detecting ${lang} compile features")
  35. set(CMAKE_CXX98_COMPILE_FEATURES)
  36. set(CMAKE_CXX11_COMPILE_FEATURES)
  37. set(CMAKE_CXX14_COMPILE_FEATURES)
  38. set(CMAKE_CXX17_COMPILE_FEATURES)
  39. set(CMAKE_CXX20_COMPILE_FEATURES)
  40. include("${CMAKE_ROOT}/Modules/Internal/FeatureTesting.cmake")
  41. cmake_record_cxx_compile_features()
  42. if(NOT _result EQUAL 0)
  43. message(STATUS "Detecting ${lang} compile features - failed")
  44. return()
  45. endif()
  46. if (CMAKE_CXX17_COMPILE_FEATURES AND CMAKE_CXX20_COMPILE_FEATURES)
  47. list(REMOVE_ITEM CMAKE_CXX20_COMPILE_FEATURES ${CMAKE_CXX17_COMPILE_FEATURES})
  48. endif()
  49. if (CMAKE_CXX14_COMPILE_FEATURES AND CMAKE_CXX17_COMPILE_FEATURES)
  50. list(REMOVE_ITEM CMAKE_CXX17_COMPILE_FEATURES ${CMAKE_CXX14_COMPILE_FEATURES})
  51. endif()
  52. if (CMAKE_CXX11_COMPILE_FEATURES AND CMAKE_CXX14_COMPILE_FEATURES)
  53. list(REMOVE_ITEM CMAKE_CXX14_COMPILE_FEATURES ${CMAKE_CXX11_COMPILE_FEATURES})
  54. endif()
  55. if (CMAKE_CXX98_COMPILE_FEATURES AND CMAKE_CXX11_COMPILE_FEATURES)
  56. list(REMOVE_ITEM CMAKE_CXX11_COMPILE_FEATURES ${CMAKE_CXX98_COMPILE_FEATURES})
  57. endif()
  58. if(NOT CMAKE_CXX_COMPILE_FEATURES)
  59. set(CMAKE_CXX_COMPILE_FEATURES
  60. ${CMAKE_CXX98_COMPILE_FEATURES}
  61. ${CMAKE_CXX11_COMPILE_FEATURES}
  62. ${CMAKE_CXX14_COMPILE_FEATURES}
  63. ${CMAKE_CXX17_COMPILE_FEATURES}
  64. ${CMAKE_CXX20_COMPILE_FEATURES}
  65. )
  66. endif()
  67. set(CMAKE_CXX_COMPILE_FEATURES ${CMAKE_CXX_COMPILE_FEATURES} PARENT_SCOPE)
  68. set(CMAKE_CXX98_COMPILE_FEATURES ${CMAKE_CXX98_COMPILE_FEATURES} PARENT_SCOPE)
  69. set(CMAKE_CXX11_COMPILE_FEATURES ${CMAKE_CXX11_COMPILE_FEATURES} PARENT_SCOPE)
  70. set(CMAKE_CXX14_COMPILE_FEATURES ${CMAKE_CXX14_COMPILE_FEATURES} PARENT_SCOPE)
  71. set(CMAKE_CXX17_COMPILE_FEATURES ${CMAKE_CXX17_COMPILE_FEATURES} PARENT_SCOPE)
  72. set(CMAKE_CXX20_COMPILE_FEATURES ${CMAKE_CXX20_COMPILE_FEATURES} PARENT_SCOPE)
  73. message(STATUS "Detecting ${lang} compile features - done")
  74. endif()
  75. endfunction()