cmMakefile.h 36 KB

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