summaryrefslogtreecommitdiffstats
path: root/Source/Checks
diff options
context:
space:
mode:
authorDaniel Pfeifer <daniel@pfeifer-mail.de>2016-06-22 22:16:15 (GMT)
committerBrad King <brad.king@kitware.com>2016-06-27 14:37:40 (GMT)
commitea5477e43de4660343897e4669bc5809dc4ddabe (patch)
treea368c8573d3b2c24b713e059e87fa1895604eb39 /Source/Checks
parent68bb74d9e651fd44ddeeb81caa59096dbf1f0605 (diff)
downloadCMake-ea5477e43de4660343897e4669bc5809dc4ddabe.zip
CMake-ea5477e43de4660343897e4669bc5809dc4ddabe.tar.gz
CMake-ea5477e43de4660343897e4669bc5809dc4ddabe.tar.bz2
Make C++ feature checks extensible
Turn the feature check for cxx11_unordered_map into a function such that we can use it for other features as well. Drop the 11 suffix, as we may want to check features from other standards.
Diffstat (limited to 'Source/Checks')
-rw-r--r--Source/Checks/cm_cxx11_unordered_map.cmake25
-rw-r--r--Source/Checks/cm_cxx_features.cmake36
-rw-r--r--Source/Checks/cm_cxx_unordered_map.cxx (renamed from Source/Checks/cm_cxx11_unordered_map.cpp)0
3 files changed, 36 insertions, 25 deletions
diff --git a/Source/Checks/cm_cxx11_unordered_map.cmake b/Source/Checks/cm_cxx11_unordered_map.cmake
deleted file mode 100644
index 80fe391..0000000
--- a/Source/Checks/cm_cxx11_unordered_map.cmake
+++ /dev/null
@@ -1,25 +0,0 @@
-
-if(CMAKE_CXX_STANDARD AND NOT DEFINED CMake_HAVE_CXX11_UNORDERED_MAP)
- message(STATUS "Checking if compiler supports C++11 unordered_map")
- try_compile(CMake_HAVE_CXX11_UNORDERED_MAP
- ${CMAKE_CURRENT_BINARY_DIR}
- ${CMAKE_CURRENT_LIST_DIR}/cm_cxx11_unordered_map.cpp
- CMAKE_FLAGS -DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}
- OUTPUT_VARIABLE OUTPUT
- )
- if(CMake_HAVE_CXX11_UNORDERED_MAP)
- message(STATUS "Checking if compiler supports C++11 unordered_map - yes")
- file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
- "Determining if compiler supports C++11 unordered_map passed with the following output:\n"
- "${OUTPUT}\n"
- "\n"
- )
- else()
- message(STATUS "Checking if compiler supports C++11 unordered_map - no")
- file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
- "Determining if compiler supports C++11 unordered_map failed with the following output:\n"
- "${OUTPUT}\n"
- "\n"
- )
- endif()
-endif()
diff --git a/Source/Checks/cm_cxx_features.cmake b/Source/Checks/cm_cxx_features.cmake
new file mode 100644
index 0000000..b0ecc4c
--- /dev/null
+++ b/Source/Checks/cm_cxx_features.cmake
@@ -0,0 +1,36 @@
+
+function(cm_check_cxx_feature name)
+ string(TOUPPER ${name} FEATURE)
+ if(NOT DEFINED CMake_HAVE_CXX_${FEATURE})
+ message(STATUS "Checking if compiler supports C++ ${name}")
+ try_compile(CMake_HAVE_CXX_${FEATURE}
+ ${CMAKE_CURRENT_BINARY_DIR}
+ ${CMAKE_CURRENT_LIST_DIR}/cm_cxx_${name}.cxx
+ CMAKE_FLAGS -DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}
+ OUTPUT_VARIABLE OUTPUT
+ )
+ # If using the feature causes warnings, treat it as broken/unavailable.
+ if(OUTPUT MATCHES "warning")
+ set(CMake_HAVE_CXX_${FEATURE} OFF CACHE INTERNAL "TRY_COMPILE" FORCE)
+ endif()
+ if(CMake_HAVE_CXX_${FEATURE})
+ message(STATUS "Checking if compiler supports C++ ${name} - yes")
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
+ "Determining if compiler supports C++ ${name} passed with the following output:\n"
+ "${OUTPUT}\n"
+ "\n"
+ )
+ else()
+ message(STATUS "Checking if compiler supports C++ ${name} - no")
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
+ "Determining if compiler supports C++ ${name} failed with the following output:\n"
+ "${OUTPUT}\n"
+ "\n"
+ )
+ endif()
+ endif()
+endfunction()
+
+if(CMAKE_CXX_STANDARD)
+ cm_check_cxx_feature(unordered_map)
+endif()
diff --git a/Source/Checks/cm_cxx11_unordered_map.cpp b/Source/Checks/cm_cxx_unordered_map.cxx
index be3de25..be3de25 100644
--- a/Source/Checks/cm_cxx11_unordered_map.cpp
+++ b/Source/Checks/cm_cxx_unordered_map.cxx