cmMakefile.h 30 KB

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