cmMakefile.h 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140
  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. bool CompileFeatureKnown(cmTarget const* target, const std::string& feature,
  769. std::string& lang, std::string *error) const;
  770. const char* CompileFeaturesAvailable(const std::string& lang,
  771. std::string *error) const;
  772. void ClearMatches();
  773. void StoreMatches(cmsys::RegularExpression& re);
  774. protected:
  775. // add link libraries and directories to the target
  776. void AddGlobalLinkInformation(const std::string& name, cmTarget& target);
  777. // Check for a an unused variable
  778. void CheckForUnused(const char* reason, const std::string& name) const;
  779. std::string Prefix;
  780. std::vector<std::string> AuxSourceDirectories; //
  781. std::string cmStartDirectory;
  782. std::string StartOutputDirectory;
  783. std::string cmHomeDirectory;
  784. std::string HomeOutputDirectory;
  785. std::string cmCurrentListFile;
  786. std::string ProjectName; // project name
  787. // libraries, classes, and executables
  788. mutable cmTargets Targets;
  789. #if defined(CMAKE_BUILD_WITH_CMAKE)
  790. typedef cmsys::hash_map<std::string, cmTarget*> TargetMap;
  791. #else
  792. typedef std::map<std::string, cmTarget*> TargetMap;
  793. #endif
  794. TargetMap AliasTargets;
  795. cmGeneratorTargetsType GeneratorTargets;
  796. std::vector<cmSourceFile*> SourceFiles;
  797. // Tests
  798. std::map<std::string, cmTest*> Tests;
  799. // The link-library paths. Order matters, use std::vector (not std::set).
  800. std::vector<std::string> LinkDirectories;
  801. // The set of include directories that are marked as system include
  802. // directories.
  803. std::set<std::string> SystemIncludeDirectories;
  804. std::vector<std::string> ListFiles; // list of command files loaded
  805. std::vector<std::string> OutputFiles; // list of command files loaded
  806. cmTarget::LinkLibraryVectorType LinkLibraries;
  807. std::vector<cmInstallGenerator*> InstallGenerators;
  808. std::vector<cmTestGenerator*> TestGenerators;
  809. std::string IncludeFileRegularExpression;
  810. std::string ComplainFileRegularExpression;
  811. std::vector<std::string> SourceFileExtensions;
  812. std::vector<std::string> HeaderFileExtensions;
  813. std::string DefineFlags;
  814. std::vector<cmValueWithOrigin> IncludeDirectoriesEntries;
  815. std::vector<cmValueWithOrigin> CompileOptionsEntries;
  816. std::vector<cmValueWithOrigin> CompileDefinitionsEntries;
  817. // Track the value of the computed DEFINITIONS property.
  818. void AddDefineFlag(const char*, std::string&);
  819. void RemoveDefineFlag(const char*, std::string::size_type, std::string&);
  820. std::string DefineFlagsOrig;
  821. #if defined(CMAKE_BUILD_WITH_CMAKE)
  822. std::vector<cmSourceGroup> SourceGroups;
  823. #endif
  824. std::vector<cmCommand*> FinalPassCommands;
  825. cmLocalGenerator* LocalGenerator;
  826. bool IsFunctionBlocked(const cmListFileFunction& lff,
  827. cmExecutionStatus &status);
  828. private:
  829. void Initialize();
  830. bool ParseDefineFlag(std::string const& definition, bool remove);
  831. bool EnforceUniqueDir(const std::string& srcPath,
  832. const std::string& binPath) const;
  833. friend class cmMakeDepend; // make depend needs direct access
  834. // to the Sources array
  835. void PrintStringVector(const char* s, const
  836. std::vector<std::pair<std::string, bool> >& v) const;
  837. void PrintStringVector(const char* s,
  838. const std::vector<std::string>& v) const;
  839. void AddDefaultDefinitions();
  840. typedef std::vector<cmFunctionBlocker*> FunctionBlockersType;
  841. FunctionBlockersType FunctionBlockers;
  842. std::vector<FunctionBlockersType::size_type> FunctionBlockerBarriers;
  843. void PushFunctionBlockerBarrier();
  844. void PopFunctionBlockerBarrier(bool reportError = true);
  845. typedef std::map<std::string, std::string> StringStringMap;
  846. StringStringMap MacrosMap;
  847. std::map<std::string, bool> SubDirectoryOrder;
  848. mutable cmsys::RegularExpression cmDefineRegex;
  849. mutable cmsys::RegularExpression cmDefine01Regex;
  850. mutable cmsys::RegularExpression cmAtVarRegex;
  851. mutable cmsys::RegularExpression cmNamedCurly;
  852. cmPropertyMap Properties;
  853. // should this makefile be processed before or after processing the parent
  854. bool PreOrder;
  855. // Unused variable flags
  856. bool WarnUnused;
  857. bool CheckSystemVars;
  858. // stack of list files being read
  859. std::deque<std::string> ListFileStack;
  860. // stack of commands being invoked.
  861. struct CallStackEntry
  862. {
  863. cmListFileContext const* Context;
  864. cmExecutionStatus* Status;
  865. };
  866. typedef std::deque<CallStackEntry> CallStackType;
  867. CallStackType CallStack;
  868. friend class cmMakefileCall;
  869. std::vector<cmTarget*> ImportedTargetsOwned;
  870. TargetMap ImportedTargets;
  871. // Internal policy stack management.
  872. void PushPolicy(bool weak = false,
  873. cmPolicies::PolicyMap const& pm = cmPolicies::PolicyMap());
  874. void PopPolicy();
  875. void PushPolicyBarrier();
  876. void PopPolicyBarrier(bool reportError = true);
  877. friend class cmCMakePolicyCommand;
  878. class IncludeScope;
  879. friend class IncludeScope;
  880. // stack of policy settings
  881. struct PolicyStackEntry: public cmPolicies::PolicyMap
  882. {
  883. typedef cmPolicies::PolicyMap derived;
  884. PolicyStackEntry(bool w = false): derived(), Weak(w) {}
  885. PolicyStackEntry(derived const& d, bool w = false): derived(d), Weak(w) {}
  886. PolicyStackEntry(PolicyStackEntry const& r): derived(r), Weak(r.Weak) {}
  887. bool Weak;
  888. };
  889. typedef std::vector<PolicyStackEntry> PolicyStackType;
  890. PolicyStackType PolicyStack;
  891. std::vector<PolicyStackType::size_type> PolicyBarriers;
  892. cmPolicies::PolicyStatus
  893. GetPolicyStatusInternal(cmPolicies::PolicyID id) const;
  894. bool CheckCMP0000;
  895. // Enforce rules about CMakeLists.txt files.
  896. void EnforceDirectoryLevelRules() const;
  897. // CMP0053 == old
  898. cmake::MessageType ExpandVariablesInStringOld(
  899. std::string& errorstr,
  900. std::string& source,
  901. bool escapeQuotes,
  902. bool noEscapes,
  903. bool atOnly,
  904. const char* filename,
  905. long line,
  906. bool removeEmpty,
  907. bool replaceAt) const;
  908. // CMP0053 == new
  909. cmake::MessageType ExpandVariablesInStringNew(
  910. std::string& errorstr,
  911. std::string& source,
  912. bool escapeQuotes,
  913. bool noEscapes,
  914. bool atOnly,
  915. const char* filename,
  916. long line,
  917. bool removeEmpty,
  918. bool replaceAt) const;
  919. bool GeneratingBuildSystem;
  920. /**
  921. * Old version of GetSourceFileWithOutput(const std::string&) kept for
  922. * backward-compatibility. It implements a linear search and support
  923. * relative file paths. It is used as a fall back by
  924. * GetSourceFileWithOutput(const std::string&).
  925. */
  926. cmSourceFile *LinearGetSourceFileWithOutput(const std::string& cname) const;
  927. // A map for fast output to input look up.
  928. #if defined(CMAKE_BUILD_WITH_CMAKE)
  929. typedef cmsys::hash_map<std::string, cmSourceFile*> OutputToSourceMap;
  930. #else
  931. typedef std::map<std::string, cmSourceFile*> OutputToSourceMap;
  932. #endif
  933. OutputToSourceMap OutputToSource;
  934. void UpdateOutputToSourceMap(std::vector<std::string> const& outputs,
  935. cmSourceFile* source);
  936. void UpdateOutputToSourceMap(std::string const& output,
  937. cmSourceFile* source);
  938. std::vector<cmSourceFile*> QtUiFilesWithOptions;
  939. unsigned int NumLastMatches;
  940. bool AddRequiredTargetCFeature(cmTarget *target,
  941. const std::string& feature) const;
  942. bool AddRequiredTargetCxxFeature(cmTarget *target,
  943. const std::string& feature) const;
  944. void CheckNeededCLanguage(const std::string& feature, bool& needC90,
  945. bool& needC99, bool& needC11) const;
  946. void CheckNeededCxxLanguage(const std::string& feature, bool& needCxx98,
  947. bool& needCxx11) const;
  948. };
  949. //----------------------------------------------------------------------------
  950. // Helper class to make sure the call stack is valid.
  951. class cmMakefileCall
  952. {
  953. public:
  954. cmMakefileCall(cmMakefile* mf,
  955. cmListFileContext const& lfc,
  956. cmExecutionStatus& status): Makefile(mf)
  957. {
  958. cmMakefile::CallStackEntry entry = {&lfc, &status};
  959. this->Makefile->CallStack.push_back(entry);
  960. }
  961. ~cmMakefileCall()
  962. {
  963. this->Makefile->CallStack.pop_back();
  964. }
  965. private:
  966. cmMakefile* Makefile;
  967. };
  968. #endif