cmMakefile.cxx 93 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236
  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 "cmVersion.h"
  15. #include "cmCommand.h"
  16. #include "cmSourceFile.h"
  17. #include "cmSourceFileLocation.h"
  18. #include "cmSystemTools.h"
  19. #include "cmGlobalGenerator.h"
  20. #include "cmLocalGenerator.h"
  21. #include "cmCommands.h"
  22. #include "cmCacheManager.h"
  23. #include "cmFunctionBlocker.h"
  24. #include "cmListFileCache.h"
  25. #include "cmCommandArgumentParserHelper.h"
  26. #include "cmTest.h"
  27. #ifdef CMAKE_BUILD_WITH_CMAKE
  28. # include "cmVariableWatch.h"
  29. #endif
  30. #include "cmInstallGenerator.h"
  31. #include "cmake.h"
  32. #include <stdlib.h> // required for atoi
  33. #include <cmsys/RegularExpression.hxx>
  34. #include <cmsys/auto_ptr.hxx>
  35. #include <ctype.h> // for isspace
  36. // default is not to be building executables
  37. cmMakefile::cmMakefile()
  38. {
  39. this->DefinitionStack.push_back(DefinitionMap());
  40. // Setup the default include file regular expression (match everything).
  41. this->IncludeFileRegularExpression = "^.*$";
  42. // Setup the default include complaint regular expression (match nothing).
  43. this->ComplainFileRegularExpression = "^$";
  44. // Source and header file extensions that we can handle
  45. // Set up a list of source and header extensions
  46. // these are used to find files when the extension
  47. // is not given
  48. // The "c" extension MUST precede the "C" extension.
  49. this->SourceFileExtensions.push_back( "c" );
  50. this->SourceFileExtensions.push_back( "C" );
  51. this->SourceFileExtensions.push_back( "c++" );
  52. this->SourceFileExtensions.push_back( "cc" );
  53. this->SourceFileExtensions.push_back( "cpp" );
  54. this->SourceFileExtensions.push_back( "cxx" );
  55. this->SourceFileExtensions.push_back( "m" );
  56. this->SourceFileExtensions.push_back( "M" );
  57. this->SourceFileExtensions.push_back( "mm" );
  58. this->HeaderFileExtensions.push_back( "h" );
  59. this->HeaderFileExtensions.push_back( "hh" );
  60. this->HeaderFileExtensions.push_back( "h++" );
  61. this->HeaderFileExtensions.push_back( "hm" );
  62. this->HeaderFileExtensions.push_back( "hpp" );
  63. this->HeaderFileExtensions.push_back( "hxx" );
  64. this->HeaderFileExtensions.push_back( "in" );
  65. this->HeaderFileExtensions.push_back( "txx" );
  66. this->DefineFlags = " ";
  67. this->LocalGenerator = 0;
  68. #if defined(CMAKE_BUILD_WITH_CMAKE)
  69. this->AddSourceGroup("", "^.*$");
  70. this->AddSourceGroup
  71. ("Source Files",
  72. "\\.(C|M|c|c\\+\\+|cc|cpp|cxx|m|mm|rc|def|r|odl|idl|hpj|bat)$");
  73. this->AddSourceGroup("Header Files",
  74. "\\.(h|hh|h\\+\\+|hm|hpp|hxx|in|txx|inl)$");
  75. this->AddSourceGroup("CMake Rules", "\\.rule$");
  76. this->AddSourceGroup("Resources", "\\.plist$");
  77. #endif
  78. this->AddDefaultDefinitions();
  79. this->Initialize();
  80. this->PreOrder = false;
  81. }
  82. cmMakefile::cmMakefile(const cmMakefile& mf)
  83. {
  84. this->Prefix = mf.Prefix;
  85. this->AuxSourceDirectories = mf.AuxSourceDirectories;
  86. this->cmStartDirectory = mf.cmStartDirectory;
  87. this->StartOutputDirectory = mf.StartOutputDirectory;
  88. this->cmHomeDirectory = mf.cmHomeDirectory;
  89. this->HomeOutputDirectory = mf.HomeOutputDirectory;
  90. this->cmCurrentListFile = mf.cmCurrentListFile;
  91. this->ProjectName = mf.ProjectName;
  92. this->Targets = mf.Targets;
  93. this->SourceFiles = mf.SourceFiles;
  94. this->Tests = mf.Tests;
  95. this->IncludeDirectories = mf.IncludeDirectories;
  96. this->LinkDirectories = mf.LinkDirectories;
  97. this->SystemIncludeDirectories = mf.SystemIncludeDirectories;
  98. this->ListFiles = mf.ListFiles;
  99. this->OutputFiles = mf.OutputFiles;
  100. this->LinkLibraries = mf.LinkLibraries;
  101. this->InstallGenerators = mf.InstallGenerators;
  102. this->IncludeFileRegularExpression = mf.IncludeFileRegularExpression;
  103. this->ComplainFileRegularExpression = mf.ComplainFileRegularExpression;
  104. this->SourceFileExtensions = mf.SourceFileExtensions;
  105. this->HeaderFileExtensions = mf.HeaderFileExtensions;
  106. this->DefineFlags = mf.DefineFlags;
  107. #if defined(CMAKE_BUILD_WITH_CMAKE)
  108. this->SourceGroups = mf.SourceGroups;
  109. #endif
  110. this->DefinitionStack.push_back(mf.DefinitionStack.back());
  111. this->LocalGenerator = mf.LocalGenerator;
  112. this->FunctionBlockers = mf.FunctionBlockers;
  113. this->DataMap = mf.DataMap;
  114. this->MacrosMap = mf.MacrosMap;
  115. this->SubDirectoryOrder = mf.SubDirectoryOrder;
  116. this->TemporaryDefinitionKey = mf.TemporaryDefinitionKey;
  117. this->Properties = mf.Properties;
  118. this->PreOrder = mf.PreOrder;
  119. this->ListFileStack = mf.ListFileStack;
  120. this->Initialize();
  121. }
  122. //----------------------------------------------------------------------------
  123. void cmMakefile::Initialize()
  124. {
  125. this->cmDefineRegex.compile("#cmakedefine[ \t]+([A-Za-z_0-9]*)");
  126. this->cmDefine01Regex.compile("#cmakedefine01[ \t]+([A-Za-z_0-9]*)");
  127. this->cmAtVarRegex.compile("(@[A-Za-z_0-9/.+-]+@)");
  128. }
  129. unsigned int cmMakefile::GetCacheMajorVersion()
  130. {
  131. return this->GetCacheManager()->GetCacheMajorVersion();
  132. }
  133. unsigned int cmMakefile::GetCacheMinorVersion()
  134. {
  135. return this->GetCacheManager()->GetCacheMinorVersion();
  136. }
  137. bool cmMakefile::NeedCacheCompatibility(int major, int minor)
  138. {
  139. return this->GetCacheManager()->NeedCacheCompatibility(major, minor);
  140. }
  141. cmMakefile::~cmMakefile()
  142. {
  143. for(std::vector<cmInstallGenerator*>::iterator
  144. i = this->InstallGenerators.begin();
  145. i != this->InstallGenerators.end(); ++i)
  146. {
  147. delete *i;
  148. }
  149. for(std::vector<cmSourceFile*>::iterator i = this->SourceFiles.begin();
  150. i != this->SourceFiles.end(); ++i)
  151. {
  152. delete *i;
  153. }
  154. for(std::vector<cmTest*>::iterator i = this->Tests.begin();
  155. i != this->Tests.end(); ++i)
  156. {
  157. delete *i;
  158. }
  159. for(std::vector<cmTarget*>::iterator
  160. i = this->ImportedTargetsOwned.begin();
  161. i != this->ImportedTargetsOwned.end(); ++i)
  162. {
  163. delete *i;
  164. }
  165. for(unsigned int i=0; i < this->UsedCommands.size(); i++)
  166. {
  167. delete this->UsedCommands[i];
  168. }
  169. for(DataMapType::const_iterator d = this->DataMap.begin();
  170. d != this->DataMap.end(); ++d)
  171. {
  172. if(d->second)
  173. {
  174. delete d->second;
  175. }
  176. }
  177. std::list<cmFunctionBlocker *>::iterator pos;
  178. for (pos = this->FunctionBlockers.begin();
  179. pos != this->FunctionBlockers.end(); ++pos)
  180. {
  181. cmFunctionBlocker* b = *pos;
  182. delete b;
  183. }
  184. this->FunctionBlockers.clear();
  185. }
  186. void cmMakefile::PrintStringVector(const char* s,
  187. const std::vector<std::string>& v) const
  188. {
  189. std::cout << s << ": ( \n";
  190. for(std::vector<std::string>::const_iterator i = v.begin();
  191. i != v.end(); ++i)
  192. {
  193. std::cout << (*i).c_str() << " ";
  194. }
  195. std::cout << " )\n";
  196. }
  197. void cmMakefile
  198. ::PrintStringVector(const char* s,
  199. const std::vector<std::pair<cmStdString, bool> >& v) const
  200. {
  201. std::cout << s << ": ( \n";
  202. for(std::vector<std::pair<cmStdString, bool> >::const_iterator i
  203. = v.begin(); i != v.end(); ++i)
  204. {
  205. std::cout << i->first.c_str() << " " << i->second;
  206. }
  207. std::cout << " )\n";
  208. }
  209. // call print on all the classes in the makefile
  210. void cmMakefile::Print()
  211. {
  212. // print the class lists
  213. std::cout << "classes:\n";
  214. std::cout << " this->Targets: ";
  215. for (cmTargets::iterator l = this->Targets.begin();
  216. l != this->Targets.end(); l++)
  217. {
  218. std::cout << l->first << std::endl;
  219. }
  220. std::cout << " this->StartOutputDirectory; " <<
  221. this->StartOutputDirectory.c_str() << std::endl;
  222. std::cout << " this->HomeOutputDirectory; " <<
  223. this->HomeOutputDirectory.c_str() << std::endl;
  224. std::cout << " this->cmStartDirectory; " <<
  225. this->cmStartDirectory.c_str() << std::endl;
  226. std::cout << " this->cmHomeDirectory; " <<
  227. this->cmHomeDirectory.c_str() << std::endl;
  228. std::cout << " this->ProjectName; "
  229. << this->ProjectName.c_str() << std::endl;
  230. this->PrintStringVector("this->IncludeDirectories;",
  231. this->IncludeDirectories);
  232. this->PrintStringVector("this->LinkDirectories", this->LinkDirectories);
  233. #if defined(CMAKE_BUILD_WITH_CMAKE)
  234. for( std::vector<cmSourceGroup>::const_iterator i =
  235. this->SourceGroups.begin(); i != this->SourceGroups.end(); ++i)
  236. {
  237. std::cout << "Source Group: " << i->GetName() << std::endl;
  238. }
  239. #endif
  240. }
  241. bool cmMakefile::CommandExists(const char* name) const
  242. {
  243. return this->GetCMakeInstance()->CommandExists(name);
  244. }
  245. bool cmMakefile::ExecuteCommand(const cmListFileFunction& lff,
  246. cmExecutionStatus &status)
  247. {
  248. bool result = true;
  249. // quick return if blocked
  250. if(this->IsFunctionBlocked(lff,status))
  251. {
  252. // No error.
  253. return result;
  254. }
  255. std::string name = lff.Name;
  256. // execute the command
  257. cmCommand *rm =
  258. this->GetCMakeInstance()->GetCommand(name.c_str());
  259. if(rm)
  260. {
  261. const char* versionValue
  262. = this->GetDefinition("CMAKE_BACKWARDS_COMPATIBILITY");
  263. int major = 0;
  264. int minor = 0;
  265. if ( versionValue )
  266. {
  267. sscanf(versionValue, "%d.%d", &major, &minor);
  268. }
  269. if ( rm->IsDeprecated(major, minor) )
  270. {
  271. cmOStringStream error;
  272. error << "Error in cmake code at\n"
  273. << lff.FilePath << ":" << lff.Line << ":\n"
  274. << rm->GetError() << std::endl
  275. << " Called from: " << this->GetListFileStack().c_str();
  276. cmSystemTools::Error(error.str().c_str());
  277. return false;
  278. }
  279. cmCommand* usedCommand = rm->Clone();
  280. usedCommand->SetMakefile(this);
  281. bool keepCommand = false;
  282. if(usedCommand->GetEnabled() && !cmSystemTools::GetFatalErrorOccured() &&
  283. (!this->GetCMakeInstance()->GetScriptMode() ||
  284. usedCommand->IsScriptable()))
  285. {
  286. if(!usedCommand->InvokeInitialPass(lff.Arguments,status))
  287. {
  288. cmOStringStream error;
  289. error << "Error in cmake code at\n"
  290. << lff.FilePath << ":" << lff.Line << ":\n"
  291. << usedCommand->GetError() << std::endl
  292. << " Called from: " << this->GetListFileStack().c_str();
  293. cmSystemTools::Error(error.str().c_str());
  294. result = false;
  295. if ( this->GetCMakeInstance()->GetScriptMode() )
  296. {
  297. cmSystemTools::SetFatalErrorOccured();
  298. }
  299. }
  300. else
  301. {
  302. // use the command
  303. keepCommand = true;
  304. this->UsedCommands.push_back(usedCommand);
  305. }
  306. }
  307. else if ( this->GetCMakeInstance()->GetScriptMode()
  308. && !usedCommand->IsScriptable() )
  309. {
  310. cmOStringStream error;
  311. error << "Error in cmake code at\n"
  312. << lff.FilePath << ":" << lff.Line << ":\n"
  313. << "Command " << usedCommand->GetName()
  314. << "() is not scriptable" << std::endl;
  315. cmSystemTools::Error(error.str().c_str());
  316. result = false;
  317. cmSystemTools::SetFatalErrorOccured();
  318. }
  319. // if the Cloned command was not used
  320. // then delete it
  321. if(!keepCommand)
  322. {
  323. delete usedCommand;
  324. }
  325. }
  326. else
  327. {
  328. if(!cmSystemTools::GetFatalErrorOccured())
  329. {
  330. cmOStringStream error;
  331. error << "Error in cmake code at\n"
  332. << lff.FilePath << ":" << lff.Line << ":\n"
  333. << "Unknown CMake command \"" << lff.Name.c_str() << "\".";
  334. cmSystemTools::Error(error.str().c_str());
  335. result = false;
  336. cmSystemTools::SetFatalErrorOccured();
  337. }
  338. }
  339. return result;
  340. }
  341. // Parse the given CMakeLists.txt file executing all commands
  342. //
  343. bool cmMakefile::ReadListFile(const char* filename_in,
  344. const char *external_in,
  345. std::string* fullPath)
  346. {
  347. std::string currentParentFile
  348. = this->GetSafeDefinition("CMAKE_PARENT_LIST_FILE");
  349. std::string currentFile
  350. = this->GetSafeDefinition("CMAKE_CURRENT_LIST_FILE");
  351. this->AddDefinition("CMAKE_PARENT_LIST_FILE", filename_in);
  352. // used to watch for blockers going out of scope
  353. // e.g. mismatched IF statement
  354. std::set<cmFunctionBlocker *> originalBlockers;
  355. const char* external = 0;
  356. std::string external_abs;
  357. const char* filename = filename_in;
  358. std::string filename_abs;
  359. if (external_in)
  360. {
  361. external_abs =
  362. cmSystemTools::CollapseFullPath(external_in,
  363. this->cmStartDirectory.c_str());
  364. external = external_abs.c_str();
  365. if (filename_in)
  366. {
  367. filename_abs =
  368. cmSystemTools::CollapseFullPath(filename_in,
  369. this->cmStartDirectory.c_str());
  370. filename = filename_abs.c_str();
  371. }
  372. }
  373. // keep track of the current file being read
  374. if (filename)
  375. {
  376. if(this->cmCurrentListFile != filename)
  377. {
  378. this->cmCurrentListFile = filename;
  379. }
  380. // loop over current function blockers and record them
  381. std::list<cmFunctionBlocker *>::iterator pos;
  382. for (pos = this->FunctionBlockers.begin();
  383. pos != this->FunctionBlockers.end(); ++pos)
  384. {
  385. originalBlockers.insert(*pos);
  386. }
  387. }
  388. // Now read the input file
  389. const char *filenametoread= filename;
  390. if( external)
  391. {
  392. filenametoread= external;
  393. }
  394. this->AddDefinition("CMAKE_CURRENT_LIST_FILE", filenametoread);
  395. // try to see if the list file is the top most
  396. // list file for a project, and if it is, then it
  397. // must have a project command. If there is not
  398. // one, then cmake will provide one via the
  399. // cmListFileCache class.
  400. bool requireProjectCommand = false;
  401. if(!external && this->cmStartDirectory == this->cmHomeDirectory)
  402. {
  403. if(cmSystemTools::LowerCase(
  404. cmSystemTools::GetFilenameName(filename)) == "cmakelists.txt")
  405. {
  406. requireProjectCommand = true;
  407. }
  408. }
  409. // push the listfile onto the stack
  410. this->ListFileStack.push_back(filenametoread);
  411. if(fullPath!=0)
  412. {
  413. *fullPath=filenametoread;
  414. }
  415. cmListFile cacheFile;
  416. if( !cacheFile.ParseFile(filenametoread, requireProjectCommand) )
  417. {
  418. // pop the listfile off the stack
  419. this->ListFileStack.pop_back();
  420. if(fullPath!=0)
  421. {
  422. *fullPath = "";
  423. }
  424. this->AddDefinition("CMAKE_PARENT_LIST_FILE", currentParentFile.c_str());
  425. this->AddDefinition("CMAKE_CURRENT_LIST_FILE", currentFile.c_str());
  426. return false;
  427. }
  428. // add this list file to the list of dependencies
  429. this->ListFiles.push_back( filenametoread);
  430. const size_t numberFunctions = cacheFile.Functions.size();
  431. for(size_t i =0; i < numberFunctions; ++i)
  432. {
  433. cmExecutionStatus status;
  434. this->ExecuteCommand(cacheFile.Functions[i],status);
  435. if (status.GetReturnInvoked() ||
  436. cmSystemTools::GetFatalErrorOccured() )
  437. {
  438. // pop the listfile off the stack
  439. this->ListFileStack.pop_back();
  440. this->AddDefinition("CMAKE_PARENT_LIST_FILE",
  441. currentParentFile.c_str());
  442. this->AddDefinition("CMAKE_CURRENT_LIST_FILE", currentFile.c_str());
  443. return true;
  444. }
  445. }
  446. // send scope ended to and function blockers
  447. if (filename)
  448. {
  449. // loop over all function blockers to see if any block this command
  450. std::list<cmFunctionBlocker *>::iterator pos;
  451. for (pos = this->FunctionBlockers.begin();
  452. pos != this->FunctionBlockers.end(); ++pos)
  453. {
  454. // if this blocker was not in the original then send a
  455. // scope ended message
  456. if (originalBlockers.find(*pos) == originalBlockers.end())
  457. {
  458. (*pos)->ScopeEnded(*this);
  459. }
  460. }
  461. }
  462. this->AddDefinition("CMAKE_PARENT_LIST_FILE", currentParentFile.c_str());
  463. this->AddDefinition("CMAKE_CURRENT_LIST_FILE", currentFile.c_str());
  464. // pop the listfile off the stack
  465. this->ListFileStack.pop_back();
  466. return true;
  467. }
  468. void cmMakefile::AddCommand(cmCommand* wg)
  469. {
  470. this->GetCMakeInstance()->AddCommand(wg);
  471. }
  472. // Set the make file
  473. void cmMakefile::SetLocalGenerator(cmLocalGenerator* lg)
  474. {
  475. this->LocalGenerator = lg;
  476. }
  477. bool cmMakefile::NeedBackwardsCompatibility(unsigned int major,
  478. unsigned int minor,
  479. unsigned int patch)
  480. {
  481. if(this->LocalGenerator)
  482. {
  483. return
  484. this->LocalGenerator->NeedBackwardsCompatibility(major, minor, patch);
  485. }
  486. else
  487. {
  488. return false;
  489. }
  490. }
  491. void cmMakefile::FinalPass()
  492. {
  493. // do all the variable expansions here
  494. this->ExpandVariables();
  495. // give all the commands a chance to do something
  496. // after the file has been parsed before generation
  497. for(std::vector<cmCommand*>::iterator i = this->UsedCommands.begin();
  498. i != this->UsedCommands.end(); ++i)
  499. {
  500. (*i)->FinalPass();
  501. }
  502. }
  503. // Generate the output file
  504. void cmMakefile::ConfigureFinalPass()
  505. {
  506. this->FinalPass();
  507. const char* oldValue
  508. = this->GetDefinition("CMAKE_BACKWARDS_COMPATIBILITY");
  509. if (oldValue && atof(oldValue) <= 1.2)
  510. {
  511. cmSystemTools::Error("You have requested backwards compatibility "
  512. "with CMake version 1.2 or earlier. This version "
  513. "of CMake only supports backwards compatibility "
  514. "with CMake 1.4 or later. For compatibility with "
  515. "1.2 or earlier please use CMake 2.0");
  516. }
  517. for (cmTargets::iterator l = this->Targets.begin();
  518. l != this->Targets.end(); l++)
  519. {
  520. l->second.AnalyzeLibDependencies(*this);
  521. }
  522. }
  523. //----------------------------------------------------------------------------
  524. void
  525. cmMakefile::AddCustomCommandToTarget(const char* target,
  526. const std::vector<std::string>& depends,
  527. const cmCustomCommandLines& commandLines,
  528. cmTarget::CustomCommandType type,
  529. const char* comment,
  530. const char* workingDir,
  531. bool escapeOldStyle)
  532. {
  533. // Find the target to which to add the custom command.
  534. cmTargets::iterator ti = this->Targets.find(target);
  535. if(ti != this->Targets.end())
  536. {
  537. // Add the command to the appropriate build step for the target.
  538. std::vector<std::string> no_output;
  539. cmCustomCommand cc(no_output, depends, commandLines, comment, workingDir);
  540. cc.SetEscapeOldStyle(escapeOldStyle);
  541. switch(type)
  542. {
  543. case cmTarget::PRE_BUILD:
  544. ti->second.GetPreBuildCommands().push_back(cc);
  545. break;
  546. case cmTarget::PRE_LINK:
  547. ti->second.GetPreLinkCommands().push_back(cc);
  548. break;
  549. case cmTarget::POST_BUILD:
  550. ti->second.GetPostBuildCommands().push_back(cc);
  551. break;
  552. }
  553. }
  554. }
  555. //----------------------------------------------------------------------------
  556. void
  557. cmMakefile::AddCustomCommandToOutput(const std::vector<std::string>& outputs,
  558. const std::vector<std::string>& depends,
  559. const char* main_dependency,
  560. const cmCustomCommandLines& commandLines,
  561. const char* comment,
  562. const char* workingDir,
  563. bool replace,
  564. bool escapeOldStyle)
  565. {
  566. // Make sure there is at least one output.
  567. if(outputs.empty())
  568. {
  569. cmSystemTools::Error("Attempt to add a custom rule with no output!");
  570. return;
  571. }
  572. // Choose a source file on which to store the custom command.
  573. cmSourceFile* file = 0;
  574. if(main_dependency && main_dependency[0])
  575. {
  576. // The main dependency was specified. Use it unless a different
  577. // custom command already used it.
  578. file = this->GetSource(main_dependency);
  579. if(file && file->GetCustomCommand() && !replace)
  580. {
  581. // The main dependency already has a custom command.
  582. if(commandLines == file->GetCustomCommand()->GetCommandLines())
  583. {
  584. // The existing custom command is identical. Silently ignore
  585. // the duplicate.
  586. return;
  587. }
  588. else
  589. {
  590. // The existing custom command is different. We need to
  591. // generate a rule file for this new command.
  592. file = 0;
  593. }
  594. }
  595. else
  596. {
  597. // The main dependency does not have a custom command or we are
  598. // allowed to replace it. Use it to store the command.
  599. file = this->GetOrCreateSource(main_dependency);
  600. }
  601. }
  602. // Generate a rule file if the main dependency is not available.
  603. if(!file)
  604. {
  605. // Construct a rule file associated with the first output produced.
  606. std::string outName = outputs[0];
  607. outName += ".rule";
  608. // Check if the rule file already exists.
  609. file = this->GetSource(outName.c_str());
  610. if(file && file->GetCustomCommand() && !replace)
  611. {
  612. // The rule file already exists.
  613. if(commandLines != file->GetCustomCommand()->GetCommandLines())
  614. {
  615. cmSystemTools::Error("Attempt to add a custom rule to output \"",
  616. outName.c_str(),
  617. "\" which already has a custom rule.");
  618. }
  619. return;
  620. }
  621. // Create a cmSourceFile for the rule file.
  622. file = this->GetOrCreateSource(outName.c_str(), true);
  623. }
  624. // Always create the output sources and mark them generated.
  625. for(std::vector<std::string>::const_iterator o = outputs.begin();
  626. o != outputs.end(); ++o)
  627. {
  628. if(cmSourceFile* out = this->GetOrCreateSource(o->c_str(), true))
  629. {
  630. out->SetProperty("GENERATED", "1");
  631. }
  632. }
  633. // Construct a complete list of dependencies.
  634. std::vector<std::string> depends2(depends);
  635. if(main_dependency && main_dependency[0])
  636. {
  637. depends2.push_back(main_dependency);
  638. }
  639. // Attach the custom command to the file.
  640. if(file)
  641. {
  642. cmCustomCommand* cc =
  643. new cmCustomCommand(outputs, depends2, commandLines,
  644. comment, workingDir);
  645. cc->SetEscapeOldStyle(escapeOldStyle);
  646. file->SetCustomCommand(cc);
  647. }
  648. }
  649. //----------------------------------------------------------------------------
  650. void
  651. cmMakefile::AddCustomCommandToOutput(const char* output,
  652. const std::vector<std::string>& depends,
  653. const char* main_dependency,
  654. const cmCustomCommandLines& commandLines,
  655. const char* comment,
  656. const char* workingDir,
  657. bool replace,
  658. bool escapeOldStyle)
  659. {
  660. std::vector<std::string> outputs;
  661. outputs.push_back(output);
  662. this->AddCustomCommandToOutput(outputs, depends, main_dependency,
  663. commandLines, comment, workingDir,
  664. replace, escapeOldStyle);
  665. }
  666. //----------------------------------------------------------------------------
  667. void
  668. cmMakefile::AddCustomCommandOldStyle(const char* target,
  669. const std::vector<std::string>& outputs,
  670. const std::vector<std::string>& depends,
  671. const char* source,
  672. const cmCustomCommandLines& commandLines,
  673. const char* comment)
  674. {
  675. // Translate the old-style signature to one of the new-style
  676. // signatures.
  677. if(strcmp(source, target) == 0)
  678. {
  679. // In the old-style signature if the source and target were the
  680. // same then it added a post-build rule to the target. Preserve
  681. // this behavior.
  682. this->AddCustomCommandToTarget(target, depends, commandLines,
  683. cmTarget::POST_BUILD, comment, 0);
  684. return;
  685. }
  686. // Each output must get its own copy of this rule.
  687. cmsys::RegularExpression sourceFiles("\\.(C|M|c|c\\+\\+|cc|cpp|cxx|m|mm|"
  688. "rc|def|r|odl|idl|hpj|bat|h|h\\+\\+|"
  689. "hm|hpp|hxx|in|txx|inl)$");
  690. for(std::vector<std::string>::const_iterator oi = outputs.begin();
  691. oi != outputs.end(); ++oi)
  692. {
  693. // Get the name of this output.
  694. const char* output = oi->c_str();
  695. // Choose whether to use a main dependency.
  696. if(sourceFiles.find(source))
  697. {
  698. // The source looks like a real file. Use it as the main dependency.
  699. this->AddCustomCommandToOutput(output, depends, source,
  700. commandLines, comment, 0);
  701. }
  702. else
  703. {
  704. // The source may not be a real file. Do not use a main dependency.
  705. const char* no_main_dependency = 0;
  706. std::vector<std::string> depends2 = depends;
  707. depends2.push_back(source);
  708. this->AddCustomCommandToOutput(output, depends2, no_main_dependency,
  709. commandLines, comment, 0);
  710. }
  711. // If the rule was added to the source (and not a .rule file),
  712. // then add the source to the target to make sure the rule is
  713. // included.
  714. std::string sname = output;
  715. sname += ".rule";
  716. if(!this->GetSource(sname.c_str()))
  717. {
  718. if (this->Targets.find(target) != this->Targets.end())
  719. {
  720. this->Targets[target].AddSource(source);
  721. }
  722. else
  723. {
  724. cmSystemTools::Error("Attempt to add a custom rule to a target "
  725. "that does not exist yet for target ", target);
  726. return;
  727. }
  728. }
  729. }
  730. }
  731. //----------------------------------------------------------------------------
  732. void cmMakefile::AddUtilityCommand(const char* utilityName,
  733. bool excludeFromAll,
  734. const std::vector<std::string>& depends,
  735. const char* workingDirectory,
  736. const char* command,
  737. const char* arg1,
  738. const char* arg2,
  739. const char* arg3,
  740. const char* arg4)
  741. {
  742. // Construct the command line for the custom command.
  743. cmCustomCommandLine commandLine;
  744. commandLine.push_back(command);
  745. if(arg1)
  746. {
  747. commandLine.push_back(arg1);
  748. }
  749. if(arg2)
  750. {
  751. commandLine.push_back(arg2);
  752. }
  753. if(arg3)
  754. {
  755. commandLine.push_back(arg3);
  756. }
  757. if(arg4)
  758. {
  759. commandLine.push_back(arg4);
  760. }
  761. cmCustomCommandLines commandLines;
  762. commandLines.push_back(commandLine);
  763. // Call the real signature of this method.
  764. this->AddUtilityCommand(utilityName, excludeFromAll, workingDirectory,
  765. depends, commandLines);
  766. }
  767. //----------------------------------------------------------------------------
  768. void cmMakefile::AddUtilityCommand(const char* utilityName,
  769. bool excludeFromAll,
  770. const char* workingDirectory,
  771. const std::vector<std::string>& depends,
  772. const cmCustomCommandLines& commandLines,
  773. bool escapeOldStyle, const char* comment)
  774. {
  775. // Create a target instance for this utility.
  776. cmTarget* target = this->AddNewTarget(cmTarget::UTILITY, utilityName);
  777. if (excludeFromAll)
  778. {
  779. target->SetProperty("EXCLUDE_FROM_ALL", "TRUE");
  780. }
  781. if(!comment)
  782. {
  783. // Use an empty comment to avoid generation of default comment.
  784. comment = "";
  785. }
  786. // Store the custom command in the target.
  787. std::string force = this->GetStartOutputDirectory();
  788. force += cmake::GetCMakeFilesDirectory();
  789. force += "/";
  790. force += utilityName;
  791. const char* no_main_dependency = 0;
  792. bool no_replace = false;
  793. this->AddCustomCommandToOutput(force.c_str(), depends,
  794. no_main_dependency,
  795. commandLines, comment,
  796. workingDirectory, no_replace,
  797. escapeOldStyle);
  798. cmSourceFile* sf = target->AddSource(force.c_str());
  799. // The output is not actually created so mark it symbolic.
  800. if(sf)
  801. {
  802. sf->SetProperty("SYMBOLIC", "1");
  803. }
  804. else
  805. {
  806. cmSystemTools::Error("Could not get source file entry for ",
  807. force.c_str());
  808. }
  809. }
  810. void cmMakefile::AddDefineFlag(const char* flag)
  811. {
  812. if (!flag)
  813. {
  814. return;
  815. }
  816. // If this is really a definition, update COMPILE_DEFINITIONS.
  817. if(this->ParseDefineFlag(flag, false))
  818. {
  819. return;
  820. }
  821. // remove any \n\r
  822. std::string ret = flag;
  823. std::string::size_type pos = 0;
  824. while((pos = ret.find('\n', pos)) != std::string::npos)
  825. {
  826. ret[pos] = ' ';
  827. pos++;
  828. }
  829. pos = 0;
  830. while((pos = ret.find('\r', pos)) != std::string::npos)
  831. {
  832. ret[pos] = ' ';
  833. pos++;
  834. }
  835. this->DefineFlags += " ";
  836. this->DefineFlags += ret;
  837. }
  838. void cmMakefile::RemoveDefineFlag(const char* flag)
  839. {
  840. // Check the length of the flag to remove.
  841. std::string::size_type len = strlen(flag);
  842. if(len < 1)
  843. {
  844. return;
  845. }
  846. // If this is really a definition, update COMPILE_DEFINITIONS.
  847. if(this->ParseDefineFlag(flag, true))
  848. {
  849. return;
  850. }
  851. // Remove all instances of the flag that are surrounded by
  852. // whitespace or the beginning/end of the string.
  853. for(std::string::size_type lpos = this->DefineFlags.find(flag, 0);
  854. lpos != std::string::npos; lpos = this->DefineFlags.find(flag, lpos))
  855. {
  856. std::string::size_type rpos = lpos + len;
  857. if((lpos <= 0 || isspace(this->DefineFlags[lpos-1])) &&
  858. (rpos >= this->DefineFlags.size() || isspace(this->DefineFlags[rpos])))
  859. {
  860. this->DefineFlags.erase(lpos, len);
  861. }
  862. else
  863. {
  864. ++lpos;
  865. }
  866. }
  867. }
  868. bool cmMakefile::ParseDefineFlag(std::string const& def, bool remove)
  869. {
  870. // Create a regular expression to match valid definitions.
  871. // Definitions with non-trivial values must not be matched because
  872. // escaping them could break compatibility with escapes added by
  873. // users.
  874. static cmsys::RegularExpression
  875. regex("^[-/]D[A-Za-z_][A-Za-z0-9_]*(=[A-Za-z0-9_.]+)?$");
  876. // Make sure the definition matches.
  877. if(!regex.find(def.c_str()))
  878. {
  879. return false;
  880. }
  881. // VS6 IDE does not support definitions with values.
  882. if((strcmp(this->LocalGenerator->GetGlobalGenerator()->GetName(),
  883. "Visual Studio 6") == 0) &&
  884. (def.find("=") != def.npos))
  885. {
  886. return false;
  887. }
  888. // Get the definition part after the flag.
  889. const char* define = def.c_str() + 2;
  890. if(remove)
  891. {
  892. if(const char* cdefs = this->GetProperty("COMPILE_DEFINITIONS"))
  893. {
  894. // Expand the list.
  895. std::vector<std::string> defs;
  896. cmSystemTools::ExpandListArgument(cdefs, defs);
  897. // Recompose the list without the definition.
  898. std::string ndefs;
  899. const char* sep = "";
  900. for(std::vector<std::string>::const_iterator di = defs.begin();
  901. di != defs.end(); ++di)
  902. {
  903. if(*di != define)
  904. {
  905. ndefs += sep;
  906. sep = ";";
  907. ndefs += *di;
  908. }
  909. }
  910. // Store the new list.
  911. this->SetProperty("COMPILE_DEFINITIONS", ndefs.c_str());
  912. }
  913. }
  914. else
  915. {
  916. // Append the definition to the directory property.
  917. this->AppendProperty("COMPILE_DEFINITIONS", define);
  918. }
  919. return true;
  920. }
  921. void cmMakefile::AddLinkLibrary(const char* lib,
  922. cmTarget::LinkLibraryType llt)
  923. {
  924. cmTarget::LibraryID tmp;
  925. tmp.first = lib;
  926. tmp.second = llt;
  927. this->LinkLibraries.push_back(tmp);
  928. }
  929. void cmMakefile::AddLinkLibraryForTarget(const char *target,
  930. const char* lib,
  931. cmTarget::LinkLibraryType llt)
  932. {
  933. cmTargets::iterator i = this->Targets.find(target);
  934. if ( i != this->Targets.end())
  935. {
  936. cmTarget* tgt =
  937. this->GetCMakeInstance()->GetGlobalGenerator()->FindTarget(0,lib);
  938. if(tgt)
  939. {
  940. bool allowModules = true;
  941. const char* versionValue
  942. = this->GetDefinition("CMAKE_BACKWARDS_COMPATIBILITY");
  943. if (versionValue && (atof(versionValue) >= 2.4) )
  944. {
  945. allowModules = false;
  946. }
  947. // if it is not a static or shared library then you can not link to it
  948. if(!((tgt->GetType() == cmTarget::STATIC_LIBRARY) ||
  949. (tgt->GetType() == cmTarget::SHARED_LIBRARY) ||
  950. tgt->IsExecutableWithExports()))
  951. {
  952. cmOStringStream e;
  953. e << "Attempt to add link target " << lib << " of type: "
  954. << cmTarget::TargetTypeNames[static_cast<int>(tgt->GetType())]
  955. << "\nto target " << target
  956. << ". One can only link to STATIC or SHARED libraries, or "
  957. << "to executables with the ENABLE_EXPORTS property set.";
  958. // in older versions of cmake linking to modules was allowed
  959. if( tgt->GetType() == cmTarget::MODULE_LIBRARY )
  960. {
  961. e <<
  962. "\nTo allow linking of modules set "
  963. "CMAKE_BACKWARDS_COMPATIBILITY to 2.2 or lower\n";
  964. }
  965. // if no modules are allowed then this is always an error
  966. if(!allowModules ||
  967. // if we allow modules but the type is not a module then it is
  968. // still an error
  969. (allowModules && tgt->GetType() != cmTarget::MODULE_LIBRARY))
  970. {
  971. cmSystemTools::Error(e.str().c_str());
  972. }
  973. }
  974. }
  975. i->second.AddLinkLibrary( *this, target, lib, llt );
  976. }
  977. else
  978. {
  979. cmOStringStream e;
  980. e << "Attempt to add link library \""
  981. << lib << "\" to target \""
  982. << target << "\" which is not built by this project.";
  983. cmSystemTools::Error(e.str().c_str());
  984. }
  985. }
  986. void cmMakefile::AddLinkDirectoryForTarget(const char *target,
  987. const char* d)
  988. {
  989. cmTargets::iterator i = this->Targets.find(target);
  990. if ( i != this->Targets.end())
  991. {
  992. i->second.AddLinkDirectory( d );
  993. }
  994. else
  995. {
  996. cmSystemTools::Error
  997. ("Attempt to add link directories to non-existant target: ",
  998. target, " for directory ", d);
  999. }
  1000. }
  1001. void cmMakefile::AddLinkLibrary(const char* lib)
  1002. {
  1003. this->AddLinkLibrary(lib,cmTarget::GENERAL);
  1004. }
  1005. void cmMakefile::AddLinkDirectory(const char* dir)
  1006. {
  1007. // Don't add a link directory that is already present. Yes, this
  1008. // linear search results in n^2 behavior, but n won't be getting
  1009. // much bigger than 20. We cannot use a set because of order
  1010. // dependency of the link search path.
  1011. if(!dir)
  1012. {
  1013. return;
  1014. }
  1015. // remove trailing slashes
  1016. if(dir[strlen(dir)-1] == '/')
  1017. {
  1018. std::string newdir = dir;
  1019. newdir = newdir.substr(0, newdir.size()-1);
  1020. if(std::find(this->LinkDirectories.begin(),
  1021. this->LinkDirectories.end(),
  1022. newdir.c_str()) == this->LinkDirectories.end())
  1023. {
  1024. this->LinkDirectories.push_back(newdir);
  1025. }
  1026. }
  1027. else
  1028. {
  1029. if(std::find(this->LinkDirectories.begin(),
  1030. this->LinkDirectories.end(), dir)
  1031. == this->LinkDirectories.end())
  1032. {
  1033. this->LinkDirectories.push_back(dir);
  1034. }
  1035. }
  1036. }
  1037. void cmMakefile::InitializeFromParent()
  1038. {
  1039. cmMakefile *parent = this->LocalGenerator->GetParent()->GetMakefile();
  1040. // copy the definitions
  1041. this->DefinitionStack.front() = parent->DefinitionStack.back();
  1042. // copy include paths
  1043. this->IncludeDirectories = parent->IncludeDirectories;
  1044. this->SystemIncludeDirectories = parent->SystemIncludeDirectories;
  1045. // define flags
  1046. this->DefineFlags = parent->DefineFlags;
  1047. // compile definitions property and per-config versions
  1048. {
  1049. this->SetProperty("COMPILE_DEFINITIONS",
  1050. parent->GetProperty("COMPILE_DEFINITIONS"));
  1051. std::vector<std::string> configs;
  1052. if(const char* configTypes =
  1053. this->GetDefinition("CMAKE_CONFIGURATION_TYPES"))
  1054. {
  1055. cmSystemTools::ExpandListArgument(configTypes, configs);
  1056. }
  1057. else if(const char* buildType =
  1058. this->GetDefinition("CMAKE_BUILD_TYPE"))
  1059. {
  1060. configs.push_back(buildType);
  1061. }
  1062. for(std::vector<std::string>::const_iterator ci = configs.begin();
  1063. ci != configs.end(); ++ci)
  1064. {
  1065. std::string defPropName = "COMPILE_DEFINITIONS_";
  1066. defPropName += cmSystemTools::UpperCase(*ci);
  1067. this->SetProperty(defPropName.c_str(),
  1068. parent->GetProperty(defPropName.c_str()));
  1069. }
  1070. }
  1071. // link libraries
  1072. this->LinkLibraries = parent->LinkLibraries;
  1073. // link directories
  1074. this->LinkDirectories = parent->LinkDirectories;
  1075. // the initial project name
  1076. this->ProjectName = parent->ProjectName;
  1077. // Copy include regular expressions.
  1078. this->IncludeFileRegularExpression = parent->IncludeFileRegularExpression;
  1079. this->ComplainFileRegularExpression = parent->ComplainFileRegularExpression;
  1080. // Imported targets.
  1081. this->ImportedTargets = parent->ImportedTargets;
  1082. }
  1083. void cmMakefile::ConfigureSubDirectory(cmLocalGenerator *lg2)
  1084. {
  1085. // copy our variables from the child makefile
  1086. lg2->GetMakefile()->InitializeFromParent();
  1087. lg2->GetMakefile()->MakeStartDirectoriesCurrent();
  1088. if (this->GetCMakeInstance()->GetDebugOutput())
  1089. {
  1090. std::string msg=" Entering ";
  1091. msg += lg2->GetMakefile()->GetCurrentDirectory();
  1092. cmSystemTools::Message(msg.c_str());
  1093. }
  1094. // finally configure the subdir
  1095. lg2->Configure();
  1096. if (this->GetCMakeInstance()->GetDebugOutput())
  1097. {
  1098. std::string msg=" Returning to ";
  1099. msg += this->GetCurrentDirectory();
  1100. cmSystemTools::Message(msg.c_str());
  1101. }
  1102. }
  1103. void cmMakefile::AddSubDirectory(const char* sub,
  1104. bool excludeFromAll, bool preorder)
  1105. {
  1106. // the source path must be made full if it isn't already
  1107. std::string srcPath = sub;
  1108. if (!cmSystemTools::FileIsFullPath(srcPath.c_str()))
  1109. {
  1110. srcPath = this->GetCurrentDirectory();
  1111. srcPath += "/";
  1112. srcPath += sub;
  1113. }
  1114. // binary path must be made full if it isn't already
  1115. std::string binPath = sub;
  1116. if (!cmSystemTools::FileIsFullPath(binPath.c_str()))
  1117. {
  1118. binPath = this->GetCurrentOutputDirectory();
  1119. binPath += "/";
  1120. binPath += sub;
  1121. }
  1122. this->AddSubDirectory(srcPath.c_str(), binPath.c_str(),
  1123. excludeFromAll, preorder, false);
  1124. }
  1125. void cmMakefile::AddSubDirectory(const char* srcPath, const char *binPath,
  1126. bool excludeFromAll, bool preorder,
  1127. bool immediate)
  1128. {
  1129. std::vector<cmLocalGenerator *>& children =
  1130. this->LocalGenerator->GetChildren();
  1131. // has this directory already been added? If so error
  1132. unsigned int i;
  1133. for (i = 0; i < children.size(); ++i)
  1134. {
  1135. if (srcPath == children[i]->GetMakefile()->GetStartDirectory())
  1136. {
  1137. cmSystemTools::Error
  1138. ("Attempt to add subdirectory multiple times for directory.\n",
  1139. srcPath);
  1140. return;
  1141. }
  1142. }
  1143. // create a new local generator and set its parent
  1144. cmLocalGenerator *lg2 =
  1145. this->LocalGenerator->GetGlobalGenerator()->CreateLocalGenerator();
  1146. lg2->SetParent(this->LocalGenerator);
  1147. this->LocalGenerator->GetGlobalGenerator()->AddLocalGenerator(lg2);
  1148. // set the subdirs start dirs
  1149. lg2->GetMakefile()->SetStartDirectory(srcPath);
  1150. lg2->GetMakefile()->SetStartOutputDirectory(binPath);
  1151. if(excludeFromAll)
  1152. {
  1153. lg2->GetMakefile()->SetProperty("EXCLUDE_FROM_ALL", "TRUE");
  1154. }
  1155. lg2->GetMakefile()->SetPreOrder(preorder);
  1156. if (immediate)
  1157. {
  1158. this->ConfigureSubDirectory(lg2);
  1159. }
  1160. }
  1161. void cmMakefile::AddIncludeDirectory(const char* inc, bool before)
  1162. {
  1163. // if there is a newline then break it into multiple arguments
  1164. if (!inc)
  1165. {
  1166. return;
  1167. }
  1168. // Don't add an include directory that is already present. Yes,
  1169. // this linear search results in n^2 behavior, but n won't be
  1170. // getting much bigger than 20. We cannot use a set because of
  1171. // order dependency of the include path.
  1172. std::vector<std::string>::iterator i =
  1173. std::find(this->IncludeDirectories.begin(),
  1174. this->IncludeDirectories.end(), inc);
  1175. if(i == this->IncludeDirectories.end())
  1176. {
  1177. if (before)
  1178. {
  1179. // WARNING: this *is* expensive (linear time) since it's a vector
  1180. this->IncludeDirectories.insert(this->IncludeDirectories.begin(), inc);
  1181. }
  1182. else
  1183. {
  1184. this->IncludeDirectories.push_back(inc);
  1185. }
  1186. }
  1187. else
  1188. {
  1189. if(before)
  1190. {
  1191. // if this before and already in the path then remove it
  1192. this->IncludeDirectories.erase(i);
  1193. // WARNING: this *is* expensive (linear time) since it's a vector
  1194. this->IncludeDirectories.insert(this->IncludeDirectories.begin(), inc);
  1195. }
  1196. }
  1197. }
  1198. //----------------------------------------------------------------------------
  1199. void cmMakefile::AddSystemIncludeDirectory(const char* dir)
  1200. {
  1201. this->SystemIncludeDirectories.insert(dir);
  1202. }
  1203. //----------------------------------------------------------------------------
  1204. bool cmMakefile::IsSystemIncludeDirectory(const char* dir)
  1205. {
  1206. return (this->SystemIncludeDirectories.find(dir) !=
  1207. this->SystemIncludeDirectories.end());
  1208. }
  1209. void cmMakefile::AddDefinition(const char* name, const char* value)
  1210. {
  1211. if (!value )
  1212. {
  1213. return;
  1214. }
  1215. #ifdef CMAKE_STRICT
  1216. if (this->GetCMakeInstance())
  1217. {
  1218. this->GetCMakeInstance()->
  1219. RecordPropertyAccess(name,cmProperty::VARIABLE);
  1220. }
  1221. #endif
  1222. this->TemporaryDefinitionKey = name;
  1223. this->DefinitionStack.back()[this->TemporaryDefinitionKey] = value;
  1224. #ifdef CMAKE_BUILD_WITH_CMAKE
  1225. cmVariableWatch* vv = this->GetVariableWatch();
  1226. if ( vv )
  1227. {
  1228. vv->VariableAccessed(this->TemporaryDefinitionKey,
  1229. cmVariableWatch::VARIABLE_MODIFIED_ACCESS,
  1230. value,
  1231. this);
  1232. }
  1233. #endif
  1234. }
  1235. void cmMakefile::AddCacheDefinition(const char* name, const char* value,
  1236. const char* doc,
  1237. cmCacheManager::CacheEntryType type)
  1238. {
  1239. const char* val = value;
  1240. cmCacheManager::CacheIterator it =
  1241. this->GetCacheManager()->GetCacheIterator(name);
  1242. if(!it.IsAtEnd() && (it.GetType() == cmCacheManager::UNINITIALIZED) &&
  1243. it.Initialized())
  1244. {
  1245. val = it.GetValue();
  1246. if ( type == cmCacheManager::PATH || type == cmCacheManager::FILEPATH )
  1247. {
  1248. std::vector<std::string>::size_type cc;
  1249. std::vector<std::string> files;
  1250. std::string nvalue = "";
  1251. cmSystemTools::ExpandListArgument(val, files);
  1252. for ( cc = 0; cc < files.size(); cc ++ )
  1253. {
  1254. files[cc] = cmSystemTools::CollapseFullPath(files[cc].c_str());
  1255. if ( cc > 0 )
  1256. {
  1257. nvalue += ";";
  1258. }
  1259. nvalue += files[cc];
  1260. }
  1261. this->GetCacheManager()->AddCacheEntry(name, nvalue.c_str(), doc, type);
  1262. val = it.GetValue();
  1263. }
  1264. }
  1265. this->GetCacheManager()->AddCacheEntry(name, val, doc, type);
  1266. // if there was a definition then remove it
  1267. this->DefinitionStack.back().erase( DefinitionMap::key_type(name));
  1268. }
  1269. void cmMakefile::AddDefinition(const char* name, bool value)
  1270. {
  1271. if(value)
  1272. {
  1273. this->DefinitionStack.back()
  1274. .erase( DefinitionMap::key_type(name));
  1275. this->DefinitionStack.back()
  1276. .insert(DefinitionMap::value_type(name, "ON"));
  1277. }
  1278. else
  1279. {
  1280. this->DefinitionStack.back()
  1281. .erase( DefinitionMap::key_type(name));
  1282. this->DefinitionStack.back()
  1283. .insert(DefinitionMap::value_type(name, "OFF"));
  1284. }
  1285. #ifdef CMAKE_BUILD_WITH_CMAKE
  1286. cmVariableWatch* vv = this->GetVariableWatch();
  1287. if ( vv )
  1288. {
  1289. vv->VariableAccessed(name, cmVariableWatch::VARIABLE_MODIFIED_ACCESS,
  1290. value?"ON":"OFF", this);
  1291. }
  1292. #endif
  1293. }
  1294. void cmMakefile::AddCacheDefinition(const char* name,
  1295. bool value,
  1296. const char* doc)
  1297. {
  1298. bool val = value;
  1299. cmCacheManager::CacheIterator it =
  1300. this->GetCacheManager()->GetCacheIterator(name);
  1301. if(!it.IsAtEnd() && (it.GetType() == cmCacheManager::UNINITIALIZED) &&
  1302. it.Initialized())
  1303. {
  1304. val = it.GetValueAsBool();
  1305. }
  1306. this->GetCacheManager()->AddCacheEntry(name, val, doc);
  1307. this->AddDefinition(name, val);
  1308. }
  1309. void cmMakefile::RemoveDefinition(const char* name)
  1310. {
  1311. this->DefinitionStack.back().erase(DefinitionMap::key_type(name));
  1312. #ifdef CMAKE_BUILD_WITH_CMAKE
  1313. cmVariableWatch* vv = this->GetVariableWatch();
  1314. if ( vv )
  1315. {
  1316. vv->VariableAccessed(name, cmVariableWatch::VARIABLE_REMOVED_ACCESS,
  1317. 0, this);
  1318. }
  1319. #endif
  1320. }
  1321. void cmMakefile::SetProjectName(const char* p)
  1322. {
  1323. this->ProjectName = p;
  1324. }
  1325. void cmMakefile::AddGlobalLinkInformation(const char* name, cmTarget& target)
  1326. {
  1327. // for these targets do not add anything
  1328. switch(target.GetType())
  1329. {
  1330. case cmTarget::UTILITY:
  1331. case cmTarget::GLOBAL_TARGET:
  1332. return;
  1333. default:;
  1334. }
  1335. std::vector<std::string>::iterator j;
  1336. for(j = this->LinkDirectories.begin();
  1337. j != this->LinkDirectories.end(); ++j)
  1338. {
  1339. target.AddLinkDirectory(j->c_str());
  1340. }
  1341. target.MergeLinkLibraries( *this, name, this->LinkLibraries );
  1342. }
  1343. void cmMakefile::AddLibrary(const char* lname, cmTarget::TargetType type,
  1344. const std::vector<std::string> &srcs,
  1345. bool excludeFromAll)
  1346. {
  1347. // wrong type ? default to STATIC
  1348. if ( (type != cmTarget::STATIC_LIBRARY)
  1349. && (type != cmTarget::SHARED_LIBRARY)
  1350. && (type != cmTarget::MODULE_LIBRARY))
  1351. {
  1352. type = cmTarget::STATIC_LIBRARY;
  1353. }
  1354. cmTarget* target = this->AddNewTarget(type, lname);
  1355. // Clear its dependencies. Otherwise, dependencies might persist
  1356. // over changes in CMakeLists.txt, making the information stale and
  1357. // hence useless.
  1358. target->ClearDependencyInformation( *this, lname );
  1359. if(excludeFromAll)
  1360. {
  1361. target->SetProperty("EXCLUDE_FROM_ALL", "TRUE");
  1362. }
  1363. target->AddSources(srcs);
  1364. this->AddGlobalLinkInformation(lname, *target);
  1365. }
  1366. cmTarget* cmMakefile::AddExecutable(const char *exeName,
  1367. const std::vector<std::string> &srcs,
  1368. bool excludeFromAll)
  1369. {
  1370. cmTarget* target = this->AddNewTarget(cmTarget::EXECUTABLE, exeName);
  1371. if(excludeFromAll)
  1372. {
  1373. target->SetProperty("EXCLUDE_FROM_ALL", "TRUE");
  1374. }
  1375. target->AddSources(srcs);
  1376. this->AddGlobalLinkInformation(exeName, *target);
  1377. return target;
  1378. }
  1379. //----------------------------------------------------------------------------
  1380. cmTarget*
  1381. cmMakefile::AddNewTarget(cmTarget::TargetType type, const char* name)
  1382. {
  1383. cmTargets::iterator it;
  1384. cmTarget target;
  1385. target.SetType(type, name);
  1386. target.SetMakefile(this);
  1387. it=this->Targets.insert(
  1388. cmTargets::value_type(target.GetName(), target)).first;
  1389. this->LocalGenerator->GetGlobalGenerator()->AddTarget(*it);
  1390. return &it->second;
  1391. }
  1392. cmSourceFile *cmMakefile::GetSourceFileWithOutput(const char *cname)
  1393. {
  1394. std::string name = cname;
  1395. std::string out;
  1396. // look through all the source files that have custom commands
  1397. // and see if the custom command has the passed source file as an output
  1398. // keep in mind the possible .rule extension that may be tacked on
  1399. for(std::vector<cmSourceFile*>::const_iterator i =
  1400. this->SourceFiles.begin(); i != this->SourceFiles.end(); ++i)
  1401. {
  1402. // does this source file have a custom command?
  1403. if ((*i)->GetCustomCommand())
  1404. {
  1405. // is the output of the custom command match the source files name
  1406. const std::vector<std::string>& outputs =
  1407. (*i)->GetCustomCommand()->GetOutputs();
  1408. for(std::vector<std::string>::const_iterator o = outputs.begin();
  1409. o != outputs.end(); ++o)
  1410. {
  1411. out = *o;
  1412. std::string::size_type pos = out.rfind(name);
  1413. // If the output matches exactly
  1414. if (pos != out.npos &&
  1415. pos == out.size() - name.size() &&
  1416. (pos ==0 || out[pos-1] == '/'))
  1417. {
  1418. return *i;
  1419. }
  1420. }
  1421. }
  1422. }
  1423. // otherwise return NULL
  1424. return 0;
  1425. }
  1426. #if defined(CMAKE_BUILD_WITH_CMAKE)
  1427. cmSourceGroup* cmMakefile::GetSourceGroup(const std::vector<std::string>&name)
  1428. {
  1429. cmSourceGroup* sg = 0;
  1430. // first look for source group starting with the same as the one we wants
  1431. for (std::vector<cmSourceGroup>::iterator sgIt = this->SourceGroups.begin();
  1432. sgIt != this->SourceGroups.end(); ++sgIt)
  1433. {
  1434. std::string sgName = sgIt->GetName();
  1435. if(sgName == name[0])
  1436. {
  1437. sg = &(*sgIt);
  1438. break;
  1439. }
  1440. }
  1441. if(sg != 0)
  1442. {
  1443. // iterate through its children to find match source group
  1444. for(unsigned int i=1; i<name.size(); ++i)
  1445. {
  1446. sg = sg->lookupChild(name[i].c_str());
  1447. if(sg == 0)
  1448. {
  1449. break;
  1450. }
  1451. }
  1452. }
  1453. return sg;
  1454. }
  1455. void cmMakefile::AddSourceGroup(const char* name,
  1456. const char* regex)
  1457. {
  1458. if (name)
  1459. {
  1460. std::vector<std::string> nameVector;
  1461. nameVector.push_back(name);
  1462. AddSourceGroup(nameVector, regex);
  1463. }
  1464. }
  1465. void cmMakefile::AddSourceGroup(const std::vector<std::string>& name,
  1466. const char* regex)
  1467. {
  1468. cmSourceGroup* sg = 0;
  1469. std::vector<std::string> currentName;
  1470. int i = 0;
  1471. const int lastElement = static_cast<int>(name.size()-1);
  1472. for(i=lastElement; i>=0; --i)
  1473. {
  1474. currentName.assign(name.begin(), name.begin()+i+1);
  1475. sg = this->GetSourceGroup(currentName);
  1476. if(sg != 0)
  1477. {
  1478. break;
  1479. }
  1480. }
  1481. // i now contains the index of the last found component
  1482. if(i==lastElement)
  1483. {
  1484. // group already exists, replace its regular expression
  1485. if ( regex )
  1486. {
  1487. // We only want to set the regular expression. If there are already
  1488. // source files in the group, we don't want to remove them.
  1489. sg->SetGroupRegex(regex);
  1490. }
  1491. return;
  1492. }
  1493. else if(i==-1)
  1494. {
  1495. // group does not exists nor belong to any existing group
  1496. // add its first component
  1497. this->SourceGroups.push_back(cmSourceGroup(name[0].c_str(), regex));
  1498. sg = this->GetSourceGroup(currentName);
  1499. i = 0; // last component found
  1500. }
  1501. // build the whole source group path
  1502. for(++i; i<=lastElement; ++i)
  1503. {
  1504. sg->AddChild(cmSourceGroup(name[i].c_str(), 0));
  1505. sg = sg->lookupChild(name[i].c_str());
  1506. }
  1507. sg->SetGroupRegex(regex);
  1508. }
  1509. #endif
  1510. void cmMakefile::AddExtraDirectory(const char* dir)
  1511. {
  1512. this->AuxSourceDirectories.push_back(dir);
  1513. }
  1514. // expance CMAKE_BINARY_DIR and CMAKE_SOURCE_DIR in the
  1515. // include and library directories.
  1516. void cmMakefile::ExpandVariables()
  1517. {
  1518. // Now expand variables in the include and link strings
  1519. for(std::vector<std::string>::iterator d = this->IncludeDirectories.begin();
  1520. d != this->IncludeDirectories.end(); ++d)
  1521. {
  1522. this->ExpandVariablesInString(*d, true, true);
  1523. }
  1524. for(std::vector<std::string>::iterator d = this->LinkDirectories.begin();
  1525. d != this->LinkDirectories.end(); ++d)
  1526. {
  1527. this->ExpandVariablesInString(*d, true, true);
  1528. }
  1529. for(cmTarget::LinkLibraryVectorType::iterator l =
  1530. this->LinkLibraries.begin();
  1531. l != this->LinkLibraries.end(); ++l)
  1532. {
  1533. this->ExpandVariablesInString(l->first, true, true);
  1534. }
  1535. }
  1536. bool cmMakefile::IsOn(const char* name) const
  1537. {
  1538. const char* value = this->GetDefinition(name);
  1539. return cmSystemTools::IsOn(value);
  1540. }
  1541. bool cmMakefile::IsSet(const char* name) const
  1542. {
  1543. const char* value = this->GetDefinition(name);
  1544. if ( !value )
  1545. {
  1546. return false;
  1547. }
  1548. if ( ! *value )
  1549. {
  1550. return false;
  1551. }
  1552. if ( cmSystemTools::IsNOTFOUND(value) )
  1553. {
  1554. return false;
  1555. }
  1556. return true;
  1557. }
  1558. bool cmMakefile::CanIWriteThisFile(const char* fileName)
  1559. {
  1560. if ( !this->IsOn("CMAKE_DISABLE_SOURCE_CHANGES") )
  1561. {
  1562. return true;
  1563. }
  1564. // If we are doing an in-source build, than the test will always fail
  1565. if ( cmSystemTools::SameFile(this->GetHomeDirectory(),
  1566. this->GetHomeOutputDirectory()) )
  1567. {
  1568. if ( this->IsOn("CMAKE_DISABLE_IN_SOURCE_BUILD") )
  1569. {
  1570. return false;
  1571. }
  1572. return true;
  1573. }
  1574. // Check if this is subdirectory of the source tree but not a
  1575. // subdirectory of a build tree
  1576. if ( cmSystemTools::IsSubDirectory(fileName,
  1577. this->GetHomeDirectory()) &&
  1578. !cmSystemTools::IsSubDirectory(fileName,
  1579. this->GetHomeOutputDirectory()) )
  1580. {
  1581. return false;
  1582. }
  1583. return true;
  1584. }
  1585. const char* cmMakefile::GetRequiredDefinition(const char* name) const
  1586. {
  1587. const char* ret = this->GetDefinition(name);
  1588. if(!ret)
  1589. {
  1590. cmSystemTools::Error("Error required internal CMake variable not "
  1591. "set, cmake may be not be built correctly.\n",
  1592. "Missing variable is:\n",
  1593. name);
  1594. return "";
  1595. }
  1596. return ret;
  1597. }
  1598. bool cmMakefile::IsDefinitionSet(const char* name) const
  1599. {
  1600. const char* def = 0;
  1601. DefinitionMap::const_iterator pos =
  1602. this->DefinitionStack.back().find(name);
  1603. if(pos != this->DefinitionStack.back().end())
  1604. {
  1605. def = (*pos).second.c_str();
  1606. }
  1607. else
  1608. {
  1609. def = this->GetCacheManager()->GetCacheValue(name);
  1610. }
  1611. #ifdef CMAKE_BUILD_WITH_CMAKE
  1612. if(cmVariableWatch* vv = this->GetVariableWatch())
  1613. {
  1614. if(!def)
  1615. {
  1616. vv->VariableAccessed
  1617. (name, cmVariableWatch::UNKNOWN_VARIABLE_DEFINED_ACCESS,
  1618. def, this);
  1619. }
  1620. }
  1621. #endif
  1622. return def?true:false;
  1623. }
  1624. const char* cmMakefile::GetDefinition(const char* name) const
  1625. {
  1626. #ifdef CMAKE_STRICT
  1627. if (this->GetCMakeInstance())
  1628. {
  1629. this->GetCMakeInstance()->
  1630. RecordPropertyAccess(name,cmProperty::VARIABLE);
  1631. }
  1632. #endif
  1633. const char* def = 0;
  1634. DefinitionMap::const_iterator pos =
  1635. this->DefinitionStack.back().find(name);
  1636. if(pos != this->DefinitionStack.back().end())
  1637. {
  1638. def = (*pos).second.c_str();
  1639. }
  1640. else
  1641. {
  1642. def = this->GetCacheManager()->GetCacheValue(name);
  1643. }
  1644. #ifdef CMAKE_BUILD_WITH_CMAKE
  1645. cmVariableWatch* vv = this->GetVariableWatch();
  1646. if ( vv )
  1647. {
  1648. if ( def )
  1649. {
  1650. vv->VariableAccessed(name, cmVariableWatch::VARIABLE_READ_ACCESS,
  1651. def, this);
  1652. }
  1653. else
  1654. {
  1655. // are unknown access allowed
  1656. DefinitionMap::const_iterator pos2 =
  1657. this->DefinitionStack.back()
  1658. .find("CMAKE_ALLOW_UNKNOWN_VARIABLE_READ_ACCESS");
  1659. if (pos2 != this->DefinitionStack.back().end() &&
  1660. cmSystemTools::IsOn((*pos2).second.c_str()))
  1661. {
  1662. vv->VariableAccessed(name,
  1663. cmVariableWatch::ALLOWED_UNKNOWN_VARIABLE_READ_ACCESS, def, this);
  1664. }
  1665. else
  1666. {
  1667. vv->VariableAccessed(name,
  1668. cmVariableWatch::UNKNOWN_VARIABLE_READ_ACCESS, def, this);
  1669. }
  1670. }
  1671. }
  1672. #endif
  1673. return def;
  1674. }
  1675. const char* cmMakefile::GetSafeDefinition(const char* def) const
  1676. {
  1677. const char* ret = this->GetDefinition(def);
  1678. if(!ret)
  1679. {
  1680. return "";
  1681. }
  1682. return ret;
  1683. }
  1684. std::vector<std::string> cmMakefile
  1685. ::GetDefinitions(int cacheonly /* = 0 */) const
  1686. {
  1687. std::map<cmStdString, int> definitions;
  1688. if ( !cacheonly )
  1689. {
  1690. DefinitionMap::const_iterator it;
  1691. for ( it = this->DefinitionStack.back().begin();
  1692. it != this->DefinitionStack.back().end(); it ++ )
  1693. {
  1694. definitions[it->first] = 1;
  1695. }
  1696. }
  1697. cmCacheManager::CacheIterator cit =
  1698. this->GetCacheManager()->GetCacheIterator();
  1699. for ( cit.Begin(); !cit.IsAtEnd(); cit.Next() )
  1700. {
  1701. definitions[cit.GetName()] = 1;
  1702. }
  1703. std::vector<std::string> res;
  1704. std::map<cmStdString, int>::iterator fit;
  1705. for ( fit = definitions.begin(); fit != definitions.end(); fit ++ )
  1706. {
  1707. res.push_back(fit->first);
  1708. }
  1709. return res;
  1710. }
  1711. const char *cmMakefile::ExpandVariablesInString(std::string& source)
  1712. {
  1713. return this->ExpandVariablesInString(source, false, false);
  1714. }
  1715. const char *cmMakefile::ExpandVariablesInString(std::string& source,
  1716. bool escapeQuotes,
  1717. bool noEscapes,
  1718. bool atOnly,
  1719. const char* filename,
  1720. long line,
  1721. bool removeEmpty,
  1722. bool replaceAt)
  1723. {
  1724. if ( source.empty() || source.find_first_of("$@\\") == source.npos)
  1725. {
  1726. return source.c_str();
  1727. }
  1728. // Special-case the @ONLY mode.
  1729. if(atOnly)
  1730. {
  1731. if(!noEscapes || !removeEmpty || !replaceAt)
  1732. {
  1733. // This case should never be called. At-only is for
  1734. // configure-file/string which always does no escapes.
  1735. abort();
  1736. }
  1737. // Store an original copy of the input.
  1738. std::string input = source;
  1739. // Start with empty output.
  1740. source = "";
  1741. // Look for one @VAR@ at a time.
  1742. const char* in = input.c_str();
  1743. while(this->cmAtVarRegex.find(in))
  1744. {
  1745. // Get the range of the string to replace.
  1746. const char* first = in + this->cmAtVarRegex.start();
  1747. const char* last = in + this->cmAtVarRegex.end();
  1748. // Store the unchanged part of the string now.
  1749. source.append(in, first-in);
  1750. // Lookup the definition of VAR.
  1751. std::string var(first+1, last-first-2);
  1752. if(const char* val = this->GetDefinition(var.c_str()))
  1753. {
  1754. // Store the value in the output escaping as requested.
  1755. if(escapeQuotes)
  1756. {
  1757. source.append(cmSystemTools::EscapeQuotes(val));
  1758. }
  1759. else
  1760. {
  1761. source.append(val);
  1762. }
  1763. }
  1764. // Continue looking for @VAR@ further along the string.
  1765. in = last;
  1766. }
  1767. // Append the rest of the unchanged part of the string.
  1768. source.append(in);
  1769. return source.c_str();
  1770. }
  1771. // This method replaces ${VAR} and @VAR@ where VAR is looked up
  1772. // with GetDefinition(), if not found in the map, nothing is expanded.
  1773. // It also supports the $ENV{VAR} syntax where VAR is looked up in
  1774. // the current environment variables.
  1775. cmCommandArgumentParserHelper parser;
  1776. parser.SetMakefile(this);
  1777. parser.SetLineFile(line, filename);
  1778. parser.SetEscapeQuotes(escapeQuotes);
  1779. parser.SetNoEscapeMode(noEscapes);
  1780. parser.SetReplaceAtSyntax(replaceAt);
  1781. parser.SetRemoveEmpty(removeEmpty);
  1782. int res = parser.ParseString(source.c_str(), 0);
  1783. if ( res )
  1784. {
  1785. source = parser.GetResult();
  1786. }
  1787. else
  1788. {
  1789. cmOStringStream error;
  1790. error << "Syntax error in cmake code at\n"
  1791. << (filename?filename:"(no filename given)")
  1792. << ":" << line << ":\n"
  1793. << parser.GetError() << ", when parsing string \""
  1794. << source.c_str() << "\"";
  1795. const char* versionValue
  1796. = this->GetDefinition("CMAKE_BACKWARDS_COMPATIBILITY");
  1797. int major = 0;
  1798. int minor = 0;
  1799. if ( versionValue )
  1800. {
  1801. sscanf(versionValue, "%d.%d", &major, &minor);
  1802. }
  1803. if ( major < 2 || major == 2 && minor < 1 )
  1804. {
  1805. cmSystemTools::Error(error.str().c_str());
  1806. cmSystemTools::SetFatalErrorOccured();
  1807. return source.c_str();
  1808. }
  1809. else
  1810. {
  1811. cmSystemTools::Message(error.str().c_str());
  1812. }
  1813. }
  1814. return source.c_str();
  1815. }
  1816. void cmMakefile::RemoveVariablesInString(std::string& source,
  1817. bool atOnly) const
  1818. {
  1819. if(!atOnly)
  1820. {
  1821. cmsys::RegularExpression var("(\\${[A-Za-z_0-9]*})");
  1822. while (var.find(source))
  1823. {
  1824. source.erase(var.start(),var.end() - var.start());
  1825. }
  1826. }
  1827. if(!atOnly)
  1828. {
  1829. cmsys::RegularExpression varb("(\\$ENV{[A-Za-z_0-9]*})");
  1830. while (varb.find(source))
  1831. {
  1832. source.erase(varb.start(),varb.end() - varb.start());
  1833. }
  1834. }
  1835. cmsys::RegularExpression var2("(@[A-Za-z_0-9]*@)");
  1836. while (var2.find(source))
  1837. {
  1838. source.erase(var2.start(),var2.end() - var2.start());
  1839. }
  1840. }
  1841. /**
  1842. * Add the default definitions to the makefile. These values must not
  1843. * be dependent on anything that isn't known when this cmMakefile instance
  1844. * is constructed.
  1845. */
  1846. void cmMakefile::AddDefaultDefinitions()
  1847. {
  1848. /* Up to CMake 2.4 here only WIN32, UNIX and APPLE were set.
  1849. With CMake must separate between target and host platform. In most cases
  1850. the tests for WIN32, UNIX and APPLE will be for the target system, so an
  1851. additional set of variables for the host system is required ->
  1852. CMAKE_HOST_WIN32, CMAKE_HOST_UNIX, CMAKE_HOST_APPLE.
  1853. WIN32, UNIX and APPLE are now set in the platform files in
  1854. Modules/Platforms/.
  1855. To keep cmake scripts (-P) and custom language and compiler modules
  1856. working, these variables are still also set here in this place, but they
  1857. will be reset in CMakeSystemSpecificInformation.cmake before the platform
  1858. files are executed. */
  1859. #if defined(_WIN32) || defined(__CYGWIN__)
  1860. this->AddDefinition("WIN32", "1");
  1861. this->AddDefinition("CMAKE_HOST_WIN32", "1");
  1862. #else
  1863. this->AddDefinition("UNIX", "1");
  1864. this->AddDefinition("CMAKE_HOST_UNIX", "1");
  1865. #endif
  1866. // Cygwin is more like unix so enable the unix commands
  1867. #if defined(__CYGWIN__)
  1868. this->AddDefinition("UNIX", "1");
  1869. this->AddDefinition("CMAKE_HOST_UNIX", "1");
  1870. #endif
  1871. #if defined(__APPLE__)
  1872. this->AddDefinition("APPLE", "1");
  1873. this->AddDefinition("CMAKE_HOST_APPLE", "1");
  1874. #endif
  1875. char temp[1024];
  1876. sprintf(temp, "%d", cmVersion::GetMinorVersion());
  1877. this->AddDefinition("CMAKE_MINOR_VERSION", temp);
  1878. sprintf(temp, "%d", cmVersion::GetMajorVersion());
  1879. this->AddDefinition("CMAKE_MAJOR_VERSION", temp);
  1880. sprintf(temp, "%d", cmVersion::GetPatchVersion());
  1881. this->AddDefinition("CMAKE_PATCH_VERSION", temp);
  1882. this->AddDefinition("CMAKE_FILES_DIRECTORY",
  1883. cmake::GetCMakeFilesDirectory());
  1884. }
  1885. #if defined(CMAKE_BUILD_WITH_CMAKE)
  1886. /**
  1887. * Find a source group whose regular expression matches the filename
  1888. * part of the given source name. Search backward through the list of
  1889. * source groups, and take the first matching group found. This way
  1890. * non-inherited SOURCE_GROUP commands will have precedence over
  1891. * inherited ones.
  1892. */
  1893. cmSourceGroup&
  1894. cmMakefile::FindSourceGroup(const char* source,
  1895. std::vector<cmSourceGroup> &groups)
  1896. {
  1897. // First search for a group that lists the file explicitly.
  1898. for(std::vector<cmSourceGroup>::reverse_iterator sg = groups.rbegin();
  1899. sg != groups.rend(); ++sg)
  1900. {
  1901. cmSourceGroup *result = sg->MatchChildrenFiles(source);
  1902. if(result)
  1903. {
  1904. return *result;
  1905. }
  1906. }
  1907. // Now search for a group whose regex matches the file.
  1908. for(std::vector<cmSourceGroup>::reverse_iterator sg = groups.rbegin();
  1909. sg != groups.rend(); ++sg)
  1910. {
  1911. cmSourceGroup *result = sg->MatchChildrenRegex(source);
  1912. if(result)
  1913. {
  1914. return *result;
  1915. }
  1916. }
  1917. // Shouldn't get here, but just in case, return the default group.
  1918. return groups.front();
  1919. }
  1920. #endif
  1921. bool cmMakefile::IsFunctionBlocked(const cmListFileFunction& lff,
  1922. cmExecutionStatus &status)
  1923. {
  1924. // if there are no blockers get out of here
  1925. if (this->FunctionBlockers.begin() == this->FunctionBlockers.end())
  1926. {
  1927. return false;
  1928. }
  1929. // loop over all function blockers to see if any block this command
  1930. // evaluate in reverse, this is critical for balanced IF statements etc
  1931. std::list<cmFunctionBlocker *>::reverse_iterator pos;
  1932. for (pos = this->FunctionBlockers.rbegin();
  1933. pos != this->FunctionBlockers.rend(); ++pos)
  1934. {
  1935. if((*pos)->IsFunctionBlocked(lff, *this, status))
  1936. {
  1937. return true;
  1938. }
  1939. }
  1940. return false;
  1941. }
  1942. void cmMakefile::ExpandArguments(
  1943. std::vector<cmListFileArgument> const& inArgs,
  1944. std::vector<std::string>& outArgs)
  1945. {
  1946. std::vector<cmListFileArgument>::const_iterator i;
  1947. std::string value;
  1948. outArgs.reserve(inArgs.size());
  1949. for(i = inArgs.begin(); i != inArgs.end(); ++i)
  1950. {
  1951. // Expand the variables in the argument.
  1952. value = i->Value;
  1953. this->ExpandVariablesInString(value, false, false, false,
  1954. i->FilePath, i->Line,
  1955. false, true);
  1956. // If the argument is quoted, it should be one argument.
  1957. // Otherwise, it may be a list of arguments.
  1958. if(i->Quoted)
  1959. {
  1960. outArgs.push_back(value);
  1961. }
  1962. else
  1963. {
  1964. cmSystemTools::ExpandListArgument(value, outArgs);
  1965. }
  1966. }
  1967. }
  1968. void cmMakefile::RemoveFunctionBlocker(const cmListFileFunction& lff)
  1969. {
  1970. // loop over all function blockers to see if any block this command
  1971. std::list<cmFunctionBlocker *>::reverse_iterator pos;
  1972. for (pos = this->FunctionBlockers.rbegin();
  1973. pos != this->FunctionBlockers.rend(); ++pos)
  1974. {
  1975. if ((*pos)->ShouldRemove(lff, *this))
  1976. {
  1977. cmFunctionBlocker* b = *pos;
  1978. this->FunctionBlockers.remove(b);
  1979. delete b;
  1980. break;
  1981. }
  1982. }
  1983. return;
  1984. }
  1985. void cmMakefile::SetHomeDirectory(const char* dir)
  1986. {
  1987. this->cmHomeDirectory = dir;
  1988. cmSystemTools::ConvertToUnixSlashes(this->cmHomeDirectory);
  1989. this->AddDefinition("CMAKE_SOURCE_DIR", this->GetHomeDirectory());
  1990. if ( !this->GetDefinition("CMAKE_CURRENT_SOURCE_DIR") )
  1991. {
  1992. this->AddDefinition("CMAKE_CURRENT_SOURCE_DIR", this->GetHomeDirectory());
  1993. }
  1994. }
  1995. void cmMakefile::SetHomeOutputDirectory(const char* lib)
  1996. {
  1997. this->HomeOutputDirectory = lib;
  1998. cmSystemTools::ConvertToUnixSlashes(this->HomeOutputDirectory);
  1999. this->AddDefinition("CMAKE_BINARY_DIR", this->GetHomeOutputDirectory());
  2000. if ( !this->GetDefinition("CMAKE_CURRENT_BINARY_DIR") )
  2001. {
  2002. this->AddDefinition("CMAKE_CURRENT_BINARY_DIR",
  2003. this->GetHomeOutputDirectory());
  2004. }
  2005. }
  2006. /**
  2007. * Register the given cmData instance with its own name.
  2008. */
  2009. void cmMakefile::RegisterData(cmData* data)
  2010. {
  2011. std::string name = data->GetName();
  2012. DataMapType::const_iterator d = this->DataMap.find(name);
  2013. if((d != this->DataMap.end()) && (d->second != 0) && (d->second != data))
  2014. {
  2015. delete d->second;
  2016. }
  2017. this->DataMap[name] = data;
  2018. }
  2019. /**
  2020. * Register the given cmData instance with the given name. This can be used
  2021. * to register a NULL pointer.
  2022. */
  2023. void cmMakefile::RegisterData(const char* name, cmData* data)
  2024. {
  2025. DataMapType::const_iterator d = this->DataMap.find(name);
  2026. if((d != this->DataMap.end()) && (d->second != 0) && (d->second != data))
  2027. {
  2028. delete d->second;
  2029. }
  2030. this->DataMap[name] = data;
  2031. }
  2032. /**
  2033. * Lookup a cmData instance previously registered with the given name. If
  2034. * the instance cannot be found, return NULL.
  2035. */
  2036. cmData* cmMakefile::LookupData(const char* name) const
  2037. {
  2038. DataMapType::const_iterator d = this->DataMap.find(name);
  2039. if(d != this->DataMap.end())
  2040. {
  2041. return d->second;
  2042. }
  2043. else
  2044. {
  2045. return 0;
  2046. }
  2047. }
  2048. //----------------------------------------------------------------------------
  2049. cmSourceFile* cmMakefile::GetSource(const char* sourceName)
  2050. {
  2051. cmSourceFileLocation sfl(this, sourceName);
  2052. for(std::vector<cmSourceFile*>::const_iterator
  2053. sfi = this->SourceFiles.begin();
  2054. sfi != this->SourceFiles.end(); ++sfi)
  2055. {
  2056. cmSourceFile* sf = *sfi;
  2057. if(sf->Matches(sfl))
  2058. {
  2059. return sf;
  2060. }
  2061. }
  2062. return 0;
  2063. }
  2064. //----------------------------------------------------------------------------
  2065. cmSourceFile* cmMakefile::GetOrCreateSource(const char* sourceName,
  2066. bool generated)
  2067. {
  2068. if(cmSourceFile* esf = this->GetSource(sourceName))
  2069. {
  2070. return esf;
  2071. }
  2072. else
  2073. {
  2074. cmSourceFile* sf = new cmSourceFile(this, sourceName);
  2075. if(generated)
  2076. {
  2077. sf->SetProperty("GENERATED", "1");
  2078. }
  2079. this->SourceFiles.push_back(sf);
  2080. return sf;
  2081. }
  2082. }
  2083. void cmMakefile::EnableLanguage(std::vector<std::string> const & lang,
  2084. bool optional)
  2085. {
  2086. this->AddDefinition("CMAKE_CFG_INTDIR",
  2087. this->LocalGenerator->GetGlobalGenerator()->GetCMakeCFGInitDirectory());
  2088. this->LocalGenerator->GetGlobalGenerator()->EnableLanguage(lang, this,
  2089. optional);
  2090. }
  2091. void cmMakefile::ExpandSourceListArguments(
  2092. std::vector<std::string> const& arguments,
  2093. std::vector<std::string>& newargs, unsigned int /* start */)
  2094. {
  2095. // now expand the args
  2096. unsigned int i;
  2097. for(i = 0; i < arguments.size(); ++i)
  2098. {
  2099. // List expansion will have been done already.
  2100. newargs.push_back(arguments[i]);
  2101. }
  2102. }
  2103. int cmMakefile::TryCompile(const char *srcdir, const char *bindir,
  2104. const char *projectName, const char *targetName,
  2105. const std::vector<std::string> *cmakeArgs,
  2106. std::string *output)
  2107. {
  2108. // does the binary directory exist ? If not create it...
  2109. if (!cmSystemTools::FileIsDirectory(bindir))
  2110. {
  2111. cmSystemTools::MakeDirectory(bindir);
  2112. }
  2113. // change to the tests directory and run cmake
  2114. // use the cmake object instead of calling cmake
  2115. std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
  2116. cmSystemTools::ChangeDirectory(bindir);
  2117. // make sure the same generator is used
  2118. // use this program as the cmake to be run, it should not
  2119. // be run that way but the cmake object requires a vailid path
  2120. std::string cmakeCommand = this->GetDefinition("CMAKE_COMMAND");
  2121. cmake cm;
  2122. cm.SetIsInTryCompile(true);
  2123. cmGlobalGenerator *gg = cm.CreateGlobalGenerator
  2124. (this->LocalGenerator->GetGlobalGenerator()->GetName());
  2125. if (!gg)
  2126. {
  2127. cmSystemTools::Error(
  2128. "Internal CMake error, TryCompile bad GlobalGenerator");
  2129. // return to the original directory
  2130. cmSystemTools::ChangeDirectory(cwd.c_str());
  2131. return 1;
  2132. }
  2133. cm.SetGlobalGenerator(gg);
  2134. // do a configure
  2135. cm.SetHomeDirectory(srcdir);
  2136. cm.SetHomeOutputDirectory(bindir);
  2137. cm.SetStartDirectory(srcdir);
  2138. cm.SetStartOutputDirectory(bindir);
  2139. cm.SetCMakeCommand(cmakeCommand.c_str());
  2140. cm.LoadCache();
  2141. // if cmake args were provided then pass them in
  2142. if (cmakeArgs)
  2143. {
  2144. cm.SetCacheArgs(*cmakeArgs);
  2145. }
  2146. // to save time we pass the EnableLanguage info directly
  2147. gg->EnableLanguagesFromGenerator
  2148. (this->LocalGenerator->GetGlobalGenerator());
  2149. if (cm.Configure() != 0)
  2150. {
  2151. cmSystemTools::Error(
  2152. "Internal CMake error, TryCompile configure of cmake failed");
  2153. // return to the original directory
  2154. cmSystemTools::ChangeDirectory(cwd.c_str());
  2155. return 1;
  2156. }
  2157. if (cm.Generate() != 0)
  2158. {
  2159. cmSystemTools::Error(
  2160. "Internal CMake error, TryCompile generation of cmake failed");
  2161. // return to the original directory
  2162. cmSystemTools::ChangeDirectory(cwd.c_str());
  2163. return 1;
  2164. }
  2165. // finally call the generator to actually build the resulting project
  2166. int ret =
  2167. this->LocalGenerator->GetGlobalGenerator()->TryCompile(srcdir,bindir,
  2168. projectName,
  2169. targetName,
  2170. output,
  2171. this);
  2172. cmSystemTools::ChangeDirectory(cwd.c_str());
  2173. return ret;
  2174. }
  2175. cmake *cmMakefile::GetCMakeInstance() const
  2176. {
  2177. if ( this->LocalGenerator && this->LocalGenerator->GetGlobalGenerator() )
  2178. {
  2179. return this->LocalGenerator->GetGlobalGenerator()->GetCMakeInstance();
  2180. }
  2181. return 0;
  2182. }
  2183. #ifdef CMAKE_BUILD_WITH_CMAKE
  2184. cmVariableWatch *cmMakefile::GetVariableWatch() const
  2185. {
  2186. if ( this->GetCMakeInstance() &&
  2187. this->GetCMakeInstance()->GetVariableWatch() )
  2188. {
  2189. return this->GetCMakeInstance()->GetVariableWatch();
  2190. }
  2191. return 0;
  2192. }
  2193. #endif
  2194. void cmMakefile::AddMacro(const char* name, const char* signature)
  2195. {
  2196. if ( !name || !signature )
  2197. {
  2198. return;
  2199. }
  2200. this->MacrosMap[name] = signature;
  2201. }
  2202. void cmMakefile::GetListOfMacros(std::string& macros)
  2203. {
  2204. StringStringMap::iterator it;
  2205. macros = "";
  2206. int cc = 0;
  2207. for ( it = this->MacrosMap.begin(); it != this->MacrosMap.end(); ++it )
  2208. {
  2209. if ( cc > 0 )
  2210. {
  2211. macros += ";";
  2212. }
  2213. macros += it->first;
  2214. cc ++;
  2215. }
  2216. }
  2217. cmCacheManager *cmMakefile::GetCacheManager() const
  2218. {
  2219. return this->GetCMakeInstance()->GetCacheManager();
  2220. }
  2221. void cmMakefile::DisplayStatus(const char* message, float s)
  2222. {
  2223. this->GetLocalGenerator()->GetGlobalGenerator()
  2224. ->GetCMakeInstance()->UpdateProgress(message, s);
  2225. }
  2226. std::string cmMakefile::GetModulesFile(const char* filename)
  2227. {
  2228. std::vector<std::string> modulePath;
  2229. const char* def = this->GetDefinition("CMAKE_MODULE_PATH");
  2230. if(def)
  2231. {
  2232. cmSystemTools::ExpandListArgument(def, modulePath);
  2233. }
  2234. // Also search in the standard modules location.
  2235. def = this->GetDefinition("CMAKE_ROOT");
  2236. if(def)
  2237. {
  2238. std::string rootModules = def;
  2239. rootModules += "/Modules";
  2240. modulePath.push_back(rootModules);
  2241. }
  2242. //std::string Look through the possible module directories.
  2243. for(std::vector<std::string>::iterator i = modulePath.begin();
  2244. i != modulePath.end(); ++i)
  2245. {
  2246. std::string itempl = *i;
  2247. cmSystemTools::ConvertToUnixSlashes(itempl);
  2248. itempl += "/";
  2249. itempl += filename;
  2250. if(cmSystemTools::FileExists(itempl.c_str()))
  2251. {
  2252. return itempl;
  2253. }
  2254. }
  2255. return "";
  2256. }
  2257. void cmMakefile::ConfigureString(const std::string& input,
  2258. std::string& output, bool atOnly,
  2259. bool escapeQuotes)
  2260. {
  2261. // Split input to handle one line at a time.
  2262. std::string::const_iterator lineStart = input.begin();
  2263. while(lineStart != input.end())
  2264. {
  2265. // Find the end of this line.
  2266. std::string::const_iterator lineEnd = lineStart;
  2267. while(lineEnd != input.end() && *lineEnd != '\n')
  2268. {
  2269. ++lineEnd;
  2270. }
  2271. // Copy the line.
  2272. std::string line(lineStart, lineEnd);
  2273. // Skip the newline character.
  2274. bool haveNewline = (lineEnd != input.end());
  2275. if(haveNewline)
  2276. {
  2277. ++lineEnd;
  2278. }
  2279. // Replace #cmakedefine instances.
  2280. if(this->cmDefineRegex.find(line))
  2281. {
  2282. const char* def =
  2283. this->GetDefinition(this->cmDefineRegex.match(1).c_str());
  2284. if(!cmSystemTools::IsOff(def))
  2285. {
  2286. cmSystemTools::ReplaceString(line, "#cmakedefine", "#define");
  2287. output += line;
  2288. }
  2289. else
  2290. {
  2291. output += "/* #undef ";
  2292. output += this->cmDefineRegex.match(1);
  2293. output += " */";
  2294. }
  2295. }
  2296. else if(this->cmDefine01Regex.find(line))
  2297. {
  2298. const char* def =
  2299. this->GetDefinition(this->cmDefine01Regex.match(1).c_str());
  2300. cmSystemTools::ReplaceString(line, "#cmakedefine01", "#define");
  2301. output += line;
  2302. if(!cmSystemTools::IsOff(def))
  2303. {
  2304. output += " 1";
  2305. }
  2306. else
  2307. {
  2308. output += " 0";
  2309. }
  2310. }
  2311. else
  2312. {
  2313. output += line;
  2314. }
  2315. if(haveNewline)
  2316. {
  2317. output += "\n";
  2318. }
  2319. // Move to the next line.
  2320. lineStart = lineEnd;
  2321. }
  2322. // Perform variable replacements.
  2323. this->ExpandVariablesInString(output, escapeQuotes, true,
  2324. atOnly, 0, -1, true);
  2325. }
  2326. int cmMakefile::ConfigureFile(const char* infile, const char* outfile,
  2327. bool copyonly, bool atOnly, bool escapeQuotes)
  2328. {
  2329. int res = 1;
  2330. if ( !this->CanIWriteThisFile(outfile) )
  2331. {
  2332. cmSystemTools::Error("Attempt to write file: ",
  2333. outfile, " into a source directory.");
  2334. return 0;
  2335. }
  2336. if ( !cmSystemTools::FileExists(infile) )
  2337. {
  2338. cmSystemTools::Error("File ", infile, " does not exist.");
  2339. return 0;
  2340. }
  2341. std::string soutfile = outfile;
  2342. std::string sinfile = infile;
  2343. this->AddCMakeDependFile(infile);
  2344. cmSystemTools::ConvertToUnixSlashes(soutfile);
  2345. mode_t perm = 0;
  2346. cmSystemTools::GetPermissions(sinfile.c_str(), perm);
  2347. std::string::size_type pos = soutfile.rfind('/');
  2348. if(pos != std::string::npos)
  2349. {
  2350. std::string path = soutfile.substr(0, pos);
  2351. cmSystemTools::MakeDirectory(path.c_str());
  2352. }
  2353. if(copyonly)
  2354. {
  2355. if ( !cmSystemTools::CopyFileIfDifferent(sinfile.c_str(),
  2356. soutfile.c_str()))
  2357. {
  2358. return 0;
  2359. }
  2360. }
  2361. else
  2362. {
  2363. std::string tempOutputFile = soutfile;
  2364. tempOutputFile += ".tmp";
  2365. std::ofstream fout(tempOutputFile.c_str());
  2366. if(!fout)
  2367. {
  2368. cmSystemTools::Error(
  2369. "Could not open file for write in copy operation ",
  2370. tempOutputFile.c_str());
  2371. cmSystemTools::ReportLastSystemError("");
  2372. return 0;
  2373. }
  2374. std::ifstream fin(sinfile.c_str());
  2375. if(!fin)
  2376. {
  2377. cmSystemTools::Error("Could not open file for read in copy operation ",
  2378. sinfile.c_str());
  2379. return 0;
  2380. }
  2381. // now copy input to output and expand variables in the
  2382. // input file at the same time
  2383. std::string inLine;
  2384. std::string outLine;
  2385. while( cmSystemTools::GetLineFromStream(fin, inLine) )
  2386. {
  2387. outLine = "";
  2388. this->ConfigureString(inLine, outLine, atOnly, escapeQuotes);
  2389. fout << outLine.c_str() << "\n";
  2390. }
  2391. // close the files before attempting to copy
  2392. fin.close();
  2393. fout.close();
  2394. if ( !cmSystemTools::CopyFileIfDifferent(tempOutputFile.c_str(),
  2395. soutfile.c_str()) )
  2396. {
  2397. res = 0;
  2398. }
  2399. else
  2400. {
  2401. cmSystemTools::SetPermissions(soutfile.c_str(), perm);
  2402. }
  2403. cmSystemTools::RemoveFile(tempOutputFile.c_str());
  2404. }
  2405. return res;
  2406. }
  2407. void cmMakefile::AddWrittenFile(const char* file)
  2408. { this->GetCMakeInstance()->AddWrittenFile(file); }
  2409. bool cmMakefile::HasWrittenFile(const char* file)
  2410. { return this->GetCMakeInstance()->HasWrittenFile(file); }
  2411. bool cmMakefile::CheckInfiniteLoops()
  2412. {
  2413. std::vector<std::string>::iterator it;
  2414. for ( it = this->ListFiles.begin();
  2415. it != this->ListFiles.end();
  2416. ++ it )
  2417. {
  2418. if ( this->HasWrittenFile(it->c_str()) )
  2419. {
  2420. cmOStringStream str;
  2421. str << "File " << it->c_str() <<
  2422. " is written by WRITE_FILE (or FILE WRITE) command and should "
  2423. "not be used as input to CMake. Please use CONFIGURE_FILE to "
  2424. "be safe. Refer to the note next to FILE WRITE command.";
  2425. cmSystemTools::Error(str.str().c_str());
  2426. return false;
  2427. }
  2428. }
  2429. return true;
  2430. }
  2431. void cmMakefile::SetProperty(const char* prop, const char* value)
  2432. {
  2433. if (!prop)
  2434. {
  2435. return;
  2436. }
  2437. // handle special props
  2438. std::string propname = prop;
  2439. if ( propname == "INCLUDE_DIRECTORIES" )
  2440. {
  2441. std::vector<std::string> varArgsExpanded;
  2442. cmSystemTools::ExpandListArgument(value, varArgsExpanded);
  2443. this->SetIncludeDirectories(varArgsExpanded);
  2444. return;
  2445. }
  2446. if ( propname == "LINK_DIRECTORIES" )
  2447. {
  2448. std::vector<std::string> varArgsExpanded;
  2449. cmSystemTools::ExpandListArgument(value, varArgsExpanded);
  2450. this->SetLinkDirectories(varArgsExpanded);
  2451. return;
  2452. }
  2453. if ( propname == "INCLUDE_REGULAR_EXPRESSION" )
  2454. {
  2455. this->SetIncludeRegularExpression(value);
  2456. return;
  2457. }
  2458. if ( propname == "ADDITIONAL_MAKE_CLEAN_FILES" )
  2459. {
  2460. // This property is not inherrited
  2461. if ( strcmp(this->GetCurrentDirectory(),
  2462. this->GetStartDirectory()) != 0 )
  2463. {
  2464. return;
  2465. }
  2466. }
  2467. this->Properties.SetProperty(prop,value,cmProperty::DIRECTORY);
  2468. }
  2469. void cmMakefile::AppendProperty(const char* prop, const char* value)
  2470. {
  2471. if (!prop)
  2472. {
  2473. return;
  2474. }
  2475. // handle special props
  2476. std::string propname = prop;
  2477. if ( propname == "INCLUDE_DIRECTORIES" )
  2478. {
  2479. std::vector<std::string> varArgsExpanded;
  2480. cmSystemTools::ExpandListArgument(value, varArgsExpanded);
  2481. for(std::vector<std::string>::const_iterator vi = varArgsExpanded.begin();
  2482. vi != varArgsExpanded.end(); ++vi)
  2483. {
  2484. this->AddIncludeDirectory(vi->c_str());
  2485. }
  2486. return;
  2487. }
  2488. if ( propname == "LINK_DIRECTORIES" )
  2489. {
  2490. std::vector<std::string> varArgsExpanded;
  2491. cmSystemTools::ExpandListArgument(value, varArgsExpanded);
  2492. for(std::vector<std::string>::const_iterator vi = varArgsExpanded.begin();
  2493. vi != varArgsExpanded.end(); ++vi)
  2494. {
  2495. this->AddLinkDirectory(vi->c_str());
  2496. }
  2497. return;
  2498. }
  2499. this->Properties.AppendProperty(prop,value,cmProperty::DIRECTORY);
  2500. }
  2501. const char *cmMakefile::GetPropertyOrDefinition(const char* prop)
  2502. {
  2503. const char *ret = this->GetProperty(prop, cmProperty::DIRECTORY);
  2504. if (!ret)
  2505. {
  2506. ret = this->GetDefinition(prop);
  2507. }
  2508. return ret;
  2509. }
  2510. const char *cmMakefile::GetProperty(const char* prop)
  2511. {
  2512. return this->GetProperty(prop, cmProperty::DIRECTORY);
  2513. }
  2514. const char *cmMakefile::GetProperty(const char* prop,
  2515. cmProperty::ScopeType scope)
  2516. {
  2517. // watch for specific properties
  2518. static std::string output;
  2519. output = "";
  2520. if (!strcmp("PARENT_DIRECTORY",prop))
  2521. {
  2522. output = this->LocalGenerator->GetParent()
  2523. ->GetMakefile()->GetStartDirectory();
  2524. return output.c_str();
  2525. }
  2526. else if (!strcmp("INCLUDE_REGULAR_EXPRESSION",prop) )
  2527. {
  2528. output = this->GetIncludeRegularExpression();
  2529. return output.c_str();
  2530. }
  2531. else if (!strcmp("LISTFILE_STACK",prop))
  2532. {
  2533. for (std::deque<cmStdString>::iterator i = this->ListFileStack.begin();
  2534. i != this->ListFileStack.end(); ++i)
  2535. {
  2536. if (i != this->ListFileStack.begin())
  2537. {
  2538. output += ";";
  2539. }
  2540. output += *i;
  2541. }
  2542. return output.c_str();
  2543. }
  2544. else if (!strcmp("VARIABLES",prop) || !strcmp("CACHE_VARIABLES",prop))
  2545. {
  2546. int cacheonly = 0;
  2547. if ( !strcmp("CACHE_VARIABLES",prop) )
  2548. {
  2549. cacheonly = 1;
  2550. }
  2551. std::vector<std::string> vars = this->GetDefinitions(cacheonly);
  2552. for (unsigned int cc = 0; cc < vars.size(); cc ++ )
  2553. {
  2554. if ( cc > 0 )
  2555. {
  2556. output += ";";
  2557. }
  2558. output += vars[cc];
  2559. }
  2560. return output.c_str();
  2561. }
  2562. else if (!strcmp("MACROS",prop))
  2563. {
  2564. this->GetListOfMacros(output);
  2565. return output.c_str();
  2566. }
  2567. else if (!strcmp("DEFINITIONS",prop))
  2568. {
  2569. output = this->GetDefineFlags();
  2570. return output.c_str();
  2571. }
  2572. else if (!strcmp("INCLUDE_DIRECTORIES",prop) )
  2573. {
  2574. cmOStringStream str;
  2575. for (std::vector<std::string>::const_iterator
  2576. it = this->GetIncludeDirectories().begin();
  2577. it != this->GetIncludeDirectories().end();
  2578. ++ it )
  2579. {
  2580. if ( it != this->GetIncludeDirectories().begin())
  2581. {
  2582. str << ";";
  2583. }
  2584. str << it->c_str();
  2585. }
  2586. output = str.str();
  2587. return output.c_str();
  2588. }
  2589. else if (!strcmp("LINK_DIRECTORIES",prop))
  2590. {
  2591. cmOStringStream str;
  2592. for (std::vector<std::string>::const_iterator
  2593. it = this->GetLinkDirectories().begin();
  2594. it != this->GetLinkDirectories().end();
  2595. ++ it )
  2596. {
  2597. if ( it != this->GetLinkDirectories().begin())
  2598. {
  2599. str << ";";
  2600. }
  2601. str << it->c_str();
  2602. }
  2603. output = str.str();
  2604. return output.c_str();
  2605. }
  2606. bool chain = false;
  2607. const char *retVal =
  2608. this->Properties.GetPropertyValue(prop, scope, chain);
  2609. if (chain)
  2610. {
  2611. if(this->LocalGenerator->GetParent())
  2612. {
  2613. return this->LocalGenerator->GetParent()->GetMakefile()->
  2614. GetProperty(prop, scope);
  2615. }
  2616. return this->GetCMakeInstance()->GetProperty(prop,scope);
  2617. }
  2618. return retVal;
  2619. }
  2620. bool cmMakefile::GetPropertyAsBool(const char* prop)
  2621. {
  2622. return cmSystemTools::IsOn(this->GetProperty(prop));
  2623. }
  2624. cmTarget* cmMakefile::FindTarget(const char* name)
  2625. {
  2626. cmTargets& tgts = this->GetTargets();
  2627. cmTargets::iterator i = tgts.find ( name );
  2628. if ( i != tgts.end() )
  2629. {
  2630. return &i->second;
  2631. }
  2632. return 0;
  2633. }
  2634. cmTest* cmMakefile::CreateTest(const char* testName)
  2635. {
  2636. if ( !testName )
  2637. {
  2638. return 0;
  2639. }
  2640. cmTest* test = this->GetTest(testName);
  2641. if ( test )
  2642. {
  2643. return test;
  2644. }
  2645. test = new cmTest;
  2646. test->SetName(testName);
  2647. test->SetMakefile(this);
  2648. this->Tests.push_back(test);
  2649. return test;
  2650. }
  2651. cmTest* cmMakefile::GetTest(const char* testName) const
  2652. {
  2653. if ( !testName )
  2654. {
  2655. return 0;
  2656. }
  2657. std::vector<cmTest*>::const_iterator it;
  2658. for ( it = this->Tests.begin(); it != this->Tests.end(); ++ it )
  2659. {
  2660. if ( strcmp((*it)->GetName(), testName) == 0 )
  2661. {
  2662. return *it;
  2663. }
  2664. }
  2665. return 0;
  2666. }
  2667. const std::vector<cmTest*> *cmMakefile::GetTests() const
  2668. {
  2669. return &this->Tests;
  2670. }
  2671. std::vector<cmTest*> *cmMakefile::GetTests()
  2672. {
  2673. return &this->Tests;
  2674. }
  2675. std::string cmMakefile::GetListFileStack()
  2676. {
  2677. cmOStringStream tmp;
  2678. size_t depth = this->ListFileStack.size();
  2679. if (depth > 0)
  2680. {
  2681. std::deque<cmStdString>::iterator it = this->ListFileStack.end();
  2682. do
  2683. {
  2684. if (depth != this->ListFileStack.size())
  2685. {
  2686. tmp << "\n ";
  2687. }
  2688. --it;
  2689. tmp << "[";
  2690. tmp << depth;
  2691. tmp << "]\t";
  2692. tmp << *it;
  2693. depth--;
  2694. }
  2695. while (it != this->ListFileStack.begin());
  2696. }
  2697. return tmp.str();
  2698. }
  2699. void cmMakefile::PushScope()
  2700. {
  2701. // Get the index of the next stack entry.
  2702. std::vector<DefinitionMap>::size_type index = this->DefinitionStack.size();
  2703. // Allocate a new stack entry.
  2704. this->DefinitionStack.push_back(DefinitionMap());
  2705. // Copy the previous top to the new top.
  2706. this->DefinitionStack[index] = this->DefinitionStack[index-1];
  2707. }
  2708. void cmMakefile::PopScope()
  2709. {
  2710. this->DefinitionStack.pop_back();
  2711. }
  2712. void cmMakefile::RaiseScope(const char *var, const char *varDef)
  2713. {
  2714. if (!var || !strlen(var))
  2715. {
  2716. return;
  2717. }
  2718. // multiple scopes in this directory?
  2719. if (this->DefinitionStack.size() > 1)
  2720. {
  2721. if(varDef)
  2722. {
  2723. this->DefinitionStack[this->DefinitionStack.size()-2][var] = varDef;
  2724. }
  2725. else
  2726. {
  2727. this->DefinitionStack[this->DefinitionStack.size()-2].erase(var);
  2728. }
  2729. }
  2730. // otherwise do the parent (if one exists)
  2731. else if (this->LocalGenerator->GetParent())
  2732. {
  2733. cmMakefile *parent = this->LocalGenerator->GetParent()->GetMakefile();
  2734. if (parent)
  2735. {
  2736. if(varDef)
  2737. {
  2738. parent->AddDefinition(var,varDef);
  2739. }
  2740. else
  2741. {
  2742. parent->RemoveDefinition(var);
  2743. }
  2744. }
  2745. }
  2746. }
  2747. // define properties
  2748. void cmMakefile::DefineProperties(cmake *cm)
  2749. {
  2750. cm->DefineProperty
  2751. ("ADDITIONAL_MAKE_CLEAN_FILES", cmProperty::DIRECTORY,
  2752. "Additional files to clean during the make clean stage.",
  2753. "A list of files that will be cleaned as a part of the "
  2754. "\"make clean\" stage. ");
  2755. cm->DefineProperty
  2756. ("CLEAN_NO_CUSTOM", cmProperty::DIRECTORY,
  2757. "Should the output of custom commands be left.",
  2758. "If this is true then the outputs of custom commands for this "
  2759. "directory will not be removed during the \"make clean\" stage. ");
  2760. cm->DefineProperty
  2761. ("CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS", cmProperty::DIRECTORY,
  2762. "Allow loops to have non-matching closing statements.",
  2763. "If this is set then the closing statement of control "
  2764. "structures in CMake will not require an exact match to the "
  2765. "opening statement. For example IF(foo) will not require "
  2766. "ENDIF(foo) but simple ENDIF() will work.",
  2767. true);
  2768. cm->DefineProperty
  2769. ("LISTFILE_STACK", cmProperty::DIRECTORY,
  2770. "The current stack of listfiles being processed.",
  2771. "This property is mainly useful when trying to debug errors "
  2772. "in your CMake scripts. It returns a list of what list files "
  2773. "are currently being processed, in order. So if one listfile "
  2774. "does an INCLUDE command then that is effectively pushing "
  2775. "the included listfile onto the stack.");
  2776. cm->DefineProperty
  2777. ("TEST_INCLUDE_FILE", cmProperty::DIRECTORY,
  2778. "A cmake file that will be included when ctest is run.",
  2779. "If you specify TEST_INCLUDE_FILE, that file will be "
  2780. "included and processed when ctest is run on the directory.");
  2781. cm->DefineProperty
  2782. ("COMPILE_DEFINITIONS", cmProperty::DIRECTORY,
  2783. "Preprocessor definitions for compiling a directory's sources.",
  2784. "The COMPILE_DEFINITIONS property may be set to a list of preprocessor "
  2785. "definitions using the syntax VAR or VAR=value. Function-style "
  2786. "definitions are not supported. CMake will automatically escape "
  2787. "the value correctly for the native build system (note that CMake "
  2788. "language syntax may require escapes to specify some values). "
  2789. "This property may be set on a per-configuration basis using the name "
  2790. "COMPILE_DEFINITIONS_<CONFIG> where <CONFIG> is an upper-case name "
  2791. "(ex. \"COMPILE_DEFINITIONS_DEBUG\"). "
  2792. "This property will be initialized in each directory by its value "
  2793. "in the directory's parent.\n"
  2794. "CMake will automatically drop some definitions that "
  2795. "are not supported by the native build tool. "
  2796. "The VS6 IDE does not support definitions with values "
  2797. "(but NMake does).\n"
  2798. "Dislaimer: Most native build tools have poor support for escaping "
  2799. "certain values. CMake has work-arounds for many cases but some "
  2800. "values may just not be possible to pass correctly. If a value "
  2801. "does not seem to be escaped correctly, do not attempt to "
  2802. "work-around the problem by adding escape sequences to the value. "
  2803. "Your work-around may break in a future version of CMake that "
  2804. "has improved escape support. Instead consider defining the macro "
  2805. "in a (configured) header file. Then report the limitation.");
  2806. cm->DefineProperty
  2807. ("COMPILE_DEFINITIONS_<CONFIG>", cmProperty::DIRECTORY,
  2808. "Per-configuration preprocessor definitions in a directory.",
  2809. "This is the configuration-specific version of COMPILE_DEFINITIONS. "
  2810. "This property will be initialized in each directory by its value "
  2811. "in the directory's parent.\n");
  2812. cm->DefineProperty
  2813. ("EXCLUDE_FROM_ALL", cmProperty::DIRECTORY,
  2814. "Exclude the directory from the all target of its parent.",
  2815. "A property on a directory that indicates if its targets are excluded "
  2816. "from the default build target. If it is not, then with a Makefile "
  2817. "for example typing make will cause the targets to be built. "
  2818. "The same concept applies to the default build of other generators.",
  2819. false);
  2820. }
  2821. //----------------------------------------------------------------------------
  2822. cmTarget*
  2823. cmMakefile::AddImportedTarget(const char* name, cmTarget::TargetType type)
  2824. {
  2825. // Create the target.
  2826. cmsys::auto_ptr<cmTarget> target(new cmTarget);
  2827. target->SetType(type, name);
  2828. target->SetMakefile(this);
  2829. target->MarkAsImported();
  2830. // Add to the set of available imported targets.
  2831. this->ImportedTargets[name] = target.get();
  2832. // Transfer ownership to this cmMakefile object.
  2833. this->ImportedTargetsOwned.push_back(target.get());
  2834. return target.release();
  2835. }
  2836. //----------------------------------------------------------------------------
  2837. cmTarget* cmMakefile::FindTargetToUse(const char* name)
  2838. {
  2839. // Look for an imported target. These take priority because they
  2840. // are more local in scope and do not have to be globally unique.
  2841. std::map<cmStdString, cmTarget*>::const_iterator
  2842. imported = this->ImportedTargets.find(name);
  2843. if(imported != this->ImportedTargets.end())
  2844. {
  2845. return imported->second;
  2846. }
  2847. // Look for a target built in this project.
  2848. return this->LocalGenerator->GetGlobalGenerator()->FindTarget(0, name);
  2849. }
  2850. //----------------------------------------------------------------------------
  2851. bool cmMakefile::EnforceUniqueName(std::string const& name, std::string& msg,
  2852. bool isCustom)
  2853. {
  2854. if(cmTarget* existing = this->FindTargetToUse(name.c_str()))
  2855. {
  2856. // The name given conflicts with an existing target. Produce an
  2857. // error in a compatible way.
  2858. if(existing->IsImported())
  2859. {
  2860. // Imported targets were not supported in previous versions.
  2861. // This is new code, so we can make it an error.
  2862. cmOStringStream e;
  2863. e << "cannot create target \"" << name
  2864. << "\" because an imported target with the same name already exists.";
  2865. msg = e.str();
  2866. return false;
  2867. }
  2868. else if(!this->NeedBackwardsCompatibility(2, 4))
  2869. {
  2870. // The conflict is with a non-imported target.
  2871. // Allow this if the user has requested support.
  2872. cmake* cm =
  2873. this->LocalGenerator->GetGlobalGenerator()->GetCMakeInstance();
  2874. if(isCustom && existing->GetType() == cmTarget::UTILITY &&
  2875. this != existing->GetMakefile() &&
  2876. cm->GetPropertyAsBool("ALLOW_DUPLICATE_CUSTOM_TARGETS"))
  2877. {
  2878. return true;
  2879. }
  2880. // Produce an error that tells the user how to work around the
  2881. // problem.
  2882. cmOStringStream e;
  2883. e << "cannot create target \"" << name
  2884. << "\" because another target with the same name already exists. "
  2885. << "The existing target is ";
  2886. switch(existing->GetType())
  2887. {
  2888. case cmTarget::EXECUTABLE:
  2889. e << "an executable ";
  2890. break;
  2891. case cmTarget::STATIC_LIBRARY:
  2892. e << "a static library ";
  2893. break;
  2894. case cmTarget::SHARED_LIBRARY:
  2895. e << "a shared library ";
  2896. break;
  2897. case cmTarget::MODULE_LIBRARY:
  2898. e << "a module library ";
  2899. break;
  2900. case cmTarget::UTILITY:
  2901. e << "a custom target ";
  2902. break;
  2903. default: break;
  2904. }
  2905. e << "created in source directory \""
  2906. << existing->GetMakefile()->GetCurrentDirectory() << "\".\n"
  2907. << "\n";
  2908. e <<
  2909. "Logical target names must be globally unique because:\n"
  2910. " - Unique names may be referenced unambiguously both in CMake\n"
  2911. " code and on make tool command lines.\n"
  2912. " - Logical names are used by Xcode and VS IDE generators\n"
  2913. " to produce meaningful project names for the targets.\n"
  2914. "The logical name of executable and library targets does not "
  2915. "have to correspond to the physical file names built. "
  2916. "Consider using the OUTPUT_NAME target property to create two "
  2917. "targets with the same physical name while keeping logical "
  2918. "names distinct. "
  2919. "Custom targets must simply have globally unique names.\n"
  2920. "\n"
  2921. "If you are building an older project it is possible that "
  2922. "it violated this rule but was working accidentally because "
  2923. "CMake did not previously diagnose this problem. "
  2924. "Set CMAKE_BACKWARDS_COMPATIBILITY to 2.4 or lower to disable "
  2925. "this error.\n";
  2926. if(isCustom && existing->GetType() == cmTarget::UTILITY)
  2927. {
  2928. e <<
  2929. "\n"
  2930. "For projects that care only about Makefile generators and do "
  2931. "not wish to support Xcode or VS IDE generators, one may add\n"
  2932. " set_property(GLOBAL PROPERTY ALLOW_DUPLICATE_CUSTOM_TARGETS 1)\n"
  2933. "to the top of the project to allow duplicate custom targets "
  2934. "(target names must still be unique within each directory). "
  2935. "However, setting this property will cause non-Makefile generators "
  2936. "to produce an error and refuse to generate the project.";
  2937. }
  2938. msg = e.str();
  2939. return false;
  2940. }
  2941. }
  2942. return true;
  2943. }