cmLocalGenerator.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #ifndef cmLocalGenerator_h
  11. #define cmLocalGenerator_h
  12. #include "cmStandardIncludes.h"
  13. #include "cmState.h"
  14. #include "cmake.h"
  15. #include "cmOutputConverter.h"
  16. class cmMakefile;
  17. class cmGlobalGenerator;
  18. class cmGeneratorTarget;
  19. class cmTargetManifest;
  20. class cmSourceFile;
  21. class cmCustomCommand;
  22. class cmCustomCommandGenerator;
  23. /** \class cmLocalGenerator
  24. * \brief Create required build files for a directory.
  25. *
  26. * Subclasses of this abstract class generate makefiles, DSP, etc for various
  27. * platforms. This class should never be constructed directly. A
  28. * GlobalGenerator will create it and invoke the appropriate commands on it.
  29. */
  30. class cmLocalGenerator : public cmOutputConverter
  31. {
  32. public:
  33. cmLocalGenerator(cmGlobalGenerator* gg, cmMakefile* makefile);
  34. virtual ~cmLocalGenerator();
  35. /**
  36. * Generate the makefile for this directory.
  37. */
  38. virtual void Generate() {}
  39. virtual void ComputeHomeRelativeOutputPath() {}
  40. /**
  41. * Calls TraceVSDependencies() on all targets of this generator.
  42. */
  43. void TraceDependencies();
  44. virtual void AddHelperCommands() {}
  45. /**
  46. * Generate the install rules files in this directory.
  47. */
  48. void GenerateInstallRules();
  49. /**
  50. * Generate the test files for tests.
  51. */
  52. void GenerateTestFiles();
  53. /**
  54. * Generate a manifest of target files that will be built.
  55. */
  56. void ComputeTargetManifest();
  57. ///! Get the makefile for this generator
  58. cmMakefile *GetMakefile() {
  59. return this->Makefile; }
  60. ///! Get the makefile for this generator, const version
  61. const cmMakefile *GetMakefile() const {
  62. return this->Makefile; }
  63. ///! Get the GlobalGenerator this is associated with
  64. cmGlobalGenerator *GetGlobalGenerator() {
  65. return this->GlobalGenerator; }
  66. const cmGlobalGenerator *GetGlobalGenerator() const {
  67. return this->GlobalGenerator; }
  68. cmState* GetState() const;
  69. cmState::Snapshot GetStateSnapshot() const;
  70. void AddArchitectureFlags(std::string& flags,
  71. cmGeneratorTarget const* target,
  72. const std::string&lang, const std::string& config);
  73. void AddLanguageFlags(std::string& flags, const std::string& lang,
  74. const std::string& config);
  75. void AddCMP0018Flags(std::string &flags, cmGeneratorTarget const* target,
  76. std::string const& lang, const std::string& config);
  77. void AddVisibilityPresetFlags(std::string &flags,
  78. cmGeneratorTarget const* target,
  79. const std::string& lang);
  80. void AddConfigVariableFlags(std::string& flags, const std::string& var,
  81. const std::string& config);
  82. void AddCompilerRequirementFlag(std::string &flags,
  83. cmGeneratorTarget const* target,
  84. const std::string& lang);
  85. ///! Append flags to a string.
  86. virtual void AppendFlags(std::string& flags, const std::string& newFlags);
  87. virtual void AppendFlags(std::string& flags, const char* newFlags);
  88. virtual void AppendFlagEscape(std::string& flags,
  89. const std::string& rawFlag);
  90. ///! Get the include flags for the current makefile and language
  91. std::string GetIncludeFlags(const std::vector<std::string> &includes,
  92. cmGeneratorTarget* target,
  93. const std::string& lang,
  94. bool forceFullPaths = false,
  95. bool forResponseFile = false,
  96. const std::string& config = "");
  97. const std::vector<cmGeneratorTarget*> &GetGeneratorTargets() const
  98. {
  99. return this->GeneratorTargets;
  100. }
  101. void AddGeneratorTarget(cmGeneratorTarget* gt);
  102. cmGeneratorTarget* FindGeneratorTarget(const std::string& name) const;
  103. cmGeneratorTarget* FindGeneratorTargetToUse(const std::string& name) const;
  104. /**
  105. * Encode a list of preprocessor definitions for the compiler
  106. * command line.
  107. */
  108. void AppendDefines(std::set<std::string>& defines,
  109. const char* defines_list);
  110. void AppendDefines(std::set<std::string>& defines,
  111. std::string defines_list)
  112. {
  113. this->AppendDefines(defines, defines_list.c_str());
  114. }
  115. void AppendDefines(std::set<std::string>& defines,
  116. const std::vector<std::string> &defines_vec);
  117. /**
  118. * Join a set of defines into a definesString with a space separator.
  119. */
  120. void JoinDefines(const std::set<std::string>& defines,
  121. std::string &definesString,
  122. const std::string& lang);
  123. /** Lookup and append options associated with a particular feature. */
  124. void AppendFeatureOptions(std::string& flags, const std::string& lang,
  125. const char* feature);
  126. const char* GetFeature(const std::string& feature,
  127. const std::string& config);
  128. /** \brief Get absolute path to dependency \a name
  129. *
  130. * Translate a dependency as given in CMake code to the name to
  131. * appear in a generated build file.
  132. * - If \a name is a utility target, returns false.
  133. * - If \a name is a CMake target, it will be transformed to the real output
  134. * location of that target for the given configuration.
  135. * - If \a name is the full path to a file, it will be returned.
  136. * - Otherwise \a name is treated as a relative path with respect to
  137. * the source directory of this generator. This should only be
  138. * used for dependencies of custom commands.
  139. */
  140. bool GetRealDependency(const std::string& name, const std::string& config,
  141. std::string& dep);
  142. virtual std::string ConvertToIncludeReference(std::string const& path,
  143. OutputFormat format = SHELL,
  144. bool forceFullPaths = false);
  145. /** Called from command-line hook to clear dependencies. */
  146. virtual void ClearDependencies(cmMakefile* /* mf */,
  147. bool /* verbose */) {}
  148. /** Called from command-line hook to update dependencies. */
  149. virtual bool UpdateDependencies(const char* /* tgtInfo */,
  150. bool /*verbose*/,
  151. bool /*color*/)
  152. { return true; }
  153. /** Get the include flags for the current makefile and language. */
  154. void GetIncludeDirectories(std::vector<std::string>& dirs,
  155. cmGeneratorTarget const* target,
  156. const std::string& lang = "C",
  157. const std::string& config = "",
  158. bool stripImplicitInclDirs = true) const;
  159. void AddCompileOptions(std::string& flags, cmGeneratorTarget* target,
  160. const std::string& lang, const std::string& config);
  161. void AddCompileDefinitions(std::set<std::string>& defines,
  162. cmGeneratorTarget const* target,
  163. const std::string& config,
  164. const std::string& lang);
  165. std::string GetProjectName() const;
  166. /** Compute the language used to compile the given source file. */
  167. std::string GetSourceFileLanguage(const cmSourceFile& source);
  168. // Fill the vector with the target names for the object files,
  169. // preprocessed files and assembly files.
  170. void GetIndividualFileTargets(std::vector<std::string>&) {}
  171. // Create a struct to hold the varibles passed into
  172. // ExpandRuleVariables
  173. struct RuleVariables
  174. {
  175. RuleVariables()
  176. {
  177. memset(this, 0, sizeof(*this));
  178. }
  179. cmGeneratorTarget* CMTarget;
  180. const char* TargetPDB;
  181. const char* TargetCompilePDB;
  182. const char* TargetVersionMajor;
  183. const char* TargetVersionMinor;
  184. const char* Language;
  185. const char* Objects;
  186. const char* Target;
  187. const char* LinkLibraries;
  188. const char* Source;
  189. const char* AssemblySource;
  190. const char* PreprocessedSource;
  191. const char* Output;
  192. const char* Object;
  193. const char* ObjectDir;
  194. const char* ObjectFileDir;
  195. const char* Flags;
  196. const char* ObjectsQuoted;
  197. const char* SONameFlag;
  198. const char* TargetSOName;
  199. const char* TargetInstallNameDir;
  200. const char* LinkFlags;
  201. const char* Manifests;
  202. const char* LanguageCompileFlags;
  203. const char* Defines;
  204. const char* Includes;
  205. const char* RuleLauncher;
  206. const char* DependencyFile;
  207. const char* FilterPrefix;
  208. };
  209. /**
  210. * Get the relative path from the generator output directory to a
  211. * per-target support directory.
  212. */
  213. virtual std::string
  214. GetTargetDirectory(cmGeneratorTarget const* target) const;
  215. /**
  216. * Get the level of backwards compatibility requested by the project
  217. * in this directory. This is the value of the CMake variable
  218. * CMAKE_BACKWARDS_COMPATIBILITY whose format is
  219. * "major.minor[.patch]". The returned integer is encoded as
  220. *
  221. * CMake_VERSION_ENCODE(major, minor, patch)
  222. *
  223. * and is monotonically increasing with the CMake version.
  224. */
  225. cmIML_INT_uint64_t GetBackwardsCompatibility();
  226. /**
  227. * Test whether compatibility is set to a given version or lower.
  228. */
  229. bool NeedBackwardsCompatibility_2_4();
  230. cmPolicies::PolicyStatus GetPolicyStatus(cmPolicies::PolicyID id) const;
  231. cmake* GetCMakeInstance() const;
  232. const char* GetSourceDirectory() const;
  233. const char* GetBinaryDirectory() const;
  234. const char* GetCurrentBinaryDirectory() const;
  235. const char* GetCurrentSourceDirectory() const;
  236. /**
  237. * Generate a Mac OS X application bundle Info.plist file.
  238. */
  239. void GenerateAppleInfoPList(cmGeneratorTarget* target,
  240. const std::string& targetName,
  241. const char* fname);
  242. /**
  243. * Generate a Mac OS X framework Info.plist file.
  244. */
  245. void GenerateFrameworkInfoPList(cmGeneratorTarget* target,
  246. const std::string& targetName,
  247. const char* fname);
  248. /** Construct a comment for a custom command. */
  249. std::string ConstructComment(cmCustomCommandGenerator const& ccg,
  250. const char* default_comment = "");
  251. // Compute object file names.
  252. std::string GetObjectFileNameWithoutTarget(const cmSourceFile& source,
  253. std::string const& dir_max,
  254. bool* hasSourceExtension = 0);
  255. /** Fill out the static linker flags for the given target. */
  256. void GetStaticLibraryFlags(std::string& flags,
  257. std::string const& config,
  258. cmGeneratorTarget* target);
  259. /** Fill out these strings for the given target. Libraries to link,
  260. * flags, and linkflags. */
  261. void GetTargetFlags(std::string& linkLibs,
  262. std::string& flags,
  263. std::string& linkFlags,
  264. std::string& frameworkPath,
  265. std::string& linkPath,
  266. cmGeneratorTarget* target,
  267. bool useWatcomQuote);
  268. virtual void ComputeObjectFilenames(
  269. std::map<cmSourceFile const*, std::string>& mapping,
  270. cmGeneratorTarget const* gt = 0);
  271. bool IsWindowsShell() const;
  272. bool IsWatcomWMake() const;
  273. bool IsMinGWMake() const;
  274. bool IsNMake() const;
  275. void IssueMessage(cmake::MessageType t, std::string const& text) const;
  276. void CreateEvaluationFileOutputs(const std::string& config);
  277. void ProcessEvaluationFiles(std::vector<std::string>& generatedFiles);
  278. protected:
  279. ///! put all the libraries for a target on into the given stream
  280. void OutputLinkLibraries(std::string& linkLibraries,
  281. std::string& frameworkPath,
  282. std::string& linkPath,
  283. cmGeneratorTarget &,
  284. bool relink,
  285. bool forResponseFile,
  286. bool useWatcomQuote);
  287. // Expand rule variables in CMake of the type found in language rules
  288. void ExpandRuleVariables(std::string& string,
  289. const RuleVariables& replaceValues);
  290. // Expand rule variables in a single string
  291. std::string ExpandRuleVariable(std::string const& variable,
  292. const RuleVariables& replaceValues);
  293. const char* GetRuleLauncher(cmGeneratorTarget* target,
  294. const std::string& prop);
  295. void InsertRuleLauncher(std::string& s, cmGeneratorTarget* target,
  296. const std::string& prop);
  297. // Handle old-style install rules stored in the targets.
  298. void GenerateTargetInstallRules(
  299. std::ostream& os, const std::string& config,
  300. std::vector<std::string> const& configurationTypes);
  301. std::string& CreateSafeUniqueObjectFileName(const std::string& sin,
  302. std::string const& dir_max);
  303. virtual std::string ConvertToLinkReference(std::string const& lib,
  304. OutputFormat format = SHELL);
  305. /** Check whether the native build system supports the given
  306. definition. Issues a warning. */
  307. virtual bool CheckDefinition(std::string const& define) const;
  308. cmMakefile *Makefile;
  309. cmState::Snapshot StateSnapshot;
  310. cmGlobalGenerator *GlobalGenerator;
  311. std::map<std::string, std::string> UniqueObjectNamesMap;
  312. std::string::size_type ObjectPathMax;
  313. std::set<std::string> ObjectMaxPathViolations;
  314. std::set<cmGeneratorTarget const*> WarnCMP0063;
  315. std::vector<cmGeneratorTarget*> GeneratorTargets;
  316. bool EmitUniversalBinaryFlags;
  317. // Hack for ExpandRuleVariable until object-oriented version is
  318. // committed.
  319. std::string TargetImplib;
  320. cmIML_INT_uint64_t BackwardsCompatibility;
  321. bool BackwardsCompatibilityFinal;
  322. private:
  323. void AddSharedFlags(std::string& flags, const std::string& lang,
  324. bool shared);
  325. bool GetShouldUseOldFlags(bool shared, const std::string &lang) const;
  326. void AddPositionIndependentFlags(std::string& flags, std::string const& l,
  327. int targetType);
  328. void ComputeObjectMaxPath();
  329. };
  330. #endif