cmLocalGenerator.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  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 "cmOutputConverter.h"
  14. #include "cmState.h"
  15. #include "cmake.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() { return this->Makefile; }
  60. ///! Get the makefile for this generator, const version
  61. const cmMakefile* GetMakefile() const { return this->Makefile; }
  62. ///! Get the GlobalGenerator this is associated with
  63. cmGlobalGenerator* GetGlobalGenerator() { return this->GlobalGenerator; }
  64. const cmGlobalGenerator* GetGlobalGenerator() const
  65. {
  66. return this->GlobalGenerator;
  67. }
  68. cmState* GetState() const;
  69. cmState::Snapshot GetStateSnapshot() const;
  70. void AddArchitectureFlags(std::string& flags,
  71. cmGeneratorTarget const* target,
  72. const std::string& lang,
  73. 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* FindLocalNonAliasGeneratorTarget(
  110. 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) const;
  118. void AppendDefines(std::set<std::string>& defines,
  119. std::string defines_list) const
  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) const;
  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, const std::string& lang);
  130. /** Lookup and append options associated with a particular feature. */
  131. void AppendFeatureOptions(std::string& flags, const std::string& lang,
  132. const char* feature);
  133. const char* GetFeature(const std::string& feature,
  134. const std::string& config);
  135. /** \brief Get absolute path to dependency \a name
  136. *
  137. * Translate a dependency as given in CMake code to the name to
  138. * appear in a generated build file.
  139. * - If \a name is a utility target, returns false.
  140. * - If \a name is a CMake target, it will be transformed to the real output
  141. * location of that target for the given configuration.
  142. * - If \a name is the full path to a file, it will be returned.
  143. * - Otherwise \a name is treated as a relative path with respect to
  144. * the source directory of this generator. This should only be
  145. * used for dependencies of custom commands.
  146. */
  147. bool GetRealDependency(const std::string& name, const std::string& config,
  148. std::string& dep);
  149. virtual std::string ConvertToIncludeReference(
  150. std::string const& path,
  151. cmOutputConverter::OutputFormat format = cmOutputConverter::SHELL,
  152. bool forceFullPaths = false);
  153. /** Called from command-line hook to clear dependencies. */
  154. virtual void ClearDependencies(cmMakefile* /* mf */, bool /* verbose */) {}
  155. /** Called from command-line hook to update dependencies. */
  156. virtual bool UpdateDependencies(const char* /* tgtInfo */, bool /*verbose*/,
  157. bool /*color*/)
  158. {
  159. return true;
  160. }
  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) const;
  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() { memset(this, 0, sizeof(*this)); }
  184. cmGeneratorTarget* CMTarget;
  185. const char* TargetPDB;
  186. const char* TargetCompilePDB;
  187. const char* TargetVersionMajor;
  188. const char* TargetVersionMinor;
  189. const char* Language;
  190. const char* Objects;
  191. const char* Target;
  192. const char* LinkLibraries;
  193. const char* Source;
  194. const char* AssemblySource;
  195. const char* PreprocessedSource;
  196. const char* Output;
  197. const char* Object;
  198. const char* ObjectDir;
  199. const char* ObjectFileDir;
  200. const char* Flags;
  201. const char* ObjectsQuoted;
  202. const char* SONameFlag;
  203. const char* TargetSOName;
  204. const char* TargetInstallNameDir;
  205. const char* LinkFlags;
  206. const char* Manifests;
  207. const char* LanguageCompileFlags;
  208. const char* Defines;
  209. const char* Includes;
  210. const char* RuleLauncher;
  211. const char* DependencyFile;
  212. const char* FilterPrefix;
  213. };
  214. /**
  215. * Get the relative path from the generator output directory to a
  216. * per-target support directory.
  217. */
  218. virtual std::string GetTargetDirectory(
  219. cmGeneratorTarget const* target) const;
  220. /**
  221. * Get the level of backwards compatibility requested by the project
  222. * in this directory. This is the value of the CMake variable
  223. * CMAKE_BACKWARDS_COMPATIBILITY whose format is
  224. * "major.minor[.patch]". The returned integer is encoded as
  225. *
  226. * CMake_VERSION_ENCODE(major, minor, patch)
  227. *
  228. * and is monotonically increasing with the CMake version.
  229. */
  230. KWIML_INT_uint64_t GetBackwardsCompatibility();
  231. /**
  232. * Test whether compatibility is set to a given version or lower.
  233. */
  234. bool NeedBackwardsCompatibility_2_4();
  235. cmPolicies::PolicyStatus GetPolicyStatus(cmPolicies::PolicyID id) const;
  236. cmake* GetCMakeInstance() const;
  237. const char* GetSourceDirectory() const;
  238. const char* GetBinaryDirectory() const;
  239. const char* GetCurrentBinaryDirectory() const;
  240. const char* GetCurrentSourceDirectory() const;
  241. /**
  242. * Generate a Mac OS X application bundle Info.plist file.
  243. */
  244. void GenerateAppleInfoPList(cmGeneratorTarget* target,
  245. const std::string& targetName,
  246. const char* fname);
  247. /**
  248. * Generate a Mac OS X framework Info.plist file.
  249. */
  250. void GenerateFrameworkInfoPList(cmGeneratorTarget* target,
  251. const std::string& targetName,
  252. const char* fname);
  253. /** Construct a comment for a custom command. */
  254. std::string ConstructComment(cmCustomCommandGenerator const& ccg,
  255. const char* default_comment = "");
  256. // Compute object file names.
  257. std::string GetObjectFileNameWithoutTarget(const cmSourceFile& source,
  258. std::string const& dir_max,
  259. bool* hasSourceExtension = 0);
  260. /** Fill out the static linker flags for the given target. */
  261. void GetStaticLibraryFlags(std::string& flags, std::string const& config,
  262. cmGeneratorTarget* target);
  263. /** Fill out these strings for the given target. Libraries to link,
  264. * flags, and linkflags. */
  265. void GetTargetFlags(const std::string& config, std::string& linkLibs,
  266. std::string& flags, std::string& linkFlags,
  267. std::string& frameworkPath, std::string& linkPath,
  268. cmGeneratorTarget* target, bool useWatcomQuote);
  269. void GetTargetDefines(cmGeneratorTarget const* target,
  270. std::string const& config, std::string const& lang,
  271. std::set<std::string>& defines) const;
  272. std::string GetFrameworkFlags(std::string const& l,
  273. std::string const& config,
  274. cmGeneratorTarget* target);
  275. virtual void ComputeObjectFilenames(
  276. std::map<cmSourceFile const*, std::string>& mapping,
  277. cmGeneratorTarget const* gt = 0);
  278. bool IsWindowsShell() const;
  279. bool IsWatcomWMake() const;
  280. bool IsMinGWMake() const;
  281. bool IsNMake() const;
  282. void IssueMessage(cmake::MessageType t, std::string const& text) const;
  283. void CreateEvaluationFileOutputs(const std::string& config);
  284. void ProcessEvaluationFiles(std::vector<std::string>& generatedFiles);
  285. protected:
  286. ///! put all the libraries for a target on into the given stream
  287. void OutputLinkLibraries(std::string& linkLibraries,
  288. std::string& frameworkPath, std::string& linkPath,
  289. cmGeneratorTarget&, bool relink,
  290. bool forResponseFile, bool useWatcomQuote);
  291. // Expand rule variables in CMake of the type found in language rules
  292. void ExpandRuleVariables(std::string& string,
  293. const RuleVariables& replaceValues);
  294. // Expand rule variables in a single string
  295. std::string ExpandRuleVariable(std::string const& variable,
  296. const RuleVariables& replaceValues);
  297. const char* GetRuleLauncher(cmGeneratorTarget* target,
  298. const std::string& prop);
  299. void InsertRuleLauncher(std::string& s, cmGeneratorTarget* target,
  300. const std::string& prop);
  301. // Handle old-style install rules stored in the targets.
  302. void GenerateTargetInstallRules(
  303. std::ostream& os, const std::string& config,
  304. std::vector<std::string> const& configurationTypes);
  305. std::string& CreateSafeUniqueObjectFileName(const std::string& sin,
  306. std::string const& dir_max);
  307. virtual std::string ConvertToLinkReference(
  308. std::string const& lib,
  309. cmOutputConverter::OutputFormat format = cmOutputConverter::SHELL);
  310. /** Check whether the native build system supports the given
  311. definition. Issues a warning. */
  312. virtual bool CheckDefinition(std::string const& define) const;
  313. cmMakefile* Makefile;
  314. cmState::Snapshot StateSnapshot;
  315. cmGlobalGenerator* GlobalGenerator;
  316. std::map<std::string, std::string> UniqueObjectNamesMap;
  317. std::string::size_type ObjectPathMax;
  318. std::set<std::string> ObjectMaxPathViolations;
  319. std::set<cmGeneratorTarget const*> WarnCMP0063;
  320. std::vector<cmGeneratorTarget*> GeneratorTargets;
  321. std::vector<cmGeneratorTarget*> ImportedGeneratorTargets;
  322. std::vector<cmGeneratorTarget*> OwnedImportedGeneratorTargets;
  323. std::map<std::string, std::string> AliasTargets;
  324. bool EmitUniversalBinaryFlags;
  325. // Hack for ExpandRuleVariable until object-oriented version is
  326. // committed.
  327. std::string TargetImplib;
  328. KWIML_INT_uint64_t BackwardsCompatibility;
  329. bool BackwardsCompatibilityFinal;
  330. private:
  331. void AddSharedFlags(std::string& flags, const std::string& lang,
  332. bool shared);
  333. bool GetShouldUseOldFlags(bool shared, const std::string& lang) const;
  334. void AddPositionIndependentFlags(std::string& flags, std::string const& l,
  335. int targetType);
  336. void ComputeObjectMaxPath();
  337. };
  338. #if defined(CMAKE_BUILD_WITH_CMAKE)
  339. bool cmLocalGeneratorCheckObjectName(std::string& objName,
  340. std::string::size_type dir_len,
  341. std::string::size_type max_total_len);
  342. #endif
  343. #endif