cmMakefile.h 34 KB

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