cmMakefile.h 39 KB

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