cmMakefile.h 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925
  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. cmTarget* 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. bool force = false);
  234. /**
  235. * Add bool variable definition to the build.
  236. */
  237. void AddDefinition(const char* name, bool);
  238. ///! Add a definition to this makefile and the global cmake cache.
  239. void AddCacheDefinition(const char* name, bool, const char* doc);
  240. /**
  241. * Remove a variable definition from the build. This is not valid
  242. * for cache entries, and will only affect the current makefile.
  243. */
  244. void RemoveDefinition(const char* name);
  245. ///! Remove a definition from the cache.
  246. void RemoveCacheDefinition(const char* name);
  247. /**
  248. * Specify the name of the project for this build.
  249. */
  250. void SetProjectName(const char*);
  251. /**
  252. * Get the name of the project for this build.
  253. */
  254. const char* GetProjectName() const
  255. {
  256. return this->ProjectName.c_str();
  257. }
  258. /**
  259. * Set the name of the library.
  260. */
  261. void AddLibrary(const char *libname, cmTarget::TargetType type,
  262. const std::vector<std::string> &srcs,
  263. bool excludeFromAll = false);
  264. #if defined(CMAKE_BUILD_WITH_CMAKE)
  265. /**
  266. * Add a root source group for consideration when adding a new source.
  267. */
  268. void AddSourceGroup(const char* name, const char* regex=0);
  269. /**
  270. * Add a source group for consideration when adding a new source.
  271. * name is tokenized.
  272. */
  273. void AddSourceGroup(const std::vector<std::string>& name,
  274. const char* regex=0);
  275. #endif
  276. //@{
  277. /**
  278. * Set, Push, Pop policy values for CMake.
  279. */
  280. bool SetPolicy(cmPolicies::PolicyID id, cmPolicies::PolicyStatus status);
  281. bool SetPolicy(const char *id, cmPolicies::PolicyStatus status);
  282. cmPolicies::PolicyStatus GetPolicyStatus(cmPolicies::PolicyID id);
  283. bool PushPolicy();
  284. bool PopPolicy(bool reportError = true);
  285. bool SetPolicyVersion(const char *version);
  286. //@}
  287. /**
  288. * Get the Policies Instance
  289. */
  290. cmPolicies *GetPolicies();
  291. /**
  292. * Add an auxiliary directory to the build.
  293. */
  294. void AddExtraDirectory(const char* dir);
  295. /**
  296. * Add an auxiliary directory to the build.
  297. */
  298. void MakeStartDirectoriesCurrent()
  299. {
  300. this->AddDefinition("CMAKE_CURRENT_SOURCE_DIR",
  301. this->cmStartDirectory.c_str());
  302. this->AddDefinition("CMAKE_CURRENT_BINARY_DIR",
  303. this->StartOutputDirectory.c_str());
  304. }
  305. //@{
  306. /**
  307. * Set/Get the home directory (or output directory) in the project. The
  308. * home directory is the top directory of the project. It is where
  309. * CMakeSetup or configure was run. Remember that CMake processes
  310. * CMakeLists files by recursing up the tree starting at the StartDirectory
  311. * and going up until it reaches the HomeDirectory.
  312. */
  313. void SetHomeDirectory(const char* dir);
  314. const char* GetHomeDirectory() const
  315. {
  316. return this->cmHomeDirectory.c_str();
  317. }
  318. void SetHomeOutputDirectory(const char* lib);
  319. const char* GetHomeOutputDirectory() const
  320. {
  321. return this->HomeOutputDirectory.c_str();
  322. }
  323. //@}
  324. //@{
  325. /**
  326. * Set/Get the start directory (or output directory). The start directory
  327. * is the directory of the CMakeLists.txt file that started the current
  328. * round of processing. Remember that CMake processes CMakeLists files by
  329. * recursing up the tree starting at the StartDirectory and going up until
  330. * it reaches the HomeDirectory.
  331. */
  332. void SetStartDirectory(const char* dir)
  333. {
  334. this->cmStartDirectory = dir;
  335. cmSystemTools::ConvertToUnixSlashes(this->cmStartDirectory);
  336. this->cmStartDirectory =
  337. cmSystemTools::CollapseFullPath(this->cmStartDirectory.c_str());
  338. this->AddDefinition("CMAKE_CURRENT_SOURCE_DIR",
  339. this->cmStartDirectory.c_str());
  340. }
  341. const char* GetStartDirectory() const
  342. {
  343. return this->cmStartDirectory.c_str();
  344. }
  345. void SetStartOutputDirectory(const char* lib)
  346. {
  347. this->StartOutputDirectory = lib;
  348. cmSystemTools::ConvertToUnixSlashes(this->StartOutputDirectory);
  349. this->StartOutputDirectory =
  350. cmSystemTools::CollapseFullPath(this->StartOutputDirectory.c_str());
  351. cmSystemTools::MakeDirectory(this->StartOutputDirectory.c_str());
  352. this->AddDefinition("CMAKE_CURRENT_BINARY_DIR",
  353. this->StartOutputDirectory.c_str());
  354. }
  355. const char* GetStartOutputDirectory() const
  356. {
  357. return this->StartOutputDirectory.c_str();
  358. }
  359. //@}
  360. const char* GetCurrentDirectory() const
  361. {
  362. return this->cmStartDirectory.c_str();
  363. }
  364. const char* GetCurrentOutputDirectory() const
  365. {
  366. return this->StartOutputDirectory.c_str();
  367. }
  368. /* Get the current CMakeLists.txt file that is being processed. This
  369. * is just used in order to be able to 'branch' from one file to a second
  370. * transparently */
  371. const char* GetCurrentListFile() const
  372. {
  373. return this->cmCurrentListFile.c_str();
  374. }
  375. //@}
  376. /**
  377. * Set a regular expression that include files must match
  378. * in order to be considered as part of the depend information.
  379. */
  380. void SetIncludeRegularExpression(const char* regex)
  381. {
  382. this->IncludeFileRegularExpression = regex;
  383. }
  384. const char* GetIncludeRegularExpression()
  385. {
  386. return this->IncludeFileRegularExpression.c_str();
  387. }
  388. /**
  389. * Set a regular expression that include files that are not found
  390. * must match in order to be considered a problem.
  391. */
  392. void SetComplainRegularExpression(const char* regex)
  393. {
  394. this->ComplainFileRegularExpression = regex;
  395. }
  396. const char* GetComplainRegularExpression()
  397. {
  398. return this->ComplainFileRegularExpression.c_str();
  399. }
  400. /**
  401. * Get the list of targets
  402. */
  403. cmTargets &GetTargets() { return this->Targets; }
  404. /**
  405. * Get the list of targets, const version
  406. */
  407. const cmTargets &GetTargets() const { return this->Targets; }
  408. cmTarget* FindTarget(const char* name);
  409. /** Find a target to use in place of the given name. The target
  410. returned may be imported or built within the project. */
  411. cmTarget* FindTargetToUse(const char* name);
  412. /**
  413. * Get a list of include directories in the build.
  414. */
  415. std::vector<std::string>& GetIncludeDirectories()
  416. {
  417. return this->IncludeDirectories;
  418. }
  419. const std::vector<std::string>& GetIncludeDirectories() const
  420. {
  421. return this->IncludeDirectories;
  422. }
  423. void SetIncludeDirectories(const std::vector<std::string>& vec)
  424. {
  425. this->IncludeDirectories = vec;
  426. }
  427. /**
  428. * Mark include directories as system directories.
  429. */
  430. void AddSystemIncludeDirectory(const char* dir);
  431. bool IsSystemIncludeDirectory(const char* dir);
  432. /** Expand out any arguements in the vector that have ; separated
  433. * strings into multiple arguements. A new vector is created
  434. * containing the expanded versions of all arguments in argsIn.
  435. * This method differes from the one in cmSystemTools in that if
  436. * the CmakeLists file is version 1.2 or earlier it will check for
  437. * source lists being used without ${} around them
  438. */
  439. void ExpandSourceListArguments(std::vector<std::string> const& argsIn,
  440. std::vector<std::string>& argsOut,
  441. unsigned int startArgumentIndex);
  442. /** Get a cmSourceFile pointer for a given source name, if the name is
  443. * not found, then a null pointer is returned.
  444. */
  445. cmSourceFile* GetSource(const char* sourceName);
  446. /** Get a cmSourceFile pointer for a given source name, if the name is
  447. * not found, then create the source file and return it. generated
  448. * indicates if it is a generated file, this is used in determining
  449. * how to create the source file instance e.g. name
  450. */
  451. cmSourceFile* GetOrCreateSource(const char* sourceName,
  452. bool generated = false);
  453. /**
  454. * Obtain a list of auxiliary source directories.
  455. */
  456. std::vector<std::string>& GetAuxSourceDirectories()
  457. {return this->AuxSourceDirectories;}
  458. //@{
  459. /**
  460. * Return a list of extensions associated with source and header
  461. * files
  462. */
  463. const std::vector<std::string>& GetSourceExtensions() const
  464. {return this->SourceFileExtensions;}
  465. const std::vector<std::string>& GetHeaderExtensions() const
  466. {return this->HeaderFileExtensions;}
  467. //@}
  468. /**
  469. * Given a variable name, return its value (as a string).
  470. * If the variable is not found in this makefile instance, the
  471. * cache is then queried.
  472. */
  473. const char* GetDefinition(const char*) const;
  474. const char* GetSafeDefinition(const char*) const;
  475. const char* GetRequiredDefinition(const char* name) const;
  476. bool IsDefinitionSet(const char*) const;
  477. /**
  478. * Get the list of all variables in the current space. If argument
  479. * cacheonly is specified and is greater than 0, then only cache
  480. * variables will be listed.
  481. */
  482. std::vector<std::string> GetDefinitions(int cacheonly=0) const;
  483. /** Test a boolean cache entry to see if it is true or false,
  484. * returns false if no entry defined.
  485. */
  486. bool IsOn(const char* name) const;
  487. bool IsSet(const char* name) const;
  488. /**
  489. * Get a list of preprocessor define flags.
  490. */
  491. const char* GetDefineFlags()
  492. {return this->DefineFlags.c_str();}
  493. /**
  494. * Make sure CMake can write this file
  495. */
  496. bool CanIWriteThisFile(const char* fileName);
  497. /**
  498. * Get the vector of used command instances.
  499. */
  500. const std::vector<cmCommand*>& GetUsedCommands() const
  501. {return this->UsedCommands;}
  502. #if defined(CMAKE_BUILD_WITH_CMAKE)
  503. /**
  504. * Get the vector source groups.
  505. */
  506. const std::vector<cmSourceGroup>& GetSourceGroups() const
  507. { return this->SourceGroups; }
  508. /**
  509. * Get the source group
  510. */
  511. cmSourceGroup* GetSourceGroup(const std::vector<std::string>&name);
  512. #endif
  513. /**
  514. * Get the vector of list files on which this makefile depends
  515. */
  516. const std::vector<std::string>& GetListFiles() const
  517. { return this->ListFiles; }
  518. ///! When the file changes cmake will be re-run from the build system.
  519. void AddCMakeDependFile(const char* file)
  520. { this->ListFiles.push_back(file);}
  521. /**
  522. * Get the list file stack as a string
  523. */
  524. std::string GetListFileStack();
  525. /**
  526. * Get the current context backtrace.
  527. */
  528. bool GetBacktrace(cmListFileBacktrace& backtrace) const;
  529. /**
  530. * Get the vector of files created by this makefile
  531. */
  532. const std::vector<std::string>& GetOutputFiles() const
  533. { return this->OutputFiles; }
  534. void AddCMakeOutputFile(const char* file)
  535. { this->OutputFiles.push_back(file);}
  536. /**
  537. * Expand all defined variables in the string.
  538. * Defined variables come from the this->Definitions map.
  539. * They are expanded with ${var} where var is the
  540. * entry in the this->Definitions map. Also @var@ is
  541. * expanded to match autoconf style expansions.
  542. */
  543. const char *ExpandVariablesInString(std::string& source);
  544. const char *ExpandVariablesInString(std::string& source, bool escapeQuotes,
  545. bool noEscapes,
  546. bool atOnly = false,
  547. const char* filename = 0,
  548. long line = -1,
  549. bool removeEmpty = false,
  550. bool replaceAt = true);
  551. /**
  552. * Remove any remaining variables in the string. Anything with ${var} or
  553. * @var@ will be removed.
  554. */
  555. void RemoveVariablesInString(std::string& source,
  556. bool atOnly = false) const;
  557. /**
  558. * Expand variables in the makefiles ivars such as link directories etc
  559. */
  560. void ExpandVariables();
  561. /**
  562. * Replace variables and #cmakedefine lines in the given string.
  563. * See cmConfigureFileCommand for details.
  564. */
  565. void ConfigureString(const std::string& input, std::string& output,
  566. bool atOnly, bool escapeQuotes);
  567. /**
  568. * Copy file but change lines acording to ConfigureString
  569. */
  570. int ConfigureFile(const char* infile, const char* outfile,
  571. bool copyonly, bool atOnly, bool escapeQuotes);
  572. #if defined(CMAKE_BUILD_WITH_CMAKE)
  573. /**
  574. * find what source group this source is in
  575. */
  576. cmSourceGroup& FindSourceGroup(const char* source,
  577. std::vector<cmSourceGroup> &groups);
  578. #endif
  579. void RegisterData(cmData*);
  580. void RegisterData(const char*, cmData*);
  581. cmData* LookupData(const char*) const;
  582. /**
  583. * Execute a single CMake command. Returns true if the command
  584. * succeeded or false if it failed.
  585. */
  586. bool ExecuteCommand(const cmListFileFunction& lff,
  587. cmExecutionStatus &status);
  588. /** Check if a command exists. */
  589. bool CommandExists(const char* name) const;
  590. /**
  591. * Add a command to this cmake instance
  592. */
  593. void AddCommand(cmCommand* );
  594. ///! Enable support for named language, if nil then all languages are
  595. ///enabled.
  596. void EnableLanguage(std::vector<std::string>const& languages, bool optional);
  597. /**
  598. * Set/Get the name of the parent directories CMakeLists file
  599. * given a current CMakeLists file name
  600. */
  601. cmCacheManager *GetCacheManager() const;
  602. /**
  603. * Get the variable watch. This is used to determine when certain variables
  604. * are accessed.
  605. */
  606. #ifdef CMAKE_BUILD_WITH_CMAKE
  607. cmVariableWatch* GetVariableWatch() const;
  608. #endif
  609. ///! Display progress or status message.
  610. void DisplayStatus(const char*, float);
  611. /**
  612. * Expand the given list file arguments into the full set after
  613. * variable replacement and list expansion.
  614. */
  615. bool ExpandArguments(std::vector<cmListFileArgument> const& inArgs,
  616. std::vector<std::string>& outArgs);
  617. /**
  618. * Get the instance
  619. */
  620. cmake *GetCMakeInstance() const;
  621. /**
  622. * Get all the source files this makefile knows about
  623. */
  624. const std::vector<cmSourceFile*> &GetSourceFiles() const
  625. {return this->SourceFiles;}
  626. std::vector<cmSourceFile*> &GetSourceFiles() {return this->SourceFiles;}
  627. /**
  628. * Is there a source file that has the provided source file as an output?
  629. * if so then return it
  630. */
  631. cmSourceFile *GetSourceFileWithOutput(const char *outName);
  632. /**
  633. * Add a macro to the list of macros. The arguments should be name of the
  634. * macro and a documentation signature of it
  635. */
  636. void AddMacro(const char* name, const char* signature);
  637. ///! Add a new cmTest to the list of tests for this makefile.
  638. cmTest* CreateTest(const char* testName);
  639. /** Get a cmTest pointer for a given test name, if the name is
  640. * not found, then a null pointer is returned.
  641. */
  642. cmTest* GetTest(const char* testName) const;
  643. const std::vector<cmTest*> *GetTests() const;
  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. /** Helper class to push and pop scopes automatically. */
  678. class ScopePushPop
  679. {
  680. public:
  681. ScopePushPop(cmMakefile* m): Makefile(m) { this->Makefile->PushScope(); }
  682. ~ScopePushPop() { this->Makefile->PopScope(); }
  683. private:
  684. cmMakefile* Makefile;
  685. };
  686. void IssueMessage(cmake::MessageType t,
  687. std::string const& text) const;
  688. /** Set whether or not to report a CMP0000 violation. */
  689. void SetCheckCMP0000(bool b) { this->CheckCMP0000 = b; }
  690. protected:
  691. // add link libraries and directories to the target
  692. void AddGlobalLinkInformation(const char* name, cmTarget& target);
  693. std::string Prefix;
  694. std::vector<std::string> AuxSourceDirectories; //
  695. std::string cmStartDirectory;
  696. std::string StartOutputDirectory;
  697. std::string cmHomeDirectory;
  698. std::string HomeOutputDirectory;
  699. std::string cmCurrentListFile;
  700. std::string ProjectName; // project name
  701. // libraries, classes, and executables
  702. cmTargets Targets;
  703. std::vector<cmSourceFile*> SourceFiles;
  704. // Tests
  705. std::map<cmStdString, cmTest*> Tests;
  706. std::vector<cmTest*> OrderedTests;
  707. // The include and link-library paths. These may have order
  708. // dependency, so they must be vectors (not set).
  709. std::vector<std::string> IncludeDirectories;
  710. std::vector<std::string> LinkDirectories;
  711. // The set of include directories that are marked as system include
  712. // directories.
  713. std::set<cmStdString> SystemIncludeDirectories;
  714. std::vector<std::string> ListFiles; // list of command files loaded
  715. std::vector<std::string> OutputFiles; // list of command files loaded
  716. cmTarget::LinkLibraryVectorType LinkLibraries;
  717. std::vector<cmInstallGenerator*> InstallGenerators;
  718. std::string IncludeFileRegularExpression;
  719. std::string ComplainFileRegularExpression;
  720. std::vector<std::string> SourceFileExtensions;
  721. std::vector<std::string> HeaderFileExtensions;
  722. std::string DefineFlags;
  723. // Track the value of the computed DEFINITIONS property.
  724. void AddDefineFlag(const char*, std::string&);
  725. void RemoveDefineFlag(const char*, std::string::size_type, std::string&);
  726. std::string DefineFlagsOrig;
  727. #if defined(CMAKE_BUILD_WITH_CMAKE)
  728. std::vector<cmSourceGroup> SourceGroups;
  729. #endif
  730. std::vector<DefinitionMap> DefinitionStack;
  731. std::vector<cmCommand*> UsedCommands;
  732. cmLocalGenerator* LocalGenerator;
  733. bool IsFunctionBlocked(const cmListFileFunction& lff,
  734. cmExecutionStatus &status);
  735. private:
  736. void Initialize();
  737. bool ParseDefineFlag(std::string const& definition, bool remove);
  738. void ReadSources(std::ifstream& fin, bool t);
  739. friend class cmMakeDepend; // make depend needs direct access
  740. // to the Sources array
  741. void PrintStringVector(const char* s, const
  742. std::vector<std::pair<cmStdString, bool> >& v) const;
  743. void PrintStringVector(const char* s,
  744. const std::vector<std::string>& v) const;
  745. void AddDefaultDefinitions();
  746. std::list<cmFunctionBlocker *> FunctionBlockers;
  747. typedef std::map<cmStdString, cmData*> DataMapType;
  748. DataMapType DataMap;
  749. typedef std::map<cmStdString, cmStdString> StringStringMap;
  750. StringStringMap MacrosMap;
  751. std::map<cmStdString, bool> SubDirectoryOrder;
  752. // used in AddDefinition for performance improvement
  753. DefinitionMap::key_type TemporaryDefinitionKey;
  754. cmsys::RegularExpression cmDefineRegex;
  755. cmsys::RegularExpression cmDefine01Regex;
  756. cmsys::RegularExpression cmAtVarRegex;
  757. cmPropertyMap Properties;
  758. // should this makefile be processed before or after processing the parent
  759. bool PreOrder;
  760. // stack of list files being read
  761. std::deque<cmStdString> ListFileStack;
  762. // stack of commands being invoked.
  763. struct CallStackEntry
  764. {
  765. cmListFileContext const* Context;
  766. cmExecutionStatus* Status;
  767. };
  768. typedef std::deque<CallStackEntry> CallStackType;
  769. CallStackType CallStack;
  770. friend class cmMakefileCall;
  771. cmTarget* FindBasicTarget(const char* name);
  772. std::vector<cmTarget*> ImportedTargetsOwned;
  773. std::map<cmStdString, cmTarget*> ImportedTargets;
  774. // stack of policy settings
  775. typedef std::map<cmPolicies::PolicyID,
  776. cmPolicies::PolicyStatus> PolicyMap;
  777. std::vector<PolicyMap> PolicyStack;
  778. cmPolicies::PolicyStatus GetPolicyStatusInternal(cmPolicies::PolicyID id);
  779. bool CheckCMP0000;
  780. // Enforce rules about CMakeLists.txt files.
  781. void EnforceDirectoryLevelRules(bool endScopeNicely);
  782. };
  783. #endif