2009-09-28 11:43:28 -04:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
2008-01-28 08:38:36 -05:00
|
|
|
|
2009-09-28 11:43:28 -04:00
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
2008-01-28 08:38:36 -05:00
|
|
|
|
2009-09-28 11:43:28 -04:00
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
|
|
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
See the License for more information.
|
|
|
|
============================================================================*/
|
2008-01-28 08:38:36 -05:00
|
|
|
#ifndef cmExportFileGenerator_h
|
|
|
|
#define cmExportFileGenerator_h
|
|
|
|
|
2016-09-01 20:59:28 +02:00
|
|
|
#include <cmConfigure.h> // IWYU pragma: keep
|
2008-01-28 08:38:36 -05:00
|
|
|
|
2016-09-01 20:59:28 +02:00
|
|
|
#include "cmGeneratorExpression.h"
|
2014-02-11 16:31:53 +01:00
|
|
|
#include "cmVersion.h"
|
2016-09-01 20:59:28 +02:00
|
|
|
#include "cmVersionConfig.h"
|
|
|
|
|
|
|
|
#include <iosfwd>
|
|
|
|
#include <map>
|
|
|
|
#include <set>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
class cmGeneratorTarget;
|
2014-02-11 16:31:53 +01:00
|
|
|
|
|
|
|
#define STRINGIFY_HELPER(X) #X
|
|
|
|
#define STRINGIFY(X) STRINGIFY_HELPER(X)
|
|
|
|
|
2016-05-16 10:34:04 -04: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-02-11 16:31:53 +01:00
|
|
|
|
2013-01-05 12:13:49 +01:00
|
|
|
class cmTargetExport;
|
|
|
|
|
2008-01-28 08:38:36 -05:00
|
|
|
/** \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:
|
2008-01-28 13:21:42 -05:00
|
|
|
cmExportFileGenerator();
|
2008-01-28 09:53:21 -05:00
|
|
|
virtual ~cmExportFileGenerator() {}
|
|
|
|
|
2008-01-28 08:38:36 -05:00
|
|
|
/** Set the full path to the export file to generate. */
|
|
|
|
void SetExportFile(const char* mainFile);
|
2016-05-16 10:34:04 -04:00
|
|
|
const char* GetMainExportFileName() const;
|
2008-01-28 08:38:36 -05:00
|
|
|
|
|
|
|
/** Set the namespace in which to place exported target names. */
|
2014-02-21 19:05:55 -05:00
|
|
|
void SetNamespace(const std::string& ns) { this->Namespace = ns; }
|
2012-10-06 17:27:40 +02:00
|
|
|
std::string GetNamespace() const { return this->Namespace; }
|
2008-01-28 08:38:36 -05:00
|
|
|
|
2013-06-04 16:47:57 +02:00
|
|
|
void SetExportOld(bool exportOld) { this->ExportOld = exportOld; }
|
|
|
|
|
2008-01-28 08:38:36 -05:00
|
|
|
/** Add a configuration to be exported. */
|
2014-02-09 22:48:34 -05:00
|
|
|
void AddConfiguration(const std::string& config);
|
2008-01-28 08:38:36 -05:00
|
|
|
|
|
|
|
/** Actually generate the export file. Returns whether there was an
|
|
|
|
error. */
|
|
|
|
bool GenerateImportFile();
|
|
|
|
|
2016-05-16 10:34:04 -04:00
|
|
|
protected:
|
2014-02-10 00:21:34 -05:00
|
|
|
typedef std::map<std::string, std::string> ImportPropertyMap;
|
2008-01-28 08:38:36 -05:00
|
|
|
|
|
|
|
// Generate per-configuration target information to the given output
|
|
|
|
// stream.
|
2014-02-09 22:48:34 -05:00
|
|
|
void GenerateImportConfig(std::ostream& os, const std::string& config,
|
2016-05-16 10:34:04 -04:00
|
|
|
std::vector<std::string>& missingTargets);
|
2008-01-28 08:38:36 -05:00
|
|
|
|
|
|
|
// Methods to implement export file code generation.
|
2016-07-12 13:26:55 -04:00
|
|
|
void GeneratePolicyHeaderCode(std::ostream& os);
|
|
|
|
void GeneratePolicyFooterCode(std::ostream& os);
|
2014-02-09 22:48:34 -05:00
|
|
|
void GenerateImportHeaderCode(std::ostream& os,
|
|
|
|
const std::string& config = "");
|
2008-01-28 08:38:36 -05:00
|
|
|
void GenerateImportFooterCode(std::ostream& os);
|
|
|
|
void GenerateImportVersionCode(std::ostream& os);
|
2015-10-17 14:33:51 +02:00
|
|
|
void GenerateImportTargetCode(std::ostream& os,
|
|
|
|
cmGeneratorTarget const* target);
|
2014-02-09 22:48:34 -05:00
|
|
|
void GenerateImportPropertyCode(std::ostream& os, const std::string& config,
|
2015-10-17 15:10:32 +02:00
|
|
|
cmGeneratorTarget const* target,
|
2008-01-28 08:38:36 -05:00
|
|
|
ImportPropertyMap const& properties);
|
2016-05-16 10:34:04 -04:00
|
|
|
void GenerateImportedFileChecksCode(
|
|
|
|
std::ostream& os, cmGeneratorTarget* target,
|
|
|
|
ImportPropertyMap const& properties,
|
|
|
|
const std::set<std::string>& importedLocations);
|
2011-11-12 18:12:07 +01:00
|
|
|
void GenerateImportedFileCheckLoop(std::ostream& os);
|
2016-05-16 10:34:04 -04:00
|
|
|
void GenerateMissingTargetsCheckCode(
|
|
|
|
std::ostream& os, const std::vector<std::string>& missingTargets);
|
2011-11-12 18:12:07 +01:00
|
|
|
|
2012-11-30 09:26:09 +01:00
|
|
|
void GenerateExpectedTargetsCode(std::ostream& os,
|
2016-05-16 10:34:04 -04:00
|
|
|
const std::string& expectedTargets);
|
2008-01-28 08:38:36 -05:00
|
|
|
|
|
|
|
// Collect properties with detailed information about targets beyond
|
|
|
|
// their location on disk.
|
2014-02-09 22:48:34 -05:00
|
|
|
void SetImportDetailProperties(const std::string& config,
|
2012-10-06 17:51:07 +02:00
|
|
|
std::string const& suffix,
|
|
|
|
cmGeneratorTarget* target,
|
2012-09-15 22:38:30 +02:00
|
|
|
ImportPropertyMap& properties,
|
|
|
|
std::vector<std::string>& missingTargets);
|
2014-06-16 09:38:04 -04:00
|
|
|
|
|
|
|
template <typename T>
|
2008-01-31 15:45:31 -05:00
|
|
|
void SetImportLinkProperty(std::string const& suffix,
|
2012-10-06 17:51:07 +02:00
|
|
|
cmGeneratorTarget* target,
|
|
|
|
const std::string& propName,
|
2014-06-16 09:38:04 -04:00
|
|
|
std::vector<T> const& entries,
|
2012-09-15 22:38:30 +02:00
|
|
|
ImportPropertyMap& properties,
|
|
|
|
std::vector<std::string>& missingTargets);
|
2008-01-28 08:38:36 -05:00
|
|
|
|
|
|
|
/** 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-05-16 10:34:04 -04:00
|
|
|
virtual void GenerateImportTargetsConfig(
|
|
|
|
std::ostream& os, const std::string& config, std::string const& suffix,
|
|
|
|
std::vector<std::string>& missingTargets) = 0;
|
2008-01-28 08:38:36 -05:00
|
|
|
|
2012-09-28 21:47:37 +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,
|
2015-10-17 15:05:46 +02:00
|
|
|
cmGeneratorTarget* depender,
|
|
|
|
cmGeneratorTarget* dependee) = 0;
|
2016-05-16 10:34:04 -04:00
|
|
|
void PopulateInterfaceProperty(const std::string&, cmGeneratorTarget* target,
|
2012-12-10 23:05:11 +01:00
|
|
|
cmGeneratorExpression::PreprocessContext,
|
2016-05-16 10:34:04 -04:00
|
|
|
ImportPropertyMap& properties,
|
|
|
|
std::vector<std::string>& missingTargets);
|
|
|
|
bool PopulateInterfaceLinkLibrariesProperty(
|
|
|
|
cmGeneratorTarget* target, cmGeneratorExpression::PreprocessContext,
|
|
|
|
ImportPropertyMap& properties, std::vector<std::string>& missingTargets);
|
2015-10-17 14:33:51 +02:00
|
|
|
void PopulateInterfaceProperty(const std::string& propName,
|
|
|
|
cmGeneratorTarget* target,
|
2016-05-16 10:34:04 -04:00
|
|
|
ImportPropertyMap& properties);
|
|
|
|
void PopulateCompatibleInterfaceProperties(cmGeneratorTarget* target,
|
|
|
|
ImportPropertyMap& properties);
|
2015-10-17 14:33:51 +02:00
|
|
|
void GenerateInterfaceProperties(cmGeneratorTarget const* target,
|
|
|
|
std::ostream& os,
|
2016-05-16 10:34:04 -04:00
|
|
|
const ImportPropertyMap& properties);
|
2013-03-24 21:18:17 +01:00
|
|
|
void PopulateIncludeDirectoriesInterface(
|
2016-05-16 10:34:04 -04:00
|
|
|
cmTargetExport* target,
|
|
|
|
cmGeneratorExpression::PreprocessContext preprocessRule,
|
|
|
|
ImportPropertyMap& properties, std::vector<std::string>& missingTargets);
|
2014-11-28 18:58:38 +01:00
|
|
|
void PopulateSourcesInterface(
|
2016-05-16 10:34:04 -04: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-01-04 15:56:13 +01:00
|
|
|
ReplaceFreeTargets,
|
|
|
|
NoReplaceFreeTargets
|
|
|
|
};
|
|
|
|
|
2016-05-16 10:34:04 -04:00
|
|
|
void ResolveTargetsInGeneratorExpressions(
|
|
|
|
std::string& input, cmGeneratorTarget* target,
|
|
|
|
std::vector<std::string>& missingTargets,
|
|
|
|
FreeTargetsReplace replace = NoReplaceFreeTargets);
|
2012-12-10 23:07:09 +01:00
|
|
|
|
2013-06-04 16:47:57 +02:00
|
|
|
void GenerateRequiredCMakeVersion(std::ostream& os,
|
2016-05-16 10:34:04 -04:00
|
|
|
const char* versionString);
|
2013-06-04 16:47:57 +02:00
|
|
|
|
2008-01-28 08:38:36 -05:00
|
|
|
// The namespace in which the exports are placed in the generated file.
|
|
|
|
std::string Namespace;
|
|
|
|
|
2013-06-04 16:47:57 +02:00
|
|
|
bool ExportOld;
|
|
|
|
|
2008-01-28 08:38:36 -05:00
|
|
|
// 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;
|
2008-01-28 13:21:42 -05:00
|
|
|
bool AppendMode;
|
2008-01-28 08:38:36 -05:00
|
|
|
|
|
|
|
// The set of targets included in the export.
|
2015-10-17 14:33:51 +02:00
|
|
|
std::set<cmGeneratorTarget*> ExportedTargets;
|
2012-12-10 23:05:11 +01:00
|
|
|
|
|
|
|
private:
|
2014-02-04 16:06:56 -05:00
|
|
|
void PopulateInterfaceProperty(const std::string&, const std::string&,
|
2015-10-17 14:33:51 +02:00
|
|
|
cmGeneratorTarget* target,
|
2012-12-10 23:05:11 +01:00
|
|
|
cmGeneratorExpression::PreprocessContext,
|
2016-05-16 10:34:04 -04:00
|
|
|
ImportPropertyMap& properties,
|
|
|
|
std::vector<std::string>& missingTargets);
|
2013-01-08 20:58:33 +01:00
|
|
|
|
2016-05-16 10:34:04 -04:00
|
|
|
bool AddTargetNamespace(std::string& input, cmGeneratorTarget* target,
|
|
|
|
std::vector<std::string>& missingTargets);
|
2013-01-08 20:58:33 +01:00
|
|
|
|
2016-05-16 10:34:04 -04:00
|
|
|
void ResolveTargetsInGeneratorExpression(
|
|
|
|
std::string& input, cmGeneratorTarget* target,
|
|
|
|
std::vector<std::string>& missingTargets);
|
2013-01-27 09:43:44 +01:00
|
|
|
|
2016-05-16 10:34:04 -04:00
|
|
|
virtual void ReplaceInstallPrefix(std::string& input);
|
2013-05-20 16:57:58 -06:00
|
|
|
|
2015-08-04 19:19:47 +02:00
|
|
|
virtual std::string InstallNameDir(cmGeneratorTarget* target,
|
2013-05-20 16:57:58 -06:00
|
|
|
const std::string& config) = 0;
|
2008-01-28 08:38:36 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|