cmake/Source/cmExportFileGenerator.h

214 lines
8.7 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. */
#ifndef cmExportFileGenerator_h
#define cmExportFileGenerator_h
2017-07-20 19:35:53 +02:00
#include "cmConfigure.h" // IWYU pragma: keep
2016-10-30 18:24:19 +01:00
#include "cmGeneratorExpression.h"
2018-08-09 18:06:22 +02:00
#include "cmStateTypes.h"
2014-08-03 19:52:23 +02:00
#include "cmVersion.h"
2016-10-30 18:24:19 +01:00
#include "cmVersionConfig.h"
#include <iosfwd>
#include <map>
#include <set>
#include <string>
#include <vector>
class cmGeneratorTarget;
2014-08-03 19:52:23 +02:00
#define STRINGIFY_HELPER(X) #X
#define STRINGIFY(X) STRINGIFY_HELPER(X)
2016-07-09 11:21:54 +02:00
#define DEVEL_CMAKE_VERSION(major, minor) \
(CMake_VERSION_ENCODE(major, minor, 0) > \
CMake_VERSION_ENCODE(CMake_VERSION_MAJOR, CMake_VERSION_MINOR, 0) \
? STRINGIFY(CMake_VERSION_MAJOR) "." STRINGIFY( \
CMake_VERSION_MINOR) "." STRINGIFY(CMake_VERSION_PATCH) \
: #major "." #minor ".0")
2014-08-03 19:52:23 +02:00
2013-11-03 12:27:13 +02:00
class cmTargetExport;
/** \class cmExportFileGenerator
* \brief Generate a file exporting targets from a build or install tree.
*
* cmExportFileGenerator is the superclass for
* cmExportBuildFileGenerator and cmExportInstallFileGenerator. It
* contains common code generation routines for the two kinds of
* export implementations.
*/
class cmExportFileGenerator
{
public:
cmExportFileGenerator();
virtual ~cmExportFileGenerator() {}
/** Set the full path to the export file to generate. */
void SetExportFile(const char* mainFile);
2016-07-09 11:21:54 +02:00
const char* GetMainExportFileName() const;
/** Set the namespace in which to place exported target names. */
2015-04-27 22:25:09 +02:00
void SetNamespace(const std::string& ns) { this->Namespace = ns; }
2014-08-03 19:52:23 +02:00
std::string GetNamespace() const { return this->Namespace; }
2013-11-03 12:27:13 +02:00
void SetExportOld(bool exportOld) { this->ExportOld = exportOld; }
/** Add a configuration to be exported. */
2015-04-27 22:25:09 +02:00
void AddConfiguration(const std::string& config);
/** Actually generate the export file. Returns whether there was an
error. */
bool GenerateImportFile();
2016-07-09 11:21:54 +02:00
protected:
2015-04-27 22:25:09 +02:00
typedef std::map<std::string, std::string> ImportPropertyMap;
// Generate per-configuration target information to the given output
// stream.
2015-04-27 22:25:09 +02:00
void GenerateImportConfig(std::ostream& os, const std::string& config,
2016-07-09 11:21:54 +02:00
std::vector<std::string>& missingTargets);
// Methods to implement export file code generation.
2016-10-30 18:24:19 +01:00
virtual void GeneratePolicyHeaderCode(std::ostream& os);
virtual void GeneratePolicyFooterCode(std::ostream& os);
virtual void GenerateImportHeaderCode(std::ostream& os,
const std::string& config = "");
virtual void GenerateImportFooterCode(std::ostream& os);
void GenerateImportVersionCode(std::ostream& os);
2016-10-30 18:24:19 +01:00
virtual void GenerateImportTargetCode(std::ostream& os,
2018-08-09 18:06:22 +02:00
cmGeneratorTarget const* target,
cmStateEnums::TargetType targetType);
2016-10-30 18:24:19 +01:00
virtual void GenerateImportPropertyCode(std::ostream& os,
const std::string& config,
cmGeneratorTarget const* target,
ImportPropertyMap const& properties);
virtual void GenerateImportedFileChecksCode(
2016-07-09 11:21:54 +02:00
std::ostream& os, cmGeneratorTarget* target,
ImportPropertyMap const& properties,
const std::set<std::string>& importedLocations);
2016-10-30 18:24:19 +01:00
virtual void GenerateImportedFileCheckLoop(std::ostream& os);
virtual void GenerateMissingTargetsCheckCode(
2016-07-09 11:21:54 +02:00
std::ostream& os, const std::vector<std::string>& missingTargets);
2012-02-18 12:40:36 +02:00
2016-10-30 18:24:19 +01:00
virtual void GenerateExpectedTargetsCode(std::ostream& os,
const std::string& expectedTargets);
// Collect properties with detailed information about targets beyond
// their location on disk.
2015-04-27 22:25:09 +02:00
void SetImportDetailProperties(const std::string& config,
2015-11-17 17:22:37 +01:00
std::string const& suffix,
cmGeneratorTarget* target,
2013-03-16 19:13:01 +02:00
ImportPropertyMap& properties,
std::vector<std::string>& missingTargets);
2015-04-27 22:25:09 +02:00
template <typename T>
void SetImportLinkProperty(std::string const& suffix,
2015-11-17 17:22:37 +01:00
cmGeneratorTarget* target,
const std::string& propName,
2015-04-27 22:25:09 +02:00
std::vector<T> const& entries,
2013-03-16 19:13:01 +02:00
ImportPropertyMap& properties,
std::vector<std::string>& missingTargets);
/** Each subclass knows how to generate its kind of export file. */
virtual bool GenerateMainFile(std::ostream& os) = 0;
/** Each subclass knows where the target files are located. */
2016-07-09 11:21:54 +02:00
virtual void GenerateImportTargetsConfig(
std::ostream& os, const std::string& config, std::string const& suffix,
std::vector<std::string>& missingTargets) = 0;
2013-03-16 19:13:01 +02:00
/** Each subclass knows how to deal with a target that is missing from an
* export set. */
virtual void HandleMissingTarget(std::string& link_libs,
std::vector<std::string>& missingTargets,
2016-03-13 13:35:51 +01:00
cmGeneratorTarget* depender,
cmGeneratorTarget* dependee) = 0;
2016-07-09 11:21:54 +02:00
void PopulateInterfaceProperty(const std::string&, cmGeneratorTarget* target,
2013-11-03 12:27:13 +02:00
cmGeneratorExpression::PreprocessContext,
2016-07-09 11:21:54 +02:00
ImportPropertyMap& properties,
std::vector<std::string>& missingTargets);
bool PopulateInterfaceLinkLibrariesProperty(
cmGeneratorTarget* target, cmGeneratorExpression::PreprocessContext,
ImportPropertyMap& properties, std::vector<std::string>& missingTargets);
2016-03-13 13:35:51 +01:00
void PopulateInterfaceProperty(const std::string& propName,
cmGeneratorTarget* target,
2016-07-09 11:21:54 +02:00
ImportPropertyMap& properties);
void PopulateCompatibleInterfaceProperties(cmGeneratorTarget* target,
ImportPropertyMap& properties);
2016-10-30 18:24:19 +01:00
virtual void GenerateInterfaceProperties(
cmGeneratorTarget const* target, std::ostream& os,
const ImportPropertyMap& properties);
2013-04-21 10:33:41 +03:00
void PopulateIncludeDirectoriesInterface(
2016-07-09 11:21:54 +02:00
cmTargetExport* target,
cmGeneratorExpression::PreprocessContext preprocessRule,
ImportPropertyMap& properties, std::vector<std::string>& missingTargets);
2015-08-17 11:37:30 +02:00
void PopulateSourcesInterface(
2016-07-09 11:21:54 +02:00
cmTargetExport* target,
cmGeneratorExpression::PreprocessContext preprocessRule,
ImportPropertyMap& properties, std::vector<std::string>& missingTargets);
void SetImportLinkInterface(
const std::string& config, std::string const& suffix,
cmGeneratorExpression::PreprocessContext preprocessRule,
cmGeneratorTarget* target, ImportPropertyMap& properties,
std::vector<std::string>& missingTargets);
enum FreeTargetsReplace
{
2013-03-16 19:13:01 +02:00
ReplaceFreeTargets,
NoReplaceFreeTargets
};
2016-07-09 11:21:54 +02:00
void ResolveTargetsInGeneratorExpressions(
std::string& input, cmGeneratorTarget* target,
std::vector<std::string>& missingTargets,
FreeTargetsReplace replace = NoReplaceFreeTargets);
2016-10-30 18:24:19 +01:00
virtual void GenerateRequiredCMakeVersion(std::ostream& os,
const char* versionString);
2013-11-03 12:27:13 +02:00
2018-08-09 18:06:22 +02:00
bool PopulateExportProperties(cmGeneratorTarget* gte,
ImportPropertyMap& properties,
std::string& errorMessage);
// The namespace in which the exports are placed in the generated file.
std::string Namespace;
2013-11-03 12:27:13 +02:00
bool ExportOld;
// The set of configurations to export.
std::vector<std::string> Configurations;
// The file to generate.
std::string MainImportFile;
std::string FileDir;
std::string FileBase;
std::string FileExt;
bool AppendMode;
// The set of targets included in the export.
2016-03-13 13:35:51 +01:00
std::set<cmGeneratorTarget*> ExportedTargets;
2013-03-16 19:13:01 +02:00
private:
2015-04-27 22:25:09 +02:00
void PopulateInterfaceProperty(const std::string&, const std::string&,
2016-03-13 13:35:51 +01:00
cmGeneratorTarget* target,
2013-03-16 19:13:01 +02:00
cmGeneratorExpression::PreprocessContext,
2016-07-09 11:21:54 +02:00
ImportPropertyMap& properties,
std::vector<std::string>& missingTargets);
2013-03-16 19:13:01 +02:00
2016-07-09 11:21:54 +02:00
bool AddTargetNamespace(std::string& input, cmGeneratorTarget* target,
std::vector<std::string>& missingTargets);
2013-03-16 19:13:01 +02:00
2016-07-09 11:21:54 +02:00
void ResolveTargetsInGeneratorExpression(
std::string& input, cmGeneratorTarget* target,
std::vector<std::string>& missingTargets);
2013-03-16 19:13:01 +02:00
2016-07-09 11:21:54 +02:00
virtual void ReplaceInstallPrefix(std::string& input);
2013-11-03 12:27:13 +02:00
2015-11-17 17:22:37 +01:00
virtual std::string InstallNameDir(cmGeneratorTarget* target,
2013-11-03 12:27:13 +02:00
const std::string& config) = 0;
};
#endif