cmMakefile.cxx 112 KB

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