cmMakefile.h 28 KB

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