cm_cxx_features.cmake 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 xcodebuild warnings.
  25. string(REGEX REPLACE "[^\n]* xcodebuild\\[[0-9]*:[0-9]*\\] warning: [^\n]*" "" check_output "${check_output}")
  26. # If using the feature causes warnings, treat it as broken/unavailable.
  27. if(check_output MATCHES "[Ww]arning")
  28. set(CMake_HAVE_CXX_${FEATURE} OFF CACHE INTERNAL "TRY_COMPILE" FORCE)
  29. endif()
  30. if(CMake_HAVE_CXX_${FEATURE})
  31. message(STATUS "Checking if compiler supports C++ ${name} - yes")
  32. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
  33. "Determining if compiler supports C++ ${name} passed with the following output:\n"
  34. "${OUTPUT}\n"
  35. "\n"
  36. )
  37. else()
  38. message(STATUS "Checking if compiler supports C++ ${name} - no")
  39. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
  40. "Determining if compiler supports C++ ${name} failed with the following output:\n"
  41. "${OUTPUT}\n"
  42. "\n"
  43. )
  44. endif()
  45. endif()
  46. endfunction()
  47. cm_check_cxx_feature(make_unique)
  48. if(CMake_HAVE_CXX_MAKE_UNIQUE)
  49. set(CMake_HAVE_CXX_UNIQUE_PTR 1)
  50. endif()
  51. cm_check_cxx_feature(unique_ptr)