cmMakefile.h 32 KB

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