cmMakefile.h 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045
  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. /**
  564. * Add a macro to the list of macros. The arguments should be name of the
  565. * macro and a documentation signature of it
  566. */
  567. void AddMacro(const char* name);
  568. ///! Add a new cmTest to the list of tests for this makefile.
  569. cmTest* CreateTest(const std::string& testName);
  570. /** Get a cmTest pointer for a given test name, if the name is
  571. * not found, then a null pointer is returned.
  572. */
  573. cmTest* GetTest(const std::string& testName) const;
  574. /**
  575. * Get a list of macros as a ; separated string
  576. */
  577. void GetListOfMacros(std::string& macros) const;
  578. /**
  579. * Return a location of a file in cmake or custom modules directory
  580. */
  581. std::string GetModulesFile(const char* name) const;
  582. ///! Set/Get a property of this directory
  583. void SetProperty(const std::string& prop, const char *value);
  584. void AppendProperty(const std::string& prop, const char *value,
  585. bool asString=false);
  586. const char *GetProperty(const std::string& prop) const;
  587. const char *GetProperty(const std::string& prop, bool chain) const;
  588. bool GetPropertyAsBool(const std::string& prop) const;
  589. std::vector<std::string> GetPropertyKeys() const;
  590. ///! Initialize a makefile from its parent
  591. void InitializeFromParent(cmMakefile* parent);
  592. void AddInstallGenerator(cmInstallGenerator* g)
  593. { if(g) this->InstallGenerators.push_back(g); }
  594. std::vector<cmInstallGenerator*>& GetInstallGenerators()
  595. { return this->InstallGenerators; }
  596. void AddTestGenerator(cmTestGenerator* g)
  597. { if(g) this->TestGenerators.push_back(g); }
  598. const std::vector<cmTestGenerator*>& GetTestGenerators() const
  599. { return this->TestGenerators; }
  600. class FunctionPushPop
  601. {
  602. public:
  603. FunctionPushPop(cmMakefile* mf, std::string const& fileName,
  604. cmPolicies::PolicyMap const& pm);
  605. ~FunctionPushPop();
  606. void Quiet() { this->ReportError = false; }
  607. private:
  608. cmMakefile* Makefile;
  609. bool ReportError;
  610. };
  611. class MacroPushPop
  612. {
  613. public:
  614. MacroPushPop(cmMakefile* mf, std::string const& fileName,
  615. cmPolicies::PolicyMap const& pm);
  616. ~MacroPushPop();
  617. void Quiet() { this->ReportError = false; }
  618. private:
  619. cmMakefile* Makefile;
  620. bool ReportError;
  621. };
  622. void PushFunctionScope(std::string const& fileName,
  623. cmPolicies::PolicyMap const& pm);
  624. void PopFunctionScope(bool reportError);
  625. void PushMacroScope(std::string const& fileName,
  626. cmPolicies::PolicyMap const& pm);
  627. void PopMacroScope(bool reportError);
  628. void PushScope();
  629. void PopScope();
  630. void RaiseScope(const std::string& var, const char *value);
  631. // push and pop loop scopes
  632. void PushLoopBlockBarrier();
  633. void PopLoopBlockBarrier();
  634. /** Helper class to push and pop scopes automatically. */
  635. class ScopePushPop
  636. {
  637. public:
  638. ScopePushPop(cmMakefile* m): Makefile(m) { this->Makefile->PushScope(); }
  639. ~ScopePushPop() { this->Makefile->PopScope(); }
  640. private:
  641. cmMakefile* Makefile;
  642. };
  643. void IssueMessage(cmake::MessageType t,
  644. std::string const& text) const;
  645. /** Set whether or not to report a CMP0000 violation. */
  646. void SetCheckCMP0000(bool b) { this->CheckCMP0000 = b; }
  647. const std::vector<cmValueWithOrigin>& GetIncludeDirectoriesEntries() const
  648. {
  649. return this->IncludeDirectoriesEntries;
  650. }
  651. const std::vector<cmValueWithOrigin>& GetCompileOptionsEntries() const
  652. {
  653. return this->CompileOptionsEntries;
  654. }
  655. const std::vector<cmValueWithOrigin>& GetCompileDefinitionsEntries() const
  656. {
  657. return this->CompileDefinitionsEntries;
  658. }
  659. bool IsConfigured() const { return this->Configured; }
  660. void SetConfigured(){ this->Configured = true; }
  661. void AddQtUiFileWithOptions(cmSourceFile *sf);
  662. std::vector<cmSourceFile*> GetQtUiFilesWithOptions() const;
  663. std::set<std::string> const & GetSystemIncludeDirectories() const
  664. { return this->SystemIncludeDirectories; }
  665. bool PolicyOptionalWarningEnabled(std::string const& var);
  666. bool AddRequiredTargetFeature(cmTarget *target,
  667. const std::string& feature,
  668. std::string *error = 0) const;
  669. bool CompileFeatureKnown(cmTarget const* target, const std::string& feature,
  670. std::string& lang, std::string *error) const;
  671. const char* CompileFeaturesAvailable(const std::string& lang,
  672. std::string *error) const;
  673. bool HaveStandardAvailable(cmTarget const* target, std::string const& lang,
  674. const std::string& feature) const;
  675. bool IsLaterStandard(std::string const& lang,
  676. std::string const& lhs,
  677. std::string const& rhs);
  678. void PushLoopBlock();
  679. void PopLoopBlock();
  680. bool IsLoopBlock() const;
  681. void ClearMatches();
  682. void StoreMatches(cmsys::RegularExpression& re);
  683. cmState::Snapshot GetStateSnapshot() const;
  684. const char* GetDefineFlagsCMP0059() const;
  685. std::string GetExecutionFilePath() const;
  686. void EnforceDirectoryLevelRules() const;
  687. protected:
  688. // add link libraries and directories to the target
  689. void AddGlobalLinkInformation(const std::string& name, cmTarget& target);
  690. // Check for a an unused variable
  691. void LogUnused(const char* reason, const std::string& name) const;
  692. mutable std::set<cmListFileContext> CMP0054ReportedIds;
  693. std::string ProjectName; // project name
  694. // libraries, classes, and executables
  695. mutable cmTargets Targets;
  696. #if defined(CMAKE_BUILD_WITH_CMAKE)
  697. #ifdef CMake_HAVE_CXX11_UNORDERED_MAP
  698. typedef std::unordered_map<std::string, cmTarget*> TargetMap;
  699. #else
  700. typedef cmsys::hash_map<std::string, cmTarget*> TargetMap;
  701. #endif
  702. #else
  703. typedef std::map<std::string, cmTarget*> TargetMap;
  704. #endif
  705. TargetMap AliasTargets;
  706. cmGeneratorTargetsType GeneratorTargets;
  707. std::vector<cmSourceFile*> SourceFiles;
  708. // Tests
  709. std::map<std::string, cmTest*> Tests;
  710. // The link-library paths. Order matters, use std::vector (not std::set).
  711. std::vector<std::string> LinkDirectories;
  712. // The set of include directories that are marked as system include
  713. // directories.
  714. std::set<std::string> SystemIncludeDirectories;
  715. std::vector<std::string> ListFiles;
  716. std::vector<std::string> OutputFiles;
  717. cmTarget::LinkLibraryVectorType LinkLibraries;
  718. std::vector<cmInstallGenerator*> InstallGenerators;
  719. std::vector<cmTestGenerator*> TestGenerators;
  720. std::string ComplainFileRegularExpression;
  721. std::vector<std::string> SourceFileExtensions;
  722. std::vector<std::string> HeaderFileExtensions;
  723. std::string DefineFlags;
  724. std::vector<cmValueWithOrigin> IncludeDirectoriesEntries;
  725. std::vector<cmValueWithOrigin> CompileOptionsEntries;
  726. std::vector<cmValueWithOrigin> CompileDefinitionsEntries;
  727. // Track the value of the computed DEFINITIONS property.
  728. void AddDefineFlag(const char*, std::string&);
  729. void RemoveDefineFlag(const char*, std::string::size_type, std::string&);
  730. std::string DefineFlagsOrig;
  731. #if defined(CMAKE_BUILD_WITH_CMAKE)
  732. std::vector<cmSourceGroup> SourceGroups;
  733. #endif
  734. std::vector<cmCommand*> FinalPassCommands;
  735. cmLocalGenerator* LocalGenerator;
  736. bool IsFunctionBlocked(const cmListFileFunction& lff,
  737. cmExecutionStatus &status);
  738. private:
  739. cmMakefile(const cmMakefile& mf);
  740. cmMakefile& operator=(const cmMakefile& mf);
  741. cmState::Snapshot StateSnapshot;
  742. void ReadListFile(cmListFile const& listFile,
  743. const std::string& filenametoread);
  744. bool ParseDefineFlag(std::string const& definition, bool remove);
  745. bool EnforceUniqueDir(const std::string& srcPath,
  746. const std::string& binPath) const;
  747. friend class cmMakeDepend; // make depend needs direct access
  748. // to the Sources array
  749. void AddDefaultDefinitions();
  750. typedef std::vector<cmFunctionBlocker*> FunctionBlockersType;
  751. FunctionBlockersType FunctionBlockers;
  752. std::vector<FunctionBlockersType::size_type> FunctionBlockerBarriers;
  753. void PushFunctionBlockerBarrier();
  754. void PopFunctionBlockerBarrier(bool reportError = true);
  755. std::stack<int> LoopBlockCounter;
  756. std::vector<std::string> MacrosList;
  757. mutable cmsys::RegularExpression cmDefineRegex;
  758. mutable cmsys::RegularExpression cmDefine01Regex;
  759. mutable cmsys::RegularExpression cmAtVarRegex;
  760. mutable cmsys::RegularExpression cmNamedCurly;
  761. std::vector<cmMakefile*> UnConfiguredDirectories;
  762. cmPropertyMap Properties;
  763. std::vector<cmCommandContext const*> ContextStack;
  764. std::vector<cmExecutionStatus*> ExecutionStatusStack;
  765. friend class cmMakefileCall;
  766. friend class cmParseFileScope;
  767. std::vector<cmTarget*> ImportedTargetsOwned;
  768. TargetMap ImportedTargets;
  769. // Internal policy stack management.
  770. void PushPolicy(bool weak = false,
  771. cmPolicies::PolicyMap const& pm = cmPolicies::PolicyMap());
  772. void PopPolicy();
  773. void PushPolicyBarrier();
  774. void PopPolicyBarrier(bool reportError = true);
  775. friend class cmCMakePolicyCommand;
  776. class IncludeScope;
  777. friend class IncludeScope;
  778. class ListFileScope;
  779. friend class ListFileScope;
  780. class BuildsystemFileScope;
  781. friend class BuildsystemFileScope;
  782. // stack of policy settings
  783. struct PolicyStackEntry: public cmPolicies::PolicyMap
  784. {
  785. typedef cmPolicies::PolicyMap derived;
  786. PolicyStackEntry(bool w = false): derived(), Weak(w) {}
  787. PolicyStackEntry(derived const& d, bool w = false): derived(d), Weak(w) {}
  788. PolicyStackEntry(PolicyStackEntry const& r): derived(r), Weak(r.Weak) {}
  789. bool Weak;
  790. };
  791. typedef std::vector<PolicyStackEntry> PolicyStackType;
  792. PolicyStackType PolicyStack;
  793. std::vector<PolicyStackType::size_type> PolicyBarriers;
  794. cmPolicies::PolicyStatus
  795. GetPolicyStatusInternal(cmPolicies::PolicyID id) const;
  796. // CMP0053 == old
  797. cmake::MessageType ExpandVariablesInStringOld(
  798. std::string& errorstr,
  799. std::string& source,
  800. bool escapeQuotes,
  801. bool noEscapes,
  802. bool atOnly,
  803. const char* filename,
  804. long line,
  805. bool removeEmpty,
  806. bool replaceAt) const;
  807. // CMP0053 == new
  808. cmake::MessageType ExpandVariablesInStringNew(
  809. std::string& errorstr,
  810. std::string& source,
  811. bool escapeQuotes,
  812. bool noEscapes,
  813. bool atOnly,
  814. const char* filename,
  815. long line,
  816. bool removeEmpty,
  817. bool replaceAt) const;
  818. /**
  819. * Old version of GetSourceFileWithOutput(const std::string&) kept for
  820. * backward-compatibility. It implements a linear search and support
  821. * relative file paths. It is used as a fall back by
  822. * GetSourceFileWithOutput(const std::string&).
  823. */
  824. cmSourceFile *LinearGetSourceFileWithOutput(const std::string& cname) const;
  825. // A map for fast output to input look up.
  826. #if defined(CMAKE_BUILD_WITH_CMAKE)
  827. #ifdef CMake_HAVE_CXX11_UNORDERED_MAP
  828. typedef std::unordered_map<std::string, cmSourceFile*> OutputToSourceMap;
  829. #else
  830. typedef cmsys::hash_map<std::string, cmSourceFile*> OutputToSourceMap;
  831. #endif
  832. #else
  833. typedef std::map<std::string, cmSourceFile*> OutputToSourceMap;
  834. #endif
  835. OutputToSourceMap OutputToSource;
  836. void UpdateOutputToSourceMap(std::vector<std::string> const& outputs,
  837. cmSourceFile* source);
  838. void UpdateOutputToSourceMap(std::string const& output,
  839. cmSourceFile* source);
  840. std::vector<cmSourceFile*> QtUiFilesWithOptions;
  841. bool AddRequiredTargetCFeature(cmTarget *target,
  842. const std::string& feature) const;
  843. bool AddRequiredTargetCxxFeature(cmTarget *target,
  844. const std::string& feature) const;
  845. void CheckNeededCLanguage(const std::string& feature, bool& needC90,
  846. bool& needC99, bool& needC11) const;
  847. void CheckNeededCxxLanguage(const std::string& feature, bool& needCxx98,
  848. bool& needCxx11, bool& needCxx14) const;
  849. bool HaveCStandardAvailable(cmTarget const* target,
  850. const std::string& feature) const;
  851. bool HaveCxxStandardAvailable(cmTarget const* target,
  852. const std::string& feature) const;
  853. void CheckForUnusedVariables() const;
  854. // Unused variable flags
  855. bool WarnUnused;
  856. bool CheckSystemVars;
  857. bool CheckCMP0000;
  858. bool Configured;
  859. mutable bool SuppressWatches;
  860. };
  861. //----------------------------------------------------------------------------
  862. // Helper class to make sure the call stack is valid.
  863. class cmMakefileCall
  864. {
  865. public:
  866. cmMakefileCall(cmMakefile* mf,
  867. cmCommandContext const& lfc,
  868. cmExecutionStatus& status);
  869. ~cmMakefileCall();
  870. private:
  871. cmMakefile* Makefile;
  872. };
  873. #endif