cmMakefile.h 39 KB

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