cmLocalGenerator.h 15 KB

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