cm_cxx_features.cmake 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. include(${CMAKE_CURRENT_LIST_DIR}/cm_message_checks_compat.cmake)
  2. function(cm_check_cxx_feature name)
  3. string(TOUPPER ${name} FEATURE)
  4. if(NOT DEFINED CMake_HAVE_CXX_${FEATURE})
  5. cm_message_checks_compat(
  6. "Checking if compiler supports C++ ${name}"
  7. __checkStart __checkPass __checkFail)
  8. message(${__checkStart})
  9. if(CMAKE_CXX_STANDARD)
  10. set(maybe_cxx_standard -DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD})
  11. else()
  12. set(maybe_cxx_standard "")
  13. endif()
  14. try_compile(CMake_HAVE_CXX_${FEATURE}
  15. ${CMAKE_CURRENT_BINARY_DIR}
  16. ${CMAKE_CURRENT_LIST_DIR}/cm_cxx_${name}.cxx
  17. CMAKE_FLAGS ${maybe_cxx_standard}
  18. OUTPUT_VARIABLE OUTPUT
  19. )
  20. set(check_output "${OUTPUT}")
  21. # Filter out MSBuild output that looks like a warning.
  22. string(REGEX REPLACE " +0 Warning\\(s\\)" "" check_output "${check_output}")
  23. # Filter out warnings caused by user flags.
  24. string(REGEX REPLACE "[^\n]*warning:[^\n]*-Winvalid-command-line-argument[^\n]*" "" check_output "${check_output}")
  25. # Filter out warnings caused by local configuration.
  26. string(REGEX REPLACE "[^\n]*warning:[^\n]*directory not found for option[^\n]*" "" check_output "${check_output}")
  27. string(REGEX REPLACE "[^\n]*warning:[^\n]*object file compiled with -mlong-branch which is no longer needed[^\n]*" "" check_output "${check_output}")
  28. # Filter out other warnings unrelated to feature checks.
  29. string(REGEX REPLACE "[^\n]*warning:[^\n]*sprintf\\(\\) is often misused, please use snprintf[^\n]*" "" check_output "${check_output}")
  30. # Filter out xcodebuild warnings.
  31. string(REGEX REPLACE "[^\n]* xcodebuild\\[[0-9]*:[0-9]*\\] warning: [^\n]*" "" check_output "${check_output}")
  32. # Filter out ld warnings.
  33. string(REGEX REPLACE "[^\n]*ld: warning: [^\n]*" "" check_output "${check_output}")
  34. # If using the feature causes warnings, treat it as broken/unavailable.
  35. if(check_output MATCHES "(^|[ :])[Ww][Aa][Rr][Nn][Ii][Nn][Gg]")
  36. set(CMake_HAVE_CXX_${FEATURE} OFF CACHE INTERNAL "TRY_COMPILE" FORCE)
  37. endif()
  38. if(CMake_HAVE_CXX_${FEATURE})
  39. message(${__checkPass} "yes")
  40. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
  41. "Determining if compiler supports C++ ${name} passed with the following output:\n"
  42. "${OUTPUT}\n"
  43. "\n"
  44. )
  45. else()
  46. message(${__checkFail} "no")
  47. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
  48. "Determining if compiler supports C++ ${name} failed with the following output:\n"
  49. "${OUTPUT}\n"
  50. "\n"
  51. )
  52. endif()
  53. endif()
  54. endfunction()
  55. cm_check_cxx_feature(make_unique)
  56. if(CMake_HAVE_CXX_MAKE_UNIQUE)
  57. set(CMake_HAVE_CXX_UNIQUE_PTR 1)
  58. endif()
  59. cm_check_cxx_feature(unique_ptr)