cmMakefile.h 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #ifndef cmMakefile_h
  14. #define cmMakefile_h
  15. #include "cmCacheManager.h"
  16. #include "cmData.h"
  17. #include "cmExecutionStatus.h"
  18. #include "cmListFileCache.h"
  19. #include "cmPolicies.h"
  20. #include "cmPropertyMap.h"
  21. #include "cmSystemTools.h"
  22. #include "cmTarget.h"
  23. #include "cmake.h"
  24. #if defined(CMAKE_BUILD_WITH_CMAKE)
  25. #include "cmSourceGroup.h"
  26. #endif
  27. #include <cmsys/auto_ptr.hxx>
  28. #include <cmsys/RegularExpression.hxx>
  29. class cmFunctionBlocker;
  30. class cmCommand;
  31. class cmInstallGenerator;
  32. class cmLocalGenerator;
  33. class cmMakeDepend;
  34. class cmSourceFile;
  35. class cmTest;
  36. class cmVariableWatch;
  37. class cmake;
  38. class cmMakefileCall;
  39. class cmCMakePolicyCommand;
  40. /** \class cmMakefile
  41. * \brief Process the input CMakeLists.txt file.
  42. *
  43. * Process and store into memory the input CMakeLists.txt file.
  44. * Each CMakeLists.txt file is parsed and the commands found there
  45. * are added into the build process.
  46. */
  47. class cmMakefile
  48. {
  49. public:
  50. /**
  51. * Return the major and minor version of the cmake that
  52. * was used to write the currently loaded cache, note
  53. * this method will not work before the cache is loaded.
  54. */
  55. unsigned int GetCacheMajorVersion();
  56. unsigned int GetCacheMinorVersion();
  57. /** Return whether compatibility features needed for a version of
  58. the cache or lower should be enabled. */
  59. bool NeedCacheCompatibility(int major, int minor);
  60. /**
  61. * Construct an empty makefile.
  62. */
  63. cmMakefile();
  64. cmMakefile(const cmMakefile& mf);
  65. /**
  66. * Destructor.
  67. */
  68. ~cmMakefile();
  69. /**
  70. * Read and parse a CMakeLists.txt file.
  71. */
  72. bool ReadListFile(const char* listfile,
  73. const char* external= 0,
  74. std::string* fullPath= 0);
  75. /**
  76. * Add a function blocker to this makefile
  77. */
  78. void AddFunctionBlocker(cmFunctionBlocker* fb);
  79. /**
  80. * Remove the function blocker whose scope ends with the given command.
  81. * This returns ownership of the function blocker object.
  82. */
  83. cmsys::auto_ptr<cmFunctionBlocker>
  84. RemoveFunctionBlocker(cmFunctionBlocker* fb, const cmListFileFunction& lff);
  85. /** Push/pop a lexical (function blocker) barrier automatically. */
  86. class LexicalPushPop
  87. {
  88. public:
  89. LexicalPushPop(cmMakefile* mf);
  90. ~LexicalPushPop();
  91. void Quiet() { this->ReportError = false; }
  92. private:
  93. cmMakefile* Makefile;
  94. bool ReportError;
  95. };
  96. friend class LexicalPushPop;
  97. /**
  98. * Try running cmake and building a file. This is used for dynalically
  99. * loaded commands, not as part of the usual build process.
  100. */
  101. int TryCompile(const char *srcdir, const char *bindir,
  102. const char *projectName, const char *targetName,
  103. const std::vector<std::string> *cmakeArgs,
  104. std::string *output);
  105. /**
  106. * Specify the makefile generator. This is platform/compiler
  107. * dependent, although the interface is through a generic
  108. * superclass.
  109. */
  110. void SetLocalGenerator(cmLocalGenerator*);
  111. ///! Get the current makefile generator.
  112. cmLocalGenerator* GetLocalGenerator()
  113. { return this->LocalGenerator;}
  114. /**
  115. * Test whether compatibility is set to a given version or lower.
  116. */
  117. bool NeedBackwardsCompatibility(unsigned int major,
  118. unsigned int minor,
  119. unsigned int patch = 0xFFu);
  120. /**
  121. * Help enforce global target name uniqueness.
  122. */
  123. bool EnforceUniqueName(std::string const& name, std::string& msg,
  124. bool isCustom = false);
  125. /**
  126. * Perform FinalPass, Library dependency analysis etc before output of the
  127. * makefile.
  128. */
  129. void ConfigureFinalPass();
  130. /**
  131. * run the final pass on all commands.
  132. */
  133. void FinalPass();
  134. /**
  135. * Print the object state to std::cout.
  136. */
  137. void Print();
  138. /** Add a custom command to the build. */
  139. void AddCustomCommandToTarget(const char* target,
  140. const std::vector<std::string>& depends,
  141. const cmCustomCommandLines& commandLines,
  142. cmTarget::CustomCommandType type,
  143. const char* comment, const char* workingDir,
  144. bool escapeOldStyle = true);
  145. void AddCustomCommandToOutput(const std::vector<std::string>& outputs,
  146. const std::vector<std::string>& depends,
  147. const char* main_dependency,
  148. const cmCustomCommandLines& commandLines,
  149. const char* comment, const char* workingDir,
  150. bool replace = false,
  151. bool escapeOldStyle = true);
  152. void AddCustomCommandToOutput(const char* output,
  153. const std::vector<std::string>& depends,
  154. const char* main_dependency,
  155. const cmCustomCommandLines& commandLines,
  156. const char* comment, const char* workingDir,
  157. bool replace = false,
  158. bool escapeOldStyle = true);
  159. void AddCustomCommandOldStyle(const char* target,
  160. const std::vector<std::string>& outputs,
  161. const std::vector<std::string>& depends,
  162. const char* source,
  163. const cmCustomCommandLines& commandLines,
  164. const char* comment);
  165. /**
  166. * Add a define flag to the build.
  167. */
  168. void AddDefineFlag(const char* definition);
  169. void RemoveDefineFlag(const char* definition);
  170. /** Create a new imported target with the name and type given. */
  171. cmTarget* AddImportedTarget(const char* name, cmTarget::TargetType type);
  172. cmTarget* AddNewTarget(cmTarget::TargetType type, const char* name);
  173. /**
  174. * Add an executable to the build.
  175. */
  176. cmTarget* AddExecutable(const char *exename,
  177. const std::vector<std::string> &srcs,
  178. bool excludeFromAll = false);
  179. /**
  180. * Add a utility to the build. A utiltity target is a command that
  181. * is run every time the target is built.
  182. */
  183. void AddUtilityCommand(const char* utilityName, bool excludeFromAll,
  184. const std::vector<std::string>& depends,
  185. const char* workingDirectory,
  186. const char* command,
  187. const char* arg1=0,
  188. const char* arg2=0,
  189. const char* arg3=0,
  190. const char* arg4=0);
  191. cmTarget* AddUtilityCommand(const char* utilityName, bool excludeFromAll,
  192. const char* workingDirectory,
  193. const std::vector<std::string>& depends,
  194. const cmCustomCommandLines& commandLines,
  195. bool escapeOldStyle = true,
  196. const char* comment = 0);
  197. /**
  198. * Add a link library to the build.
  199. */
  200. void AddLinkLibrary(const char*);
  201. void AddLinkLibrary(const char*, cmTarget::LinkLibraryType type);
  202. void AddLinkLibraryForTarget(const char *tgt, const char*,
  203. cmTarget::LinkLibraryType type);
  204. void AddLinkDirectoryForTarget(const char *tgt, const char* d);
  205. /**
  206. * Add a link directory to the build.
  207. */
  208. void AddLinkDirectory(const char*);
  209. /**
  210. * Get the list of link directories
  211. */
  212. std::vector<std::string>& GetLinkDirectories()
  213. {
  214. return this->LinkDirectories;
  215. }
  216. const std::vector<std::string>& GetLinkDirectories() const
  217. {
  218. return this->LinkDirectories;
  219. }
  220. void SetLinkDirectories(const std::vector<std::string>& vec)
  221. {
  222. this->LinkDirectories = vec;
  223. }
  224. /**
  225. * Add a subdirectory to the build.
  226. */
  227. void AddSubDirectory(const char*, bool excludeFromAll=false,
  228. bool preorder = false);
  229. void AddSubDirectory(const char* fullSrcDir,const char *fullBinDir,
  230. bool excludeFromAll, bool preorder,
  231. bool immediate);
  232. /**
  233. * Configure a subdirectory
  234. */
  235. void ConfigureSubDirectory(cmLocalGenerator *);
  236. /**
  237. * Add an include directory to the build.
  238. */
  239. void AddIncludeDirectory(const char*, bool before = false);
  240. /**
  241. * Add a variable definition to the build. This variable
  242. * can be used in CMake to refer to lists, directories, etc.
  243. */
  244. void AddDefinition(const char* name, const char* value);
  245. ///! Add a definition to this makefile and the global cmake cache.
  246. void AddCacheDefinition(const char* name, const char* value,
  247. const char* doc,
  248. cmCacheManager::CacheEntryType type,
  249. bool force = false);
  250. /**
  251. * Add bool variable definition to the build.
  252. */
  253. void AddDefinition(const char* name, bool);
  254. ///! Add a definition to this makefile and the global cmake cache.
  255. void AddCacheDefinition(const char* name, bool, const char* doc);
  256. /**
  257. * Remove a variable definition from the build. This is not valid
  258. * for cache entries, and will only affect the current makefile.
  259. */
  260. void RemoveDefinition(const char* name);
  261. ///! Remove a definition from the cache.
  262. void RemoveCacheDefinition(const char* name);
  263. /**
  264. * Specify the name of the project for this build.
  265. */
  266. void SetProjectName(const char*);
  267. /**
  268. * Get the name of the project for this build.
  269. */
  270. const char* GetProjectName() const
  271. {
  272. return this->ProjectName.c_str();
  273. }
  274. /**
  275. * Set the name of the library.
  276. */
  277. void AddLibrary(const char *libname, cmTarget::TargetType type,
  278. const std::vector<std::string> &srcs,
  279. bool excludeFromAll = false);
  280. #if defined(CMAKE_BUILD_WITH_CMAKE)
  281. /**
  282. * Add a root source group for consideration when adding a new source.
  283. */
  284. void AddSourceGroup(const char* name, const char* regex=0);
  285. /**
  286. * Add a source group for consideration when adding a new source.
  287. * name is tokenized.
  288. */
  289. void AddSourceGroup(const std::vector<std::string>& name,
  290. const char* regex=0);
  291. #endif
  292. //@{
  293. /**
  294. * Set, Push, Pop policy values for CMake.
  295. */
  296. bool SetPolicy(cmPolicies::PolicyID id, cmPolicies::PolicyStatus status);
  297. bool SetPolicy(const char *id, cmPolicies::PolicyStatus status);
  298. cmPolicies::PolicyStatus GetPolicyStatus(cmPolicies::PolicyID id);
  299. bool SetPolicyVersion(const char *version);
  300. //@}
  301. /** Helper class to push and pop policies automatically. */
  302. class PolicyPushPop
  303. {
  304. public:
  305. PolicyPushPop(cmMakefile* m);
  306. ~PolicyPushPop();
  307. void Quiet() { this->ReportError = false; }
  308. private:
  309. cmMakefile* Makefile;
  310. bool ReportError;
  311. };
  312. friend class PolicyPushPop;
  313. /**
  314. * Get the Policies Instance
  315. */
  316. cmPolicies *GetPolicies();
  317. /**
  318. * Add an auxiliary directory to the build.
  319. */
  320. void AddExtraDirectory(const char* dir);
  321. /**
  322. * Add an auxiliary directory to the build.
  323. */
  324. void MakeStartDirectoriesCurrent()
  325. {
  326. this->AddDefinition("CMAKE_CURRENT_SOURCE_DIR",
  327. this->cmStartDirectory.c_str());
  328. this->AddDefinition("CMAKE_CURRENT_BINARY_DIR",
  329. this->StartOutputDirectory.c_str());
  330. }
  331. //@{
  332. /**
  333. * Set/Get the home directory (or output directory) in the project. The
  334. * home directory is the top directory of the project. It is where
  335. * CMakeSetup or configure was run. Remember that CMake processes
  336. * CMakeLists files by recursing up the tree starting at the StartDirectory
  337. * and going up until it reaches the HomeDirectory.
  338. */
  339. void SetHomeDirectory(const char* dir);
  340. const char* GetHomeDirectory() const
  341. {
  342. return this->cmHomeDirectory.c_str();
  343. }
  344. void SetHomeOutputDirectory(const char* lib);
  345. const char* GetHomeOutputDirectory() const
  346. {
  347. return this->HomeOutputDirectory.c_str();
  348. }
  349. //@}
  350. //@{
  351. /**
  352. * Set/Get the start directory (or output directory). The start directory
  353. * is the directory of the CMakeLists.txt file that started the current
  354. * round of processing. Remember that CMake processes CMakeLists files by
  355. * recursing up the tree starting at the StartDirectory and going up until
  356. * it reaches the HomeDirectory.
  357. */
  358. void SetStartDirectory(const char* dir)
  359. {
  360. this->cmStartDirectory = dir;
  361. cmSystemTools::ConvertToUnixSlashes(this->cmStartDirectory);
  362. this->cmStartDirectory =
  363. cmSystemTools::CollapseFullPath(this->cmStartDirectory.c_str());
  364. this->AddDefinition("CMAKE_CURRENT_SOURCE_DIR",
  365. this->cmStartDirectory.c_str());
  366. }
  367. const char* GetStartDirectory() const
  368. {
  369. return this->cmStartDirectory.c_str();
  370. }
  371. void SetStartOutputDirectory(const char* lib)
  372. {
  373. this->StartOutputDirectory = lib;
  374. cmSystemTools::ConvertToUnixSlashes(this->StartOutputDirectory);
  375. this->StartOutputDirectory =
  376. cmSystemTools::CollapseFullPath(this->StartOutputDirectory.c_str());
  377. cmSystemTools::MakeDirectory(this->StartOutputDirectory.c_str());
  378. this->AddDefinition("CMAKE_CURRENT_BINARY_DIR",
  379. this->StartOutputDirectory.c_str());
  380. }
  381. const char* GetStartOutputDirectory() const
  382. {
  383. return this->StartOutputDirectory.c_str();
  384. }
  385. //@}
  386. const char* GetCurrentDirectory() const
  387. {
  388. return this->cmStartDirectory.c_str();
  389. }
  390. const char* GetCurrentOutputDirectory() const
  391. {
  392. return this->StartOutputDirectory.c_str();
  393. }
  394. /* Get the current CMakeLists.txt file that is being processed. This
  395. * is just used in order to be able to 'branch' from one file to a second
  396. * transparently */
  397. const char* GetCurrentListFile() const
  398. {
  399. return this->cmCurrentListFile.c_str();
  400. }
  401. //@}
  402. /**
  403. * Set a regular expression that include files must match
  404. * in order to be considered as part of the depend information.
  405. */
  406. void SetIncludeRegularExpression(const char* regex)
  407. {
  408. this->IncludeFileRegularExpression = regex;
  409. }
  410. const char* GetIncludeRegularExpression()
  411. {
  412. return this->IncludeFileRegularExpression.c_str();
  413. }
  414. /**
  415. * Set a regular expression that include files that are not found
  416. * must match in order to be considered a problem.
  417. */
  418. void SetComplainRegularExpression(const char* regex)
  419. {
  420. this->ComplainFileRegularExpression = regex;
  421. }
  422. const char* GetComplainRegularExpression()
  423. {
  424. return this->ComplainFileRegularExpression.c_str();
  425. }
  426. /**
  427. * Get the list of targets
  428. */
  429. cmTargets &GetTargets() { return this->Targets; }
  430. /**
  431. * Get the list of targets, const version
  432. */
  433. const cmTargets &GetTargets() const { return this->Targets; }
  434. cmTarget* FindTarget(const char* name);
  435. /** Find a target to use in place of the given name. The target
  436. returned may be imported or built within the project. */
  437. cmTarget* FindTargetToUse(const char* name);
  438. /**
  439. * Get a list of include directories in the build.
  440. */
  441. std::vector<std::string>& GetIncludeDirectories()
  442. {
  443. return this->IncludeDirectories;
  444. }
  445. const std::vector<std::string>& GetIncludeDirectories() const
  446. {
  447. return this->IncludeDirectories;
  448. }
  449. void SetIncludeDirectories(const std::vector<std::string>& vec)
  450. {
  451. this->IncludeDirectories = vec;
  452. }
  453. /**
  454. * Mark include directories as system directories.
  455. */
  456. void AddSystemIncludeDirectory(const char* dir);
  457. bool IsSystemIncludeDirectory(const char* dir);
  458. /** Expand out any arguements in the vector that have ; separated
  459. * strings into multiple arguements. A new vector is created
  460. * containing the expanded versions of all arguments in argsIn.
  461. * This method differes from the one in cmSystemTools in that if
  462. * the CmakeLists file is version 1.2 or earlier it will check for
  463. * source lists being used without ${} around them
  464. */
  465. void ExpandSourceListArguments(std::vector<std::string> const& argsIn,
  466. std::vector<std::string>& argsOut,
  467. unsigned int startArgumentIndex);
  468. /** Get a cmSourceFile pointer for a given source name, if the name is
  469. * not found, then a null pointer is returned.
  470. */
  471. cmSourceFile* GetSource(const char* sourceName);
  472. /** Get a cmSourceFile pointer for a given source name, if the name is
  473. * not found, then create the source file and return it. generated
  474. * indicates if it is a generated file, this is used in determining
  475. * how to create the source file instance e.g. name
  476. */
  477. cmSourceFile* GetOrCreateSource(const char* sourceName,
  478. bool generated = false);
  479. /**
  480. * Obtain a list of auxiliary source directories.
  481. */
  482. std::vector<std::string>& GetAuxSourceDirectories()
  483. {return this->AuxSourceDirectories;}
  484. //@{
  485. /**
  486. * Return a list of extensions associated with source and header
  487. * files
  488. */
  489. const std::vector<std::string>& GetSourceExtensions() const
  490. {return this->SourceFileExtensions;}
  491. const std::vector<std::string>& GetHeaderExtensions() const
  492. {return this->HeaderFileExtensions;}
  493. //@}
  494. /**
  495. * Given a variable name, return its value (as a string).
  496. * If the variable is not found in this makefile instance, the
  497. * cache is then queried.
  498. */
  499. const char* GetDefinition(const char*) const;
  500. const char* GetSafeDefinition(const char*) const;
  501. const char* GetRequiredDefinition(const char* name) const;
  502. bool IsDefinitionSet(const char*) const;
  503. /**
  504. * Get the list of all variables in the current space. If argument
  505. * cacheonly is specified and is greater than 0, then only cache
  506. * variables will be listed.
  507. */
  508. std::vector<std::string> GetDefinitions(int cacheonly=0) const;
  509. /** Test a boolean cache entry to see if it is true or false,
  510. * returns false if no entry defined.
  511. */
  512. bool IsOn(const char* name) const;
  513. bool IsSet(const char* name) const;
  514. /**
  515. * Get a list of preprocessor define flags.
  516. */
  517. const char* GetDefineFlags()
  518. {return this->DefineFlags.c_str();}
  519. /**
  520. * Make sure CMake can write this file
  521. */
  522. bool CanIWriteThisFile(const char* fileName);
  523. /**
  524. * Get the vector of used command instances.
  525. */
  526. const std::vector<cmCommand*>& GetUsedCommands() const
  527. {return this->UsedCommands;}
  528. #if defined(CMAKE_BUILD_WITH_CMAKE)
  529. /**
  530. * Get the vector source groups.
  531. */
  532. const std::vector<cmSourceGroup>& GetSourceGroups() const
  533. { return this->SourceGroups; }
  534. /**
  535. * Get the source group
  536. */
  537. cmSourceGroup* GetSourceGroup(const std::vector<std::string>&name);
  538. #endif
  539. /**
  540. * Get the vector of list files on which this makefile depends
  541. */
  542. const std::vector<std::string>& GetListFiles() const
  543. { return this->ListFiles; }
  544. ///! When the file changes cmake will be re-run from the build system.
  545. void AddCMakeDependFile(const char* file)
  546. { this->ListFiles.push_back(file);}
  547. /**
  548. * Get the list file stack as a string
  549. */
  550. std::string GetListFileStack();
  551. /**
  552. * Get the current context backtrace.
  553. */
  554. bool GetBacktrace(cmListFileBacktrace& backtrace) const;
  555. /**
  556. * Get the vector of files created by this makefile
  557. */
  558. const std::vector<std::string>& GetOutputFiles() const
  559. { return this->OutputFiles; }
  560. void AddCMakeOutputFile(const char* file)
  561. { this->OutputFiles.push_back(file);}
  562. /**
  563. * Expand all defined variables in the string.
  564. * Defined variables come from the this->Definitions map.
  565. * They are expanded with ${var} where var is the
  566. * entry in the this->Definitions map. Also @var@ is
  567. * expanded to match autoconf style expansions.
  568. */
  569. const char *ExpandVariablesInString(std::string& source);
  570. const char *ExpandVariablesInString(std::string& source, bool escapeQuotes,
  571. bool noEscapes,
  572. bool atOnly = false,
  573. const char* filename = 0,
  574. long line = -1,
  575. bool removeEmpty = false,
  576. bool replaceAt = true);
  577. /**
  578. * Remove any remaining variables in the string. Anything with ${var} or
  579. * @var@ will be removed.
  580. */
  581. void RemoveVariablesInString(std::string& source,
  582. bool atOnly = false) const;
  583. /**
  584. * Expand variables in the makefiles ivars such as link directories etc
  585. */
  586. void ExpandVariables();
  587. /**
  588. * Replace variables and #cmakedefine lines in the given string.
  589. * See cmConfigureFileCommand for details.
  590. */
  591. void ConfigureString(const std::string& input, std::string& output,
  592. bool atOnly, bool escapeQuotes);
  593. /**
  594. * Copy file but change lines acording to ConfigureString
  595. */
  596. int ConfigureFile(const char* infile, const char* outfile,
  597. bool copyonly, bool atOnly, bool escapeQuotes);
  598. #if defined(CMAKE_BUILD_WITH_CMAKE)
  599. /**
  600. * find what source group this source is in
  601. */
  602. cmSourceGroup& FindSourceGroup(const char* source,
  603. std::vector<cmSourceGroup> &groups);
  604. #endif
  605. void RegisterData(cmData*);
  606. void RegisterData(const char*, cmData*);
  607. cmData* LookupData(const char*) const;
  608. /**
  609. * Execute a single CMake command. Returns true if the command
  610. * succeeded or false if it failed.
  611. */
  612. bool ExecuteCommand(const cmListFileFunction& lff,
  613. cmExecutionStatus &status);
  614. /** Check if a command exists. */
  615. bool CommandExists(const char* name) const;
  616. /**
  617. * Add a command to this cmake instance
  618. */
  619. void AddCommand(cmCommand* );
  620. ///! Enable support for named language, if nil then all languages are
  621. ///enabled.
  622. void EnableLanguage(std::vector<std::string>const& languages, bool optional);
  623. /**
  624. * Set/Get the name of the parent directories CMakeLists file
  625. * given a current CMakeLists file name
  626. */
  627. cmCacheManager *GetCacheManager() const;
  628. /**
  629. * Get the variable watch. This is used to determine when certain variables
  630. * are accessed.
  631. */
  632. #ifdef CMAKE_BUILD_WITH_CMAKE
  633. cmVariableWatch* GetVariableWatch() const;
  634. #endif
  635. ///! Display progress or status message.
  636. void DisplayStatus(const char*, float);
  637. /**
  638. * Expand the given list file arguments into the full set after
  639. * variable replacement and list expansion.
  640. */
  641. bool ExpandArguments(std::vector<cmListFileArgument> const& inArgs,
  642. std::vector<std::string>& outArgs);
  643. /**
  644. * Get the instance
  645. */
  646. cmake *GetCMakeInstance() const;
  647. /**
  648. * Get all the source files this makefile knows about
  649. */
  650. const std::vector<cmSourceFile*> &GetSourceFiles() const
  651. {return this->SourceFiles;}
  652. std::vector<cmSourceFile*> &GetSourceFiles() {return this->SourceFiles;}
  653. /**
  654. * Is there a source file that has the provided source file as an output?
  655. * if so then return it
  656. */
  657. cmSourceFile *GetSourceFileWithOutput(const char *outName);
  658. /**
  659. * Add a macro to the list of macros. The arguments should be name of the
  660. * macro and a documentation signature of it
  661. */
  662. void AddMacro(const char* name, const char* signature);
  663. ///! Add a new cmTest to the list of tests for this makefile.
  664. cmTest* CreateTest(const char* testName);
  665. /** Get a cmTest pointer for a given test name, if the name is
  666. * not found, then a null pointer is returned.
  667. */
  668. cmTest* GetTest(const char* testName) const;
  669. const std::vector<cmTest*> *GetTests() const;
  670. /**
  671. * Get a list of macros as a ; separated string
  672. */
  673. void GetListOfMacros(std::string& macros);
  674. /**
  675. * Return a location of a file in cmake or custom modules directory
  676. */
  677. std::string GetModulesFile(const char* name);
  678. ///! Set/Get a property of this directory
  679. void SetProperty(const char *prop, const char *value);
  680. void AppendProperty(const char *prop, const char *value);
  681. const char *GetProperty(const char *prop);
  682. const char *GetPropertyOrDefinition(const char *prop);
  683. const char *GetProperty(const char *prop, cmProperty::ScopeType scope);
  684. bool GetPropertyAsBool(const char *prop);
  685. // Get the properties
  686. cmPropertyMap &GetProperties() { return this->Properties; };
  687. typedef std::map<cmStdString, cmStdString> DefinitionMap;
  688. ///! Initialize a makefile from its parent
  689. void InitializeFromParent();
  690. ///! Set/Get the preorder flag
  691. void SetPreOrder(bool p) { this->PreOrder = p; }
  692. bool GetPreOrder() const { return this->PreOrder; }
  693. void AddInstallGenerator(cmInstallGenerator* g)
  694. { if(g) this->InstallGenerators.push_back(g); }
  695. std::vector<cmInstallGenerator*>& GetInstallGenerators()
  696. { return this->InstallGenerators; }
  697. // Define the properties
  698. static void DefineProperties(cmake *cm);
  699. // push and pop variable scopes
  700. void PushScope();
  701. void PopScope();
  702. void RaiseScope(const char *var, const char *value);
  703. /** Helper class to push and pop scopes automatically. */
  704. class ScopePushPop
  705. {
  706. public:
  707. ScopePushPop(cmMakefile* m): Makefile(m) { this->Makefile->PushScope(); }
  708. ~ScopePushPop() { this->Makefile->PopScope(); }
  709. private:
  710. cmMakefile* Makefile;
  711. };
  712. void IssueMessage(cmake::MessageType t,
  713. std::string const& text) const;
  714. /** Set whether or not to report a CMP0000 violation. */
  715. void SetCheckCMP0000(bool b) { this->CheckCMP0000 = b; }
  716. protected:
  717. // add link libraries and directories to the target
  718. void AddGlobalLinkInformation(const char* name, cmTarget& target);
  719. std::string Prefix;
  720. std::vector<std::string> AuxSourceDirectories; //
  721. std::string cmStartDirectory;
  722. std::string StartOutputDirectory;
  723. std::string cmHomeDirectory;
  724. std::string HomeOutputDirectory;
  725. std::string cmCurrentListFile;
  726. std::string ProjectName; // project name
  727. // libraries, classes, and executables
  728. cmTargets Targets;
  729. std::vector<cmSourceFile*> SourceFiles;
  730. // Tests
  731. std::map<cmStdString, cmTest*> Tests;
  732. std::vector<cmTest*> OrderedTests;
  733. // The include and link-library paths. These may have order
  734. // dependency, so they must be vectors (not set).
  735. std::vector<std::string> IncludeDirectories;
  736. std::vector<std::string> LinkDirectories;
  737. // The set of include directories that are marked as system include
  738. // directories.
  739. std::set<cmStdString> SystemIncludeDirectories;
  740. std::vector<std::string> ListFiles; // list of command files loaded
  741. std::vector<std::string> OutputFiles; // list of command files loaded
  742. cmTarget::LinkLibraryVectorType LinkLibraries;
  743. std::vector<cmInstallGenerator*> InstallGenerators;
  744. std::string IncludeFileRegularExpression;
  745. std::string ComplainFileRegularExpression;
  746. std::vector<std::string> SourceFileExtensions;
  747. std::vector<std::string> HeaderFileExtensions;
  748. std::string DefineFlags;
  749. // Track the value of the computed DEFINITIONS property.
  750. void AddDefineFlag(const char*, std::string&);
  751. void RemoveDefineFlag(const char*, std::string::size_type, std::string&);
  752. std::string DefineFlagsOrig;
  753. #if defined(CMAKE_BUILD_WITH_CMAKE)
  754. std::vector<cmSourceGroup> SourceGroups;
  755. #endif
  756. std::vector<DefinitionMap> DefinitionStack;
  757. std::vector<cmCommand*> UsedCommands;
  758. cmLocalGenerator* LocalGenerator;
  759. bool IsFunctionBlocked(const cmListFileFunction& lff,
  760. cmExecutionStatus &status);
  761. private:
  762. void Initialize();
  763. bool ParseDefineFlag(std::string const& definition, bool remove);
  764. void ReadSources(std::ifstream& fin, bool t);
  765. friend class cmMakeDepend; // make depend needs direct access
  766. // to the Sources array
  767. void PrintStringVector(const char* s, const
  768. std::vector<std::pair<cmStdString, bool> >& v) const;
  769. void PrintStringVector(const char* s,
  770. const std::vector<std::string>& v) const;
  771. void AddDefaultDefinitions();
  772. typedef std::vector<cmFunctionBlocker*> FunctionBlockersType;
  773. FunctionBlockersType FunctionBlockers;
  774. std::vector<FunctionBlockersType::size_type> FunctionBlockerBarriers;
  775. void PushFunctionBlockerBarrier();
  776. void PopFunctionBlockerBarrier(bool reportError = true);
  777. typedef std::map<cmStdString, cmData*> DataMapType;
  778. DataMapType DataMap;
  779. typedef std::map<cmStdString, cmStdString> StringStringMap;
  780. StringStringMap MacrosMap;
  781. std::map<cmStdString, bool> SubDirectoryOrder;
  782. // used in AddDefinition for performance improvement
  783. DefinitionMap::key_type TemporaryDefinitionKey;
  784. cmsys::RegularExpression cmDefineRegex;
  785. cmsys::RegularExpression cmDefine01Regex;
  786. cmsys::RegularExpression cmAtVarRegex;
  787. cmPropertyMap Properties;
  788. // should this makefile be processed before or after processing the parent
  789. bool PreOrder;
  790. // stack of list files being read
  791. std::deque<cmStdString> ListFileStack;
  792. // stack of commands being invoked.
  793. struct CallStackEntry
  794. {
  795. cmListFileContext const* Context;
  796. cmExecutionStatus* Status;
  797. };
  798. typedef std::deque<CallStackEntry> CallStackType;
  799. CallStackType CallStack;
  800. friend class cmMakefileCall;
  801. cmTarget* FindBasicTarget(const char* name);
  802. std::vector<cmTarget*> ImportedTargetsOwned;
  803. std::map<cmStdString, cmTarget*> ImportedTargets;
  804. // Internal policy stack management.
  805. void PushPolicy();
  806. void PopPolicy();
  807. void PushPolicyBarrier();
  808. void PopPolicyBarrier(bool reportError = true);
  809. friend class cmCMakePolicyCommand;
  810. class IncludeScope;
  811. friend class IncludeScope;
  812. // stack of policy settings
  813. struct PolicyStackEntry: public cmPolicies::PolicyMap
  814. {
  815. typedef cmPolicies::PolicyMap derived;
  816. PolicyStackEntry(): derived() {}
  817. PolicyStackEntry(derived const& d): derived(d) {}
  818. PolicyStackEntry(PolicyStackEntry const& r): derived(r) {}
  819. };
  820. typedef std::vector<PolicyStackEntry> PolicyStackType;
  821. PolicyStackType PolicyStack;
  822. std::vector<PolicyStackType::size_type> PolicyBarriers;
  823. cmPolicies::PolicyStatus GetPolicyStatusInternal(cmPolicies::PolicyID id);
  824. bool CheckCMP0000;
  825. // Enforce rules about CMakeLists.txt files.
  826. void EnforceDirectoryLevelRules();
  827. };
  828. //----------------------------------------------------------------------------
  829. // Helper class to make sure the call stack is valid.
  830. class cmMakefileCall
  831. {
  832. public:
  833. cmMakefileCall(cmMakefile* mf,
  834. cmListFileContext const& lfc,
  835. cmExecutionStatus& status): Makefile(mf)
  836. {
  837. cmMakefile::CallStackEntry entry = {&lfc, &status};
  838. this->Makefile->CallStack.push_back(entry);
  839. }
  840. ~cmMakefileCall()
  841. {
  842. this->Makefile->CallStack.pop_back();
  843. }
  844. private:
  845. cmMakefile* Makefile;
  846. };
  847. #endif