cmMakefile.h 30 KB

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