cmake/Source/cmLocalGenerator.h

427 lines
16 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 cmLocalGenerator_h
#define cmLocalGenerator_h
2018-01-26 17:06:56 +01:00
#include "cmConfigure.h" // IWYU pragma: keep
2016-07-09 11:21:54 +02:00
2017-07-20 19:35:53 +02:00
#include "cm_kwiml.h"
2016-10-30 18:24:19 +01:00
#include <iosfwd>
#include <map>
#include <set>
#include <string>
2018-01-26 17:06:56 +01:00
#include <unordered_map>
2016-10-30 18:24:19 +01:00
#include <vector>
2017-04-14 19:02:05 +02:00
#include "cmListFileCache.h"
#include "cmOutputConverter.h"
#include "cmPolicies.h"
#include "cmStateSnapshot.h"
#include "cmake.h"
class cmComputeLinkInformation;
2016-10-30 18:24:19 +01:00
class cmCustomCommandGenerator;
2013-03-16 19:13:01 +02:00
class cmGeneratorTarget;
2016-10-30 18:24:19 +01:00
class cmGlobalGenerator;
2017-04-14 19:02:05 +02:00
class cmLinkLineComputer;
2016-10-30 18:24:19 +01:00
class cmMakefile;
2017-04-14 19:02:05 +02:00
class cmRulePlaceholderExpander;
class cmSourceFile;
2017-04-14 19:02:05 +02:00
class cmState;
/** \class cmLocalGenerator
* \brief Create required build files for a directory.
*
* Subclasses of this abstract class generate makefiles, DSP, etc for various
2012-02-18 12:40:36 +02:00
* platforms. This class should never be constructed directly. A
* GlobalGenerator will create it and invoke the appropriate commands on it.
*/
2015-11-17 17:22:37 +01:00
class cmLocalGenerator : public cmOutputConverter
{
public:
2015-11-17 17:22:37 +01:00
cmLocalGenerator(cmGlobalGenerator* gg, cmMakefile* makefile);
virtual ~cmLocalGenerator();
2012-02-18 12:40:36 +02:00
/**
2012-02-18 12:40:36 +02:00
* Generate the makefile for this directory.
*/
virtual void Generate() {}
2015-11-17 17:22:37 +01:00
virtual void ComputeHomeRelativeOutputPath() {}
2012-02-18 12:40:36 +02:00
/**
* Calls TraceVSDependencies() on all targets of this generator.
*/
2013-03-16 19:13:01 +02:00
void TraceDependencies();
virtual void AddHelperCommands() {}
/**
* Generate the install rules files in this directory.
*/
2013-03-16 19:13:01 +02:00
void GenerateInstallRules();
/**
* Generate the test files for tests.
*/
2013-03-16 19:13:01 +02:00
void GenerateTestFiles();
/**
* Generate a manifest of target files that will be built.
*/
2015-11-17 17:22:37 +01:00
void ComputeTargetManifest();
2017-07-20 19:35:53 +02:00
bool ComputeTargetCompileFeatures();
2016-03-13 13:35:51 +01:00
bool IsRootMakefile() const;
///! Get the makefile for this generator
2016-07-09 11:21:54 +02:00
cmMakefile* GetMakefile() { return this->Makefile; }
2012-02-18 12:40:36 +02:00
///! Get the makefile for this generator, const version
2016-07-09 11:21:54 +02:00
const cmMakefile* GetMakefile() const { return this->Makefile; }
2012-02-18 12:40:36 +02:00
///! Get the GlobalGenerator this is associated with
2016-07-09 11:21:54 +02:00
cmGlobalGenerator* GetGlobalGenerator() { return this->GlobalGenerator; }
const cmGlobalGenerator* GetGlobalGenerator() const
{
return this->GlobalGenerator;
}
2017-04-14 19:02:05 +02:00
virtual cmRulePlaceholderExpander* CreateRulePlaceholderExpander() const;
std::string GetLinkLibsCMP0065(std::string const& linkLanguage,
cmGeneratorTarget& tgt) const;
2015-08-17 11:37:30 +02:00
cmState* GetState() const;
2017-04-14 19:02:05 +02:00
cmStateSnapshot GetStateSnapshot() const;
2015-08-17 11:37:30 +02:00
void AddArchitectureFlags(std::string& flags,
cmGeneratorTarget const* target,
2016-07-09 11:21:54 +02:00
const std::string& lang,
const std::string& config);
2010-03-17 14:00:29 +02:00
2017-07-20 19:35:53 +02:00
void AddLanguageFlags(std::string& flags, cmGeneratorTarget const* target,
const std::string& lang, const std::string& config);
void AddLanguageFlagsForLinking(std::string& flags,
cmGeneratorTarget const* target,
const std::string& lang,
const std::string& config);
2016-07-09 11:21:54 +02:00
void AddCMP0018Flags(std::string& flags, cmGeneratorTarget const* target,
2015-04-27 22:25:09 +02:00
std::string const& lang, const std::string& config);
2016-07-09 11:21:54 +02:00
void AddVisibilityPresetFlags(std::string& flags,
2016-03-13 13:35:51 +01:00
cmGeneratorTarget const* target,
2015-04-27 22:25:09 +02:00
const std::string& lang);
void AddConfigVariableFlags(std::string& flags, const std::string& var,
const std::string& config);
2016-07-09 11:21:54 +02:00
void AddCompilerRequirementFlag(std::string& flags,
2016-03-13 13:35:51 +01:00
cmGeneratorTarget const* target,
2015-04-27 22:25:09 +02:00
const std::string& lang);
2012-02-18 12:40:36 +02:00
///! Append flags to a string.
2018-04-23 21:13:27 +02:00
virtual void AppendFlags(std::string& flags,
const std::string& newFlags) const;
virtual void AppendFlags(std::string& flags, const char* newFlags) const;
2015-04-27 22:25:09 +02:00
virtual void AppendFlagEscape(std::string& flags,
2018-04-23 21:13:27 +02:00
const std::string& rawFlag) const;
2017-07-20 19:35:53 +02:00
void AppendIPOLinkerFlags(std::string& flags, cmGeneratorTarget* target,
const std::string& config,
const std::string& lang);
///! Get the include flags for the current makefile and language
2016-07-09 11:21:54 +02:00
std::string GetIncludeFlags(const std::vector<std::string>& includes,
2013-11-03 12:27:13 +02:00
cmGeneratorTarget* target,
2015-04-27 22:25:09 +02:00
const std::string& lang,
bool forceFullPaths = false,
bool forResponseFile = false,
const std::string& config = "");
2016-07-09 11:21:54 +02:00
const std::vector<cmGeneratorTarget*>& GetGeneratorTargets() const
{
return this->GeneratorTargets;
}
2016-03-13 13:35:51 +01:00
void AddGeneratorTarget(cmGeneratorTarget* gt);
void AddImportedGeneratorTarget(cmGeneratorTarget* gt);
void AddOwnedImportedGeneratorTarget(cmGeneratorTarget* gt);
2016-07-09 11:21:54 +02:00
cmGeneratorTarget* FindLocalNonAliasGeneratorTarget(
const std::string& name) const;
2016-03-13 13:35:51 +01:00
cmGeneratorTarget* FindGeneratorTargetToUse(const std::string& name) const;
2018-04-23 21:13:27 +02:00
/**
* Process a list of include directories
*/
void AppendIncludeDirectories(std::vector<std::string>& includes,
const char* includes_list,
const cmSourceFile& sourceFile) const;
void AppendIncludeDirectories(std::vector<std::string>& includes,
std::string const& includes_list,
const cmSourceFile& sourceFile) const
{
this->AppendIncludeDirectories(includes, includes_list.c_str(),
sourceFile);
}
void AppendIncludeDirectories(std::vector<std::string>& includes,
const std::vector<std::string>& includes_vec,
const cmSourceFile& sourceFile) const;
/**
* Encode a list of preprocessor definitions for the compiler
* command line.
*/
2016-10-30 18:24:19 +01:00
void AppendDefines(std::set<std::string>& defines,
const char* defines_list) const;
void AppendDefines(std::set<std::string>& defines,
2017-04-14 19:02:05 +02:00
std::string const& defines_list) const
2013-03-16 19:13:01 +02:00
{
this->AppendDefines(defines, defines_list.c_str());
}
2013-11-03 12:27:13 +02:00
void AppendDefines(std::set<std::string>& defines,
2016-10-30 18:24:19 +01:00
const std::vector<std::string>& defines_vec) const;
2013-11-03 12:27:13 +02:00
2018-04-23 21:13:27 +02:00
/**
* Encode a list of compile options for the compiler
* command line.
*/
void AppendCompileOptions(std::string& options, const char* options_list,
const char* regex = nullptr) const;
void AppendCompileOptions(std::string& options,
std::string const& options_list,
const char* regex = nullptr) const
{
this->AppendCompileOptions(options, options_list.c_str(), regex);
}
void AppendCompileOptions(std::string& options,
const std::vector<std::string>& options_vec,
const char* regex = nullptr) const;
2013-03-16 19:13:01 +02:00
/**
* Join a set of defines into a definesString with a space separator.
*/
void JoinDefines(const std::set<std::string>& defines,
2016-07-09 11:21:54 +02:00
std::string& definesString, const std::string& lang);
2009-10-11 10:55:36 +03:00
/** Lookup and append options associated with a particular feature. */
2015-04-27 22:25:09 +02:00
void AppendFeatureOptions(std::string& flags, const std::string& lang,
2009-10-11 10:55:36 +03:00
const char* feature);
2015-11-17 17:22:37 +01:00
const char* GetFeature(const std::string& feature,
const std::string& config);
2012-04-19 19:04:21 +03:00
/** \brief Get absolute path to dependency \a name
*
* Translate a dependency as given in CMake code to the name to
* appear in a generated build file.
* - If \a name is a utility target, returns false.
* - If \a name is a CMake target, it will be transformed to the real output
* location of that target for the given configuration.
* - If \a name is the full path to a file, it will be returned.
* - Otherwise \a name is treated as a relative path with respect to
* the source directory of this generator. This should only be
* used for dependencies of custom commands.
*/
2015-04-27 22:25:09 +02:00
bool GetRealDependency(const std::string& name, const std::string& config,
2011-01-16 11:35:12 +01:00
std::string& dep);
2016-07-09 11:21:54 +02:00
virtual std::string ConvertToIncludeReference(
std::string const& path,
cmOutputConverter::OutputFormat format = cmOutputConverter::SHELL,
bool forceFullPaths = false);
2012-02-18 12:40:36 +02:00
/** Called from command-line hook to clear dependencies. */
2016-07-09 11:21:54 +02:00
virtual void ClearDependencies(cmMakefile* /* mf */, bool /* verbose */) {}
2012-02-18 12:40:36 +02:00
/** Called from command-line hook to update dependencies. */
2016-07-09 11:21:54 +02:00
virtual bool UpdateDependencies(const char* /* tgtInfo */, bool /*verbose*/,
bool /*color*/)
2016-07-09 11:21:54 +02:00
{
return true;
}
/** Get the include flags for the current makefile and language. */
void GetIncludeDirectories(std::vector<std::string>& dirs,
2016-03-13 13:35:51 +01:00
cmGeneratorTarget const* target,
2015-04-27 22:25:09 +02:00
const std::string& lang = "C",
const std::string& config = "",
2015-11-17 17:22:37 +01:00
bool stripImplicitInclDirs = true) const;
2016-03-13 13:35:51 +01:00
void AddCompileOptions(std::string& flags, cmGeneratorTarget* target,
2015-04-27 22:25:09 +02:00
const std::string& lang, const std::string& config);
2014-08-03 19:52:23 +02:00
void AddCompileDefinitions(std::set<std::string>& defines,
2016-03-13 13:35:51 +01:00
cmGeneratorTarget const* target,
2015-08-17 11:37:30 +02:00
const std::string& config,
2016-10-30 18:24:19 +01:00
const std::string& lang) const;
2016-03-13 13:35:51 +01:00
std::string GetProjectName() const;
/** Compute the language used to compile the given source file. */
2015-04-27 22:25:09 +02:00
std::string GetSourceFileLanguage(const cmSourceFile& source);
2012-06-27 20:52:58 +03:00
// Fill the vector with the target names for the object files,
// preprocessed files and assembly files.
2016-03-13 13:35:51 +01:00
void GetIndividualFileTargets(std::vector<std::string>&) {}
2012-06-27 20:52:58 +03:00
/**
* Get the relative path from the generator output directory to a
* per-target support directory.
*/
2016-07-09 11:21:54 +02:00
virtual std::string GetTargetDirectory(
cmGeneratorTarget const* target) const;
/**
* Get the level of backwards compatibility requested by the project
* in this directory. This is the value of the CMake variable
* CMAKE_BACKWARDS_COMPATIBILITY whose format is
* "major.minor[.patch]". The returned integer is encoded as
*
* CMake_VERSION_ENCODE(major, minor, patch)
*
* and is monotonically increasing with the CMake version.
*/
2016-03-13 13:35:51 +01:00
KWIML_INT_uint64_t GetBackwardsCompatibility();
/**
* Test whether compatibility is set to a given version or lower.
*/
2014-08-03 19:52:23 +02:00
bool NeedBackwardsCompatibility_2_4();
2016-03-13 13:35:51 +01:00
cmPolicies::PolicyStatus GetPolicyStatus(cmPolicies::PolicyID id) const;
cmake* GetCMakeInstance() const;
2018-04-23 21:13:27 +02:00
std::string const& GetSourceDirectory() const;
std::string const& GetBinaryDirectory() const;
2016-03-13 13:35:51 +01:00
const char* GetCurrentBinaryDirectory() const;
const char* GetCurrentSourceDirectory() const;
/**
* Generate a Mac OS X application bundle Info.plist file.
*/
2016-03-13 13:35:51 +01:00
void GenerateAppleInfoPList(cmGeneratorTarget* target,
const std::string& targetName,
const char* fname);
/**
* Generate a Mac OS X framework Info.plist file.
*/
2016-03-13 13:35:51 +01:00
void GenerateFrameworkInfoPList(cmGeneratorTarget* target,
2015-04-27 22:25:09 +02:00
const std::string& targetName,
const char* fname);
/** Construct a comment for a custom command. */
2015-04-27 22:25:09 +02:00
std::string ConstructComment(cmCustomCommandGenerator const& ccg,
const char* default_comment = "");
2009-10-04 10:30:41 +03:00
// Compute object file names.
2016-10-30 18:24:19 +01:00
std::string GetObjectFileNameWithoutTarget(
const cmSourceFile& source, std::string const& dir_max,
2018-01-26 17:06:56 +01:00
bool* hasSourceExtension = nullptr,
char const* customOutputExtension = nullptr);
2013-11-03 12:27:13 +02:00
/** Fill out the static linker flags for the given target. */
2016-07-09 11:21:54 +02:00
void GetStaticLibraryFlags(std::string& flags, std::string const& config,
2016-03-13 13:35:51 +01:00
cmGeneratorTarget* target);
2013-11-03 12:27:13 +02:00
/** Fill out these strings for the given target. Libraries to link,
* flags, and linkflags. */
2017-04-14 19:02:05 +02:00
void GetTargetFlags(cmLinkLineComputer* linkLineComputer,
const std::string& config, std::string& linkLibs,
2016-10-30 18:24:19 +01:00
std::string& flags, std::string& linkFlags,
std::string& frameworkPath, std::string& linkPath,
2017-04-14 19:02:05 +02:00
cmGeneratorTarget* target);
2016-10-30 18:24:19 +01:00
void GetTargetDefines(cmGeneratorTarget const* target,
std::string const& config, std::string const& lang,
std::set<std::string>& defines) const;
void GetTargetCompileFlags(cmGeneratorTarget* target,
std::string const& config,
std::string const& lang, std::string& flags);
std::string GetFrameworkFlags(std::string const& l,
std::string const& config,
cmGeneratorTarget* target);
virtual std::string GetTargetFortranFlags(cmGeneratorTarget const* target,
std::string const& config);
2015-04-27 22:25:09 +02:00
virtual void ComputeObjectFilenames(
2016-07-09 11:21:54 +02:00
std::map<cmSourceFile const*, std::string>& mapping,
2018-01-26 17:06:56 +01:00
cmGeneratorTarget const* gt = nullptr);
2012-02-18 12:40:36 +02:00
2015-08-17 11:37:30 +02:00
bool IsWindowsShell() const;
bool IsWatcomWMake() const;
bool IsMinGWMake() const;
bool IsNMake() const;
2015-11-17 17:22:37 +01:00
void IssueMessage(cmake::MessageType t, std::string const& text) const;
void CreateEvaluationFileOutputs(const std::string& config);
void ProcessEvaluationFiles(std::vector<std::string>& generatedFiles);
2015-08-17 11:37:30 +02:00
2016-03-13 13:35:51 +01:00
const char* GetRuleLauncher(cmGeneratorTarget* target,
const std::string& prop);
2017-04-14 19:02:05 +02:00
protected:
///! put all the libraries for a target on into the given stream
void OutputLinkLibraries(cmComputeLinkInformation* pcli,
cmLinkLineComputer* linkLineComputer,
std::string& linkLibraries,
std::string& frameworkPath, std::string& linkPath);
2009-10-04 10:30:41 +03:00
// Handle old-style install rules stored in the targets.
void GenerateTargetInstallRules(
2015-04-27 22:25:09 +02:00
std::ostream& os, const std::string& config,
std::vector<std::string> const& configurationTypes);
2015-04-27 22:25:09 +02:00
std::string& CreateSafeUniqueObjectFileName(const std::string& sin,
std::string const& dir_max);
/** Check whether the native build system supports the given
definition. Issues a warning. */
virtual bool CheckDefinition(std::string const& define) const;
2016-07-09 11:21:54 +02:00
cmMakefile* Makefile;
2017-04-14 19:02:05 +02:00
cmStateSnapshot StateSnapshot;
2016-10-30 18:24:19 +01:00
cmListFileBacktrace DirectoryBacktrace;
2016-07-09 11:21:54 +02:00
cmGlobalGenerator* GlobalGenerator;
2015-04-27 22:25:09 +02:00
std::map<std::string, std::string> UniqueObjectNamesMap;
std::string::size_type ObjectPathMax;
2015-04-27 22:25:09 +02:00
std::set<std::string> ObjectMaxPathViolations;
2015-08-17 11:37:30 +02:00
2018-01-26 17:06:56 +01:00
typedef std::unordered_map<std::string, cmGeneratorTarget*>
GeneratorTargetMap;
GeneratorTargetMap GeneratorTargetSearchIndex;
2016-03-13 13:35:51 +01:00
std::vector<cmGeneratorTarget*> GeneratorTargets;
2018-01-26 17:06:56 +01:00
std::set<cmGeneratorTarget const*> WarnCMP0063;
2018-04-23 21:13:27 +02:00
GeneratorTargetMap ImportedGeneratorTargets;
2016-03-13 13:35:51 +01:00
std::vector<cmGeneratorTarget*> OwnedImportedGeneratorTargets;
std::map<std::string, std::string> AliasTargets;
2015-08-17 11:37:30 +02:00
2017-04-14 19:02:05 +02:00
std::map<std::string, std::string> Compilers;
std::map<std::string, std::string> VariableMappings;
std::string CompilerSysroot;
2017-07-20 19:35:53 +02:00
std::string LinkerSysroot;
2015-08-17 11:37:30 +02:00
2017-04-14 19:02:05 +02:00
bool EmitUniversalBinaryFlags;
2016-03-13 13:35:51 +01:00
KWIML_INT_uint64_t BackwardsCompatibility;
bool BackwardsCompatibilityFinal;
2016-07-09 11:21:54 +02:00
private:
2015-04-27 22:25:09 +02:00
void AddSharedFlags(std::string& flags, const std::string& lang,
bool shared);
2016-07-09 11:21:54 +02:00
bool GetShouldUseOldFlags(bool shared, const std::string& lang) const;
2012-06-27 20:52:58 +03:00
void AddPositionIndependentFlags(std::string& flags, std::string const& l,
int targetType);
2015-11-17 17:22:37 +01:00
void ComputeObjectMaxPath();
2018-08-09 18:06:22 +02:00
void MoveSystemIncludesToEnd(std::vector<std::string>& includeDirs,
const std::string& config,
const std::string& lang,
cmGeneratorTarget const* target) const;
};
2016-07-09 11:21:54 +02:00
#if defined(CMAKE_BUILD_WITH_CMAKE)
bool cmLocalGeneratorCheckObjectName(std::string& objName,
std::string::size_type dir_len,
std::string::size_type max_total_len);
#endif
#endif