cmMakefile.h 33 KB

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