cmake/Source/cmState.cxx

1087 lines
33 KiB
C++
Raw Normal View History

2016-10-30 18:24:19 +01:00
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
2015-08-17 11:37:30 +02:00
#include "cmState.h"
2017-04-14 19:02:05 +02:00
#include <algorithm>
2020-08-30 11:54:41 +02:00
#include <array>
2020-02-01 23:06:01 +01:00
#include <cassert>
#include <cstdlib>
2017-04-14 19:02:05 +02:00
#include <utility>
2020-02-01 23:06:01 +01:00
#include <cm/memory>
#include "cmsys/RegularExpression.hxx"
2015-08-17 11:37:30 +02:00
#include "cmCacheManager.h"
#include "cmCommand.h"
2015-11-17 17:22:37 +01:00
#include "cmDefinitions.h"
2020-02-01 23:06:01 +01:00
#include "cmExecutionStatus.h"
2018-08-09 18:06:22 +02:00
#include "cmGlobVerificationManager.h"
2016-10-30 18:24:19 +01:00
#include "cmListFileCache.h"
2020-02-01 23:06:01 +01:00
#include "cmMakefile.h"
#include "cmMessageType.h"
2017-04-14 19:02:05 +02:00
#include "cmStatePrivate.h"
#include "cmStateSnapshot.h"
2020-02-01 23:06:01 +01:00
#include "cmStringAlgorithms.h"
2016-10-30 18:24:19 +01:00
#include "cmSystemTools.h"
2016-07-09 11:21:54 +02:00
#include "cmake.h"
2015-08-17 11:37:30 +02:00
2021-11-20 13:41:27 +01:00
cmState::cmState(Mode mode, ProjectKind projectKind)
: StateMode(mode)
, StateProjectKind(projectKind)
2015-08-17 11:37:30 +02:00
{
2020-02-01 23:06:01 +01:00
this->CacheManager = cm::make_unique<cmCacheManager>();
this->GlobVerificationManager = cm::make_unique<cmGlobVerificationManager>();
2015-08-17 11:37:30 +02:00
}
2020-02-01 23:06:01 +01:00
cmState::~cmState() = default;
2015-08-17 11:37:30 +02:00
2020-08-30 11:54:41 +02:00
const std::string& cmState::GetTargetTypeName(
cmStateEnums::TargetType targetType)
{
#define MAKE_STATIC_PROP(PROP) static const std::string prop##PROP = #PROP
MAKE_STATIC_PROP(STATIC_LIBRARY);
MAKE_STATIC_PROP(MODULE_LIBRARY);
MAKE_STATIC_PROP(SHARED_LIBRARY);
MAKE_STATIC_PROP(OBJECT_LIBRARY);
MAKE_STATIC_PROP(EXECUTABLE);
MAKE_STATIC_PROP(UTILITY);
MAKE_STATIC_PROP(GLOBAL_TARGET);
MAKE_STATIC_PROP(INTERFACE_LIBRARY);
MAKE_STATIC_PROP(UNKNOWN_LIBRARY);
static const std::string propEmpty;
#undef MAKE_STATIC_PROP
2016-07-09 11:21:54 +02:00
switch (targetType) {
2017-04-14 19:02:05 +02:00
case cmStateEnums::STATIC_LIBRARY:
2020-08-30 11:54:41 +02:00
return propSTATIC_LIBRARY;
2017-04-14 19:02:05 +02:00
case cmStateEnums::MODULE_LIBRARY:
2020-08-30 11:54:41 +02:00
return propMODULE_LIBRARY;
2017-04-14 19:02:05 +02:00
case cmStateEnums::SHARED_LIBRARY:
2020-08-30 11:54:41 +02:00
return propSHARED_LIBRARY;
2017-04-14 19:02:05 +02:00
case cmStateEnums::OBJECT_LIBRARY:
2020-08-30 11:54:41 +02:00
return propOBJECT_LIBRARY;
2017-04-14 19:02:05 +02:00
case cmStateEnums::EXECUTABLE:
2020-08-30 11:54:41 +02:00
return propEXECUTABLE;
2017-04-14 19:02:05 +02:00
case cmStateEnums::UTILITY:
2020-08-30 11:54:41 +02:00
return propUTILITY;
2017-04-14 19:02:05 +02:00
case cmStateEnums::GLOBAL_TARGET:
2020-08-30 11:54:41 +02:00
return propGLOBAL_TARGET;
2017-04-14 19:02:05 +02:00
case cmStateEnums::INTERFACE_LIBRARY:
2020-08-30 11:54:41 +02:00
return propINTERFACE_LIBRARY;
2017-04-14 19:02:05 +02:00
case cmStateEnums::UNKNOWN_LIBRARY:
2020-08-30 11:54:41 +02:00
return propUNKNOWN_LIBRARY;
2016-07-09 11:21:54 +02:00
}
2017-04-14 19:02:05 +02:00
assert(false && "Unexpected target type");
2020-08-30 11:54:41 +02:00
return propEmpty;
2016-03-13 13:35:51 +01:00
}
2020-08-30 11:54:41 +02:00
static const std::array<std::string, 7> cmCacheEntryTypes = {
{ "BOOL", "PATH", "FILEPATH", "STRING", "INTERNAL", "STATIC",
"UNINITIALIZED" }
};
2015-08-17 11:37:30 +02:00
2020-08-30 11:54:41 +02:00
const std::string& cmState::CacheEntryTypeToString(
cmStateEnums::CacheEntryType type)
2015-08-17 11:37:30 +02:00
{
2020-08-30 11:54:41 +02:00
if (type < cmStateEnums::BOOL || type > cmStateEnums::UNINITIALIZED) {
type = cmStateEnums::UNINITIALIZED;
2016-07-09 11:21:54 +02:00
}
2015-08-17 11:37:30 +02:00
return cmCacheEntryTypes[type];
}
2020-08-30 11:54:41 +02:00
cmStateEnums::CacheEntryType cmState::StringToCacheEntryType(
const std::string& s)
2019-11-11 23:01:05 +01:00
{
cmStateEnums::CacheEntryType type = cmStateEnums::STRING;
StringToCacheEntryType(s, type);
return type;
}
2020-08-30 11:54:41 +02:00
bool cmState::StringToCacheEntryType(const std::string& s,
2019-11-11 23:01:05 +01:00
cmStateEnums::CacheEntryType& type)
2015-08-17 11:37:30 +02:00
{
2020-08-30 11:54:41 +02:00
for (size_t i = 0; i < cmCacheEntryTypes.size(); ++i) {
if (s == cmCacheEntryTypes[i]) {
2019-11-11 23:01:05 +01:00
type = static_cast<cmStateEnums::CacheEntryType>(i);
return true;
2015-08-17 11:37:30 +02:00
}
2016-07-09 11:21:54 +02:00
}
2019-11-11 23:01:05 +01:00
return false;
2015-08-17 11:37:30 +02:00
}
bool cmState::IsCacheEntryType(std::string const& key)
{
2021-09-14 00:13:48 +02:00
return std::any_of(
cmCacheEntryTypes.begin(), cmCacheEntryTypes.end(),
[&key](std::string const& i) -> bool { return key == i; });
2015-08-17 11:37:30 +02:00
}
2016-03-13 13:35:51 +01:00
bool cmState::LoadCache(const std::string& path, bool internal,
std::set<std::string>& excludes,
std::set<std::string>& includes)
{
2016-07-09 11:21:54 +02:00
return this->CacheManager->LoadCache(path, internal, excludes, includes);
2016-03-13 13:35:51 +01:00
}
2018-04-23 21:13:27 +02:00
bool cmState::SaveCache(const std::string& path, cmMessenger* messenger)
2016-03-13 13:35:51 +01:00
{
2018-04-23 21:13:27 +02:00
return this->CacheManager->SaveCache(path, messenger);
2016-03-13 13:35:51 +01:00
}
bool cmState::DeleteCache(const std::string& path)
{
return this->CacheManager->DeleteCache(path);
}
2021-09-14 00:13:48 +02:00
bool cmState::IsCacheLoaded() const
{
return this->CacheManager->IsCacheLoaded();
}
2015-08-17 11:37:30 +02:00
std::vector<std::string> cmState::GetCacheEntryKeys() const
{
2020-08-30 11:54:41 +02:00
return this->CacheManager->GetCacheEntryKeys();
}
2021-11-20 13:41:27 +01:00
cmValue cmState::GetCacheEntryValue(std::string const& key) const
2020-08-30 11:54:41 +02:00
{
return this->CacheManager->GetCacheEntryValue(key);
2015-08-17 11:37:30 +02:00
}
2020-08-30 11:54:41 +02:00
std::string cmState::GetSafeCacheEntryValue(std::string const& key) const
2015-08-17 11:37:30 +02:00
{
2021-11-20 13:41:27 +01:00
if (cmValue val = this->GetCacheEntryValue(key)) {
2020-08-30 11:54:41 +02:00
return *val;
2016-07-09 11:21:54 +02:00
}
2020-08-30 11:54:41 +02:00
return std::string();
2015-08-17 11:37:30 +02:00
}
2021-11-20 13:41:27 +01:00
cmValue cmState::GetInitializedCacheValue(std::string const& key) const
2015-08-17 11:37:30 +02:00
{
2016-03-13 13:35:51 +01:00
return this->CacheManager->GetInitializedCacheValue(key);
2015-08-17 11:37:30 +02:00
}
2017-04-14 19:02:05 +02:00
cmStateEnums::CacheEntryType cmState::GetCacheEntryType(
2016-07-09 11:21:54 +02:00
std::string const& key) const
2015-08-17 11:37:30 +02:00
{
2020-08-30 11:54:41 +02:00
return this->CacheManager->GetCacheEntryType(key);
2015-08-17 11:37:30 +02:00
}
void cmState::SetCacheEntryValue(std::string const& key,
2016-07-09 11:21:54 +02:00
std::string const& value)
2015-08-17 11:37:30 +02:00
{
2016-03-13 13:35:51 +01:00
this->CacheManager->SetCacheEntryValue(key, value);
2015-08-17 11:37:30 +02:00
}
void cmState::SetCacheEntryProperty(std::string const& key,
2016-07-09 11:21:54 +02:00
std::string const& propertyName,
std::string const& value)
2015-08-17 11:37:30 +02:00
{
2020-08-30 11:54:41 +02:00
this->CacheManager->SetCacheEntryProperty(key, propertyName, value);
2015-08-17 11:37:30 +02:00
}
void cmState::SetCacheEntryBoolProperty(std::string const& key,
2016-07-09 11:21:54 +02:00
std::string const& propertyName,
bool value)
2015-08-17 11:37:30 +02:00
{
2020-08-30 11:54:41 +02:00
this->CacheManager->SetCacheEntryBoolProperty(key, propertyName, value);
2015-08-17 11:37:30 +02:00
}
2016-10-30 18:24:19 +01:00
std::vector<std::string> cmState::GetCacheEntryPropertyList(
const std::string& key)
{
2020-08-30 11:54:41 +02:00
return this->CacheManager->GetCacheEntryPropertyList(key);
2016-10-30 18:24:19 +01:00
}
2021-11-20 13:41:27 +01:00
cmValue cmState::GetCacheEntryProperty(std::string const& key,
std::string const& propertyName)
2015-08-17 11:37:30 +02:00
{
2020-08-30 11:54:41 +02:00
return this->CacheManager->GetCacheEntryProperty(key, propertyName);
2015-08-17 11:37:30 +02:00
}
bool cmState::GetCacheEntryPropertyAsBool(std::string const& key,
2016-07-09 11:21:54 +02:00
std::string const& propertyName)
2015-08-17 11:37:30 +02:00
{
2020-08-30 11:54:41 +02:00
return this->CacheManager->GetCacheEntryPropertyAsBool(key, propertyName);
2015-08-17 11:37:30 +02:00
}
2021-11-20 13:41:27 +01:00
void cmState::AddCacheEntry(const std::string& key, cmValue value,
2016-07-09 11:21:54 +02:00
const char* helpString,
2017-04-14 19:02:05 +02:00
cmStateEnums::CacheEntryType type)
2015-08-17 11:37:30 +02:00
{
2016-07-09 11:21:54 +02:00
this->CacheManager->AddCacheEntry(key, value, helpString, type);
2015-08-17 11:37:30 +02:00
}
2018-08-09 18:06:22 +02:00
bool cmState::DoWriteGlobVerifyTarget() const
{
return this->GlobVerificationManager->DoWriteVerifyTarget();
}
std::string const& cmState::GetGlobVerifyScript() const
{
return this->GlobVerificationManager->GetVerifyScript();
}
std::string const& cmState::GetGlobVerifyStamp() const
{
return this->GlobVerificationManager->GetVerifyStamp();
}
2022-03-29 21:10:50 +02:00
bool cmState::SaveVerificationScript(const std::string& path,
cmMessenger* messenger)
2018-08-09 18:06:22 +02:00
{
2022-03-29 21:10:50 +02:00
return this->GlobVerificationManager->SaveVerificationScript(path,
messenger);
2018-08-09 18:06:22 +02:00
}
2022-03-29 21:10:50 +02:00
void cmState::AddGlobCacheEntry(
bool recurse, bool listDirectories, bool followSymlinks,
const std::string& relative, const std::string& expression,
const std::vector<std::string>& files, const std::string& variable,
cmListFileBacktrace const& backtrace, cmMessenger* messenger)
2018-08-09 18:06:22 +02:00
{
this->GlobVerificationManager->AddCacheEntry(
recurse, listDirectories, followSymlinks, relative, expression, files,
2022-03-29 21:10:50 +02:00
variable, backtrace, messenger);
2018-08-09 18:06:22 +02:00
}
2015-08-17 11:37:30 +02:00
void cmState::RemoveCacheEntry(std::string const& key)
{
2016-03-13 13:35:51 +01:00
this->CacheManager->RemoveCacheEntry(key);
2015-08-17 11:37:30 +02:00
}
void cmState::AppendCacheEntryProperty(const std::string& key,
2016-07-09 11:21:54 +02:00
const std::string& property,
const std::string& value, bool asString)
2015-08-17 11:37:30 +02:00
{
2020-08-30 11:54:41 +02:00
this->CacheManager->AppendCacheEntryProperty(key, property, value, asString);
2015-08-17 11:37:30 +02:00
}
void cmState::RemoveCacheEntryProperty(std::string const& key,
2016-07-09 11:21:54 +02:00
std::string const& propertyName)
2015-08-17 11:37:30 +02:00
{
2020-08-30 11:54:41 +02:00
this->CacheManager->RemoveCacheEntryProperty(key, propertyName);
2015-08-17 11:37:30 +02:00
}
2017-04-14 19:02:05 +02:00
cmStateSnapshot cmState::Reset()
2015-08-17 11:37:30 +02:00
{
2020-02-01 23:06:01 +01:00
this->GlobalProperties.Clear();
2020-08-30 11:54:41 +02:00
this->PropertyDefinitions = {};
2018-10-07 12:27:06 +02:00
this->GlobVerificationManager->Reset();
2015-08-17 11:37:30 +02:00
2017-04-14 19:02:05 +02:00
cmStateDetail::PositionType pos = this->SnapshotData.Truncate();
2015-11-17 17:22:37 +01:00
this->ExecutionListFiles.Truncate();
{
2017-04-14 19:02:05 +02:00
cmLinkedTree<cmStateDetail::BuildsystemDirectoryStateType>::iterator it =
2015-11-17 17:22:37 +01:00
this->BuildsystemDirectory.Truncate();
2016-07-09 11:21:54 +02:00
it->IncludeDirectories.clear();
it->CompileDefinitions.clear();
it->CompileOptions.clear();
2018-10-28 12:09:07 +01:00
it->LinkOptions.clear();
it->LinkDirectories.clear();
2022-11-16 20:14:03 +01:00
it->CurrentScope = pos;
2016-10-30 18:24:19 +01:00
it->NormalTargetNames.clear();
2021-09-14 00:13:48 +02:00
it->ImportedTargetNames.clear();
2020-02-01 23:06:01 +01:00
it->Properties.Clear();
2016-07-09 11:21:54 +02:00
it->Children.clear();
2015-11-17 17:22:37 +01:00
}
this->PolicyStack.Clear();
pos->Policies = this->PolicyStack.Root();
pos->PolicyRoot = this->PolicyStack.Root();
pos->PolicyScope = this->PolicyStack.Root();
assert(pos->Policies.IsValid());
assert(pos->PolicyRoot.IsValid());
2016-03-13 13:35:51 +01:00
{
2016-07-09 11:21:54 +02:00
std::string srcDir =
2018-10-28 12:09:07 +01:00
*cmDefinitions::Get("CMAKE_SOURCE_DIR", pos->Vars, pos->Root);
2016-07-09 11:21:54 +02:00
std::string binDir =
2018-10-28 12:09:07 +01:00
*cmDefinitions::Get("CMAKE_BINARY_DIR", pos->Vars, pos->Root);
2016-07-09 11:21:54 +02:00
this->VarTree.Clear();
pos->Vars = this->VarTree.Push(this->VarTree.Root());
pos->Parent = this->VarTree.Root();
pos->Root = this->VarTree.Root();
2015-08-17 11:37:30 +02:00
2020-02-01 23:06:01 +01:00
pos->Vars->Set("CMAKE_SOURCE_DIR", srcDir);
pos->Vars->Set("CMAKE_BINARY_DIR", binDir);
2016-03-13 13:35:51 +01:00
}
2016-07-09 11:21:54 +02:00
this->DefineProperty("RULE_LAUNCH_COMPILE", cmProperty::DIRECTORY, "", "",
true);
this->DefineProperty("RULE_LAUNCH_LINK", cmProperty::DIRECTORY, "", "",
true);
this->DefineProperty("RULE_LAUNCH_CUSTOM", cmProperty::DIRECTORY, "", "",
true);
this->DefineProperty("RULE_LAUNCH_COMPILE", cmProperty::TARGET, "", "",
true);
this->DefineProperty("RULE_LAUNCH_LINK", cmProperty::TARGET, "", "", true);
this->DefineProperty("RULE_LAUNCH_CUSTOM", cmProperty::TARGET, "", "", true);
2015-11-17 17:22:37 +01:00
2020-02-01 23:06:01 +01:00
return { this, pos };
2015-08-17 11:37:30 +02:00
}
void cmState::DefineProperty(const std::string& name,
2016-07-09 11:21:54 +02:00
cmProperty::ScopeType scope,
2020-08-30 11:54:41 +02:00
const std::string& ShortDescription,
2022-03-29 21:10:50 +02:00
const std::string& FullDescription, bool chained,
const std::string& initializeFromVariable)
2015-08-17 11:37:30 +02:00
{
2020-08-30 11:54:41 +02:00
this->PropertyDefinitions.DefineProperty(name, scope, ShortDescription,
2022-03-29 21:10:50 +02:00
FullDescription, chained,
initializeFromVariable);
2015-08-17 11:37:30 +02:00
}
2016-07-09 11:21:54 +02:00
cmPropertyDefinition const* cmState::GetPropertyDefinition(
const std::string& name, cmProperty::ScopeType scope) const
2015-08-17 11:37:30 +02:00
{
2020-08-30 11:54:41 +02:00
return this->PropertyDefinitions.GetPropertyDefinition(name, scope);
2015-08-17 11:37:30 +02:00
}
bool cmState::IsPropertyChained(const std::string& name,
2015-11-17 17:22:37 +01:00
cmProperty::ScopeType scope) const
2015-08-17 11:37:30 +02:00
{
2021-09-14 00:13:48 +02:00
if (const auto* def = this->GetPropertyDefinition(name, scope)) {
2020-08-30 11:54:41 +02:00
return def->IsChained();
2016-07-09 11:21:54 +02:00
}
2020-08-30 11:54:41 +02:00
return false;
2015-08-17 11:37:30 +02:00
}
void cmState::SetLanguageEnabled(std::string const& l)
{
2020-02-01 23:06:01 +01:00
auto it = std::lower_bound(this->EnabledLanguages.begin(),
this->EnabledLanguages.end(), l);
2016-07-09 11:21:54 +02:00
if (it == this->EnabledLanguages.end() || *it != l) {
2015-08-17 11:37:30 +02:00
this->EnabledLanguages.insert(it, l);
2016-07-09 11:21:54 +02:00
}
2015-08-17 11:37:30 +02:00
}
bool cmState::GetLanguageEnabled(std::string const& l) const
{
return std::binary_search(this->EnabledLanguages.begin(),
this->EnabledLanguages.end(), l);
}
std::vector<std::string> cmState::GetEnabledLanguages() const
{
return this->EnabledLanguages;
}
void cmState::SetEnabledLanguages(std::vector<std::string> const& langs)
{
this->EnabledLanguages = langs;
}
void cmState::ClearEnabledLanguages()
{
this->EnabledLanguages.clear();
}
2017-07-20 19:35:53 +02:00
bool cmState::GetIsGeneratorMultiConfig() const
2015-08-17 11:37:30 +02:00
{
2017-07-20 19:35:53 +02:00
return this->IsGeneratorMultiConfig;
}
2015-08-17 11:37:30 +02:00
2017-07-20 19:35:53 +02:00
void cmState::SetIsGeneratorMultiConfig(bool b)
{
this->IsGeneratorMultiConfig = b;
2015-08-17 11:37:30 +02:00
}
2020-02-01 23:06:01 +01:00
void cmState::AddBuiltinCommand(std::string const& name,
std::unique_ptr<cmCommand> command)
{
this->AddBuiltinCommand(name, cmLegacyCommandWrapper(std::move(command)));
}
void cmState::AddBuiltinCommand(std::string const& name, Command command)
2015-08-17 11:37:30 +02:00
{
2017-07-20 19:35:53 +02:00
assert(name == cmSystemTools::LowerCase(name));
assert(this->BuiltinCommands.find(name) == this->BuiltinCommands.end());
2020-02-01 23:06:01 +01:00
this->BuiltinCommands.emplace(name, std::move(command));
2017-07-20 19:35:53 +02:00
}
2020-02-01 23:06:01 +01:00
static bool InvokeBuiltinCommand(cmState::BuiltinCommand command,
std::vector<cmListFileArgument> const& args,
cmExecutionStatus& status)
{
cmMakefile& mf = status.GetMakefile();
std::vector<std::string> expandedArguments;
if (!mf.ExpandArguments(args, expandedArguments)) {
// There was an error expanding arguments. It was already
// reported, so we can skip this command without error.
return true;
}
return command(expandedArguments, status);
}
void cmState::AddBuiltinCommand(std::string const& name,
BuiltinCommand command)
{
this->AddBuiltinCommand(
name,
[command](const std::vector<cmListFileArgument>& args,
cmExecutionStatus& status) -> bool {
return InvokeBuiltinCommand(command, args, status);
});
}
2021-09-14 00:13:48 +02:00
void cmState::AddFlowControlCommand(std::string const& name, Command command)
{
this->FlowControlCommands.insert(name);
this->AddBuiltinCommand(name, std::move(command));
}
void cmState::AddFlowControlCommand(std::string const& name,
BuiltinCommand command)
{
this->FlowControlCommands.insert(name);
this->AddBuiltinCommand(name, command);
}
2020-02-01 23:06:01 +01:00
void cmState::AddDisallowedCommand(std::string const& name,
BuiltinCommand command,
2017-07-20 19:35:53 +02:00
cmPolicies::PolicyID policy,
const char* message)
{
2020-02-01 23:06:01 +01:00
this->AddBuiltinCommand(
name,
[command, policy, message](const std::vector<cmListFileArgument>& args,
cmExecutionStatus& status) -> bool {
cmMakefile& mf = status.GetMakefile();
switch (mf.GetPolicyStatus(policy)) {
case cmPolicies::WARN:
mf.IssueMessage(MessageType::AUTHOR_WARNING,
cmPolicies::GetPolicyWarning(policy));
2021-11-20 13:41:27 +01:00
CM_FALLTHROUGH;
2020-02-01 23:06:01 +01:00
case cmPolicies::OLD:
break;
case cmPolicies::REQUIRED_IF_USED:
case cmPolicies::REQUIRED_ALWAYS:
case cmPolicies::NEW:
mf.IssueMessage(MessageType::FATAL_ERROR, message);
return true;
}
return InvokeBuiltinCommand(command, args, status);
});
2017-07-20 19:35:53 +02:00
}
void cmState::AddUnexpectedCommand(std::string const& name, const char* error)
{
2020-02-01 23:06:01 +01:00
this->AddBuiltinCommand(
name,
[name, error](std::vector<cmListFileArgument> const&,
cmExecutionStatus& status) -> bool {
2021-11-20 13:41:27 +01:00
cmValue versionValue =
2020-02-01 23:06:01 +01:00
status.GetMakefile().GetDefinition("CMAKE_MINIMUM_REQUIRED_VERSION");
2021-09-14 00:13:48 +02:00
if (name == "endif" &&
(!versionValue || atof(versionValue->c_str()) <= 1.4)) {
2020-02-01 23:06:01 +01:00
return true;
}
status.SetError(error);
return false;
});
2015-08-17 11:37:30 +02:00
}
2021-09-14 00:13:48 +02:00
void cmState::AddUnexpectedFlowControlCommand(std::string const& name,
const char* error)
{
this->FlowControlCommands.insert(name);
this->AddUnexpectedCommand(name, error);
}
bool cmState::AddScriptedCommand(std::string const& name, BT<Command> command,
cmMakefile& mf)
2015-08-17 11:37:30 +02:00
{
2017-07-20 19:35:53 +02:00
std::string sName = cmSystemTools::LowerCase(name);
2021-09-14 00:13:48 +02:00
if (this->FlowControlCommands.count(sName)) {
mf.GetCMakeInstance()->IssueMessage(
MessageType::FATAL_ERROR,
cmStrCat("Built-in flow control command \"", sName,
"\" cannot be overridden."),
command.Backtrace);
2022-08-04 22:12:04 +02:00
cmSystemTools::SetFatalErrorOccurred();
2021-09-14 00:13:48 +02:00
return false;
}
2017-07-20 19:35:53 +02:00
// if the command already exists, give a new name to the old command.
2020-02-01 23:06:01 +01:00
if (Command oldCmd = this->GetCommandByExactName(sName)) {
this->ScriptedCommands["_" + sName] = oldCmd;
2017-07-20 19:35:53 +02:00
}
2021-09-14 00:13:48 +02:00
this->ScriptedCommands[sName] = std::move(command.Value);
return true;
2015-08-17 11:37:30 +02:00
}
2020-02-01 23:06:01 +01:00
cmState::Command cmState::GetCommand(std::string const& name) const
2015-08-17 11:37:30 +02:00
{
2021-09-14 00:13:48 +02:00
return this->GetCommandByExactName(cmSystemTools::LowerCase(name));
2018-08-09 18:06:22 +02:00
}
2020-02-01 23:06:01 +01:00
cmState::Command cmState::GetCommandByExactName(std::string const& name) const
2018-08-09 18:06:22 +02:00
{
2020-02-01 23:06:01 +01:00
auto pos = this->ScriptedCommands.find(name);
2017-07-20 19:35:53 +02:00
if (pos != this->ScriptedCommands.end()) {
return pos->second;
2016-07-09 11:21:54 +02:00
}
2018-08-09 18:06:22 +02:00
pos = this->BuiltinCommands.find(name);
2017-07-20 19:35:53 +02:00
if (pos != this->BuiltinCommands.end()) {
return pos->second;
}
2018-01-26 17:06:56 +01:00
return nullptr;
2015-08-17 11:37:30 +02:00
}
std::vector<std::string> cmState::GetCommandNames() const
{
std::vector<std::string> commandNames;
2017-07-20 19:35:53 +02:00
commandNames.reserve(this->BuiltinCommands.size() +
this->ScriptedCommands.size());
2018-01-26 17:06:56 +01:00
for (auto const& bc : this->BuiltinCommands) {
commandNames.push_back(bc.first);
2017-07-20 19:35:53 +02:00
}
2018-01-26 17:06:56 +01:00
for (auto const& sc : this->ScriptedCommands) {
commandNames.push_back(sc.first);
2016-07-09 11:21:54 +02:00
}
2017-07-20 19:35:53 +02:00
std::sort(commandNames.begin(), commandNames.end());
commandNames.erase(std::unique(commandNames.begin(), commandNames.end()),
commandNames.end());
2015-08-17 11:37:30 +02:00
return commandNames;
}
2018-11-29 20:27:00 +01:00
void cmState::RemoveBuiltinCommand(std::string const& name)
{
assert(name == cmSystemTools::LowerCase(name));
2020-02-01 23:06:01 +01:00
this->BuiltinCommands.erase(name);
2018-11-29 20:27:00 +01:00
}
2015-08-17 11:37:30 +02:00
void cmState::RemoveUserDefinedCommands()
{
2017-07-20 19:35:53 +02:00
this->ScriptedCommands.clear();
2015-08-17 11:37:30 +02:00
}
void cmState::SetGlobalProperty(const std::string& prop, const char* value)
{
2015-11-17 17:22:37 +01:00
this->GlobalProperties.SetProperty(prop, value);
2015-08-17 11:37:30 +02:00
}
2021-11-20 13:41:27 +01:00
void cmState::SetGlobalProperty(const std::string& prop, cmValue value)
{
this->GlobalProperties.SetProperty(prop, value);
}
2015-08-17 11:37:30 +02:00
2020-08-30 11:54:41 +02:00
void cmState::AppendGlobalProperty(const std::string& prop,
const std::string& value, bool asString)
2015-08-17 11:37:30 +02:00
{
2015-11-17 17:22:37 +01:00
this->GlobalProperties.AppendProperty(prop, value, asString);
2015-08-17 11:37:30 +02:00
}
2021-11-20 13:41:27 +01:00
cmValue cmState::GetGlobalProperty(const std::string& prop)
2015-08-17 11:37:30 +02:00
{
2016-07-09 11:21:54 +02:00
if (prop == "CACHE_VARIABLES") {
2015-08-17 11:37:30 +02:00
std::vector<std::string> cacheKeys = this->GetCacheEntryKeys();
this->SetGlobalProperty("CACHE_VARIABLES", cmJoin(cacheKeys, ";").c_str());
2016-07-09 11:21:54 +02:00
} else if (prop == "COMMANDS") {
2015-08-17 11:37:30 +02:00
std::vector<std::string> commands = this->GetCommandNames();
this->SetGlobalProperty("COMMANDS", cmJoin(commands, ";").c_str());
2016-07-09 11:21:54 +02:00
} else if (prop == "IN_TRY_COMPILE") {
2021-11-20 13:41:27 +01:00
this->SetGlobalProperty(
"IN_TRY_COMPILE",
this->StateProjectKind == ProjectKind::TryCompile ? "1" : "0");
2017-07-20 19:35:53 +02:00
} else if (prop == "GENERATOR_IS_MULTI_CONFIG") {
this->SetGlobalProperty("GENERATOR_IS_MULTI_CONFIG",
this->IsGeneratorMultiConfig ? "1" : "0");
2016-07-09 11:21:54 +02:00
} else if (prop == "ENABLED_LANGUAGES") {
2015-08-17 11:37:30 +02:00
std::string langs;
langs = cmJoin(this->EnabledLanguages, ";");
this->SetGlobalProperty("ENABLED_LANGUAGES", langs.c_str());
2019-11-11 23:01:05 +01:00
} else if (prop == "CMAKE_ROLE") {
std::string mode = this->GetModeString();
this->SetGlobalProperty("CMAKE_ROLE", mode.c_str());
2016-07-09 11:21:54 +02:00
}
2015-08-17 11:37:30 +02:00
#define STRING_LIST_ELEMENT(F) ";" #F
2016-07-09 11:21:54 +02:00
if (prop == "CMAKE_C_KNOWN_FEATURES") {
2020-08-30 11:54:41 +02:00
static const std::string s_out(
&FOR_EACH_C_FEATURE(STRING_LIST_ELEMENT)[1]);
2021-11-20 13:41:27 +01:00
return cmValue(s_out);
2019-11-11 23:01:05 +01:00
}
if (prop == "CMAKE_C90_KNOWN_FEATURES") {
2020-08-30 11:54:41 +02:00
static const std::string s_out(
&FOR_EACH_C90_FEATURE(STRING_LIST_ELEMENT)[1]);
2021-11-20 13:41:27 +01:00
return cmValue(s_out);
2019-11-11 23:01:05 +01:00
}
if (prop == "CMAKE_C99_KNOWN_FEATURES") {
2020-08-30 11:54:41 +02:00
static const std::string s_out(
&FOR_EACH_C99_FEATURE(STRING_LIST_ELEMENT)[1]);
2021-11-20 13:41:27 +01:00
return cmValue(s_out);
2019-11-11 23:01:05 +01:00
}
if (prop == "CMAKE_C11_KNOWN_FEATURES") {
2020-08-30 11:54:41 +02:00
static const std::string s_out(
&FOR_EACH_C11_FEATURE(STRING_LIST_ELEMENT)[1]);
2021-11-20 13:41:27 +01:00
return cmValue(s_out);
2016-07-09 11:21:54 +02:00
}
if (prop == "CMAKE_CXX_KNOWN_FEATURES") {
2020-08-30 11:54:41 +02:00
static const std::string s_out(
&FOR_EACH_CXX_FEATURE(STRING_LIST_ELEMENT)[1]);
2021-11-20 13:41:27 +01:00
return cmValue(s_out);
2016-07-09 11:21:54 +02:00
}
2019-11-11 23:01:05 +01:00
if (prop == "CMAKE_CXX98_KNOWN_FEATURES") {
2020-08-30 11:54:41 +02:00
static const std::string s_out(
&FOR_EACH_CXX98_FEATURE(STRING_LIST_ELEMENT)[1]);
2021-11-20 13:41:27 +01:00
return cmValue(s_out);
2019-11-11 23:01:05 +01:00
}
if (prop == "CMAKE_CXX11_KNOWN_FEATURES") {
2020-08-30 11:54:41 +02:00
static const std::string s_out(
&FOR_EACH_CXX11_FEATURE(STRING_LIST_ELEMENT)[1]);
2021-11-20 13:41:27 +01:00
return cmValue(s_out);
2019-11-11 23:01:05 +01:00
}
if (prop == "CMAKE_CXX14_KNOWN_FEATURES") {
2020-08-30 11:54:41 +02:00
static const std::string s_out(
&FOR_EACH_CXX14_FEATURE(STRING_LIST_ELEMENT)[1]);
2021-11-20 13:41:27 +01:00
return cmValue(s_out);
2020-08-30 11:54:41 +02:00
}
if (prop == "CMAKE_CUDA_KNOWN_FEATURES") {
static const std::string s_out(
&FOR_EACH_CUDA_FEATURE(STRING_LIST_ELEMENT)[1]);
2021-11-20 13:41:27 +01:00
return cmValue(s_out);
2019-11-11 23:01:05 +01:00
}
2015-08-17 11:37:30 +02:00
#undef STRING_LIST_ELEMENT
2015-11-17 17:22:37 +01:00
return this->GlobalProperties.GetPropertyValue(prop);
2015-08-17 11:37:30 +02:00
}
bool cmState::GetGlobalPropertyAsBool(const std::string& prop)
{
2021-09-14 00:13:48 +02:00
return cmIsOn(this->GetGlobalProperty(prop));
2015-08-17 11:37:30 +02:00
}
void cmState::SetSourceDirectory(std::string const& sourceDirectory)
{
this->SourceDirectory = sourceDirectory;
cmSystemTools::ConvertToUnixSlashes(this->SourceDirectory);
}
2018-04-23 21:13:27 +02:00
std::string const& cmState::GetSourceDirectory() const
2015-08-17 11:37:30 +02:00
{
2018-04-23 21:13:27 +02:00
return this->SourceDirectory;
2015-08-17 11:37:30 +02:00
}
void cmState::SetBinaryDirectory(std::string const& binaryDirectory)
{
this->BinaryDirectory = binaryDirectory;
cmSystemTools::ConvertToUnixSlashes(this->BinaryDirectory);
}
void cmState::SetWindowsShell(bool windowsShell)
{
this->WindowsShell = windowsShell;
}
bool cmState::UseWindowsShell() const
{
return this->WindowsShell;
}
void cmState::SetWindowsVSIDE(bool windowsVSIDE)
{
this->WindowsVSIDE = windowsVSIDE;
}
bool cmState::UseWindowsVSIDE() const
{
return this->WindowsVSIDE;
}
2019-11-11 23:01:05 +01:00
void cmState::SetGhsMultiIDE(bool ghsMultiIDE)
{
this->GhsMultiIDE = ghsMultiIDE;
}
bool cmState::UseGhsMultiIDE() const
{
return this->GhsMultiIDE;
}
2015-08-17 11:37:30 +02:00
void cmState::SetWatcomWMake(bool watcomWMake)
{
this->WatcomWMake = watcomWMake;
}
bool cmState::UseWatcomWMake() const
{
return this->WatcomWMake;
}
void cmState::SetMinGWMake(bool minGWMake)
{
this->MinGWMake = minGWMake;
}
bool cmState::UseMinGWMake() const
{
return this->MinGWMake;
}
void cmState::SetNMake(bool nMake)
{
this->NMake = nMake;
}
bool cmState::UseNMake() const
{
return this->NMake;
}
void cmState::SetMSYSShell(bool mSYSShell)
{
this->MSYSShell = mSYSShell;
}
bool cmState::UseMSYSShell() const
{
return this->MSYSShell;
}
2020-08-30 11:54:41 +02:00
void cmState::SetNinjaMulti(bool ninjaMulti)
{
this->NinjaMulti = ninjaMulti;
}
bool cmState::UseNinjaMulti() const
{
return this->NinjaMulti;
}
2016-03-13 13:35:51 +01:00
unsigned int cmState::GetCacheMajorVersion() const
{
return this->CacheManager->GetCacheMajorVersion();
}
unsigned int cmState::GetCacheMinorVersion() const
{
return this->CacheManager->GetCacheMinorVersion();
}
2019-11-11 23:01:05 +01:00
cmState::Mode cmState::GetMode() const
{
2021-11-20 13:41:27 +01:00
return this->StateMode;
2019-11-11 23:01:05 +01:00
}
std::string cmState::GetModeString() const
{
2021-11-20 13:41:27 +01:00
return ModeToString(this->StateMode);
2019-11-11 23:01:05 +01:00
}
std::string cmState::ModeToString(cmState::Mode mode)
{
switch (mode) {
case Project:
return "PROJECT";
case Script:
return "SCRIPT";
case FindPackage:
return "FIND_PACKAGE";
case CTest:
return "CTEST";
case CPack:
return "CPACK";
2023-05-23 16:38:00 +02:00
case Help:
return "HELP";
2019-11-11 23:01:05 +01:00
case Unknown:
return "UNKNOWN";
}
return "UNKNOWN";
}
2021-11-20 13:41:27 +01:00
cmState::ProjectKind cmState::GetProjectKind() const
{
return this->StateProjectKind;
}
2018-04-23 21:13:27 +02:00
std::string const& cmState::GetBinaryDirectory() const
2015-08-17 11:37:30 +02:00
{
2018-04-23 21:13:27 +02:00
return this->BinaryDirectory;
2015-08-17 11:37:30 +02:00
}
2017-04-14 19:02:05 +02:00
cmStateSnapshot cmState::CreateBaseSnapshot()
2015-08-17 11:37:30 +02:00
{
2017-04-14 19:02:05 +02:00
cmStateDetail::PositionType pos =
this->SnapshotData.Push(this->SnapshotData.Root());
2015-11-17 17:22:37 +01:00
pos->DirectoryParent = this->SnapshotData.Root();
pos->ScopeParent = this->SnapshotData.Root();
2017-04-14 19:02:05 +02:00
pos->SnapshotType = cmStateEnums::BaseType;
2015-12-03 18:43:53 +01:00
pos->Keep = true;
2015-11-17 17:22:37 +01:00
pos->BuildSystemDirectory =
2016-07-09 11:21:54 +02:00
this->BuildsystemDirectory.Push(this->BuildsystemDirectory.Root());
2015-11-17 17:22:37 +01:00
pos->ExecutionListFile =
2016-07-09 11:21:54 +02:00
this->ExecutionListFiles.Push(this->ExecutionListFiles.Root());
2015-11-17 17:22:37 +01:00
pos->IncludeDirectoryPosition = 0;
pos->CompileDefinitionsPosition = 0;
pos->CompileOptionsPosition = 0;
2018-10-28 12:09:07 +01:00
pos->LinkOptionsPosition = 0;
pos->LinkDirectoriesPosition = 0;
2022-11-16 20:14:03 +01:00
pos->BuildSystemDirectory->CurrentScope = pos;
2015-11-17 17:22:37 +01:00
pos->Policies = this->PolicyStack.Root();
pos->PolicyRoot = this->PolicyStack.Root();
pos->PolicyScope = this->PolicyStack.Root();
assert(pos->Policies.IsValid());
assert(pos->PolicyRoot.IsValid());
2015-12-03 18:43:53 +01:00
pos->Vars = this->VarTree.Push(this->VarTree.Root());
2015-11-17 17:22:37 +01:00
assert(pos->Vars.IsValid());
pos->Parent = this->VarTree.Root();
pos->Root = this->VarTree.Root();
2020-02-01 23:06:01 +01:00
return { this, pos };
2015-11-17 17:22:37 +01:00
}
2017-04-14 19:02:05 +02:00
cmStateSnapshot cmState::CreateBuildsystemDirectorySnapshot(
2017-07-20 19:35:53 +02:00
cmStateSnapshot const& originSnapshot)
2015-11-17 17:22:37 +01:00
{
assert(originSnapshot.IsValid());
2017-04-14 19:02:05 +02:00
cmStateDetail::PositionType pos =
this->SnapshotData.Push(originSnapshot.Position);
2015-11-17 17:22:37 +01:00
pos->DirectoryParent = originSnapshot.Position;
pos->ScopeParent = originSnapshot.Position;
2017-04-14 19:02:05 +02:00
pos->SnapshotType = cmStateEnums::BuildsystemDirectoryType;
2015-12-03 18:43:53 +01:00
pos->Keep = true;
2016-07-09 11:21:54 +02:00
pos->BuildSystemDirectory = this->BuildsystemDirectory.Push(
originSnapshot.Position->BuildSystemDirectory);
2015-11-17 17:22:37 +01:00
pos->ExecutionListFile =
2016-07-09 11:21:54 +02:00
this->ExecutionListFiles.Push(originSnapshot.Position->ExecutionListFile);
2022-11-16 20:14:03 +01:00
pos->BuildSystemDirectory->CurrentScope = pos;
2015-11-17 17:22:37 +01:00
pos->Policies = originSnapshot.Position->Policies;
pos->PolicyRoot = originSnapshot.Position->Policies;
pos->PolicyScope = originSnapshot.Position->Policies;
assert(pos->Policies.IsValid());
assert(pos->PolicyRoot.IsValid());
2016-07-09 11:21:54 +02:00
cmLinkedTree<cmDefinitions>::iterator origin = originSnapshot.Position->Vars;
2015-11-17 17:22:37 +01:00
pos->Parent = origin;
pos->Root = origin;
2015-12-03 18:43:53 +01:00
pos->Vars = this->VarTree.Push(origin);
2016-03-13 13:35:51 +01:00
2017-04-14 19:02:05 +02:00
cmStateSnapshot snapshot = cmStateSnapshot(this, pos);
2015-11-17 17:22:37 +01:00
originSnapshot.Position->BuildSystemDirectory->Children.push_back(snapshot);
2016-03-13 13:35:51 +01:00
snapshot.SetDefaultDefinitions();
snapshot.InitializeFromParent();
snapshot.SetDirectoryDefinitions();
2015-11-17 17:22:37 +01:00
return snapshot;
}
2021-09-14 00:13:48 +02:00
cmStateSnapshot cmState::CreateDeferCallSnapshot(
cmStateSnapshot const& originSnapshot, std::string const& fileName)
{
cmStateDetail::PositionType pos =
this->SnapshotData.Push(originSnapshot.Position, *originSnapshot.Position);
pos->SnapshotType = cmStateEnums::DeferCallType;
pos->Keep = false;
pos->ExecutionListFile = this->ExecutionListFiles.Push(
originSnapshot.Position->ExecutionListFile, fileName);
assert(originSnapshot.Position->Vars.IsValid());
2022-11-16 20:14:03 +01:00
pos->BuildSystemDirectory->CurrentScope = pos;
2021-09-14 00:13:48 +02:00
pos->PolicyScope = originSnapshot.Position->Policies;
return { this, pos };
}
2017-04-14 19:02:05 +02:00
cmStateSnapshot cmState::CreateFunctionCallSnapshot(
2017-07-20 19:35:53 +02:00
cmStateSnapshot const& originSnapshot, std::string const& fileName)
2015-11-17 17:22:37 +01:00
{
2017-04-14 19:02:05 +02:00
cmStateDetail::PositionType pos =
2016-07-09 11:21:54 +02:00
this->SnapshotData.Push(originSnapshot.Position, *originSnapshot.Position);
2015-11-17 17:22:37 +01:00
pos->ScopeParent = originSnapshot.Position;
2017-04-14 19:02:05 +02:00
pos->SnapshotType = cmStateEnums::FunctionCallType;
2015-12-03 18:43:53 +01:00
pos->Keep = false;
pos->ExecutionListFile = this->ExecutionListFiles.Push(
2016-07-09 11:21:54 +02:00
originSnapshot.Position->ExecutionListFile, fileName);
2022-11-16 20:14:03 +01:00
pos->BuildSystemDirectory->CurrentScope = pos;
2015-11-17 17:22:37 +01:00
pos->PolicyScope = originSnapshot.Position->Policies;
assert(originSnapshot.Position->Vars.IsValid());
2016-07-09 11:21:54 +02:00
cmLinkedTree<cmDefinitions>::iterator origin = originSnapshot.Position->Vars;
2015-11-17 17:22:37 +01:00
pos->Parent = origin;
2015-12-03 18:43:53 +01:00
pos->Vars = this->VarTree.Push(origin);
2020-02-01 23:06:01 +01:00
return { this, pos };
2015-11-17 17:22:37 +01:00
}
2017-04-14 19:02:05 +02:00
cmStateSnapshot cmState::CreateMacroCallSnapshot(
2017-07-20 19:35:53 +02:00
cmStateSnapshot const& originSnapshot, std::string const& fileName)
2015-08-17 11:37:30 +02:00
{
2017-04-14 19:02:05 +02:00
cmStateDetail::PositionType pos =
2016-07-09 11:21:54 +02:00
this->SnapshotData.Push(originSnapshot.Position, *originSnapshot.Position);
2017-04-14 19:02:05 +02:00
pos->SnapshotType = cmStateEnums::MacroCallType;
2015-12-03 18:43:53 +01:00
pos->Keep = false;
pos->ExecutionListFile = this->ExecutionListFiles.Push(
2016-07-09 11:21:54 +02:00
originSnapshot.Position->ExecutionListFile, fileName);
2015-11-17 17:22:37 +01:00
assert(originSnapshot.Position->Vars.IsValid());
2022-11-16 20:14:03 +01:00
pos->BuildSystemDirectory->CurrentScope = pos;
2015-11-17 17:22:37 +01:00
pos->PolicyScope = originSnapshot.Position->Policies;
2020-02-01 23:06:01 +01:00
return { this, pos };
2015-11-17 17:22:37 +01:00
}
2017-04-14 19:02:05 +02:00
cmStateSnapshot cmState::CreateIncludeFileSnapshot(
2017-07-20 19:35:53 +02:00
cmStateSnapshot const& originSnapshot, std::string const& fileName)
2015-11-17 17:22:37 +01:00
{
2017-04-14 19:02:05 +02:00
cmStateDetail::PositionType pos =
2016-07-09 11:21:54 +02:00
this->SnapshotData.Push(originSnapshot.Position, *originSnapshot.Position);
2017-04-14 19:02:05 +02:00
pos->SnapshotType = cmStateEnums::IncludeFileType;
2015-12-03 18:43:53 +01:00
pos->Keep = true;
pos->ExecutionListFile = this->ExecutionListFiles.Push(
2016-07-09 11:21:54 +02:00
originSnapshot.Position->ExecutionListFile, fileName);
2015-11-17 17:22:37 +01:00
assert(originSnapshot.Position->Vars.IsValid());
2022-11-16 20:14:03 +01:00
pos->BuildSystemDirectory->CurrentScope = pos;
2015-11-17 17:22:37 +01:00
pos->PolicyScope = originSnapshot.Position->Policies;
2020-02-01 23:06:01 +01:00
return { this, pos };
2015-11-17 17:22:37 +01:00
}
2017-04-14 19:02:05 +02:00
cmStateSnapshot cmState::CreateVariableScopeSnapshot(
2017-07-20 19:35:53 +02:00
cmStateSnapshot const& originSnapshot)
2015-11-17 17:22:37 +01:00
{
2017-04-14 19:02:05 +02:00
cmStateDetail::PositionType pos =
2016-07-09 11:21:54 +02:00
this->SnapshotData.Push(originSnapshot.Position, *originSnapshot.Position);
2015-11-17 17:22:37 +01:00
pos->ScopeParent = originSnapshot.Position;
2017-04-14 19:02:05 +02:00
pos->SnapshotType = cmStateEnums::VariableScopeType;
2015-12-03 18:43:53 +01:00
pos->Keep = false;
2022-11-16 20:14:03 +01:00
pos->BuildSystemDirectory->CurrentScope = pos;
2015-12-03 18:43:53 +01:00
pos->PolicyScope = originSnapshot.Position->Policies;
2015-11-17 17:22:37 +01:00
assert(originSnapshot.Position->Vars.IsValid());
2016-07-09 11:21:54 +02:00
cmLinkedTree<cmDefinitions>::iterator origin = originSnapshot.Position->Vars;
2015-11-17 17:22:37 +01:00
pos->Parent = origin;
2015-12-03 18:43:53 +01:00
pos->Vars = this->VarTree.Push(origin);
2015-11-17 17:22:37 +01:00
assert(pos->Vars.IsValid());
2020-02-01 23:06:01 +01:00
return { this, pos };
2015-11-17 17:22:37 +01:00
}
2017-04-14 19:02:05 +02:00
cmStateSnapshot cmState::CreateInlineListFileSnapshot(
2017-07-20 19:35:53 +02:00
cmStateSnapshot const& originSnapshot, std::string const& fileName)
2015-11-17 17:22:37 +01:00
{
2017-04-14 19:02:05 +02:00
cmStateDetail::PositionType pos =
2016-07-09 11:21:54 +02:00
this->SnapshotData.Push(originSnapshot.Position, *originSnapshot.Position);
2017-04-14 19:02:05 +02:00
pos->SnapshotType = cmStateEnums::InlineListFileType;
2015-12-03 18:43:53 +01:00
pos->Keep = true;
pos->ExecutionListFile = this->ExecutionListFiles.Push(
2016-07-09 11:21:54 +02:00
originSnapshot.Position->ExecutionListFile, fileName);
2022-11-16 20:14:03 +01:00
pos->BuildSystemDirectory->CurrentScope = pos;
2015-11-17 17:22:37 +01:00
pos->PolicyScope = originSnapshot.Position->Policies;
2020-02-01 23:06:01 +01:00
return { this, pos };
2015-11-17 17:22:37 +01:00
}
2017-04-14 19:02:05 +02:00
cmStateSnapshot cmState::CreatePolicyScopeSnapshot(
2017-07-20 19:35:53 +02:00
cmStateSnapshot const& originSnapshot)
2015-11-17 17:22:37 +01:00
{
2017-04-14 19:02:05 +02:00
cmStateDetail::PositionType pos =
2016-07-09 11:21:54 +02:00
this->SnapshotData.Push(originSnapshot.Position, *originSnapshot.Position);
2017-04-14 19:02:05 +02:00
pos->SnapshotType = cmStateEnums::PolicyScopeType;
2015-12-03 18:43:53 +01:00
pos->Keep = false;
2022-11-16 20:14:03 +01:00
pos->BuildSystemDirectory->CurrentScope = pos;
2015-11-17 17:22:37 +01:00
pos->PolicyScope = originSnapshot.Position->Policies;
2020-02-01 23:06:01 +01:00
return { this, pos };
2015-08-17 11:37:30 +02:00
}
2017-07-20 19:35:53 +02:00
cmStateSnapshot cmState::Pop(cmStateSnapshot const& originSnapshot)
2015-11-17 17:22:37 +01:00
{
2017-04-14 19:02:05 +02:00
cmStateDetail::PositionType pos = originSnapshot.Position;
cmStateDetail::PositionType prevPos = pos;
2015-11-17 17:22:37 +01:00
++prevPos;
prevPos->IncludeDirectoryPosition =
2016-07-09 11:21:54 +02:00
prevPos->BuildSystemDirectory->IncludeDirectories.size();
2015-11-17 17:22:37 +01:00
prevPos->CompileDefinitionsPosition =
2016-07-09 11:21:54 +02:00
prevPos->BuildSystemDirectory->CompileDefinitions.size();
2015-11-17 17:22:37 +01:00
prevPos->CompileOptionsPosition =
2016-07-09 11:21:54 +02:00
prevPos->BuildSystemDirectory->CompileOptions.size();
2018-10-28 12:09:07 +01:00
prevPos->LinkOptionsPosition =
prevPos->BuildSystemDirectory->LinkOptions.size();
prevPos->LinkDirectoriesPosition =
prevPos->BuildSystemDirectory->LinkDirectories.size();
2022-11-16 20:14:03 +01:00
prevPos->BuildSystemDirectory->CurrentScope = prevPos;
2015-11-17 17:22:37 +01:00
2016-07-09 11:21:54 +02:00
if (!pos->Keep && this->SnapshotData.IsLast(pos)) {
if (pos->Vars != prevPos->Vars) {
2015-12-03 18:43:53 +01:00
assert(this->VarTree.IsLast(pos->Vars));
this->VarTree.Pop(pos->Vars);
2016-07-09 11:21:54 +02:00
}
if (pos->ExecutionListFile != prevPos->ExecutionListFile) {
2015-12-03 18:43:53 +01:00
assert(this->ExecutionListFiles.IsLast(pos->ExecutionListFile));
this->ExecutionListFiles.Pop(pos->ExecutionListFile);
}
2016-07-09 11:21:54 +02:00
this->SnapshotData.Pop(pos);
}
2015-12-03 18:43:53 +01:00
2020-02-01 23:06:01 +01:00
return { this, prevPos };
2015-11-17 17:22:37 +01:00
}
2016-03-13 13:35:51 +01:00
2016-07-09 11:21:54 +02:00
static bool ParseEntryWithoutType(const std::string& entry, std::string& var,
2016-03-13 13:35:51 +01:00
std::string& value)
{
// input line is: key=value
static cmsys::RegularExpression reg(
"^([^=]*)=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
// input line is: "key"=value
static cmsys::RegularExpression regQuoted(
"^\"([^\"]*)\"=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
bool flag = false;
2016-07-09 11:21:54 +02:00
if (regQuoted.find(entry)) {
2016-03-13 13:35:51 +01:00
var = regQuoted.match(1);
value = regQuoted.match(2);
flag = true;
2016-07-09 11:21:54 +02:00
} else if (reg.find(entry)) {
2016-03-13 13:35:51 +01:00
var = reg.match(1);
value = reg.match(2);
flag = true;
2016-07-09 11:21:54 +02:00
}
2016-03-13 13:35:51 +01:00
// if value is enclosed in single quotes ('foo') then remove them
// it is used to enclose trailing space or tab
2019-11-11 23:01:05 +01:00
if (flag && value.size() >= 2 && value.front() == '\'' &&
value.back() == '\'') {
2016-07-09 11:21:54 +02:00
value = value.substr(1, value.size() - 2);
}
2016-03-13 13:35:51 +01:00
return flag;
}
2016-07-09 11:21:54 +02:00
bool cmState::ParseCacheEntry(const std::string& entry, std::string& var,
2017-04-14 19:02:05 +02:00
std::string& value,
cmStateEnums::CacheEntryType& type)
2016-03-13 13:35:51 +01:00
{
// input line is: key:type=value
static cmsys::RegularExpression reg(
"^([^=:]*):([^=]*)=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
// input line is: "key":type=value
static cmsys::RegularExpression regQuoted(
"^\"([^\"]*)\":([^=]*)=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
bool flag = false;
2016-07-09 11:21:54 +02:00
if (regQuoted.find(entry)) {
2016-03-13 13:35:51 +01:00
var = regQuoted.match(1);
2020-08-30 11:54:41 +02:00
type = cmState::StringToCacheEntryType(regQuoted.match(2));
2016-03-13 13:35:51 +01:00
value = regQuoted.match(3);
flag = true;
2016-07-09 11:21:54 +02:00
} else if (reg.find(entry)) {
2016-03-13 13:35:51 +01:00
var = reg.match(1);
2020-08-30 11:54:41 +02:00
type = cmState::StringToCacheEntryType(reg.match(2));
2016-03-13 13:35:51 +01:00
value = reg.match(3);
flag = true;
2016-07-09 11:21:54 +02:00
}
2016-03-13 13:35:51 +01:00
// if value is enclosed in single quotes ('foo') then remove them
// it is used to enclose trailing space or tab
2019-11-11 23:01:05 +01:00
if (flag && value.size() >= 2 && value.front() == '\'' &&
value.back() == '\'') {
2016-07-09 11:21:54 +02:00
value = value.substr(1, value.size() - 2);
}
2016-03-13 13:35:51 +01:00
2016-07-09 11:21:54 +02:00
if (!flag) {
2016-03-13 13:35:51 +01:00
return ParseEntryWithoutType(entry, var, value);
2016-07-09 11:21:54 +02:00
}
2016-03-13 13:35:51 +01:00
return flag;
}
2022-08-04 22:12:04 +02:00
cmState::Command cmState::GetDependencyProviderCommand(
cmDependencyProvider::Method method) const
{
return (this->DependencyProvider &&
this->DependencyProvider->SupportsMethod(method))
? this->GetCommand(this->DependencyProvider->GetCommand())
: Command{};
}