cmMakefile.h 31 KB

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