mirror of
https://github.com/Kitware/CMake.git
synced 2026-08-10 01:28:02 +00:00
The full path of a file in a file set can be broken into groups like `<base>/[<sub>/]<name>`, where `<base>` is the base directory and `<name>` is the file name without any directory components. Existing users evaluate file set files as a mapping from `<rel>` to the full path. However, CPS export needs files grouped by base directory, and cares about the composition of `<rel>` and `<name>`. To facilitate obtaining this information in a more useful form, refactor how we extract file set files to allow the user to pass a lambda 'handler' for each file, which has the base directory, full path, and path relative to the base directory available. (We already obtained `<rel>` from the latter, so while this technically means the existing use needs to do additional work, in practice it just means the call to get `<rel>` moves to the lambda.) Because there are many existing users that would need to duplicate the lambda, the old methods are retained as-is, although this does result in minor code duplication between `GetFiles` (which calls the overload of `EvaluateFileEntry` which fills the old file map) and `EvaluateFiles` (which is essentially `GetFiles`, but accepts a user-provided 'handler' lambda rather than directly producing a file map).
157 lines
5.7 KiB
C++
157 lines
5.7 KiB
C++
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
file LICENSE.rst or https://cmake.org/licensing for details. */
|
|
#pragma once
|
|
|
|
#include "cmConfigure.h" // IWYU pragma: keep
|
|
|
|
#include <functional>
|
|
#include <map>
|
|
#include <memory>
|
|
#include <string>
|
|
#include <utility>
|
|
#include <vector>
|
|
|
|
#include "cmFileSetMetadata.h"
|
|
#include "cmGeneratorExpression.h"
|
|
#include "cmListFileCache.h"
|
|
#include "cmTargetPropertyEntry.h"
|
|
#include "cmValue.h"
|
|
|
|
namespace cm {
|
|
namespace GenEx {
|
|
struct Context;
|
|
}
|
|
}
|
|
|
|
struct cmGeneratorExpressionDAGChecker;
|
|
|
|
class cmFileSet;
|
|
class cmGeneratorTarget;
|
|
|
|
class cmGeneratorFileSet
|
|
{
|
|
public:
|
|
using TargetPropertyEntry = cm::TargetPropertyEntry;
|
|
|
|
cmGeneratorFileSet(cmGeneratorTarget const*, cmFileSet const*);
|
|
~cmGeneratorFileSet() = default;
|
|
|
|
cmGeneratorFileSet(cmGeneratorFileSet&&) = default;
|
|
cmGeneratorFileSet(cmGeneratorFileSet const&) = delete;
|
|
cmGeneratorFileSet& operator=(cmGeneratorFileSet const&) = delete;
|
|
|
|
std::string const& GetName() const;
|
|
std::string const& GetType() const;
|
|
cm::FileSetMetadata::Visibility GetVisibility() const;
|
|
|
|
bool IsForSelf() const;
|
|
bool IsForInterface() const;
|
|
bool CanBeIncluded() const;
|
|
|
|
cmGeneratorTarget const* GetTarget() const { return this->Target; }
|
|
bool BelongsTo(cmGeneratorTarget const* target) const
|
|
{
|
|
return this->Target == target;
|
|
}
|
|
|
|
cmFileSet const* GetFileSet() const { return this->FileSet; }
|
|
|
|
cmValue GetProperty(std::string const& prop) const;
|
|
|
|
std::vector<BT<std::string>> GetIncludeDirectories(
|
|
std::string const& config, std::string const& lang) const;
|
|
std::vector<BT<std::string>> GetInterfaceIncludeDirectories(
|
|
std::string const& config, std::string const& lang) const;
|
|
|
|
std::vector<BT<std::string>> GetCompileOptions(
|
|
std::string const& config, std::string const& language) const;
|
|
std::vector<BT<std::string>> GetInterfaceCompileOptions(
|
|
std::string const& config, std::string const& language) const;
|
|
|
|
std::vector<BT<std::string>> GetCompileDefinitions(
|
|
std::string const& config, std::string const& language) const;
|
|
std::vector<BT<std::string>> GetInterfaceCompileDefinitions(
|
|
std::string const& config, std::string const& language) const;
|
|
|
|
std::vector<BT<std::string>> const& GetDirectoryEntries() const;
|
|
std::vector<BT<std::string>> const& GetFileEntries() const;
|
|
|
|
std::vector<std::unique_ptr<TargetPropertyEntry>> GetSources(
|
|
cm::GenEx::Context const& context, cmGeneratorTarget const* target,
|
|
cmGeneratorExpressionDAGChecker* dagChecker = nullptr) const;
|
|
|
|
using FileMap = std::map<std::string, std::vector<std::string>>;
|
|
|
|
// returned value:
|
|
// first: list of directories
|
|
// second: is context sensitive
|
|
std::pair<std::vector<std::string>, bool> GetDirectories(
|
|
cm::GenEx::Context const& context, cmGeneratorTarget const* target,
|
|
cmGeneratorExpressionDAGChecker* dagChecker = nullptr) const;
|
|
// returned value:
|
|
// first: list of files per directory
|
|
// second: is context sensitive
|
|
std::pair<FileMap, bool> GetFiles(
|
|
cm::GenEx::Context const& context, cmGeneratorTarget const* target,
|
|
cmGeneratorExpressionDAGChecker* dagChecker = nullptr) const;
|
|
|
|
std::vector<std::unique_ptr<cmCompiledGeneratorExpression>> const&
|
|
CompileFileEntries() const;
|
|
|
|
std::vector<std::unique_ptr<cmCompiledGeneratorExpression>> const&
|
|
CompileDirectoryEntries() const;
|
|
|
|
std::vector<std::string> EvaluateDirectoryEntries(
|
|
std::vector<std::unique_ptr<cmCompiledGeneratorExpression>> const& cges,
|
|
cm::GenEx::Context const& context, cmGeneratorTarget const* target,
|
|
cmGeneratorExpressionDAGChecker* dagChecker = nullptr) const;
|
|
|
|
using EvaluateFileEntryFunction =
|
|
std::function<void(std::string&&, std::string&&, std::string&&)>;
|
|
|
|
// returned value: is context sensitive
|
|
bool EvaluateFiles(
|
|
cm::GenEx::Context const& context, cmGeneratorTarget const* target,
|
|
EvaluateFileEntryFunction callback,
|
|
cmGeneratorExpressionDAGChecker* dagChecker = nullptr) const;
|
|
|
|
void EvaluateFileEntry(
|
|
std::vector<std::string> const& dirs, EvaluateFileEntryFunction handler,
|
|
std::unique_ptr<cmCompiledGeneratorExpression> const& cge,
|
|
cm::GenEx::Context const& context, cmGeneratorTarget const* target,
|
|
cmGeneratorExpressionDAGChecker* dagChecker = nullptr) const;
|
|
|
|
void EvaluateFileEntry(
|
|
std::vector<std::string> const& dirs, FileMap& filesPerDir,
|
|
std::unique_ptr<cmCompiledGeneratorExpression> const& cge,
|
|
cm::GenEx::Context const& context, cmGeneratorTarget const* target,
|
|
cmGeneratorExpressionDAGChecker* dagChecker = nullptr) const;
|
|
|
|
private:
|
|
cmGeneratorTarget const* Target;
|
|
cmFileSet const* FileSet;
|
|
mutable std::vector<std::unique_ptr<cmCompiledGeneratorExpression>>
|
|
CompiledDirectoryEntries;
|
|
mutable std::vector<std::unique_ptr<cmCompiledGeneratorExpression>>
|
|
CompiledFileEntries;
|
|
|
|
using TargetPropertyEntries =
|
|
std::vector<std::unique_ptr<TargetPropertyEntry>>;
|
|
TargetPropertyEntries IncludeDirectories;
|
|
TargetPropertyEntries InterfaceIncludeDirectories;
|
|
TargetPropertyEntries CompileOptions;
|
|
TargetPropertyEntries InterfaceCompileOptions;
|
|
TargetPropertyEntries CompileDefinitions;
|
|
TargetPropertyEntries InterfaceCompileDefinitions;
|
|
|
|
using ConfigAndLanguage = std::pair<std::string, std::string>;
|
|
using ConfigAndLanguageToBTStrings =
|
|
std::map<ConfigAndLanguage, std::vector<BT<std::string>>>;
|
|
mutable ConfigAndLanguageToBTStrings IncludeDirectoriesCache;
|
|
mutable ConfigAndLanguageToBTStrings InterfaceIncludeDirectoriesCache;
|
|
mutable ConfigAndLanguageToBTStrings CompileOptionsCache;
|
|
mutable ConfigAndLanguageToBTStrings InterfaceCompileOptionsCache;
|
|
mutable ConfigAndLanguageToBTStrings CompileDefinitionsCache;
|
|
mutable ConfigAndLanguageToBTStrings InterfaceCompileDefinitionsCache;
|
|
};
|