cm_cxx_features.cmake 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 libhugetlbfs warnings.
  31. string(REGEX REPLACE "[^\n]*libhugetlbfs [^\n]*: WARNING[^\n]*" "" check_output "${check_output}")
  32. # Filter out xcodebuild warnings.
  33. string(REGEX REPLACE "[^\n]* xcodebuild\\[[0-9]*:[0-9]*\\] warning: [^\n]*" "" check_output "${check_output}")
  34. # Filter out ld warnings.
  35. string(REGEX REPLACE "[^\n]*ld: warning: [^\n]*" "" check_output "${check_output}")
  36. # Filter out CUDA installation warnings.
  37. string(REGEX REPLACE "[^\n]*clang: warning: Unknown CUDA version[^\n]*" "" check_output "${check_output}")
  38. # If using the feature causes warnings, treat it as broken/unavailable.
  39. if(check_output MATCHES "(^|[ :])[Ww][Aa][Rr][Nn][Ii][Nn][Gg]")
  40. set(CMake_HAVE_CXX_${FEATURE} OFF CACHE INTERNAL "TRY_COMPILE" FORCE)
  41. endif()
  42. if(CMake_HAVE_CXX_${FEATURE})
  43. message(${__checkPass} "yes")
  44. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
  45. "Determining if compiler supports C++ ${name} passed with the following output:\n"
  46. "${OUTPUT}\n"
  47. "\n"
  48. )
  49. else()
  50. message(${__checkFail} "no")
  51. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
  52. "Determining if compiler supports C++ ${name} failed with the following output:\n"
  53. "${OUTPUT}\n"
  54. "\n"
  55. )
  56. endif()
  57. endif()
  58. endfunction()
  59. cm_check_cxx_feature(make_unique)
  60. if(CMake_HAVE_CXX_MAKE_UNIQUE)
  61. set(CMake_HAVE_CXX_UNIQUE_PTR 1)
  62. endif()
  63. cm_check_cxx_feature(unique_ptr)