cmMakefile.h 30 KB

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