cmake/Source/cmGlobalCommonGenerator.cxx

151 lines
5.4 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-11-17 17:22:37 +01:00
#include "cmGlobalCommonGenerator.h"
2023-05-23 16:38:00 +02:00
#include <algorithm>
2020-08-30 11:54:41 +02:00
#include <memory>
2020-02-01 23:06:01 +01:00
#include <utility>
2021-09-14 00:13:48 +02:00
#include <cmext/algorithm>
2023-05-23 16:38:00 +02:00
#include <cmsys/Glob.hxx>
2021-09-14 00:13:48 +02:00
#include "cmGeneratorExpression.h"
2020-02-01 23:06:01 +01:00
#include "cmGeneratorTarget.h"
2024-07-09 14:46:46 +02:00
#include "cmLocalCommonGenerator.h"
2020-02-01 23:06:01 +01:00
#include "cmLocalGenerator.h"
#include "cmStateDirectory.h"
#include "cmStateSnapshot.h"
#include "cmStateTypes.h"
2023-05-23 16:38:00 +02:00
#include "cmStringAlgorithms.h"
2021-11-20 13:41:27 +01:00
#include "cmSystemTools.h"
#include "cmValue.h"
#include "cmake.h"
2016-10-30 18:24:19 +01:00
2016-07-09 11:21:54 +02:00
cmGlobalCommonGenerator::cmGlobalCommonGenerator(cmake* cm)
: cmGlobalGenerator(cm)
2015-11-17 17:22:37 +01:00
{
}
2019-11-11 23:01:05 +01:00
cmGlobalCommonGenerator::~cmGlobalCommonGenerator() = default;
2020-02-01 23:06:01 +01:00
std::map<std::string, cmGlobalCommonGenerator::DirectoryTarget>
cmGlobalCommonGenerator::ComputeDirectoryTargets() const
{
std::map<std::string, DirectoryTarget> dirTargets;
2020-08-30 11:54:41 +02:00
for (const auto& lg : this->LocalGenerators) {
2023-07-02 19:51:09 +02:00
std::string currentBinaryDir =
lg->GetStateSnapshot().GetDirectory().GetCurrentBinary();
2020-02-01 23:06:01 +01:00
DirectoryTarget& dirTarget = dirTargets[currentBinaryDir];
2020-08-30 11:54:41 +02:00
dirTarget.LG = lg.get();
2024-07-09 14:46:46 +02:00
std::vector<std::string> const& configs =
static_cast<cmLocalCommonGenerator const*>(lg.get())->GetConfigNames();
2020-02-01 23:06:01 +01:00
// The directory-level rule should depend on the target-level rules
// for all targets in the directory.
2020-08-30 11:54:41 +02:00
for (const auto& gt : lg->GetGeneratorTargets()) {
2020-02-01 23:06:01 +01:00
cmStateEnums::TargetType const type = gt->GetType();
2021-09-14 00:13:48 +02:00
if (type == cmStateEnums::GLOBAL_TARGET || !gt->IsInBuildSystem()) {
2020-02-01 23:06:01 +01:00
continue;
}
DirectoryTarget::Target t;
2020-08-30 11:54:41 +02:00
t.GT = gt.get();
2021-09-14 00:13:48 +02:00
const std::string EXCLUDE_FROM_ALL("EXCLUDE_FROM_ALL");
2021-11-20 13:41:27 +01:00
if (cmValue exclude = gt->GetProperty(EXCLUDE_FROM_ALL)) {
2021-09-14 00:13:48 +02:00
for (const std::string& config : configs) {
cmGeneratorExpressionInterpreter genexInterpreter(lg.get(), config,
gt.get());
if (cmIsOn(genexInterpreter.Evaluate(*exclude, EXCLUDE_FROM_ALL))) {
// This target has been explicitly excluded.
t.ExcludedFromAllInConfigs.push_back(config);
}
}
if (t.ExcludedFromAllInConfigs.empty()) {
2020-02-01 23:06:01 +01:00
// This target has been explicitly un-excluded. The directory-level
// rule for every directory between this and the root should depend
// on the target-level rule for this target.
for (cmStateSnapshot dir =
lg->GetStateSnapshot().GetBuildsystemDirectoryParent();
dir.IsValid(); dir = dir.GetBuildsystemDirectoryParent()) {
2023-07-02 19:51:09 +02:00
std::string d = dir.GetDirectory().GetCurrentBinary();
2020-02-01 23:06:01 +01:00
dirTargets[d].Targets.emplace_back(t);
}
}
}
dirTarget.Targets.emplace_back(t);
}
// The directory-level rule should depend on the directory-level
// rules of the subdirectories.
for (cmStateSnapshot const& state : lg->GetStateSnapshot().GetChildren()) {
DirectoryTarget::Dir d;
d.Path = state.GetDirectory().GetCurrentBinary();
d.ExcludeFromAll =
state.GetDirectory().GetPropertyAsBool("EXCLUDE_FROM_ALL");
dirTarget.Children.emplace_back(std::move(d));
}
}
return dirTargets;
}
2021-09-14 00:13:48 +02:00
bool cmGlobalCommonGenerator::IsExcludedFromAllInConfig(
const DirectoryTarget::Target& t, const std::string& config)
{
if (this->IsMultiConfig()) {
return cm::contains(t.ExcludedFromAllInConfigs, config);
}
return !t.ExcludedFromAllInConfigs.empty();
}
2021-11-20 13:41:27 +01:00
std::string cmGlobalCommonGenerator::GetEditCacheCommand() const
{
// If generating for an extra IDE, the edit_cache target cannot
// launch a terminal-interactive tool, so always use cmake-gui.
if (!this->GetExtraGeneratorName().empty()) {
return cmSystemTools::GetCMakeGUICommand();
}
// Use an internal cache entry to track the latest dialog used
// to edit the cache, and use that for the edit_cache target.
cmake* cm = this->GetCMakeInstance();
std::string editCacheCommand = cm->GetCMakeEditCommand();
if (!cm->GetCacheDefinition("CMAKE_EDIT_COMMAND") ||
!editCacheCommand.empty()) {
if (this->SupportsDirectConsole() && editCacheCommand.empty()) {
editCacheCommand = cmSystemTools::GetCMakeCursesCommand();
}
if (editCacheCommand.empty()) {
editCacheCommand = cmSystemTools::GetCMakeGUICommand();
}
if (!editCacheCommand.empty()) {
cm->AddCacheEntry("CMAKE_EDIT_COMMAND", editCacheCommand,
"Path to cache edit program executable.",
cmStateEnums::INTERNAL);
}
}
cmValue edit_cmd = cm->GetCacheDefinition("CMAKE_EDIT_COMMAND");
return edit_cmd ? *edit_cmd : std::string();
}
2023-05-23 16:38:00 +02:00
void cmGlobalCommonGenerator::RemoveUnknownClangTidyExportFixesFiles() const
{
for (auto const& dir : this->ClangTidyExportFixesDirs) {
cmsys::Glob g;
g.SetRecurse(true);
g.SetListDirs(false);
g.FindFiles(cmStrCat(dir, "/*.yaml"));
for (auto const& file : g.GetFiles()) {
if (!this->ClangTidyExportFixesFiles.count(file) &&
!std::any_of(this->ClangTidyExportFixesFiles.begin(),
this->ClangTidyExportFixesFiles.end(),
[&file](const std::string& knownFile) -> bool {
return cmSystemTools::SameFile(file, knownFile);
})) {
cmSystemTools::RemoveFile(file);
}
}
}
}