cmMakefile.h 31 KB

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