cmMakefile.h 34 KB

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