cmMakefile.h 31 KB

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