cmMakefile.h 29 KB

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