cmMakefile.h 35 KB

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