cmMakefile.h 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164
  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 cmMakefile_h
  11. #define cmMakefile_h
  12. #include "cmExecutionStatus.h"
  13. #include "cmListFileCache.h"
  14. #include "cmPolicies.h"
  15. #include "cmPropertyMap.h"
  16. #include "cmSystemTools.h"
  17. #include "cmTarget.h"
  18. #include "cmNewLineStyle.h"
  19. #include "cmGeneratorTarget.h"
  20. #include "cmExpandedCommandArgument.h"
  21. #include "cmake.h"
  22. #include "cmState.h"
  23. #if defined(CMAKE_BUILD_WITH_CMAKE)
  24. #include "cmSourceGroup.h"
  25. #endif
  26. #include <cmsys/auto_ptr.hxx>
  27. #include <cmsys/RegularExpression.hxx>
  28. #if defined(CMAKE_BUILD_WITH_CMAKE)
  29. # include <cmsys/hash_map.hxx>
  30. #endif
  31. #include <stack>
  32. #include <deque>
  33. class cmFunctionBlocker;
  34. class cmCommand;
  35. class cmInstallGenerator;
  36. class cmLocalGenerator;
  37. class cmMakeDepend;
  38. class cmSourceFile;
  39. class cmTest;
  40. class cmTestGenerator;
  41. class cmVariableWatch;
  42. class cmake;
  43. class cmMakefileCall;
  44. class cmCMakePolicyCommand;
  45. /** \class cmMakefile
  46. * \brief Process the input CMakeLists.txt file.
  47. *
  48. * Process and store into memory the input CMakeLists.txt file.
  49. * Each CMakeLists.txt file is parsed and the commands found there
  50. * are added into the build process.
  51. */
  52. class cmMakefile
  53. {
  54. class Internals;
  55. cmsys::auto_ptr<Internals> Internal;
  56. public:
  57. /* Check for unused variables in this scope */
  58. void CheckForUnusedVariables() const;
  59. /* Mark a variable as used */
  60. void MarkVariableAsUsed(const std::string& var);
  61. /* return true if a variable has been initialized */
  62. bool VariableInitialized(const std::string& ) const;
  63. /* return true if a variable has been used */
  64. bool VariableUsed(const std::string& ) const;
  65. /**
  66. * Construct an empty makefile.
  67. */
  68. cmMakefile();
  69. cmMakefile(const cmMakefile& mf);
  70. /**
  71. * Destructor.
  72. */
  73. ~cmMakefile();
  74. /**
  75. * Read and parse a CMakeLists.txt file.
  76. */
  77. bool ReadListFile(const char* listfile,
  78. bool noPolicyScope = true,
  79. bool requireProjectCommand = false);
  80. bool ReadDependentFile(const char* listfile, bool noPolicyScope = true);
  81. bool ProcessBuildsystemFile(const char* listfile);
  82. /**
  83. * Add a function blocker to this makefile
  84. */
  85. void AddFunctionBlocker(cmFunctionBlocker* fb);
  86. /**
  87. * Remove the function blocker whose scope ends with the given command.
  88. * This returns ownership of the function blocker object.
  89. */
  90. cmsys::auto_ptr<cmFunctionBlocker>
  91. RemoveFunctionBlocker(cmFunctionBlocker* fb, const cmListFileFunction& lff);
  92. /** Push/pop a lexical (function blocker) barrier automatically. */
  93. class LexicalPushPop
  94. {
  95. public:
  96. LexicalPushPop(cmMakefile* mf);
  97. ~LexicalPushPop();
  98. void Quiet() { this->ReportError = false; }
  99. private:
  100. cmMakefile* Makefile;
  101. bool ReportError;
  102. };
  103. friend class LexicalPushPop;
  104. class LoopBlockPop
  105. {
  106. public:
  107. LoopBlockPop(cmMakefile* mf) { this->Makefile = mf; }
  108. ~LoopBlockPop() { this->Makefile->PopLoopBlock(); }
  109. private:
  110. cmMakefile* Makefile;
  111. };
  112. /**
  113. * Try running cmake and building a file. This is used for dynalically
  114. * loaded commands, not as part of the usual build process.
  115. */
  116. int TryCompile(const std::string& srcdir, const std::string& bindir,
  117. const std::string& projectName, const std::string& targetName,
  118. bool fast,
  119. const std::vector<std::string> *cmakeArgs,
  120. std::string& output);
  121. bool GetIsSourceFileTryCompile() const;
  122. /**
  123. * Specify the makefile generator. This is platform/compiler
  124. * dependent, although the interface is through a generic
  125. * superclass.
  126. */
  127. void SetLocalGenerator(cmLocalGenerator*);
  128. ///! Get the current makefile generator.
  129. cmLocalGenerator* GetLocalGenerator() const
  130. { return this->LocalGenerator;}
  131. /**
  132. * Help enforce global target name uniqueness.
  133. */
  134. bool EnforceUniqueName(std::string const& name, std::string& msg,
  135. bool isCustom = false) const;
  136. /**
  137. * Perform FinalPass, Library dependency analysis etc before output of the
  138. * makefile.
  139. */
  140. void ConfigureFinalPass();
  141. /**
  142. * run the final pass on all commands.
  143. */
  144. void FinalPass();
  145. /**
  146. * Print the object state to std::cout.
  147. */
  148. void Print() const;
  149. /** Add a custom command to the build. */
  150. void AddCustomCommandToTarget(const std::string& target,
  151. const std::vector<std::string>& byproducts,
  152. const std::vector<std::string>& depends,
  153. const cmCustomCommandLines& commandLines,
  154. cmTarget::CustomCommandType type,
  155. const char* comment, const char* workingDir,
  156. bool escapeOldStyle = true,
  157. bool uses_terminal = false);
  158. cmSourceFile* AddCustomCommandToOutput(
  159. const std::vector<std::string>& outputs,
  160. const std::vector<std::string>& byproducts,
  161. const std::vector<std::string>& depends,
  162. const std::string& main_dependency,
  163. const cmCustomCommandLines& commandLines,
  164. const char* comment, const char* workingDir,
  165. bool replace = false,
  166. bool escapeOldStyle = true,
  167. bool uses_terminal = false);
  168. cmSourceFile* AddCustomCommandToOutput(
  169. const std::string& output,
  170. const std::vector<std::string>& depends,
  171. const std::string& main_dependency,
  172. const cmCustomCommandLines& commandLines,
  173. const char* comment, const char* workingDir,
  174. bool replace = false,
  175. bool escapeOldStyle = true,
  176. bool uses_terminal = false);
  177. void AddCustomCommandOldStyle(const std::string& target,
  178. const std::vector<std::string>& outputs,
  179. const std::vector<std::string>& depends,
  180. const std::string& source,
  181. const cmCustomCommandLines& commandLines,
  182. const char* comment);
  183. /**
  184. * Add a define flag to the build.
  185. */
  186. void AddDefineFlag(const char* definition);
  187. void RemoveDefineFlag(const char* definition);
  188. void AddCompileOption(const char* option);
  189. /** Create a new imported target with the name and type given. */
  190. cmTarget* AddImportedTarget(const std::string& name,
  191. cmTarget::TargetType type,
  192. bool global);
  193. cmTarget* AddNewTarget(cmTarget::TargetType type, const std::string& name);
  194. /**
  195. * Add an executable to the build.
  196. */
  197. cmTarget* AddExecutable(const char *exename,
  198. const std::vector<std::string> &srcs,
  199. bool excludeFromAll = false);
  200. /**
  201. * Add a utility to the build. A utiltity target is a command that
  202. * is run every time the target is built.
  203. */
  204. void AddUtilityCommand(const std::string& utilityName, bool excludeFromAll,
  205. const std::vector<std::string>& depends,
  206. const char* workingDirectory,
  207. const char* command,
  208. const char* arg1=0,
  209. const char* arg2=0,
  210. const char* arg3=0,
  211. const char* arg4=0);
  212. cmTarget* AddUtilityCommand(const std::string& utilityName,
  213. bool excludeFromAll,
  214. const char* workingDirectory,
  215. const std::vector<std::string>& depends,
  216. const cmCustomCommandLines& commandLines,
  217. bool escapeOldStyle = true,
  218. const char* comment = 0,
  219. bool uses_terminal = false);
  220. cmTarget* AddUtilityCommand(const std::string& utilityName,
  221. bool excludeFromAll,
  222. const char* workingDirectory,
  223. const std::vector<std::string>& byproducts,
  224. const std::vector<std::string>& depends,
  225. const cmCustomCommandLines& commandLines,
  226. bool escapeOldStyle = true,
  227. const char* comment = 0,
  228. bool uses_terminal = false);
  229. /**
  230. * Add a link library to the build.
  231. */
  232. void AddLinkLibrary(const std::string&);
  233. void AddLinkLibrary(const std::string&, cmTarget::LinkLibraryType type);
  234. void AddLinkLibraryForTarget(const std::string& tgt, const std::string&,
  235. cmTarget::LinkLibraryType type);
  236. void AddLinkDirectoryForTarget(const std::string& tgt, const std::string& d);
  237. /**
  238. * Add a link directory to the build.
  239. */
  240. void AddLinkDirectory(const std::string&);
  241. const std::vector<std::string>& GetLinkDirectories() const
  242. {
  243. return this->LinkDirectories;
  244. }
  245. void SetLinkDirectories(const std::vector<std::string>& vec)
  246. {
  247. this->LinkDirectories = vec;
  248. }
  249. /**
  250. * Add a subdirectory to the build.
  251. */
  252. void AddSubDirectory(const std::string& fullSrcDir,
  253. const std::string& fullBinDir,
  254. bool excludeFromAll,
  255. bool immediate);
  256. /**
  257. * Configure a subdirectory
  258. */
  259. void ConfigureSubDirectory(cmLocalGenerator *);
  260. /**
  261. * Add an include directory to the build.
  262. */
  263. void AddIncludeDirectories(const std::vector<std::string> &incs,
  264. bool before = false);
  265. /**
  266. * Add a variable definition to the build. This variable
  267. * can be used in CMake to refer to lists, directories, etc.
  268. */
  269. void AddDefinition(const std::string& name, const char* value);
  270. ///! Add a definition to this makefile and the global cmake cache.
  271. void AddCacheDefinition(const std::string& name, const char* value,
  272. const char* doc,
  273. cmState::CacheEntryType type,
  274. bool force = false);
  275. /**
  276. * Add bool variable definition to the build.
  277. */
  278. void AddDefinition(const std::string& name, bool);
  279. /**
  280. * Remove a variable definition from the build. This is not valid
  281. * for cache entries, and will only affect the current makefile.
  282. */
  283. void RemoveDefinition(const std::string& name);
  284. ///! Remove a definition from the cache.
  285. void RemoveCacheDefinition(const std::string& name);
  286. /**
  287. * Specify the name of the project for this build.
  288. */
  289. void SetProjectName(const char*);
  290. /**
  291. * Get the name of the project for this build.
  292. */
  293. const char* GetProjectName() const
  294. {
  295. return this->ProjectName.c_str();
  296. }
  297. /** Get the configurations to be generated. */
  298. std::string GetConfigurations(std::vector<std::string>& configs,
  299. bool single = true) const;
  300. /**
  301. * Set the name of the library.
  302. */
  303. cmTarget* AddLibrary(const std::string& libname, cmTarget::TargetType type,
  304. const std::vector<std::string> &srcs,
  305. bool excludeFromAll = false);
  306. void AddAlias(const std::string& libname, cmTarget *tgt);
  307. #if defined(CMAKE_BUILD_WITH_CMAKE)
  308. /**
  309. * Add a root source group for consideration when adding a new source.
  310. */
  311. void AddSourceGroup(const std::string& name, const char* regex=0);
  312. /**
  313. * Add a source group for consideration when adding a new source.
  314. * name is tokenized.
  315. */
  316. void AddSourceGroup(const std::vector<std::string>& name,
  317. const char* regex=0);
  318. #endif
  319. //@{
  320. /**
  321. * Set, Push, Pop policy values for CMake.
  322. */
  323. bool SetPolicy(cmPolicies::PolicyID id, cmPolicies::PolicyStatus status);
  324. bool SetPolicy(const char *id, cmPolicies::PolicyStatus status);
  325. cmPolicies::PolicyStatus GetPolicyStatus(cmPolicies::PolicyID id) const;
  326. bool SetPolicyVersion(const char *version);
  327. void RecordPolicies(cmPolicies::PolicyMap& pm);
  328. //@}
  329. /** Helper class to push and pop policies automatically. */
  330. class PolicyPushPop
  331. {
  332. public:
  333. PolicyPushPop(cmMakefile* m,
  334. bool weak = false,
  335. cmPolicies::PolicyMap const& pm = cmPolicies::PolicyMap());
  336. ~PolicyPushPop();
  337. void Quiet() { this->ReportError = false; }
  338. private:
  339. cmMakefile* Makefile;
  340. bool ReportError;
  341. };
  342. friend class PolicyPushPop;
  343. /**
  344. * Get the Policies Instance
  345. */
  346. cmPolicies *GetPolicies() const;
  347. struct cmCMP0054Id
  348. {
  349. cmCMP0054Id(cmListFileContext const& context):
  350. Context(context)
  351. {
  352. }
  353. bool operator< (cmCMP0054Id const& id) const
  354. {
  355. if(this->Context.FilePath != id.Context.FilePath)
  356. return this->Context.FilePath < id.Context.FilePath;
  357. return this->Context.Line < id.Context.Line;
  358. }
  359. cmListFileContext Context;
  360. };
  361. mutable std::set<cmCMP0054Id> CMP0054ReportedIds;
  362. /**
  363. * Determine if the given context, name pair has already been reported
  364. * in context of CMP0054.
  365. */
  366. bool HasCMP0054AlreadyBeenReported(
  367. cmListFileContext context) const;
  368. void MakeStartDirectoriesCurrent()
  369. {
  370. this->AddDefinition("CMAKE_CURRENT_SOURCE_DIR",
  371. this->cmStartDirectory.c_str());
  372. this->AddDefinition("CMAKE_CURRENT_BINARY_DIR",
  373. this->StartOutputDirectory.c_str());
  374. }
  375. //@{
  376. /**
  377. * Set/Get the home directory (or output directory) in the project. The
  378. * home directory is the top directory of the project. It is where
  379. * CMakeSetup or configure was run. Remember that CMake processes
  380. * CMakeLists files by recursing up the tree starting at the StartDirectory
  381. * and going up until it reaches the HomeDirectory.
  382. */
  383. void SetHomeDirectory(const std::string& dir);
  384. const char* GetHomeDirectory() const;
  385. void SetHomeOutputDirectory(const std::string& lib);
  386. const char* GetHomeOutputDirectory() const;
  387. //@}
  388. /**
  389. * Set CMAKE_SCRIPT_MODE_FILE variable when running a -P script.
  390. */
  391. void SetScriptModeFile(const char* scriptfile);
  392. /**
  393. * Set CMAKE_ARGC, CMAKE_ARGV0 ... variables.
  394. */
  395. void SetArgcArgv(const std::vector<std::string>& args);
  396. //@{
  397. /**
  398. * Set/Get the start directory (or output directory). The start directory
  399. * is the directory of the CMakeLists.txt file that started the current
  400. * round of processing. Remember that CMake processes CMakeLists files by
  401. * recursing up the tree starting at the StartDirectory and going up until
  402. * it reaches the HomeDirectory.
  403. */
  404. void SetStartDirectory(const std::string& dir)
  405. {
  406. this->cmStartDirectory = dir;
  407. cmSystemTools::ConvertToUnixSlashes(this->cmStartDirectory);
  408. this->cmStartDirectory =
  409. cmSystemTools::CollapseFullPath(this->cmStartDirectory);
  410. this->AddDefinition("CMAKE_CURRENT_SOURCE_DIR",
  411. this->cmStartDirectory.c_str());
  412. }
  413. const char* GetStartDirectory() const
  414. {
  415. return this->cmStartDirectory.c_str();
  416. }
  417. void SetStartOutputDirectory(const std::string& lib)
  418. {
  419. this->StartOutputDirectory = lib;
  420. cmSystemTools::ConvertToUnixSlashes(this->StartOutputDirectory);
  421. this->StartOutputDirectory =
  422. cmSystemTools::CollapseFullPath(this->StartOutputDirectory);
  423. cmSystemTools::MakeDirectory(this->StartOutputDirectory.c_str());
  424. this->AddDefinition("CMAKE_CURRENT_BINARY_DIR",
  425. this->StartOutputDirectory.c_str());
  426. }
  427. const char* GetStartOutputDirectory() const
  428. {
  429. return this->StartOutputDirectory.c_str();
  430. }
  431. //@}
  432. const char* GetCurrentDirectory() const
  433. {
  434. return this->cmStartDirectory.c_str();
  435. }
  436. const char* GetCurrentOutputDirectory() const
  437. {
  438. return this->StartOutputDirectory.c_str();
  439. }
  440. /* Get the current CMakeLists.txt file that is being processed. This
  441. * is just used in order to be able to 'branch' from one file to a second
  442. * transparently */
  443. const char* GetCurrentListFile() const
  444. {
  445. return this->cmCurrentListFile.c_str();
  446. }
  447. //@}
  448. /**
  449. * Set a regular expression that include files must match
  450. * in order to be considered as part of the depend information.
  451. */
  452. void SetIncludeRegularExpression(const char* regex)
  453. {
  454. this->IncludeFileRegularExpression = regex;
  455. }
  456. const char* GetIncludeRegularExpression() const
  457. {
  458. return this->IncludeFileRegularExpression.c_str();
  459. }
  460. /**
  461. * Set a regular expression that include files that are not found
  462. * must match in order to be considered a problem.
  463. */
  464. void SetComplainRegularExpression(const std::string& regex)
  465. {
  466. this->ComplainFileRegularExpression = regex;
  467. }
  468. const char* GetComplainRegularExpression() const
  469. {
  470. return this->ComplainFileRegularExpression.c_str();
  471. }
  472. /**
  473. * Get the list of targets
  474. */
  475. cmTargets &GetTargets() { return this->Targets; }
  476. /**
  477. * Get the list of targets, const version
  478. */
  479. const cmTargets &GetTargets() const { return this->Targets; }
  480. const std::vector<cmTarget*> &GetOwnedImportedTargets() const
  481. {
  482. return this->ImportedTargetsOwned;
  483. }
  484. const cmGeneratorTargetsType &GetGeneratorTargets() const
  485. {
  486. return this->GeneratorTargets;
  487. }
  488. void SetGeneratorTargets(const cmGeneratorTargetsType &targets)
  489. {
  490. this->GeneratorTargets = targets;
  491. }
  492. cmTarget* FindTarget(const std::string& name,
  493. bool excludeAliases = false) const;
  494. /** Find a target to use in place of the given name. The target
  495. returned may be imported or built within the project. */
  496. cmTarget* FindTargetToUse(const std::string& name,
  497. bool excludeAliases = false) const;
  498. bool IsAlias(const std::string& name) const;
  499. cmGeneratorTarget* FindGeneratorTargetToUse(const std::string& name) const;
  500. /**
  501. * Mark include directories as system directories.
  502. */
  503. void AddSystemIncludeDirectories(const std::set<std::string> &incs);
  504. /** Get a cmSourceFile pointer for a given source name, if the name is
  505. * not found, then a null pointer is returned.
  506. */
  507. cmSourceFile* GetSource(const std::string& sourceName) const;
  508. /** Create the source file and return it. generated
  509. * indicates if it is a generated file, this is used in determining
  510. * how to create the source file instance e.g. name
  511. */
  512. cmSourceFile* CreateSource(const std::string& sourceName,
  513. bool generated = false);
  514. /** Get a cmSourceFile pointer for a given source name, if the name is
  515. * not found, then create the source file and return it. generated
  516. * indicates if it is a generated file, this is used in determining
  517. * how to create the source file instance e.g. name
  518. */
  519. cmSourceFile* GetOrCreateSource(const std::string& sourceName,
  520. bool generated = false);
  521. //@{
  522. /**
  523. * Return a list of extensions associated with source and header
  524. * files
  525. */
  526. const std::vector<std::string>& GetSourceExtensions() const
  527. {return this->SourceFileExtensions;}
  528. const std::vector<std::string>& GetHeaderExtensions() const
  529. {return this->HeaderFileExtensions;}
  530. //@}
  531. /**
  532. * Given a variable name, return its value (as a string).
  533. * If the variable is not found in this makefile instance, the
  534. * cache is then queried.
  535. */
  536. const char* GetDefinition(const std::string&) const;
  537. const char* GetSafeDefinition(const std::string&) const;
  538. const char* GetRequiredDefinition(const std::string& name) const;
  539. bool IsDefinitionSet(const std::string&) const;
  540. /**
  541. * Get the list of all variables in the current space. If argument
  542. * cacheonly is specified and is greater than 0, then only cache
  543. * variables will be listed.
  544. */
  545. std::vector<std::string> GetDefinitions(int cacheonly=0) const;
  546. /**
  547. * Test a boolean variable to see if it is true or false.
  548. * If the variable is not found in this makefile instance, the
  549. * cache is then queried.
  550. * Returns false if no entry defined.
  551. */
  552. bool IsOn(const std::string& name) const;
  553. bool IsSet(const std::string& name) const;
  554. /** Return whether the target platform is 64-bit. */
  555. bool PlatformIs64Bit() const;
  556. /** Retrieve soname flag for the specified language if supported */
  557. const char* GetSONameFlag(const std::string& language) const;
  558. /**
  559. * Get a list of preprocessor define flags.
  560. */
  561. const char* GetDefineFlags() const
  562. {return this->DefineFlags.c_str();}
  563. /**
  564. * Make sure CMake can write this file
  565. */
  566. bool CanIWriteThisFile(const char* fileName) const;
  567. #if defined(CMAKE_BUILD_WITH_CMAKE)
  568. /**
  569. * Get the vector source groups.
  570. */
  571. const std::vector<cmSourceGroup>& GetSourceGroups() const
  572. { return this->SourceGroups; }
  573. /**
  574. * Get the source group
  575. */
  576. cmSourceGroup* GetSourceGroup(const std::vector<std::string>&name) const;
  577. #endif
  578. /**
  579. * Get the vector of list files on which this makefile depends
  580. */
  581. const std::vector<std::string>& GetListFiles() const
  582. { return this->ListFiles; }
  583. ///! When the file changes cmake will be re-run from the build system.
  584. void AddCMakeDependFile(const std::string& file)
  585. { this->ListFiles.push_back(file);}
  586. void AddCMakeDependFilesFromUser();
  587. std::string GetListFileStack() const;
  588. /**
  589. * Get the current context backtrace.
  590. */
  591. cmListFileBacktrace GetBacktrace() const;
  592. /**
  593. * Get the vector of files created by this makefile
  594. */
  595. const std::vector<std::string>& GetOutputFiles() const
  596. { return this->OutputFiles; }
  597. void AddCMakeOutputFile(const std::string& file)
  598. { this->OutputFiles.push_back(file);}
  599. /**
  600. * Expand all defined variables in the string.
  601. * Defined variables come from the this->Definitions map.
  602. * They are expanded with ${var} where var is the
  603. * entry in the this->Definitions map. Also \@var\@ is
  604. * expanded to match autoconf style expansions.
  605. */
  606. const char *ExpandVariablesInString(std::string& source) const;
  607. const char *ExpandVariablesInString(std::string& source, bool escapeQuotes,
  608. bool noEscapes,
  609. bool atOnly = false,
  610. const char* filename = 0,
  611. long line = -1,
  612. bool removeEmpty = false,
  613. bool replaceAt = false) const;
  614. /**
  615. * Remove any remaining variables in the string. Anything with ${var} or
  616. * \@var\@ will be removed.
  617. */
  618. void RemoveVariablesInString(std::string& source,
  619. bool atOnly = false) const;
  620. /**
  621. * Expand variables in the makefiles ivars such as link directories etc
  622. */
  623. void ExpandVariablesCMP0019();
  624. /**
  625. * Replace variables and #cmakedefine lines in the given string.
  626. * See cmConfigureFileCommand for details.
  627. */
  628. void ConfigureString(const std::string& input, std::string& output,
  629. bool atOnly, bool escapeQuotes) const;
  630. /**
  631. * Copy file but change lines acording to ConfigureString
  632. */
  633. int ConfigureFile(const char* infile, const char* outfile,
  634. bool copyonly, bool atOnly, bool escapeQuotes,
  635. const cmNewLineStyle& = cmNewLineStyle());
  636. #if defined(CMAKE_BUILD_WITH_CMAKE)
  637. /**
  638. * find what source group this source is in
  639. */
  640. cmSourceGroup* FindSourceGroup(const char* source,
  641. std::vector<cmSourceGroup> &groups) const;
  642. #endif
  643. /**
  644. * Print a command's invocation
  645. */
  646. void PrintCommandTrace(const cmListFileFunction& lff) const;
  647. /**
  648. * Execute a single CMake command. Returns true if the command
  649. * succeeded or false if it failed.
  650. */
  651. bool ExecuteCommand(const cmListFileFunction& lff,
  652. cmExecutionStatus &status);
  653. ///! Enable support for named language, if nil then all languages are
  654. ///enabled.
  655. void EnableLanguage(std::vector<std::string>const& languages, bool optional);
  656. cmState *GetState() const;
  657. /**
  658. * Get the variable watch. This is used to determine when certain variables
  659. * are accessed.
  660. */
  661. #ifdef CMAKE_BUILD_WITH_CMAKE
  662. cmVariableWatch* GetVariableWatch() const;
  663. #endif
  664. ///! Display progress or status message.
  665. void DisplayStatus(const char*, float) const;
  666. /**
  667. * Expand the given list file arguments into the full set after
  668. * variable replacement and list expansion.
  669. */
  670. bool ExpandArguments(std::vector<cmListFileArgument> const& inArgs,
  671. std::vector<std::string>& outArgs) const;
  672. bool ExpandArguments(std::vector<cmListFileArgument> const& inArgs,
  673. std::vector<cmExpandedCommandArgument>& outArgs) const;
  674. /**
  675. * Get the instance
  676. */
  677. cmake *GetCMakeInstance() const;
  678. /**
  679. * Get all the source files this makefile knows about
  680. */
  681. const std::vector<cmSourceFile*> &GetSourceFiles() const
  682. {return this->SourceFiles;}
  683. std::vector<cmSourceFile*> &GetSourceFiles() {return this->SourceFiles;}
  684. /**
  685. * Is there a source file that has the provided source file as an output?
  686. * if so then return it
  687. */
  688. cmSourceFile *GetSourceFileWithOutput(const std::string& outName) const;
  689. /**
  690. * Add a macro to the list of macros. The arguments should be name of the
  691. * macro and a documentation signature of it
  692. */
  693. void AddMacro(const char* name);
  694. ///! Add a new cmTest to the list of tests for this makefile.
  695. cmTest* CreateTest(const std::string& testName);
  696. /** Get a cmTest pointer for a given test name, if the name is
  697. * not found, then a null pointer is returned.
  698. */
  699. cmTest* GetTest(const std::string& testName) const;
  700. /**
  701. * Get a list of macros as a ; separated string
  702. */
  703. void GetListOfMacros(std::string& macros) const;
  704. /**
  705. * Return a location of a file in cmake or custom modules directory
  706. */
  707. std::string GetModulesFile(const char* name) const;
  708. ///! Set/Get a property of this directory
  709. void SetProperty(const std::string& prop, const char *value);
  710. void AppendProperty(const std::string& prop, const char *value,
  711. bool asString=false);
  712. const char *GetProperty(const std::string& prop) const;
  713. const char *GetProperty(const std::string& prop,
  714. cmProperty::ScopeType scope) const;
  715. bool GetPropertyAsBool(const std::string& prop) const;
  716. const char* GetFeature(const std::string& feature,
  717. const std::string& config);
  718. // Get the properties
  719. cmPropertyMap &GetProperties() { return this->Properties; }
  720. ///! Initialize a makefile from its parent
  721. void InitializeFromParent();
  722. void AddInstallGenerator(cmInstallGenerator* g)
  723. { if(g) this->InstallGenerators.push_back(g); }
  724. std::vector<cmInstallGenerator*>& GetInstallGenerators()
  725. { return this->InstallGenerators; }
  726. void AddTestGenerator(cmTestGenerator* g)
  727. { if(g) this->TestGenerators.push_back(g); }
  728. const std::vector<cmTestGenerator*>& GetTestGenerators() const
  729. { return this->TestGenerators; }
  730. // push and pop variable scopes
  731. void PushScope();
  732. void PopScope();
  733. void RaiseScope(const std::string& var, const char *value);
  734. // push and pop loop scopes
  735. void PushLoopBlockBarrier();
  736. void PopLoopBlockBarrier();
  737. /** Helper class to push and pop scopes automatically. */
  738. class ScopePushPop
  739. {
  740. public:
  741. ScopePushPop(cmMakefile* m): Makefile(m) { this->Makefile->PushScope(); }
  742. ~ScopePushPop() { this->Makefile->PopScope(); }
  743. private:
  744. cmMakefile* Makefile;
  745. };
  746. void IssueMessage(cmake::MessageType t,
  747. std::string const& text) const;
  748. /** Set whether or not to report a CMP0000 violation. */
  749. void SetCheckCMP0000(bool b) { this->CheckCMP0000 = b; }
  750. const std::vector<cmValueWithOrigin>& GetIncludeDirectoriesEntries() const
  751. {
  752. return this->IncludeDirectoriesEntries;
  753. }
  754. const std::vector<cmValueWithOrigin>& GetCompileOptionsEntries() const
  755. {
  756. return this->CompileOptionsEntries;
  757. }
  758. const std::vector<cmValueWithOrigin>& GetCompileDefinitionsEntries() const
  759. {
  760. return this->CompileDefinitionsEntries;
  761. }
  762. bool IsGeneratingBuildSystem() const { return this->GeneratingBuildSystem; }
  763. void SetGeneratingBuildSystem(){ this->GeneratingBuildSystem = true; }
  764. void AddQtUiFileWithOptions(cmSourceFile *sf);
  765. std::vector<cmSourceFile*> GetQtUiFilesWithOptions() const;
  766. std::set<std::string> const & GetSystemIncludeDirectories() const
  767. { return this->SystemIncludeDirectories; }
  768. bool PolicyOptionalWarningEnabled(std::string const& var);
  769. bool AddRequiredTargetFeature(cmTarget *target,
  770. const std::string& feature,
  771. std::string *error = 0) const;
  772. bool CompileFeatureKnown(cmTarget const* target, const std::string& feature,
  773. std::string& lang, std::string *error) const;
  774. const char* CompileFeaturesAvailable(const std::string& lang,
  775. std::string *error) const;
  776. bool HaveStandardAvailable(cmTarget const* target, std::string const& lang,
  777. const std::string& feature) const;
  778. bool IsLaterStandard(std::string const& lang,
  779. std::string const& lhs,
  780. std::string const& rhs);
  781. void PushLoopBlock();
  782. void PopLoopBlock();
  783. bool IsLoopBlock() const;
  784. void ClearMatches();
  785. void StoreMatches(cmsys::RegularExpression& re);
  786. protected:
  787. // add link libraries and directories to the target
  788. void AddGlobalLinkInformation(const std::string& name, cmTarget& target);
  789. // Check for a an unused variable
  790. void CheckForUnused(const char* reason, const std::string& name) const;
  791. std::string cmStartDirectory;
  792. std::string StartOutputDirectory;
  793. std::string cmHomeDirectory;
  794. std::string HomeOutputDirectory;
  795. std::string cmCurrentListFile;
  796. std::string ProjectName; // project name
  797. // libraries, classes, and executables
  798. mutable cmTargets Targets;
  799. #if defined(CMAKE_BUILD_WITH_CMAKE)
  800. typedef cmsys::hash_map<std::string, cmTarget*> TargetMap;
  801. #else
  802. typedef std::map<std::string, cmTarget*> TargetMap;
  803. #endif
  804. TargetMap AliasTargets;
  805. cmGeneratorTargetsType GeneratorTargets;
  806. std::vector<cmSourceFile*> SourceFiles;
  807. // Tests
  808. std::map<std::string, cmTest*> Tests;
  809. // The link-library paths. Order matters, use std::vector (not std::set).
  810. std::vector<std::string> LinkDirectories;
  811. // The set of include directories that are marked as system include
  812. // directories.
  813. std::set<std::string> SystemIncludeDirectories;
  814. std::vector<std::string> ListFiles;
  815. std::vector<std::string> OutputFiles;
  816. cmTarget::LinkLibraryVectorType LinkLibraries;
  817. std::vector<cmInstallGenerator*> InstallGenerators;
  818. std::vector<cmTestGenerator*> TestGenerators;
  819. std::string IncludeFileRegularExpression;
  820. std::string ComplainFileRegularExpression;
  821. std::vector<std::string> SourceFileExtensions;
  822. std::vector<std::string> HeaderFileExtensions;
  823. std::string DefineFlags;
  824. std::vector<cmValueWithOrigin> IncludeDirectoriesEntries;
  825. std::vector<cmValueWithOrigin> CompileOptionsEntries;
  826. std::vector<cmValueWithOrigin> CompileDefinitionsEntries;
  827. // Track the value of the computed DEFINITIONS property.
  828. void AddDefineFlag(const char*, std::string&);
  829. void RemoveDefineFlag(const char*, std::string::size_type, std::string&);
  830. std::string DefineFlagsOrig;
  831. #if defined(CMAKE_BUILD_WITH_CMAKE)
  832. std::vector<cmSourceGroup> SourceGroups;
  833. #endif
  834. std::vector<cmCommand*> FinalPassCommands;
  835. cmLocalGenerator* LocalGenerator;
  836. bool IsFunctionBlocked(const cmListFileFunction& lff,
  837. cmExecutionStatus &status);
  838. private:
  839. void Initialize();
  840. bool ReadListFileInternal(const char* filenametoread,
  841. bool noPolicyScope,
  842. bool requireProjectCommand);
  843. bool ParseDefineFlag(std::string const& definition, bool remove);
  844. bool EnforceUniqueDir(const std::string& srcPath,
  845. const std::string& binPath) const;
  846. friend class cmMakeDepend; // make depend needs direct access
  847. // to the Sources array
  848. void PrintStringVector(const char* s, const
  849. std::vector<std::pair<std::string, bool> >& v) const;
  850. void PrintStringVector(const char* s,
  851. const std::vector<std::string>& v) const;
  852. void AddDefaultDefinitions();
  853. typedef std::vector<cmFunctionBlocker*> FunctionBlockersType;
  854. FunctionBlockersType FunctionBlockers;
  855. std::vector<FunctionBlockersType::size_type> FunctionBlockerBarriers;
  856. void PushFunctionBlockerBarrier();
  857. void PopFunctionBlockerBarrier(bool reportError = true);
  858. std::stack<int> LoopBlockCounter;
  859. std::vector<std::string> MacrosList;
  860. mutable cmsys::RegularExpression cmDefineRegex;
  861. mutable cmsys::RegularExpression cmDefine01Regex;
  862. mutable cmsys::RegularExpression cmAtVarRegex;
  863. mutable cmsys::RegularExpression cmNamedCurly;
  864. cmPropertyMap Properties;
  865. // Unused variable flags
  866. bool WarnUnused;
  867. bool CheckSystemVars;
  868. // stack of list files being read
  869. std::deque<std::string> ListFileStack;
  870. // stack of commands being invoked.
  871. struct CallStackEntry
  872. {
  873. cmListFileContext const* Context;
  874. cmExecutionStatus* Status;
  875. };
  876. typedef std::deque<CallStackEntry> CallStackType;
  877. CallStackType CallStack;
  878. friend class cmMakefileCall;
  879. std::vector<cmTarget*> ImportedTargetsOwned;
  880. TargetMap ImportedTargets;
  881. // Internal policy stack management.
  882. void PushPolicy(bool weak = false,
  883. cmPolicies::PolicyMap const& pm = cmPolicies::PolicyMap());
  884. void PopPolicy();
  885. void PushPolicyBarrier();
  886. void PopPolicyBarrier(bool reportError = true);
  887. friend class cmCMakePolicyCommand;
  888. class IncludeScope;
  889. friend class IncludeScope;
  890. // stack of policy settings
  891. struct PolicyStackEntry: public cmPolicies::PolicyMap
  892. {
  893. typedef cmPolicies::PolicyMap derived;
  894. PolicyStackEntry(bool w = false): derived(), Weak(w) {}
  895. PolicyStackEntry(derived const& d, bool w = false): derived(d), Weak(w) {}
  896. PolicyStackEntry(PolicyStackEntry const& r): derived(r), Weak(r.Weak) {}
  897. bool Weak;
  898. };
  899. typedef std::vector<PolicyStackEntry> PolicyStackType;
  900. PolicyStackType PolicyStack;
  901. std::vector<PolicyStackType::size_type> PolicyBarriers;
  902. cmPolicies::PolicyStatus
  903. GetPolicyStatusInternal(cmPolicies::PolicyID id) const;
  904. bool CheckCMP0000;
  905. // Enforce rules about CMakeLists.txt files.
  906. void EnforceDirectoryLevelRules() const;
  907. // CMP0053 == old
  908. cmake::MessageType ExpandVariablesInStringOld(
  909. std::string& errorstr,
  910. std::string& source,
  911. bool escapeQuotes,
  912. bool noEscapes,
  913. bool atOnly,
  914. const char* filename,
  915. long line,
  916. bool removeEmpty,
  917. bool replaceAt) const;
  918. // CMP0053 == new
  919. cmake::MessageType ExpandVariablesInStringNew(
  920. std::string& errorstr,
  921. std::string& source,
  922. bool escapeQuotes,
  923. bool noEscapes,
  924. bool atOnly,
  925. const char* filename,
  926. long line,
  927. bool removeEmpty,
  928. bool replaceAt) const;
  929. bool GeneratingBuildSystem;
  930. /**
  931. * Old version of GetSourceFileWithOutput(const std::string&) kept for
  932. * backward-compatibility. It implements a linear search and support
  933. * relative file paths. It is used as a fall back by
  934. * GetSourceFileWithOutput(const std::string&).
  935. */
  936. cmSourceFile *LinearGetSourceFileWithOutput(const std::string& cname) const;
  937. // A map for fast output to input look up.
  938. #if defined(CMAKE_BUILD_WITH_CMAKE)
  939. typedef cmsys::hash_map<std::string, cmSourceFile*> OutputToSourceMap;
  940. #else
  941. typedef std::map<std::string, cmSourceFile*> OutputToSourceMap;
  942. #endif
  943. OutputToSourceMap OutputToSource;
  944. void UpdateOutputToSourceMap(std::vector<std::string> const& outputs,
  945. cmSourceFile* source);
  946. void UpdateOutputToSourceMap(std::string const& output,
  947. cmSourceFile* source);
  948. std::vector<cmSourceFile*> QtUiFilesWithOptions;
  949. bool AddRequiredTargetCFeature(cmTarget *target,
  950. const std::string& feature) const;
  951. bool AddRequiredTargetCxxFeature(cmTarget *target,
  952. const std::string& feature) const;
  953. void CheckNeededCLanguage(const std::string& feature, bool& needC90,
  954. bool& needC99, bool& needC11) const;
  955. void CheckNeededCxxLanguage(const std::string& feature, bool& needCxx98,
  956. bool& needCxx11, bool& needCxx14) const;
  957. bool HaveCStandardAvailable(cmTarget const* target,
  958. const std::string& feature) const;
  959. bool HaveCxxStandardAvailable(cmTarget const* target,
  960. const std::string& feature) const;
  961. mutable bool SuppressWatches;
  962. };
  963. //----------------------------------------------------------------------------
  964. // Helper class to make sure the call stack is valid.
  965. class cmMakefileCall
  966. {
  967. public:
  968. cmMakefileCall(cmMakefile* mf,
  969. cmListFileContext const& lfc,
  970. cmExecutionStatus& status): Makefile(mf)
  971. {
  972. cmMakefile::CallStackEntry entry = {&lfc, &status};
  973. this->Makefile->CallStack.push_back(entry);
  974. }
  975. ~cmMakefileCall()
  976. {
  977. this->Makefile->CallStack.pop_back();
  978. }
  979. private:
  980. cmMakefile* Makefile;
  981. };
  982. #endif