cmMakefile.h 31 KB

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