Commit ea5477e4 authored by Daniel Pfeifer's avatar Daniel Pfeifer Committed by Brad King
Browse files

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.
parent 68bb74d9
......@@ -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
......
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()
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()
......@@ -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@"
......
......@@ -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 <unordered_map>
#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<std::string, Def> MapType;
#else
typedef cmsys::hash_map<std::string, Def> MapType;
......
......@@ -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 <unordered_map>
#else
#include <cmsys/hash_map.hxx>
......@@ -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<const char*> h;
#else
cmsys::hash<const char*> h;
#endif
};
#ifdef CMake_HAVE_CXX11_UNORDERED_MAP
#ifdef CMake_HAVE_CXX_UNORDERED_MAP
typedef std::unordered_map<std::string,
#else
typedef cmsys::hash_map<std::string,
......
......@@ -25,7 +25,7 @@
#if defined(CMAKE_BUILD_WITH_CMAKE)
#include "cmFileLockPool.h"
#ifdef CMake_HAVE_CXX11_UNORDERED_MAP
#ifdef CMake_HAVE_CXX_UNORDERED_MAP
#include <unordered_map>
#else
#include <cmsys/hash_map.hxx>
......@@ -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<std::string, cmTarget*> TargetMap;
typedef std::unordered_map<std::string, cmGeneratorTarget*>
GeneratorTargetMap;
......
......@@ -31,7 +31,7 @@
#include <cmsys/RegularExpression.hxx>
#include <cmsys/auto_ptr.hxx>
#if defined(CMAKE_BUILD_WITH_CMAKE)
#ifdef CMake_HAVE_CXX11_UNORDERED_MAP
#ifdef CMake_HAVE_CXX_UNORDERED_MAP
#include <unordered_map>
#else
#include <cmsys/hash_map.hxx>
......@@ -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<std::string, cmTarget*> TargetMap;
#else
typedef cmsys::hash_map<std::string, cmTarget*> 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<std::string, cmSourceFile*> OutputToSourceMap;
#else
typedef cmsys::hash_map<std::string, cmSourceFile*> OutputToSourceMap;
......
......@@ -21,7 +21,7 @@
#include <cmsys/auto_ptr.hxx>
#if defined(CMAKE_BUILD_WITH_CMAKE)
#ifdef CMake_HAVE_CXX11_UNORDERED_MAP
#ifdef CMake_HAVE_CXX_UNORDERED_MAP
#include <unordered_map>
#else
#include <cmsys/hash_map.hxx>
......@@ -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<std::string, cmTarget> cmTargets;
#else
typedef cmsys::hash_map<std::string, cmTarget> cmTargets;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment