cmake/Source/cmTarget.h

327 lines
11 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. */
2021-09-14 00:13:48 +02:00
#pragma once
2017-07-20 19:35:53 +02:00
#include "cmConfigure.h" // IWYU pragma: keep
2016-07-09 11:21:54 +02:00
2016-10-30 18:24:19 +01:00
#include <iosfwd>
2022-08-04 22:12:04 +02:00
#include <map>
2020-02-01 23:06:01 +01:00
#include <memory>
2016-10-30 18:24:19 +01:00
#include <set>
#include <string>
#include <utility>
#include <vector>
2022-08-04 22:12:04 +02:00
#include <cm/optional>
2017-04-14 19:02:05 +02:00
#include "cmAlgorithms.h"
2022-04-13 00:32:21 +02:00
#include "cmFileSet.h"
2017-04-14 19:02:05 +02:00
#include "cmPolicies.h"
#include "cmStateTypes.h"
2020-02-01 23:06:01 +01:00
#include "cmStringAlgorithms.h"
2017-04-14 19:02:05 +02:00
#include "cmTargetLinkLibraryType.h"
2021-11-20 13:41:27 +01:00
#include "cmValue.h"
2009-10-04 10:30:41 +03:00
2019-11-11 23:01:05 +01:00
class cmCustomCommand;
2017-04-14 19:02:05 +02:00
class cmGlobalGenerator;
2019-11-11 23:01:05 +01:00
class cmInstallTargetGenerator;
2022-03-29 21:10:50 +02:00
class cmListFileBacktrace;
class cmListFileContext;
class cmMakefile;
2019-11-11 23:01:05 +01:00
class cmPropertyMap;
class cmSourceFile;
2022-03-29 21:10:50 +02:00
class cmTargetExport;
class cmTargetInternals;
2016-10-30 18:24:19 +01:00
2022-03-29 21:10:50 +02:00
template <typename T>
class BT;
template <typename T>
class BTs;
/** \class cmTarget
* \brief Represent a library or executable target loaded from a makefile.
*
2019-11-11 23:01:05 +01:00
* cmTarget represents a target loaded from a makefile.
*/
class cmTarget
{
public:
2016-10-30 18:24:19 +01:00
enum Visibility
{
VisibilityNormal,
VisibilityImported,
VisibilityImportedGlobally
};
2020-08-30 11:54:41 +02:00
enum class PerConfig
{
Yes,
No
};
2019-11-11 23:01:05 +01:00
cmTarget(std::string const& name, cmStateEnums::TargetType type,
2020-08-30 11:54:41 +02:00
Visibility vis, cmMakefile* mf, PerConfig perConfig);
2019-11-11 23:01:05 +01:00
cmTarget(cmTarget const&) = delete;
cmTarget(cmTarget&&) noexcept;
~cmTarget();
cmTarget& operator=(cmTarget const&) = delete;
cmTarget& operator=(cmTarget&&) noexcept;
2017-04-14 19:02:05 +02:00
2019-11-11 23:01:05 +01:00
//! Return the type of target.
cmStateEnums::TargetType GetType() const;
//! Get the cmMakefile that owns this target.
cmMakefile* GetMakefile() const;
//! Return the global generator.
2017-04-14 19:02:05 +02:00
cmGlobalGenerator* GetGlobalGenerator() const;
2019-11-11 23:01:05 +01:00
//! Set/Get the name of the target
const std::string& GetName() const;
2019-11-11 23:01:05 +01:00
//! Get the policy map
cmPolicies::PolicyMap const& GetPolicyMap() const;
//! Get policy status
cmPolicies::PolicyStatus GetPolicyStatus(cmPolicies::PolicyID policy) const;
2016-07-09 11:21:54 +02:00
#define DECLARE_TARGET_POLICY(POLICY) \
cmPolicies::PolicyStatus GetPolicyStatus##POLICY() const \
{ \
2019-11-11 23:01:05 +01:00
return this->GetPolicyStatus(cmPolicies::POLICY); \
2016-07-09 11:21:54 +02:00
}
2013-11-03 12:27:13 +02:00
CM_FOR_EACH_TARGET_POLICY(DECLARE_TARGET_POLICY)
2013-11-03 12:27:13 +02:00
#undef DECLARE_TARGET_POLICY
2013-03-16 19:13:01 +02:00
2019-11-11 23:01:05 +01:00
//! Get the list of the PRE_BUILD custom commands for this target
std::vector<cmCustomCommand> const& GetPreBuildCommands() const;
void AddPreBuildCommand(cmCustomCommand const& cmd);
2020-02-01 23:06:01 +01:00
void AddPreBuildCommand(cmCustomCommand&& cmd);
2019-11-11 23:01:05 +01:00
//! Get the list of the PRE_LINK custom commands for this target
std::vector<cmCustomCommand> const& GetPreLinkCommands() const;
void AddPreLinkCommand(cmCustomCommand const& cmd);
2020-02-01 23:06:01 +01:00
void AddPreLinkCommand(cmCustomCommand&& cmd);
2019-11-11 23:01:05 +01:00
//! Get the list of the POST_BUILD custom commands for this target
std::vector<cmCustomCommand> const& GetPostBuildCommands() const;
void AddPostBuildCommand(cmCustomCommand const& cmd);
2020-02-01 23:06:01 +01:00
void AddPostBuildCommand(cmCustomCommand&& cmd);
2019-11-11 23:01:05 +01:00
//! Add sources to the target.
void AddSources(std::vector<std::string> const& srcs);
2015-04-27 22:25:09 +02:00
void AddTracedSources(std::vector<std::string> const& srcs);
2020-02-01 23:06:01 +01:00
std::string GetSourceCMP0049(const std::string& src);
2019-11-11 23:01:05 +01:00
cmSourceFile* AddSource(const std::string& src, bool before = false);
2019-11-11 23:01:05 +01:00
//! how we identify a library, by name and type
2020-02-01 23:06:01 +01:00
using LibraryID = std::pair<std::string, cmTargetLinkLibraryType>;
using LinkLibraryVectorType = std::vector<LibraryID>;
2019-11-11 23:01:05 +01:00
LinkLibraryVectorType const& GetOriginalLinkLibraries() const;
2019-11-11 23:01:05 +01:00
//! Clear the dependency information recorded for this target, if any.
2021-09-14 00:13:48 +02:00
void ClearDependencyInformation(cmMakefile& mf) const;
2018-10-28 12:09:07 +01:00
void AddLinkLibrary(cmMakefile& mf, std::string const& lib,
2020-08-30 11:54:41 +02:00
cmTargetLinkLibraryType llt);
2018-10-28 12:09:07 +01:00
2016-07-09 11:21:54 +02:00
enum TLLSignature
{
2013-11-03 12:27:13 +02:00
KeywordTLLSignature,
PlainTLLSignature
};
2015-08-17 11:37:30 +02:00
bool PushTLLCommandTrace(TLLSignature signature,
cmListFileContext const& lfc);
2016-10-30 18:24:19 +01:00
void GetTllSignatureTraces(std::ostream& s, TLLSignature sig) const;
/**
* Set the path where this target should be installed. This is relative to
* INSTALL_PREFIX
*/
2019-11-11 23:01:05 +01:00
std::string const& GetInstallPath() const;
void SetInstallPath(std::string const& name);
/**
* Set the path where this target (if it has a runtime part) should be
* installed. This is relative to INSTALL_PREFIX
*/
2019-11-11 23:01:05 +01:00
std::string const& GetRuntimeInstallPath() const;
void SetRuntimeInstallPath(std::string const& name);
/**
* Get/Set whether there is an install rule for this target.
*/
2019-11-11 23:01:05 +01:00
bool GetHaveInstallRule() const;
void SetHaveInstallRule(bool hir);
void AddInstallGenerator(cmInstallTargetGenerator* g);
std::vector<cmInstallTargetGenerator*> const& GetInstallGenerators() const;
2018-04-23 21:13:27 +02:00
/**
2018-08-09 18:06:22 +02:00
* Get/Set whether this target was auto-created by a generator.
*/
2019-11-11 23:01:05 +01:00
bool GetIsGeneratorProvided() const;
void SetIsGeneratorProvided(bool igp);
2018-04-23 21:13:27 +02:00
2019-11-11 23:01:05 +01:00
/**
* Add a utility on which this project depends. A utility is an executable
* name as would be specified to the ADD_EXECUTABLE or UTILITY_SOURCE
* commands. It is not a full path nor does it have an extension.
*/
2020-08-30 11:54:41 +02:00
void AddUtility(std::string const& name, bool cross,
cmMakefile* mf = nullptr);
2021-09-14 00:13:48 +02:00
void AddUtility(BT<std::pair<std::string, bool>> util);
2019-11-11 23:01:05 +01:00
//! Get the utilities used by this target
2020-08-30 11:54:41 +02:00
std::set<BT<std::pair<std::string, bool>>> const& GetUtilities() const;
2019-11-11 23:01:05 +01:00
//! Set/Get a property of this target file
2016-07-09 11:21:54 +02:00
void SetProperty(const std::string& prop, const char* value);
2021-11-20 13:41:27 +01:00
void SetProperty(const std::string& prop, cmValue value);
2020-08-30 11:54:41 +02:00
void SetProperty(const std::string& prop, const std::string& value)
{
2021-11-20 13:41:27 +01:00
this->SetProperty(prop, cmValue(value));
2020-08-30 11:54:41 +02:00
}
2022-11-16 20:14:03 +01:00
void AppendProperty(
const std::string& prop, const std::string& value,
cm::optional<cmListFileBacktrace> const& bt = cm::nullopt,
bool asString = false);
2019-11-11 23:01:05 +01:00
//! Might return a nullptr if the property is not set or invalid
2021-11-20 13:41:27 +01:00
cmValue GetProperty(const std::string& prop) const;
2019-11-11 23:01:05 +01:00
//! Always returns a valid pointer
2020-08-30 11:54:41 +02:00
std::string const& GetSafeProperty(std::string const& prop) const;
2015-04-27 22:25:09 +02:00
bool GetPropertyAsBool(const std::string& prop) const;
void CheckProperty(const std::string& prop, cmMakefile* context) const;
2022-03-29 21:10:50 +02:00
cmValue GetComputedProperty(const std::string& prop, cmMakefile& mf) const;
2019-11-11 23:01:05 +01:00
//! Get all properties
cmPropertyMap const& GetProperties() const;
2015-04-27 22:25:09 +02:00
2020-02-01 23:06:01 +01:00
//! Return whether or not the target is for a DLL platform.
bool IsDLLPlatform() const;
//! Return whether or not we are targeting AIX.
bool IsAIX() const;
2019-11-11 23:01:05 +01:00
bool IsImported() const;
bool IsImportedGloballyVisible() const;
2020-08-30 11:54:41 +02:00
bool IsPerConfig() const;
2021-09-14 00:13:48 +02:00
bool CanCompileSources() const;
2021-11-20 13:41:27 +01:00
bool GetMappedConfig(std::string const& desired_config, cmValue& loc,
cmValue& imp, std::string& suffix) const;
2013-03-16 19:13:01 +02:00
2019-11-11 23:01:05 +01:00
//! Return whether this target is an executable with symbol exports enabled.
2014-08-03 19:52:23 +02:00
bool IsExecutableWithExports() const;
2019-11-11 23:01:05 +01:00
//! Return whether this target is a shared library Framework on Apple.
2014-08-03 19:52:23 +02:00
bool IsFrameworkOnApple() const;
2019-11-11 23:01:05 +01:00
//! Return whether this target is an executable Bundle on Apple.
2014-08-03 19:52:23 +02:00
bool IsAppBundleOnApple() const;
2021-09-14 00:13:48 +02:00
//! Return whether this target is a GUI executable on Android.
bool IsAndroidGuiExecutable() const;
2022-08-04 22:12:04 +02:00
bool HasKnownObjectFileLocation(std::string* reason = nullptr) const;
2019-11-11 23:01:05 +01:00
//! Get a backtrace from the creation of the target.
cmListFileBacktrace const& GetBacktrace() const;
2021-11-20 13:41:27 +01:00
void InsertInclude(BT<std::string> const& entry, bool before = false);
void InsertCompileOption(BT<std::string> const& entry, bool before = false);
void InsertCompileDefinition(BT<std::string> const& entry);
void InsertLinkOption(BT<std::string> const& entry, bool before = false);
void InsertLinkDirectory(BT<std::string> const& entry, bool before = false);
void InsertPrecompileHeader(BT<std::string> const& entry);
2013-03-16 19:13:01 +02:00
void AppendBuildInterfaceIncludes();
2022-09-13 21:35:23 +02:00
void FinalizeTargetConfiguration(
2022-08-04 22:12:04 +02:00
const cmBTStringRange& noConfigCompileDefinitions,
cm::optional<std::map<std::string, cmValue>>& perConfigCompileDefinitions);
2013-03-16 19:13:01 +02:00
2016-07-09 11:21:54 +02:00
std::string GetDebugGeneratorExpressions(const std::string& value,
cmTargetLinkLibraryType llt) const;
2013-11-03 12:27:13 +02:00
2019-11-11 23:01:05 +01:00
void AddSystemIncludeDirectories(std::set<std::string> const& incs);
std::set<std::string> const& GetSystemIncludeDirectories() const;
2013-11-03 12:27:13 +02:00
2022-03-29 21:10:50 +02:00
void AddInstallIncludeDirectories(cmTargetExport const& te,
cmStringRange const& incs);
cmStringRange GetInstallIncludeDirectoriesEntries(
cmTargetExport const& te) const;
2021-11-20 13:41:27 +01:00
2021-09-14 00:13:48 +02:00
BTs<std::string> const* GetLanguageStandardProperty(
const std::string& propertyName) const;
void SetLanguageStandardProperty(std::string const& lang,
std::string const& value,
const std::string& feature);
2021-11-20 13:41:27 +01:00
cmBTStringRange GetIncludeDirectoriesEntries() const;
2015-11-17 17:22:37 +01:00
2021-11-20 13:41:27 +01:00
cmBTStringRange GetCompileOptionsEntries() const;
2015-11-17 17:22:37 +01:00
2021-11-20 13:41:27 +01:00
cmBTStringRange GetCompileFeaturesEntries() const;
2015-11-17 17:22:37 +01:00
2021-11-20 13:41:27 +01:00
cmBTStringRange GetCompileDefinitionsEntries() const;
2015-11-17 17:22:37 +01:00
2021-11-20 13:41:27 +01:00
cmBTStringRange GetPrecompileHeadersEntries() const;
2020-02-01 23:06:01 +01:00
2021-11-20 13:41:27 +01:00
cmBTStringRange GetSourceEntries() const;
2018-10-28 12:09:07 +01:00
2021-11-20 13:41:27 +01:00
cmBTStringRange GetLinkOptionsEntries() const;
2018-10-28 12:09:07 +01:00
2021-11-20 13:41:27 +01:00
cmBTStringRange GetLinkDirectoriesEntries() const;
2018-10-28 12:09:07 +01:00
2021-11-20 13:41:27 +01:00
cmBTStringRange GetLinkImplementationEntries() const;
2016-03-13 13:35:51 +01:00
2022-03-29 21:10:50 +02:00
cmBTStringRange GetLinkInterfaceEntries() const;
2022-08-04 22:12:04 +02:00
cmBTStringRange GetLinkInterfaceDirectEntries() const;
cmBTStringRange GetLinkInterfaceDirectExcludeEntries() const;
2022-03-29 21:10:50 +02:00
cmBTStringRange GetHeaderSetsEntries() const;
2022-11-16 20:14:03 +01:00
cmBTStringRange GetCxxModuleSetsEntries() const;
cmBTStringRange GetCxxModuleHeaderSetsEntries() const;
2022-03-29 21:10:50 +02:00
cmBTStringRange GetInterfaceHeaderSetsEntries() const;
2022-11-16 20:14:03 +01:00
cmBTStringRange GetInterfaceCxxModuleSetsEntries() const;
cmBTStringRange GetInterfaceCxxModuleHeaderSetsEntries() const;
2022-03-29 21:10:50 +02:00
2019-11-11 23:01:05 +01:00
std::string ImportedGetFullPath(const std::string& config,
cmStateEnums::ArtifactType artifact) const;
2016-07-09 11:21:54 +02:00
struct StrictTargetComparison
{
2016-03-13 13:35:51 +01:00
bool operator()(cmTarget const* t1, cmTarget const* t2) const;
};
2022-03-29 21:10:50 +02:00
const cmFileSet* GetFileSet(const std::string& name) const;
cmFileSet* GetFileSet(const std::string& name);
std::pair<cmFileSet*, bool> GetOrCreateFileSet(const std::string& name,
2022-04-13 00:32:21 +02:00
const std::string& type,
cmFileSetVisibility vis);
2022-03-29 21:10:50 +02:00
2022-08-04 22:12:04 +02:00
std::vector<std::string> GetAllFileSetNames() const;
2022-03-29 21:10:50 +02:00
std::vector<std::string> GetAllInterfaceFileSets() const;
static std::string GetFileSetsPropertyName(const std::string& type);
static std::string GetInterfaceFileSetsPropertyName(const std::string& type);
2017-04-14 19:02:05 +02:00
private:
2021-11-20 13:41:27 +01:00
template <typename ValueType>
void StoreProperty(const std::string& prop, ValueType value);
2019-11-11 23:01:05 +01:00
// Internal representation details.
friend class cmGeneratorTarget;
2017-07-20 19:35:53 +02:00
const char* GetSuffixVariableInternal(
cmStateEnums::ArtifactType artifact) const;
const char* GetPrefixVariableInternal(
cmStateEnums::ArtifactType artifact) const;
2019-11-11 23:01:05 +01:00
std::unique_ptr<cmTargetInternals> impl;
2016-07-09 11:21:54 +02:00
};