mirror of
https://github.com/Kitware/CMake.git
synced 2026-02-16 04:02:03 -06:00
cmStandardLevelResolver: Factor out public representation of level
This commit is contained in:
@@ -417,6 +417,7 @@ add_library(
|
|||||||
cmSourceFileLocationKind.h
|
cmSourceFileLocationKind.h
|
||||||
cmSourceGroup.cxx
|
cmSourceGroup.cxx
|
||||||
cmSourceGroup.h
|
cmSourceGroup.h
|
||||||
|
cmStandardLevel.h
|
||||||
cmStandardLevelResolver.cxx
|
cmStandardLevelResolver.cxx
|
||||||
cmStandardLevelResolver.h
|
cmStandardLevelResolver.h
|
||||||
cmState.cxx
|
cmState.cxx
|
||||||
|
|||||||
21
Source/cmStandardLevel.h
Normal file
21
Source/cmStandardLevel.h
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
||||||
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "cmConfigure.h" // IWYU pragma: keep
|
||||||
|
|
||||||
|
class cmStandardLevel
|
||||||
|
{
|
||||||
|
size_t index_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
cmStandardLevel(size_t index)
|
||||||
|
: index_(index)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
size_t Index() const { return index_; }
|
||||||
|
friend bool operator<(cmStandardLevel const& l, cmStandardLevel const& r)
|
||||||
|
{
|
||||||
|
return l.index_ < r.index_;
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -13,6 +13,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <cm/iterator>
|
#include <cm/iterator>
|
||||||
|
#include <cm/optional>
|
||||||
#include <cm/string_view>
|
#include <cm/string_view>
|
||||||
#include <cmext/algorithm>
|
#include <cmext/algorithm>
|
||||||
#include <cmext/string_view>
|
#include <cmext/string_view>
|
||||||
@@ -25,6 +26,7 @@
|
|||||||
#include "cmMakefile.h"
|
#include "cmMakefile.h"
|
||||||
#include "cmMessageType.h"
|
#include "cmMessageType.h"
|
||||||
#include "cmPolicies.h"
|
#include "cmPolicies.h"
|
||||||
|
#include "cmStandardLevel.h"
|
||||||
#include "cmStringAlgorithms.h"
|
#include "cmStringAlgorithms.h"
|
||||||
#include "cmTarget.h"
|
#include "cmTarget.h"
|
||||||
#include "cmValue.h"
|
#include "cmValue.h"
|
||||||
@@ -46,12 +48,6 @@ const char* const HIP_FEATURES[] = { nullptr FOR_EACH_HIP_FEATURE(
|
|||||||
FEATURE_STRING) };
|
FEATURE_STRING) };
|
||||||
#undef FEATURE_STRING
|
#undef FEATURE_STRING
|
||||||
|
|
||||||
struct StandardNeeded
|
|
||||||
{
|
|
||||||
int index;
|
|
||||||
int value;
|
|
||||||
};
|
|
||||||
|
|
||||||
int ParseStd(std::string const& level)
|
int ParseStd(std::string const& level)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
@@ -352,7 +348,8 @@ struct StandardLevelComputer
|
|||||||
newRequiredStandard.clear();
|
newRequiredStandard.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto needed = this->HighestStandardNeeded(makefile, feature);
|
cm::optional<cmStandardLevel> needed =
|
||||||
|
this->HighestStandardNeeded(makefile, feature);
|
||||||
|
|
||||||
cmValue existingStandard = currentLangStandardValue;
|
cmValue existingStandard = currentLangStandardValue;
|
||||||
if (!existingStandard) {
|
if (!existingStandard) {
|
||||||
@@ -382,12 +379,12 @@ struct StandardLevelComputer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (needed.index != -1) {
|
if (needed) {
|
||||||
// Ensure the C++ language level is high enough to support
|
// Ensure the C++ language level is high enough to support
|
||||||
// the needed C++ features.
|
// the needed C++ features.
|
||||||
if (existingLevelIter == cm::cend(this->Levels) ||
|
if (existingLevelIter == cm::cend(this->Levels) ||
|
||||||
existingLevelIter < this->Levels.begin() + needed.index) {
|
existingLevelIter < this->Levels.begin() + needed->Index()) {
|
||||||
newRequiredStandard = this->LevelsAsStrings[needed.index];
|
newRequiredStandard = this->LevelsAsStrings[needed->Index()];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -439,23 +436,24 @@ struct StandardLevelComputer
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto needed = this->HighestStandardNeeded(makefile, feature);
|
cm::optional<cmStandardLevel> needed =
|
||||||
|
this->HighestStandardNeeded(makefile, feature);
|
||||||
|
|
||||||
return (needed.index == -1) ||
|
return !needed ||
|
||||||
(this->Levels.begin() + needed.index) <= existingLevelIter;
|
(this->Levels.begin() + needed->Index()) <= existingLevelIter;
|
||||||
}
|
}
|
||||||
|
|
||||||
StandardNeeded HighestStandardNeeded(cmMakefile* makefile,
|
cm::optional<cmStandardLevel> HighestStandardNeeded(
|
||||||
std::string const& feature) const
|
cmMakefile* makefile, std::string const& feature) const
|
||||||
{
|
{
|
||||||
std::string prefix = cmStrCat("CMAKE_", this->Language);
|
std::string prefix = cmStrCat("CMAKE_", this->Language);
|
||||||
StandardNeeded maxLevel = { -1, -1 };
|
cm::optional<cmStandardLevel> maxLevel;
|
||||||
for (size_t i = 0; i < this->Levels.size(); ++i) {
|
for (size_t i = 0; i < this->Levels.size(); ++i) {
|
||||||
if (cmValue prop = makefile->GetDefinition(
|
if (cmValue prop = makefile->GetDefinition(
|
||||||
cmStrCat(prefix, this->LevelsAsStrings[i], "_COMPILE_FEATURES"))) {
|
cmStrCat(prefix, this->LevelsAsStrings[i], "_COMPILE_FEATURES"))) {
|
||||||
cmList props{ *prop };
|
cmList props{ *prop };
|
||||||
if (cm::contains(props, feature)) {
|
if (cm::contains(props, feature)) {
|
||||||
maxLevel = { static_cast<int>(i), this->Levels[i] };
|
maxLevel = cmStandardLevel(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user