Merge topic 'use-std-unordered_map'

d7923b82 Use std::unordered_map instead of hash_map where available.
820777af Tests: Don't rely on ordering of targets in maps.
921d74d8 AutoGen: Don't iterate over a container while populating it.
This commit is contained in:
Brad King 2015-05-19 11:30:21 -04:00 committed by CMake Topic Stage
commit 594dd9b36a
16 changed files with 100 additions and 12 deletions

View File

@ -48,6 +48,7 @@ if(NOT DEFINED CMAKE_CXX_STANDARD AND NOT CMake_NO_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD 11)
endif() endif()
endif() endif()
include(${CMake_SOURCE_DIR}/Source/Checks/cm_cxx11_unordered_map.cmake)
# option to set the internal encoding of CMake to UTF-8 # option to set the internal encoding of CMake to UTF-8
option(CMAKE_ENCODING_UTF8 "Use UTF-8 encoding internally." ON) option(CMAKE_ENCODING_UTF8 "Use UTF-8 encoding internally." ON)

View File

@ -0,0 +1,25 @@
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()

View File

@ -0,0 +1,6 @@
#include <unordered_map>
int main() {
std::unordered_map<int, int> map;
map[0] = 0;
return 0;
}

View File

@ -14,4 +14,5 @@
#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
#define CMAKE_DATA_DIR "/@CMAKE_DATA_DIR@" #define CMAKE_DATA_DIR "/@CMAKE_DATA_DIR@"

View File

@ -14,8 +14,12 @@
#include "cmStandardIncludes.h" #include "cmStandardIncludes.h"
#if defined(CMAKE_BUILD_WITH_CMAKE) #if defined(CMAKE_BUILD_WITH_CMAKE)
#ifdef CMake_HAVE_CXX11_UNORDERED_MAP
#include <unordered_map>
#else
#include "cmsys/hash_map.hxx" #include "cmsys/hash_map.hxx"
#endif #endif
#endif
#include <list> #include <list>
@ -64,9 +68,12 @@ private:
}; };
static Def NoDef; static Def NoDef;
// Local definitions, set or unset.
#if defined(CMAKE_BUILD_WITH_CMAKE) #if defined(CMAKE_BUILD_WITH_CMAKE)
#ifdef CMake_HAVE_CXX11_UNORDERED_MAP
typedef std::unordered_map<std::string, Def> MapType;
#else
typedef cmsys::hash_map<std::string, Def> MapType; typedef cmsys::hash_map<std::string, Def> MapType;
#endif
#else #else
typedef std::map<std::string, Def> MapType; typedef std::map<std::string, Def> MapType;
#endif #endif

View File

@ -13,8 +13,12 @@
// 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
#include <unordered_map>
#else
# include <cmsys/hash_map.hxx> # include <cmsys/hash_map.hxx>
#endif #endif
#endif
#include <cmsys/Encoding.hxx> #include <cmsys/Encoding.hxx>
@ -47,9 +51,17 @@ private:
{ {
return h(s.c_str()); return h(s.c_str());
} }
#ifdef CMake_HAVE_CXX11_UNORDERED_MAP
std::hash<const char*> h;
#else
cmsys::hash<const char*> h; cmsys::hash<const char*> h;
#endif
}; };
#ifdef CMake_HAVE_CXX11_UNORDERED_MAP
typedef std::unordered_map<std::string,
#else
typedef cmsys::hash_map<std::string, typedef cmsys::hash_map<std::string,
#endif
cmFileTimeComparison_Type, HashString> FileStatsMap; cmFileTimeComparison_Type, HashString> FileStatsMap;
FileStatsMap Files; FileStatsMap Files;
#endif #endif

View File

@ -1373,10 +1373,18 @@ void cmGlobalGenerator::CreateQtAutoGeneratorsTargets(AutogensType &autogens)
{ {
cmTargets& targets = cmTargets& targets =
this->LocalGenerators[i]->GetMakefile()->GetTargets(); this->LocalGenerators[i]->GetMakefile()->GetTargets();
std::vector<std::string> targetNames;
targetNames.reserve(targets.size());
for(cmTargets::iterator ti = targets.begin(); for(cmTargets::iterator ti = targets.begin();
ti != targets.end(); ++ti) ti != targets.end(); ++ti)
{ {
cmTarget& target = ti->second; targetNames.push_back(ti->second.GetName());
}
for(std::vector<std::string>::iterator ti = targetNames.begin();
ti != targetNames.end(); ++ti)
{
cmTarget& target = *this->LocalGenerators[i]
->GetMakefile()->FindTarget(*ti, true);
if(target.GetType() == cmTarget::EXECUTABLE || if(target.GetType() == cmTarget::EXECUTABLE ||
target.GetType() == cmTarget::STATIC_LIBRARY || target.GetType() == cmTarget::STATIC_LIBRARY ||
target.GetType() == cmTarget::SHARED_LIBRARY || target.GetType() == cmTarget::SHARED_LIBRARY ||

View File

@ -24,7 +24,11 @@
#if defined(CMAKE_BUILD_WITH_CMAKE) #if defined(CMAKE_BUILD_WITH_CMAKE)
# include "cmFileLockPool.h" # include "cmFileLockPool.h"
# include <cmsys/hash_map.hxx> # ifdef CMake_HAVE_CXX11_UNORDERED_MAP
# include <unordered_map>
# else
# include <cmsys/hash_map.hxx>
# endif
#endif #endif
class cmake; class cmake;
@ -429,7 +433,11 @@ protected:
// All targets in the entire project. // All targets in the entire project.
#if defined(CMAKE_BUILD_WITH_CMAKE) #if defined(CMAKE_BUILD_WITH_CMAKE)
#ifdef CMake_HAVE_CXX11_UNORDERED_MAP
typedef std::unordered_map<std::string, cmTarget*> TargetMap;
#else
typedef cmsys::hash_map<std::string, cmTarget*> TargetMap; typedef cmsys::hash_map<std::string, cmTarget*> TargetMap;
#endif
#else #else
typedef std::map<std::string,cmTarget *> TargetMap; typedef std::map<std::string,cmTarget *> TargetMap;
#endif #endif

View File

@ -31,7 +31,11 @@
#include <cmsys/auto_ptr.hxx> #include <cmsys/auto_ptr.hxx>
#include <cmsys/RegularExpression.hxx> #include <cmsys/RegularExpression.hxx>
#if defined(CMAKE_BUILD_WITH_CMAKE) #if defined(CMAKE_BUILD_WITH_CMAKE)
# include <cmsys/hash_map.hxx> # ifdef CMake_HAVE_CXX11_UNORDERED_MAP
# include <unordered_map>
# else
# include <cmsys/hash_map.hxx>
# endif
#endif #endif
#include <stack> #include <stack>
@ -848,7 +852,11 @@ 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
typedef std::unordered_map<std::string, cmTarget*> TargetMap;
#else
typedef cmsys::hash_map<std::string, cmTarget*> TargetMap; typedef cmsys::hash_map<std::string, cmTarget*> TargetMap;
#endif
#else #else
typedef std::map<std::string, cmTarget*> TargetMap; typedef std::map<std::string, cmTarget*> TargetMap;
#endif #endif
@ -1021,7 +1029,11 @@ 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
typedef std::unordered_map<std::string, cmSourceFile*> OutputToSourceMap;
#else
typedef cmsys::hash_map<std::string, cmSourceFile*> OutputToSourceMap; typedef cmsys::hash_map<std::string, cmSourceFile*> OutputToSourceMap;
#endif
#else #else
typedef std::map<std::string, cmSourceFile*> OutputToSourceMap; typedef std::map<std::string, cmSourceFile*> OutputToSourceMap;
#endif #endif

View File

@ -19,7 +19,11 @@
#include <cmsys/auto_ptr.hxx> #include <cmsys/auto_ptr.hxx>
#if defined(CMAKE_BUILD_WITH_CMAKE) #if defined(CMAKE_BUILD_WITH_CMAKE)
#include <cmsys/hash_map.hxx> # ifdef CMake_HAVE_CXX11_UNORDERED_MAP
# include <unordered_map>
# else
# include <cmsys/hash_map.hxx>
# endif
#endif #endif
#define CM_FOR_EACH_TARGET_POLICY(F) \ #define CM_FOR_EACH_TARGET_POLICY(F) \
@ -849,7 +853,11 @@ private:
}; };
#ifdef CMAKE_BUILD_WITH_CMAKE #ifdef CMAKE_BUILD_WITH_CMAKE
typedef cmsys::hash_map<std::string,cmTarget> cmTargets; #ifdef CMake_HAVE_CXX11_UNORDERED_MAP
typedef std::unordered_map<std::string, cmTarget> cmTargets;
#else
typedef cmsys::hash_map<std::string, cmTarget> cmTargets;
#endif
#else #else
typedef std::map<std::string,cmTarget> cmTargets; typedef std::map<std::string,cmTarget> cmTargets;
#endif #endif

View File

@ -3,4 +3,4 @@ CMake Error:
\$<TARGET_PROPERTY:INCLUDE_DIRECTORIES> \$<TARGET_PROPERTY:INCLUDE_DIRECTORIES>
Self reference on target "TargetPropertyGeneratorExpressions".$ Self reference on target "TargetPropertyGeneratorExpressions".

View File

@ -3,4 +3,4 @@ CMake Error:
\$<TARGET_PROPERTY:INCLUDE_DIRECTORIES> \$<TARGET_PROPERTY:INCLUDE_DIRECTORIES>
Self reference on target "TargetPropertyGeneratorExpressions".$ Self reference on target "TargetPropertyGeneratorExpressions".

View File

@ -3,4 +3,4 @@ CMake Error:
\$<TARGET_PROPERTY:TargetPropertyGeneratorExpressions,INCLUDE_DIRECTORIES> \$<TARGET_PROPERTY:TargetPropertyGeneratorExpressions,INCLUDE_DIRECTORIES>
Self reference on target "TargetPropertyGeneratorExpressions".$ Self reference on target "TargetPropertyGeneratorExpressions".

View File

@ -3,4 +3,4 @@ CMake Error:
\$<TARGET_PROPERTY:TargetPropertyGeneratorExpressions,INCLUDE_DIRECTORIES> \$<TARGET_PROPERTY:TargetPropertyGeneratorExpressions,INCLUDE_DIRECTORIES>
Self reference on target "TargetPropertyGeneratorExpressions".$ Self reference on target "TargetPropertyGeneratorExpressions".

View File

@ -3,4 +3,4 @@ CMake Error:
\$<TARGET_PROPERTY:COMPILE_DEFINITIONS> \$<TARGET_PROPERTY:COMPILE_DEFINITIONS>
Self reference on target "TargetPropertyGeneratorExpressions".$ Self reference on target "TargetPropertyGeneratorExpressions".

View File

@ -3,4 +3,4 @@ CMake Error:
\$<TARGET_PROPERTY:TargetPropertyGeneratorExpressions,COMPILE_DEFINITIONS> \$<TARGET_PROPERTY:TargetPropertyGeneratorExpressions,COMPILE_DEFINITIONS>
Self reference on target "TargetPropertyGeneratorExpressions".$ Self reference on target "TargetPropertyGeneratorExpressions".