cmMakefile.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #ifndef cmMakefile_h
  14. #define cmMakefile_h
  15. #include "cmCacheManager.h"
  16. #include "cmData.h"
  17. #include "cmExecutionStatus.h"
  18. #include "cmListFileCache.h"
  19. #include "cmPropertyMap.h"
  20. #include "cmSystemTools.h"
  21. #include "cmTarget.h"
  22. #if defined(CMAKE_BUILD_WITH_CMAKE)
  23. #include "cmSourceGroup.h"
  24. #endif
  25. #include <cmsys/RegularExpression.hxx>
  26. class cmFunctionBlocker;
  27. class cmCommand;
  28. class cmInstallGenerator;
  29. class cmLocalGenerator;
  30. class cmMakeDepend;
  31. class cmSourceFile;
  32. class cmTest;
  33. class cmVariableWatch;
  34. class cmake;
  35. /** \class cmMakefile
  36. * \brief Process the input CMakeLists.txt file.
  37. *
  38. * Process and store into memory the input CMakeLists.txt file.
  39. * Each CMakeLists.txt file is parsed and the commands found there
  40. * are added into the build process.
  41. */
  42. class cmMakefile
  43. {
  44. public:
  45. /**
  46. * Return the major and minor version of the cmake that
  47. * was used to write the currently loaded cache, note
  48. * this method will not work before the cache is loaded.
  49. */
  50. unsigned int GetCacheMajorVersion();
  51. unsigned int GetCacheMinorVersion();
  52. /** Return whether compatibility features needed for a version of
  53. the cache or lower should be enabled. */
  54. bool NeedCacheCompatibility(int major, int minor);
  55. /**
  56. * Construct an empty makefile.
  57. */
  58. cmMakefile();
  59. cmMakefile(const cmMakefile& mf);
  60. /**
  61. * Destructor.
  62. */
  63. ~cmMakefile();
  64. /**
  65. * Read and parse a CMakeLists.txt file.
  66. */
  67. bool ReadListFile(const char* listfile,
  68. const char* external= 0,
  69. std::string* fullPath= 0);
  70. /**
  71. * Add a function blocker to this makefile
  72. */
  73. void AddFunctionBlocker(cmFunctionBlocker *fb)
  74. { this->FunctionBlockers.push_back(fb);}
  75. void RemoveFunctionBlocker(cmFunctionBlocker *fb)
  76. { this->FunctionBlockers.remove(fb);}
  77. void RemoveFunctionBlocker(const cmListFileFunction& lff);
  78. /**
  79. * Add file to the written file list. These file should not be in the list
  80. * of dependencies because they cause infinite loops.
  81. */
  82. void AddWrittenFile(const char* file);
  83. bool HasWrittenFile(const char* file);
  84. /**
  85. * Check if there are any infinite loops
  86. */
  87. bool CheckInfiniteLoops();
  88. /**
  89. * Try running cmake and building a file. This is used for dynalically
  90. * loaded commands, not as part of the usual build process.
  91. */
  92. int TryCompile(const char *srcdir, const char *bindir,
  93. const char *projectName, const char *targetName,
  94. const std::vector<std::string> *cmakeArgs,
  95. std::string *output);
  96. /**
  97. * Specify the makefile generator. This is platform/compiler
  98. * dependent, although the interface is through a generic
  99. * superclass.
  100. */
  101. void SetLocalGenerator(cmLocalGenerator*);
  102. ///! Get the current makefile generator.
  103. cmLocalGenerator* GetLocalGenerator()
  104. { return this->LocalGenerator;}
  105. /**
  106. * Test whether compatibility is set to a given version or lower.
  107. */
  108. bool NeedBackwardsCompatibility(unsigned int major,
  109. unsigned int minor,
  110. unsigned int patch = 0xFFu);
  111. /**
  112. * Help enforce global target name uniqueness.
  113. */
  114. bool EnforceUniqueName(std::string const& name, std::string& msg,
  115. bool isCustom = false);
  116. /**
  117. * Perform FinalPass, Library dependency analysis etc before output of the
  118. * makefile.
  119. */
  120. void ConfigureFinalPass();
  121. /**
  122. * run the final pass on all commands.
  123. */
  124. void FinalPass();
  125. /**
  126. * Print the object state to std::cout.
  127. */
  128. void Print();
  129. /** Add a custom command to the build. */
  130. void AddCustomCommandToTarget(const char* target,
  131. const std::vector<std::string>& depends,
  132. const cmCustomCommandLines& commandLines,
  133. cmTarget::CustomCommandType type,
  134. const char* comment, const char* workingDir,
  135. bool escapeOldStyle = true);
  136. void AddCustomCommandToOutput(const std::vector<std::string>& outputs,
  137. const std::vector<std::string>& depends,
  138. const char* main_dependency,
  139. const cmCustomCommandLines& commandLines,
  140. const char* comment, const char* workingDir,
  141. bool replace = false,
  142. bool escapeOldStyle = true);
  143. void AddCustomCommandToOutput(const char* output,
  144. const std::vector<std::string>& depends,
  145. const char* main_dependency,
  146. const cmCustomCommandLines& commandLines,
  147. const char* comment, const char* workingDir,
  148. bool replace = false,
  149. bool escapeOldStyle = true);
  150. void AddCustomCommandOldStyle(const char* target,
  151. const std::vector<std::string>& outputs,
  152. const std::vector<std::string>& depends,
  153. const char* source,
  154. const cmCustomCommandLines& commandLines,
  155. const char* comment);
  156. /**
  157. * Add a define flag to the build.
  158. */
  159. void AddDefineFlag(const char* definition);
  160. void RemoveDefineFlag(const char* definition);
  161. /** Create a new imported target with the name and type given. */
  162. cmTarget* AddImportedTarget(const char* name, cmTarget::TargetType type);
  163. cmTarget* AddNewTarget(cmTarget::TargetType type, const char* name);
  164. /**
  165. * Add an executable to the build.
  166. */
  167. cmTarget* AddExecutable(const char *exename,
  168. const std::vector<std::string> &srcs,
  169. bool excludeFromAll = false);
  170. /**
  171. * Add a utility to the build. A utiltity target is a command that
  172. * is run every time the target is built.
  173. */
  174. void AddUtilityCommand(const char* utilityName, bool excludeFromAll,
  175. const std::vector<std::string>& depends,
  176. const char* workingDirectory,
  177. const char* command,
  178. const char* arg1=0,
  179. const char* arg2=0,
  180. const char* arg3=0,
  181. const char* arg4=0);
  182. void AddUtilityCommand(const char* utilityName, bool excludeFromAll,
  183. const char* workingDirectory,
  184. const std::vector<std::string>& depends,
  185. const cmCustomCommandLines& commandLines,
  186. bool escapeOldStyle = true,
  187. const char* comment = 0);
  188. /**
  189. * Add a link library to the build.
  190. */
  191. void AddLinkLibrary(const char*);
  192. void AddLinkLibrary(const char*, cmTarget::LinkLibraryType type);
  193. void AddLinkLibraryForTarget(const char *tgt, const char*,
  194. cmTarget::LinkLibraryType type);
  195. void AddLinkDirectoryForTarget(const char *tgt, const char* d);
  196. /**
  197. * Add a link directory to the build.
  198. */
  199. void AddLinkDirectory(const char*);
  200. /**
  201. * Get the list of link directories
  202. */
  203. std::vector<std::string>& GetLinkDirectories()
  204. {
  205. return this->LinkDirectories;
  206. }
  207. const std::vector<std::string>& GetLinkDirectories() const
  208. {
  209. return this->LinkDirectories;
  210. }
  211. void SetLinkDirectories(const std::vector<std::string>& vec)
  212. {
  213. this->LinkDirectories = vec;
  214. }
  215. /**
  216. * Add a subdirectory to the build.
  217. */
  218. void AddSubDirectory(const char*, bool excludeFromAll=false,
  219. bool preorder = false);
  220. void AddSubDirectory(const char* fullSrcDir,const char *fullBinDir,
  221. bool excludeFromAll, bool preorder,
  222. bool immediate);
  223. /**
  224. * Configure a subdirectory
  225. */
  226. void ConfigureSubDirectory(cmLocalGenerator *);
  227. /**
  228. * Add an include directory to the build.
  229. */
  230. void AddIncludeDirectory(const char*, bool before = false);
  231. /**
  232. * Add a variable definition to the build. This variable
  233. * can be used in CMake to refer to lists, directories, etc.
  234. */
  235. void AddDefinition(const char* name, const char* value);
  236. ///! Add a definition to this makefile and the global cmake cache.
  237. void AddCacheDefinition(const char* name, const char* value,
  238. const char* doc,
  239. cmCacheManager::CacheEntryType type);
  240. /**
  241. * Add bool variable definition to the build.
  242. */
  243. void AddDefinition(const char* name, bool);
  244. ///! Add a definition to this makefile and the global cmake cache.
  245. void AddCacheDefinition(const char* name, bool, const char* doc);
  246. /**
  247. * Remove a variable definition from the build. This is not valid
  248. * for cache entries, and will only affect the current makefile.
  249. */
  250. void RemoveDefinition(const char* name);
  251. /**
  252. * Specify the name of the project for this build.
  253. */
  254. void SetProjectName(const char*);
  255. /**
  256. * Get the name of the project for this build.
  257. */
  258. const char* GetProjectName() const
  259. {
  260. return this->ProjectName.c_str();
  261. }
  262. /**
  263. * Set the name of the library.
  264. */
  265. void AddLibrary(const char *libname, cmTarget::TargetType type,
  266. const std::vector<std::string> &srcs,
  267. bool excludeFromAll = false);
  268. #if defined(CMAKE_BUILD_WITH_CMAKE)
  269. /**
  270. * Add a root source group for consideration when adding a new source.
  271. */
  272. void AddSourceGroup(const char* name, const char* regex=0);
  273. /**
  274. * Add a source group for consideration when adding a new source.
  275. * name is tokenized.
  276. */
  277. void AddSourceGroup(const std::vector<std::string>& name,
  278. const char* regex=0);
  279. #endif
  280. /**
  281. * Add an auxiliary directory to the build.
  282. */
  283. void AddExtraDirectory(const char* dir);
  284. /**
  285. * Add an auxiliary directory to the build.
  286. */
  287. void MakeStartDirectoriesCurrent()
  288. {
  289. this->AddDefinition("CMAKE_CURRENT_SOURCE_DIR",
  290. this->cmStartDirectory.c_str());
  291. this->AddDefinition("CMAKE_CURRENT_BINARY_DIR",
  292. this->StartOutputDirectory.c_str());
  293. }
  294. //@{
  295. /**
  296. * Set/Get the home directory (or output directory) in the project. The
  297. * home directory is the top directory of the project. It is where
  298. * CMakeSetup or configure was run. Remember that CMake processes
  299. * CMakeLists files by recursing up the tree starting at the StartDirectory
  300. * and going up until it reaches the HomeDirectory.
  301. */
  302. void SetHomeDirectory(const char* dir);
  303. const char* GetHomeDirectory() const
  304. {
  305. return this->cmHomeDirectory.c_str();
  306. }
  307. void SetHomeOutputDirectory(const char* lib);
  308. const char* GetHomeOutputDirectory() const
  309. {
  310. return this->HomeOutputDirectory.c_str();
  311. }
  312. //@}
  313. //@{
  314. /**
  315. * Set/Get the start directory (or output directory). The start directory
  316. * is the directory of the CMakeLists.txt file that started the current
  317. * round of processing. Remember that CMake processes CMakeLists files by
  318. * recursing up the tree starting at the StartDirectory and going up until
  319. * it reaches the HomeDirectory.
  320. */
  321. void SetStartDirectory(const char* dir)
  322. {
  323. this->cmStartDirectory = dir;
  324. cmSystemTools::ConvertToUnixSlashes(this->cmStartDirectory);
  325. this->cmStartDirectory =
  326. cmSystemTools::CollapseFullPath(this->cmStartDirectory.c_str());
  327. this->AddDefinition("CMAKE_CURRENT_SOURCE_DIR",
  328. this->cmStartDirectory.c_str());
  329. }
  330. const char* GetStartDirectory() const
  331. {
  332. return this->cmStartDirectory.c_str();
  333. }
  334. void SetStartOutputDirectory(const char* lib)
  335. {
  336. this->StartOutputDirectory = lib;
  337. cmSystemTools::ConvertToUnixSlashes(this->StartOutputDirectory);
  338. this->StartOutputDirectory =
  339. cmSystemTools::CollapseFullPath(this->StartOutputDirectory.c_str());
  340. cmSystemTools::MakeDirectory(this->StartOutputDirectory.c_str());
  341. this->AddDefinition("CMAKE_CURRENT_BINARY_DIR",
  342. this->StartOutputDirectory.c_str());
  343. }
  344. const char* GetStartOutputDirectory() const
  345. {
  346. return this->StartOutputDirectory.c_str();
  347. }
  348. //@}
  349. const char* GetCurrentDirectory() const
  350. {
  351. return this->cmStartDirectory.c_str();
  352. }
  353. const char* GetCurrentOutputDirectory() const
  354. {
  355. return this->StartOutputDirectory.c_str();
  356. }
  357. /* Get the current CMakeLists.txt file that is being processed. This
  358. * is just used in order to be able to 'branch' from one file to a second
  359. * transparently */
  360. const char* GetCurrentListFile() const
  361. {
  362. return this->cmCurrentListFile.c_str();
  363. }
  364. //@}
  365. /**
  366. * Set a regular expression that include files must match
  367. * in order to be considered as part of the depend information.
  368. */
  369. void SetIncludeRegularExpression(const char* regex)
  370. {
  371. this->IncludeFileRegularExpression = regex;
  372. }
  373. const char* GetIncludeRegularExpression()
  374. {
  375. return this->IncludeFileRegularExpression.c_str();
  376. }
  377. /**
  378. * Set a regular expression that include files that are not found
  379. * must match in order to be considered a problem.
  380. */
  381. void SetComplainRegularExpression(const char* regex)
  382. {
  383. this->ComplainFileRegularExpression = regex;
  384. }
  385. const char* GetComplainRegularExpression()
  386. {
  387. return this->ComplainFileRegularExpression.c_str();
  388. }
  389. /**
  390. * Get the list of targets
  391. */
  392. cmTargets &GetTargets() { return this->Targets; }
  393. /**
  394. * Get the list of targets, const version
  395. */
  396. const cmTargets &GetTargets() const { return this->Targets; }
  397. cmTarget* FindTarget(const char* name);
  398. /** Find a target to use in place of the given name. The target
  399. returned may be imported or built within the project. */
  400. cmTarget* FindTargetToUse(const char* name);
  401. /**
  402. * Get a list of include directories in the build.
  403. */
  404. std::vector<std::string>& GetIncludeDirectories()
  405. {
  406. return this->IncludeDirectories;
  407. }
  408. const std::vector<std::string>& GetIncludeDirectories() const
  409. {
  410. return this->IncludeDirectories;
  411. }
  412. void SetIncludeDirectories(const std::vector<std::string>& vec)
  413. {
  414. this->IncludeDirectories = vec;
  415. }
  416. /**
  417. * Mark include directories as system directories.
  418. */
  419. void AddSystemIncludeDirectory(const char* dir);
  420. bool IsSystemIncludeDirectory(const char* dir);
  421. /** Expand out any arguements in the vector that have ; separated
  422. * strings into multiple arguements. A new vector is created
  423. * containing the expanded versions of all arguments in argsIn.
  424. * This method differes from the one in cmSystemTools in that if
  425. * the CmakeLists file is version 1.2 or earlier it will check for
  426. * source lists being used without ${} around them
  427. */
  428. void ExpandSourceListArguments(std::vector<std::string> const& argsIn,
  429. std::vector<std::string>& argsOut,
  430. unsigned int startArgumentIndex);
  431. /** Get a cmSourceFile pointer for a given source name, if the name is
  432. * not found, then a null pointer is returned.
  433. */
  434. cmSourceFile* GetSource(const char* sourceName);
  435. /** Get a cmSourceFile pointer for a given source name, if the name is
  436. * not found, then create the source file and return it. generated
  437. * indicates if it is a generated file, this is used in determining
  438. * how to create the source file instance e.g. name
  439. */
  440. cmSourceFile* GetOrCreateSource(const char* sourceName,
  441. bool generated = false);
  442. /**
  443. * Obtain a list of auxiliary source directories.
  444. */
  445. std::vector<std::string>& GetAuxSourceDirectories()
  446. {return this->AuxSourceDirectories;}
  447. //@{
  448. /**
  449. * Return a list of extensions associated with source and header
  450. * files
  451. */
  452. const std::vector<std::string>& GetSourceExtensions() const
  453. {return this->SourceFileExtensions;}
  454. const std::vector<std::string>& GetHeaderExtensions() const
  455. {return this->HeaderFileExtensions;}
  456. //@}
  457. /**
  458. * Given a variable name, return its value (as a string).
  459. * If the variable is not found in this makefile instance, the
  460. * cache is then queried.
  461. */
  462. const char* GetDefinition(const char*) const;
  463. const char* GetSafeDefinition(const char*) const;
  464. const char* GetRequiredDefinition(const char* name) const;
  465. bool IsDefinitionSet(const char*) const;
  466. /**
  467. * Get the list of all variables in the current space. If argument
  468. * cacheonly is specified and is greater than 0, then only cache
  469. * variables will be listed.
  470. */
  471. std::vector<std::string> GetDefinitions(int cacheonly=0) const;
  472. /** Test a boolean cache entry to see if it is true or false,
  473. * returns false if no entry defined.
  474. */
  475. bool IsOn(const char* name) const;
  476. bool IsSet(const char* name) const;
  477. /**
  478. * Get a list of preprocessor define flags.
  479. */
  480. const char* GetDefineFlags()
  481. {return this->DefineFlags.c_str();}
  482. /**
  483. * Make sure CMake can write this file
  484. */
  485. bool CanIWriteThisFile(const char* fileName);
  486. /**
  487. * Get the vector of used command instances.
  488. */
  489. const std::vector<cmCommand*>& GetUsedCommands() const
  490. {return this->UsedCommands;}
  491. #if defined(CMAKE_BUILD_WITH_CMAKE)
  492. /**
  493. * Get the vector source groups.
  494. */
  495. const std::vector<cmSourceGroup>& GetSourceGroups() const
  496. { return this->SourceGroups; }
  497. /**
  498. * Get the source group
  499. */
  500. cmSourceGroup* GetSourceGroup(const std::vector<std::string>&name);
  501. #endif
  502. /**
  503. * Get the vector of list files on which this makefile depends
  504. */
  505. const std::vector<std::string>& GetListFiles() const
  506. { return this->ListFiles; }
  507. ///! When the file changes cmake will be re-run from the build system.
  508. void AddCMakeDependFile(const char* file)
  509. { this->ListFiles.push_back(file);}
  510. /**
  511. * Get the list file stack as a string
  512. */
  513. std::string GetListFileStack();
  514. /**
  515. * Get the vector of files created by this makefile
  516. */
  517. const std::vector<std::string>& GetOutputFiles() const
  518. { return this->OutputFiles; }
  519. void AddCMakeOutputFile(const char* file)
  520. { this->OutputFiles.push_back(file);}
  521. /**
  522. * Expand all defined variables in the string.
  523. * Defined variables come from the this->Definitions map.
  524. * They are expanded with ${var} where var is the
  525. * entry in the this->Definitions map. Also @var@ is
  526. * expanded to match autoconf style expansions.
  527. */
  528. const char *ExpandVariablesInString(std::string& source);
  529. const char *ExpandVariablesInString(std::string& source, bool escapeQuotes,
  530. bool noEscapes,
  531. bool atOnly = false,
  532. const char* filename = 0,
  533. long line = -1,
  534. bool removeEmpty = false,
  535. bool replaceAt = true);
  536. /**
  537. * Remove any remaining variables in the string. Anything with ${var} or
  538. * @var@ will be removed.
  539. */
  540. void RemoveVariablesInString(std::string& source,
  541. bool atOnly = false) const;
  542. /**
  543. * Expand variables in the makefiles ivars such as link directories etc
  544. */
  545. void ExpandVariables();
  546. /**
  547. * Replace variables and #cmakedefine lines in the given string.
  548. * See cmConfigureFileCommand for details.
  549. */
  550. void ConfigureString(const std::string& input, std::string& output,
  551. bool atOnly, bool escapeQuotes);
  552. /**
  553. * Copy file but change lines acording to ConfigureString
  554. */
  555. int ConfigureFile(const char* infile, const char* outfile,
  556. bool copyonly, bool atOnly, bool escapeQuotes);
  557. #if defined(CMAKE_BUILD_WITH_CMAKE)
  558. /**
  559. * find what source group this source is in
  560. */
  561. cmSourceGroup& FindSourceGroup(const char* source,
  562. std::vector<cmSourceGroup> &groups);
  563. #endif
  564. void RegisterData(cmData*);
  565. void RegisterData(const char*, cmData*);
  566. cmData* LookupData(const char*) const;
  567. /**
  568. * Execute a single CMake command. Returns true if the command
  569. * succeeded or false if it failed.
  570. */
  571. bool ExecuteCommand(const cmListFileFunction& lff,
  572. cmExecutionStatus &status);
  573. /** Check if a command exists. */
  574. bool CommandExists(const char* name) const;
  575. /**
  576. * Add a command to this cmake instance
  577. */
  578. void AddCommand(cmCommand* );
  579. ///! Enable support for named language, if nil then all languages are
  580. ///enabled.
  581. void EnableLanguage(std::vector<std::string>const& languages, bool optional);
  582. /**
  583. * Set/Get the name of the parent directories CMakeLists file
  584. * given a current CMakeLists file name
  585. */
  586. cmCacheManager *GetCacheManager() const;
  587. /**
  588. * Get the variable watch. This is used to determine when certain variables
  589. * are accessed.
  590. */
  591. #ifdef CMAKE_BUILD_WITH_CMAKE
  592. cmVariableWatch* GetVariableWatch() const;
  593. #endif
  594. ///! Display progress or status message.
  595. void DisplayStatus(const char*, float);
  596. /**
  597. * Expand the given list file arguments into the full set after
  598. * variable replacement and list expansion.
  599. */
  600. void ExpandArguments(std::vector<cmListFileArgument> const& inArgs,
  601. std::vector<std::string>& outArgs);
  602. /**
  603. * Get the instance
  604. */
  605. cmake *GetCMakeInstance() const;
  606. /**
  607. * Get all the source files this makefile knows about
  608. */
  609. const std::vector<cmSourceFile*> &GetSourceFiles() const
  610. {return this->SourceFiles;}
  611. std::vector<cmSourceFile*> &GetSourceFiles() {return this->SourceFiles;}
  612. /**
  613. * Is there a source file that has the provided source file as an output?
  614. * if so then return it
  615. */
  616. cmSourceFile *GetSourceFileWithOutput(const char *outName);
  617. /**
  618. * Add a macro to the list of macros. The arguments should be name of the
  619. * macro and a documentation signature of it
  620. */
  621. void AddMacro(const char* name, const char* signature);
  622. ///! Add a new cmTest to the list of tests for this makefile.
  623. cmTest* CreateTest(const char* testName);
  624. /** Get a cmTest pointer for a given test name, if the name is
  625. * not found, then a null pointer is returned.
  626. */
  627. cmTest* GetTest(const char* testName) const;
  628. const std::vector<cmTest*> *GetTests() const;
  629. std::vector<cmTest*> *GetTests();
  630. /**
  631. * Get a list of macros as a ; separated string
  632. */
  633. void GetListOfMacros(std::string& macros);
  634. /**
  635. * Return a location of a file in cmake or custom modules directory
  636. */
  637. std::string GetModulesFile(const char* name);
  638. ///! Set/Get a property of this directory
  639. void SetProperty(const char *prop, const char *value);
  640. void AppendProperty(const char *prop, const char *value);
  641. const char *GetProperty(const char *prop);
  642. const char *GetPropertyOrDefinition(const char *prop);
  643. const char *GetProperty(const char *prop, cmProperty::ScopeType scope);
  644. bool GetPropertyAsBool(const char *prop);
  645. // Get the properties
  646. cmPropertyMap &GetProperties() { return this->Properties; };
  647. typedef std::map<cmStdString, cmStdString> DefinitionMap;
  648. ///! Initialize a makefile from its parent
  649. void InitializeFromParent();
  650. ///! Set/Get the preorder flag
  651. void SetPreOrder(bool p) { this->PreOrder = p; }
  652. bool GetPreOrder() const { return this->PreOrder; }
  653. void AddInstallGenerator(cmInstallGenerator* g)
  654. { if(g) this->InstallGenerators.push_back(g); }
  655. std::vector<cmInstallGenerator*>& GetInstallGenerators()
  656. { return this->InstallGenerators; }
  657. // Define the properties
  658. static void DefineProperties(cmake *cm);
  659. // push and pop variable scopes
  660. void PushScope();
  661. void PopScope();
  662. void RaiseScope(const char *var, const char *value);
  663. protected:
  664. // add link libraries and directories to the target
  665. void AddGlobalLinkInformation(const char* name, cmTarget& target);
  666. std::string Prefix;
  667. std::vector<std::string> AuxSourceDirectories; //
  668. std::string cmStartDirectory;
  669. std::string StartOutputDirectory;
  670. std::string cmHomeDirectory;
  671. std::string HomeOutputDirectory;
  672. std::string cmCurrentListFile;
  673. std::string ProjectName; // project name
  674. // libraries, classes, and executables
  675. cmTargets Targets;
  676. std::vector<cmSourceFile*> SourceFiles;
  677. // Tests
  678. std::vector<cmTest*> Tests;
  679. // The include and link-library paths. These may have order
  680. // dependency, so they must be vectors (not set).
  681. std::vector<std::string> IncludeDirectories;
  682. std::vector<std::string> LinkDirectories;
  683. // The set of include directories that are marked as system include
  684. // directories.
  685. std::set<cmStdString> SystemIncludeDirectories;
  686. std::vector<std::string> ListFiles; // list of command files loaded
  687. std::vector<std::string> OutputFiles; // list of command files loaded
  688. cmTarget::LinkLibraryVectorType LinkLibraries;
  689. std::vector<cmInstallGenerator*> InstallGenerators;
  690. std::string IncludeFileRegularExpression;
  691. std::string ComplainFileRegularExpression;
  692. std::vector<std::string> SourceFileExtensions;
  693. std::vector<std::string> HeaderFileExtensions;
  694. std::string DefineFlags;
  695. #if defined(CMAKE_BUILD_WITH_CMAKE)
  696. std::vector<cmSourceGroup> SourceGroups;
  697. #endif
  698. std::vector<DefinitionMap> DefinitionStack;
  699. std::vector<cmCommand*> UsedCommands;
  700. cmLocalGenerator* LocalGenerator;
  701. bool IsFunctionBlocked(const cmListFileFunction& lff,
  702. cmExecutionStatus &status);
  703. private:
  704. void Initialize();
  705. bool ParseDefineFlag(std::string const& definition, bool remove);
  706. void ReadSources(std::ifstream& fin, bool t);
  707. friend class cmMakeDepend; // make depend needs direct access
  708. // to the Sources array
  709. void PrintStringVector(const char* s, const
  710. std::vector<std::pair<cmStdString, bool> >& v) const;
  711. void PrintStringVector(const char* s,
  712. const std::vector<std::string>& v) const;
  713. void AddDefaultDefinitions();
  714. std::list<cmFunctionBlocker *> FunctionBlockers;
  715. typedef std::map<cmStdString, cmData*> DataMapType;
  716. DataMapType DataMap;
  717. typedef std::map<cmStdString, cmStdString> StringStringMap;
  718. StringStringMap MacrosMap;
  719. std::map<cmStdString, bool> SubDirectoryOrder;
  720. // used in AddDefinition for performance improvement
  721. DefinitionMap::key_type TemporaryDefinitionKey;
  722. cmsys::RegularExpression cmDefineRegex;
  723. cmsys::RegularExpression cmDefine01Regex;
  724. cmsys::RegularExpression cmAtVarRegex;
  725. cmPropertyMap Properties;
  726. // should this makefile be processed before or after processing the parent
  727. bool PreOrder;
  728. // stack of list files being read
  729. std::deque<cmStdString> ListFileStack;
  730. cmTarget* FindBasicTarget(const char* name);
  731. std::vector<cmTarget*> ImportedTargetsOwned;
  732. std::map<cmStdString, cmTarget*> ImportedTargets;
  733. };
  734. #endif