cmMakefile.h 32 KB

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