cmLocalGenerator.h 15 KB

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