cm_cxx_features.cmake 2.5 KB

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