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