cmMakefile.h 34 KB

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