CMakeDetermineCompileFeatures.cmake 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #=============================================================================
  2. # Copyright 2013 Stephen Kelly <steveire@gmail.com>
  3. #
  4. # Distributed under the OSI-approved BSD License (the "License");
  5. # see accompanying file Copyright.txt for details.
  6. #
  7. # This software is distributed WITHOUT ANY WARRANTY; without even the
  8. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9. # See the License for more information.
  10. #=============================================================================
  11. # (To distribute this file outside of CMake, substitute the full
  12. # License text for the above reference.)
  13. function(cmake_determine_compile_features lang)
  14. if(lang STREQUAL C AND COMMAND cmake_record_c_compile_features)
  15. message(STATUS "Detecting ${lang} compile features")
  16. set(CMAKE_C90_COMPILE_FEATURES)
  17. set(CMAKE_C99_COMPILE_FEATURES)
  18. set(CMAKE_C11_COMPILE_FEATURES)
  19. include("${CMAKE_ROOT}/Modules/Internal/FeatureTesting.cmake")
  20. cmake_record_c_compile_features()
  21. if(NOT _result EQUAL 0)
  22. message(STATUS "Detecting ${lang} compile features - failed")
  23. return()
  24. endif()
  25. if (CMAKE_C99_COMPILE_FEATURES AND CMAKE_C11_COMPILE_FEATURES)
  26. list(REMOVE_ITEM CMAKE_C11_COMPILE_FEATURES ${CMAKE_C99_COMPILE_FEATURES})
  27. endif()
  28. if (CMAKE_C90_COMPILE_FEATURES AND CMAKE_C99_COMPILE_FEATURES)
  29. list(REMOVE_ITEM CMAKE_C99_COMPILE_FEATURES ${CMAKE_C90_COMPILE_FEATURES})
  30. endif()
  31. if(NOT CMAKE_C_COMPILE_FEATURES)
  32. set(CMAKE_C_COMPILE_FEATURES
  33. ${CMAKE_C90_COMPILE_FEATURES}
  34. ${CMAKE_C99_COMPILE_FEATURES}
  35. ${CMAKE_C11_COMPILE_FEATURES}
  36. )
  37. endif()
  38. set(CMAKE_C_COMPILE_FEATURES ${CMAKE_C_COMPILE_FEATURES} PARENT_SCOPE)
  39. set(CMAKE_C90_COMPILE_FEATURES ${CMAKE_C90_COMPILE_FEATURES} PARENT_SCOPE)
  40. set(CMAKE_C99_COMPILE_FEATURES ${CMAKE_C99_COMPILE_FEATURES} PARENT_SCOPE)
  41. set(CMAKE_C11_COMPILE_FEATURES ${CMAKE_C11_COMPILE_FEATURES} PARENT_SCOPE)
  42. message(STATUS "Detecting ${lang} compile features - done")
  43. elseif(lang STREQUAL CXX AND COMMAND cmake_record_cxx_compile_features)
  44. message(STATUS "Detecting ${lang} compile features")
  45. set(CMAKE_CXX98_COMPILE_FEATURES)
  46. set(CMAKE_CXX11_COMPILE_FEATURES)
  47. set(CMAKE_CXX14_COMPILE_FEATURES)
  48. include("${CMAKE_ROOT}/Modules/Internal/FeatureTesting.cmake")
  49. cmake_record_cxx_compile_features()
  50. if(NOT _result EQUAL 0)
  51. message(STATUS "Detecting ${lang} compile features - failed")
  52. return()
  53. endif()
  54. if (CMAKE_CXX11_COMPILE_FEATURES AND CMAKE_CXX14_COMPILE_FEATURES)
  55. list(REMOVE_ITEM CMAKE_CXX14_COMPILE_FEATURES ${CMAKE_CXX11_COMPILE_FEATURES})
  56. endif()
  57. if (CMAKE_CXX98_COMPILE_FEATURES AND CMAKE_CXX11_COMPILE_FEATURES)
  58. list(REMOVE_ITEM CMAKE_CXX11_COMPILE_FEATURES ${CMAKE_CXX98_COMPILE_FEATURES})
  59. endif()
  60. if(NOT CMAKE_CXX_COMPILE_FEATURES)
  61. set(CMAKE_CXX_COMPILE_FEATURES
  62. ${CMAKE_CXX98_COMPILE_FEATURES}
  63. ${CMAKE_CXX11_COMPILE_FEATURES}
  64. ${CMAKE_CXX14_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. message(STATUS "Detecting ${lang} compile features - done")
  72. endif()
  73. endfunction()