cmake/Source/cmGlobalCommonGenerator.cxx

81 lines
2.8 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"
2020-08-30 11:54:41 +02:00
#include <memory>
2020-02-01 23:06:01 +01:00
#include <utility>
#include "cmGeneratorTarget.h"
#include "cmLocalGenerator.h"
2020-08-30 11:54:41 +02:00
#include "cmProperty.h"
2020-02-01 23:06:01 +01:00
#include "cmStateDirectory.h"
#include "cmStateSnapshot.h"
#include "cmStateTypes.h"
#include "cmStringAlgorithms.h"
2016-10-30 18:24:19 +01:00
class cmake;
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) {
2020-02-01 23:06:01 +01:00
std::string const& currentBinaryDir(
lg->GetStateSnapshot().GetDirectory().GetCurrentBinary());
DirectoryTarget& dirTarget = dirTargets[currentBinaryDir];
2020-08-30 11:54:41 +02:00
dirTarget.LG = lg.get();
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();
if (type != cmStateEnums::EXECUTABLE &&
type != cmStateEnums::STATIC_LIBRARY &&
type != cmStateEnums::SHARED_LIBRARY &&
type != cmStateEnums::MODULE_LIBRARY &&
type != cmStateEnums::OBJECT_LIBRARY &&
type != cmStateEnums::UTILITY) {
continue;
}
DirectoryTarget::Target t;
2020-08-30 11:54:41 +02:00
t.GT = gt.get();
if (cmProp exclude = gt->GetProperty("EXCLUDE_FROM_ALL")) {
if (cmIsOn(*exclude)) {
2020-02-01 23:06:01 +01:00
// This target has been explicitly excluded.
t.ExcludeFromAll = true;
} else {
// 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()) {
std::string const& d = dir.GetDirectory().GetCurrentBinary();
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;
}