Introduce CM_UNORDERED_SET

Avoid duplicating switch among std::unordered_set, cmsys::hash_set, and
std::set.
This commit is contained in:
Daniel Pfeifer 2016-10-24 22:33:18 +02:00
parent f660832999
commit c15dc19728
4 changed files with 51 additions and 49 deletions

View File

@ -21,6 +21,7 @@
#include "cmTargetLinkLibraryType.h"
#include "cmTargetPropertyComputer.h"
#include "cm_auto_ptr.hxx"
#include "cm_unordered_set.hxx"
#include "cmake.h"
#include <algorithm>
@ -34,16 +35,6 @@
#include <stdlib.h>
#include <string.h>
#if defined(CMake_HAVE_CXX_UNORDERED_SET)
#include <unordered_set>
#define UNORDERED_SET std::unordered_set
#elif defined(CMAKE_BUILD_WITH_CMAKE)
#include <cmsys/hash_set.hxx>
#define UNORDERED_SET cmsys::hash_set
#else
#define UNORDERED_SET std::set
#endif
template <>
const char* cmTargetPropertyComputer::GetSources<cmGeneratorTarget>(
cmGeneratorTarget const* tgt, cmMessenger* /* messenger */,
@ -926,7 +917,7 @@ static void AddInterfaceEntries(
static bool processSources(
cmGeneratorTarget const* tgt,
const std::vector<cmGeneratorTarget::TargetPropertyEntry*>& entries,
std::vector<std::string>& srcs, UNORDERED_SET<std::string>& uniqueSrcs,
std::vector<std::string>& srcs, CM_UNORDERED_SET<std::string>& uniqueSrcs,
cmGeneratorExpressionDAGChecker* dagChecker, std::string const& config,
bool debugSources)
{
@ -1053,7 +1044,7 @@ void cmGeneratorTarget::GetSourceFiles(std::vector<std::string>& files,
cmGeneratorExpressionDAGChecker dagChecker(this->GetName(), "SOURCES",
CM_NULLPTR, CM_NULLPTR);
UNORDERED_SET<std::string> uniqueSrcs;
CM_UNORDERED_SET<std::string> uniqueSrcs;
bool contextDependentDirectSources =
processSources(this, this->SourceEntries, files, uniqueSrcs, &dagChecker,
config, debugSources);
@ -1592,7 +1583,7 @@ class cmTargetCollectLinkLanguages
public:
cmTargetCollectLinkLanguages(cmGeneratorTarget const* target,
const std::string& config,
UNORDERED_SET<std::string>& languages,
CM_UNORDERED_SET<std::string>& languages,
cmGeneratorTarget const* head)
: Config(config)
, Languages(languages)
@ -1659,7 +1650,7 @@ public:
private:
std::string Config;
UNORDERED_SET<std::string>& Languages;
CM_UNORDERED_SET<std::string>& Languages;
cmGeneratorTarget const* HeadTarget;
const cmGeneratorTarget* Target;
std::set<cmGeneratorTarget const*> Visited;
@ -1731,7 +1722,7 @@ void cmGeneratorTarget::ComputeLinkClosure(const std::string& config,
LinkClosure& lc) const
{
// Get languages built in this target.
UNORDERED_SET<std::string> languages;
CM_UNORDERED_SET<std::string> languages;
cmLinkImplementation const* impl = this->GetLinkImplementation(config);
assert(impl);
for (std::vector<std::string>::const_iterator li = impl->Languages.begin();
@ -1748,7 +1739,7 @@ void cmGeneratorTarget::ComputeLinkClosure(const std::string& config,
}
// Store the transitive closure of languages.
for (UNORDERED_SET<std::string>::const_iterator li = languages.begin();
for (CM_UNORDERED_SET<std::string>::const_iterator li = languages.begin();
li != languages.end(); ++li) {
lc.Languages.push_back(*li);
}
@ -1769,7 +1760,7 @@ void cmGeneratorTarget::ComputeLinkClosure(const std::string& config,
}
// Now consider languages that propagate from linked targets.
for (UNORDERED_SET<std::string>::const_iterator sit = languages.begin();
for (CM_UNORDERED_SET<std::string>::const_iterator sit = languages.begin();
sit != languages.end(); ++sit) {
std::string propagates =
"CMAKE_" + *sit + "_LINKER_PREFERENCE_PROPAGATES";
@ -2338,7 +2329,7 @@ static void processIncludeDirectories(
cmGeneratorTarget const* tgt,
const std::vector<cmGeneratorTarget::TargetPropertyEntry*>& entries,
std::vector<std::string>& includes,
UNORDERED_SET<std::string>& uniqueIncludes,
CM_UNORDERED_SET<std::string>& uniqueIncludes,
cmGeneratorExpressionDAGChecker* dagChecker, const std::string& config,
bool debugIncludes, const std::string& language)
{
@ -2451,7 +2442,7 @@ std::vector<std::string> cmGeneratorTarget::GetIncludeDirectories(
const std::string& config, const std::string& lang) const
{
std::vector<std::string> includes;
UNORDERED_SET<std::string> uniqueIncludes;
CM_UNORDERED_SET<std::string> uniqueIncludes;
cmGeneratorExpressionDAGChecker dagChecker(
this->GetName(), "INCLUDE_DIRECTORIES", CM_NULLPTR, CM_NULLPTR);
@ -2528,7 +2519,8 @@ std::vector<std::string> cmGeneratorTarget::GetIncludeDirectories(
static void processCompileOptionsInternal(
cmGeneratorTarget const* tgt,
const std::vector<cmGeneratorTarget::TargetPropertyEntry*>& entries,
std::vector<std::string>& options, UNORDERED_SET<std::string>& uniqueOptions,
std::vector<std::string>& options,
CM_UNORDERED_SET<std::string>& uniqueOptions,
cmGeneratorExpressionDAGChecker* dagChecker, const std::string& config,
bool debugOptions, const char* logName, std::string const& language)
{
@ -2565,7 +2557,8 @@ static void processCompileOptionsInternal(
static void processCompileOptions(
cmGeneratorTarget const* tgt,
const std::vector<cmGeneratorTarget::TargetPropertyEntry*>& entries,
std::vector<std::string>& options, UNORDERED_SET<std::string>& uniqueOptions,
std::vector<std::string>& options,
CM_UNORDERED_SET<std::string>& uniqueOptions,
cmGeneratorExpressionDAGChecker* dagChecker, const std::string& config,
bool debugOptions, std::string const& language)
{
@ -2578,7 +2571,7 @@ void cmGeneratorTarget::GetCompileOptions(std::vector<std::string>& result,
const std::string& config,
const std::string& language) const
{
UNORDERED_SET<std::string> uniqueOptions;
CM_UNORDERED_SET<std::string> uniqueOptions;
cmGeneratorExpressionDAGChecker dagChecker(
this->GetName(), "COMPILE_OPTIONS", CM_NULLPTR, CM_NULLPTR);
@ -2618,7 +2611,8 @@ void cmGeneratorTarget::GetCompileOptions(std::vector<std::string>& result,
static void processCompileFeatures(
cmGeneratorTarget const* tgt,
const std::vector<cmGeneratorTarget::TargetPropertyEntry*>& entries,
std::vector<std::string>& options, UNORDERED_SET<std::string>& uniqueOptions,
std::vector<std::string>& options,
CM_UNORDERED_SET<std::string>& uniqueOptions,
cmGeneratorExpressionDAGChecker* dagChecker, const std::string& config,
bool debugOptions)
{
@ -2630,7 +2624,7 @@ static void processCompileFeatures(
void cmGeneratorTarget::GetCompileFeatures(std::vector<std::string>& result,
const std::string& config) const
{
UNORDERED_SET<std::string> uniqueFeatures;
CM_UNORDERED_SET<std::string> uniqueFeatures;
cmGeneratorExpressionDAGChecker dagChecker(
this->GetName(), "COMPILE_FEATURES", CM_NULLPTR, CM_NULLPTR);
@ -2667,7 +2661,8 @@ void cmGeneratorTarget::GetCompileFeatures(std::vector<std::string>& result,
static void processCompileDefinitions(
cmGeneratorTarget const* tgt,
const std::vector<cmGeneratorTarget::TargetPropertyEntry*>& entries,
std::vector<std::string>& options, UNORDERED_SET<std::string>& uniqueOptions,
std::vector<std::string>& options,
CM_UNORDERED_SET<std::string>& uniqueOptions,
cmGeneratorExpressionDAGChecker* dagChecker, const std::string& config,
bool debugOptions, std::string const& language)
{
@ -2680,7 +2675,7 @@ void cmGeneratorTarget::GetCompileDefinitions(
std::vector<std::string>& list, const std::string& config,
const std::string& language) const
{
UNORDERED_SET<std::string> uniqueOptions;
CM_UNORDERED_SET<std::string> uniqueOptions;
cmGeneratorExpressionDAGChecker dagChecker(
this->GetName(), "COMPILE_DEFINITIONS", CM_NULLPTR, CM_NULLPTR);
@ -4149,7 +4144,7 @@ void cmGeneratorTarget::ComputeLinkInterface(
this->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
// Shared libraries may have runtime implementation dependencies
// on other shared libraries that are not in the interface.
UNORDERED_SET<std::string> emitted;
CM_UNORDERED_SET<std::string> emitted;
for (std::vector<cmLinkItem>::const_iterator li =
iface.Libraries.begin();
li != iface.Libraries.end(); ++li) {

View File

@ -16,6 +16,7 @@
#include "cmState.h"
#include "cmSystemTools.h"
#include "cmTargetPropertyComputer.h"
#include "cm_unordered_set.hxx"
#include "cmake.h"
#include <algorithm>
@ -26,16 +27,6 @@
#include <sstream>
#include <string.h>
#if defined(CMake_HAVE_CXX_UNORDERED_SET)
#include <unordered_set>
#define UNORDERED_SET std::unordered_set
#elif defined(CMAKE_BUILD_WITH_CMAKE)
#include <cmsys/hash_set.hxx>
#define UNORDERED_SET cmsys::hash_set
#else
#define UNORDERED_SET std::set
#endif
template <>
const char* cmTargetPropertyComputer::ComputeLocationForBuild<cmTarget>(
cmTarget const* tgt)
@ -1145,7 +1136,7 @@ const char* cmTarget::GetComputedProperty(
const char* cmTarget::GetProperty(const std::string& prop) const
{
static UNORDERED_SET<std::string> specialProps;
static CM_UNORDERED_SET<std::string> specialProps;
#define MAKE_STATIC_PROP(PROP) static const std::string prop##PROP = #PROP
MAKE_STATIC_PROP(LINK_LIBRARIES);
MAKE_STATIC_PROP(TYPE);

View File

@ -10,16 +10,7 @@
#include "cmSourceFile.h"
#include "cmSourceFileLocation.h"
#include "cmTarget.h"
#if defined(CMake_HAVE_CXX_UNORDERED_SET)
#include <unordered_set>
#define UNORDERED_SET std::unordered_set
#elif defined(CMAKE_BUILD_WITH_CMAKE)
#include <cmsys/hash_set.hxx>
#define UNORDERED_SET cmsys::hash_set
#else
#define UNORDERED_SET std::set
#endif
#include "cm_unordered_set.hxx"
bool cmTargetPropertyComputer::HandleLocationPropertyPolicy(
std::string const& tgtName, cmMessenger* messenger,
@ -59,7 +50,7 @@ bool cmTargetPropertyComputer::WhiteListedInterfaceProperty(
if (cmHasLiteralPrefix(prop, "INTERFACE_")) {
return true;
}
static UNORDERED_SET<std::string> builtIns;
static CM_UNORDERED_SET<std::string> builtIns;
if (builtIns.empty()) {
builtIns.insert("COMPATIBLE_INTERFACE_BOOL");
builtIns.insert("COMPATIBLE_INTERFACE_NUMBER_MAX");

View File

@ -0,0 +1,25 @@
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
#ifndef CM_UNORDERED_SET_HXX
#define CM_UNORDERED_SET_HXX
#include <cmConfigure.h>
#if defined(CMake_HAVE_CXX_UNORDERED_SET)
#include <unordered_set>
#define CM_UNORDERED_SET std::unordered_set
#elif defined(CMAKE_BUILD_WITH_CMAKE)
#include <cmsys/hash_set.hxx>
#define CM_UNORDERED_SET cmsys::hash_set
#else
#include <set>
#define CM_UNORDERED_SET std::set
#endif
#endif