cmMakefile.h 32 KB

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