cmMakefile.h 35 KB

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