cmMakefile.h 32 KB

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