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. * Add bool variable definition to the build.
  254. */
  255. void AddDefinition(const char* name, bool);
  256. /**
  257. * Remove a variable definition from the build. This is not valid
  258. * for cache entries, and will only affect the current makefile.
  259. */
  260. void RemoveDefinition(const char* name);
  261. ///! Remove a definition from the cache.
  262. void RemoveCacheDefinition(const char* name);
  263. /**
  264. * Specify the name of the project for this build.
  265. */
  266. void SetProjectName(const char*);
  267. /**
  268. * Get the name of the project for this build.
  269. */
  270. const char* GetProjectName() const
  271. {
  272. return this->ProjectName.c_str();
  273. }
  274. /**
  275. * Set the name of the library.
  276. */
  277. void AddLibrary(const char *libname, cmTarget::TargetType type,
  278. const std::vector<std::string> &srcs,
  279. bool excludeFromAll = false);
  280. #if defined(CMAKE_BUILD_WITH_CMAKE)
  281. /**
  282. * Add a root source group for consideration when adding a new source.
  283. */
  284. void AddSourceGroup(const char* name, const char* regex=0);
  285. /**
  286. * Add a source group for consideration when adding a new source.
  287. * name is tokenized.
  288. */
  289. void AddSourceGroup(const std::vector<std::string>& name,
  290. const char* regex=0);
  291. #endif
  292. //@{
  293. /**
  294. * Set, Push, Pop policy values for CMake.
  295. */
  296. bool SetPolicy(cmPolicies::PolicyID id, cmPolicies::PolicyStatus status);
  297. bool SetPolicy(const char *id, cmPolicies::PolicyStatus status);
  298. cmPolicies::PolicyStatus GetPolicyStatus(cmPolicies::PolicyID id);
  299. bool SetPolicyVersion(const char *version);
  300. void RecordPolicies(cmPolicies::PolicyMap& pm);
  301. //@}
  302. /** Helper class to push and pop policies automatically. */
  303. class PolicyPushPop
  304. {
  305. public:
  306. PolicyPushPop(cmMakefile* m,
  307. bool weak = false,
  308. cmPolicies::PolicyMap const& pm = cmPolicies::PolicyMap());
  309. ~PolicyPushPop();
  310. void Quiet() { this->ReportError = false; }
  311. private:
  312. cmMakefile* Makefile;
  313. bool ReportError;
  314. };
  315. friend class PolicyPushPop;
  316. /**
  317. * Get the Policies Instance
  318. */
  319. cmPolicies *GetPolicies();
  320. /**
  321. * Add an auxiliary directory to the build.
  322. */
  323. void AddExtraDirectory(const char* dir);
  324. /**
  325. * Add an auxiliary directory to the build.
  326. */
  327. void MakeStartDirectoriesCurrent()
  328. {
  329. this->AddDefinition("CMAKE_CURRENT_SOURCE_DIR",
  330. this->cmStartDirectory.c_str());
  331. this->AddDefinition("CMAKE_CURRENT_BINARY_DIR",
  332. this->StartOutputDirectory.c_str());
  333. }
  334. //@{
  335. /**
  336. * Set/Get the home directory (or output directory) in the project. The
  337. * home directory is the top directory of the project. It is where
  338. * CMakeSetup or configure was run. Remember that CMake processes
  339. * CMakeLists files by recursing up the tree starting at the StartDirectory
  340. * and going up until it reaches the HomeDirectory.
  341. */
  342. void SetHomeDirectory(const char* dir);
  343. const char* GetHomeDirectory() const
  344. {
  345. return this->cmHomeDirectory.c_str();
  346. }
  347. void SetHomeOutputDirectory(const char* lib);
  348. const char* GetHomeOutputDirectory() const
  349. {
  350. return this->HomeOutputDirectory.c_str();
  351. }
  352. //@}
  353. //@{
  354. /**
  355. * Set/Get the start directory (or output directory). The start directory
  356. * is the directory of the CMakeLists.txt file that started the current
  357. * round of processing. Remember that CMake processes CMakeLists files by
  358. * recursing up the tree starting at the StartDirectory and going up until
  359. * it reaches the HomeDirectory.
  360. */
  361. void SetStartDirectory(const char* dir)
  362. {
  363. this->cmStartDirectory = dir;
  364. cmSystemTools::ConvertToUnixSlashes(this->cmStartDirectory);
  365. this->cmStartDirectory =
  366. cmSystemTools::CollapseFullPath(this->cmStartDirectory.c_str());
  367. this->AddDefinition("CMAKE_CURRENT_SOURCE_DIR",
  368. this->cmStartDirectory.c_str());
  369. }
  370. const char* GetStartDirectory() const
  371. {
  372. return this->cmStartDirectory.c_str();
  373. }
  374. void SetStartOutputDirectory(const char* lib)
  375. {
  376. this->StartOutputDirectory = lib;
  377. cmSystemTools::ConvertToUnixSlashes(this->StartOutputDirectory);
  378. this->StartOutputDirectory =
  379. cmSystemTools::CollapseFullPath(this->StartOutputDirectory.c_str());
  380. cmSystemTools::MakeDirectory(this->StartOutputDirectory.c_str());
  381. this->AddDefinition("CMAKE_CURRENT_BINARY_DIR",
  382. this->StartOutputDirectory.c_str());
  383. }
  384. const char* GetStartOutputDirectory() const
  385. {
  386. return this->StartOutputDirectory.c_str();
  387. }
  388. //@}
  389. const char* GetCurrentDirectory() const
  390. {
  391. return this->cmStartDirectory.c_str();
  392. }
  393. const char* GetCurrentOutputDirectory() const
  394. {
  395. return this->StartOutputDirectory.c_str();
  396. }
  397. /* Get the current CMakeLists.txt file that is being processed. This
  398. * is just used in order to be able to 'branch' from one file to a second
  399. * transparently */
  400. const char* GetCurrentListFile() const
  401. {
  402. return this->cmCurrentListFile.c_str();
  403. }
  404. //@}
  405. /**
  406. * Set a regular expression that include files must match
  407. * in order to be considered as part of the depend information.
  408. */
  409. void SetIncludeRegularExpression(const char* regex)
  410. {
  411. this->IncludeFileRegularExpression = regex;
  412. }
  413. const char* GetIncludeRegularExpression()
  414. {
  415. return this->IncludeFileRegularExpression.c_str();
  416. }
  417. /**
  418. * Set a regular expression that include files that are not found
  419. * must match in order to be considered a problem.
  420. */
  421. void SetComplainRegularExpression(const char* regex)
  422. {
  423. this->ComplainFileRegularExpression = regex;
  424. }
  425. const char* GetComplainRegularExpression()
  426. {
  427. return this->ComplainFileRegularExpression.c_str();
  428. }
  429. /**
  430. * Get the list of targets
  431. */
  432. cmTargets &GetTargets() { return this->Targets; }
  433. /**
  434. * Get the list of targets, const version
  435. */
  436. const cmTargets &GetTargets() const { return this->Targets; }
  437. cmTarget* FindTarget(const char* name);
  438. /** Find a target to use in place of the given name. The target
  439. returned may be imported or built within the project. */
  440. cmTarget* FindTargetToUse(const char* name);
  441. /**
  442. * Get a list of include directories in the build.
  443. */
  444. std::vector<std::string>& GetIncludeDirectories()
  445. {
  446. return this->IncludeDirectories;
  447. }
  448. const std::vector<std::string>& GetIncludeDirectories() const
  449. {
  450. return this->IncludeDirectories;
  451. }
  452. void SetIncludeDirectories(const std::vector<std::string>& vec)
  453. {
  454. this->IncludeDirectories = vec;
  455. }
  456. /**
  457. * Mark include directories as system directories.
  458. */
  459. void AddSystemIncludeDirectory(const char* dir);
  460. bool IsSystemIncludeDirectory(const char* dir);
  461. /** Expand out any arguements in the vector that have ; separated
  462. * strings into multiple arguements. A new vector is created
  463. * containing the expanded versions of all arguments in argsIn.
  464. * This method differes from the one in cmSystemTools in that if
  465. * the CmakeLists file is version 1.2 or earlier it will check for
  466. * source lists being used without ${} around them
  467. */
  468. void ExpandSourceListArguments(std::vector<std::string> const& argsIn,
  469. std::vector<std::string>& argsOut,
  470. unsigned int startArgumentIndex);
  471. /** Get a cmSourceFile pointer for a given source name, if the name is
  472. * not found, then a null pointer is returned.
  473. */
  474. cmSourceFile* GetSource(const char* sourceName);
  475. /** Get a cmSourceFile pointer for a given source name, if the name is
  476. * not found, then create the source file and return it. generated
  477. * indicates if it is a generated file, this is used in determining
  478. * how to create the source file instance e.g. name
  479. */
  480. cmSourceFile* GetOrCreateSource(const char* sourceName,
  481. bool generated = false);
  482. /**
  483. * Obtain a list of auxiliary source directories.
  484. */
  485. std::vector<std::string>& GetAuxSourceDirectories()
  486. {return this->AuxSourceDirectories;}
  487. //@{
  488. /**
  489. * Return a list of extensions associated with source and header
  490. * files
  491. */
  492. const std::vector<std::string>& GetSourceExtensions() const
  493. {return this->SourceFileExtensions;}
  494. const std::vector<std::string>& GetHeaderExtensions() const
  495. {return this->HeaderFileExtensions;}
  496. //@}
  497. /**
  498. * Given a variable name, return its value (as a string).
  499. * If the variable is not found in this makefile instance, the
  500. * cache is then queried.
  501. */
  502. const char* GetDefinition(const char*) const;
  503. const char* GetSafeDefinition(const char*) const;
  504. const char* GetRequiredDefinition(const char* name) const;
  505. bool IsDefinitionSet(const char*) const;
  506. /**
  507. * Get the list of all variables in the current space. If argument
  508. * cacheonly is specified and is greater than 0, then only cache
  509. * variables will be listed.
  510. */
  511. std::vector<std::string> GetDefinitions(int cacheonly=0) const;
  512. /** Test a boolean cache entry to see if it is true or false,
  513. * returns false if no entry defined.
  514. */
  515. bool IsOn(const char* name) const;
  516. bool IsSet(const char* name) const;
  517. /** Return whether the target platform is 64-bit. */
  518. bool PlatformIs64Bit() const;
  519. /**
  520. * Get a list of preprocessor define flags.
  521. */
  522. const char* GetDefineFlags()
  523. {return this->DefineFlags.c_str();}
  524. /**
  525. * Make sure CMake can write this file
  526. */
  527. bool CanIWriteThisFile(const char* fileName);
  528. /**
  529. * Get the vector of used command instances.
  530. */
  531. const std::vector<cmCommand*>& GetUsedCommands() const
  532. {return this->UsedCommands;}
  533. #if defined(CMAKE_BUILD_WITH_CMAKE)
  534. /**
  535. * Get the vector source groups.
  536. */
  537. const std::vector<cmSourceGroup>& GetSourceGroups() const
  538. { return this->SourceGroups; }
  539. /**
  540. * Get the source group
  541. */
  542. cmSourceGroup* GetSourceGroup(const std::vector<std::string>&name);
  543. #endif
  544. /**
  545. * Get the vector of list files on which this makefile depends
  546. */
  547. const std::vector<std::string>& GetListFiles() const
  548. { return this->ListFiles; }
  549. ///! When the file changes cmake will be re-run from the build system.
  550. void AddCMakeDependFile(const char* file)
  551. { this->ListFiles.push_back(file);}
  552. /**
  553. * Get the list file stack as a string
  554. */
  555. std::string GetListFileStack();
  556. /**
  557. * Get the current context backtrace.
  558. */
  559. bool GetBacktrace(cmListFileBacktrace& backtrace) const;
  560. /**
  561. * Get the vector of files created by this makefile
  562. */
  563. const std::vector<std::string>& GetOutputFiles() const
  564. { return this->OutputFiles; }
  565. void AddCMakeOutputFile(const char* file)
  566. { this->OutputFiles.push_back(file);}
  567. /**
  568. * Expand all defined variables in the string.
  569. * Defined variables come from the this->Definitions map.
  570. * They are expanded with ${var} where var is the
  571. * entry in the this->Definitions map. Also @var@ is
  572. * expanded to match autoconf style expansions.
  573. */
  574. const char *ExpandVariablesInString(std::string& source);
  575. const char *ExpandVariablesInString(std::string& source, bool escapeQuotes,
  576. bool noEscapes,
  577. bool atOnly = false,
  578. const char* filename = 0,
  579. long line = -1,
  580. bool removeEmpty = false,
  581. bool replaceAt = true);
  582. /**
  583. * Remove any remaining variables in the string. Anything with ${var} or
  584. * @var@ will be removed.
  585. */
  586. void RemoveVariablesInString(std::string& source,
  587. bool atOnly = false) const;
  588. /**
  589. * Expand variables in the makefiles ivars such as link directories etc
  590. */
  591. void ExpandVariables();
  592. /**
  593. * Replace variables and #cmakedefine lines in the given string.
  594. * See cmConfigureFileCommand for details.
  595. */
  596. void ConfigureString(const std::string& input, std::string& output,
  597. bool atOnly, bool escapeQuotes);
  598. /**
  599. * Copy file but change lines acording to ConfigureString
  600. */
  601. int ConfigureFile(const char* infile, const char* outfile,
  602. bool copyonly, bool atOnly, bool escapeQuotes);
  603. #if defined(CMAKE_BUILD_WITH_CMAKE)
  604. /**
  605. * find what source group this source is in
  606. */
  607. cmSourceGroup& FindSourceGroup(const char* source,
  608. std::vector<cmSourceGroup> &groups);
  609. #endif
  610. void RegisterData(cmData*);
  611. void RegisterData(const char*, cmData*);
  612. cmData* LookupData(const char*) const;
  613. /**
  614. * Execute a single CMake command. Returns true if the command
  615. * succeeded or false if it failed.
  616. */
  617. bool ExecuteCommand(const cmListFileFunction& lff,
  618. cmExecutionStatus &status);
  619. /** Check if a command exists. */
  620. bool CommandExists(const char* name) const;
  621. /**
  622. * Add a command to this cmake instance
  623. */
  624. void AddCommand(cmCommand* );
  625. ///! Enable support for named language, if nil then all languages are
  626. ///enabled.
  627. void EnableLanguage(std::vector<std::string>const& languages, bool optional);
  628. /**
  629. * Set/Get the name of the parent directories CMakeLists file
  630. * given a current CMakeLists file name
  631. */
  632. cmCacheManager *GetCacheManager() const;
  633. /**
  634. * Get the variable watch. This is used to determine when certain variables
  635. * are accessed.
  636. */
  637. #ifdef CMAKE_BUILD_WITH_CMAKE
  638. cmVariableWatch* GetVariableWatch() const;
  639. #endif
  640. ///! Display progress or status message.
  641. void DisplayStatus(const char*, float);
  642. /**
  643. * Expand the given list file arguments into the full set after
  644. * variable replacement and list expansion.
  645. */
  646. bool ExpandArguments(std::vector<cmListFileArgument> const& inArgs,
  647. std::vector<std::string>& outArgs);
  648. /**
  649. * Get the instance
  650. */
  651. cmake *GetCMakeInstance() const;
  652. /**
  653. * Get all the source files this makefile knows about
  654. */
  655. const std::vector<cmSourceFile*> &GetSourceFiles() const
  656. {return this->SourceFiles;}
  657. std::vector<cmSourceFile*> &GetSourceFiles() {return this->SourceFiles;}
  658. /**
  659. * Is there a source file that has the provided source file as an output?
  660. * if so then return it
  661. */
  662. cmSourceFile *GetSourceFileWithOutput(const char *outName);
  663. /**
  664. * Add a macro to the list of macros. The arguments should be name of the
  665. * macro and a documentation signature of it
  666. */
  667. void AddMacro(const char* name, const char* signature);
  668. ///! Add a new cmTest to the list of tests for this makefile.
  669. cmTest* CreateTest(const char* testName);
  670. /** Get a cmTest pointer for a given test name, if the name is
  671. * not found, then a null pointer is returned.
  672. */
  673. cmTest* GetTest(const char* testName) const;
  674. /**
  675. * Get a list of macros as a ; separated string
  676. */
  677. void GetListOfMacros(std::string& macros);
  678. /**
  679. * Return a location of a file in cmake or custom modules directory
  680. */
  681. std::string GetModulesFile(const char* name);
  682. ///! Set/Get a property of this directory
  683. void SetProperty(const char *prop, const char *value);
  684. void AppendProperty(const char *prop, const char *value);
  685. const char *GetProperty(const char *prop);
  686. const char *GetPropertyOrDefinition(const char *prop);
  687. const char *GetProperty(const char *prop, cmProperty::ScopeType scope);
  688. bool GetPropertyAsBool(const char *prop);
  689. const char* GetFeature(const char* feature, const char* config);
  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