cmMakefile.cxx 39 KB

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