cmMakefile.h 38 KB

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