cmMakefile.h 36 KB

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