cmMakefile.h 33 KB

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