From ea5477e43de4660343897e4669bc5809dc4ddabe Mon Sep 17 00:00:00 2001 From: Daniel Pfeifer Date: Thu, 23 Jun 2016 00:16:15 +0200 Subject: 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. --- CMakeLists.txt | 2 +- Source/Checks/cm_cxx11_unordered_map.cmake | 25 --------------------- Source/Checks/cm_cxx11_unordered_map.cpp | 7 ------ Source/Checks/cm_cxx_features.cmake | 36 ++++++++++++++++++++++++++++++ Source/Checks/cm_cxx_unordered_map.cxx | 7 ++++++ Source/cmConfigure.cmake.h.in | 2 +- Source/cmDefinitions.h | 4 ++-- Source/cmFileTimeComparison.cxx | 6 ++--- Source/cmGlobalGenerator.h | 4 ++-- Source/cmMakefile.h | 6 ++--- Source/cmTarget.h | 4 ++-- 11 files changed, 57 insertions(+), 46 deletions(-) delete mode 100644 Source/Checks/cm_cxx11_unordered_map.cmake delete mode 100644 Source/Checks/cm_cxx11_unordered_map.cpp create mode 100644 Source/Checks/cm_cxx_features.cmake create mode 100644 Source/Checks/cm_cxx_unordered_map.cxx diff --git a/CMakeLists.txt b/CMakeLists.txt index 5336208..ae5990e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -67,7 +67,7 @@ if(NOT DEFINED CMAKE_CXX_STANDARD AND NOT CMake_NO_CXX_STANDARD) endif() endif() if(NOT CMake_TEST_EXTERNAL_CMAKE) - include(${CMake_SOURCE_DIR}/Source/Checks/cm_cxx11_unordered_map.cmake) + include(${CMake_SOURCE_DIR}/Source/Checks/cm_cxx_features.cmake) endif() # option to set the internal encoding of CMake to UTF-8 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_cxx11_unordered_map.cpp b/Source/Checks/cm_cxx11_unordered_map.cpp deleted file mode 100644 index be3de25..0000000 --- a/Source/Checks/cm_cxx11_unordered_map.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include -int main() -{ - std::unordered_map map; - map[0] = 0; - return 0; -} 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_cxx_unordered_map.cxx b/Source/Checks/cm_cxx_unordered_map.cxx new file mode 100644 index 0000000..be3de25 --- /dev/null +++ b/Source/Checks/cm_cxx_unordered_map.cxx @@ -0,0 +1,7 @@ +#include +int main() +{ + std::unordered_map map; + map[0] = 0; + return 0; +} diff --git a/Source/cmConfigure.cmake.h.in b/Source/cmConfigure.cmake.h.in index 938b10e..4c5ad2a 100644 --- a/Source/cmConfigure.cmake.h.in +++ b/Source/cmConfigure.cmake.h.in @@ -29,7 +29,7 @@ #cmakedefine CMAKE_USE_ELF_PARSER #cmakedefine CMAKE_USE_MACH_PARSER #cmakedefine CMAKE_ENCODING_UTF8 -#cmakedefine CMake_HAVE_CXX11_UNORDERED_MAP +#cmakedefine CMake_HAVE_CXX_UNORDERED_MAP #define CMAKE_BIN_DIR "/@CMAKE_BIN_DIR@" #define CMAKE_DATA_DIR "/@CMAKE_DATA_DIR@" diff --git a/Source/cmDefinitions.h b/Source/cmDefinitions.h index 7be0098..8f1813c 100644 --- a/Source/cmDefinitions.h +++ b/Source/cmDefinitions.h @@ -17,7 +17,7 @@ #include "cmLinkedTree.h" #if defined(CMAKE_BUILD_WITH_CMAKE) -#ifdef CMake_HAVE_CXX11_UNORDERED_MAP +#ifdef CMake_HAVE_CXX_UNORDERED_MAP #include #else #include "cmsys/hash_map.hxx" @@ -92,7 +92,7 @@ private: static Def NoDef; #if defined(CMAKE_BUILD_WITH_CMAKE) -#ifdef CMake_HAVE_CXX11_UNORDERED_MAP +#ifdef CMake_HAVE_CXX_UNORDERED_MAP typedef std::unordered_map MapType; #else typedef cmsys::hash_map MapType; diff --git a/Source/cmFileTimeComparison.cxx b/Source/cmFileTimeComparison.cxx index 7efe194..9d63505 100644 --- a/Source/cmFileTimeComparison.cxx +++ b/Source/cmFileTimeComparison.cxx @@ -13,7 +13,7 @@ // Use a hash table to avoid duplicate file time checks from disk. #if defined(CMAKE_BUILD_WITH_CMAKE) -#ifdef CMake_HAVE_CXX11_UNORDERED_MAP +#ifdef CMake_HAVE_CXX_UNORDERED_MAP #include #else #include @@ -47,13 +47,13 @@ private: { public: size_t operator()(const std::string& s) const { return h(s.c_str()); } -#ifdef CMake_HAVE_CXX11_UNORDERED_MAP +#ifdef CMake_HAVE_CXX_UNORDERED_MAP std::hash h; #else cmsys::hash h; #endif }; -#ifdef CMake_HAVE_CXX11_UNORDERED_MAP +#ifdef CMake_HAVE_CXX_UNORDERED_MAP typedef std::unordered_map #else #include @@ -433,7 +433,7 @@ protected: private: #if defined(CMAKE_BUILD_WITH_CMAKE) -#ifdef CMake_HAVE_CXX11_UNORDERED_MAP +#ifdef CMake_HAVE_CXX_UNORDERED_MAP typedef std::unordered_map TargetMap; typedef std::unordered_map GeneratorTargetMap; diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index 1680c6a..c68cd1c 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -31,7 +31,7 @@ #include #include #if defined(CMAKE_BUILD_WITH_CMAKE) -#ifdef CMake_HAVE_CXX11_UNORDERED_MAP +#ifdef CMake_HAVE_CXX_UNORDERED_MAP #include #else #include @@ -796,7 +796,7 @@ protected: // libraries, classes, and executables mutable cmTargets Targets; #if defined(CMAKE_BUILD_WITH_CMAKE) -#ifdef CMake_HAVE_CXX11_UNORDERED_MAP +#ifdef CMake_HAVE_CXX_UNORDERED_MAP typedef std::unordered_map TargetMap; #else typedef cmsys::hash_map TargetMap; @@ -915,7 +915,7 @@ private: // A map for fast output to input look up. #if defined(CMAKE_BUILD_WITH_CMAKE) -#ifdef CMake_HAVE_CXX11_UNORDERED_MAP +#ifdef CMake_HAVE_CXX_UNORDERED_MAP typedef std::unordered_map OutputToSourceMap; #else typedef cmsys::hash_map OutputToSourceMap; diff --git a/Source/cmTarget.h b/Source/cmTarget.h index f91e5c6..9e095c2 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -21,7 +21,7 @@ #include #if defined(CMAKE_BUILD_WITH_CMAKE) -#ifdef CMake_HAVE_CXX11_UNORDERED_MAP +#ifdef CMake_HAVE_CXX_UNORDERED_MAP #include #else #include @@ -331,7 +331,7 @@ private: }; #ifdef CMAKE_BUILD_WITH_CMAKE -#ifdef CMake_HAVE_CXX11_UNORDERED_MAP +#ifdef CMake_HAVE_CXX_UNORDERED_MAP typedef std::unordered_map cmTargets; #else typedef cmsys::hash_map cmTargets; -- cgit v0.12