cmMakefile.h 39 KB

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