cmMakefile.h 34 KB

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