cmMakefile.h 35 KB

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