cmMakefile.h 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003
  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. /**
  522. * Get a list of preprocessor define flags.
  523. */
  524. const char* GetDefineFlags()
  525. {return this->DefineFlags.c_str();}
  526. /**
  527. * Make sure CMake can write this file
  528. */
  529. bool CanIWriteThisFile(const char* fileName);
  530. /**
  531. * Get the vector of used command instances.
  532. */
  533. const std::vector<cmCommand*>& GetUsedCommands() const
  534. {return this->UsedCommands;}
  535. #if defined(CMAKE_BUILD_WITH_CMAKE)
  536. /**
  537. * Get the vector source groups.
  538. */
  539. const std::vector<cmSourceGroup>& GetSourceGroups() const
  540. { return this->SourceGroups; }
  541. /**
  542. * Get the source group
  543. */
  544. cmSourceGroup* GetSourceGroup(const std::vector<std::string>&name);
  545. #endif
  546. /**
  547. * Get the vector of list files on which this makefile depends
  548. */
  549. const std::vector<std::string>& GetListFiles() const
  550. { return this->ListFiles; }
  551. ///! When the file changes cmake will be re-run from the build system.
  552. void AddCMakeDependFile(const char* file)
  553. { this->ListFiles.push_back(file);}
  554. /**
  555. * Get the list file stack as a string
  556. */
  557. std::string GetListFileStack();
  558. /**
  559. * Get the current context backtrace.
  560. */
  561. bool GetBacktrace(cmListFileBacktrace& backtrace) const;
  562. /**
  563. * Get the vector of files created by this makefile
  564. */
  565. const std::vector<std::string>& GetOutputFiles() const
  566. { return this->OutputFiles; }
  567. void AddCMakeOutputFile(const char* file)
  568. { this->OutputFiles.push_back(file);}
  569. /**
  570. * Expand all defined variables in the string.
  571. * Defined variables come from the this->Definitions map.
  572. * They are expanded with ${var} where var is the
  573. * entry in the this->Definitions map. Also @var@ is
  574. * expanded to match autoconf style expansions.
  575. */
  576. const char *ExpandVariablesInString(std::string& source);
  577. const char *ExpandVariablesInString(std::string& source, bool escapeQuotes,
  578. bool noEscapes,
  579. bool atOnly = false,
  580. const char* filename = 0,
  581. long line = -1,
  582. bool removeEmpty = false,
  583. bool replaceAt = true);
  584. /**
  585. * Remove any remaining variables in the string. Anything with ${var} or
  586. * @var@ will be removed.
  587. */
  588. void RemoveVariablesInString(std::string& source,
  589. bool atOnly = false) const;
  590. /**
  591. * Expand variables in the makefiles ivars such as link directories etc
  592. */
  593. void ExpandVariables();
  594. /**
  595. * Replace variables and #cmakedefine lines in the given string.
  596. * See cmConfigureFileCommand for details.
  597. */
  598. void ConfigureString(const std::string& input, std::string& output,
  599. bool atOnly, bool escapeQuotes);
  600. /**
  601. * Copy file but change lines acording to ConfigureString
  602. */
  603. int ConfigureFile(const char* infile, const char* outfile,
  604. bool copyonly, bool atOnly, bool escapeQuotes);
  605. #if defined(CMAKE_BUILD_WITH_CMAKE)
  606. /**
  607. * find what source group this source is in
  608. */
  609. cmSourceGroup& FindSourceGroup(const char* source,
  610. std::vector<cmSourceGroup> &groups);
  611. #endif
  612. void RegisterData(cmData*);
  613. void RegisterData(const char*, cmData*);
  614. cmData* LookupData(const char*) const;
  615. /**
  616. * Execute a single CMake command. Returns true if the command
  617. * succeeded or false if it failed.
  618. */
  619. bool ExecuteCommand(const cmListFileFunction& lff,
  620. cmExecutionStatus &status);
  621. /** Check if a command exists. */
  622. bool CommandExists(const char* name) const;
  623. /**
  624. * Add a command to this cmake instance
  625. */
  626. void AddCommand(cmCommand* );
  627. ///! Enable support for named language, if nil then all languages are
  628. ///enabled.
  629. void EnableLanguage(std::vector<std::string>const& languages, bool optional);
  630. /**
  631. * Set/Get the name of the parent directories CMakeLists file
  632. * given a current CMakeLists file name
  633. */
  634. cmCacheManager *GetCacheManager() const;
  635. /**
  636. * Get the variable watch. This is used to determine when certain variables
  637. * are accessed.
  638. */
  639. #ifdef CMAKE_BUILD_WITH_CMAKE
  640. cmVariableWatch* GetVariableWatch() const;
  641. #endif
  642. ///! Display progress or status message.
  643. void DisplayStatus(const char*, float);
  644. /**
  645. * Expand the given list file arguments into the full set after
  646. * variable replacement and list expansion.
  647. */
  648. bool ExpandArguments(std::vector<cmListFileArgument> const& inArgs,
  649. std::vector<std::string>& outArgs);
  650. /**
  651. * Get the instance
  652. */
  653. cmake *GetCMakeInstance() const;
  654. /**
  655. * Get all the source files this makefile knows about
  656. */
  657. const std::vector<cmSourceFile*> &GetSourceFiles() const
  658. {return this->SourceFiles;}
  659. std::vector<cmSourceFile*> &GetSourceFiles() {return this->SourceFiles;}
  660. /**
  661. * Is there a source file that has the provided source file as an output?
  662. * if so then return it
  663. */
  664. cmSourceFile *GetSourceFileWithOutput(const char *outName);
  665. /**
  666. * Add a macro to the list of macros. The arguments should be name of the
  667. * macro and a documentation signature of it
  668. */
  669. void AddMacro(const char* name, const char* signature);
  670. ///! Add a new cmTest to the list of tests for this makefile.
  671. cmTest* CreateTest(const char* testName);
  672. /** Get a cmTest pointer for a given test name, if the name is
  673. * not found, then a null pointer is returned.
  674. */
  675. cmTest* GetTest(const char* testName) const;
  676. /**
  677. * Get a list of macros as a ; separated string
  678. */
  679. void GetListOfMacros(std::string& macros);
  680. /**
  681. * Return a location of a file in cmake or custom modules directory
  682. */
  683. std::string GetModulesFile(const char* name);
  684. ///! Set/Get a property of this directory
  685. void SetProperty(const char *prop, const char *value);
  686. void AppendProperty(const char *prop, const char *value);
  687. const char *GetProperty(const char *prop);
  688. const char *GetPropertyOrDefinition(const char *prop);
  689. const char *GetProperty(const char *prop, cmProperty::ScopeType scope);
  690. bool GetPropertyAsBool(const char *prop);
  691. // Get the properties
  692. cmPropertyMap &GetProperties() { return this->Properties; };
  693. ///! Initialize a makefile from its parent
  694. void InitializeFromParent();
  695. ///! Set/Get the preorder flag
  696. void SetPreOrder(bool p) { this->PreOrder = p; }
  697. bool GetPreOrder() const { return this->PreOrder; }
  698. void AddInstallGenerator(cmInstallGenerator* g)
  699. { if(g) this->InstallGenerators.push_back(g); }
  700. std::vector<cmInstallGenerator*>& GetInstallGenerators()
  701. { return this->InstallGenerators; }
  702. void AddTestGenerator(cmTestGenerator* g)
  703. { if(g) this->TestGenerators.push_back(g); }
  704. std::vector<cmTestGenerator*>& GetTestGenerators()
  705. { return this->TestGenerators; }
  706. // Define the properties
  707. static void DefineProperties(cmake *cm);
  708. // push and pop variable scopes
  709. void PushScope();
  710. void PopScope();
  711. void RaiseScope(const char *var, const char *value);
  712. /** Helper class to push and pop scopes automatically. */
  713. class ScopePushPop
  714. {
  715. public:
  716. ScopePushPop(cmMakefile* m): Makefile(m) { this->Makefile->PushScope(); }
  717. ~ScopePushPop() { this->Makefile->PopScope(); }
  718. private:
  719. cmMakefile* Makefile;
  720. };
  721. void IssueMessage(cmake::MessageType t,
  722. std::string const& text) const;
  723. /** Set whether or not to report a CMP0000 violation. */
  724. void SetCheckCMP0000(bool b) { this->CheckCMP0000 = b; }
  725. protected:
  726. // add link libraries and directories to the target
  727. void AddGlobalLinkInformation(const char* name, cmTarget& target);
  728. std::string Prefix;
  729. std::vector<std::string> AuxSourceDirectories; //
  730. std::string cmStartDirectory;
  731. std::string StartOutputDirectory;
  732. std::string cmHomeDirectory;
  733. std::string HomeOutputDirectory;
  734. std::string cmCurrentListFile;
  735. std::string ProjectName; // project name
  736. // libraries, classes, and executables
  737. cmTargets Targets;
  738. std::vector<cmSourceFile*> SourceFiles;
  739. // Tests
  740. std::map<cmStdString, cmTest*> Tests;
  741. // The include and link-library paths. These may have order
  742. // dependency, so they must be vectors (not set).
  743. std::vector<std::string> IncludeDirectories;
  744. std::vector<std::string> LinkDirectories;
  745. // The set of include directories that are marked as system include
  746. // directories.
  747. std::set<cmStdString> SystemIncludeDirectories;
  748. std::vector<std::string> ListFiles; // list of command files loaded
  749. std::vector<std::string> OutputFiles; // list of command files loaded
  750. cmTarget::LinkLibraryVectorType LinkLibraries;
  751. std::vector<cmInstallGenerator*> InstallGenerators;
  752. std::vector<cmTestGenerator*> TestGenerators;
  753. std::string IncludeFileRegularExpression;
  754. std::string ComplainFileRegularExpression;
  755. std::vector<std::string> SourceFileExtensions;
  756. std::vector<std::string> HeaderFileExtensions;
  757. std::string DefineFlags;
  758. // Track the value of the computed DEFINITIONS property.
  759. void AddDefineFlag(const char*, std::string&);
  760. void RemoveDefineFlag(const char*, std::string::size_type, std::string&);
  761. std::string DefineFlagsOrig;
  762. #if defined(CMAKE_BUILD_WITH_CMAKE)
  763. std::vector<cmSourceGroup> SourceGroups;
  764. #endif
  765. std::vector<cmCommand*> UsedCommands;
  766. cmLocalGenerator* LocalGenerator;
  767. bool IsFunctionBlocked(const cmListFileFunction& lff,
  768. cmExecutionStatus &status);
  769. private:
  770. void Initialize();
  771. bool ParseDefineFlag(std::string const& definition, bool remove);
  772. bool EnforceUniqueDir(const char* srcPath, const char* binPath);
  773. void ReadSources(std::ifstream& fin, bool t);
  774. friend class cmMakeDepend; // make depend needs direct access
  775. // to the Sources array
  776. void PrintStringVector(const char* s, const
  777. std::vector<std::pair<cmStdString, bool> >& v) const;
  778. void PrintStringVector(const char* s,
  779. const std::vector<std::string>& v) const;
  780. void AddDefaultDefinitions();
  781. typedef std::vector<cmFunctionBlocker*> FunctionBlockersType;
  782. FunctionBlockersType FunctionBlockers;
  783. std::vector<FunctionBlockersType::size_type> FunctionBlockerBarriers;
  784. void PushFunctionBlockerBarrier();
  785. void PopFunctionBlockerBarrier(bool reportError = true);
  786. typedef std::map<cmStdString, cmData*> DataMapType;
  787. DataMapType DataMap;
  788. typedef std::map<cmStdString, cmStdString> StringStringMap;
  789. StringStringMap MacrosMap;
  790. std::map<cmStdString, bool> SubDirectoryOrder;
  791. cmsys::RegularExpression cmDefineRegex;
  792. cmsys::RegularExpression cmDefine01Regex;
  793. cmsys::RegularExpression cmAtVarRegex;
  794. cmPropertyMap Properties;
  795. // should this makefile be processed before or after processing the parent
  796. bool PreOrder;
  797. // stack of list files being read
  798. std::deque<cmStdString> ListFileStack;
  799. // stack of commands being invoked.
  800. struct CallStackEntry
  801. {
  802. cmListFileContext const* Context;
  803. cmExecutionStatus* Status;
  804. };
  805. typedef std::deque<CallStackEntry> CallStackType;
  806. CallStackType CallStack;
  807. friend class cmMakefileCall;
  808. cmTarget* FindBasicTarget(const char* name);
  809. std::vector<cmTarget*> ImportedTargetsOwned;
  810. std::map<cmStdString, cmTarget*> ImportedTargets;
  811. // Internal policy stack management.
  812. void PushPolicy(bool weak = false,
  813. cmPolicies::PolicyMap const& pm = cmPolicies::PolicyMap());
  814. void PopPolicy();
  815. void PushPolicyBarrier();
  816. void PopPolicyBarrier(bool reportError = true);
  817. friend class cmCMakePolicyCommand;
  818. class IncludeScope;
  819. friend class IncludeScope;
  820. // stack of policy settings
  821. struct PolicyStackEntry: public cmPolicies::PolicyMap
  822. {
  823. typedef cmPolicies::PolicyMap derived;
  824. PolicyStackEntry(bool w = false): derived(), Weak(w) {}
  825. PolicyStackEntry(derived const& d, bool w = false): derived(d), Weak(w) {}
  826. PolicyStackEntry(PolicyStackEntry const& r): derived(r), Weak(r.Weak) {}
  827. bool Weak;
  828. };
  829. typedef std::vector<PolicyStackEntry> PolicyStackType;
  830. PolicyStackType PolicyStack;
  831. std::vector<PolicyStackType::size_type> PolicyBarriers;
  832. cmPolicies::PolicyStatus GetPolicyStatusInternal(cmPolicies::PolicyID id);
  833. bool CheckCMP0000;
  834. // Enforce rules about CMakeLists.txt files.
  835. void EnforceDirectoryLevelRules();
  836. };
  837. //----------------------------------------------------------------------------
  838. // Helper class to make sure the call stack is valid.
  839. class cmMakefileCall
  840. {
  841. public:
  842. cmMakefileCall(cmMakefile* mf,
  843. cmListFileContext const& lfc,
  844. cmExecutionStatus& status): Makefile(mf)
  845. {
  846. cmMakefile::CallStackEntry entry = {&lfc, &status};
  847. this->Makefile->CallStack.push_back(entry);
  848. }
  849. ~cmMakefileCall()
  850. {
  851. this->Makefile->CallStack.pop_back();
  852. }
  853. private:
  854. cmMakefile* Makefile;
  855. };
  856. #endif