cmMakefile.h 32 KB

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