mirror of
https://github.com/Kitware/CMake.git
synced 2025-05-09 06:42:18 +08:00

#pragma once is a widely supported compiler pragma, even though it is not part of the C++ standard. Many of the issues keeping #pragma once from being standardized (distributed filesystems, build farms, hard links, etc.) do not apply to CMake - it is easy to build CMake on a single machine. CMake also does not install any header files which can be consumed by other projects (though cmCPluginAPI.h has been deliberately omitted from this conversion in case anyone is still using it.) Finally, #pragma once has been required to build CMake since at least August 2017 (7f29bbe6 enabled server mode unconditionally, which had been using #pragma once since September 2016 (b13d3e0d)). The fact that we now require C++11 filters out old compilers, and it is unlikely that there is a compiler which supports C++11 but does not support #pragma once.
138 lines
4.2 KiB
C++
138 lines
4.2 KiB
C++
/* 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
|
|
|
|
#include <map>
|
|
#include <memory>
|
|
#include <set>
|
|
#include <string>
|
|
#include <utility>
|
|
#include <vector>
|
|
|
|
#include "cmsys/RegularExpression.hxx"
|
|
|
|
#include "cmGeneratedFileStream.h"
|
|
#include "cmLinkItem.h"
|
|
#include "cmLinkItemGraphVisitor.h"
|
|
#include "cmStateTypes.h"
|
|
|
|
class cmGlobalGenerator;
|
|
|
|
/** This class implements writing files for graphviz (dot) for graphs
|
|
* representing the dependencies between the targets in the project. */
|
|
class cmGraphVizWriter : public cmLinkItemGraphVisitor
|
|
{
|
|
public:
|
|
cmGraphVizWriter(std::string const& fileName,
|
|
const cmGlobalGenerator* globalGenerator);
|
|
~cmGraphVizWriter() override;
|
|
|
|
void VisitGraph(std::string const& name) override;
|
|
|
|
void OnItem(cmLinkItem const& item) override;
|
|
|
|
void OnDirectLink(cmLinkItem const& depender, cmLinkItem const& dependee,
|
|
DependencyType dt) override;
|
|
|
|
void OnIndirectLink(cmLinkItem const& depender,
|
|
cmLinkItem const& dependee) override;
|
|
|
|
void ReadSettings(const std::string& settingsFileName,
|
|
const std::string& fallbackSettingsFileName);
|
|
|
|
void Write();
|
|
|
|
private:
|
|
struct Connection
|
|
{
|
|
Connection(cmLinkItem s, cmLinkItem d, std::string scope)
|
|
: src(std::move(s))
|
|
, dst(std::move(d))
|
|
, scopeType(std::move(scope))
|
|
{
|
|
}
|
|
|
|
cmLinkItem src;
|
|
cmLinkItem dst;
|
|
std::string scopeType;
|
|
};
|
|
using Connections = std::vector<Connection>;
|
|
using ConnectionsMap = std::map<cmLinkItem, Connections>;
|
|
|
|
void VisitLink(cmLinkItem const& depender, cmLinkItem const& dependee,
|
|
bool isDirectLink, std::string const& scopeType = "");
|
|
|
|
void WriteHeader(cmGeneratedFileStream& fs, std::string const& name);
|
|
|
|
void WriteFooter(cmGeneratedFileStream& fs);
|
|
|
|
void WriteLegend(cmGeneratedFileStream& fs);
|
|
|
|
void WriteNode(cmGeneratedFileStream& fs, cmLinkItem const& item);
|
|
|
|
std::unique_ptr<cmGeneratedFileStream> CreateTargetFile(
|
|
cmLinkItem const& target, std::string const& fileNameSuffix = "");
|
|
|
|
void WriteConnection(cmGeneratedFileStream& fs,
|
|
cmLinkItem const& dependerTargetName,
|
|
cmLinkItem const& dependeeTargetName,
|
|
std::string const& edgeStyle);
|
|
|
|
void FindAllConnections(const ConnectionsMap& connectionMap,
|
|
const cmLinkItem& rootItem,
|
|
Connections& extendedCons,
|
|
std::set<cmLinkItem>& visitedItems);
|
|
|
|
void FindAllConnections(const ConnectionsMap& connectionMap,
|
|
const cmLinkItem& rootItem,
|
|
Connections& extendedCons);
|
|
|
|
template <typename DirFunc>
|
|
void WritePerTargetConnections(const ConnectionsMap& connections,
|
|
const std::string& fileNameSuffix = "");
|
|
|
|
bool ItemExcluded(cmLinkItem const& item);
|
|
bool ItemNameFilteredOut(std::string const& itemName);
|
|
bool TargetTypeEnabled(cmStateEnums::TargetType targetType) const;
|
|
|
|
std::string ItemNameWithAliases(std::string const& itemName) const;
|
|
|
|
static std::string GetEdgeStyle(DependencyType dt);
|
|
|
|
static std::string EscapeForDotFile(std::string const& str);
|
|
|
|
static std::string PathSafeString(std::string const& str);
|
|
|
|
std::string FileName;
|
|
cmGeneratedFileStream GlobalFileStream;
|
|
|
|
ConnectionsMap PerTargetConnections;
|
|
ConnectionsMap TargetDependersConnections;
|
|
|
|
std::string GraphName;
|
|
std::string GraphHeader;
|
|
std::string GraphNodePrefix;
|
|
|
|
std::vector<cmsys::RegularExpression> TargetsToIgnoreRegex;
|
|
|
|
cmGlobalGenerator const* GlobalGenerator;
|
|
|
|
int NextNodeId;
|
|
// maps from the actual item names to node names in dot:
|
|
std::map<std::string, std::string> NodeNames;
|
|
|
|
bool GenerateForExecutables;
|
|
bool GenerateForStaticLibs;
|
|
bool GenerateForSharedLibs;
|
|
bool GenerateForModuleLibs;
|
|
bool GenerateForInterfaceLibs;
|
|
bool GenerateForObjectLibs;
|
|
bool GenerateForUnknownLibs;
|
|
bool GenerateForCustomTargets;
|
|
bool GenerateForExternals;
|
|
bool GeneratePerTarget;
|
|
bool GenerateDependers;
|
|
};
|