cmMakefile.cxx 76 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html 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 "cmSourceFile.h"
  16. #include "cmSystemTools.h"
  17. #include "cmGlobalGenerator.h"
  18. #include "cmLocalGenerator.h"
  19. #include "cmCommands.h"
  20. #include "cmCacheManager.h"
  21. #include "cmFunctionBlocker.h"
  22. #include "cmListFileCache.h"
  23. #include "cmCommandArgumentParserHelper.h"
  24. #include "cmTest.h"
  25. #ifdef CMAKE_BUILD_WITH_CMAKE
  26. # include "cmVariableWatch.h"
  27. #endif
  28. #include "cmInstallGenerator.h"
  29. #include "cmake.h"
  30. #include <stdlib.h> // required for atoi
  31. #include <cmsys/RegularExpression.hxx>
  32. // default is not to be building executables
  33. cmMakefile::cmMakefile()
  34. {
  35. // Setup the default include file regular expression (match everything).
  36. this->IncludeFileRegularExpression = "^.*$";
  37. // Setup the default include complaint regular expression (match nothing).
  38. this->ComplainFileRegularExpression = "^$";
  39. // Source and header file extensions that we can handle
  40. // Set up a list of source and header extensions
  41. // these are used to find files when the extension
  42. // is not given
  43. // The "c" extension MUST precede the "C" extension.
  44. this->SourceFileExtensions.push_back( "c" );
  45. this->SourceFileExtensions.push_back( "C" );
  46. this->SourceFileExtensions.push_back( "c++" );
  47. this->SourceFileExtensions.push_back( "cc" );
  48. this->SourceFileExtensions.push_back( "cpp" );
  49. this->SourceFileExtensions.push_back( "cxx" );
  50. this->SourceFileExtensions.push_back( "m" );
  51. this->SourceFileExtensions.push_back( "M" );
  52. this->SourceFileExtensions.push_back( "mm" );
  53. this->HeaderFileExtensions.push_back( "h" );
  54. this->HeaderFileExtensions.push_back( "h++" );
  55. this->HeaderFileExtensions.push_back( "hm" );
  56. this->HeaderFileExtensions.push_back( "hpp" );
  57. this->HeaderFileExtensions.push_back( "hxx" );
  58. this->HeaderFileExtensions.push_back( "in" );
  59. this->HeaderFileExtensions.push_back( "txx" );
  60. this->DefineFlags = " ";
  61. this->LocalGenerator = 0;
  62. #if defined(CMAKE_BUILD_WITH_CMAKE)
  63. this->AddSourceGroup("", "^.*$");
  64. this->AddSourceGroup
  65. ("Source Files",
  66. "\\.(C|M|c|c\\+\\+|cc|cpp|cxx|m|mm|rc|def|r|odl|idl|hpj|bat)$");
  67. this->AddSourceGroup("Header Files",
  68. "\\.(h|h\\+\\+|hm|hpp|hxx|in|txx|inl)$");
  69. this->AddSourceGroup("CMake Rules", "\\.rule$");
  70. this->AddSourceGroup("Resources", "\\.plist$");
  71. #endif
  72. this->AddDefaultDefinitions();
  73. this->cmDefineRegex.compile("#cmakedefine[ \t]+([A-Za-z_0-9]*)");
  74. this->cmDefine01Regex.compile("#cmakedefine01[ \t]+([A-Za-z_0-9]*)");
  75. this->PreOrder = false;
  76. }
  77. const char* cmMakefile::GetReleaseVersion()
  78. {
  79. #if CMake_VERSION_MINOR & 1
  80. return "development";
  81. #else
  82. # if CMake_VERSION_PATCH == 0
  83. return "beta";
  84. # else
  85. return "patch " CMAKE_TO_STRING(CMake_VERSION_PATCH);
  86. # endif
  87. #endif
  88. }
  89. unsigned int cmMakefile::GetCacheMajorVersion()
  90. {
  91. if(const char* vstr =
  92. this->GetCacheManager()->GetCacheValue("CMAKE_CACHE_MAJOR_VERSION"))
  93. {
  94. unsigned int v=0;
  95. if(sscanf(vstr, "%u", &v) == 1)
  96. {
  97. return v;
  98. }
  99. }
  100. return 0;
  101. }
  102. unsigned int cmMakefile::GetCacheMinorVersion()
  103. {
  104. if(const char* vstr =
  105. this->GetCacheManager()->GetCacheValue("CMAKE_CACHE_MINOR_VERSION"))
  106. {
  107. unsigned int v=0;
  108. if(sscanf(vstr, "%u", &v) == 1)
  109. {
  110. return v;
  111. }
  112. }
  113. return 0;
  114. }
  115. cmMakefile::~cmMakefile()
  116. {
  117. for(std::vector<cmInstallGenerator*>::iterator
  118. i = this->InstallGenerators.begin();
  119. i != this->InstallGenerators.end(); ++i)
  120. {
  121. delete *i;
  122. }
  123. for(std::vector<cmSourceFile*>::iterator i = this->SourceFiles.begin();
  124. i != this->SourceFiles.end(); ++i)
  125. {
  126. delete *i;
  127. }
  128. for(std::vector<cmTest*>::iterator i = this->Tests.begin();
  129. i != this->Tests.end(); ++i)
  130. {
  131. delete *i;
  132. }
  133. for(unsigned int i=0; i < this->UsedCommands.size(); i++)
  134. {
  135. delete this->UsedCommands[i];
  136. }
  137. for(DataMapType::const_iterator d = this->DataMap.begin();
  138. d != this->DataMap.end(); ++d)
  139. {
  140. if(d->second)
  141. {
  142. delete d->second;
  143. }
  144. }
  145. std::list<cmFunctionBlocker *>::iterator pos;
  146. for (pos = this->FunctionBlockers.begin();
  147. pos != this->FunctionBlockers.end(); ++pos)
  148. {
  149. cmFunctionBlocker* b = *pos;
  150. delete b;
  151. }
  152. this->FunctionBlockers.clear();
  153. }
  154. void cmMakefile::PrintStringVector(const char* s,
  155. const std::vector<std::string>& v) const
  156. {
  157. std::cout << s << ": ( \n";
  158. for(std::vector<std::string>::const_iterator i = v.begin();
  159. i != v.end(); ++i)
  160. {
  161. std::cout << (*i).c_str() << " ";
  162. }
  163. std::cout << " )\n";
  164. }
  165. void cmMakefile
  166. ::PrintStringVector(const char* s,
  167. const std::vector<std::pair<cmStdString, bool> >& v) const
  168. {
  169. std::cout << s << ": ( \n";
  170. for(std::vector<std::pair<cmStdString, bool> >::const_iterator i
  171. = v.begin(); i != v.end(); ++i)
  172. {
  173. std::cout << i->first.c_str() << " " << i->second;
  174. }
  175. std::cout << " )\n";
  176. }
  177. // call print on all the classes in the makefile
  178. void cmMakefile::Print()
  179. {
  180. // print the class lists
  181. std::cout << "classes:\n";
  182. std::cout << " this->Targets: ";
  183. for (cmTargets::iterator l = this->Targets.begin();
  184. l != this->Targets.end(); l++)
  185. {
  186. std::cout << l->first << std::endl;
  187. }
  188. std::cout << " this->StartOutputDirectory; " <<
  189. this->StartOutputDirectory.c_str() << std::endl;
  190. std::cout << " this->HomeOutputDirectory; " <<
  191. this->HomeOutputDirectory.c_str() << std::endl;
  192. std::cout << " this->cmStartDirectory; " <<
  193. this->cmStartDirectory.c_str() << std::endl;
  194. std::cout << " this->cmHomeDirectory; " <<
  195. this->cmHomeDirectory.c_str() << std::endl;
  196. std::cout << " this->ProjectName; "
  197. << this->ProjectName.c_str() << std::endl;
  198. this->PrintStringVector("this->IncludeDirectories;",
  199. this->IncludeDirectories);
  200. this->PrintStringVector("this->LinkDirectories", this->LinkDirectories);
  201. #if defined(CMAKE_BUILD_WITH_CMAKE)
  202. for( std::vector<cmSourceGroup>::const_iterator i =
  203. this->SourceGroups.begin(); i != this->SourceGroups.end(); ++i)
  204. {
  205. std::cout << "Source Group: " << i->GetName() << std::endl;
  206. }
  207. #endif
  208. }
  209. bool cmMakefile::CommandExists(const char* name) const
  210. {
  211. return this->GetCMakeInstance()->CommandExists(name);
  212. }
  213. bool cmMakefile::ExecuteCommand(const cmListFileFunction& lff)
  214. {
  215. bool result = true;
  216. // quick return if blocked
  217. if(this->IsFunctionBlocked(lff))
  218. {
  219. // No error.
  220. return result;
  221. }
  222. std::string name = lff.Name;
  223. // execute the command
  224. cmCommand *rm =
  225. this->GetCMakeInstance()->GetCommand(name.c_str());
  226. if(rm)
  227. {
  228. const char* versionValue
  229. = this->GetDefinition("CMAKE_BACKWARDS_COMPATIBILITY");
  230. int major = 0;
  231. int minor = 0;
  232. if ( versionValue )
  233. {
  234. sscanf(versionValue, "%d.%d", &major, &minor);
  235. }
  236. if ( rm->IsDeprecated(major, minor) )
  237. {
  238. cmOStringStream error;
  239. error << "Error in cmake code at\n"
  240. << lff.FilePath << ":" << lff.Line << ":\n"
  241. << rm->GetError();
  242. cmSystemTools::Error(error.str().c_str());
  243. return false;
  244. }
  245. cmCommand* usedCommand = rm->Clone();
  246. usedCommand->SetMakefile(this);
  247. bool keepCommand = false;
  248. if(usedCommand->GetEnabled() && !cmSystemTools::GetFatalErrorOccured() &&
  249. (!this->GetCMakeInstance()->GetScriptMode() ||
  250. usedCommand->IsScriptable()))
  251. {
  252. if(!usedCommand->InvokeInitialPass(lff.Arguments))
  253. {
  254. cmOStringStream error;
  255. error << "Error in cmake code at\n"
  256. << lff.FilePath << ":" << lff.Line << ":\n"
  257. << usedCommand->GetError();
  258. cmSystemTools::Error(error.str().c_str());
  259. result = false;
  260. if ( this->GetCMakeInstance()->GetScriptMode() )
  261. {
  262. cmSystemTools::SetFatalErrorOccured();
  263. }
  264. }
  265. else
  266. {
  267. // use the command
  268. keepCommand = true;
  269. this->UsedCommands.push_back(usedCommand);
  270. }
  271. }
  272. else if ( this->GetCMakeInstance()->GetScriptMode()
  273. && !usedCommand->IsScriptable() )
  274. {
  275. cmOStringStream error;
  276. error << "Error in cmake code at\n"
  277. << lff.FilePath << ":" << lff.Line << ":\n"
  278. << "Command " << usedCommand->GetName()
  279. << " not scriptable" << std::endl;
  280. cmSystemTools::Error(error.str().c_str());
  281. result = false;
  282. cmSystemTools::SetFatalErrorOccured();
  283. }
  284. // if the Cloned command was not used
  285. // then delete it
  286. if(!keepCommand)
  287. {
  288. delete usedCommand;
  289. }
  290. }
  291. else
  292. {
  293. if(!cmSystemTools::GetFatalErrorOccured())
  294. {
  295. cmOStringStream error;
  296. error << "Error in cmake code at\n"
  297. << lff.FilePath << ":" << lff.Line << ":\n"
  298. << "Unknown CMake command \"" << lff.Name.c_str() << "\".";
  299. cmSystemTools::Error(error.str().c_str());
  300. result = false;
  301. }
  302. }
  303. return result;
  304. }
  305. // Parse the given CMakeLists.txt file executing all commands
  306. //
  307. bool cmMakefile::ReadListFile(const char* filename_in,
  308. const char *external_in)
  309. {
  310. std::string currentFile = this->GetSafeDefinition("CMAKE_PARENT_LIST_FILE");
  311. this->AddDefinition("CMAKE_PARENT_LIST_FILE", filename_in);
  312. // used to watch for blockers going out of scope
  313. // e.g. mismatched IF statement
  314. std::set<cmFunctionBlocker *> originalBlockers;
  315. const char* external = 0;
  316. std::string external_abs;
  317. const char* filename = filename_in;
  318. std::string filename_abs;
  319. if (external_in)
  320. {
  321. external_abs =
  322. cmSystemTools::CollapseFullPath(external_in,
  323. this->cmStartDirectory.c_str());
  324. external = external_abs.c_str();
  325. if (filename_in)
  326. {
  327. filename_abs =
  328. cmSystemTools::CollapseFullPath(filename_in,
  329. this->cmStartDirectory.c_str());
  330. filename = filename_abs.c_str();
  331. }
  332. }
  333. // keep track of the current file being read
  334. if (filename)
  335. {
  336. if(this->cmCurrentListFile != filename)
  337. {
  338. this->cmCurrentListFile = filename;
  339. }
  340. // loop over current function blockers and record them
  341. std::list<cmFunctionBlocker *>::iterator pos;
  342. for (pos = this->FunctionBlockers.begin();
  343. pos != this->FunctionBlockers.end(); ++pos)
  344. {
  345. originalBlockers.insert(*pos);
  346. }
  347. }
  348. // Now read the input file
  349. const char *filenametoread= filename;
  350. if( external)
  351. {
  352. filenametoread= external;
  353. }
  354. // try to see if the list file is the top most
  355. // list file for a project, and if it is, then it
  356. // must have a project command. If there is not
  357. // one, then cmake will provide one via the
  358. // cmListFileCache class.
  359. bool requireProjectCommand = false;
  360. if(!external && this->cmStartDirectory == this->cmHomeDirectory)
  361. {
  362. if(cmSystemTools::LowerCase(
  363. cmSystemTools::GetFilenameName(filename)) == "cmakelists.txt")
  364. {
  365. requireProjectCommand = true;
  366. }
  367. }
  368. // push the listfile onto the stack
  369. this->ListFileStack.push_back(filenametoread);
  370. cmListFile cacheFile;
  371. if( !cacheFile.ParseFile(filenametoread, requireProjectCommand) )
  372. {
  373. this->AddDefinition("CMAKE_PARENT_LIST_FILE", currentFile.c_str());
  374. return false;
  375. }
  376. // add this list file to the list of dependencies
  377. this->ListFiles.push_back( filenametoread);
  378. const size_t numberFunctions = cacheFile.Functions.size();
  379. for(size_t i =0; i < numberFunctions; ++i)
  380. {
  381. this->ExecuteCommand(cacheFile.Functions[i]);
  382. if ( cmSystemTools::GetFatalErrorOccured() )
  383. {
  384. // pop the listfile off the stack
  385. this->ListFileStack.pop_back();
  386. this->AddDefinition("CMAKE_PARENT_LIST_FILE", currentFile.c_str());
  387. return true;
  388. }
  389. }
  390. // send scope ended to and function blockers
  391. if (filename)
  392. {
  393. // loop over all function blockers to see if any block this command
  394. std::list<cmFunctionBlocker *>::iterator pos;
  395. for (pos = this->FunctionBlockers.begin();
  396. pos != this->FunctionBlockers.end(); ++pos)
  397. {
  398. // if this blocker was not in the original then send a
  399. // scope ended message
  400. if (originalBlockers.find(*pos) == originalBlockers.end())
  401. {
  402. (*pos)->ScopeEnded(*this);
  403. }
  404. }
  405. }
  406. this->AddDefinition("CMAKE_PARENT_LIST_FILE", currentFile.c_str());
  407. // pop the listfile off the stack
  408. this->ListFileStack.pop_back();
  409. return true;
  410. }
  411. void cmMakefile::AddCommand(cmCommand* wg)
  412. {
  413. this->GetCMakeInstance()->AddCommand(wg);
  414. }
  415. // Set the make file
  416. void cmMakefile::SetLocalGenerator(cmLocalGenerator* lg)
  417. {
  418. this->LocalGenerator = lg;
  419. }
  420. void cmMakefile::FinalPass()
  421. {
  422. // do all the variable expansions here
  423. this->ExpandVariables();
  424. // give all the commands a chance to do something
  425. // after the file has been parsed before generation
  426. for(std::vector<cmCommand*>::iterator i = this->UsedCommands.begin();
  427. i != this->UsedCommands.end(); ++i)
  428. {
  429. (*i)->FinalPass();
  430. }
  431. }
  432. // Generate the output file
  433. void cmMakefile::ConfigureFinalPass()
  434. {
  435. this->FinalPass();
  436. const char* oldValue
  437. = this->GetDefinition("CMAKE_BACKWARDS_COMPATIBILITY");
  438. if (oldValue && atof(oldValue) <= 1.2)
  439. {
  440. cmSystemTools::Error("You have requested backwards compatibility "
  441. "with CMake version 1.2 or earlier. This version "
  442. "of CMake only supports backwards compatibility "
  443. "with CMake 1.4 or later. For compatibility with "
  444. "1.2 or earlier please use CMake 2.0");
  445. }
  446. for (cmTargets::iterator l = this->Targets.begin();
  447. l != this->Targets.end(); l++)
  448. {
  449. l->second.GenerateSourceFilesFromSourceLists(*this);
  450. l->second.AnalyzeLibDependencies(*this);
  451. }
  452. }
  453. //----------------------------------------------------------------------------
  454. void
  455. cmMakefile::AddCustomCommandToTarget(const char* target,
  456. const std::vector<std::string>& depends,
  457. const cmCustomCommandLines& commandLines,
  458. cmTarget::CustomCommandType type,
  459. const char* comment,
  460. const char* workingDir)
  461. {
  462. // Find the target to which to add the custom command.
  463. cmTargets::iterator ti = this->Targets.find(target);
  464. if(ti != this->Targets.end())
  465. {
  466. // Add the command to the appropriate build step for the target.
  467. std::vector<std::string> no_output;
  468. cmCustomCommand cc(no_output, depends, commandLines, comment, workingDir);
  469. switch(type)
  470. {
  471. case cmTarget::PRE_BUILD:
  472. ti->second.GetPreBuildCommands().push_back(cc);
  473. break;
  474. case cmTarget::PRE_LINK:
  475. ti->second.GetPreLinkCommands().push_back(cc);
  476. break;
  477. case cmTarget::POST_BUILD:
  478. ti->second.GetPostBuildCommands().push_back(cc);
  479. break;
  480. }
  481. // Add dependencies on commands CMake knows how to build.
  482. for(cmCustomCommandLines::const_iterator cli = commandLines.begin();
  483. cli != commandLines.end(); ++cli)
  484. {
  485. std::string cacheCommand = *cli->begin();
  486. if(const char* knownTarget =
  487. this->GetCacheManager()->GetCacheValue(cacheCommand.c_str()))
  488. {
  489. ti->second.AddUtility(knownTarget);
  490. }
  491. }
  492. }
  493. }
  494. //----------------------------------------------------------------------------
  495. void
  496. cmMakefile::AddCustomCommandToOutput(const std::vector<std::string>& outputs,
  497. const std::vector<std::string>& depends,
  498. const char* main_dependency,
  499. const cmCustomCommandLines& commandLines,
  500. const char* comment,
  501. const char* workingDir,
  502. bool replace)
  503. {
  504. // Make sure there is at least one output.
  505. if(outputs.empty())
  506. {
  507. cmSystemTools::Error("Attempt to add a custom rule with no output!");
  508. return;
  509. }
  510. // Choose a source file on which to store the custom command.
  511. cmSourceFile* file = 0;
  512. if(main_dependency && main_dependency[0])
  513. {
  514. // The main dependency was specified. Use it unless a different
  515. // custom command already used it.
  516. file = this->GetSource(main_dependency);
  517. if(file && file->GetCustomCommand() && !replace)
  518. {
  519. // The main dependency already has a custom command.
  520. if(commandLines == file->GetCustomCommand()->GetCommandLines())
  521. {
  522. // The existing custom command is identical. Silently ignore
  523. // the duplicate.
  524. return;
  525. }
  526. else
  527. {
  528. // The existing custom command is different. We need to
  529. // generate a rule file for this new command.
  530. file = 0;
  531. }
  532. }
  533. else
  534. {
  535. // The main dependency does not have a custom command or we are
  536. // allowed to replace it. Use it to store the command.
  537. file = this->GetOrCreateSource(main_dependency);
  538. }
  539. }
  540. // Generate a rule file if the main dependency is not available.
  541. if(!file)
  542. {
  543. // Construct a rule file associated with the first output produced.
  544. std::string outName = outputs[0];
  545. outName += ".rule";
  546. // Check if the rule file already exists.
  547. file = this->GetSource(outName.c_str());
  548. if(file && file->GetCustomCommand() && !replace)
  549. {
  550. // The rule file already exists.
  551. if(commandLines != file->GetCustomCommand()->GetCommandLines())
  552. {
  553. cmSystemTools::Error("Attempt to add a custom rule to output \"",
  554. outName.c_str(),
  555. "\" which already has a custom rule.");
  556. }
  557. return;
  558. }
  559. // Create a cmSourceFile for the rule file.
  560. file = this->GetOrCreateSource(outName.c_str(), true);
  561. }
  562. // Always create the output sources and mark them generated.
  563. for(std::vector<std::string>::const_iterator o = outputs.begin();
  564. o != outputs.end(); ++o)
  565. {
  566. if(cmSourceFile* out = this->GetOrCreateSource(o->c_str(), true))
  567. {
  568. out->SetProperty("GENERATED", "1");
  569. }
  570. }
  571. // Construct a complete list of dependencies.
  572. std::vector<std::string> depends2(depends);
  573. if(main_dependency && main_dependency[0])
  574. {
  575. depends2.push_back(main_dependency);
  576. }
  577. // Attach the custom command to the file.
  578. if(file)
  579. {
  580. cmCustomCommand* cc =
  581. new cmCustomCommand(outputs, depends2, commandLines,
  582. comment, workingDir);
  583. file->SetCustomCommand(cc);
  584. }
  585. }
  586. //----------------------------------------------------------------------------
  587. void
  588. cmMakefile::AddCustomCommandToOutput(const char* output,
  589. const std::vector<std::string>& depends,
  590. const char* main_dependency,
  591. const cmCustomCommandLines& commandLines,
  592. const char* comment,
  593. const char* workingDir,
  594. bool replace)
  595. {
  596. std::vector<std::string> outputs;
  597. outputs.push_back(output);
  598. this->AddCustomCommandToOutput(outputs, depends, main_dependency,
  599. commandLines, comment, workingDir,
  600. replace);
  601. }
  602. //----------------------------------------------------------------------------
  603. void
  604. cmMakefile::AddCustomCommandOldStyle(const char* target,
  605. const std::vector<std::string>& outputs,
  606. const std::vector<std::string>& depends,
  607. const char* source,
  608. const cmCustomCommandLines& commandLines,
  609. const char* comment)
  610. {
  611. // Translate the old-style signature to one of the new-style
  612. // signatures.
  613. if(strcmp(source, target) == 0)
  614. {
  615. // In the old-style signature if the source and target were the
  616. // same then it added a post-build rule to the target. Preserve
  617. // this behavior.
  618. this->AddCustomCommandToTarget(target, depends, commandLines,
  619. cmTarget::POST_BUILD, comment, 0);
  620. return;
  621. }
  622. // Each output must get its own copy of this rule.
  623. cmsys::RegularExpression sourceFiles("\\.(C|M|c|c\\+\\+|cc|cpp|cxx|m|mm|"
  624. "rc|def|r|odl|idl|hpj|bat|h|h\\+\\+|"
  625. "hm|hpp|hxx|in|txx|inl)$");
  626. for(std::vector<std::string>::const_iterator oi = outputs.begin();
  627. oi != outputs.end(); ++oi)
  628. {
  629. // Get the name of this output.
  630. const char* output = oi->c_str();
  631. // Choose whether to use a main dependency.
  632. if(sourceFiles.find(source))
  633. {
  634. // The source looks like a real file. Use it as the main dependency.
  635. this->AddCustomCommandToOutput(output, depends, source,
  636. commandLines, comment, 0);
  637. }
  638. else
  639. {
  640. // The source may not be a real file. Do not use a main dependency.
  641. const char* no_main_dependency = 0;
  642. std::vector<std::string> depends2 = depends;
  643. depends2.push_back(source);
  644. this->AddCustomCommandToOutput(output, depends2, no_main_dependency,
  645. commandLines, comment, 0);
  646. }
  647. // If the rule was added to the source (and not a .rule file),
  648. // then add the source to the target to make sure the rule is
  649. // included.
  650. std::string sname = output;
  651. sname += ".rule";
  652. if(!this->GetSource(sname.c_str()))
  653. {
  654. if (this->Targets.find(target) != this->Targets.end())
  655. {
  656. this->Targets[target].GetSourceLists().push_back(source);
  657. }
  658. else
  659. {
  660. cmSystemTools::Error("Attempt to add a custom rule to a target "
  661. "that does not exist yet for target ", target);
  662. return;
  663. }
  664. }
  665. }
  666. }
  667. //----------------------------------------------------------------------------
  668. void cmMakefile::AddUtilityCommand(const char* utilityName, bool all,
  669. const char* output,
  670. const std::vector<std::string>& depends,
  671. const char* workingDirectory,
  672. const char* command,
  673. const char* arg1,
  674. const char* arg2,
  675. const char* arg3,
  676. const char* arg4)
  677. {
  678. // Construct the command line for the custom command.
  679. cmCustomCommandLine commandLine;
  680. commandLine.push_back(command);
  681. if(arg1)
  682. {
  683. commandLine.push_back(arg1);
  684. }
  685. if(arg2)
  686. {
  687. commandLine.push_back(arg2);
  688. }
  689. if(arg3)
  690. {
  691. commandLine.push_back(arg3);
  692. }
  693. if(arg4)
  694. {
  695. commandLine.push_back(arg4);
  696. }
  697. cmCustomCommandLines commandLines;
  698. commandLines.push_back(commandLine);
  699. // Call the real signature of this method.
  700. this->AddUtilityCommand(utilityName, all, output, workingDirectory,
  701. depends, commandLines);
  702. }
  703. //----------------------------------------------------------------------------
  704. void cmMakefile::AddUtilityCommand(const char* utilityName, bool all,
  705. const char* output,
  706. const char* workingDirectory,
  707. const std::vector<std::string>& depends,
  708. const cmCustomCommandLines& commandLines)
  709. {
  710. // Create a target instance for this utility.
  711. cmTarget target;
  712. target.SetType(cmTarget::UTILITY, utilityName);
  713. target.SetInAll(all);
  714. target.SetMakefile(this);
  715. // Store the custom command in the target.
  716. std::vector<std::string> outputs;
  717. if(output)
  718. {
  719. outputs.push_back(output);
  720. }
  721. cmCustomCommand cc(outputs, depends, commandLines, 0, workingDirectory);
  722. target.GetPostBuildCommands().push_back(cc);
  723. // Add the target to the set of targets.
  724. cmTargets::iterator it =
  725. this->Targets.insert(cmTargets::value_type(utilityName,target)).first;
  726. this->LocalGenerator->GetGlobalGenerator()->AddTarget(*it);
  727. }
  728. void cmMakefile::AddDefineFlag(const char* flag)
  729. {
  730. this->DefineFlags += " ";
  731. this->DefineFlags += flag;
  732. }
  733. void cmMakefile::RemoveDefineFlag(const char* flag)
  734. {
  735. cmSystemTools::ReplaceString(this->DefineFlags, flag, " ");
  736. }
  737. void cmMakefile::AddLinkLibrary(const char* lib,
  738. cmTarget::LinkLibraryType llt)
  739. {
  740. this->LinkLibraries.push_back(
  741. std::pair<std::string, cmTarget::LinkLibraryType>(lib,llt));
  742. }
  743. void cmMakefile::AddLinkLibraryForTarget(const char *target,
  744. const char* lib,
  745. cmTarget::LinkLibraryType llt)
  746. {
  747. cmTargets::iterator i = this->Targets.find(target);
  748. if ( i != this->Targets.end())
  749. {
  750. cmTarget* tgt =
  751. this->GetCMakeInstance()->GetGlobalGenerator()->FindTarget(0, lib);
  752. if(tgt)
  753. {
  754. // if it is not a static or shared library then you can not link to it
  755. if(!((tgt->GetType() == cmTarget::STATIC_LIBRARY) ||
  756. (tgt->GetType() == cmTarget::SHARED_LIBRARY)))
  757. {
  758. cmOStringStream e;
  759. e << "Attempt to add link library " << lib
  760. << " which is not a library target to target "
  761. << tgt->GetType() << " " <<
  762. target << "\n";
  763. cmSystemTools::Error(e.str().c_str());
  764. }
  765. }
  766. i->second.AddLinkLibrary( *this, target, lib, llt );
  767. }
  768. else
  769. {
  770. cmOStringStream e;
  771. e << "Attempt to add link library \""
  772. << lib << "\" to target \""
  773. << target << "\" which is not built by this project.";
  774. cmSystemTools::Error(e.str().c_str());
  775. }
  776. }
  777. void cmMakefile::AddLinkDirectoryForTarget(const char *target,
  778. const char* d)
  779. {
  780. cmTargets::iterator i = this->Targets.find(target);
  781. if ( i != this->Targets.end())
  782. {
  783. i->second.AddLinkDirectory( d );
  784. }
  785. else
  786. {
  787. cmSystemTools::Error
  788. ("Attempt to add link directories to non-existant target: ",
  789. target, " for directory ", d);
  790. }
  791. }
  792. void cmMakefile::AddLinkLibrary(const char* lib)
  793. {
  794. this->AddLinkLibrary(lib,cmTarget::GENERAL);
  795. }
  796. void cmMakefile::AddLinkDirectory(const char* dir)
  797. {
  798. // Don't add a link directory that is already present. Yes, this
  799. // linear search results in n^2 behavior, but n won't be getting
  800. // much bigger than 20. We cannot use a set because of order
  801. // dependency of the link search path.
  802. // remove trailing slashes
  803. if(dir && dir[strlen(dir)-1] == '/')
  804. {
  805. std::string newdir = dir;
  806. newdir = newdir.substr(0, newdir.size()-1);
  807. if(std::find(this->LinkDirectories.begin(),
  808. this->LinkDirectories.end(),
  809. newdir.c_str()) == this->LinkDirectories.end())
  810. {
  811. this->LinkDirectories.push_back(newdir);
  812. }
  813. }
  814. else
  815. {
  816. if(std::find(this->LinkDirectories.begin(),
  817. this->LinkDirectories.end(), dir)
  818. == this->LinkDirectories.end())
  819. {
  820. this->LinkDirectories.push_back(dir);
  821. }
  822. }
  823. }
  824. void cmMakefile::InitializeFromParent()
  825. {
  826. cmMakefile *parent = this->LocalGenerator->GetParent()->GetMakefile();
  827. // copy the definitions
  828. this->Definitions = parent->Definitions;
  829. // copy include paths
  830. this->IncludeDirectories = parent->IncludeDirectories;
  831. // define flags
  832. this->DefineFlags = parent->DefineFlags;
  833. // link libraries
  834. this->LinkLibraries = parent->LinkLibraries;
  835. // link directories
  836. this->LinkDirectories = parent->LinkDirectories;
  837. // the initial project name
  838. this->ProjectName = parent->ProjectName;
  839. // Copy include regular expressions.
  840. this->IncludeFileRegularExpression = parent->IncludeFileRegularExpression;
  841. this->ComplainFileRegularExpression = parent->ComplainFileRegularExpression;
  842. }
  843. void cmMakefile::ConfigureSubDirectory(cmLocalGenerator *lg2)
  844. {
  845. // copy our variables from the child makefile
  846. lg2->GetMakefile()->InitializeFromParent();
  847. lg2->GetMakefile()->MakeStartDirectoriesCurrent();
  848. // finally configure the subdir
  849. lg2->Configure();
  850. }
  851. void cmMakefile::AddSubDirectory(const char* sub,
  852. bool topLevel, bool preorder)
  853. {
  854. // the source path must be made full if it isn't already
  855. std::string srcPath = sub;
  856. if (!cmSystemTools::FileIsFullPath(srcPath.c_str()))
  857. {
  858. srcPath = this->GetCurrentDirectory();
  859. srcPath += "/";
  860. srcPath += sub;
  861. }
  862. // binary path must be made full if it isn't already
  863. std::string binPath = sub;
  864. if (!cmSystemTools::FileIsFullPath(binPath.c_str()))
  865. {
  866. binPath = this->GetCurrentOutputDirectory();
  867. binPath += "/";
  868. binPath += sub;
  869. }
  870. this->AddSubDirectory(srcPath.c_str(), binPath.c_str(),
  871. topLevel, preorder, false);
  872. }
  873. void cmMakefile::AddSubDirectory(const char* srcPath, const char *binPath,
  874. bool topLevel, bool preorder,
  875. bool immediate)
  876. {
  877. std::vector<cmLocalGenerator *>& children =
  878. this->LocalGenerator->GetChildren();
  879. // has this directory already been added? If so error
  880. unsigned int i;
  881. for (i = 0; i < children.size(); ++i)
  882. {
  883. if (srcPath == children[i]->GetMakefile()->GetStartDirectory())
  884. {
  885. cmSystemTools::Error
  886. ("Attempt to add subdirectory multiple times for directory.\n",
  887. srcPath);
  888. return;
  889. }
  890. }
  891. // create a new local generator and set its parent
  892. cmLocalGenerator *lg2 =
  893. this->LocalGenerator->GetGlobalGenerator()->CreateLocalGenerator();
  894. lg2->SetParent(this->LocalGenerator);
  895. this->LocalGenerator->GetGlobalGenerator()->AddLocalGenerator(lg2);
  896. // set the subdirs start dirs
  897. lg2->GetMakefile()->SetStartDirectory(srcPath);
  898. lg2->GetMakefile()->SetStartOutputDirectory(binPath);
  899. lg2->SetExcludeAll(!topLevel);
  900. lg2->GetMakefile()->SetPreOrder(preorder);
  901. if (immediate)
  902. {
  903. this->ConfigureSubDirectory(lg2);
  904. }
  905. }
  906. void cmMakefile::AddIncludeDirectory(const char* inc, bool before)
  907. {
  908. // Don't add an include directory that is already present. Yes,
  909. // this linear search results in n^2 behavior, but n won't be
  910. // getting much bigger than 20. We cannot use a set because of
  911. // order dependency of the include path.
  912. std::vector<std::string>::iterator i =
  913. std::find(this->IncludeDirectories.begin(),
  914. this->IncludeDirectories.end(), inc);
  915. if(i == this->IncludeDirectories.end())
  916. {
  917. if (before)
  918. {
  919. // WARNING: this *is* expensive (linear time) since it's a vector
  920. this->IncludeDirectories.insert(this->IncludeDirectories.begin(), inc);
  921. }
  922. else
  923. {
  924. this->IncludeDirectories.push_back(inc);
  925. }
  926. }
  927. else
  928. {
  929. if(before)
  930. {
  931. // if this before and already in the path then remove it
  932. this->IncludeDirectories.erase(i);
  933. // WARNING: this *is* expensive (linear time) since it's a vector
  934. this->IncludeDirectories.insert(this->IncludeDirectories.begin(), inc);
  935. }
  936. }
  937. }
  938. void cmMakefile::AddDefinition(const char* name, const char* value)
  939. {
  940. if (!value )
  941. {
  942. return;
  943. }
  944. this->TemporaryDefinitionKey = name;
  945. this->Definitions[this->TemporaryDefinitionKey] = value;
  946. #ifdef CMAKE_BUILD_WITH_CMAKE
  947. cmVariableWatch* vv = this->GetVariableWatch();
  948. if ( vv )
  949. {
  950. vv->VariableAccessed(this->TemporaryDefinitionKey,
  951. cmVariableWatch::VARIABLE_MODIFIED_ACCESS);
  952. }
  953. #endif
  954. }
  955. void cmMakefile::AddCacheDefinition(const char* name, const char* value,
  956. const char* doc,
  957. cmCacheManager::CacheEntryType type)
  958. {
  959. const char* val = value;
  960. cmCacheManager::CacheIterator it =
  961. this->GetCacheManager()->GetCacheIterator(name);
  962. if(!it.IsAtEnd() && (it.GetType() == cmCacheManager::UNINITIALIZED) &&
  963. it.Initialized())
  964. {
  965. val = it.GetValue();
  966. if ( type == cmCacheManager::PATH || type == cmCacheManager::FILEPATH )
  967. {
  968. std::vector<std::string>::size_type cc;
  969. std::vector<std::string> files;
  970. std::string nvalue = "";
  971. cmSystemTools::ExpandListArgument(val, files);
  972. for ( cc = 0; cc < files.size(); cc ++ )
  973. {
  974. files[cc] = cmSystemTools::CollapseFullPath(files[cc].c_str());
  975. if ( cc > 0 )
  976. {
  977. nvalue += ";";
  978. }
  979. nvalue += files[cc];
  980. }
  981. this->GetCacheManager()->AddCacheEntry(name, nvalue.c_str(), doc, type);
  982. val = it.GetValue();
  983. }
  984. }
  985. this->GetCacheManager()->AddCacheEntry(name, val, doc, type);
  986. this->AddDefinition(name, val);
  987. }
  988. void cmMakefile::AddDefinition(const char* name, bool value)
  989. {
  990. if(value)
  991. {
  992. this->Definitions.erase( DefinitionMap::key_type(name));
  993. this->Definitions.insert(DefinitionMap::value_type(name, "ON"));
  994. }
  995. else
  996. {
  997. this->Definitions.erase( DefinitionMap::key_type(name));
  998. this->Definitions.insert(DefinitionMap::value_type(name, "OFF"));
  999. }
  1000. #ifdef CMAKE_BUILD_WITH_CMAKE
  1001. cmVariableWatch* vv = this->GetVariableWatch();
  1002. if ( vv )
  1003. {
  1004. vv->VariableAccessed(name, cmVariableWatch::VARIABLE_MODIFIED_ACCESS);
  1005. }
  1006. #endif
  1007. }
  1008. void cmMakefile::AddCacheDefinition(const char* name,
  1009. bool value,
  1010. const char* doc)
  1011. {
  1012. bool val = value;
  1013. cmCacheManager::CacheIterator it =
  1014. this->GetCacheManager()->GetCacheIterator(name);
  1015. if(!it.IsAtEnd() && (it.GetType() == cmCacheManager::UNINITIALIZED) &&
  1016. it.Initialized())
  1017. {
  1018. val = it.GetValueAsBool();
  1019. }
  1020. this->GetCacheManager()->AddCacheEntry(name, val, doc);
  1021. this->AddDefinition(name, val);
  1022. }
  1023. void cmMakefile::RemoveDefinition(const char* name)
  1024. {
  1025. this->Definitions.erase(DefinitionMap::key_type(name));
  1026. #ifdef CMAKE_BUILD_WITH_CMAKE
  1027. cmVariableWatch* vv = this->GetVariableWatch();
  1028. if ( vv )
  1029. {
  1030. vv->VariableAccessed(name, cmVariableWatch::VARIABLE_REMOVED_ACCESS);
  1031. }
  1032. #endif
  1033. }
  1034. void cmMakefile::SetProjectName(const char* p)
  1035. {
  1036. this->ProjectName = p;
  1037. }
  1038. void cmMakefile::AddGlobalLinkInformation(const char* name, cmTarget& target)
  1039. {
  1040. // for these targets do not add anything
  1041. switch(target.GetType())
  1042. {
  1043. case cmTarget::UTILITY:
  1044. case cmTarget::GLOBAL_TARGET:
  1045. case cmTarget::INSTALL_FILES:
  1046. case cmTarget::INSTALL_PROGRAMS:
  1047. return;
  1048. default:;
  1049. }
  1050. std::vector<std::string>::iterator j;
  1051. for(j = this->LinkDirectories.begin();
  1052. j != this->LinkDirectories.end(); ++j)
  1053. {
  1054. target.AddLinkDirectory(j->c_str());
  1055. }
  1056. target.MergeLinkLibraries( *this, name, this->LinkLibraries );
  1057. }
  1058. void cmMakefile::AddLibrary(const char* lname, int shared,
  1059. const std::vector<std::string> &srcs)
  1060. {
  1061. cmTarget target;
  1062. switch (shared)
  1063. {
  1064. case 0:
  1065. target.SetType(cmTarget::STATIC_LIBRARY, lname);
  1066. break;
  1067. case 1:
  1068. target.SetType(cmTarget::SHARED_LIBRARY, lname);
  1069. break;
  1070. case 2:
  1071. target.SetType(cmTarget::MODULE_LIBRARY, lname);
  1072. break;
  1073. default:
  1074. target.SetType(cmTarget::STATIC_LIBRARY, lname);
  1075. }
  1076. // Clear its dependencies. Otherwise, dependencies might persist
  1077. // over changes in CMakeLists.txt, making the information stale and
  1078. // hence useless.
  1079. target.ClearDependencyInformation( *this, lname );
  1080. target.SetInAll(true);
  1081. target.GetSourceLists() = srcs;
  1082. target.SetMakefile(this);
  1083. this->AddGlobalLinkInformation(lname, target);
  1084. cmTargets::iterator it =
  1085. this->Targets.insert(cmTargets::value_type(lname,target)).first;
  1086. this->LocalGenerator->GetGlobalGenerator()->AddTarget(*it);
  1087. }
  1088. cmTarget* cmMakefile::AddExecutable(const char *exeName,
  1089. const std::vector<std::string> &srcs)
  1090. {
  1091. cmTarget target;
  1092. target.SetType(cmTarget::EXECUTABLE, exeName);
  1093. target.SetInAll(true);
  1094. target.GetSourceLists() = srcs;
  1095. target.SetMakefile(this);
  1096. this->AddGlobalLinkInformation(exeName, target);
  1097. cmTargets::iterator it =
  1098. this->Targets.insert(cmTargets::value_type(exeName,target)).first;
  1099. this->LocalGenerator->GetGlobalGenerator()->AddTarget(*it);
  1100. return &it->second;
  1101. }
  1102. cmSourceFile *cmMakefile::GetSourceFileWithOutput(const char *cname)
  1103. {
  1104. std::string name = cname;
  1105. std::string out;
  1106. // look through all the source files that have custom commands
  1107. // and see if the custom command has the passed source file as an output
  1108. // keep in mind the possible .rule extension that may be tacked on
  1109. for(std::vector<cmSourceFile*>::const_iterator i =
  1110. this->SourceFiles.begin(); i != this->SourceFiles.end(); ++i)
  1111. {
  1112. // does this source file have a custom command?
  1113. if ((*i)->GetCustomCommand())
  1114. {
  1115. // is the output of the custom command match the source files name
  1116. const std::vector<std::string>& outputs =
  1117. (*i)->GetCustomCommand()->GetOutputs();
  1118. for(std::vector<std::string>::const_iterator o = outputs.begin();
  1119. o != outputs.end(); ++o)
  1120. {
  1121. out = *o;
  1122. std::string::size_type pos = out.rfind(name);
  1123. // If the output matches exactly
  1124. if (pos != out.npos &&
  1125. pos == out.size() - name.size() &&
  1126. (pos ==0 || out[pos-1] == '/'))
  1127. {
  1128. return *i;
  1129. }
  1130. }
  1131. }
  1132. }
  1133. // otherwise return NULL
  1134. return 0;
  1135. }
  1136. #if defined(CMAKE_BUILD_WITH_CMAKE)
  1137. cmSourceGroup* cmMakefile::GetSourceGroup(const char* name)
  1138. {
  1139. // First see if the group exists. If so, replace its regular expression.
  1140. for(std::vector<cmSourceGroup>::iterator sg = this->SourceGroups.begin();
  1141. sg != this->SourceGroups.end(); ++sg)
  1142. {
  1143. std::string sgName = sg->GetName();
  1144. if(sgName == name)
  1145. {
  1146. return &(*sg);
  1147. }
  1148. else
  1149. {
  1150. cmSourceGroup *target = sg->lookupChild(name);
  1151. if(target)
  1152. {
  1153. return target;
  1154. }
  1155. }
  1156. }
  1157. return 0;
  1158. }
  1159. void cmMakefile::AddSourceGroup(const char* name,
  1160. const char* regex,
  1161. const char *parent)
  1162. {
  1163. // First see if the group exists. If so, replace its regular expression.
  1164. for(unsigned int i=0;i<this->SourceGroups.size();++i)
  1165. {
  1166. cmSourceGroup *sg = &this->SourceGroups[i];
  1167. std::string sgName = sg->GetName();
  1168. if(!parent)
  1169. {
  1170. if(sgName == name)
  1171. {
  1172. if ( regex )
  1173. {
  1174. // We only want to set the regular expression. If there are already
  1175. // source files in the group, we don't want to remove them.
  1176. sg->SetGroupRegex(regex);
  1177. }
  1178. return;
  1179. }
  1180. }
  1181. else
  1182. {
  1183. if(sgName == parent)
  1184. {
  1185. cmSourceGroup *localtarget = sg->lookupChild(name);
  1186. if(localtarget)
  1187. {
  1188. if ( regex )
  1189. {
  1190. // We only want to set the regular expression. If there are
  1191. // already source files in the group, we don't want to remove
  1192. // them.
  1193. localtarget->SetGroupRegex(regex);
  1194. }
  1195. }
  1196. else
  1197. {
  1198. sg->AddChild(cmSourceGroup(name, regex));
  1199. }
  1200. return;
  1201. }
  1202. else
  1203. {
  1204. cmSourceGroup *localtarget = sg->lookupChild(parent);
  1205. if(localtarget)
  1206. {
  1207. cmSourceGroup *addtarget = localtarget->lookupChild(name);
  1208. if(addtarget)
  1209. {
  1210. if ( regex )
  1211. {
  1212. // We only want to set the regular expression. If there are
  1213. // already source files in the group, we don't want to
  1214. // remove them.
  1215. addtarget->SetGroupRegex(regex);
  1216. }
  1217. }
  1218. else
  1219. {
  1220. localtarget->AddChild(cmSourceGroup(name, regex));
  1221. }
  1222. return;
  1223. }
  1224. }
  1225. }
  1226. }
  1227. // The group doesn't exist. Add it.
  1228. this->SourceGroups.push_back(cmSourceGroup(name, regex));
  1229. }
  1230. #endif
  1231. void cmMakefile::AddExtraDirectory(const char* dir)
  1232. {
  1233. this->AuxSourceDirectories.push_back(dir);
  1234. }
  1235. // expance CMAKE_BINARY_DIR and CMAKE_SOURCE_DIR in the
  1236. // include and library directories.
  1237. void cmMakefile::ExpandVariables()
  1238. {
  1239. // Now expand variables in the include and link strings
  1240. for(std::vector<std::string>::iterator d = this->IncludeDirectories.begin();
  1241. d != this->IncludeDirectories.end(); ++d)
  1242. {
  1243. this->ExpandVariablesInString(*d, true, true);
  1244. }
  1245. for(std::vector<std::string>::iterator d = this->LinkDirectories.begin();
  1246. d != this->LinkDirectories.end(); ++d)
  1247. {
  1248. this->ExpandVariablesInString(*d, true, true);
  1249. }
  1250. for(cmTarget::LinkLibraryVectorType::iterator l =
  1251. this->LinkLibraries.begin();
  1252. l != this->LinkLibraries.end(); ++l)
  1253. {
  1254. this->ExpandVariablesInString(l->first, true, true);
  1255. }
  1256. }
  1257. bool cmMakefile::IsOn(const char* name) const
  1258. {
  1259. const char* value = this->GetDefinition(name);
  1260. return cmSystemTools::IsOn(value);
  1261. }
  1262. bool cmMakefile::IsSet(const char* name) const
  1263. {
  1264. const char* value = this->GetDefinition(name);
  1265. if ( !value )
  1266. {
  1267. return false;
  1268. }
  1269. if ( ! *value )
  1270. {
  1271. return false;
  1272. }
  1273. if ( cmSystemTools::IsNOTFOUND(value) )
  1274. {
  1275. return false;
  1276. }
  1277. return true;
  1278. }
  1279. bool cmMakefile::CanIWriteThisFile(const char* fileName)
  1280. {
  1281. if ( !this->IsOn("CMAKE_DISABLE_SOURCE_CHANGES") )
  1282. {
  1283. return true;
  1284. }
  1285. // If we are doing an in-source build, than the test will always fail
  1286. if ( cmSystemTools::SameFile(this->GetHomeDirectory(),
  1287. this->GetHomeOutputDirectory()) )
  1288. {
  1289. if ( this->IsOn("CMAKE_DISABLE_IN_SOURCE_BUILD") )
  1290. {
  1291. return false;
  1292. }
  1293. return true;
  1294. }
  1295. // Check if this is subdirectory of the source tree but not a
  1296. // subdirectory of a build tree
  1297. if ( cmSystemTools::IsSubDirectory(fileName,
  1298. this->GetHomeDirectory()) &&
  1299. !cmSystemTools::IsSubDirectory(fileName,
  1300. this->GetHomeOutputDirectory()) )
  1301. {
  1302. return false;
  1303. }
  1304. return true;
  1305. }
  1306. const char* cmMakefile::GetRequiredDefinition(const char* name) const
  1307. {
  1308. const char* ret = this->GetDefinition(name);
  1309. if(!ret)
  1310. {
  1311. cmSystemTools::Error("Error required internal CMake variable not "
  1312. "set, cmake may be not be built correctly.\n",
  1313. "Missing variable is:\n",
  1314. name);
  1315. return "";
  1316. }
  1317. return ret;
  1318. }
  1319. const char* cmMakefile::GetDefinition(const char* name) const
  1320. {
  1321. const char* def = 0;
  1322. DefinitionMap::const_iterator pos = this->Definitions.find(name);
  1323. if(pos != this->Definitions.end())
  1324. {
  1325. def = (*pos).second.c_str();
  1326. }
  1327. else
  1328. {
  1329. def = this->GetCacheManager()->GetCacheValue(name);
  1330. }
  1331. #ifdef CMAKE_BUILD_WITH_CMAKE
  1332. cmVariableWatch* vv = this->GetVariableWatch();
  1333. if ( vv )
  1334. {
  1335. if ( def )
  1336. {
  1337. vv->VariableAccessed(name, cmVariableWatch::VARIABLE_READ_ACCESS);
  1338. }
  1339. else
  1340. {
  1341. // are unknown access allowed
  1342. DefinitionMap::const_iterator pos2 =
  1343. this->Definitions.find("CMAKE_ALLOW_UNKNOWN_VARIABLE_READ_ACCESS");
  1344. if (pos2 != this->Definitions.end() &&
  1345. cmSystemTools::IsOn((*pos2).second.c_str()))
  1346. {
  1347. vv->VariableAccessed
  1348. (name, cmVariableWatch::ALLOWED_UNKNOWN_VARIABLE_READ_ACCESS);
  1349. }
  1350. else
  1351. {
  1352. vv->VariableAccessed(name, cmVariableWatch::
  1353. UNKNOWN_VARIABLE_READ_ACCESS);
  1354. }
  1355. }
  1356. }
  1357. #endif
  1358. return def;
  1359. }
  1360. const char* cmMakefile::GetSafeDefinition(const char* def) const
  1361. {
  1362. const char* ret = this->GetDefinition(def);
  1363. if(!ret)
  1364. {
  1365. return "";
  1366. }
  1367. return ret;
  1368. }
  1369. std::vector<std::string> cmMakefile
  1370. ::GetDefinitions(int cacheonly /* = 0 */) const
  1371. {
  1372. std::map<cmStdString, int> definitions;
  1373. if ( !cacheonly )
  1374. {
  1375. DefinitionMap::const_iterator it;
  1376. for ( it = this->Definitions.begin();
  1377. it != this->Definitions.end(); it ++ )
  1378. {
  1379. definitions[it->first] = 1;
  1380. }
  1381. }
  1382. cmCacheManager::CacheIterator cit =
  1383. this->GetCacheManager()->GetCacheIterator();
  1384. for ( cit.Begin(); !cit.IsAtEnd(); cit.Next() )
  1385. {
  1386. definitions[cit.GetName()] = 1;
  1387. }
  1388. std::vector<std::string> res;
  1389. std::map<cmStdString, int>::iterator fit;
  1390. for ( fit = definitions.begin(); fit != definitions.end(); fit ++ )
  1391. {
  1392. res.push_back(fit->first);
  1393. }
  1394. return res;
  1395. }
  1396. const char *cmMakefile::ExpandVariablesInString(std::string& source) const
  1397. {
  1398. return this->ExpandVariablesInString(source, false, false);
  1399. }
  1400. const char *cmMakefile::ExpandVariablesInString(std::string& source,
  1401. bool escapeQuotes,
  1402. bool noEscapes,
  1403. bool atOnly,
  1404. const char* filename,
  1405. long line,
  1406. bool removeEmpty) const
  1407. {
  1408. if ( source.empty() || source.find_first_of("$@\\") == source.npos)
  1409. {
  1410. return source.c_str();
  1411. }
  1412. // This method replaces ${VAR} and @VAR@ where VAR is looked up
  1413. // with GetDefinition(), if not found in the map, nothing is expanded.
  1414. // It also supports the $ENV{VAR} syntax where VAR is looked up in
  1415. // the current environment variables.
  1416. bool notParsed = true;
  1417. if ( !atOnly )
  1418. {
  1419. cmCommandArgumentParserHelper parser;
  1420. parser.SetMakefile(this);
  1421. parser.SetLineFile(line, filename);
  1422. parser.SetEscapeQuotes(escapeQuotes);
  1423. parser.SetNoEscapeMode(noEscapes);
  1424. int res = parser.ParseString(source.c_str(), 0);
  1425. if ( res )
  1426. {
  1427. source = parser.GetResult();
  1428. notParsed = false;
  1429. }
  1430. else
  1431. {
  1432. cmOStringStream error;
  1433. error << "Syntax error in cmake code at\n"
  1434. << (filename?filename:"(no filename given)")
  1435. << ":" << line << ":\n"
  1436. << parser.GetError() << ", when parsing string \""
  1437. << source.c_str() << "\"";
  1438. const char* versionValue
  1439. = this->GetDefinition("CMAKE_BACKWARDS_COMPATIBILITY");
  1440. int major = 0;
  1441. int minor = 0;
  1442. if ( versionValue )
  1443. {
  1444. sscanf(versionValue, "%d.%d", &major, &minor);
  1445. }
  1446. if ( major < 2 || major == 2 && minor < 1 )
  1447. {
  1448. cmSystemTools::Error(error.str().c_str());
  1449. cmSystemTools::SetFatalErrorOccured();
  1450. return source.c_str();
  1451. }
  1452. else
  1453. {
  1454. cmSystemTools::Message(error.str().c_str());
  1455. }
  1456. }
  1457. }
  1458. if ( notParsed )
  1459. {
  1460. // start by look for $ or @ in the string
  1461. std::string::size_type markerPos;
  1462. if(atOnly)
  1463. {
  1464. markerPos = source.find_first_of("@");
  1465. }
  1466. else
  1467. {
  1468. markerPos = source.find_first_of("$@");
  1469. }
  1470. // if not found, or found as the last character, then leave quickly as
  1471. // nothing needs to be expanded
  1472. if((markerPos == std::string::npos) || (markerPos >= source.size()-1))
  1473. {
  1474. return source.c_str();
  1475. }
  1476. // current position
  1477. std::string::size_type currentPos =0; // start at 0
  1478. std::string result; // string with replacements
  1479. // go until the the end of the string
  1480. while((markerPos != std::string::npos) && (markerPos < source.size()-1))
  1481. {
  1482. // grab string from currentPos to the start of the variable
  1483. // and add it to the result
  1484. result += source.substr(currentPos, markerPos - currentPos);
  1485. char endVariableMarker; // what is the end of the variable @ or }
  1486. int markerStartSize = 1; // size of the start marker 1 or 2 or 5
  1487. if(!atOnly && source[markerPos] == '$')
  1488. {
  1489. // ${var} case
  1490. if(source[markerPos+1] == '{')
  1491. {
  1492. endVariableMarker = '}';
  1493. markerStartSize = 2;
  1494. }
  1495. // $ENV{var} case
  1496. else if(markerPos+4 < source.size() &&
  1497. source[markerPos+4] == '{' &&
  1498. !source.substr(markerPos+1, 3).compare("ENV"))
  1499. {
  1500. endVariableMarker = '}';
  1501. markerStartSize = 5;
  1502. }
  1503. else
  1504. {
  1505. // bogus $ with no { so add $ to result and move on
  1506. result += '$'; // add bogus $ back into string
  1507. currentPos = markerPos+1; // move on
  1508. // set end var to space so we can tell bogus
  1509. endVariableMarker = ' ';
  1510. }
  1511. }
  1512. else
  1513. {
  1514. // @VAR case
  1515. endVariableMarker = '@';
  1516. }
  1517. // if it was a valid variable (started with @ or ${ or $ENV{ )
  1518. if(endVariableMarker != ' ')
  1519. {
  1520. markerPos += markerStartSize; // move past marker
  1521. // find the end variable marker starting at the markerPos
  1522. std::string::size_type endVariablePos =
  1523. source.find(endVariableMarker, markerPos);
  1524. if(endVariablePos == std::string::npos)
  1525. {
  1526. // no end marker found so add the bogus start
  1527. if(endVariableMarker == '@')
  1528. {
  1529. result += '@';
  1530. }
  1531. else
  1532. {
  1533. result += (markerStartSize == 5 ? "$ENV{" : "${");
  1534. }
  1535. currentPos = markerPos;
  1536. }
  1537. else
  1538. {
  1539. // good variable remove it
  1540. std::string var =
  1541. source.substr(markerPos, endVariablePos - markerPos);
  1542. bool found = false;
  1543. if (markerStartSize == 5) // $ENV{
  1544. {
  1545. char *ptr = getenv(var.c_str());
  1546. if (ptr)
  1547. {
  1548. if (escapeQuotes)
  1549. {
  1550. result += cmSystemTools::EscapeQuotes(ptr);
  1551. }
  1552. else
  1553. {
  1554. result += ptr;
  1555. }
  1556. found = true;
  1557. }
  1558. }
  1559. else
  1560. {
  1561. const char* lookup = this->GetDefinition(var.c_str());
  1562. if(lookup)
  1563. {
  1564. if (escapeQuotes)
  1565. {
  1566. result += cmSystemTools::EscapeQuotes(lookup);
  1567. }
  1568. else
  1569. {
  1570. result += lookup;
  1571. }
  1572. found = true;
  1573. }
  1574. else if(filename && (var == "CMAKE_CURRENT_LIST_FILE"))
  1575. {
  1576. result += filename;
  1577. found = true;
  1578. }
  1579. else if(line >= 0 && (var == "CMAKE_CURRENT_LIST_LINE"))
  1580. {
  1581. cmOStringStream ostr;
  1582. ostr << line;
  1583. result += ostr.str();
  1584. found = true;
  1585. }
  1586. }
  1587. // if found add to result, if not, then it gets blanked
  1588. if (!found)
  1589. {
  1590. // if no definition is found then add the var back
  1591. if(!removeEmpty && endVariableMarker == '@')
  1592. {
  1593. result += "@";
  1594. result += var;
  1595. result += "@";
  1596. }
  1597. }
  1598. // lookup var, and replace it
  1599. currentPos = endVariablePos+1;
  1600. }
  1601. }
  1602. if(atOnly)
  1603. {
  1604. markerPos = source.find_first_of("@", currentPos);
  1605. }
  1606. else
  1607. {
  1608. markerPos = source.find_first_of("$@", currentPos);
  1609. }
  1610. }
  1611. result += source.substr(currentPos); // pick up the rest of the string
  1612. source = result;
  1613. }
  1614. return source.c_str();
  1615. }
  1616. void cmMakefile::RemoveVariablesInString(std::string& source,
  1617. bool atOnly) const
  1618. {
  1619. if(!atOnly)
  1620. {
  1621. cmsys::RegularExpression var("(\\${[A-Za-z_0-9]*})");
  1622. while (var.find(source))
  1623. {
  1624. source.erase(var.start(),var.end() - var.start());
  1625. }
  1626. }
  1627. if(!atOnly)
  1628. {
  1629. cmsys::RegularExpression varb("(\\$ENV{[A-Za-z_0-9]*})");
  1630. while (varb.find(source))
  1631. {
  1632. source.erase(varb.start(),varb.end() - varb.start());
  1633. }
  1634. }
  1635. cmsys::RegularExpression var2("(@[A-Za-z_0-9]*@)");
  1636. while (var2.find(source))
  1637. {
  1638. source.erase(var2.start(),var2.end() - var2.start());
  1639. }
  1640. }
  1641. /**
  1642. * Add the default definitions to the makefile. These values must not
  1643. * be dependent on anything that isn't known when this cmMakefile instance
  1644. * is constructed.
  1645. */
  1646. void cmMakefile::AddDefaultDefinitions()
  1647. {
  1648. #if defined(_WIN32) || defined(__CYGWIN__)
  1649. this->AddDefinition("WIN32", "1");
  1650. #else
  1651. this->AddDefinition("UNIX", "1");
  1652. #endif
  1653. // Cygwin is more like unix so enable the unix commands
  1654. #if defined(__CYGWIN__)
  1655. this->AddDefinition("UNIX", "1");
  1656. this->AddDefinition("CYGWIN", "1");
  1657. #endif
  1658. #if defined(__APPLE__)
  1659. this->AddDefinition("APPLE", "1");
  1660. #endif
  1661. char temp[1024];
  1662. sprintf(temp, "%d", cmMakefile::GetMinorVersion());
  1663. this->AddDefinition("CMAKE_MINOR_VERSION", temp);
  1664. sprintf(temp, "%d", cmMakefile::GetMajorVersion());
  1665. this->AddDefinition("CMAKE_MAJOR_VERSION", temp);
  1666. }
  1667. #if defined(CMAKE_BUILD_WITH_CMAKE)
  1668. /**
  1669. * Find a source group whose regular expression matches the filename
  1670. * part of the given source name. Search backward through the list of
  1671. * source groups, and take the first matching group found. This way
  1672. * non-inherited SOURCE_GROUP commands will have precedence over
  1673. * inherited ones.
  1674. */
  1675. cmSourceGroup&
  1676. cmMakefile::FindSourceGroup(const char* source,
  1677. std::vector<cmSourceGroup> &groups)
  1678. {
  1679. // First search for a group that lists the file explicitly.
  1680. for(std::vector<cmSourceGroup>::reverse_iterator sg = groups.rbegin();
  1681. sg != groups.rend(); ++sg)
  1682. {
  1683. cmSourceGroup *result = sg->MatchChildrenFiles(source);
  1684. if(result)
  1685. {
  1686. return *result;
  1687. }
  1688. }
  1689. // Now search for a group whose regex matches the file.
  1690. for(std::vector<cmSourceGroup>::reverse_iterator sg = groups.rbegin();
  1691. sg != groups.rend(); ++sg)
  1692. {
  1693. cmSourceGroup *result = sg->MatchChildrenRegex(source);
  1694. if(result)
  1695. {
  1696. return *result;
  1697. }
  1698. }
  1699. // Shouldn't get here, but just in case, return the default group.
  1700. return groups.front();
  1701. }
  1702. #endif
  1703. bool cmMakefile::IsFunctionBlocked(const cmListFileFunction& lff)
  1704. {
  1705. // if there are no blockers get out of here
  1706. if (this->FunctionBlockers.begin() == this->FunctionBlockers.end())
  1707. {
  1708. return false;
  1709. }
  1710. // loop over all function blockers to see if any block this command
  1711. // evaluate in reverse, this is critical for balanced IF statements etc
  1712. std::list<cmFunctionBlocker *>::reverse_iterator pos;
  1713. for (pos = this->FunctionBlockers.rbegin();
  1714. pos != this->FunctionBlockers.rend(); ++pos)
  1715. {
  1716. if((*pos)->IsFunctionBlocked(lff, *this))
  1717. {
  1718. return true;
  1719. }
  1720. }
  1721. return false;
  1722. }
  1723. void cmMakefile::ExpandArguments(
  1724. std::vector<cmListFileArgument> const& inArgs,
  1725. std::vector<std::string>& outArgs)
  1726. {
  1727. std::vector<cmListFileArgument>::const_iterator i;
  1728. std::string value;
  1729. outArgs.reserve(inArgs.size());
  1730. for(i = inArgs.begin(); i != inArgs.end(); ++i)
  1731. {
  1732. // Expand the variables in the argument.
  1733. value = i->Value;
  1734. this->ExpandVariablesInString(value, false, false, false,
  1735. i->FilePath, i->Line);
  1736. // If the argument is quoted, it should be one argument.
  1737. // Otherwise, it may be a list of arguments.
  1738. if(i->Quoted)
  1739. {
  1740. outArgs.push_back(value);
  1741. }
  1742. else
  1743. {
  1744. cmSystemTools::ExpandListArgument(value, outArgs);
  1745. }
  1746. }
  1747. }
  1748. void cmMakefile::RemoveFunctionBlocker(const cmListFileFunction& lff)
  1749. {
  1750. // loop over all function blockers to see if any block this command
  1751. std::list<cmFunctionBlocker *>::reverse_iterator pos;
  1752. for (pos = this->FunctionBlockers.rbegin();
  1753. pos != this->FunctionBlockers.rend(); ++pos)
  1754. {
  1755. if ((*pos)->ShouldRemove(lff, *this))
  1756. {
  1757. cmFunctionBlocker* b = *pos;
  1758. this->FunctionBlockers.remove(b);
  1759. delete b;
  1760. break;
  1761. }
  1762. }
  1763. return;
  1764. }
  1765. void cmMakefile::SetHomeDirectory(const char* dir)
  1766. {
  1767. this->cmHomeDirectory = dir;
  1768. cmSystemTools::ConvertToUnixSlashes(this->cmHomeDirectory);
  1769. this->AddDefinition("CMAKE_SOURCE_DIR", this->GetHomeDirectory());
  1770. if ( !this->GetDefinition("CMAKE_CURRENT_SOURCE_DIR") )
  1771. {
  1772. this->AddDefinition("CMAKE_CURRENT_SOURCE_DIR", this->GetHomeDirectory());
  1773. }
  1774. }
  1775. void cmMakefile::SetHomeOutputDirectory(const char* lib)
  1776. {
  1777. this->HomeOutputDirectory = lib;
  1778. cmSystemTools::ConvertToUnixSlashes(this->HomeOutputDirectory);
  1779. this->AddDefinition("CMAKE_BINARY_DIR", this->GetHomeOutputDirectory());
  1780. if ( !this->GetDefinition("CMAKE_CURRENT_BINARY_DIR") )
  1781. {
  1782. this->AddDefinition("CMAKE_CURRENT_BINARY_DIR",
  1783. this->GetHomeOutputDirectory());
  1784. }
  1785. }
  1786. /**
  1787. * Register the given cmData instance with its own name.
  1788. */
  1789. void cmMakefile::RegisterData(cmData* data)
  1790. {
  1791. std::string name = data->GetName();
  1792. DataMapType::const_iterator d = this->DataMap.find(name);
  1793. if((d != this->DataMap.end()) && (d->second != 0) && (d->second != data))
  1794. {
  1795. delete d->second;
  1796. }
  1797. this->DataMap[name] = data;
  1798. }
  1799. /**
  1800. * Register the given cmData instance with the given name. This can be used
  1801. * to register a NULL pointer.
  1802. */
  1803. void cmMakefile::RegisterData(const char* name, cmData* data)
  1804. {
  1805. DataMapType::const_iterator d = this->DataMap.find(name);
  1806. if((d != this->DataMap.end()) && (d->second != 0) && (d->second != data))
  1807. {
  1808. delete d->second;
  1809. }
  1810. this->DataMap[name] = data;
  1811. }
  1812. /**
  1813. * Lookup a cmData instance previously registered with the given name. If
  1814. * the instance cannot be found, return NULL.
  1815. */
  1816. cmData* cmMakefile::LookupData(const char* name) const
  1817. {
  1818. DataMapType::const_iterator d = this->DataMap.find(name);
  1819. if(d != this->DataMap.end())
  1820. {
  1821. return d->second;
  1822. }
  1823. else
  1824. {
  1825. return 0;
  1826. }
  1827. }
  1828. cmSourceFile* cmMakefile::GetSource(const char* sourceName) const
  1829. {
  1830. // if the source is provided with a full path use it, otherwise
  1831. // by default it is in the current source dir
  1832. std::string path = cmSystemTools::GetFilenamePath(sourceName);
  1833. if (path.empty())
  1834. {
  1835. path = this->GetCurrentDirectory();
  1836. }
  1837. std::string sname =
  1838. cmSystemTools::GetFilenameWithoutLastExtension(sourceName);
  1839. // compute the extension
  1840. std::string ext
  1841. = cmSystemTools::GetFilenameLastExtension(sourceName);
  1842. if ( ext.length() && ext[0] == '.' )
  1843. {
  1844. ext = ext.substr(1);
  1845. }
  1846. for(std::vector<cmSourceFile*>::const_iterator i =
  1847. this->SourceFiles.begin();
  1848. i != this->SourceFiles.end(); ++i)
  1849. {
  1850. if ((*i)->GetSourceNameWithoutLastExtension() == sname &&
  1851. cmSystemTools::GetFilenamePath((*i)->GetFullPath()) == path &&
  1852. (ext.size() == 0 || (ext == (*i)->GetSourceExtension())))
  1853. {
  1854. return *i;
  1855. }
  1856. }
  1857. // geeze, if it wasn't found maybe it is listed under the output dir
  1858. if (!cmSystemTools::GetFilenamePath(sourceName).empty())
  1859. {
  1860. return 0;
  1861. }
  1862. path = this->GetCurrentOutputDirectory();
  1863. for(std::vector<cmSourceFile*>::const_iterator i =
  1864. this->SourceFiles.begin();
  1865. i != this->SourceFiles.end(); ++i)
  1866. {
  1867. if ((*i)->GetSourceName() == sname &&
  1868. cmSystemTools::GetFilenamePath((*i)->GetFullPath()) == path &&
  1869. (ext.size() == 0 || (ext == (*i)->GetSourceExtension())))
  1870. {
  1871. return *i;
  1872. }
  1873. }
  1874. return 0;
  1875. }
  1876. cmSourceFile* cmMakefile::GetOrCreateSource(const char* sourceName,
  1877. bool generated)
  1878. {
  1879. // make it a full path first
  1880. std::string src = sourceName;
  1881. bool relative = !cmSystemTools::FileIsFullPath(sourceName);
  1882. std::string srcTreeFile = this->GetCurrentDirectory();
  1883. srcTreeFile += "/";
  1884. srcTreeFile += sourceName;
  1885. if(relative)
  1886. {
  1887. src = srcTreeFile;
  1888. }
  1889. // check to see if it exists
  1890. cmSourceFile* ret = this->GetSource(src.c_str());
  1891. if (ret)
  1892. {
  1893. return ret;
  1894. }
  1895. // OK a source file object doesn't exist for the source
  1896. // maybe we made a bad call on assuming it was in the src tree
  1897. std::string buildTreeFile = this->GetCurrentOutputDirectory();
  1898. buildTreeFile += "/";
  1899. buildTreeFile += sourceName;
  1900. if (relative)
  1901. {
  1902. src = buildTreeFile;
  1903. ret = this->GetSource(src.c_str());
  1904. if (ret)
  1905. {
  1906. return ret;
  1907. }
  1908. // if it has not been marked generated check to see if it exists in the
  1909. // src tree
  1910. if(!generated)
  1911. {
  1912. // see if the file is in the source tree, otherwise assume it
  1913. // is in the binary tree
  1914. if (cmSystemTools::FileExists(srcTreeFile.c_str()) &&
  1915. !cmSystemTools::FileIsDirectory(srcTreeFile.c_str()))
  1916. {
  1917. src = srcTreeFile;
  1918. }
  1919. else
  1920. {
  1921. if ( cmSystemTools::GetFilenameLastExtension
  1922. (srcTreeFile.c_str()).size() == 0)
  1923. {
  1924. if (cmSystemTools::DoesFileExistWithExtensions(
  1925. srcTreeFile.c_str(), this->GetSourceExtensions()))
  1926. {
  1927. src = srcTreeFile;
  1928. }
  1929. else if (cmSystemTools::DoesFileExistWithExtensions(
  1930. srcTreeFile.c_str(), this->GetHeaderExtensions()))
  1931. {
  1932. src = srcTreeFile;
  1933. }
  1934. }
  1935. }
  1936. }
  1937. }
  1938. // a cmSourceFile instance does not exist yet so we must create one
  1939. // go back to looking in the source directory for it
  1940. // we must create one
  1941. cmSourceFile file;
  1942. std::string path = cmSystemTools::GetFilenamePath(src);
  1943. if(generated)
  1944. {
  1945. std::string ext = cmSystemTools::GetFilenameLastExtension(src);
  1946. std::string name_no_ext = cmSystemTools::GetFilenameName(src.c_str());
  1947. name_no_ext = name_no_ext.substr(0, name_no_ext.length()-ext.length());
  1948. if ( ext.length() && ext[0] == '.' )
  1949. {
  1950. ext = ext.substr(1);
  1951. }
  1952. bool headerFile =
  1953. !(std::find( this->HeaderFileExtensions.begin(),
  1954. this->HeaderFileExtensions.end(), ext ) ==
  1955. this->HeaderFileExtensions.end());
  1956. file.SetName(name_no_ext.c_str(), path.c_str(), ext.c_str(), headerFile);
  1957. }
  1958. else
  1959. {
  1960. std::string relPath = cmSystemTools::GetFilenamePath(sourceName);
  1961. if (relative && relPath.size())
  1962. {
  1963. // we need to keep the relative part of the filename
  1964. std::string fullPathLessRel = path;
  1965. std::string::size_type pos = fullPathLessRel.rfind(relPath);
  1966. if (pos == std::string::npos)
  1967. {
  1968. cmSystemTools::Error(
  1969. "CMake failed to properly look up relative cmSourceFile: ",
  1970. sourceName);
  1971. }
  1972. fullPathLessRel.erase(pos-1);
  1973. file.SetName(sourceName, fullPathLessRel.c_str(),
  1974. this->GetSourceExtensions(),
  1975. this->GetHeaderExtensions());
  1976. }
  1977. else
  1978. {
  1979. file.SetName(cmSystemTools::GetFilenameName(src.c_str()).c_str(),
  1980. path.c_str(),
  1981. this->GetSourceExtensions(),
  1982. this->GetHeaderExtensions());
  1983. }
  1984. }
  1985. // add the source file to the makefile
  1986. this->AddSource(file);
  1987. src = file.GetFullPath();
  1988. ret = this->GetSource(src.c_str());
  1989. if (!ret)
  1990. {
  1991. cmSystemTools::Error(
  1992. "CMake failed to properly look up cmSourceFile: ", sourceName);
  1993. }
  1994. return ret;
  1995. }
  1996. cmSourceFile* cmMakefile::AddSource(cmSourceFile const&sf)
  1997. {
  1998. // check to see if it exists
  1999. cmSourceFile* ret = this->GetSource(sf.GetFullPath().c_str());
  2000. if(ret)
  2001. {
  2002. return ret;
  2003. }
  2004. ret = new cmSourceFile(sf);
  2005. this->SourceFiles.push_back(ret);
  2006. return ret;
  2007. }
  2008. void cmMakefile::EnableLanguage(std::vector<std::string> const & lang)
  2009. {
  2010. this->AddDefinition("CMAKE_CFG_INTDIR",
  2011. this->LocalGenerator->GetGlobalGenerator()->GetCMakeCFGInitDirectory());
  2012. this->LocalGenerator->GetGlobalGenerator()->EnableLanguage(lang, this);
  2013. }
  2014. void cmMakefile::ExpandSourceListArguments(
  2015. std::vector<std::string> const& arguments,
  2016. std::vector<std::string>& newargs, unsigned int /* start */)
  2017. {
  2018. // now expand the args
  2019. unsigned int i;
  2020. for(i = 0; i < arguments.size(); ++i)
  2021. {
  2022. // List expansion will have been done already.
  2023. newargs.push_back(arguments[i]);
  2024. }
  2025. }
  2026. int cmMakefile::TryCompile(const char *srcdir, const char *bindir,
  2027. const char *projectName, const char *targetName,
  2028. const std::vector<std::string> *cmakeArgs,
  2029. std::string *output)
  2030. {
  2031. // does the binary directory exist ? If not create it...
  2032. if (!cmSystemTools::FileIsDirectory(bindir))
  2033. {
  2034. cmSystemTools::MakeDirectory(bindir);
  2035. }
  2036. // change to the tests directory and run cmake
  2037. // use the cmake object instead of calling cmake
  2038. std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
  2039. cmSystemTools::ChangeDirectory(bindir);
  2040. // make sure the same generator is used
  2041. // use this program as the cmake to be run, it should not
  2042. // be run that way but the cmake object requires a vailid path
  2043. std::string cmakeCommand = this->GetDefinition("CMAKE_COMMAND");
  2044. cmake cm;
  2045. cm.SetIsInTryCompile(true);
  2046. cmGlobalGenerator *gg = cm.CreateGlobalGenerator
  2047. (this->LocalGenerator->GetGlobalGenerator()->GetName());
  2048. if (!gg)
  2049. {
  2050. cmSystemTools::Error(
  2051. "Internal CMake error, TryCompile bad GlobalGenerator");
  2052. // return to the original directory
  2053. cmSystemTools::ChangeDirectory(cwd.c_str());
  2054. return 1;
  2055. }
  2056. cm.SetGlobalGenerator(gg);
  2057. // do a configure
  2058. cm.SetHomeDirectory(srcdir);
  2059. cm.SetHomeOutputDirectory(bindir);
  2060. cm.SetStartDirectory(srcdir);
  2061. cm.SetStartOutputDirectory(bindir);
  2062. cm.SetCMakeCommand(cmakeCommand.c_str());
  2063. cm.LoadCache();
  2064. // if cmake args were provided then pass them in
  2065. if (cmakeArgs)
  2066. {
  2067. cm.SetCacheArgs(*cmakeArgs);
  2068. }
  2069. // to save time we pass the EnableLanguage info directly
  2070. gg->EnableLanguagesFromGenerator
  2071. (this->LocalGenerator->GetGlobalGenerator());
  2072. if (cm.Configure() != 0)
  2073. {
  2074. cmSystemTools::Error(
  2075. "Internal CMake error, TryCompile configure of cmake failed");
  2076. // return to the original directory
  2077. cmSystemTools::ChangeDirectory(cwd.c_str());
  2078. return 1;
  2079. }
  2080. if (cm.Generate() != 0)
  2081. {
  2082. cmSystemTools::Error(
  2083. "Internal CMake error, TryCompile generation of cmake failed");
  2084. // return to the original directory
  2085. cmSystemTools::ChangeDirectory(cwd.c_str());
  2086. return 1;
  2087. }
  2088. // finally call the generator to actually build the resulting project
  2089. int ret =
  2090. this->LocalGenerator->GetGlobalGenerator()->TryCompile(srcdir,bindir,
  2091. projectName,
  2092. targetName,
  2093. output,
  2094. this);
  2095. cmSystemTools::ChangeDirectory(cwd.c_str());
  2096. return ret;
  2097. }
  2098. cmake *cmMakefile::GetCMakeInstance() const
  2099. {
  2100. if ( this->LocalGenerator && this->LocalGenerator->GetGlobalGenerator() )
  2101. {
  2102. return this->LocalGenerator->GetGlobalGenerator()->GetCMakeInstance();
  2103. }
  2104. return 0;
  2105. }
  2106. #ifdef CMAKE_BUILD_WITH_CMAKE
  2107. cmVariableWatch *cmMakefile::GetVariableWatch() const
  2108. {
  2109. if ( this->GetCMakeInstance() &&
  2110. this->GetCMakeInstance()->GetVariableWatch() )
  2111. {
  2112. return this->GetCMakeInstance()->GetVariableWatch();
  2113. }
  2114. return 0;
  2115. }
  2116. #endif
  2117. void cmMakefile::AddMacro(const char* name, const char* signature)
  2118. {
  2119. if ( !name || !signature )
  2120. {
  2121. return;
  2122. }
  2123. this->MacrosMap[name] = signature;
  2124. }
  2125. void cmMakefile::GetListOfMacros(std::string& macros)
  2126. {
  2127. StringStringMap::iterator it;
  2128. macros = "";
  2129. int cc = 0;
  2130. for ( it = this->MacrosMap.begin(); it != this->MacrosMap.end(); ++it )
  2131. {
  2132. if ( cc > 0 )
  2133. {
  2134. macros += ";";
  2135. }
  2136. macros += it->first;
  2137. cc ++;
  2138. }
  2139. }
  2140. cmCacheManager *cmMakefile::GetCacheManager() const
  2141. {
  2142. return this->GetCMakeInstance()->GetCacheManager();
  2143. }
  2144. void cmMakefile::DisplayStatus(const char* message, float s)
  2145. {
  2146. this->GetLocalGenerator()->GetGlobalGenerator()
  2147. ->GetCMakeInstance()->UpdateProgress(message, s);
  2148. }
  2149. std::string cmMakefile::GetModulesFile(const char* filename)
  2150. {
  2151. std::vector<std::string> modulePath;
  2152. const char* def = this->GetDefinition("CMAKE_MODULE_PATH");
  2153. if(def)
  2154. {
  2155. cmSystemTools::ExpandListArgument(def, modulePath);
  2156. }
  2157. // Also search in the standard modules location.
  2158. def = this->GetDefinition("CMAKE_ROOT");
  2159. if(def)
  2160. {
  2161. std::string rootModules = def;
  2162. rootModules += "/Modules";
  2163. modulePath.push_back(rootModules);
  2164. }
  2165. //std::string Look through the possible module directories.
  2166. for(std::vector<std::string>::iterator i = modulePath.begin();
  2167. i != modulePath.end(); ++i)
  2168. {
  2169. std::string itempl = *i;
  2170. cmSystemTools::ConvertToUnixSlashes(itempl);
  2171. itempl += "/";
  2172. itempl += filename;
  2173. if(cmSystemTools::FileExists(itempl.c_str()))
  2174. {
  2175. return itempl;
  2176. }
  2177. }
  2178. return "";
  2179. }
  2180. void cmMakefile::ConfigureString(const std::string& input,
  2181. std::string& output, bool atOnly,
  2182. bool escapeQuotes)
  2183. {
  2184. // Split input to handle one line at a time.
  2185. std::string::const_iterator lineStart = input.begin();
  2186. while(lineStart != input.end())
  2187. {
  2188. // Find the end of this line.
  2189. std::string::const_iterator lineEnd = lineStart;
  2190. while(lineEnd != input.end() && *lineEnd != '\n')
  2191. {
  2192. ++lineEnd;
  2193. }
  2194. // Copy the line.
  2195. std::string line(lineStart, lineEnd);
  2196. // Skip the newline character.
  2197. bool haveNewline = (lineEnd != input.end());
  2198. if(haveNewline)
  2199. {
  2200. ++lineEnd;
  2201. }
  2202. // Replace #cmakedefine instances.
  2203. if(this->cmDefineRegex.find(line))
  2204. {
  2205. const char* def =
  2206. this->GetDefinition(this->cmDefineRegex.match(1).c_str());
  2207. if(!cmSystemTools::IsOff(def))
  2208. {
  2209. cmSystemTools::ReplaceString(line, "#cmakedefine", "#define");
  2210. output += line;
  2211. }
  2212. else
  2213. {
  2214. cmSystemTools::ReplaceString(line, "#cmakedefine", "#undef");
  2215. output += "/* ";
  2216. output += line;
  2217. output += " */";
  2218. }
  2219. }
  2220. else if(this->cmDefine01Regex.find(line))
  2221. {
  2222. const char* def =
  2223. this->GetDefinition(this->cmDefine01Regex.match(1).c_str());
  2224. cmSystemTools::ReplaceString(line, "#cmakedefine01", "#define");
  2225. output += line;
  2226. if(!cmSystemTools::IsOff(def))
  2227. {
  2228. output += " 1";
  2229. }
  2230. else
  2231. {
  2232. output += " 0";
  2233. }
  2234. }
  2235. else
  2236. {
  2237. output += line;
  2238. }
  2239. if(haveNewline)
  2240. {
  2241. output += "\n";
  2242. }
  2243. // Move to the next line.
  2244. lineStart = lineEnd;
  2245. }
  2246. // Perform variable replacements.
  2247. this->ExpandVariablesInString(output, escapeQuotes, true,
  2248. atOnly, 0, -1, true);
  2249. }
  2250. int cmMakefile::ConfigureFile(const char* infile, const char* outfile,
  2251. bool copyonly, bool atOnly, bool escapeQuotes)
  2252. {
  2253. int res = 1;
  2254. if ( !this->CanIWriteThisFile(outfile) )
  2255. {
  2256. cmSystemTools::Error("Attempt to write file: ",
  2257. outfile, " into a source directory.");
  2258. return 0;
  2259. }
  2260. if ( !cmSystemTools::FileExists(infile) )
  2261. {
  2262. cmSystemTools::Error("File ", infile, " does not exist.");
  2263. return 0;
  2264. }
  2265. std::string soutfile = outfile;
  2266. std::string sinfile = infile;
  2267. this->AddCMakeDependFile(infile);
  2268. cmSystemTools::ConvertToUnixSlashes(soutfile);
  2269. mode_t perm = 0;
  2270. cmSystemTools::GetPermissions(sinfile.c_str(), perm);
  2271. std::string::size_type pos = soutfile.rfind('/');
  2272. if(pos != std::string::npos)
  2273. {
  2274. std::string path = soutfile.substr(0, pos);
  2275. cmSystemTools::MakeDirectory(path.c_str());
  2276. }
  2277. if(copyonly)
  2278. {
  2279. if ( !cmSystemTools::CopyFileIfDifferent(sinfile.c_str(),
  2280. soutfile.c_str()))
  2281. {
  2282. return 0;
  2283. }
  2284. }
  2285. else
  2286. {
  2287. std::string tempOutputFile = soutfile;
  2288. tempOutputFile += ".tmp";
  2289. std::ofstream fout(tempOutputFile.c_str());
  2290. if(!fout)
  2291. {
  2292. cmSystemTools::Error(
  2293. "Could not open file for write in copy operation ",
  2294. tempOutputFile.c_str());
  2295. cmSystemTools::ReportLastSystemError("");
  2296. return 0;
  2297. }
  2298. std::ifstream fin(sinfile.c_str());
  2299. if(!fin)
  2300. {
  2301. cmSystemTools::Error("Could not open file for read in copy operation ",
  2302. sinfile.c_str());
  2303. return 0;
  2304. }
  2305. // now copy input to output and expand variables in the
  2306. // input file at the same time
  2307. std::string inLine;
  2308. std::string outLine;
  2309. while( cmSystemTools::GetLineFromStream(fin, inLine) )
  2310. {
  2311. outLine = "";
  2312. this->ConfigureString(inLine, outLine, atOnly, escapeQuotes);
  2313. fout << outLine.c_str() << "\n";
  2314. }
  2315. // close the files before attempting to copy
  2316. fin.close();
  2317. fout.close();
  2318. if ( !cmSystemTools::CopyFileIfDifferent(tempOutputFile.c_str(),
  2319. soutfile.c_str()) )
  2320. {
  2321. res = 0;
  2322. }
  2323. else
  2324. {
  2325. cmSystemTools::SetPermissions(soutfile.c_str(), perm);
  2326. }
  2327. cmSystemTools::RemoveFile(tempOutputFile.c_str());
  2328. }
  2329. return res;
  2330. }
  2331. void cmMakefile::AddWrittenFile(const char* file)
  2332. { this->GetCMakeInstance()->AddWrittenFile(file); }
  2333. bool cmMakefile::HasWrittenFile(const char* file)
  2334. { return this->GetCMakeInstance()->HasWrittenFile(file); }
  2335. bool cmMakefile::CheckInfiniteLoops()
  2336. {
  2337. std::vector<std::string>::iterator it;
  2338. for ( it = this->ListFiles.begin();
  2339. it != this->ListFiles.end();
  2340. ++ it )
  2341. {
  2342. if ( this->HasWrittenFile(it->c_str()) )
  2343. {
  2344. cmOStringStream str;
  2345. str << "File " << it->c_str() <<
  2346. " is written by WRITE_FILE (or FILE WRITE) command and should "
  2347. "not be used as input to CMake. Please use CONFIGURE_FILE to "
  2348. "be safe. Refer to the note next to FILE WRITE command.";
  2349. cmSystemTools::Error(str.str().c_str());
  2350. return false;
  2351. }
  2352. }
  2353. return true;
  2354. }
  2355. void cmMakefile::SetProperty(const char* prop, const char* value)
  2356. {
  2357. if (!prop)
  2358. {
  2359. return;
  2360. }
  2361. if (!value)
  2362. {
  2363. value = "NOTFOUND";
  2364. }
  2365. this->Properties[prop] = value;
  2366. }
  2367. const char *cmMakefile::GetProperty(const char* prop)
  2368. {
  2369. // watch for specific properties
  2370. if (!strcmp("PARENT_DIRECTORY",prop))
  2371. {
  2372. return this->LocalGenerator->GetParent()
  2373. ->GetMakefile()->GetStartDirectory();
  2374. }
  2375. // watch for specific properties
  2376. if (!strcmp("LISTFILE_STACK",prop))
  2377. {
  2378. std::string tmp;
  2379. for (std::deque<cmStdString>::iterator i = this->ListFileStack.begin();
  2380. i != this->ListFileStack.end(); ++i)
  2381. {
  2382. if (i != this->ListFileStack.begin())
  2383. {
  2384. tmp += ";";
  2385. }
  2386. tmp += *i;
  2387. }
  2388. this->SetProperty("LISTFILE_STACK",tmp.c_str());
  2389. }
  2390. std::map<cmStdString,cmStdString>::const_iterator i =
  2391. this->Properties.find(prop);
  2392. if (i != this->Properties.end())
  2393. {
  2394. return i->second.c_str();
  2395. }
  2396. return 0;
  2397. }
  2398. bool cmMakefile::GetPropertyAsBool(const char* prop) const
  2399. {
  2400. std::map<cmStdString,cmStdString>::const_iterator i =
  2401. this->Properties.find(prop);
  2402. if (i != this->Properties.end())
  2403. {
  2404. return cmSystemTools::IsOn(i->second.c_str());
  2405. }
  2406. return false;
  2407. }
  2408. cmTarget* cmMakefile::FindTarget(const char* name)
  2409. {
  2410. cmTargets& tgts = this->GetTargets();
  2411. cmTargets::iterator i = tgts.find(name);
  2412. if (i == tgts.end())
  2413. {
  2414. return 0;
  2415. }
  2416. return &i->second;
  2417. }
  2418. cmTest* cmMakefile::CreateTest(const char* testName)
  2419. {
  2420. if ( !testName )
  2421. {
  2422. return 0;
  2423. }
  2424. cmTest* test = this->GetTest(testName);
  2425. if ( test )
  2426. {
  2427. return test;
  2428. }
  2429. test = new cmTest;
  2430. test->SetName(testName);
  2431. this->Tests.push_back(test);
  2432. return test;
  2433. }
  2434. cmTest* cmMakefile::GetTest(const char* testName) const
  2435. {
  2436. if ( !testName )
  2437. {
  2438. return 0;
  2439. }
  2440. std::vector<cmTest*>::const_iterator it;
  2441. for ( it = this->Tests.begin(); it != this->Tests.end(); ++ it )
  2442. {
  2443. if ( strcmp((*it)->GetName(), testName) == 0 )
  2444. {
  2445. return *it;
  2446. }
  2447. }
  2448. return 0;
  2449. }
  2450. const std::vector<cmTest*> *cmMakefile::GetTests() const
  2451. {
  2452. return &this->Tests;
  2453. }
  2454. std::vector<cmTest*> *cmMakefile::GetTests()
  2455. {
  2456. return &this->Tests;
  2457. }