cmMakefile.h 33 KB

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