cmMakefile.h 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028
  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. * Get a list of include directories in the build.
  463. */
  464. std::vector<std::string>& GetIncludeDirectories()
  465. {
  466. return this->IncludeDirectories;
  467. }
  468. const std::vector<std::string>& GetIncludeDirectories() const
  469. {
  470. return this->IncludeDirectories;
  471. }
  472. void SetIncludeDirectories(const std::vector<std::string>& vec)
  473. {
  474. this->IncludeDirectories = vec;
  475. }
  476. /**
  477. * Mark include directories as system directories.
  478. */
  479. void AddSystemIncludeDirectory(const char* dir);
  480. bool IsSystemIncludeDirectory(const char* dir);
  481. /** Expand out any arguements in the vector that have ; separated
  482. * strings into multiple arguements. A new vector is created
  483. * containing the expanded versions of all arguments in argsIn.
  484. * This method differes from the one in cmSystemTools in that if
  485. * the CmakeLists file is version 1.2 or earlier it will check for
  486. * source lists being used without ${} around them
  487. */
  488. void ExpandSourceListArguments(std::vector<std::string> const& argsIn,
  489. std::vector<std::string>& argsOut,
  490. unsigned int startArgumentIndex);
  491. /** Get a cmSourceFile pointer for a given source name, if the name is
  492. * not found, then a null pointer is returned.
  493. */
  494. cmSourceFile* GetSource(const char* sourceName);
  495. /** Get a cmSourceFile pointer for a given source name, if the name is
  496. * not found, then create the source file and return it. generated
  497. * indicates if it is a generated file, this is used in determining
  498. * how to create the source file instance e.g. name
  499. */
  500. cmSourceFile* GetOrCreateSource(const char* sourceName,
  501. bool generated = false);
  502. /**
  503. * Obtain a list of auxiliary source directories.
  504. */
  505. std::vector<std::string>& GetAuxSourceDirectories()
  506. {return this->AuxSourceDirectories;}
  507. //@{
  508. /**
  509. * Return a list of extensions associated with source and header
  510. * files
  511. */
  512. const std::vector<std::string>& GetSourceExtensions() const
  513. {return this->SourceFileExtensions;}
  514. const std::vector<std::string>& GetHeaderExtensions() const
  515. {return this->HeaderFileExtensions;}
  516. //@}
  517. /**
  518. * Given a variable name, return its value (as a string).
  519. * If the variable is not found in this makefile instance, the
  520. * cache is then queried.
  521. */
  522. const char* GetDefinition(const char*) const;
  523. const char* GetSafeDefinition(const char*) const;
  524. const char* GetRequiredDefinition(const char* name) const;
  525. bool IsDefinitionSet(const char*) const;
  526. /**
  527. * Get the list of all variables in the current space. If argument
  528. * cacheonly is specified and is greater than 0, then only cache
  529. * variables will be listed.
  530. */
  531. std::vector<std::string> GetDefinitions(int cacheonly=0) const;
  532. /** Test a boolean cache entry to see if it is true or false,
  533. * returns false if no entry defined.
  534. */
  535. bool IsOn(const char* name) const;
  536. bool IsSet(const char* name) const;
  537. /** Return whether the target platform is 64-bit. */
  538. bool PlatformIs64Bit() const;
  539. /**
  540. * Get a list of preprocessor define flags.
  541. */
  542. const char* GetDefineFlags()
  543. {return this->DefineFlags.c_str();}
  544. /**
  545. * Make sure CMake can write this file
  546. */
  547. bool CanIWriteThisFile(const char* fileName);
  548. /**
  549. * Get the vector of used command instances.
  550. */
  551. const std::vector<cmCommand*>& GetUsedCommands() const
  552. {return this->UsedCommands;}
  553. #if defined(CMAKE_BUILD_WITH_CMAKE)
  554. /**
  555. * Get the vector source groups.
  556. */
  557. const std::vector<cmSourceGroup>& GetSourceGroups() const
  558. { return this->SourceGroups; }
  559. /**
  560. * Get the source group
  561. */
  562. cmSourceGroup* GetSourceGroup(const std::vector<std::string>&name);
  563. #endif
  564. /**
  565. * Get the vector of list files on which this makefile depends
  566. */
  567. const std::vector<std::string>& GetListFiles() const
  568. { return this->ListFiles; }
  569. ///! When the file changes cmake will be re-run from the build system.
  570. void AddCMakeDependFile(const char* file)
  571. { this->ListFiles.push_back(file);}
  572. /**
  573. * Get the list file stack as a string
  574. */
  575. std::string GetListFileStack();
  576. /**
  577. * Get the current context backtrace.
  578. */
  579. bool GetBacktrace(cmListFileBacktrace& backtrace) const;
  580. /**
  581. * Get the vector of files created by this makefile
  582. */
  583. const std::vector<std::string>& GetOutputFiles() const
  584. { return this->OutputFiles; }
  585. void AddCMakeOutputFile(const char* file)
  586. { this->OutputFiles.push_back(file);}
  587. /**
  588. * Expand all defined variables in the string.
  589. * Defined variables come from the this->Definitions map.
  590. * They are expanded with ${var} where var is the
  591. * entry in the this->Definitions map. Also \@var\@ is
  592. * expanded to match autoconf style expansions.
  593. */
  594. const char *ExpandVariablesInString(std::string& source);
  595. const char *ExpandVariablesInString(std::string& source, bool escapeQuotes,
  596. bool noEscapes,
  597. bool atOnly = false,
  598. const char* filename = 0,
  599. long line = -1,
  600. bool removeEmpty = false,
  601. bool replaceAt = true);
  602. /**
  603. * Remove any remaining variables in the string. Anything with ${var} or
  604. * \@var\@ will be removed.
  605. */
  606. void RemoveVariablesInString(std::string& source,
  607. bool atOnly = false) const;
  608. /**
  609. * Expand variables in the makefiles ivars such as link directories etc
  610. */
  611. void ExpandVariables();
  612. /**
  613. * Replace variables and #cmakedefine lines in the given string.
  614. * See cmConfigureFileCommand for details.
  615. */
  616. void ConfigureString(const std::string& input, std::string& output,
  617. bool atOnly, bool escapeQuotes);
  618. /**
  619. * Copy file but change lines acording to ConfigureString
  620. */
  621. int ConfigureFile(const char* infile, const char* outfile,
  622. bool copyonly, bool atOnly, bool escapeQuotes,
  623. const cmNewLineStyle& = cmNewLineStyle());
  624. #if defined(CMAKE_BUILD_WITH_CMAKE)
  625. /**
  626. * find what source group this source is in
  627. */
  628. cmSourceGroup& FindSourceGroup(const char* source,
  629. std::vector<cmSourceGroup> &groups);
  630. #endif
  631. /**
  632. * Execute a single CMake command. Returns true if the command
  633. * succeeded or false if it failed.
  634. */
  635. bool ExecuteCommand(const cmListFileFunction& lff,
  636. cmExecutionStatus &status);
  637. /** Check if a command exists. */
  638. bool CommandExists(const char* name) const;
  639. /**
  640. * Add a command to this cmake instance
  641. */
  642. void AddCommand(cmCommand* );
  643. ///! Enable support for named language, if nil then all languages are
  644. ///enabled.
  645. void EnableLanguage(std::vector<std::string>const& languages, bool optional);
  646. /**
  647. * Set/Get the name of the parent directories CMakeLists file
  648. * given a current CMakeLists file name
  649. */
  650. cmCacheManager *GetCacheManager() const;
  651. /**
  652. * Get the variable watch. This is used to determine when certain variables
  653. * are accessed.
  654. */
  655. #ifdef CMAKE_BUILD_WITH_CMAKE
  656. cmVariableWatch* GetVariableWatch() const;
  657. #endif
  658. ///! Display progress or status message.
  659. void DisplayStatus(const char*, float);
  660. /**
  661. * Expand the given list file arguments into the full set after
  662. * variable replacement and list expansion.
  663. */
  664. bool ExpandArguments(std::vector<cmListFileArgument> const& inArgs,
  665. std::vector<std::string>& outArgs);
  666. /**
  667. * Get the instance
  668. */
  669. cmake *GetCMakeInstance() const;
  670. /**
  671. * Get all the source files this makefile knows about
  672. */
  673. const std::vector<cmSourceFile*> &GetSourceFiles() const
  674. {return this->SourceFiles;}
  675. std::vector<cmSourceFile*> &GetSourceFiles() {return this->SourceFiles;}
  676. /**
  677. * Is there a source file that has the provided source file as an output?
  678. * if so then return it
  679. */
  680. cmSourceFile *GetSourceFileWithOutput(const char *outName);
  681. /**
  682. * Add a macro to the list of macros. The arguments should be name of the
  683. * macro and a documentation signature of it
  684. */
  685. void AddMacro(const char* name, const char* signature);
  686. ///! Add a new cmTest to the list of tests for this makefile.
  687. cmTest* CreateTest(const char* testName);
  688. /** Get a cmTest pointer for a given test name, if the name is
  689. * not found, then a null pointer is returned.
  690. */
  691. cmTest* GetTest(const char* testName) const;
  692. /**
  693. * Get a list of macros as a ; separated string
  694. */
  695. void GetListOfMacros(std::string& macros);
  696. /**
  697. * Return a location of a file in cmake or custom modules directory
  698. */
  699. std::string GetModulesFile(const char* name);
  700. ///! Set/Get a property of this directory
  701. void SetProperty(const char *prop, const char *value);
  702. void AppendProperty(const char *prop, const char *value,bool asString=false);
  703. const char *GetProperty(const char *prop);
  704. const char *GetPropertyOrDefinition(const char *prop);
  705. const char *GetProperty(const char *prop, cmProperty::ScopeType scope);
  706. bool GetPropertyAsBool(const char *prop);
  707. const char* GetFeature(const char* feature, const char* config);
  708. // Get the properties
  709. cmPropertyMap &GetProperties() { return this->Properties; };
  710. ///! Initialize a makefile from its parent
  711. void InitializeFromParent();
  712. ///! Set/Get the preorder flag
  713. void SetPreOrder(bool p) { this->PreOrder = p; }
  714. bool GetPreOrder() const { return this->PreOrder; }
  715. void AddInstallGenerator(cmInstallGenerator* g)
  716. { if(g) this->InstallGenerators.push_back(g); }
  717. std::vector<cmInstallGenerator*>& GetInstallGenerators()
  718. { return this->InstallGenerators; }
  719. void AddTestGenerator(cmTestGenerator* g)
  720. { if(g) this->TestGenerators.push_back(g); }
  721. std::vector<cmTestGenerator*>& GetTestGenerators()
  722. { return this->TestGenerators; }
  723. // Define the properties
  724. static void DefineProperties(cmake *cm);
  725. // push and pop variable scopes
  726. void PushScope();
  727. void PopScope();
  728. void RaiseScope(const char *var, const char *value);
  729. /** Helper class to push and pop scopes automatically. */
  730. class ScopePushPop
  731. {
  732. public:
  733. ScopePushPop(cmMakefile* m): Makefile(m) { this->Makefile->PushScope(); }
  734. ~ScopePushPop() { this->Makefile->PopScope(); }
  735. private:
  736. cmMakefile* Makefile;
  737. };
  738. void IssueMessage(cmake::MessageType t,
  739. std::string const& text) const;
  740. /** Set whether or not to report a CMP0000 violation. */
  741. void SetCheckCMP0000(bool b) { this->CheckCMP0000 = b; }
  742. protected:
  743. // add link libraries and directories to the target
  744. void AddGlobalLinkInformation(const char* name, cmTarget& target);
  745. // Check for a an unused variable
  746. void CheckForUnused(const char* reason, const char* name) const;
  747. std::string Prefix;
  748. std::vector<std::string> AuxSourceDirectories; //
  749. std::string cmStartDirectory;
  750. std::string StartOutputDirectory;
  751. std::string cmHomeDirectory;
  752. std::string HomeOutputDirectory;
  753. std::string cmCurrentListFile;
  754. std::string ProjectName; // project name
  755. // libraries, classes, and executables
  756. cmTargets Targets;
  757. std::vector<cmSourceFile*> SourceFiles;
  758. // Tests
  759. std::map<cmStdString, cmTest*> Tests;
  760. // The include and link-library paths. These may have order
  761. // dependency, so they must be vectors (not set).
  762. std::vector<std::string> IncludeDirectories;
  763. std::vector<std::string> LinkDirectories;
  764. // The set of include directories that are marked as system include
  765. // directories.
  766. std::set<cmStdString> SystemIncludeDirectories;
  767. std::vector<std::string> ListFiles; // list of command files loaded
  768. std::vector<std::string> OutputFiles; // list of command files loaded
  769. cmTarget::LinkLibraryVectorType LinkLibraries;
  770. std::vector<cmInstallGenerator*> InstallGenerators;
  771. std::vector<cmTestGenerator*> TestGenerators;
  772. std::string IncludeFileRegularExpression;
  773. std::string ComplainFileRegularExpression;
  774. std::vector<std::string> SourceFileExtensions;
  775. std::vector<std::string> HeaderFileExtensions;
  776. std::string DefineFlags;
  777. // Track the value of the computed DEFINITIONS property.
  778. void AddDefineFlag(const char*, std::string&);
  779. void RemoveDefineFlag(const char*, std::string::size_type, std::string&);
  780. std::string DefineFlagsOrig;
  781. #if defined(CMAKE_BUILD_WITH_CMAKE)
  782. std::vector<cmSourceGroup> SourceGroups;
  783. #endif
  784. std::vector<cmCommand*> UsedCommands;
  785. cmLocalGenerator* LocalGenerator;
  786. bool IsFunctionBlocked(const cmListFileFunction& lff,
  787. cmExecutionStatus &status);
  788. private:
  789. void Initialize();
  790. bool ParseDefineFlag(std::string const& definition, bool remove);
  791. bool EnforceUniqueDir(const char* srcPath, const char* binPath);
  792. void ReadSources(std::ifstream& fin, bool t);
  793. friend class cmMakeDepend; // make depend needs direct access
  794. // to the Sources array
  795. void PrintStringVector(const char* s, const
  796. std::vector<std::pair<cmStdString, bool> >& v) const;
  797. void PrintStringVector(const char* s,
  798. const std::vector<std::string>& v) const;
  799. void AddDefaultDefinitions();
  800. typedef std::vector<cmFunctionBlocker*> FunctionBlockersType;
  801. FunctionBlockersType FunctionBlockers;
  802. std::vector<FunctionBlockersType::size_type> FunctionBlockerBarriers;
  803. void PushFunctionBlockerBarrier();
  804. void PopFunctionBlockerBarrier(bool reportError = true);
  805. typedef std::map<cmStdString, cmStdString> StringStringMap;
  806. StringStringMap MacrosMap;
  807. std::map<cmStdString, bool> SubDirectoryOrder;
  808. cmsys::RegularExpression cmDefineRegex;
  809. cmsys::RegularExpression cmDefine01Regex;
  810. cmsys::RegularExpression cmAtVarRegex;
  811. cmPropertyMap Properties;
  812. // should this makefile be processed before or after processing the parent
  813. bool PreOrder;
  814. // Unused variable flags
  815. bool WarnUnused;
  816. bool CheckSystemVars;
  817. // stack of list files being read
  818. std::deque<cmStdString> ListFileStack;
  819. // stack of commands being invoked.
  820. struct CallStackEntry
  821. {
  822. cmListFileContext const* Context;
  823. cmExecutionStatus* Status;
  824. };
  825. typedef std::deque<CallStackEntry> CallStackType;
  826. CallStackType CallStack;
  827. friend class cmMakefileCall;
  828. cmTarget* FindBasicTarget(const char* name);
  829. std::vector<cmTarget*> ImportedTargetsOwned;
  830. std::map<cmStdString, cmTarget*> ImportedTargets;
  831. // Internal policy stack management.
  832. void PushPolicy(bool weak = false,
  833. cmPolicies::PolicyMap const& pm = cmPolicies::PolicyMap());
  834. void PopPolicy();
  835. void PushPolicyBarrier();
  836. void PopPolicyBarrier(bool reportError = true);
  837. friend class cmCMakePolicyCommand;
  838. class IncludeScope;
  839. friend class IncludeScope;
  840. // stack of policy settings
  841. struct PolicyStackEntry: public cmPolicies::PolicyMap
  842. {
  843. typedef cmPolicies::PolicyMap derived;
  844. PolicyStackEntry(bool w = false): derived(), Weak(w) {}
  845. PolicyStackEntry(derived const& d, bool w = false): derived(d), Weak(w) {}
  846. PolicyStackEntry(PolicyStackEntry const& r): derived(r), Weak(r.Weak) {}
  847. bool Weak;
  848. };
  849. typedef std::vector<PolicyStackEntry> PolicyStackType;
  850. PolicyStackType PolicyStack;
  851. std::vector<PolicyStackType::size_type> PolicyBarriers;
  852. cmPolicies::PolicyStatus GetPolicyStatusInternal(cmPolicies::PolicyID id);
  853. bool CheckCMP0000;
  854. // Enforce rules about CMakeLists.txt files.
  855. void EnforceDirectoryLevelRules();
  856. };
  857. //----------------------------------------------------------------------------
  858. // Helper class to make sure the call stack is valid.
  859. class cmMakefileCall
  860. {
  861. public:
  862. cmMakefileCall(cmMakefile* mf,
  863. cmListFileContext const& lfc,
  864. cmExecutionStatus& status): Makefile(mf)
  865. {
  866. cmMakefile::CallStackEntry entry = {&lfc, &status};
  867. this->Makefile->CallStack.push_back(entry);
  868. }
  869. ~cmMakefileCall()
  870. {
  871. this->Makefile->CallStack.pop_back();
  872. }
  873. private:
  874. cmMakefile* Makefile;
  875. };
  876. #endif