cmMakefile.h 40 KB

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