cmMakefile.h 31 KB

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