cmLocalGenerator.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  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 cmTarget;
  20. class cmTargetManifest;
  21. class cmSourceFile;
  22. class cmCustomCommand;
  23. class cmCustomCommandGenerator;
  24. /** \class cmLocalGenerator
  25. * \brief Create required build files for a directory.
  26. *
  27. * Subclasses of this abstract class generate makefiles, DSP, etc for various
  28. * platforms. This class should never be constructed directly. A
  29. * GlobalGenerator will create it and invoke the appropriate commands on it.
  30. */
  31. class cmLocalGenerator : public cmOutputConverter
  32. {
  33. public:
  34. cmLocalGenerator(cmGlobalGenerator* gg, cmMakefile* makefile);
  35. virtual ~cmLocalGenerator();
  36. /**
  37. * Generate the makefile for this directory.
  38. */
  39. virtual void Generate() {}
  40. virtual void ComputeHomeRelativeOutputPath() {}
  41. /**
  42. * Calls TraceVSDependencies() on all targets of this generator.
  43. */
  44. void TraceDependencies();
  45. virtual void AddHelperCommands() {}
  46. /**
  47. * Generate the install rules files in this directory.
  48. */
  49. void GenerateInstallRules();
  50. /**
  51. * Generate the test files for tests.
  52. */
  53. void GenerateTestFiles();
  54. /**
  55. * Generate a manifest of target files that will be built.
  56. */
  57. void ComputeTargetManifest();
  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, cmTarget const* target,
  77. std::string const& lang, const std::string& config);
  78. void AddVisibilityPresetFlags(std::string &flags, cmTarget 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, cmTarget const* target,
  83. const std::string& lang);
  84. ///! Append flags to a string.
  85. virtual void AppendFlags(std::string& flags, const std::string& newFlags);
  86. virtual void AppendFlags(std::string& flags, const char* newFlags);
  87. virtual void AppendFlagEscape(std::string& flags,
  88. const std::string& rawFlag);
  89. ///! Get the include flags for the current makefile and language
  90. std::string GetIncludeFlags(const std::vector<std::string> &includes,
  91. cmGeneratorTarget* target,
  92. const std::string& lang,
  93. bool forceFullPaths = false,
  94. bool forResponseFile = false,
  95. const std::string& config = "");
  96. const cmGeneratorTargetsType &GetGeneratorTargets() const
  97. {
  98. return this->GeneratorTargets;
  99. }
  100. void SetGeneratorTargets(const cmGeneratorTargetsType &targets)
  101. {
  102. this->GeneratorTargets = targets;
  103. }
  104. void AddGeneratorTarget(cmTarget* t, cmGeneratorTarget* gt);
  105. cmGeneratorTarget* FindGeneratorTargetToUse(const std::string& name) const;
  106. /**
  107. * Encode a list of preprocessor definitions for the compiler
  108. * command line.
  109. */
  110. void AppendDefines(std::set<std::string>& defines,
  111. const char* defines_list);
  112. void AppendDefines(std::set<std::string>& defines,
  113. std::string defines_list)
  114. {
  115. this->AppendDefines(defines, defines_list.c_str());
  116. }
  117. void AppendDefines(std::set<std::string>& defines,
  118. const std::vector<std::string> &defines_vec);
  119. /**
  120. * Join a set of defines into a definesString with a space separator.
  121. */
  122. void JoinDefines(const std::set<std::string>& defines,
  123. std::string &definesString,
  124. const std::string& lang);
  125. /** Lookup and append options associated with a particular feature. */
  126. void AppendFeatureOptions(std::string& flags, const std::string& lang,
  127. const char* feature);
  128. const char* GetFeature(const std::string& feature,
  129. const std::string& config);
  130. /** \brief Get absolute path to dependency \a name
  131. *
  132. * Translate a dependency as given in CMake code to the name to
  133. * appear in a generated build file.
  134. * - If \a name is a utility target, returns false.
  135. * - If \a name is a CMake target, it will be transformed to the real output
  136. * location of that target for the given configuration.
  137. * - If \a name is the full path to a file, it will be returned.
  138. * - Otherwise \a name is treated as a relative path with respect to
  139. * the source directory of this generator. This should only be
  140. * used for dependencies of custom commands.
  141. */
  142. bool GetRealDependency(const std::string& name, const std::string& config,
  143. std::string& dep);
  144. virtual std::string ConvertToIncludeReference(std::string const& path,
  145. OutputFormat format = SHELL,
  146. bool forceFullPaths = false);
  147. /** Called from command-line hook to clear dependencies. */
  148. virtual void ClearDependencies(cmMakefile* /* mf */,
  149. bool /* verbose */) {}
  150. /** Called from command-line hook to update dependencies. */
  151. virtual bool UpdateDependencies(const char* /* tgtInfo */,
  152. bool /*verbose*/,
  153. bool /*color*/)
  154. { return true; }
  155. /** Get the include flags for the current makefile and language. */
  156. void GetIncludeDirectories(std::vector<std::string>& dirs,
  157. cmGeneratorTarget const* target,
  158. const std::string& lang = "C",
  159. const std::string& config = "",
  160. bool stripImplicitInclDirs = true) const;
  161. void AddCompileOptions(std::string& flags, cmTarget* target,
  162. const std::string& lang, const std::string& config);
  163. void AddCompileDefinitions(std::set<std::string>& defines,
  164. cmTarget const* target,
  165. const std::string& config,
  166. const std::string& lang);
  167. std::string GetProjectName() const;
  168. /** Compute the language used to compile the given source file. */
  169. std::string GetSourceFileLanguage(const cmSourceFile& source);
  170. // Fill the vector with the target names for the object files,
  171. // preprocessed files and assembly files.
  172. void GetIndividualFileTargets(std::vector<std::string>&) {}
  173. // Create a struct to hold the varibles passed into
  174. // ExpandRuleVariables
  175. struct RuleVariables
  176. {
  177. RuleVariables()
  178. {
  179. memset(this, 0, sizeof(*this));
  180. }
  181. cmTarget* CMTarget;
  182. const char* TargetPDB;
  183. const char* TargetCompilePDB;
  184. const char* TargetVersionMajor;
  185. const char* TargetVersionMinor;
  186. const char* Language;
  187. const char* Objects;
  188. const char* Target;
  189. const char* LinkLibraries;
  190. const char* Source;
  191. const char* AssemblySource;
  192. const char* PreprocessedSource;
  193. const char* Output;
  194. const char* Object;
  195. const char* ObjectDir;
  196. const char* ObjectFileDir;
  197. const char* Flags;
  198. const char* ObjectsQuoted;
  199. const char* SONameFlag;
  200. const char* TargetSOName;
  201. const char* TargetInstallNameDir;
  202. const char* LinkFlags;
  203. const char* Manifests;
  204. const char* LanguageCompileFlags;
  205. const char* Defines;
  206. const char* Includes;
  207. const char* RuleLauncher;
  208. const char* DependencyFile;
  209. const char* FilterPrefix;
  210. };
  211. /**
  212. * Get the relative path from the generator output directory to a
  213. * per-target support directory.
  214. */
  215. virtual std::string GetTargetDirectory(cmTarget 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. 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(cmTarget* target, const std::string& targetName,
  240. const char* fname);
  241. /**
  242. * Generate a Mac OS X framework Info.plist file.
  243. */
  244. void GenerateFrameworkInfoPList(cmTarget* target,
  245. const std::string& targetName,
  246. const char* fname);
  247. /** Construct a comment for a custom command. */
  248. std::string ConstructComment(cmCustomCommandGenerator const& ccg,
  249. const char* default_comment = "");
  250. // Compute object file names.
  251. std::string GetObjectFileNameWithoutTarget(const cmSourceFile& source,
  252. std::string const& dir_max,
  253. bool* hasSourceExtension = 0);
  254. /** Fill out the static linker flags for the given target. */
  255. void GetStaticLibraryFlags(std::string& flags,
  256. std::string const& config,
  257. cmTarget* target);
  258. /** Fill out these strings for the given target. Libraries to link,
  259. * flags, and linkflags. */
  260. void GetTargetFlags(std::string& linkLibs,
  261. std::string& flags,
  262. std::string& linkFlags,
  263. std::string& frameworkPath,
  264. std::string& linkPath,
  265. cmGeneratorTarget* target,
  266. bool useWatcomQuote);
  267. virtual void ComputeObjectFilenames(
  268. std::map<cmSourceFile const*, std::string>& mapping,
  269. cmGeneratorTarget const* gt = 0);
  270. bool IsWindowsShell() const;
  271. bool IsWatcomWMake() const;
  272. bool IsMinGWMake() const;
  273. bool IsNMake() const;
  274. void IssueMessage(cmake::MessageType t, std::string const& text) const;
  275. void CreateEvaluationFileOutputs(const std::string& config);
  276. void ProcessEvaluationFiles(std::vector<std::string>& generatedFiles);
  277. protected:
  278. ///! put all the libraries for a target on into the given stream
  279. void OutputLinkLibraries(std::string& linkLibraries,
  280. std::string& frameworkPath,
  281. std::string& linkPath,
  282. cmGeneratorTarget &,
  283. bool relink,
  284. bool forResponseFile,
  285. bool useWatcomQuote);
  286. // Expand rule variables in CMake of the type found in language rules
  287. void ExpandRuleVariables(std::string& string,
  288. const RuleVariables& replaceValues);
  289. // Expand rule variables in a single string
  290. std::string ExpandRuleVariable(std::string const& variable,
  291. const RuleVariables& replaceValues);
  292. const char* GetRuleLauncher(cmTarget* target, const std::string& prop);
  293. void InsertRuleLauncher(std::string& s, cmTarget* target,
  294. const std::string& prop);
  295. // Handle old-style install rules stored in the targets.
  296. void GenerateTargetInstallRules(
  297. std::ostream& os, const std::string& config,
  298. std::vector<std::string> const& configurationTypes);
  299. std::string& CreateSafeUniqueObjectFileName(const std::string& sin,
  300. std::string const& dir_max);
  301. virtual std::string ConvertToLinkReference(std::string const& lib,
  302. OutputFormat format = SHELL);
  303. /** Check whether the native build system supports the given
  304. definition. Issues a warning. */
  305. virtual bool CheckDefinition(std::string const& define) const;
  306. cmMakefile *Makefile;
  307. cmState::Snapshot StateSnapshot;
  308. cmGlobalGenerator *GlobalGenerator;
  309. std::map<std::string, std::string> UniqueObjectNamesMap;
  310. std::string::size_type ObjectPathMax;
  311. std::set<std::string> ObjectMaxPathViolations;
  312. std::set<cmTarget const*> WarnCMP0063;
  313. cmGeneratorTargetsType GeneratorTargets;
  314. bool EmitUniversalBinaryFlags;
  315. // Hack for ExpandRuleVariable until object-oriented version is
  316. // committed.
  317. std::string TargetImplib;
  318. cmIML_INT_uint64_t BackwardsCompatibility;
  319. bool BackwardsCompatibilityFinal;
  320. private:
  321. void AddSharedFlags(std::string& flags, const std::string& lang,
  322. bool shared);
  323. bool GetShouldUseOldFlags(bool shared, const std::string &lang) const;
  324. void AddPositionIndependentFlags(std::string& flags, std::string const& l,
  325. int targetType);
  326. void ComputeObjectMaxPath();
  327. };
  328. #endif