cmMakefile.h 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942
  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 <set>
  10. #include <stack>
  11. #include <stddef.h>
  12. #include <string>
  13. #include <unordered_map>
  14. #include <vector>
  15. #include "cmAlgorithms.h"
  16. #include "cmListFileCache.h"
  17. #include "cmNewLineStyle.h"
  18. #include "cmPolicies.h"
  19. #include "cmStateSnapshot.h"
  20. #include "cmStateTypes.h"
  21. #include "cmTarget.h"
  22. #include "cm_auto_ptr.hxx"
  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. CM_AUTO_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. * find what source group this source is in
  408. */
  409. cmSourceGroup* FindSourceGroup(const char* source,
  410. std::vector<cmSourceGroup>& groups) const;
  411. #endif
  412. /**
  413. * Get the vector of list files on which this makefile depends
  414. */
  415. const std::vector<std::string>& GetListFiles() const
  416. {
  417. return this->ListFiles;
  418. }
  419. ///! When the file changes cmake will be re-run from the build system.
  420. void AddCMakeDependFile(const std::string& file)
  421. {
  422. this->ListFiles.push_back(file);
  423. }
  424. void AddCMakeDependFilesFromUser();
  425. std::string FormatListFileStack() const;
  426. /**
  427. * Get the current context backtrace.
  428. */
  429. cmListFileBacktrace GetBacktrace() const;
  430. cmListFileBacktrace GetBacktrace(cmCommandContext const& lfc) const;
  431. cmListFileContext GetExecutionContext() const;
  432. /**
  433. * Get the vector of files created by this makefile
  434. */
  435. const std::vector<std::string>& GetOutputFiles() const
  436. {
  437. return this->OutputFiles;
  438. }
  439. void AddCMakeOutputFile(const std::string& file)
  440. {
  441. this->OutputFiles.push_back(file);
  442. }
  443. /**
  444. * Expand all defined variables in the string.
  445. * Defined variables come from the this->Definitions map.
  446. * They are expanded with ${var} where var is the
  447. * entry in the this->Definitions map. Also \@var\@ is
  448. * expanded to match autoconf style expansions.
  449. */
  450. const char* ExpandVariablesInString(std::string& source) const;
  451. const char* ExpandVariablesInString(std::string& source, bool escapeQuotes,
  452. bool noEscapes, bool atOnly = false,
  453. const char* filename = nullptr,
  454. long line = -1, bool removeEmpty = false,
  455. bool replaceAt = false) const;
  456. /**
  457. * Remove any remaining variables in the string. Anything with ${var} or
  458. * \@var\@ will be removed.
  459. */
  460. void RemoveVariablesInString(std::string& source, bool atOnly = false) const;
  461. /**
  462. * Expand variables in the makefiles ivars such as link directories etc
  463. */
  464. void ExpandVariablesCMP0019();
  465. /**
  466. * Replace variables and #cmakedefine lines in the given string.
  467. * See cmConfigureFileCommand for details.
  468. */
  469. void ConfigureString(const std::string& input, std::string& output,
  470. bool atOnly, bool escapeQuotes) const;
  471. /**
  472. * Copy file but change lines acording to ConfigureString
  473. */
  474. int ConfigureFile(const char* infile, const char* outfile, bool copyonly,
  475. bool atOnly, bool escapeQuotes,
  476. cmNewLineStyle = cmNewLineStyle());
  477. /**
  478. * Print a command's invocation
  479. */
  480. void PrintCommandTrace(const cmListFileFunction& lff) const;
  481. /**
  482. * Execute a single CMake command. Returns true if the command
  483. * succeeded or false if it failed.
  484. */
  485. bool ExecuteCommand(const cmListFileFunction& lff,
  486. cmExecutionStatus& status);
  487. ///! Enable support for named language, if nil then all languages are
  488. /// enabled.
  489. void EnableLanguage(std::vector<std::string> const& languages,
  490. bool optional);
  491. cmState* GetState() const;
  492. /**
  493. * Get the variable watch. This is used to determine when certain variables
  494. * are accessed.
  495. */
  496. #ifdef CMAKE_BUILD_WITH_CMAKE
  497. cmVariableWatch* GetVariableWatch() const;
  498. #endif
  499. ///! Display progress or status message.
  500. void DisplayStatus(const char*, float) const;
  501. /**
  502. * Expand the given list file arguments into the full set after
  503. * variable replacement and list expansion.
  504. */
  505. bool ExpandArguments(std::vector<cmListFileArgument> const& inArgs,
  506. std::vector<std::string>& outArgs,
  507. const char* filename = nullptr) const;
  508. bool ExpandArguments(std::vector<cmListFileArgument> const& inArgs,
  509. std::vector<cmExpandedCommandArgument>& outArgs,
  510. const char* filename = nullptr) const;
  511. /**
  512. * Get the instance
  513. */
  514. cmake* GetCMakeInstance() const;
  515. cmMessenger* GetMessenger() const;
  516. cmGlobalGenerator* GetGlobalGenerator() const;
  517. /**
  518. * Get all the source files this makefile knows about
  519. */
  520. const std::vector<cmSourceFile*>& GetSourceFiles() const
  521. {
  522. return this->SourceFiles;
  523. }
  524. std::vector<cmSourceFile*>& GetSourceFiles() { return this->SourceFiles; }
  525. /**
  526. * Is there a source file that has the provided source file as an output?
  527. * if so then return it
  528. */
  529. cmSourceFile* GetSourceFileWithOutput(const std::string& outName) const;
  530. ///! Add a new cmTest to the list of tests for this makefile.
  531. cmTest* CreateTest(const std::string& testName);
  532. /** Get a cmTest pointer for a given test name, if the name is
  533. * not found, then a null pointer is returned.
  534. */
  535. cmTest* GetTest(const std::string& testName) const;
  536. /**
  537. * Return a location of a file in cmake or custom modules directory
  538. */
  539. std::string GetModulesFile(const char* name) const;
  540. ///! Set/Get a property of this directory
  541. void SetProperty(const std::string& prop, const char* value);
  542. void AppendProperty(const std::string& prop, const char* value,
  543. bool asString = false);
  544. const char* GetProperty(const std::string& prop) const;
  545. const char* GetProperty(const std::string& prop, bool chain) const;
  546. bool GetPropertyAsBool(const std::string& prop) const;
  547. std::vector<std::string> GetPropertyKeys() const;
  548. ///! Initialize a makefile from its parent
  549. void InitializeFromParent(cmMakefile* parent);
  550. void AddInstallGenerator(cmInstallGenerator* g)
  551. {
  552. if (g) {
  553. this->InstallGenerators.push_back(g);
  554. }
  555. }
  556. std::vector<cmInstallGenerator*>& GetInstallGenerators()
  557. {
  558. return this->InstallGenerators;
  559. }
  560. void AddTestGenerator(cmTestGenerator* g)
  561. {
  562. if (g) {
  563. this->TestGenerators.push_back(g);
  564. }
  565. }
  566. const std::vector<cmTestGenerator*>& GetTestGenerators() const
  567. {
  568. return this->TestGenerators;
  569. }
  570. class FunctionPushPop
  571. {
  572. public:
  573. FunctionPushPop(cmMakefile* mf, std::string const& fileName,
  574. cmPolicies::PolicyMap const& pm);
  575. ~FunctionPushPop();
  576. void Quiet() { this->ReportError = false; }
  577. private:
  578. cmMakefile* Makefile;
  579. bool ReportError;
  580. };
  581. class MacroPushPop
  582. {
  583. public:
  584. MacroPushPop(cmMakefile* mf, std::string const& fileName,
  585. cmPolicies::PolicyMap const& pm);
  586. ~MacroPushPop();
  587. void Quiet() { this->ReportError = false; }
  588. private:
  589. cmMakefile* Makefile;
  590. bool ReportError;
  591. };
  592. void PushFunctionScope(std::string const& fileName,
  593. cmPolicies::PolicyMap const& pm);
  594. void PopFunctionScope(bool reportError);
  595. void PushMacroScope(std::string const& fileName,
  596. cmPolicies::PolicyMap const& pm);
  597. void PopMacroScope(bool reportError);
  598. void PushScope();
  599. void PopScope();
  600. void RaiseScope(const std::string& var, const char* value);
  601. // push and pop loop scopes
  602. void PushLoopBlockBarrier();
  603. void PopLoopBlockBarrier();
  604. /** Helper class to push and pop scopes automatically. */
  605. class ScopePushPop
  606. {
  607. CM_DISABLE_COPY(ScopePushPop)
  608. public:
  609. ScopePushPop(cmMakefile* m)
  610. : Makefile(m)
  611. {
  612. this->Makefile->PushScope();
  613. }
  614. ~ScopePushPop() { this->Makefile->PopScope(); }
  615. private:
  616. cmMakefile* Makefile;
  617. };
  618. void IssueMessage(cmake::MessageType t, std::string const& text) const;
  619. /** Set whether or not to report a CMP0000 violation. */
  620. void SetCheckCMP0000(bool b) { this->CheckCMP0000 = b; }
  621. cmStringRange GetIncludeDirectoriesEntries() const;
  622. cmBacktraceRange GetIncludeDirectoriesBacktraces() const;
  623. cmStringRange GetCompileOptionsEntries() const;
  624. cmBacktraceRange GetCompileOptionsBacktraces() const;
  625. cmStringRange GetCompileDefinitionsEntries() const;
  626. cmBacktraceRange GetCompileDefinitionsBacktraces() const;
  627. std::set<std::string> const& GetSystemIncludeDirectories() const
  628. {
  629. return this->SystemIncludeDirectories;
  630. }
  631. bool PolicyOptionalWarningEnabled(std::string const& var);
  632. bool AddRequiredTargetFeature(cmTarget* target, const std::string& feature,
  633. std::string* error = nullptr) const;
  634. bool CompileFeatureKnown(cmTarget const* target, const std::string& feature,
  635. std::string& lang, std::string* error) const;
  636. const char* CompileFeaturesAvailable(const std::string& lang,
  637. std::string* error) const;
  638. bool HaveStandardAvailable(cmTarget const* target, std::string const& lang,
  639. const std::string& feature) const;
  640. bool IsLaterStandard(std::string const& lang, std::string const& lhs,
  641. std::string const& rhs);
  642. void PushLoopBlock();
  643. void PopLoopBlock();
  644. bool IsLoopBlock() const;
  645. void ClearMatches();
  646. void StoreMatches(cmsys::RegularExpression& re);
  647. cmStateSnapshot GetStateSnapshot() const;
  648. const char* GetDefineFlagsCMP0059() const;
  649. std::string GetExecutionFilePath() const;
  650. void EnforceDirectoryLevelRules() const;
  651. void AddEvaluationFile(const std::string& inputFile,
  652. CM_AUTO_PTR<cmCompiledGeneratorExpression> outputName,
  653. CM_AUTO_PTR<cmCompiledGeneratorExpression> condition,
  654. bool inputIsContent);
  655. std::vector<cmGeneratorExpressionEvaluationFile*> GetEvaluationFiles() const;
  656. std::vector<cmExportBuildFileGenerator*> GetExportBuildFileGenerators()
  657. const;
  658. void RemoveExportBuildFileGeneratorCMP0024(cmExportBuildFileGenerator* gen);
  659. void AddExportBuildFileGenerator(cmExportBuildFileGenerator* gen);
  660. // Maintain a stack of pacakge names to determine the depth of find modules
  661. // we are currently being called with
  662. std::deque<std::string> FindPackageModuleStack;
  663. protected:
  664. // add link libraries and directories to the target
  665. void AddGlobalLinkInformation(cmTarget& target);
  666. // Check for a an unused variable
  667. void LogUnused(const char* reason, const std::string& name) const;
  668. mutable std::set<cmListFileContext> CMP0054ReportedIds;
  669. // libraries, classes, and executables
  670. mutable cmTargets Targets;
  671. std::map<std::string, std::string> AliasTargets;
  672. std::vector<cmSourceFile*> SourceFiles;
  673. // Tests
  674. std::map<std::string, cmTest*> Tests;
  675. // The set of include directories that are marked as system include
  676. // directories.
  677. std::set<std::string> SystemIncludeDirectories;
  678. std::vector<std::string> ListFiles;
  679. std::vector<std::string> OutputFiles;
  680. std::vector<cmInstallGenerator*> InstallGenerators;
  681. std::vector<cmTestGenerator*> TestGenerators;
  682. std::string ComplainFileRegularExpression;
  683. std::string DefineFlags;
  684. // Track the value of the computed DEFINITIONS property.
  685. void AddDefineFlag(const char*, std::string&);
  686. void RemoveDefineFlag(const char*, std::string::size_type, std::string&);
  687. std::string DefineFlagsOrig;
  688. #if defined(CMAKE_BUILD_WITH_CMAKE)
  689. std::vector<cmSourceGroup> SourceGroups;
  690. size_t ObjectLibrariesSourceGroupIndex;
  691. #endif
  692. std::vector<cmCommand*> FinalPassCommands;
  693. cmGlobalGenerator* GlobalGenerator;
  694. bool IsFunctionBlocked(const cmListFileFunction& lff,
  695. cmExecutionStatus& status);
  696. private:
  697. cmStateSnapshot StateSnapshot;
  698. cmListFileBacktrace Backtrace;
  699. void ReadListFile(cmListFile const& listFile,
  700. const std::string& filenametoread);
  701. bool ParseDefineFlag(std::string const& definition, bool remove);
  702. bool EnforceUniqueDir(const std::string& srcPath,
  703. const std::string& binPath) const;
  704. typedef std::vector<cmFunctionBlocker*> FunctionBlockersType;
  705. FunctionBlockersType FunctionBlockers;
  706. std::vector<FunctionBlockersType::size_type> FunctionBlockerBarriers;
  707. void PushFunctionBlockerBarrier();
  708. void PopFunctionBlockerBarrier(bool reportError = true);
  709. std::stack<int> LoopBlockCounter;
  710. mutable cmsys::RegularExpression cmDefineRegex;
  711. mutable cmsys::RegularExpression cmDefine01Regex;
  712. mutable cmsys::RegularExpression cmAtVarRegex;
  713. mutable cmsys::RegularExpression cmNamedCurly;
  714. std::vector<cmMakefile*> UnConfiguredDirectories;
  715. std::vector<cmExportBuildFileGenerator*> ExportBuildFileGenerators;
  716. std::vector<cmGeneratorExpressionEvaluationFile*> EvaluationFiles;
  717. std::vector<cmExecutionStatus*> ExecutionStatusStack;
  718. friend class cmMakefileCall;
  719. friend class cmParseFileScope;
  720. std::vector<cmTarget*> ImportedTargetsOwned;
  721. typedef std::unordered_map<std::string, cmTarget*> TargetMap;
  722. TargetMap ImportedTargets;
  723. // Internal policy stack management.
  724. void PushPolicy(bool weak = false,
  725. cmPolicies::PolicyMap const& pm = cmPolicies::PolicyMap());
  726. void PopPolicy();
  727. void PopSnapshot(bool reportError = true);
  728. friend class cmCMakePolicyCommand;
  729. class IncludeScope;
  730. friend class IncludeScope;
  731. class ListFileScope;
  732. friend class ListFileScope;
  733. class BuildsystemFileScope;
  734. friend class BuildsystemFileScope;
  735. // CMP0053 == old
  736. cmake::MessageType ExpandVariablesInStringOld(
  737. std::string& errorstr, std::string& source, bool escapeQuotes,
  738. bool noEscapes, bool atOnly, const char* filename, long line,
  739. bool removeEmpty, bool replaceAt) const;
  740. // CMP0053 == new
  741. cmake::MessageType ExpandVariablesInStringNew(
  742. std::string& errorstr, std::string& source, bool escapeQuotes,
  743. bool noEscapes, bool atOnly, const char* filename, long line,
  744. bool removeEmpty, bool replaceAt) const;
  745. /**
  746. * Old version of GetSourceFileWithOutput(const std::string&) kept for
  747. * backward-compatibility. It implements a linear search and support
  748. * relative file paths. It is used as a fall back by
  749. * GetSourceFileWithOutput(const std::string&).
  750. */
  751. cmSourceFile* LinearGetSourceFileWithOutput(const std::string& cname) const;
  752. // A map for fast output to input look up.
  753. typedef std::unordered_map<std::string, cmSourceFile*> OutputToSourceMap;
  754. OutputToSourceMap OutputToSource;
  755. void UpdateOutputToSourceMap(std::vector<std::string> const& outputs,
  756. cmSourceFile* source);
  757. void UpdateOutputToSourceMap(std::string const& output,
  758. cmSourceFile* source);
  759. bool AddRequiredTargetCFeature(cmTarget* target, const std::string& feature,
  760. std::string* error = nullptr) const;
  761. bool AddRequiredTargetCxxFeature(cmTarget* target,
  762. const std::string& feature,
  763. std::string* error = nullptr) const;
  764. void CheckNeededCLanguage(const std::string& feature, bool& needC90,
  765. bool& needC99, bool& needC11) const;
  766. void CheckNeededCxxLanguage(const std::string& feature, bool& needCxx98,
  767. bool& needCxx11, bool& needCxx14,
  768. bool& needCxx17) const;
  769. bool HaveCStandardAvailable(cmTarget const* target,
  770. const std::string& feature) const;
  771. bool HaveCxxStandardAvailable(cmTarget const* target,
  772. const std::string& feature) const;
  773. void CheckForUnusedVariables() const;
  774. // Unused variable flags
  775. bool WarnUnused;
  776. bool CheckSystemVars;
  777. bool CheckCMP0000;
  778. bool IsSourceFileTryCompile;
  779. mutable bool SuppressWatches;
  780. };
  781. #endif