cmLocalGenerator.h 14 KB

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