cmMakefile.h 30 KB

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