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.
This commit is contained in:
parent
68bb74d9e6
commit
ea5477e43d
|
@ -67,7 +67,7 @@ if(NOT DEFINED CMAKE_CXX_STANDARD AND NOT CMake_NO_CXX_STANDARD)
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
if(NOT CMake_TEST_EXTERNAL_CMAKE)
|
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()
|
endif()
|
||||||
|
|
||||||
# option to set the internal encoding of CMake to UTF-8
|
# option to set the internal encoding of CMake to UTF-8
|
||||||
|
|
|
@ -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()
|
|
|
@ -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()
|
|
@ -29,7 +29,7 @@
|
||||||
#cmakedefine CMAKE_USE_ELF_PARSER
|
#cmakedefine CMAKE_USE_ELF_PARSER
|
||||||
#cmakedefine CMAKE_USE_MACH_PARSER
|
#cmakedefine CMAKE_USE_MACH_PARSER
|
||||||
#cmakedefine CMAKE_ENCODING_UTF8
|
#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_BIN_DIR "/@CMAKE_BIN_DIR@"
|
||||||
#define CMAKE_DATA_DIR "/@CMAKE_DATA_DIR@"
|
#define CMAKE_DATA_DIR "/@CMAKE_DATA_DIR@"
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
#include "cmLinkedTree.h"
|
#include "cmLinkedTree.h"
|
||||||
|
|
||||||
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
||||||
#ifdef CMake_HAVE_CXX11_UNORDERED_MAP
|
#ifdef CMake_HAVE_CXX_UNORDERED_MAP
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#else
|
#else
|
||||||
#include "cmsys/hash_map.hxx"
|
#include "cmsys/hash_map.hxx"
|
||||||
|
@ -92,7 +92,7 @@ private:
|
||||||
static Def NoDef;
|
static Def NoDef;
|
||||||
|
|
||||||
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
#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;
|
typedef std::unordered_map<std::string, Def> MapType;
|
||||||
#else
|
#else
|
||||||
typedef cmsys::hash_map<std::string, Def> MapType;
|
typedef cmsys::hash_map<std::string, Def> MapType;
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
|
|
||||||
// Use a hash table to avoid duplicate file time checks from disk.
|
// Use a hash table to avoid duplicate file time checks from disk.
|
||||||
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
||||||
#ifdef CMake_HAVE_CXX11_UNORDERED_MAP
|
#ifdef CMake_HAVE_CXX_UNORDERED_MAP
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#else
|
#else
|
||||||
#include <cmsys/hash_map.hxx>
|
#include <cmsys/hash_map.hxx>
|
||||||
|
@ -47,13 +47,13 @@ private:
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
size_t operator()(const std::string& s) const { return h(s.c_str()); }
|
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;
|
std::hash<const char*> h;
|
||||||
#else
|
#else
|
||||||
cmsys::hash<const char*> h;
|
cmsys::hash<const char*> h;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
#ifdef CMake_HAVE_CXX11_UNORDERED_MAP
|
#ifdef CMake_HAVE_CXX_UNORDERED_MAP
|
||||||
typedef std::unordered_map<std::string,
|
typedef std::unordered_map<std::string,
|
||||||
#else
|
#else
|
||||||
typedef cmsys::hash_map<std::string,
|
typedef cmsys::hash_map<std::string,
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
|
|
||||||
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
||||||
#include "cmFileLockPool.h"
|
#include "cmFileLockPool.h"
|
||||||
#ifdef CMake_HAVE_CXX11_UNORDERED_MAP
|
#ifdef CMake_HAVE_CXX_UNORDERED_MAP
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#else
|
#else
|
||||||
#include <cmsys/hash_map.hxx>
|
#include <cmsys/hash_map.hxx>
|
||||||
|
@ -433,7 +433,7 @@ protected:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
#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, cmTarget*> TargetMap;
|
||||||
typedef std::unordered_map<std::string, cmGeneratorTarget*>
|
typedef std::unordered_map<std::string, cmGeneratorTarget*>
|
||||||
GeneratorTargetMap;
|
GeneratorTargetMap;
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
#include <cmsys/RegularExpression.hxx>
|
#include <cmsys/RegularExpression.hxx>
|
||||||
#include <cmsys/auto_ptr.hxx>
|
#include <cmsys/auto_ptr.hxx>
|
||||||
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
||||||
#ifdef CMake_HAVE_CXX11_UNORDERED_MAP
|
#ifdef CMake_HAVE_CXX_UNORDERED_MAP
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#else
|
#else
|
||||||
#include <cmsys/hash_map.hxx>
|
#include <cmsys/hash_map.hxx>
|
||||||
|
@ -796,7 +796,7 @@ protected:
|
||||||
// libraries, classes, and executables
|
// libraries, classes, and executables
|
||||||
mutable cmTargets Targets;
|
mutable cmTargets Targets;
|
||||||
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
#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, cmTarget*> TargetMap;
|
||||||
#else
|
#else
|
||||||
typedef cmsys::hash_map<std::string, cmTarget*> TargetMap;
|
typedef cmsys::hash_map<std::string, cmTarget*> TargetMap;
|
||||||
|
@ -915,7 +915,7 @@ private:
|
||||||
|
|
||||||
// A map for fast output to input look up.
|
// A map for fast output to input look up.
|
||||||
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
#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;
|
typedef std::unordered_map<std::string, cmSourceFile*> OutputToSourceMap;
|
||||||
#else
|
#else
|
||||||
typedef cmsys::hash_map<std::string, cmSourceFile*> OutputToSourceMap;
|
typedef cmsys::hash_map<std::string, cmSourceFile*> OutputToSourceMap;
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
|
|
||||||
#include <cmsys/auto_ptr.hxx>
|
#include <cmsys/auto_ptr.hxx>
|
||||||
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
||||||
#ifdef CMake_HAVE_CXX11_UNORDERED_MAP
|
#ifdef CMake_HAVE_CXX_UNORDERED_MAP
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#else
|
#else
|
||||||
#include <cmsys/hash_map.hxx>
|
#include <cmsys/hash_map.hxx>
|
||||||
|
@ -331,7 +331,7 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef CMAKE_BUILD_WITH_CMAKE
|
#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;
|
typedef std::unordered_map<std::string, cmTarget> cmTargets;
|
||||||
#else
|
#else
|
||||||
typedef cmsys::hash_map<std::string, cmTarget> cmTargets;
|
typedef cmsys::hash_map<std::string, cmTarget> cmTargets;
|
||||||
|
|
Loading…
Reference in New Issue