cmMakefile.cxx 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352
  1. /*=========================================================================
  2. Program: Insight Segmentation & Registration Toolkit
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Insight Consortium. All rights reserved.
  8. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmMakefile.h"
  14. #include "cmCommand.h"
  15. #include "cmStandardIncludes.h"
  16. #include "cmSourceFile.h"
  17. #include "cmDirectory.h"
  18. #include "cmSystemTools.h"
  19. #include "cmMakefileGenerator.h"
  20. #include "cmCommands.h"
  21. #include "cmCacheManager.h"
  22. #include "cmFunctionBlocker.h"
  23. #include "cmListFileCache.h"
  24. #include <stdio.h> // required for sprintf
  25. // default is not to be building executables
  26. cmMakefile::cmMakefile()
  27. {
  28. // Setup the default include file regular expression (match everything).
  29. m_IncludeFileRegularExpression = "^.*$";
  30. // Setup the default include complaint regular expression (match nothing).
  31. m_ComplainFileRegularExpression = "^$";
  32. // Source and header file extensions that we can handle
  33. m_SourceFileExtensions.push_back( "cxx" );
  34. m_SourceFileExtensions.push_back( "cpp" );
  35. m_SourceFileExtensions.push_back( "c" );
  36. m_SourceFileExtensions.push_back( "M" );
  37. m_SourceFileExtensions.push_back( "m" );
  38. m_SourceFileExtensions.push_back( "mm" );
  39. m_HeaderFileExtensions.push_back( "h" );
  40. m_HeaderFileExtensions.push_back( "txx" );
  41. m_HeaderFileExtensions.push_back( "in" );
  42. m_DefineFlags = " ";
  43. m_MakefileGenerator = 0;
  44. this->AddSourceGroup("", "^.*$");
  45. this->AddSourceGroup("Source Files", "\\.(cpp|C|c|cxx|rc|def|r|odl|idl|hpj|bat)$");
  46. this->AddSourceGroup("Header Files", "\\.(h|hh|hpp|hxx|hm|inl)$");
  47. this->AddDefaultCommands();
  48. this->AddDefaultDefinitions();
  49. }
  50. unsigned int cmMakefile::GetCacheMajorVersion()
  51. {
  52. if(!cmCacheManager::GetInstance()->
  53. GetCacheValue("CMAKE_CACHE_MAJOR_VERSION"))
  54. {
  55. return 0;
  56. }
  57. return atoi(cmCacheManager::GetInstance()->
  58. GetCacheValue("CMAKE_CACHE_MAJOR_VERSION"));
  59. }
  60. unsigned int cmMakefile::GetCacheMinorVersion()
  61. {
  62. if(!cmCacheManager::GetInstance()->
  63. GetCacheValue("Cmake_Cache_MINOR_VERSION"))
  64. {
  65. return 0;
  66. }
  67. return atoi(cmCacheManager::GetInstance()->
  68. GetCacheValue("CMAKE_CACHE_MINOR_VERSION"));
  69. }
  70. void cmMakefile::AddDefaultCommands()
  71. {
  72. std::list<cmCommand*> commands;
  73. GetPredefinedCommands(commands);
  74. for(std::list<cmCommand*>::iterator i = commands.begin();
  75. i != commands.end(); ++i)
  76. {
  77. this->AddCommand(*i);
  78. }
  79. #if defined(_WIN32) || defined(__CYGWIN__)
  80. this->AddDefinition("WIN32", "1");
  81. #else
  82. this->AddDefinition("UNIX", "1");
  83. #endif
  84. // Cygwin is more like unix so enable the unix commands
  85. #if defined(__CYGWIN__)
  86. this->AddDefinition("UNIX", "1");
  87. this->AddDefinition("CYGWIN", "1");
  88. #endif
  89. #if defined(__APPLE__)
  90. this->AddDefinition("APPLE", "1");
  91. #endif
  92. }
  93. cmMakefile::~cmMakefile()
  94. {
  95. for(std::vector<cmSourceFile*>::iterator i = m_SourceFiles.begin();
  96. i != m_SourceFiles.end(); ++i)
  97. {
  98. delete *i;
  99. }
  100. for(unsigned int i=0; i < m_UsedCommands.size(); i++)
  101. {
  102. delete m_UsedCommands[i];
  103. }
  104. for(RegisteredCommandsMap::iterator j = m_Commands.begin();
  105. j != m_Commands.end(); ++j)
  106. {
  107. delete (*j).second;
  108. }
  109. for(DataMap::const_iterator d = m_DataMap.begin();
  110. d != m_DataMap.end(); ++d)
  111. {
  112. if(d->second)
  113. {
  114. delete d->second;
  115. }
  116. }
  117. std::set<cmFunctionBlocker *>::const_iterator pos;
  118. for (pos = m_FunctionBlockers.begin();
  119. pos != m_FunctionBlockers.end(); pos = m_FunctionBlockers.begin())
  120. {
  121. cmFunctionBlocker* b = *pos;
  122. m_FunctionBlockers.erase(*pos);
  123. delete b;
  124. }
  125. delete m_MakefileGenerator;
  126. }
  127. void cmMakefile::PrintStringVector(const char* s, const std::vector<std::string>& v) const
  128. {
  129. std::cout << s << ": ( \n";
  130. for(std::vector<std::string>::const_iterator i = v.begin();
  131. i != v.end(); ++i)
  132. {
  133. std::cout << (*i).c_str() << " ";
  134. }
  135. std::cout << " )\n";
  136. }
  137. // call print on all the classes in the makefile
  138. void cmMakefile::Print() const
  139. {
  140. // print the class lists
  141. std::cout << "classes:\n";
  142. for(SourceMap::const_iterator l = m_Sources.begin();
  143. l != m_Sources.end(); l++)
  144. {
  145. std::cout << " Class list named: " << l->first << std::endl;
  146. for(std::vector<cmSourceFile*>::const_iterator i = l->second.begin();
  147. i != l->second.end(); i++)
  148. {
  149. (*i)->Print();
  150. }
  151. }
  152. std::cout << " m_Targets: ";
  153. for (cmTargets::const_iterator l = m_Targets.begin();
  154. l != m_Targets.end(); l++)
  155. {
  156. std::cout << l->first << std::endl;
  157. }
  158. std::cout << " m_CurrentOutputDirectory; " <<
  159. m_CurrentOutputDirectory.c_str() << std::endl;
  160. std::cout << " m_StartOutputDirectory; " <<
  161. m_StartOutputDirectory.c_str() << std::endl;
  162. std::cout << " m_HomeOutputDirectory; " <<
  163. m_HomeOutputDirectory.c_str() << std::endl;
  164. std::cout << " m_cmCurrentDirectory; " <<
  165. m_cmCurrentDirectory.c_str() << std::endl;
  166. std::cout << " m_cmStartDirectory; " <<
  167. m_cmStartDirectory.c_str() << std::endl;
  168. std::cout << " m_cmHomeDirectory; " <<
  169. m_cmHomeDirectory.c_str() << std::endl;
  170. std::cout << " m_ProjectName; " << m_ProjectName.c_str() << std::endl;
  171. this->PrintStringVector("m_SubDirectories ", m_SubDirectories);
  172. this->PrintStringVector("m_IncludeDirectories;", m_IncludeDirectories);
  173. this->PrintStringVector("m_LinkDirectories", m_LinkDirectories);
  174. for( std::vector<cmSourceGroup>::const_iterator i = m_SourceGroups.begin();
  175. i != m_SourceGroups.end(); ++i)
  176. {
  177. i->Print();
  178. }
  179. }
  180. bool cmMakefile::CommandExists(const char* name) const
  181. {
  182. return (m_Commands.find(name) != m_Commands.end());
  183. }
  184. void cmMakefile::ExecuteCommand(std::string &name,
  185. std::vector<std::string> const& arguments)
  186. {
  187. RegisteredCommandsMap::iterator pos = m_Commands.find(name);
  188. if(pos != m_Commands.end())
  189. {
  190. cmCommand* rm = (*pos).second;
  191. cmCommand* usedCommand = rm->Clone();
  192. usedCommand->SetMakefile(this);
  193. bool keepCommand = false;
  194. if(usedCommand->GetEnabled())
  195. {
  196. // if not running in inherit mode or
  197. // if the command is inherited then InitialPass it.
  198. if(!m_Inheriting || usedCommand->IsInherited())
  199. {
  200. std::vector<std::string> expandedArguments = arguments;
  201. for(std::vector<std::string>::iterator i = expandedArguments.begin();
  202. i != expandedArguments.end(); ++i)
  203. {
  204. this->ExpandVariablesInString(*i);
  205. }
  206. if(!usedCommand->InitialPass(expandedArguments))
  207. {
  208. cmSystemTools::Error(usedCommand->GetName(),
  209. ": Error : \n",
  210. usedCommand->GetError(),
  211. m_cmCurrentDirectory.c_str());
  212. }
  213. else
  214. {
  215. // use the command
  216. keepCommand = true;
  217. m_UsedCommands.push_back(usedCommand);
  218. }
  219. }
  220. }
  221. // if the Cloned command was not used
  222. // then delete it
  223. if(!keepCommand)
  224. {
  225. delete usedCommand;
  226. }
  227. }
  228. else if((name == "CABLE_WRAP_TCL") || (name == "CABLE_CLASS_SET") ||
  229. (name == "CONFIGURE_GCCXML"))
  230. {
  231. cmSystemTools::Error("The command ", name.c_str(),
  232. " is not implemented in this version of CMake.\n"
  233. "Contact [email protected] for more information.");
  234. }
  235. else
  236. {
  237. cmSystemTools::Error("unknown CMake command:", name.c_str(),
  238. "\nReading cmake file in directory:" ,
  239. m_cmCurrentDirectory.c_str());
  240. }
  241. }
  242. // Parse the given CMakeLists.txt file into a list of classes.
  243. // Reads in current CMakeLists file and all parent CMakeLists files
  244. // executing all inherited commands in the parents
  245. //
  246. // if external is non-zero, this means that we have branched to grab some
  247. // commands from a remote list-file (that is, the equivalent of a
  248. // #include has been called). We DO NOT look at the parents of this
  249. // list-file, and for all other purposes, the name of this list-file
  250. // is "filename" and not "external".
  251. bool cmMakefile::ReadListFile(const char* filename, const char* external)
  252. {
  253. // keep track of the current file being read
  254. if (filename)
  255. {
  256. if(m_cmCurrentListFile != filename)
  257. {
  258. m_cmCurrentListFile = filename;
  259. }
  260. }
  261. // if this is not a remote makefile
  262. // (if it were, this would be called from the "filename" call,
  263. // rather than the "external" call)
  264. if (!external)
  265. {
  266. // is there a parent CMakeLists file that does not go beyond the
  267. // Home directory? if so recurse and read in that List file
  268. std::string parentList = this->GetParentListFileName(filename);
  269. if (parentList != "")
  270. {
  271. std::string srcdir = m_cmCurrentDirectory;
  272. std::string bindir = m_CurrentOutputDirectory;
  273. std::string::size_type pos = parentList.rfind('/');
  274. m_cmCurrentDirectory = parentList.substr(0, pos);
  275. m_CurrentOutputDirectory = m_HomeOutputDirectory + parentList.substr(m_cmHomeDirectory.size(), pos - m_cmHomeDirectory.size());
  276. // if not found, oops
  277. if(pos == std::string::npos)
  278. {
  279. cmSystemTools::Error("Trailing slash not found");
  280. }
  281. this->ReadListFile(parentList.c_str());
  282. // restore the current directory
  283. m_cmCurrentDirectory = srcdir;
  284. m_CurrentOutputDirectory = bindir;
  285. }
  286. }
  287. // are we at the start CMakeLists file or are we processing a parent
  288. // lists file
  289. //
  290. // this might, or might not be true, irrespective if we are
  291. // off looking at an external makefile.
  292. m_Inheriting = (m_cmCurrentDirectory != m_cmStartDirectory);
  293. // Now read the input file
  294. const char *filenametoread= filename;
  295. if( external)
  296. {
  297. filenametoread= external;
  298. }
  299. cmListFile* lf =
  300. cmListFileCache::GetInstance()->GetFileCache(filenametoread);
  301. if(!lf)
  302. {
  303. return false;
  304. }
  305. // add this list file to the list of dependencies
  306. m_ListFiles.push_back( filenametoread);
  307. const size_t numberFunctions = lf->m_Functions.size();
  308. for(size_t i =0; i < numberFunctions; ++i)
  309. {
  310. cmListFileFunction& curFunction = lf->m_Functions[i];
  311. if(!this->IsFunctionBlocked(curFunction.m_Name.c_str(),
  312. curFunction.m_Arguments))
  313. {
  314. this->ExecuteCommand(curFunction.m_Name,
  315. curFunction.m_Arguments);
  316. }
  317. }
  318. // send scope ended to and funciton blockers
  319. if (filename)
  320. {
  321. // loop over all function blockers to see if any block this command
  322. std::set<cmFunctionBlocker *>::const_iterator pos;
  323. for (pos = m_FunctionBlockers.begin();
  324. pos != m_FunctionBlockers.end(); ++pos)
  325. {
  326. (*pos)->ScopeEnded(*this);
  327. }
  328. }
  329. return true;
  330. }
  331. cmSourceFile *cmMakefile::GetSource(const char *srclist, const char *cname)
  332. {
  333. SourceMap::iterator sl = m_Sources.find(srclist);
  334. // find the src list
  335. if (sl == m_Sources.end())
  336. {
  337. return 0;
  338. }
  339. // find the class
  340. for (std::vector<cmSourceFile*>::iterator i = sl->second.begin();
  341. i != sl->second.end(); ++i)
  342. {
  343. if ((*i)->GetSourceName() == cname)
  344. {
  345. return *i;
  346. }
  347. }
  348. return 0;
  349. }
  350. void cmMakefile::AddCommand(cmCommand* wg)
  351. {
  352. std::string name = wg->GetName();
  353. m_Commands.insert( RegisteredCommandsMap::value_type(name, wg));
  354. }
  355. // Set the make file
  356. void cmMakefile::SetMakefileGenerator(cmMakefileGenerator* mf)
  357. {
  358. if(mf == m_MakefileGenerator)
  359. {
  360. return;
  361. }
  362. delete m_MakefileGenerator;
  363. m_MakefileGenerator = mf;
  364. mf->SetMakefile(this);
  365. }
  366. void cmMakefile::FinalPass()
  367. {
  368. // do all the variable expansions here
  369. this->ExpandVariables();
  370. // give all the commands a chance to do something
  371. // after the file has been parsed before generation
  372. for(std::vector<cmCommand*>::iterator i = m_UsedCommands.begin();
  373. i != m_UsedCommands.end(); ++i)
  374. {
  375. (*i)->FinalPass();
  376. }
  377. }
  378. // Generate the output file
  379. void cmMakefile::GenerateMakefile()
  380. {
  381. this->FinalPass();
  382. // merge libraries
  383. for (cmTargets::iterator l = m_Targets.begin();
  384. l != m_Targets.end(); l++)
  385. {
  386. l->second.GenerateSourceFilesFromSourceLists(*this);
  387. l->second.MergeLibraries(m_LinkLibraries);
  388. }
  389. // now do the generation
  390. m_MakefileGenerator->GenerateMakefile();
  391. }
  392. void cmMakefile::AddSource(cmSourceFile& cmfile, const char *srclist)
  393. {
  394. m_Sources[srclist].push_back(this->AddSource(cmfile));
  395. }
  396. void cmMakefile::RemoveSource(cmSourceFile& cmfile, const char *srclist)
  397. {
  398. std::vector<cmSourceFile*> &maplist = m_Sources[srclist];
  399. for( std::vector<cmSourceFile*>::iterator f = maplist.begin();
  400. f != maplist.end(); ++f)
  401. {
  402. if((*f)->GetSourceName() == cmfile.GetSourceName())
  403. {
  404. maplist.erase(f);
  405. return;
  406. }
  407. }
  408. }
  409. void cmMakefile::AddCustomCommand(const char* source,
  410. const char* command,
  411. const std::vector<std::string>& commandArgs,
  412. const std::vector<std::string>& depends,
  413. const std::vector<std::string>& outputs,
  414. const char *target)
  415. {
  416. // find the target,
  417. if (m_Targets.find(target) != m_Targets.end())
  418. {
  419. std::string expandC = command;
  420. this->ExpandVariablesInString(expandC);
  421. std::string c = cmSystemTools::EscapeSpaces(expandC.c_str());
  422. std::string combinedArgs;
  423. unsigned int i;
  424. for (i = 0; i < commandArgs.size(); ++i)
  425. {
  426. combinedArgs += cmSystemTools::EscapeSpaces(commandArgs[i].c_str());
  427. combinedArgs += " ";
  428. }
  429. cmCustomCommand cc(source,c.c_str(),combinedArgs.c_str(),depends,outputs);
  430. m_Targets[target].GetCustomCommands().push_back(cc);
  431. std::string cacheCommand = command;
  432. this->ExpandVariablesInString(cacheCommand);
  433. if(cmCacheManager::GetInstance()->GetCacheValue(cacheCommand.c_str()))
  434. {
  435. m_Targets[target].AddUtility(
  436. cmCacheManager::GetInstance()->GetCacheValue(cacheCommand.c_str()));
  437. }
  438. }
  439. }
  440. void cmMakefile::AddCustomCommand(const char* source,
  441. const char* command,
  442. const std::vector<std::string>& commandArgs,
  443. const std::vector<std::string>& depends,
  444. const char* output,
  445. const char *target)
  446. {
  447. std::vector<std::string> outputs;
  448. outputs.push_back(output);
  449. this->AddCustomCommand(source, command, commandArgs, depends, outputs, target);
  450. }
  451. void cmMakefile::AddDefineFlag(const char* flag)
  452. {
  453. m_DefineFlags += " ";
  454. m_DefineFlags += flag;
  455. }
  456. void cmMakefile::AddLinkLibrary(const char* lib, cmTarget::LinkLibraryType llt)
  457. {
  458. m_LinkLibraries.push_back(
  459. std::pair<std::string, cmTarget::LinkLibraryType>(lib,llt));
  460. }
  461. void cmMakefile::AddLinkLibraryForTarget(const char *target,
  462. const char* lib,
  463. cmTarget::LinkLibraryType llt)
  464. {
  465. if (m_Targets.find(target) != m_Targets.end())
  466. {
  467. m_Targets[target].GetLinkLibraries().
  468. push_back(
  469. std::pair<std::string, cmTarget::LinkLibraryType>(lib,llt));
  470. }
  471. else
  472. {
  473. cmSystemTools::Error("Attempt to add link libraries to non-existant target: ", target, " for lib ", lib);
  474. }
  475. }
  476. void cmMakefile::AddLinkLibrary(const char* lib)
  477. {
  478. this->AddLinkLibrary(lib,cmTarget::GENERAL);
  479. }
  480. void cmMakefile::AddLinkDirectory(const char* dir)
  481. {
  482. // Don't add a link directory that is already present. Yes, this
  483. // linear search results in n^2 behavior, but n won't be getting
  484. // much bigger than 20. We cannot use a set because of order
  485. // dependency of the link search path.
  486. // remove trailing slashes
  487. if(dir && dir[strlen(dir)-1] == '/')
  488. {
  489. std::string newdir = dir;
  490. newdir = newdir.substr(0, newdir.size()-1);
  491. if(std::find(m_LinkDirectories.begin(),
  492. m_LinkDirectories.end(), newdir.c_str()) == m_LinkDirectories.end())
  493. {
  494. m_LinkDirectories.push_back(newdir);
  495. }
  496. }
  497. else
  498. {
  499. if(std::find(m_LinkDirectories.begin(),
  500. m_LinkDirectories.end(), dir) == m_LinkDirectories.end())
  501. {
  502. m_LinkDirectories.push_back(dir);
  503. }
  504. }
  505. }
  506. void cmMakefile::AddSubDirectory(const char* sub)
  507. {
  508. m_SubDirectories.push_back(sub);
  509. }
  510. void cmMakefile::AddIncludeDirectory(const char* inc, bool before)
  511. {
  512. // Don't add an include directory that is already present. Yes,
  513. // this linear search results in n^2 behavior, but n won't be
  514. // getting much bigger than 20. We cannot use a set because of
  515. // order dependency of the include path.
  516. if(std::find(m_IncludeDirectories.begin(),
  517. m_IncludeDirectories.end(), inc) == m_IncludeDirectories.end())
  518. {
  519. if (before)
  520. {
  521. // WARNING: this *is* expensive (linear time) since it's a vector
  522. m_IncludeDirectories.insert(m_IncludeDirectories.begin(), inc);
  523. }
  524. else
  525. {
  526. m_IncludeDirectories.push_back(inc);
  527. }
  528. }
  529. }
  530. void cmMakefile::AddDefinition(const char* name, const char* value)
  531. {
  532. m_Definitions.erase( DefinitionMap::key_type(name));
  533. m_Definitions.insert(DefinitionMap::value_type(name, value));
  534. }
  535. void cmMakefile::AddCacheDefinition(const char* name, const char* value,
  536. const char* doc,
  537. cmCacheManager::CacheEntryType type)
  538. {
  539. cmCacheManager::GetInstance()->AddCacheEntry(name, value, doc, type);
  540. this->AddDefinition(name, value);
  541. }
  542. void cmMakefile::AddDefinition(const char* name, bool value)
  543. {
  544. if(value)
  545. {
  546. m_Definitions.erase( DefinitionMap::key_type(name));
  547. m_Definitions.insert(DefinitionMap::value_type(name, "ON"));
  548. }
  549. else
  550. {
  551. m_Definitions.erase( DefinitionMap::key_type(name));
  552. m_Definitions.insert(DefinitionMap::value_type(name, "OFF"));
  553. }
  554. }
  555. void cmMakefile::AddCacheDefinition(const char* name, bool value, const char* doc)
  556. {
  557. cmCacheManager::GetInstance()->AddCacheEntry(name, value, doc);
  558. this->AddDefinition(name, value);
  559. }
  560. void cmMakefile::SetProjectName(const char* p)
  561. {
  562. m_ProjectName = p;
  563. }
  564. void cmMakefile::AddLibrary(const char* lname, int shared,
  565. const std::vector<std::string> &srcs)
  566. {
  567. cmTarget target;
  568. switch (shared)
  569. {
  570. case 0:
  571. target.SetType(cmTarget::STATIC_LIBRARY);
  572. break;
  573. case 1:
  574. target.SetType(cmTarget::SHARED_LIBRARY);
  575. break;
  576. case 2:
  577. target.SetType(cmTarget::MODULE_LIBRARY);
  578. break;
  579. default:
  580. target.SetType(cmTarget::STATIC_LIBRARY);
  581. }
  582. target.SetInAll(true);
  583. target.GetSourceLists() = srcs;
  584. m_Targets.insert(cmTargets::value_type(lname,target));
  585. // Add an entry into the cache
  586. cmCacheManager::GetInstance()->
  587. AddCacheEntry(lname,
  588. this->GetCurrentOutputDirectory(),
  589. "Path to a library", cmCacheManager::INTERNAL);
  590. // Add an entry into the cache
  591. std::string ltname = lname;
  592. ltname += "_LIBRARY_TYPE";
  593. switch (shared)
  594. {
  595. case 0:
  596. cmCacheManager::GetInstance()->
  597. AddCacheEntry(ltname.c_str(),
  598. "STATIC",
  599. "Whether a library is static, shared or module.",
  600. cmCacheManager::INTERNAL);
  601. break;
  602. case 1:
  603. cmCacheManager::GetInstance()->
  604. AddCacheEntry(ltname.c_str(),
  605. "SHARED",
  606. "Whether a library is static, shared or module.",
  607. cmCacheManager::INTERNAL);
  608. break;
  609. case 2:
  610. cmCacheManager::GetInstance()->
  611. AddCacheEntry(ltname.c_str(),
  612. "MODULE",
  613. "Whether a library is static, shared or module.",
  614. cmCacheManager::INTERNAL);
  615. break;
  616. default:
  617. cmCacheManager::GetInstance()->
  618. AddCacheEntry(ltname.c_str(),
  619. "STATIC",
  620. "Whether a library is static, shared or module.",
  621. cmCacheManager::INTERNAL);
  622. }
  623. }
  624. void cmMakefile::AddExecutable(const char *exeName,
  625. const std::vector<std::string> &srcs)
  626. {
  627. this->AddExecutable(exeName,srcs,false);
  628. }
  629. void cmMakefile::AddExecutable(const char *exeName,
  630. const std::vector<std::string> &srcs,
  631. bool win32)
  632. {
  633. cmTarget target;
  634. if (win32)
  635. {
  636. target.SetType(cmTarget::WIN32_EXECUTABLE);
  637. }
  638. else
  639. {
  640. target.SetType(cmTarget::EXECUTABLE);
  641. }
  642. target.SetInAll(true);
  643. target.GetSourceLists() = srcs;
  644. m_Targets.insert(cmTargets::value_type(exeName,target));
  645. // Add an entry into the cache
  646. cmCacheManager::GetInstance()->
  647. AddCacheEntry(exeName,
  648. this->GetCurrentOutputDirectory(),
  649. "Path to an executable", cmCacheManager::INTERNAL);
  650. }
  651. void cmMakefile::AddUtilityCommand(const char* utilityName,
  652. const char* command,
  653. const char* arguments,
  654. bool all)
  655. {
  656. std::vector<std::string> empty;
  657. this->AddUtilityCommand(utilityName,command,arguments,all,
  658. empty,empty);
  659. }
  660. void cmMakefile::AddUtilityCommand(const char* utilityName,
  661. const char* command,
  662. const char* arguments,
  663. bool all,
  664. const std::vector<std::string> &dep,
  665. const std::vector<std::string> &out)
  666. {
  667. cmTarget target;
  668. target.SetType(cmTarget::UTILITY);
  669. target.SetInAll(all);
  670. cmCustomCommand cc(utilityName, command, arguments, dep, out);
  671. target.GetCustomCommands().push_back(cc);
  672. m_Targets.insert(cmTargets::value_type(utilityName,target));
  673. }
  674. void cmMakefile::AddSourceGroup(const char* name, const char* regex)
  675. {
  676. // First see if the group exists. If so, replace its regular expression.
  677. for(std::vector<cmSourceGroup>::iterator sg = m_SourceGroups.begin();
  678. sg != m_SourceGroups.end(); ++sg)
  679. {
  680. std::string sgName = sg->GetName();
  681. if(sgName == name)
  682. {
  683. // We only want to set the regular expression. If there are already
  684. // source files in the group, we don't want to remove them.
  685. sg->SetGroupRegex(regex);
  686. return;
  687. }
  688. }
  689. // The group doesn't exist. Add it.
  690. m_SourceGroups.push_back(cmSourceGroup(name, regex));
  691. }
  692. void cmMakefile::AddExtraDirectory(const char* dir)
  693. {
  694. m_AuxSourceDirectories.push_back(dir);
  695. }
  696. // return the file name for the parent CMakeLists file to the
  697. // one passed in. Zero is returned if the CMakeLists file is the
  698. // one in the home directory or if for some reason a parent cmake lists
  699. // file cannot be found.
  700. std::string cmMakefile::GetParentListFileName(const char *currentFileName)
  701. {
  702. // extract the directory name
  703. std::string parentFile;
  704. std::string listsDir = currentFileName;
  705. std::string::size_type pos = listsDir.rfind('/');
  706. // if we could not find the directory return 0
  707. if(pos == std::string::npos)
  708. {
  709. return parentFile;
  710. }
  711. listsDir = listsDir.substr(0, pos);
  712. // if we are in the home directory then stop, return 0
  713. if(m_cmHomeDirectory == listsDir)
  714. {
  715. return parentFile;
  716. }
  717. // is there a parent directory we can check
  718. pos = listsDir.rfind('/');
  719. // if we could not find the directory return 0
  720. if(pos == std::string::npos)
  721. {
  722. return parentFile;
  723. }
  724. listsDir = listsDir.substr(0, pos);
  725. // is there a CMakeLists.txt file in the parent directory ?
  726. parentFile = listsDir;
  727. parentFile += "/CMakeLists.txt";
  728. while(!cmSystemTools::FileExists(parentFile.c_str()))
  729. {
  730. // There is no CMakeLists.txt file in the parent directory. This
  731. // can occur when coming out of a subdirectory resulting from a
  732. // SUBDIRS(Foo/Bar) command (coming out of Bar into Foo). Try
  733. // walking up until a CMakeLists.txt is found or the home
  734. // directory is hit.
  735. // if we are in the home directory then stop, return 0
  736. if(m_cmHomeDirectory == listsDir) { return ""; }
  737. // is there a parent directory we can check
  738. pos = listsDir.rfind('/');
  739. // if we could not find the directory return 0
  740. if(pos == std::string::npos) { return ""; }
  741. listsDir = listsDir.substr(0, pos);
  742. parentFile = listsDir;
  743. parentFile += "/CMakeLists.txt";
  744. }
  745. return parentFile;
  746. }
  747. // expance CMAKE_BINARY_DIR and CMAKE_SOURCE_DIR in the
  748. // include and library directories.
  749. void cmMakefile::ExpandVariables()
  750. {
  751. // Now expand varibles in the include and link strings
  752. for(std::vector<std::string>::iterator d = m_IncludeDirectories.begin();
  753. d != m_IncludeDirectories.end(); ++d)
  754. {
  755. this->ExpandVariablesInString(*d);
  756. }
  757. for(std::vector<std::string>::iterator d = m_LinkDirectories.begin();
  758. d != m_LinkDirectories.end(); ++d)
  759. {
  760. this->ExpandVariablesInString(*d);
  761. }
  762. for(cmTarget::LinkLibraries::iterator l = m_LinkLibraries.begin();
  763. l != m_LinkLibraries.end(); ++l)
  764. {
  765. this->ExpandVariablesInString(l->first);
  766. }
  767. }
  768. bool cmMakefile::IsOn(const char* name)
  769. {
  770. const char* value = this->GetDefinition(name);
  771. return cmSystemTools::IsOn(value);
  772. }
  773. const char* cmMakefile::GetDefinition(const char* name) const
  774. {
  775. DefinitionMap::const_iterator pos = m_Definitions.find(name);
  776. if(pos != m_Definitions.end())
  777. {
  778. return (*pos).second.c_str();
  779. }
  780. return cmCacheManager::GetInstance()->GetCacheValue(name);
  781. }
  782. int cmMakefile::DumpDocumentationToFile(std::ostream& f)
  783. {
  784. // Open the supplied filename
  785. // Loop over all registered commands and print out documentation
  786. const char *name;
  787. const char *terse;
  788. const char *full;
  789. char tmp[1024];
  790. sprintf(tmp,"Version %d.%d", cmMakefile::GetMajorVersion(),
  791. cmMakefile::GetMinorVersion());
  792. f << "<html>\n";
  793. f << "<h1>Documentation for commands of CMake " << tmp << "</h1>\n";
  794. f << "<ul>\n";
  795. for(RegisteredCommandsMap::iterator j = m_Commands.begin();
  796. j != m_Commands.end(); ++j)
  797. {
  798. name = (*j).second->GetName();
  799. terse = (*j).second->GetTerseDocumentation();
  800. full = (*j).second->GetFullDocumentation();
  801. f << "<li><b>" << name << "</b> - " << terse << std::endl
  802. << "<br><i>Usage:</i> " << full << "</li>" << std::endl << std::endl;
  803. }
  804. f << "</ul></html>\n";
  805. return 1;
  806. }
  807. const char *cmMakefile::ExpandVariablesInString(std::string& source) const
  808. {
  809. return this->ExpandVariablesInString(source, false);
  810. }
  811. const char *cmMakefile::ExpandVariablesInString(std::string& source,
  812. bool escapeQuotes,
  813. bool atOnly) const
  814. {
  815. // This method replaces ${VAR} and @VAR@ where VAR is looked up
  816. // with GetDefinition(), if not found in the map, nothing is expanded.
  817. // It also supports the $ENV{VAR} syntax where VAR is looked up in
  818. // the current environment variables.
  819. // start by look for $ or @ in the string
  820. std::string::size_type markerPos;
  821. if(atOnly)
  822. {
  823. markerPos = source.find_first_of("@");
  824. }
  825. else
  826. {
  827. markerPos = source.find_first_of("$@");
  828. }
  829. // if not found, or found as the last character, then leave quickly as
  830. // nothing needs to be expanded
  831. if((markerPos == std::string::npos) || (markerPos >= source.size()-1))
  832. {
  833. return source.c_str();
  834. }
  835. // current position
  836. std::string::size_type currentPos =0; // start at 0
  837. std::string result; // string with replacements
  838. // go until the the end of the string
  839. while((markerPos != std::string::npos) && (markerPos < source.size()-1))
  840. {
  841. // grab string from currentPos to the start of the variable
  842. // and add it to the result
  843. result += source.substr(currentPos, markerPos - currentPos);
  844. char endVariableMarker; // what is the end of the variable @ or }
  845. int markerStartSize = 1; // size of the start marker 1 or 2 or 5
  846. if(!atOnly && source[markerPos] == '$')
  847. {
  848. // ${var} case
  849. if(source[markerPos+1] == '{')
  850. {
  851. endVariableMarker = '}';
  852. markerStartSize = 2;
  853. }
  854. // $ENV{var} case
  855. else if(markerPos+4 < source.size() &&
  856. source[markerPos+4] == '{' &&
  857. !source.substr(markerPos+1, 3).compare("ENV"))
  858. {
  859. endVariableMarker = '}';
  860. markerStartSize = 5;
  861. }
  862. else
  863. {
  864. // bogus $ with no { so add $ to result and move on
  865. result += '$'; // add bogus $ back into string
  866. currentPos = markerPos+1; // move on
  867. endVariableMarker = ' '; // set end var to space so we can tell bogus
  868. }
  869. }
  870. else
  871. {
  872. // @VAR case
  873. endVariableMarker = '@';
  874. }
  875. // if it was a valid variable (started with @ or ${ or $ENV{ )
  876. if(endVariableMarker != ' ')
  877. {
  878. markerPos += markerStartSize; // move past marker
  879. // find the end variable marker starting at the markerPos
  880. std::string::size_type endVariablePos =
  881. source.find(endVariableMarker, markerPos);
  882. if(endVariablePos == std::string::npos)
  883. {
  884. // no end marker found so add the bogus start
  885. if(endVariableMarker == '@')
  886. {
  887. result += '@';
  888. }
  889. else
  890. {
  891. result += (markerStartSize == 5 ? "$ENV{" : "${");
  892. }
  893. currentPos = markerPos;
  894. }
  895. else
  896. {
  897. // good variable remove it
  898. std::string var = source.substr(markerPos, endVariablePos - markerPos);
  899. bool found = false;
  900. if (markerStartSize == 5) // $ENV{
  901. {
  902. char *ptr = getenv(var.c_str());
  903. if (ptr)
  904. {
  905. if (escapeQuotes)
  906. {
  907. result += cmSystemTools::EscapeQuotes(ptr);
  908. }
  909. else
  910. {
  911. result += ptr;
  912. }
  913. found = true;
  914. }
  915. }
  916. else
  917. {
  918. const char* lookup = this->GetDefinition(var.c_str());
  919. if(lookup)
  920. {
  921. if (escapeQuotes)
  922. {
  923. result += cmSystemTools::EscapeQuotes(lookup);
  924. }
  925. else
  926. {
  927. result += lookup;
  928. }
  929. found = true;
  930. }
  931. }
  932. // if found add to result, if not, then it gets blanked
  933. if (!found)
  934. {
  935. // if no definition is found then add the var back
  936. if(endVariableMarker == '@')
  937. {
  938. result += "@";
  939. result += var;
  940. result += "@";
  941. }
  942. else
  943. {
  944. result += (markerStartSize == 5 ? "$ENV{" : "${");
  945. result += var;
  946. result += "}";
  947. }
  948. }
  949. // lookup var, and replace it
  950. currentPos = endVariablePos+1;
  951. }
  952. }
  953. if(atOnly)
  954. {
  955. markerPos = source.find_first_of("@", currentPos);
  956. }
  957. else
  958. {
  959. markerPos = source.find_first_of("$@", currentPos);
  960. }
  961. }
  962. result += source.substr(currentPos); // pick up the rest of the string
  963. source = result;
  964. return source.c_str();
  965. }
  966. void cmMakefile::RemoveVariablesInString(std::string& source,
  967. bool atOnly) const
  968. {
  969. if(!atOnly)
  970. {
  971. cmRegularExpression var("(\\${[A-Za-z_0-9]*})");
  972. while (var.find(source))
  973. {
  974. source.erase(var.start(),var.end() - var.start());
  975. }
  976. }
  977. if(!atOnly)
  978. {
  979. cmRegularExpression varb("(\\$ENV{[A-Za-z_0-9]*})");
  980. while (varb.find(source))
  981. {
  982. source.erase(varb.start(),varb.end() - varb.start());
  983. }
  984. }
  985. cmRegularExpression var2("(@[A-Za-z_0-9]*@)");
  986. while (var2.find(source))
  987. {
  988. source.erase(var2.start(),var2.end() - var2.start());
  989. }
  990. }
  991. // recursive function to create a vector of cmMakefile objects
  992. // This is done by reading the sub directory CMakeLists.txt files,
  993. // then calling this function with the new cmMakefile object
  994. void
  995. cmMakefile::FindSubDirectoryCMakeListsFiles(std::vector<cmMakefile*>& makefiles)
  996. {
  997. // loop over all the sub directories of this makefile
  998. const std::vector<std::string>& subdirs = this->GetSubDirectories();
  999. for(std::vector<std::string>::const_iterator i = subdirs.begin();
  1000. i != subdirs.end(); ++i)
  1001. {
  1002. std::string subdir = *i;
  1003. // Create a path to the list file in the sub directory
  1004. std::string listFile = this->GetCurrentDirectory();
  1005. listFile += "/";
  1006. listFile += subdir;
  1007. listFile += "/CMakeLists.txt";
  1008. // if there is a CMakeLists.txt file read it
  1009. if(!cmSystemTools::FileExists(listFile.c_str()))
  1010. {
  1011. cmSystemTools::Error("CMakeLists.txt file missing from sub directory:",
  1012. listFile.c_str());
  1013. }
  1014. else
  1015. {
  1016. cmMakefile* mf = new cmMakefile;
  1017. mf->SetMakefileGenerator(m_MakefileGenerator->CreateObject());
  1018. makefiles.push_back(mf);
  1019. // initialize new makefile
  1020. mf->SetHomeOutputDirectory(this->GetHomeOutputDirectory());
  1021. mf->SetHomeDirectory(this->GetHomeDirectory());
  1022. // add the subdir to the start output directory
  1023. std::string outdir = this->GetStartOutputDirectory();
  1024. outdir += "/";
  1025. outdir += subdir;
  1026. mf->SetStartOutputDirectory(outdir.c_str());
  1027. // add the subdir to the start source directory
  1028. std::string currentDir = this->GetStartDirectory();
  1029. currentDir += "/";
  1030. currentDir += subdir;
  1031. mf->SetStartDirectory(currentDir.c_str());
  1032. // Parse the CMakeLists.txt file
  1033. currentDir += "/CMakeLists.txt";
  1034. mf->MakeStartDirectoriesCurrent();
  1035. mf->ReadListFile(currentDir.c_str());
  1036. // recurse into nextDir
  1037. mf->FindSubDirectoryCMakeListsFiles(makefiles);
  1038. }
  1039. }
  1040. }
  1041. /**
  1042. * Add the default definitions to the makefile. These values must not
  1043. * be dependent on anything that isn't known when this cmMakefile instance
  1044. * is constructed.
  1045. */
  1046. void cmMakefile::AddDefaultDefinitions()
  1047. {
  1048. #if defined(_WIN32) && !defined(__CYGWIN__)
  1049. this->AddDefinition("CMAKE_CFG_INTDIR","$(IntDir)");
  1050. #else
  1051. this->AddDefinition("CMAKE_CFG_INTDIR",".");
  1052. #endif
  1053. char temp[1024];
  1054. sprintf(temp, "%d", cmMakefile::GetMinorVersion());
  1055. this->AddDefinition("CMAKE_MINOR_VERSION", temp);
  1056. sprintf(temp, "%d", cmMakefile::GetMajorVersion());
  1057. this->AddDefinition("CMAKE_MAJOR_VERSION", temp);
  1058. }
  1059. /**
  1060. * Find a source group whose regular expression matches the filename
  1061. * part of the given source name. Search backward through the list of
  1062. * source groups, and take the first matching group found. This way
  1063. * non-inherited SOURCE_GROUP commands will have precedence over
  1064. * inherited ones.
  1065. */
  1066. cmSourceGroup&
  1067. cmMakefile::FindSourceGroup(const char* source,
  1068. std::vector<cmSourceGroup> &groups)
  1069. {
  1070. std::string file = source;
  1071. std::string::size_type pos = file.rfind('/');
  1072. if(pos != std::string::npos)
  1073. {
  1074. file = file.substr(pos, file.length()-pos);
  1075. }
  1076. for(std::vector<cmSourceGroup>::reverse_iterator sg = groups.rbegin();
  1077. sg != groups.rend(); ++sg)
  1078. {
  1079. if(sg->Matches(file.c_str()))
  1080. {
  1081. return *sg;
  1082. }
  1083. }
  1084. // Shouldn't get here, but just in case, return the default group.
  1085. return groups.front();
  1086. }
  1087. bool cmMakefile::IsFunctionBlocked(const char *name,
  1088. std::vector<std::string> const&args)
  1089. {
  1090. // loop over all function blockers to see if any block this command
  1091. std::set<cmFunctionBlocker *>::const_iterator pos;
  1092. std::vector<std::string> expandedArguments = args;
  1093. for(std::vector<std::string>::iterator i = expandedArguments.begin();
  1094. i != expandedArguments.end(); ++i)
  1095. {
  1096. this->ExpandVariablesInString(*i);
  1097. }
  1098. for (pos = m_FunctionBlockers.begin();
  1099. pos != m_FunctionBlockers.end(); ++pos)
  1100. {
  1101. if ((*pos)->NeedExpandedVariables())
  1102. {
  1103. if ((*pos)->IsFunctionBlocked(name, expandedArguments, *this))
  1104. {
  1105. return true;
  1106. }
  1107. }
  1108. else
  1109. {
  1110. if ((*pos)->IsFunctionBlocked(name, args, *this))
  1111. {
  1112. return true;
  1113. }
  1114. }
  1115. }
  1116. return false;
  1117. }
  1118. void cmMakefile::RemoveFunctionBlocker(const char *name,
  1119. const std::vector<std::string> &args)
  1120. {
  1121. // loop over all function blockers to see if any block this command
  1122. std::set<cmFunctionBlocker *>::const_iterator pos;
  1123. for (pos = m_FunctionBlockers.begin();
  1124. pos != m_FunctionBlockers.end(); ++pos)
  1125. {
  1126. if ((*pos)->ShouldRemove(name, args, *this))
  1127. {
  1128. cmFunctionBlocker* b = *pos;
  1129. m_FunctionBlockers.erase(*pos);
  1130. delete b;
  1131. return;
  1132. }
  1133. }
  1134. return;
  1135. }
  1136. void cmMakefile::SetHomeDirectory(const char* dir)
  1137. {
  1138. m_cmHomeDirectory = dir;
  1139. cmSystemTools::ConvertToUnixSlashes(m_cmHomeDirectory);
  1140. this->AddDefinition("CMAKE_SOURCE_DIR", this->GetHomeDirectory());
  1141. }
  1142. void cmMakefile::SetHomeOutputDirectory(const char* lib)
  1143. {
  1144. m_HomeOutputDirectory = lib;
  1145. cmSystemTools::ConvertToUnixSlashes(m_HomeOutputDirectory);
  1146. this->AddDefinition("CMAKE_BINARY_DIR", this->GetHomeOutputDirectory());
  1147. }
  1148. /**
  1149. * Register the given cmData instance with its own name.
  1150. */
  1151. void cmMakefile::RegisterData(cmData* data)
  1152. {
  1153. std::string name = data->GetName();
  1154. DataMap::const_iterator d = m_DataMap.find(name);
  1155. if((d != m_DataMap.end()) && (d->second != NULL) && (d->second != data))
  1156. {
  1157. delete d->second;
  1158. }
  1159. m_DataMap[name] = data;
  1160. }
  1161. /**
  1162. * Register the given cmData instance with the given name. This can be used
  1163. * to register a NULL pointer.
  1164. */
  1165. void cmMakefile::RegisterData(const char* name, cmData* data)
  1166. {
  1167. DataMap::const_iterator d = m_DataMap.find(name);
  1168. if((d != m_DataMap.end()) && (d->second != NULL) && (d->second != data))
  1169. {
  1170. delete d->second;
  1171. }
  1172. m_DataMap[name] = data;
  1173. }
  1174. /**
  1175. * Lookup a cmData instance previously registered with the given name. If
  1176. * the instance cannot be found, return NULL.
  1177. */
  1178. cmData* cmMakefile::LookupData(const char* name) const
  1179. {
  1180. DataMap::const_iterator d = m_DataMap.find(name);
  1181. if(d != m_DataMap.end())
  1182. {
  1183. return d->second;
  1184. }
  1185. else
  1186. {
  1187. return NULL;
  1188. }
  1189. }
  1190. cmSourceFile* cmMakefile::GetSource(const char* sourceName)
  1191. {
  1192. std::string s = sourceName;
  1193. std::string ext;
  1194. std::string::size_type pos = s.rfind('.');
  1195. if(pos != std::string::npos)
  1196. {
  1197. ext = s.substr(pos+1, s.size() - pos-1);
  1198. s = s.substr(0, pos);
  1199. }
  1200. for(std::vector<cmSourceFile*>::iterator i = m_SourceFiles.begin();
  1201. i != m_SourceFiles.end(); ++i)
  1202. {
  1203. if((*i)->GetSourceName() == s
  1204. && (ext.size() == 0 || (ext == (*i)->GetSourceExtension())))
  1205. {
  1206. return *i;
  1207. }
  1208. }
  1209. return 0;
  1210. }
  1211. cmSourceFile* cmMakefile::AddSource(cmSourceFile const&sf)
  1212. {
  1213. // check to see if it exists
  1214. cmSourceFile* ret = this->GetSource(sf.GetSourceName().c_str());
  1215. if(ret && ret->GetSourceExtension() == sf.GetSourceExtension())
  1216. {
  1217. return ret;
  1218. }
  1219. ret = new cmSourceFile(sf);
  1220. m_SourceFiles.push_back(ret);
  1221. return ret;
  1222. }
  1223. void cmMakefile::EnableLanguage(const char* lang)
  1224. {
  1225. m_MakefileGenerator->EnableLanguage(lang);
  1226. }