cmMakefile.h 31 KB

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