cmMakefile.h 31 KB

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