cmMakefile.h 32 KB

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