cmake.cxx 136 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmake.h"
  11. #include "cmDocumentVariables.h"
  12. #include "time.h"
  13. #include "cmCacheManager.h"
  14. #include "cmMakefile.h"
  15. #include "cmLocalGenerator.h"
  16. #include "cmExternalMakefileProjectGenerator.h"
  17. #include "cmCommands.h"
  18. #include "cmCommand.h"
  19. #include "cmFileTimeComparison.h"
  20. #include "cmGeneratedFileStream.h"
  21. #include "cmQtAutomoc.h"
  22. #include "cmSourceFile.h"
  23. #include "cmVersion.h"
  24. #include "cmTest.h"
  25. #include "cmDocumentationFormatterText.h"
  26. #if defined(CMAKE_BUILD_WITH_CMAKE)
  27. # include "cmGraphVizWriter.h"
  28. # include "cmDependsFortran.h" // For -E cmake_copy_f90_mod callback.
  29. # include "cmVariableWatch.h"
  30. # include <cmsys/Terminal.h>
  31. # include <cmsys/CommandLineArguments.hxx>
  32. #endif
  33. #include <cmsys/Directory.hxx>
  34. #include <cmsys/Process.h>
  35. #include <cmsys/Glob.hxx>
  36. #include <cmsys/RegularExpression.hxx>
  37. // only build kdevelop generator on non-windows platforms
  38. // when not bootstrapping cmake
  39. #if !defined(_WIN32)
  40. # if defined(CMAKE_BUILD_WITH_CMAKE)
  41. # define CMAKE_USE_KDEVELOP
  42. # endif
  43. #endif
  44. #if defined(CMAKE_BUILD_WITH_CMAKE)
  45. # define CMAKE_USE_ECLIPSE
  46. #endif
  47. #if defined(__MINGW32__) && !defined(CMAKE_BUILD_WITH_CMAKE)
  48. # define CMAKE_BOOT_MINGW
  49. #endif
  50. // include the generator
  51. #if defined(_WIN32) && !defined(__CYGWIN__)
  52. # if !defined(CMAKE_BOOT_MINGW)
  53. # include "cmGlobalVisualStudio6Generator.h"
  54. # include "cmGlobalVisualStudio7Generator.h"
  55. # include "cmGlobalVisualStudio71Generator.h"
  56. # include "cmGlobalVisualStudio8Generator.h"
  57. # include "cmGlobalVisualStudio9Generator.h"
  58. # include "cmGlobalVisualStudio9IA64Generator.h"
  59. # include "cmGlobalVisualStudio9Win64Generator.h"
  60. # include "cmGlobalVisualStudio10Generator.h"
  61. # include "cmGlobalVisualStudio10IA64Generator.h"
  62. # include "cmGlobalVisualStudio10Win64Generator.h"
  63. # include "cmGlobalVisualStudio11Generator.h"
  64. # include "cmGlobalVisualStudio11Win64Generator.h"
  65. # include "cmGlobalVisualStudio8Win64Generator.h"
  66. # include "cmGlobalBorlandMakefileGenerator.h"
  67. # include "cmGlobalNMakeMakefileGenerator.h"
  68. # include "cmGlobalJOMMakefileGenerator.h"
  69. # include "cmGlobalWatcomWMakeGenerator.h"
  70. # define CMAKE_HAVE_VS_GENERATORS
  71. # endif
  72. # include "cmGlobalMSYSMakefileGenerator.h"
  73. # include "cmGlobalMinGWMakefileGenerator.h"
  74. # include "cmWin32ProcessExecution.h"
  75. #else
  76. #endif
  77. #include "cmGlobalUnixMakefileGenerator3.h"
  78. #if defined(CMAKE_HAVE_VS_GENERATORS)
  79. #include "cmCallVisualStudioMacro.h"
  80. #endif
  81. #if !defined(CMAKE_BOOT_MINGW)
  82. # include "cmExtraCodeBlocksGenerator.h"
  83. #endif
  84. #ifdef CMAKE_USE_KDEVELOP
  85. # include "cmGlobalKdevelopGenerator.h"
  86. #endif
  87. #ifdef CMAKE_USE_ECLIPSE
  88. # include "cmExtraEclipseCDT4Generator.h"
  89. #endif
  90. #include <stdlib.h> // required for atoi
  91. #if defined( __APPLE__ )
  92. # if defined(CMAKE_BUILD_WITH_CMAKE)
  93. # include "cmGlobalXCodeGenerator.h"
  94. # define CMAKE_USE_XCODE 1
  95. # endif
  96. # include <sys/types.h>
  97. # include <sys/time.h>
  98. # include <sys/resource.h>
  99. #endif
  100. #include <sys/stat.h> // struct stat
  101. #include <memory> // auto_ptr
  102. static bool cmakeCheckStampFile(const char* stampName);
  103. static bool cmakeCheckStampList(const char* stampName);
  104. void cmNeedBackwardsCompatibility(const std::string& variable,
  105. int access_type, void*, const char*, const cmMakefile*)
  106. {
  107. #ifdef CMAKE_BUILD_WITH_CMAKE
  108. if (access_type == cmVariableWatch::UNKNOWN_VARIABLE_READ_ACCESS)
  109. {
  110. std::string message = "An attempt was made to access a variable: ";
  111. message += variable;
  112. message +=
  113. " that has not been defined. Some variables were always defined "
  114. "by CMake in versions prior to 1.6. To fix this you might need to set "
  115. "the cache value of CMAKE_BACKWARDS_COMPATIBILITY to 1.4 or less. If "
  116. "you are writing a CMakeList file, (or have already set "
  117. "CMAKE_BACKWARDS_COMPATABILITY to 1.4 or less) then you probably need "
  118. "to include a CMake module to test for the feature this variable "
  119. "defines.";
  120. cmSystemTools::Error(message.c_str());
  121. }
  122. #else
  123. (void)variable;
  124. (void)access_type;
  125. #endif
  126. }
  127. void cmWarnUnusedCliWarning(const std::string& variable,
  128. int, void* ctx, const char*, const cmMakefile*)
  129. {
  130. cmake* cm = reinterpret_cast<cmake*>(ctx);
  131. cm->MarkCliAsUsed(variable);
  132. }
  133. cmake::cmake()
  134. {
  135. this->Trace = false;
  136. this->WarnUninitialized = false;
  137. this->WarnUnused = false;
  138. this->WarnUnusedCli = true;
  139. this->CheckSystemVars = false;
  140. this->SuppressDevWarnings = false;
  141. this->DoSuppressDevWarnings = false;
  142. this->DebugOutput = false;
  143. this->DebugTryCompile = false;
  144. this->ClearBuildSystem = false;
  145. this->FileComparison = new cmFileTimeComparison;
  146. this->Policies = new cmPolicies();
  147. this->InitializeProperties();
  148. #ifdef __APPLE__
  149. struct rlimit rlp;
  150. if(!getrlimit(RLIMIT_STACK, &rlp))
  151. {
  152. if(rlp.rlim_cur != rlp.rlim_max)
  153. {
  154. rlp.rlim_cur = rlp.rlim_max;
  155. setrlimit(RLIMIT_STACK, &rlp);
  156. }
  157. }
  158. #endif
  159. this->Verbose = false;
  160. this->InTryCompile = false;
  161. this->CacheManager = new cmCacheManager(this);
  162. this->GlobalGenerator = 0;
  163. this->ProgressCallback = 0;
  164. this->ProgressCallbackClientData = 0;
  165. this->CurrentWorkingMode = NORMAL_MODE;
  166. #ifdef CMAKE_BUILD_WITH_CMAKE
  167. this->VariableWatch = new cmVariableWatch;
  168. this->VariableWatch->AddWatch("CMAKE_WORDS_BIGENDIAN",
  169. cmNeedBackwardsCompatibility);
  170. this->VariableWatch->AddWatch("CMAKE_SIZEOF_INT",
  171. cmNeedBackwardsCompatibility);
  172. this->VariableWatch->AddWatch("CMAKE_X_LIBS",
  173. cmNeedBackwardsCompatibility);
  174. #endif
  175. this->AddDefaultGenerators();
  176. this->AddDefaultExtraGenerators();
  177. this->AddDefaultCommands();
  178. // Make sure we can capture the build tool output.
  179. cmSystemTools::EnableVSConsoleOutput();
  180. }
  181. cmake::~cmake()
  182. {
  183. delete this->CacheManager;
  184. delete this->Policies;
  185. if (this->GlobalGenerator)
  186. {
  187. delete this->GlobalGenerator;
  188. this->GlobalGenerator = 0;
  189. }
  190. for(RegisteredCommandsMap::iterator j = this->Commands.begin();
  191. j != this->Commands.end(); ++j)
  192. {
  193. delete (*j).second;
  194. }
  195. #ifdef CMAKE_BUILD_WITH_CMAKE
  196. delete this->VariableWatch;
  197. #endif
  198. delete this->FileComparison;
  199. }
  200. void cmake::InitializeProperties()
  201. {
  202. this->Properties.clear();
  203. this->Properties.SetCMakeInstance(this);
  204. this->AccessedProperties.clear();
  205. this->PropertyDefinitions.clear();
  206. // initialize properties
  207. cmCacheManager::DefineProperties(this);
  208. cmSourceFile::DefineProperties(this);
  209. cmTarget::DefineProperties(this);
  210. cmMakefile::DefineProperties(this);
  211. cmTest::DefineProperties(this);
  212. cmake::DefineProperties(this);
  213. }
  214. void cmake::CleanupCommandsAndMacros()
  215. {
  216. this->InitializeProperties();
  217. std::vector<cmCommand*> commands;
  218. for(RegisteredCommandsMap::iterator j = this->Commands.begin();
  219. j != this->Commands.end(); ++j)
  220. {
  221. if ( !j->second->IsA("cmMacroHelperCommand") &&
  222. !j->second->IsA("cmFunctionHelperCommand"))
  223. {
  224. commands.push_back(j->second);
  225. }
  226. else
  227. {
  228. delete j->second;
  229. }
  230. }
  231. this->Commands.erase(this->Commands.begin(), this->Commands.end());
  232. std::vector<cmCommand*>::iterator it;
  233. for ( it = commands.begin(); it != commands.end();
  234. ++ it )
  235. {
  236. this->Commands[cmSystemTools::LowerCase((*it)->GetName())] = *it;
  237. }
  238. }
  239. bool cmake::CommandExists(const char* name) const
  240. {
  241. std::string sName = cmSystemTools::LowerCase(name);
  242. return (this->Commands.find(sName) != this->Commands.end());
  243. }
  244. cmCommand *cmake::GetCommand(const char *name)
  245. {
  246. cmCommand* rm = 0;
  247. std::string sName = cmSystemTools::LowerCase(name);
  248. RegisteredCommandsMap::iterator pos = this->Commands.find(sName);
  249. if (pos != this->Commands.end())
  250. {
  251. rm = (*pos).second;
  252. }
  253. return rm;
  254. }
  255. void cmake::RenameCommand(const char*oldName, const char* newName)
  256. {
  257. // if the command already exists, free the old one
  258. std::string sOldName = cmSystemTools::LowerCase(oldName);
  259. std::string sNewName = cmSystemTools::LowerCase(newName);
  260. RegisteredCommandsMap::iterator pos = this->Commands.find(sOldName);
  261. if ( pos == this->Commands.end() )
  262. {
  263. return;
  264. }
  265. cmCommand* cmd = pos->second;
  266. pos = this->Commands.find(sNewName);
  267. if (pos != this->Commands.end())
  268. {
  269. delete pos->second;
  270. this->Commands.erase(pos);
  271. }
  272. this->Commands.insert(RegisteredCommandsMap::value_type(sNewName, cmd));
  273. pos = this->Commands.find(sOldName);
  274. this->Commands.erase(pos);
  275. }
  276. void cmake::RemoveCommand(const char* name)
  277. {
  278. std::string sName = cmSystemTools::LowerCase(name);
  279. RegisteredCommandsMap::iterator pos = this->Commands.find(sName);
  280. if ( pos != this->Commands.end() )
  281. {
  282. delete pos->second;
  283. this->Commands.erase(pos);
  284. }
  285. }
  286. void cmake::AddCommand(cmCommand* wg)
  287. {
  288. std::string name = cmSystemTools::LowerCase(wg->GetName());
  289. // if the command already exists, free the old one
  290. RegisteredCommandsMap::iterator pos = this->Commands.find(name);
  291. if (pos != this->Commands.end())
  292. {
  293. delete pos->second;
  294. this->Commands.erase(pos);
  295. }
  296. this->Commands.insert( RegisteredCommandsMap::value_type(name, wg));
  297. }
  298. void cmake::RemoveUnscriptableCommands()
  299. {
  300. std::vector<std::string> unscriptableCommands;
  301. cmake::RegisteredCommandsMap* commands = this->GetCommands();
  302. for (cmake::RegisteredCommandsMap::const_iterator pos = commands->begin();
  303. pos != commands->end();
  304. ++pos)
  305. {
  306. if (!pos->second->IsScriptable())
  307. {
  308. unscriptableCommands.push_back(pos->first);
  309. }
  310. }
  311. for(std::vector<std::string>::const_iterator it=unscriptableCommands.begin();
  312. it != unscriptableCommands.end();
  313. ++it)
  314. {
  315. this->RemoveCommand(it->c_str());
  316. }
  317. }
  318. // Parse the args
  319. bool cmake::SetCacheArgs(const std::vector<std::string>& args)
  320. {
  321. bool findPackageMode = false;
  322. for(unsigned int i=1; i < args.size(); ++i)
  323. {
  324. std::string arg = args[i];
  325. if(arg.find("-D",0) == 0)
  326. {
  327. std::string entry = arg.substr(2);
  328. if(entry.size() == 0)
  329. {
  330. ++i;
  331. if(i < args.size())
  332. {
  333. entry = args[i];
  334. }
  335. else
  336. {
  337. cmSystemTools::Error("-D must be followed with VAR=VALUE.");
  338. return false;
  339. }
  340. }
  341. std::string var, value;
  342. cmCacheManager::CacheEntryType type = cmCacheManager::UNINITIALIZED;
  343. if(cmCacheManager::ParseEntry(entry.c_str(), var, value, type))
  344. {
  345. this->CacheManager->AddCacheEntry(var.c_str(), value.c_str(),
  346. "No help, variable specified on the command line.", type);
  347. if(this->WarnUnusedCli)
  348. {
  349. this->WatchUnusedCli(var.c_str());
  350. }
  351. }
  352. else
  353. {
  354. std::cerr << "Parse error in command line argument: " << arg << "\n"
  355. << "Should be: VAR:type=value\n";
  356. cmSystemTools::Error("No cmake script provided.");
  357. return false;
  358. }
  359. }
  360. else if(arg.find("-Wno-dev",0) == 0)
  361. {
  362. this->SuppressDevWarnings = true;
  363. this->DoSuppressDevWarnings = true;
  364. }
  365. else if(arg.find("-Wdev",0) == 0)
  366. {
  367. this->SuppressDevWarnings = false;
  368. this->DoSuppressDevWarnings = true;
  369. }
  370. else if(arg.find("-U",0) == 0)
  371. {
  372. std::string entryPattern = arg.substr(2);
  373. if(entryPattern.size() == 0)
  374. {
  375. ++i;
  376. if(i < args.size())
  377. {
  378. entryPattern = args[i];
  379. }
  380. else
  381. {
  382. cmSystemTools::Error("-U must be followed with VAR.");
  383. return false;
  384. }
  385. }
  386. cmsys::RegularExpression regex(
  387. cmsys::Glob::PatternToRegex(entryPattern.c_str(), true, true).c_str());
  388. //go through all cache entries and collect the vars which will be removed
  389. std::vector<std::string> entriesToDelete;
  390. cmCacheManager::CacheIterator it =
  391. this->CacheManager->GetCacheIterator();
  392. for ( it.Begin(); !it.IsAtEnd(); it.Next() )
  393. {
  394. cmCacheManager::CacheEntryType t = it.GetType();
  395. if(t != cmCacheManager::STATIC)
  396. {
  397. std::string entryName = it.GetName();
  398. if (regex.find(entryName.c_str()))
  399. {
  400. entriesToDelete.push_back(entryName);
  401. }
  402. }
  403. }
  404. // now remove them from the cache
  405. for(std::vector<std::string>::const_iterator currentEntry =
  406. entriesToDelete.begin();
  407. currentEntry != entriesToDelete.end();
  408. ++currentEntry)
  409. {
  410. this->CacheManager->RemoveCacheEntry(currentEntry->c_str());
  411. }
  412. }
  413. else if(arg.find("-C",0) == 0)
  414. {
  415. std::string path = arg.substr(2);
  416. if ( path.size() == 0 )
  417. {
  418. ++i;
  419. if(i < args.size())
  420. {
  421. path = args[i];
  422. }
  423. else
  424. {
  425. cmSystemTools::Error("-C must be followed by a file name.");
  426. return false;
  427. }
  428. }
  429. std::cerr << "loading initial cache file " << path.c_str() << "\n";
  430. this->ReadListFile(args, path.c_str());
  431. }
  432. else if(arg.find("-P",0) == 0)
  433. {
  434. i++;
  435. if(i >= args.size())
  436. {
  437. cmSystemTools::Error("-P must be followed by a file name.");
  438. return false;
  439. }
  440. std::string path = args[i];
  441. if ( path.size() == 0 )
  442. {
  443. cmSystemTools::Error("No cmake script provided.");
  444. return false;
  445. }
  446. this->ReadListFile(args, path.c_str());
  447. }
  448. else if (arg.find("--find-package",0) == 0)
  449. {
  450. findPackageMode = true;
  451. }
  452. }
  453. if (findPackageMode)
  454. {
  455. return this->FindPackage(args);
  456. }
  457. return true;
  458. }
  459. void cmake::ReadListFile(const std::vector<std::string>& args,
  460. const char *path)
  461. {
  462. // if a generator was not yet created, temporarily create one
  463. cmGlobalGenerator *gg = this->GetGlobalGenerator();
  464. bool created = false;
  465. // if a generator was not specified use a generic one
  466. if (!gg)
  467. {
  468. gg = new cmGlobalGenerator;
  469. gg->SetCMakeInstance(this);
  470. created = true;
  471. }
  472. // read in the list file to fill the cache
  473. if(path)
  474. {
  475. std::auto_ptr<cmLocalGenerator> lg(gg->CreateLocalGenerator());
  476. lg->GetMakefile()->SetHomeOutputDirectory
  477. (cmSystemTools::GetCurrentWorkingDirectory().c_str());
  478. lg->GetMakefile()->SetStartOutputDirectory
  479. (cmSystemTools::GetCurrentWorkingDirectory().c_str());
  480. lg->GetMakefile()->SetHomeDirectory
  481. (cmSystemTools::GetCurrentWorkingDirectory().c_str());
  482. lg->GetMakefile()->SetStartDirectory
  483. (cmSystemTools::GetCurrentWorkingDirectory().c_str());
  484. if (this->GetWorkingMode() != NORMAL_MODE)
  485. {
  486. std::string file(cmSystemTools::CollapseFullPath(path));
  487. cmSystemTools::ConvertToUnixSlashes(file);
  488. lg->GetMakefile()->SetScriptModeFile(file.c_str());
  489. lg->GetMakefile()->SetArgcArgv(args);
  490. }
  491. if (!lg->GetMakefile()->ReadListFile(0, path))
  492. {
  493. cmSystemTools::Error("Error processing file:", path);
  494. }
  495. }
  496. // free generic one if generated
  497. if (created)
  498. {
  499. delete gg;
  500. }
  501. }
  502. bool cmake::FindPackage(const std::vector<std::string>& args)
  503. {
  504. // if a generator was not yet created, temporarily create one
  505. cmGlobalGenerator *gg = new cmGlobalGenerator;
  506. gg->SetCMakeInstance(this);
  507. this->SetGlobalGenerator(gg);
  508. // read in the list file to fill the cache
  509. std::auto_ptr<cmLocalGenerator> lg(gg->CreateLocalGenerator());
  510. cmMakefile* mf = lg->GetMakefile();
  511. mf->SetHomeOutputDirectory
  512. (cmSystemTools::GetCurrentWorkingDirectory().c_str());
  513. mf->SetStartOutputDirectory
  514. (cmSystemTools::GetCurrentWorkingDirectory().c_str());
  515. mf->SetHomeDirectory
  516. (cmSystemTools::GetCurrentWorkingDirectory().c_str());
  517. mf->SetStartDirectory
  518. (cmSystemTools::GetCurrentWorkingDirectory().c_str());
  519. mf->SetArgcArgv(args);
  520. std::string systemFile = mf->GetModulesFile("CMakeFindPackageMode.cmake");
  521. mf->ReadListFile(0, systemFile.c_str());
  522. std::string language = mf->GetSafeDefinition("LANGUAGE");
  523. std::string mode = mf->GetSafeDefinition("MODE");
  524. std::string packageName = mf->GetSafeDefinition("NAME");
  525. bool packageFound = mf->IsOn("PACKAGE_FOUND");
  526. bool quiet = mf->IsOn("PACKAGE_QUIET");
  527. if (!packageFound)
  528. {
  529. if (!quiet)
  530. {
  531. printf("%s not found.\n", packageName.c_str());
  532. }
  533. }
  534. else if (mode == "EXIST")
  535. {
  536. if (!quiet)
  537. {
  538. printf("%s found.\n", packageName.c_str());
  539. }
  540. }
  541. else if (mode == "COMPILE")
  542. {
  543. std::string includes = mf->GetSafeDefinition("PACKAGE_INCLUDE_DIRS");
  544. std::vector<std::string> includeDirs;
  545. cmSystemTools::ExpandListArgument(includes, includeDirs);
  546. std::string includeFlags = lg->GetIncludeFlags(includeDirs,
  547. language.c_str(), false);
  548. std::string definitions = mf->GetSafeDefinition("PACKAGE_DEFINITIONS");
  549. printf("%s %s\n", includeFlags.c_str(), definitions.c_str());
  550. }
  551. else if (mode == "LINK")
  552. {
  553. const char* targetName = "dummy";
  554. std::vector<std::string> srcs;
  555. cmTarget* tgt = mf->AddExecutable(targetName, srcs, true);
  556. tgt->SetProperty("LINKER_LANGUAGE", language.c_str());
  557. std::string libs = mf->GetSafeDefinition("PACKAGE_LIBRARIES");
  558. std::vector<std::string> libList;
  559. cmSystemTools::ExpandListArgument(libs, libList);
  560. for(std::vector<std::string>::const_iterator libIt=libList.begin();
  561. libIt != libList.end();
  562. ++libIt)
  563. {
  564. mf->AddLinkLibraryForTarget(targetName, libIt->c_str(),
  565. cmTarget::GENERAL);
  566. }
  567. std::string linkLibs;
  568. std::string flags;
  569. std::string linkFlags;
  570. lg->GetTargetFlags(linkLibs, flags, linkFlags, *tgt);
  571. printf("%s\n", linkLibs.c_str() );
  572. /* if ( use_win32 )
  573. {
  574. tgt->SetProperty("WIN32_EXECUTABLE", "ON");
  575. }
  576. if ( use_macbundle)
  577. {
  578. tgt->SetProperty("MACOSX_BUNDLE", "ON");
  579. }*/
  580. }
  581. // free generic one if generated
  582. // this->SetGlobalGenerator(0); // setting 0-pointer is not possible
  583. // delete gg; // this crashes inside the cmake instance
  584. return packageFound;
  585. }
  586. // Parse the args
  587. void cmake::SetArgs(const std::vector<std::string>& args,
  588. bool directoriesSetBefore)
  589. {
  590. bool directoriesSet = directoriesSetBefore;
  591. for(unsigned int i=1; i < args.size(); ++i)
  592. {
  593. std::string arg = args[i];
  594. if(arg.find("-H",0) == 0)
  595. {
  596. directoriesSet = true;
  597. std::string path = arg.substr(2);
  598. path = cmSystemTools::CollapseFullPath(path.c_str());
  599. cmSystemTools::ConvertToUnixSlashes(path);
  600. this->SetHomeDirectory(path.c_str());
  601. }
  602. else if(arg.find("-S",0) == 0)
  603. {
  604. // There is no local generate anymore. Ignore -S option.
  605. }
  606. else if(arg.find("-O",0) == 0)
  607. {
  608. // There is no local generate anymore. Ignore -O option.
  609. }
  610. else if(arg.find("-B",0) == 0)
  611. {
  612. directoriesSet = true;
  613. std::string path = arg.substr(2);
  614. path = cmSystemTools::CollapseFullPath(path.c_str());
  615. cmSystemTools::ConvertToUnixSlashes(path);
  616. this->SetHomeOutputDirectory(path.c_str());
  617. }
  618. else if((i < args.size()-1) && (arg.find("--check-build-system",0) == 0))
  619. {
  620. this->CheckBuildSystemArgument = args[++i];
  621. this->ClearBuildSystem = (atoi(args[++i].c_str()) > 0);
  622. }
  623. else if((i < args.size()-1) && (arg.find("--check-stamp-file",0) == 0))
  624. {
  625. this->CheckStampFile = args[++i];
  626. }
  627. else if((i < args.size()-1) && (arg.find("--check-stamp-list",0) == 0))
  628. {
  629. this->CheckStampList = args[++i];
  630. }
  631. #if defined(CMAKE_HAVE_VS_GENERATORS)
  632. else if((i < args.size()-1) && (arg.find("--vs-solution-file",0) == 0))
  633. {
  634. this->VSSolutionFile = args[++i];
  635. }
  636. #endif
  637. else if(arg.find("-V",0) == 0)
  638. {
  639. this->Verbose = true;
  640. }
  641. else if(arg.find("-D",0) == 0)
  642. {
  643. // skip for now
  644. }
  645. else if(arg.find("-U",0) == 0)
  646. {
  647. // skip for now
  648. }
  649. else if(arg.find("-C",0) == 0)
  650. {
  651. // skip for now
  652. }
  653. else if(arg.find("-P",0) == 0)
  654. {
  655. // skip for now
  656. i++;
  657. }
  658. else if(arg.find("--find-package",0) == 0)
  659. {
  660. // skip for now
  661. i++;
  662. }
  663. else if(arg.find("-Wno-dev",0) == 0)
  664. {
  665. // skip for now
  666. }
  667. else if(arg.find("-Wdev",0) == 0)
  668. {
  669. // skip for now
  670. }
  671. else if(arg.find("--graphviz=",0) == 0)
  672. {
  673. std::string path = arg.substr(strlen("--graphviz="));
  674. path = cmSystemTools::CollapseFullPath(path.c_str());
  675. cmSystemTools::ConvertToUnixSlashes(path);
  676. this->GraphVizFile = path;
  677. if ( this->GraphVizFile.empty() )
  678. {
  679. cmSystemTools::Error("No file specified for --graphviz");
  680. }
  681. }
  682. else if(arg.find("--debug-trycompile",0) == 0)
  683. {
  684. std::cout << "debug trycompile on\n";
  685. this->DebugTryCompileOn();
  686. }
  687. else if(arg.find("--debug-output",0) == 0)
  688. {
  689. std::cout << "Running with debug output on.\n";
  690. this->SetDebugOutputOn(true);
  691. }
  692. else if(arg.find("--trace",0) == 0)
  693. {
  694. std::cout << "Running with trace output on.\n";
  695. this->SetTrace(true);
  696. }
  697. else if(arg.find("--warn-uninitialized",0) == 0)
  698. {
  699. std::cout << "Warn about uninitialized values.\n";
  700. this->SetWarnUninitialized(true);
  701. }
  702. else if(arg.find("--warn-unused-vars",0) == 0)
  703. {
  704. std::cout << "Finding unused variables.\n";
  705. this->SetWarnUnused(true);
  706. }
  707. else if(arg.find("--no-warn-unused-cli",0) == 0)
  708. {
  709. std::cout << "Not searching for unused variables given on the " <<
  710. "command line.\n";
  711. this->SetWarnUnusedCli(false);
  712. }
  713. else if(arg.find("--check-system-vars",0) == 0)
  714. {
  715. std::cout << "Also check system files when warning about unused and " <<
  716. "uninitialized variables.\n";
  717. this->SetCheckSystemVars(true);
  718. }
  719. else if(arg.find("-G",0) == 0)
  720. {
  721. std::string value = arg.substr(2);
  722. if(value.size() == 0)
  723. {
  724. ++i;
  725. if(i >= args.size())
  726. {
  727. cmSystemTools::Error("No generator specified for -G");
  728. return;
  729. }
  730. value = args[i];
  731. }
  732. cmGlobalGenerator* gen =
  733. this->CreateGlobalGenerator(value.c_str());
  734. if(!gen)
  735. {
  736. cmSystemTools::Error("Could not create named generator ",
  737. value.c_str());
  738. }
  739. else
  740. {
  741. this->SetGlobalGenerator(gen);
  742. }
  743. }
  744. // no option assume it is the path to the source
  745. else
  746. {
  747. directoriesSet = true;
  748. this->SetDirectoriesFromFile(arg.c_str());
  749. }
  750. }
  751. if(!directoriesSet)
  752. {
  753. this->SetHomeOutputDirectory
  754. (cmSystemTools::GetCurrentWorkingDirectory().c_str());
  755. this->SetStartOutputDirectory
  756. (cmSystemTools::GetCurrentWorkingDirectory().c_str());
  757. this->SetHomeDirectory
  758. (cmSystemTools::GetCurrentWorkingDirectory().c_str());
  759. this->SetStartDirectory
  760. (cmSystemTools::GetCurrentWorkingDirectory().c_str());
  761. }
  762. this->SetStartDirectory(this->GetHomeDirectory());
  763. this->SetStartOutputDirectory(this->GetHomeOutputDirectory());
  764. }
  765. //----------------------------------------------------------------------------
  766. void cmake::SetDirectoriesFromFile(const char* arg)
  767. {
  768. // Check if the argument refers to a CMakeCache.txt or
  769. // CMakeLists.txt file.
  770. std::string listPath;
  771. std::string cachePath;
  772. bool argIsFile = false;
  773. if(cmSystemTools::FileIsDirectory(arg))
  774. {
  775. std::string path = cmSystemTools::CollapseFullPath(arg);
  776. cmSystemTools::ConvertToUnixSlashes(path);
  777. std::string cacheFile = path;
  778. cacheFile += "/CMakeCache.txt";
  779. std::string listFile = path;
  780. listFile += "/CMakeLists.txt";
  781. if(cmSystemTools::FileExists(cacheFile.c_str()))
  782. {
  783. cachePath = path;
  784. }
  785. if(cmSystemTools::FileExists(listFile.c_str()))
  786. {
  787. listPath = path;
  788. }
  789. }
  790. else if(cmSystemTools::FileExists(arg))
  791. {
  792. argIsFile = true;
  793. std::string fullPath = cmSystemTools::CollapseFullPath(arg);
  794. std::string name = cmSystemTools::GetFilenameName(fullPath.c_str());
  795. name = cmSystemTools::LowerCase(name);
  796. if(name == "cmakecache.txt")
  797. {
  798. cachePath = cmSystemTools::GetFilenamePath(fullPath.c_str());
  799. }
  800. else if(name == "cmakelists.txt")
  801. {
  802. listPath = cmSystemTools::GetFilenamePath(fullPath.c_str());
  803. }
  804. }
  805. else
  806. {
  807. // Specified file or directory does not exist. Try to set things
  808. // up to produce a meaningful error message.
  809. std::string fullPath = cmSystemTools::CollapseFullPath(arg);
  810. std::string name = cmSystemTools::GetFilenameName(fullPath.c_str());
  811. name = cmSystemTools::LowerCase(name);
  812. if(name == "cmakecache.txt" || name == "cmakelists.txt")
  813. {
  814. argIsFile = true;
  815. listPath = cmSystemTools::GetFilenamePath(fullPath.c_str());
  816. }
  817. else
  818. {
  819. listPath = fullPath;
  820. }
  821. }
  822. // If there is a CMakeCache.txt file, use its settings.
  823. if(cachePath.length() > 0)
  824. {
  825. cmCacheManager* cachem = this->GetCacheManager();
  826. cmCacheManager::CacheIterator it = cachem->NewIterator();
  827. if(cachem->LoadCache(cachePath.c_str()) &&
  828. it.Find("CMAKE_HOME_DIRECTORY"))
  829. {
  830. this->SetHomeOutputDirectory(cachePath.c_str());
  831. this->SetStartOutputDirectory(cachePath.c_str());
  832. this->SetHomeDirectory(it.GetValue());
  833. this->SetStartDirectory(it.GetValue());
  834. return;
  835. }
  836. }
  837. // If there is a CMakeLists.txt file, use it as the source tree.
  838. if(listPath.length() > 0)
  839. {
  840. this->SetHomeDirectory(listPath.c_str());
  841. this->SetStartDirectory(listPath.c_str());
  842. if(argIsFile)
  843. {
  844. // Source CMakeLists.txt file given. It was probably dropped
  845. // onto the executable in a GUI. Default to an in-source build.
  846. this->SetHomeOutputDirectory(listPath.c_str());
  847. this->SetStartOutputDirectory(listPath.c_str());
  848. }
  849. else
  850. {
  851. // Source directory given on command line. Use current working
  852. // directory as build tree.
  853. std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
  854. this->SetHomeOutputDirectory(cwd.c_str());
  855. this->SetStartOutputDirectory(cwd.c_str());
  856. }
  857. return;
  858. }
  859. // We didn't find a CMakeLists.txt or CMakeCache.txt file from the
  860. // argument. Assume it is the path to the source tree, and use the
  861. // current working directory as the build tree.
  862. std::string full = cmSystemTools::CollapseFullPath(arg);
  863. std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
  864. this->SetHomeDirectory(full.c_str());
  865. this->SetStartDirectory(full.c_str());
  866. this->SetHomeOutputDirectory(cwd.c_str());
  867. this->SetStartOutputDirectory(cwd.c_str());
  868. }
  869. // at the end of this CMAKE_ROOT and CMAKE_COMMAND should be added to the
  870. // cache
  871. int cmake::AddCMakePaths()
  872. {
  873. // Find the cmake executable
  874. std::string cMakeSelf = cmSystemTools::GetExecutableDirectory();
  875. cMakeSelf = cmSystemTools::GetRealPath(cMakeSelf.c_str());
  876. cMakeSelf += "/cmake";
  877. cMakeSelf += cmSystemTools::GetExecutableExtension();
  878. #if __APPLE__
  879. // on the apple this might be the gui bundle
  880. if(!cmSystemTools::FileExists(cMakeSelf.c_str()))
  881. {
  882. cMakeSelf = cmSystemTools::GetExecutableDirectory();
  883. cMakeSelf = cmSystemTools::GetRealPath(cMakeSelf.c_str());
  884. cMakeSelf += "../../../..";
  885. cMakeSelf = cmSystemTools::GetRealPath(cMakeSelf.c_str());
  886. cMakeSelf = cmSystemTools::CollapseFullPath(cMakeSelf.c_str());
  887. cMakeSelf += "/cmake";
  888. std::cerr << cMakeSelf.c_str() << "\n";
  889. }
  890. #endif
  891. if(!cmSystemTools::FileExists(cMakeSelf.c_str()))
  892. {
  893. cmSystemTools::Error("CMake executable cannot be found at ",
  894. cMakeSelf.c_str());
  895. return 0;
  896. }
  897. // Save the value in the cache
  898. this->CacheManager->AddCacheEntry
  899. ("CMAKE_COMMAND",cMakeSelf.c_str(), "Path to CMake executable.",
  900. cmCacheManager::INTERNAL);
  901. // if the edit command is not yet in the cache,
  902. // or if CMakeEditCommand has been set on this object,
  903. // then set the CMAKE_EDIT_COMMAND in the cache
  904. // This will mean that the last gui to edit the cache
  905. // will be the one that make edit_cache uses.
  906. if(!this->GetCacheDefinition("CMAKE_EDIT_COMMAND")
  907. || !this->CMakeEditCommand.empty())
  908. {
  909. // Find and save the command to edit the cache
  910. std::string editCacheCommand;
  911. if(!this->CMakeEditCommand.empty())
  912. {
  913. editCacheCommand = cmSystemTools::GetFilenamePath(cMakeSelf)
  914. + std::string("/")
  915. + this->CMakeEditCommand
  916. + cmSystemTools::GetFilenameExtension(cMakeSelf);
  917. }
  918. if( !cmSystemTools::FileExists(editCacheCommand.c_str()))
  919. {
  920. editCacheCommand = cmSystemTools::GetFilenamePath(cMakeSelf) +
  921. "/ccmake" + cmSystemTools::GetFilenameExtension(cMakeSelf);
  922. }
  923. if( !cmSystemTools::FileExists(editCacheCommand.c_str()))
  924. {
  925. editCacheCommand = cmSystemTools::GetFilenamePath(cMakeSelf) +
  926. "/cmake-gui" + cmSystemTools::GetFilenameExtension(cMakeSelf);
  927. }
  928. if(cmSystemTools::FileExists(editCacheCommand.c_str()))
  929. {
  930. this->CacheManager->AddCacheEntry
  931. ("CMAKE_EDIT_COMMAND", editCacheCommand.c_str(),
  932. "Path to cache edit program executable.", cmCacheManager::INTERNAL);
  933. }
  934. }
  935. std::string ctestCommand = cmSystemTools::GetFilenamePath(cMakeSelf) +
  936. "/ctest" + cmSystemTools::GetFilenameExtension(cMakeSelf);
  937. if(cmSystemTools::FileExists(ctestCommand.c_str()))
  938. {
  939. this->CacheManager->AddCacheEntry
  940. ("CMAKE_CTEST_COMMAND", ctestCommand.c_str(),
  941. "Path to ctest program executable.", cmCacheManager::INTERNAL);
  942. }
  943. std::string cpackCommand = cmSystemTools::GetFilenamePath(cMakeSelf) +
  944. "/cpack" + cmSystemTools::GetFilenameExtension(cMakeSelf);
  945. if(cmSystemTools::FileExists(cpackCommand.c_str()))
  946. {
  947. this->CacheManager->AddCacheEntry
  948. ("CMAKE_CPACK_COMMAND", cpackCommand.c_str(),
  949. "Path to cpack program executable.", cmCacheManager::INTERNAL);
  950. }
  951. // do CMAKE_ROOT, look for the environment variable first
  952. std::string cMakeRoot;
  953. std::string modules;
  954. if (getenv("CMAKE_ROOT"))
  955. {
  956. cMakeRoot = getenv("CMAKE_ROOT");
  957. modules = cMakeRoot + "/Modules/CMake.cmake";
  958. }
  959. if(!cmSystemTools::FileExists(modules.c_str()))
  960. {
  961. // next try exe/..
  962. cMakeRoot = cmSystemTools::GetRealPath(cMakeSelf.c_str());
  963. cMakeRoot = cmSystemTools::GetProgramPath(cMakeRoot.c_str());
  964. std::string::size_type slashPos = cMakeRoot.rfind("/");
  965. if(slashPos != std::string::npos)
  966. {
  967. cMakeRoot = cMakeRoot.substr(0, slashPos);
  968. }
  969. // is there no Modules direcory there?
  970. modules = cMakeRoot + "/Modules/CMake.cmake";
  971. }
  972. if (!cmSystemTools::FileExists(modules.c_str()))
  973. {
  974. // try exe/../share/cmake
  975. cMakeRoot += CMAKE_DATA_DIR;
  976. modules = cMakeRoot + "/Modules/CMake.cmake";
  977. }
  978. #ifdef CMAKE_ROOT_DIR
  979. if (!cmSystemTools::FileExists(modules.c_str()))
  980. {
  981. // try compiled in root directory
  982. cMakeRoot = CMAKE_ROOT_DIR;
  983. modules = cMakeRoot + "/Modules/CMake.cmake";
  984. }
  985. #endif
  986. if (!cmSystemTools::FileExists(modules.c_str()))
  987. {
  988. // try
  989. cMakeRoot = cmSystemTools::GetProgramPath(cMakeSelf.c_str());
  990. cMakeRoot += CMAKE_DATA_DIR;
  991. modules = cMakeRoot + "/Modules/CMake.cmake";
  992. }
  993. if(!cmSystemTools::FileExists(modules.c_str()))
  994. {
  995. // next try exe
  996. cMakeRoot = cmSystemTools::GetProgramPath(cMakeSelf.c_str());
  997. // is there no Modules direcory there?
  998. modules = cMakeRoot + "/Modules/CMake.cmake";
  999. }
  1000. if (!cmSystemTools::FileExists(modules.c_str()))
  1001. {
  1002. // couldn't find modules
  1003. cmSystemTools::Error("Could not find CMAKE_ROOT !!!\n"
  1004. "CMake has most likely not been installed correctly.\n"
  1005. "Modules directory not found in\n",
  1006. cMakeRoot.c_str());
  1007. return 0;
  1008. }
  1009. this->CacheManager->AddCacheEntry
  1010. ("CMAKE_ROOT", cMakeRoot.c_str(),
  1011. "Path to CMake installation.", cmCacheManager::INTERNAL);
  1012. #ifdef _WIN32
  1013. std::string comspec = "cmw9xcom.exe";
  1014. cmSystemTools::SetWindows9xComspecSubstitute(comspec.c_str());
  1015. #endif
  1016. return 1;
  1017. }
  1018. void CMakeCommandUsage(const char* program)
  1019. {
  1020. cmOStringStream errorStream;
  1021. #ifdef CMAKE_BUILD_WITH_CMAKE
  1022. errorStream
  1023. << "cmake version " << cmVersion::GetCMakeVersion() << "\n";
  1024. #else
  1025. errorStream
  1026. << "cmake bootstrap\n";
  1027. #endif
  1028. // If you add new commands, change here,
  1029. // and in cmakemain.cxx in the options table
  1030. errorStream
  1031. << "Usage: " << program << " -E [command] [arguments ...]\n"
  1032. << "Available commands: \n"
  1033. << " chdir dir cmd [args]... - run command in a given directory\n"
  1034. << " compare_files file1 file2 - check if file1 is same as file2\n"
  1035. << " copy file destination - copy file to destination (either file "
  1036. "or directory)\n"
  1037. << " copy_directory source destination - copy directory 'source' "
  1038. "content to directory 'destination'\n"
  1039. << " copy_if_different in-file out-file - copy file if input has "
  1040. "changed\n"
  1041. << " echo [string]... - displays arguments as text\n"
  1042. << " echo_append [string]... - displays arguments as text but no new "
  1043. "line\n"
  1044. << " environment - display the current environment\n"
  1045. << " make_directory dir - create a directory\n"
  1046. << " md5sum file1 [...] - compute md5sum of files\n"
  1047. << " remove [-f] file1 file2 ... - remove the file(s), use -f to force "
  1048. "it\n"
  1049. << " remove_directory dir - remove a directory and its contents\n"
  1050. << " rename oldname newname - rename a file or directory "
  1051. "(on one volume)\n"
  1052. << " tar [cxt][vfz][cvfj] file.tar "
  1053. "file/dir1 file/dir2 ... - create a tar "
  1054. "archive\n"
  1055. << " time command [args] ... - run command and return elapsed time\n"
  1056. << " touch file - touch a file.\n"
  1057. << " touch_nocreate file - touch a file but do not create it.\n"
  1058. #if defined(_WIN32) && !defined(__CYGWIN__)
  1059. << "Available on Windows only:\n"
  1060. << " comspec - on windows 9x use this for RunCommand\n"
  1061. << " delete_regv key - delete registry value\n"
  1062. << " write_regv key value - write registry value\n"
  1063. #else
  1064. << "Available on UNIX only:\n"
  1065. << " create_symlink old new - create a symbolic link new -> old\n"
  1066. #endif
  1067. ;
  1068. cmSystemTools::Error(errorStream.str().c_str());
  1069. }
  1070. int cmake::ExecuteCMakeCommand(std::vector<std::string>& args)
  1071. {
  1072. // IF YOU ADD A NEW COMMAND, DOCUMENT IT ABOVE and in cmakemain.cxx
  1073. if (args.size() > 1)
  1074. {
  1075. // Copy file
  1076. if (args[1] == "copy" && args.size() == 4)
  1077. {
  1078. if(!cmSystemTools::cmCopyFile(args[2].c_str(), args[3].c_str()))
  1079. {
  1080. std::cerr << "Error copying file \"" << args[2].c_str()
  1081. << "\" to \"" << args[3].c_str() << "\".\n";
  1082. return 1;
  1083. }
  1084. return 0;
  1085. }
  1086. // Copy file if different.
  1087. if (args[1] == "copy_if_different" && args.size() == 4)
  1088. {
  1089. if(!cmSystemTools::CopyFileIfDifferent(args[2].c_str(),
  1090. args[3].c_str()))
  1091. {
  1092. std::cerr << "Error copying file (if different) from \""
  1093. << args[2].c_str() << "\" to \"" << args[3].c_str()
  1094. << "\".\n";
  1095. return 1;
  1096. }
  1097. return 0;
  1098. }
  1099. // Copy directory content
  1100. if (args[1] == "copy_directory" && args.size() == 4)
  1101. {
  1102. if(!cmSystemTools::CopyADirectory(args[2].c_str(), args[3].c_str()))
  1103. {
  1104. std::cerr << "Error copying directory from \""
  1105. << args[2].c_str() << "\" to \"" << args[3].c_str()
  1106. << "\".\n";
  1107. return 1;
  1108. }
  1109. return 0;
  1110. }
  1111. // Rename a file or directory
  1112. if (args[1] == "rename" && args.size() == 4)
  1113. {
  1114. if(!cmSystemTools::RenameFile(args[2].c_str(), args[3].c_str()))
  1115. {
  1116. std::string e = cmSystemTools::GetLastSystemError();
  1117. std::cerr << "Error renaming from \""
  1118. << args[2].c_str() << "\" to \"" << args[3].c_str()
  1119. << "\": " << e << "\n";
  1120. return 1;
  1121. }
  1122. return 0;
  1123. }
  1124. // Compare files
  1125. if (args[1] == "compare_files" && args.size() == 4)
  1126. {
  1127. if(cmSystemTools::FilesDiffer(args[2].c_str(), args[3].c_str()))
  1128. {
  1129. std::cerr << "Files \""
  1130. << args[2].c_str() << "\" to \"" << args[3].c_str()
  1131. << "\" are different.\n";
  1132. return 1;
  1133. }
  1134. return 0;
  1135. }
  1136. // Echo string
  1137. else if (args[1] == "echo" )
  1138. {
  1139. unsigned int cc;
  1140. const char* space = "";
  1141. for ( cc = 2; cc < args.size(); cc ++ )
  1142. {
  1143. std::cout << space << args[cc];
  1144. space = " ";
  1145. }
  1146. std::cout << std::endl;
  1147. return 0;
  1148. }
  1149. // Echo string no new line
  1150. else if (args[1] == "echo_append" )
  1151. {
  1152. unsigned int cc;
  1153. const char* space = "";
  1154. for ( cc = 2; cc < args.size(); cc ++ )
  1155. {
  1156. std::cout << space << args[cc];
  1157. space = " ";
  1158. }
  1159. return 0;
  1160. }
  1161. #if defined(CMAKE_BUILD_WITH_CMAKE)
  1162. // Command to create a symbolic link. Fails on platforms not
  1163. // supporting them.
  1164. else if (args[1] == "environment" )
  1165. {
  1166. std::vector<std::string> env = cmSystemTools::GetEnvironmentVariables();
  1167. std::vector<std::string>::iterator it;
  1168. for ( it = env.begin(); it != env.end(); ++ it )
  1169. {
  1170. std::cout << it->c_str() << std::endl;
  1171. }
  1172. return 0;
  1173. }
  1174. #endif
  1175. else if (args[1] == "make_directory" && args.size() == 3)
  1176. {
  1177. if(!cmSystemTools::MakeDirectory(args[2].c_str()))
  1178. {
  1179. std::cerr << "Error making directory \"" << args[2].c_str()
  1180. << "\".\n";
  1181. return 1;
  1182. }
  1183. return 0;
  1184. }
  1185. else if (args[1] == "remove_directory" && args.size() == 3)
  1186. {
  1187. if(cmSystemTools::FileIsDirectory(args[2].c_str()) &&
  1188. !cmSystemTools::RemoveADirectory(args[2].c_str()))
  1189. {
  1190. std::cerr << "Error removing directory \"" << args[2].c_str()
  1191. << "\".\n";
  1192. return 1;
  1193. }
  1194. return 0;
  1195. }
  1196. // Remove file
  1197. else if (args[1] == "remove" && args.size() > 2)
  1198. {
  1199. bool force = false;
  1200. for (std::string::size_type cc = 2; cc < args.size(); cc ++)
  1201. {
  1202. if(args[cc] == "\\-f" || args[cc] == "-f")
  1203. {
  1204. force = true;
  1205. }
  1206. else
  1207. {
  1208. // Complain if the file could not be removed, still exists,
  1209. // and the -f option was not given.
  1210. if(!cmSystemTools::RemoveFile(args[cc].c_str()) && !force &&
  1211. cmSystemTools::FileExists(args[cc].c_str()))
  1212. {
  1213. return 1;
  1214. }
  1215. }
  1216. }
  1217. return 0;
  1218. }
  1219. // Touch file
  1220. else if (args[1] == "touch" && args.size() > 2)
  1221. {
  1222. for (std::string::size_type cc = 2; cc < args.size(); cc ++)
  1223. {
  1224. // Complain if the file could not be removed, still exists,
  1225. // and the -f option was not given.
  1226. if(!cmSystemTools::Touch(args[cc].c_str(), true))
  1227. {
  1228. return 1;
  1229. }
  1230. }
  1231. return 0;
  1232. }
  1233. // Touch file
  1234. else if (args[1] == "touch_nocreate" && args.size() > 2)
  1235. {
  1236. for (std::string::size_type cc = 2; cc < args.size(); cc ++)
  1237. {
  1238. // Complain if the file could not be removed, still exists,
  1239. // and the -f option was not given.
  1240. if(!cmSystemTools::Touch(args[cc].c_str(), false))
  1241. {
  1242. return 1;
  1243. }
  1244. }
  1245. return 0;
  1246. }
  1247. // Clock command
  1248. else if (args[1] == "time" && args.size() > 2)
  1249. {
  1250. std::string command = args[2];
  1251. for (std::string::size_type cc = 3; cc < args.size(); cc ++)
  1252. {
  1253. command += " ";
  1254. command += args[cc];
  1255. }
  1256. clock_t clock_start, clock_finish;
  1257. time_t time_start, time_finish;
  1258. time(&time_start);
  1259. clock_start = clock();
  1260. int ret =0;
  1261. cmSystemTools::RunSingleCommand(command.c_str(), 0, &ret);
  1262. clock_finish = clock();
  1263. time(&time_finish);
  1264. double clocks_per_sec = static_cast<double>(CLOCKS_PER_SEC);
  1265. std::cout << "Elapsed time: "
  1266. << static_cast<long>(time_finish - time_start) << " s. (time)"
  1267. << ", "
  1268. << static_cast<double>(clock_finish - clock_start) / clocks_per_sec
  1269. << " s. (clock)"
  1270. << "\n";
  1271. return ret;
  1272. }
  1273. // Command to calculate the md5sum of a file
  1274. else if (args[1] == "md5sum" && args.size() >= 3)
  1275. {
  1276. char md5out[32];
  1277. int retval = 0;
  1278. for (std::string::size_type cc = 2; cc < args.size(); cc ++)
  1279. {
  1280. const char *filename = args[cc].c_str();
  1281. // Cannot compute md5sum of a directory
  1282. if(cmSystemTools::FileIsDirectory(filename))
  1283. {
  1284. std::cerr << "Error: " << filename << " is a directory" << std::endl;
  1285. retval++;
  1286. }
  1287. else if(!cmSystemTools::ComputeFileMD5(filename, md5out))
  1288. {
  1289. // To mimic md5sum behavior in a shell:
  1290. std::cerr << filename << ": No such file or directory" << std::endl;
  1291. retval++;
  1292. }
  1293. else
  1294. {
  1295. std::cout << std::string(md5out,32) << " " << filename << std::endl;
  1296. }
  1297. }
  1298. return retval;
  1299. }
  1300. // Command to change directory and run a program.
  1301. else if (args[1] == "chdir" && args.size() >= 4)
  1302. {
  1303. std::string directory = args[2];
  1304. if(!cmSystemTools::FileExists(directory.c_str()))
  1305. {
  1306. cmSystemTools::Error("Directory does not exist for chdir command: ",
  1307. args[2].c_str());
  1308. return 1;
  1309. }
  1310. std::string command = "\"";
  1311. command += args[3];
  1312. command += "\"";
  1313. for (std::string::size_type cc = 4; cc < args.size(); cc ++)
  1314. {
  1315. command += " \"";
  1316. command += args[cc];
  1317. command += "\"";
  1318. }
  1319. int retval = 0;
  1320. int timeout = 0;
  1321. if ( cmSystemTools::RunSingleCommand(command.c_str(), 0, &retval,
  1322. directory.c_str(), cmSystemTools::OUTPUT_MERGE, timeout) )
  1323. {
  1324. return retval;
  1325. }
  1326. return 1;
  1327. }
  1328. // Command to start progress for a build
  1329. else if (args[1] == "cmake_progress_start" && args.size() == 4)
  1330. {
  1331. // bascially remove the directory
  1332. std::string dirName = args[2];
  1333. dirName += "/Progress";
  1334. cmSystemTools::RemoveADirectory(dirName.c_str());
  1335. // is the last argument a filename that exists?
  1336. FILE *countFile = fopen(args[3].c_str(),"r");
  1337. int count;
  1338. if (countFile)
  1339. {
  1340. if (1!=fscanf(countFile,"%i",&count))
  1341. {
  1342. cmSystemTools::Message("Could not read from count file.");
  1343. }
  1344. fclose(countFile);
  1345. }
  1346. else
  1347. {
  1348. count = atoi(args[3].c_str());
  1349. }
  1350. if (count)
  1351. {
  1352. cmSystemTools::MakeDirectory(dirName.c_str());
  1353. // write the count into the directory
  1354. std::string fName = dirName;
  1355. fName += "/count.txt";
  1356. FILE *progFile = fopen(fName.c_str(),"w");
  1357. if (progFile)
  1358. {
  1359. fprintf(progFile,"%i\n",count);
  1360. fclose(progFile);
  1361. }
  1362. }
  1363. return 0;
  1364. }
  1365. // Command to report progress for a build
  1366. else if (args[1] == "cmake_progress_report" && args.size() >= 3)
  1367. {
  1368. std::string dirName = args[2];
  1369. dirName += "/Progress";
  1370. std::string fName;
  1371. FILE *progFile;
  1372. // read the count
  1373. fName = dirName;
  1374. fName += "/count.txt";
  1375. progFile = fopen(fName.c_str(),"r");
  1376. int count = 0;
  1377. if (!progFile)
  1378. {
  1379. return 0;
  1380. }
  1381. else
  1382. {
  1383. if (1!=fscanf(progFile,"%i",&count))
  1384. {
  1385. cmSystemTools::Message("Could not read from progress file.");
  1386. }
  1387. fclose(progFile);
  1388. }
  1389. unsigned int i;
  1390. for (i = 3; i < args.size(); ++i)
  1391. {
  1392. fName = dirName;
  1393. fName += "/";
  1394. fName += args[i];
  1395. progFile = fopen(fName.c_str(),"w");
  1396. if (progFile)
  1397. {
  1398. fprintf(progFile,"empty");
  1399. fclose(progFile);
  1400. }
  1401. }
  1402. int fileNum = static_cast<int>
  1403. (cmsys::Directory::GetNumberOfFilesInDirectory(dirName.c_str()));
  1404. if (count > 0)
  1405. {
  1406. // print the progress
  1407. fprintf(stdout,"[%3i%%] ",((fileNum-3)*100)/count);
  1408. }
  1409. return 0;
  1410. }
  1411. // Command to create a symbolic link. Fails on platforms not
  1412. // supporting them.
  1413. else if (args[1] == "create_symlink" && args.size() == 4)
  1414. {
  1415. const char* destinationFileName = args[3].c_str();
  1416. if ( cmSystemTools::FileExists(destinationFileName) )
  1417. {
  1418. if ( cmSystemTools::FileIsSymlink(destinationFileName) )
  1419. {
  1420. if ( !cmSystemTools::RemoveFile(destinationFileName) ||
  1421. cmSystemTools::FileExists(destinationFileName) )
  1422. {
  1423. return 0;
  1424. }
  1425. }
  1426. else
  1427. {
  1428. return 0;
  1429. }
  1430. }
  1431. return cmSystemTools::CreateSymlink(args[2].c_str(),
  1432. args[3].c_str())? 0:1;
  1433. }
  1434. // Internal CMake shared library support.
  1435. else if (args[1] == "cmake_symlink_library" && args.size() == 5)
  1436. {
  1437. return cmake::SymlinkLibrary(args);
  1438. }
  1439. // Internal CMake versioned executable support.
  1440. else if (args[1] == "cmake_symlink_executable" && args.size() == 4)
  1441. {
  1442. return cmake::SymlinkExecutable(args);
  1443. }
  1444. #if defined(CMAKE_HAVE_VS_GENERATORS)
  1445. // Internal CMake support for calling Visual Studio macros.
  1446. else if (args[1] == "cmake_call_visual_studio_macro" && args.size() >= 4)
  1447. {
  1448. // args[2] = full path to .sln file or "ALL"
  1449. // args[3] = name of Visual Studio macro to call
  1450. // args[4..args.size()-1] = [optional] args for Visual Studio macro
  1451. std::string macroArgs;
  1452. if (args.size() > 4)
  1453. {
  1454. macroArgs = args[4];
  1455. for (size_t i = 5; i < args.size(); ++i)
  1456. {
  1457. macroArgs += " ";
  1458. macroArgs += args[i];
  1459. }
  1460. }
  1461. return cmCallVisualStudioMacro::CallMacro(args[2], args[3],
  1462. macroArgs, true);
  1463. }
  1464. #endif
  1465. // Internal CMake dependency scanning support.
  1466. else if (args[1] == "cmake_depends" && args.size() >= 6)
  1467. {
  1468. // Use the make system's VERBOSE environment variable to enable
  1469. // verbose output. This can be skipped by also setting CMAKE_NO_VERBOSE
  1470. // (which is set by the Eclipse and KDevelop generators).
  1471. bool verbose = ((cmSystemTools::GetEnv("VERBOSE") != 0)
  1472. && (cmSystemTools::GetEnv("CMAKE_NO_VERBOSE") == 0));
  1473. // Create a cmake object instance to process dependencies.
  1474. cmake cm;
  1475. std::string gen;
  1476. std::string homeDir;
  1477. std::string startDir;
  1478. std::string homeOutDir;
  1479. std::string startOutDir;
  1480. std::string depInfo;
  1481. bool color = false;
  1482. if(args.size() >= 8)
  1483. {
  1484. // Full signature:
  1485. //
  1486. // -E cmake_depends <generator>
  1487. // <home-src-dir> <start-src-dir>
  1488. // <home-out-dir> <start-out-dir>
  1489. // <dep-info> [--color=$(COLOR)]
  1490. //
  1491. // All paths are provided.
  1492. gen = args[2];
  1493. homeDir = args[3];
  1494. startDir = args[4];
  1495. homeOutDir = args[5];
  1496. startOutDir = args[6];
  1497. depInfo = args[7];
  1498. if(args.size() >= 9 &&
  1499. args[8].length() >= 8 &&
  1500. args[8].substr(0, 8) == "--color=")
  1501. {
  1502. // Enable or disable color based on the switch value.
  1503. color = (args[8].size() == 8 ||
  1504. cmSystemTools::IsOn(args[8].substr(8).c_str()));
  1505. }
  1506. }
  1507. else
  1508. {
  1509. // Support older signature for existing makefiles:
  1510. //
  1511. // -E cmake_depends <generator>
  1512. // <home-out-dir> <start-out-dir>
  1513. // <dep-info>
  1514. //
  1515. // Just pretend the source directories are the same as the
  1516. // binary directories so at least scanning will work.
  1517. gen = args[2];
  1518. homeDir = args[3];
  1519. startDir = args[4];
  1520. homeOutDir = args[3];
  1521. startOutDir = args[3];
  1522. depInfo = args[5];
  1523. }
  1524. // Create a local generator configured for the directory in
  1525. // which dependencies will be scanned.
  1526. homeDir = cmSystemTools::CollapseFullPath(homeDir.c_str());
  1527. startDir = cmSystemTools::CollapseFullPath(startDir.c_str());
  1528. homeOutDir = cmSystemTools::CollapseFullPath(homeOutDir.c_str());
  1529. startOutDir = cmSystemTools::CollapseFullPath(startOutDir.c_str());
  1530. cm.SetHomeDirectory(homeDir.c_str());
  1531. cm.SetStartDirectory(startDir.c_str());
  1532. cm.SetHomeOutputDirectory(homeOutDir.c_str());
  1533. cm.SetStartOutputDirectory(startOutDir.c_str());
  1534. if(cmGlobalGenerator* ggd = cm.CreateGlobalGenerator(gen.c_str()))
  1535. {
  1536. cm.SetGlobalGenerator(ggd);
  1537. std::auto_ptr<cmLocalGenerator> lgd(ggd->CreateLocalGenerator());
  1538. lgd->GetMakefile()->SetStartDirectory(startDir.c_str());
  1539. lgd->GetMakefile()->SetStartOutputDirectory(startOutDir.c_str());
  1540. lgd->GetMakefile()->MakeStartDirectoriesCurrent();
  1541. // Actually scan dependencies.
  1542. return lgd->UpdateDependencies(depInfo.c_str(),
  1543. verbose, color)? 0 : 2;
  1544. }
  1545. return 1;
  1546. }
  1547. // Internal CMake link script support.
  1548. else if (args[1] == "cmake_link_script" && args.size() >= 3)
  1549. {
  1550. return cmake::ExecuteLinkScript(args);
  1551. }
  1552. // Internal CMake unimplemented feature notification.
  1553. else if (args[1] == "cmake_unimplemented_variable")
  1554. {
  1555. std::cerr << "Feature not implemented for this platform.";
  1556. if(args.size() == 3)
  1557. {
  1558. std::cerr << " Variable " << args[2] << " is not set.";
  1559. }
  1560. std::cerr << std::endl;
  1561. return 1;
  1562. }
  1563. else if (args[1] == "vs_link_exe")
  1564. {
  1565. return cmake::VisualStudioLink(args, 1);
  1566. }
  1567. else if (args[1] == "vs_link_dll")
  1568. {
  1569. return cmake::VisualStudioLink(args, 2);
  1570. }
  1571. #ifdef CMAKE_BUILD_WITH_CMAKE
  1572. // Internal CMake color makefile support.
  1573. else if (args[1] == "cmake_echo_color")
  1574. {
  1575. return cmake::ExecuteEchoColor(args);
  1576. }
  1577. else if (args[1] == "cmake_automoc")
  1578. {
  1579. cmQtAutomoc automoc;
  1580. automoc.Run(args[2].c_str());
  1581. return 0;
  1582. }
  1583. #endif
  1584. // Tar files
  1585. else if (args[1] == "tar" && args.size() > 3)
  1586. {
  1587. std::string flags = args[2];
  1588. std::string outFile = args[3];
  1589. std::vector<cmStdString> files;
  1590. for (std::string::size_type cc = 4; cc < args.size(); cc ++)
  1591. {
  1592. files.push_back(args[cc]);
  1593. }
  1594. bool gzip = false;
  1595. bool bzip2 = false;
  1596. bool verbose = false;
  1597. if ( flags.find_first_of('j') != flags.npos )
  1598. {
  1599. bzip2 = true;
  1600. }
  1601. if ( flags.find_first_of('z') != flags.npos )
  1602. {
  1603. gzip = true;
  1604. }
  1605. if ( flags.find_first_of('v') != flags.npos )
  1606. {
  1607. verbose = true;
  1608. }
  1609. if ( flags.find_first_of('t') != flags.npos )
  1610. {
  1611. if ( !cmSystemTools::ListTar(outFile.c_str(), gzip, verbose) )
  1612. {
  1613. cmSystemTools::Error("Problem creating tar: ", outFile.c_str());
  1614. return 1;
  1615. }
  1616. }
  1617. else if ( flags.find_first_of('c') != flags.npos )
  1618. {
  1619. if ( !cmSystemTools::CreateTar(
  1620. outFile.c_str(), files, gzip, bzip2, verbose) )
  1621. {
  1622. cmSystemTools::Error("Problem creating tar: ", outFile.c_str());
  1623. return 1;
  1624. }
  1625. }
  1626. else if ( flags.find_first_of('x') != flags.npos )
  1627. {
  1628. if ( !cmSystemTools::ExtractTar(
  1629. outFile.c_str(), gzip, verbose) )
  1630. {
  1631. cmSystemTools::Error("Problem extracting tar: ", outFile.c_str());
  1632. return 1;
  1633. }
  1634. #ifdef WIN32
  1635. // OK, on windows 7 after we untar some files,
  1636. // sometimes we can not rename the directory after
  1637. // the untar is done. This breaks the external project
  1638. // untar and rename code. So, by default we will wait
  1639. // 1/10th of a second after the untar. If CMAKE_UNTAR_DELAY
  1640. // is set in the env, its value will be used instead of 100.
  1641. int delay = 100;
  1642. const char* delayVar = cmSystemTools::GetEnv("CMAKE_UNTAR_DELAY");
  1643. if(delayVar)
  1644. {
  1645. delay = atoi(delayVar);
  1646. }
  1647. if(delay)
  1648. {
  1649. cmSystemTools::Delay(delay);
  1650. }
  1651. #endif
  1652. }
  1653. return 0;
  1654. }
  1655. #if defined(CMAKE_BUILD_WITH_CMAKE)
  1656. // Internal CMake Fortran module support.
  1657. else if (args[1] == "cmake_copy_f90_mod" && args.size() >= 4)
  1658. {
  1659. return cmDependsFortran::CopyModule(args)? 0 : 1;
  1660. }
  1661. #endif
  1662. #if defined(_WIN32) && !defined(__CYGWIN__)
  1663. // Write registry value
  1664. else if (args[1] == "write_regv" && args.size() > 3)
  1665. {
  1666. return cmSystemTools::WriteRegistryValue(args[2].c_str(),
  1667. args[3].c_str()) ? 0 : 1;
  1668. }
  1669. // Delete registry value
  1670. else if (args[1] == "delete_regv" && args.size() > 2)
  1671. {
  1672. return cmSystemTools::DeleteRegistryValue(args[2].c_str()) ? 0 : 1;
  1673. }
  1674. // Remove file
  1675. else if (args[1] == "comspec" && args.size() > 2)
  1676. {
  1677. unsigned int cc;
  1678. std::string command = args[2];
  1679. for ( cc = 3; cc < args.size(); cc ++ )
  1680. {
  1681. command += " " + args[cc];
  1682. }
  1683. return cmWin32ProcessExecution::Windows9xHack(command.c_str());
  1684. }
  1685. #endif
  1686. }
  1687. ::CMakeCommandUsage(args[0].c_str());
  1688. return 1;
  1689. }
  1690. void cmake::AddExtraGenerator(const char* name,
  1691. CreateExtraGeneratorFunctionType newFunction)
  1692. {
  1693. cmExternalMakefileProjectGenerator* extraGenerator = newFunction();
  1694. const std::vector<std::string>& supportedGlobalGenerators =
  1695. extraGenerator->GetSupportedGlobalGenerators();
  1696. for(std::vector<std::string>::const_iterator
  1697. it = supportedGlobalGenerators.begin();
  1698. it != supportedGlobalGenerators.end();
  1699. ++it )
  1700. {
  1701. std::string fullName = cmExternalMakefileProjectGenerator::
  1702. CreateFullGeneratorName(it->c_str(), name);
  1703. this->ExtraGenerators[fullName.c_str()] = newFunction;
  1704. }
  1705. delete extraGenerator;
  1706. }
  1707. void cmake::AddDefaultExtraGenerators()
  1708. {
  1709. #if defined(CMAKE_BUILD_WITH_CMAKE)
  1710. #if defined(_WIN32) && !defined(__CYGWIN__)
  1711. // e.g. kdevelop4 ?
  1712. #endif
  1713. this->AddExtraGenerator(cmExtraCodeBlocksGenerator::GetActualName(),
  1714. &cmExtraCodeBlocksGenerator::New);
  1715. #ifdef CMAKE_USE_ECLIPSE
  1716. this->AddExtraGenerator(cmExtraEclipseCDT4Generator::GetActualName(),
  1717. &cmExtraEclipseCDT4Generator::New);
  1718. #endif
  1719. #ifdef CMAKE_USE_KDEVELOP
  1720. this->AddExtraGenerator(cmGlobalKdevelopGenerator::GetActualName(),
  1721. &cmGlobalKdevelopGenerator::New);
  1722. // for kdevelop also add the generator with just the name of the
  1723. // extra generator, since it was this way since cmake 2.2
  1724. this->ExtraGenerators[cmGlobalKdevelopGenerator::GetActualName()]
  1725. = &cmGlobalKdevelopGenerator::New;
  1726. #endif
  1727. #endif
  1728. }
  1729. //----------------------------------------------------------------------------
  1730. void cmake::GetRegisteredGenerators(std::vector<std::string>& names)
  1731. {
  1732. for(RegisteredGeneratorsMap::const_iterator i = this->Generators.begin();
  1733. i != this->Generators.end(); ++i)
  1734. {
  1735. names.push_back(i->first);
  1736. }
  1737. for(RegisteredExtraGeneratorsMap::const_iterator
  1738. i = this->ExtraGenerators.begin();
  1739. i != this->ExtraGenerators.end(); ++i)
  1740. {
  1741. names.push_back(i->first);
  1742. }
  1743. }
  1744. cmGlobalGenerator* cmake::CreateGlobalGenerator(const char* name)
  1745. {
  1746. cmGlobalGenerator* generator = 0;
  1747. cmExternalMakefileProjectGenerator* extraGenerator = 0;
  1748. RegisteredGeneratorsMap::const_iterator genIt = this->Generators.find(name);
  1749. if(genIt == this->Generators.end())
  1750. {
  1751. RegisteredExtraGeneratorsMap::const_iterator extraGenIt =
  1752. this->ExtraGenerators.find(name);
  1753. if (extraGenIt == this->ExtraGenerators.end())
  1754. {
  1755. return 0;
  1756. }
  1757. extraGenerator = (extraGenIt->second)();
  1758. genIt=this->Generators.find(extraGenerator->GetGlobalGeneratorName(name));
  1759. if(genIt == this->Generators.end())
  1760. {
  1761. delete extraGenerator;
  1762. return 0;
  1763. }
  1764. }
  1765. generator = (genIt->second)();
  1766. generator->SetCMakeInstance(this);
  1767. generator->SetExternalMakefileProjectGenerator(extraGenerator);
  1768. return generator;
  1769. }
  1770. void cmake::SetHomeDirectory(const char* dir)
  1771. {
  1772. this->cmHomeDirectory = dir;
  1773. cmSystemTools::ConvertToUnixSlashes(this->cmHomeDirectory);
  1774. }
  1775. void cmake::SetHomeOutputDirectory(const char* lib)
  1776. {
  1777. this->HomeOutputDirectory = lib;
  1778. cmSystemTools::ConvertToUnixSlashes(this->HomeOutputDirectory);
  1779. }
  1780. void cmake::SetGlobalGenerator(cmGlobalGenerator *gg)
  1781. {
  1782. if(!gg)
  1783. {
  1784. cmSystemTools::Error("Error SetGlobalGenerator called with null");
  1785. return;
  1786. }
  1787. // delete the old generator
  1788. if (this->GlobalGenerator)
  1789. {
  1790. delete this->GlobalGenerator;
  1791. // restore the original environment variables CXX and CC
  1792. // Restor CC
  1793. std::string env = "CC=";
  1794. if(this->CCEnvironment.size())
  1795. {
  1796. env += this->CCEnvironment;
  1797. }
  1798. cmSystemTools::PutEnv(env.c_str());
  1799. env = "CXX=";
  1800. if(this->CXXEnvironment.size())
  1801. {
  1802. env += this->CXXEnvironment;
  1803. }
  1804. cmSystemTools::PutEnv(env.c_str());
  1805. }
  1806. // set the new
  1807. this->GlobalGenerator = gg;
  1808. // set the global flag for unix style paths on cmSystemTools as soon as
  1809. // the generator is set. This allows gmake to be used on windows.
  1810. cmSystemTools::SetForceUnixPaths
  1811. (this->GlobalGenerator->GetForceUnixPaths());
  1812. // Save the environment variables CXX and CC
  1813. const char* cxx = getenv("CXX");
  1814. const char* cc = getenv("CC");
  1815. if(cxx)
  1816. {
  1817. this->CXXEnvironment = cxx;
  1818. }
  1819. else
  1820. {
  1821. this->CXXEnvironment = "";
  1822. }
  1823. if(cc)
  1824. {
  1825. this->CCEnvironment = cc;
  1826. }
  1827. else
  1828. {
  1829. this->CCEnvironment = "";
  1830. }
  1831. // set the cmake instance just to be sure
  1832. gg->SetCMakeInstance(this);
  1833. }
  1834. int cmake::DoPreConfigureChecks()
  1835. {
  1836. // Make sure the Start directory contains a CMakeLists.txt file.
  1837. std::string srcList = this->GetHomeDirectory();
  1838. srcList += "/CMakeLists.txt";
  1839. if(!cmSystemTools::FileExists(srcList.c_str()))
  1840. {
  1841. cmOStringStream err;
  1842. if(cmSystemTools::FileIsDirectory(this->GetHomeDirectory()))
  1843. {
  1844. err << "The source directory \"" << this->GetHomeDirectory()
  1845. << "\" does not appear to contain CMakeLists.txt.\n";
  1846. }
  1847. else if(cmSystemTools::FileExists(this->GetHomeDirectory()))
  1848. {
  1849. err << "The source directory \"" << this->GetHomeDirectory()
  1850. << "\" is a file, not a directory.\n";
  1851. }
  1852. else
  1853. {
  1854. err << "The source directory \"" << this->GetHomeDirectory()
  1855. << "\" does not exist.\n";
  1856. }
  1857. err << "Specify --help for usage, or press the help button on the CMake "
  1858. "GUI.";
  1859. cmSystemTools::Error(err.str().c_str());
  1860. return -2;
  1861. }
  1862. // do a sanity check on some values
  1863. if(this->CacheManager->GetCacheValue("CMAKE_HOME_DIRECTORY"))
  1864. {
  1865. std::string cacheStart =
  1866. this->CacheManager->GetCacheValue("CMAKE_HOME_DIRECTORY");
  1867. cacheStart += "/CMakeLists.txt";
  1868. std::string currentStart = this->GetHomeDirectory();
  1869. currentStart += "/CMakeLists.txt";
  1870. if(!cmSystemTools::SameFile(cacheStart.c_str(), currentStart.c_str()))
  1871. {
  1872. std::string message = "The source \"";
  1873. message += currentStart;
  1874. message += "\" does not match the source \"";
  1875. message += cacheStart;
  1876. message += "\" used to generate cache. ";
  1877. message += "Re-run cmake with a different source directory.";
  1878. cmSystemTools::Error(message.c_str());
  1879. return -2;
  1880. }
  1881. }
  1882. else
  1883. {
  1884. return 0;
  1885. }
  1886. return 1;
  1887. }
  1888. struct SaveCacheEntry
  1889. {
  1890. std::string key;
  1891. std::string value;
  1892. std::string help;
  1893. cmCacheManager::CacheEntryType type;
  1894. };
  1895. int cmake::HandleDeleteCacheVariables(const char* var)
  1896. {
  1897. std::vector<std::string> argsSplit;
  1898. cmSystemTools::ExpandListArgument(std::string(var), argsSplit);
  1899. // erase the property to avoid infinite recursion
  1900. this->SetProperty("__CMAKE_DELETE_CACHE_CHANGE_VARS_", "");
  1901. if(this->GetIsInTryCompile())
  1902. {
  1903. return 0;
  1904. }
  1905. cmCacheManager::CacheIterator ci = this->CacheManager->NewIterator();
  1906. std::vector<SaveCacheEntry> saved;
  1907. cmOStringStream warning;
  1908. warning
  1909. << "You have changed variables that require your cache to be deleted.\n"
  1910. << "Configure will be re-run and you may have to reset some variables.\n"
  1911. << "The following variables have changed:\n";
  1912. for(std::vector<std::string>::iterator i = argsSplit.begin();
  1913. i != argsSplit.end(); ++i)
  1914. {
  1915. SaveCacheEntry save;
  1916. save.key = *i;
  1917. warning << *i << "= ";
  1918. i++;
  1919. save.value = *i;
  1920. warning << *i << "\n";
  1921. if(ci.Find(save.key.c_str()))
  1922. {
  1923. save.type = ci.GetType();
  1924. save.help = ci.GetProperty("HELPSTRING");
  1925. }
  1926. saved.push_back(save);
  1927. }
  1928. // remove the cache
  1929. this->CacheManager->DeleteCache(this->GetStartOutputDirectory());
  1930. // load the empty cache
  1931. this->LoadCache();
  1932. // restore the changed compilers
  1933. for(std::vector<SaveCacheEntry>::iterator i = saved.begin();
  1934. i != saved.end(); ++i)
  1935. {
  1936. this->AddCacheEntry(i->key.c_str(), i->value.c_str(),
  1937. i->help.c_str(), i->type);
  1938. }
  1939. cmSystemTools::Message(warning.str().c_str());
  1940. // avoid reconfigure if there were errors
  1941. if(!cmSystemTools::GetErrorOccuredFlag())
  1942. {
  1943. // re-run configure
  1944. return this->Configure();
  1945. }
  1946. return 0;
  1947. }
  1948. int cmake::Configure()
  1949. {
  1950. if(this->DoSuppressDevWarnings)
  1951. {
  1952. if(this->SuppressDevWarnings)
  1953. {
  1954. this->CacheManager->
  1955. AddCacheEntry("CMAKE_SUPPRESS_DEVELOPER_WARNINGS", "TRUE",
  1956. "Suppress Warnings that are meant for"
  1957. " the author of the CMakeLists.txt files.",
  1958. cmCacheManager::INTERNAL);
  1959. }
  1960. else
  1961. {
  1962. this->CacheManager->
  1963. AddCacheEntry("CMAKE_SUPPRESS_DEVELOPER_WARNINGS", "FALSE",
  1964. "Suppress Warnings that are meant for"
  1965. " the author of the CMakeLists.txt files.",
  1966. cmCacheManager::INTERNAL);
  1967. }
  1968. }
  1969. int ret = this->ActualConfigure();
  1970. const char* delCacheVars =
  1971. this->GetProperty("__CMAKE_DELETE_CACHE_CHANGE_VARS_");
  1972. if(delCacheVars && delCacheVars[0] != 0)
  1973. {
  1974. return this->HandleDeleteCacheVariables(delCacheVars);
  1975. }
  1976. return ret;
  1977. }
  1978. int cmake::ActualConfigure()
  1979. {
  1980. // Construct right now our path conversion table before it's too late:
  1981. this->UpdateConversionPathTable();
  1982. this->CleanupCommandsAndMacros();
  1983. int res = 0;
  1984. if ( this->GetWorkingMode() == NORMAL_MODE )
  1985. {
  1986. res = this->DoPreConfigureChecks();
  1987. }
  1988. if ( res < 0 )
  1989. {
  1990. return -2;
  1991. }
  1992. if ( !res )
  1993. {
  1994. this->CacheManager->AddCacheEntry
  1995. ("CMAKE_HOME_DIRECTORY",
  1996. this->GetHomeDirectory(),
  1997. "Start directory with the top level CMakeLists.txt file for this "
  1998. "project",
  1999. cmCacheManager::INTERNAL);
  2000. }
  2001. // no generator specified on the command line
  2002. if(!this->GlobalGenerator)
  2003. {
  2004. const char* genName =
  2005. this->CacheManager->GetCacheValue("CMAKE_GENERATOR");
  2006. const char* extraGenName =
  2007. this->CacheManager->GetCacheValue("CMAKE_EXTRA_GENERATOR");
  2008. if(genName)
  2009. {
  2010. std::string fullName = cmExternalMakefileProjectGenerator::
  2011. CreateFullGeneratorName(genName, extraGenName);
  2012. this->GlobalGenerator = this->CreateGlobalGenerator(fullName.c_str());
  2013. }
  2014. if(this->GlobalGenerator)
  2015. {
  2016. // set the global flag for unix style paths on cmSystemTools as
  2017. // soon as the generator is set. This allows gmake to be used
  2018. // on windows.
  2019. cmSystemTools::SetForceUnixPaths
  2020. (this->GlobalGenerator->GetForceUnixPaths());
  2021. }
  2022. else
  2023. {
  2024. #if defined(__BORLANDC__) && defined(_WIN32)
  2025. this->SetGlobalGenerator(new cmGlobalBorlandMakefileGenerator);
  2026. #elif defined(_WIN32) && !defined(__CYGWIN__) && !defined(CMAKE_BOOT_MINGW)
  2027. std::string installedCompiler;
  2028. // Try to find the newest VS installed on the computer and
  2029. // use that as a default if -G is not specified
  2030. const std::string vsregBase =
  2031. "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\";
  2032. std::vector<std::string> vsVerions;
  2033. vsVerions.push_back("VisualStudio\\");
  2034. vsVerions.push_back("VCExpress\\");
  2035. struct VSRegistryEntryName
  2036. {
  2037. const char* MSVersion;
  2038. const char* GeneratorName;
  2039. };
  2040. VSRegistryEntryName version[] = {
  2041. {"6.0", "Visual Studio 6"},
  2042. {"7.0", "Visual Studio 7"},
  2043. {"7.1", "Visual Studio 7 .NET 2003"},
  2044. {"8.0", "Visual Studio 8 2005"},
  2045. {"9.0", "Visual Studio 9 2008"},
  2046. {"10.0", "Visual Studio 10"},
  2047. {0, 0}};
  2048. for(size_t b=0; b < vsVerions.size() && installedCompiler.empty(); b++)
  2049. {
  2050. for(int i =0; version[i].MSVersion != 0; i++)
  2051. {
  2052. std::string reg = vsregBase + vsVerions[b] + version[i].MSVersion;
  2053. reg += ";InstallDir]";
  2054. cmSystemTools::ExpandRegistryValues(reg,
  2055. cmSystemTools::KeyWOW64_32);
  2056. if (!(reg == "/registry"))
  2057. {
  2058. installedCompiler = version[i].GeneratorName;
  2059. }
  2060. }
  2061. }
  2062. cmGlobalGenerator* gen
  2063. = this->CreateGlobalGenerator(installedCompiler.c_str());
  2064. if(!gen)
  2065. {
  2066. gen = new cmGlobalNMakeMakefileGenerator;
  2067. }
  2068. this->SetGlobalGenerator(gen);
  2069. std::cout << "-- Building for: " << gen->GetName() << "\n";
  2070. #else
  2071. this->SetGlobalGenerator(new cmGlobalUnixMakefileGenerator3);
  2072. #endif
  2073. }
  2074. if(!this->GlobalGenerator)
  2075. {
  2076. cmSystemTools::Error("Could not create generator");
  2077. return -1;
  2078. }
  2079. }
  2080. const char* genName = this->CacheManager->GetCacheValue("CMAKE_GENERATOR");
  2081. if(genName)
  2082. {
  2083. if(strcmp(this->GlobalGenerator->GetName(), genName) != 0)
  2084. {
  2085. std::string message = "Error: generator : ";
  2086. message += this->GlobalGenerator->GetName();
  2087. message += "\nDoes not match the generator used previously: ";
  2088. message += genName;
  2089. message +=
  2090. "\nEither remove the CMakeCache.txt file or choose a different"
  2091. " binary directory.";
  2092. cmSystemTools::Error(message.c_str());
  2093. return -2;
  2094. }
  2095. }
  2096. if(!this->CacheManager->GetCacheValue("CMAKE_GENERATOR"))
  2097. {
  2098. this->CacheManager->AddCacheEntry("CMAKE_GENERATOR",
  2099. this->GlobalGenerator->GetName(),
  2100. "Name of generator.",
  2101. cmCacheManager::INTERNAL);
  2102. this->CacheManager->AddCacheEntry("CMAKE_EXTRA_GENERATOR",
  2103. this->GlobalGenerator->GetExtraGeneratorName(),
  2104. "Name of external makefile project generator.",
  2105. cmCacheManager::INTERNAL);
  2106. }
  2107. // reset any system configuration information, except for when we are
  2108. // InTryCompile. With TryCompile the system info is taken from the parent's
  2109. // info to save time
  2110. if (!this->InTryCompile)
  2111. {
  2112. this->GlobalGenerator->ClearEnabledLanguages();
  2113. }
  2114. // Truncate log files
  2115. if (!this->InTryCompile)
  2116. {
  2117. this->TruncateOutputLog("CMakeOutput.log");
  2118. this->TruncateOutputLog("CMakeError.log");
  2119. }
  2120. // actually do the configure
  2121. this->GlobalGenerator->Configure();
  2122. // Before saving the cache
  2123. // if the project did not define one of the entries below, add them now
  2124. // so users can edit the values in the cache:
  2125. // We used to always present LIBRARY_OUTPUT_PATH and
  2126. // EXECUTABLE_OUTPUT_PATH. They are now documented as old-style and
  2127. // should no longer be used. Therefore we present them only if the
  2128. // project requires compatibility with CMake 2.4. We detect this
  2129. // here by looking for the old CMAKE_BACKWARDS_COMPATABILITY
  2130. // variable created when CMP0001 is not set to NEW.
  2131. if(this->GetCacheManager()->GetCacheValue("CMAKE_BACKWARDS_COMPATIBILITY"))
  2132. {
  2133. if(!this->CacheManager->GetCacheValue("LIBRARY_OUTPUT_PATH"))
  2134. {
  2135. this->CacheManager->AddCacheEntry
  2136. ("LIBRARY_OUTPUT_PATH", "",
  2137. "Single output directory for building all libraries.",
  2138. cmCacheManager::PATH);
  2139. }
  2140. if(!this->CacheManager->GetCacheValue("EXECUTABLE_OUTPUT_PATH"))
  2141. {
  2142. this->CacheManager->AddCacheEntry
  2143. ("EXECUTABLE_OUTPUT_PATH", "",
  2144. "Single output directory for building all executables.",
  2145. cmCacheManager::PATH);
  2146. }
  2147. }
  2148. if(!this->CacheManager->GetCacheValue("CMAKE_USE_RELATIVE_PATHS"))
  2149. {
  2150. this->CacheManager->AddCacheEntry
  2151. ("CMAKE_USE_RELATIVE_PATHS", "OFF",
  2152. "If true, cmake will use relative paths in makefiles and projects.",
  2153. cmCacheManager::BOOL);
  2154. cmCacheManager::CacheIterator it =
  2155. this->CacheManager->GetCacheIterator("CMAKE_USE_RELATIVE_PATHS");
  2156. if ( !it.PropertyExists("ADVANCED") )
  2157. {
  2158. it.SetProperty("ADVANCED", "1");
  2159. }
  2160. }
  2161. if(cmSystemTools::GetFatalErrorOccured() &&
  2162. (!this->CacheManager->GetCacheValue("CMAKE_MAKE_PROGRAM") ||
  2163. cmSystemTools::IsOff(this->CacheManager->
  2164. GetCacheValue("CMAKE_MAKE_PROGRAM"))))
  2165. {
  2166. // We must have a bad generator selection. Wipe the cache entry so the
  2167. // user can select another.
  2168. this->CacheManager->RemoveCacheEntry("CMAKE_GENERATOR");
  2169. this->CacheManager->RemoveCacheEntry("CMAKE_EXTRA_GENERATOR");
  2170. }
  2171. // only save the cache if there were no fatal errors
  2172. if ( this->GetWorkingMode() == NORMAL_MODE )
  2173. {
  2174. this->CacheManager->SaveCache(this->GetHomeOutputDirectory());
  2175. }
  2176. if ( !this->GraphVizFile.empty() )
  2177. {
  2178. std::cout << "Generate graphviz: " << this->GraphVizFile << std::endl;
  2179. this->GenerateGraphViz(this->GraphVizFile.c_str());
  2180. }
  2181. if(cmSystemTools::GetErrorOccuredFlag())
  2182. {
  2183. return -1;
  2184. }
  2185. return 0;
  2186. }
  2187. void cmake::PreLoadCMakeFiles()
  2188. {
  2189. std::vector<std::string> args;
  2190. std::string pre_load = this->GetHomeDirectory();
  2191. if ( pre_load.size() > 0 )
  2192. {
  2193. pre_load += "/PreLoad.cmake";
  2194. if ( cmSystemTools::FileExists(pre_load.c_str()) )
  2195. {
  2196. this->ReadListFile(args, pre_load.c_str());
  2197. }
  2198. }
  2199. pre_load = this->GetHomeOutputDirectory();
  2200. if ( pre_load.size() > 0 )
  2201. {
  2202. pre_load += "/PreLoad.cmake";
  2203. if ( cmSystemTools::FileExists(pre_load.c_str()) )
  2204. {
  2205. this->ReadListFile(args, pre_load.c_str());
  2206. }
  2207. }
  2208. }
  2209. // handle a command line invocation
  2210. int cmake::Run(const std::vector<std::string>& args, bool noconfigure)
  2211. {
  2212. // Process the arguments
  2213. this->SetArgs(args);
  2214. if(cmSystemTools::GetErrorOccuredFlag())
  2215. {
  2216. return -1;
  2217. }
  2218. // If we are given a stamp list file check if it is really out of date.
  2219. if(!this->CheckStampList.empty() &&
  2220. cmakeCheckStampList(this->CheckStampList.c_str()))
  2221. {
  2222. return 0;
  2223. }
  2224. // If we are given a stamp file check if it is really out of date.
  2225. if(!this->CheckStampFile.empty() &&
  2226. cmakeCheckStampFile(this->CheckStampFile.c_str()))
  2227. {
  2228. return 0;
  2229. }
  2230. // set the cmake command
  2231. this->CMakeCommand = args[0];
  2232. if ( this->GetWorkingMode() == NORMAL_MODE )
  2233. {
  2234. // load the cache
  2235. if(this->LoadCache() < 0)
  2236. {
  2237. cmSystemTools::Error("Error executing cmake::LoadCache(). Aborting.\n");
  2238. return -1;
  2239. }
  2240. }
  2241. else
  2242. {
  2243. this->AddCMakePaths();
  2244. }
  2245. // Add any cache args
  2246. if ( !this->SetCacheArgs(args) )
  2247. {
  2248. cmSystemTools::Error("Problem processing arguments. Aborting.\n");
  2249. return -1;
  2250. }
  2251. // In script mode we terminate after running the script.
  2252. if(this->GetWorkingMode() != NORMAL_MODE)
  2253. {
  2254. if(cmSystemTools::GetErrorOccuredFlag())
  2255. {
  2256. return -1;
  2257. }
  2258. else
  2259. {
  2260. return 0;
  2261. }
  2262. }
  2263. // If MAKEFLAGS are given in the environment, remove the environment
  2264. // variable. This will prevent try-compile from succeeding when it
  2265. // should fail (if "-i" is an option). We cannot simply test
  2266. // whether "-i" is given and remove it because some make programs
  2267. // encode the MAKEFLAGS variable in a strange way.
  2268. if(getenv("MAKEFLAGS"))
  2269. {
  2270. cmSystemTools::PutEnv("MAKEFLAGS=");
  2271. }
  2272. this->PreLoadCMakeFiles();
  2273. std::string systemFile = this->GetHomeOutputDirectory();
  2274. systemFile += "/CMakeSystem.cmake";
  2275. if ( noconfigure )
  2276. {
  2277. return 0;
  2278. }
  2279. // now run the global generate
  2280. // Check the state of the build system to see if we need to regenerate.
  2281. if(!this->CheckBuildSystem())
  2282. {
  2283. return 0;
  2284. }
  2285. // If we are doing global generate, we better set start and start
  2286. // output directory to the root of the project.
  2287. std::string oldstartdir = this->GetStartDirectory();
  2288. std::string oldstartoutputdir = this->GetStartOutputDirectory();
  2289. this->SetStartDirectory(this->GetHomeDirectory());
  2290. this->SetStartOutputDirectory(this->GetHomeOutputDirectory());
  2291. int ret = this->Configure();
  2292. if (ret || this->GetWorkingMode() != NORMAL_MODE)
  2293. {
  2294. #if defined(CMAKE_HAVE_VS_GENERATORS)
  2295. if(!this->VSSolutionFile.empty() && this->GlobalGenerator)
  2296. {
  2297. // CMake is running to regenerate a Visual Studio build tree
  2298. // during a build from the VS IDE. The build files cannot be
  2299. // regenerated, so we should stop the build.
  2300. cmSystemTools::Message(
  2301. "CMake Configure step failed. "
  2302. "Build files cannot be regenerated correctly. "
  2303. "Attempting to stop IDE build.");
  2304. cmGlobalVisualStudioGenerator* gg =
  2305. static_cast<cmGlobalVisualStudioGenerator*>(this->GlobalGenerator);
  2306. gg->CallVisualStudioMacro(cmGlobalVisualStudioGenerator::MacroStop,
  2307. this->VSSolutionFile.c_str());
  2308. }
  2309. #endif
  2310. return ret;
  2311. }
  2312. ret = this->Generate();
  2313. std::string message = "Build files have been written to: ";
  2314. message += this->GetHomeOutputDirectory();
  2315. this->UpdateProgress(message.c_str(), -1);
  2316. if(ret)
  2317. {
  2318. return ret;
  2319. }
  2320. this->SetStartDirectory(oldstartdir.c_str());
  2321. this->SetStartOutputDirectory(oldstartoutputdir.c_str());
  2322. return ret;
  2323. }
  2324. int cmake::Generate()
  2325. {
  2326. if(!this->GlobalGenerator)
  2327. {
  2328. return -1;
  2329. }
  2330. this->GlobalGenerator->Generate();
  2331. if(this->WarnUnusedCli)
  2332. {
  2333. this->RunCheckForUnusedVariables();
  2334. }
  2335. if(cmSystemTools::GetErrorOccuredFlag())
  2336. {
  2337. return -1;
  2338. }
  2339. if (this->GetProperty("REPORT_UNDEFINED_PROPERTIES"))
  2340. {
  2341. this->ReportUndefinedPropertyAccesses
  2342. (this->GetProperty("REPORT_UNDEFINED_PROPERTIES"));
  2343. }
  2344. // Save the cache again after a successful Generate so that any internal
  2345. // variables created during Generate are saved. (Specifically target GUIDs
  2346. // for the Visual Studio and Xcode generators.)
  2347. if ( this->GetWorkingMode() == NORMAL_MODE )
  2348. {
  2349. this->CacheManager->SaveCache(this->GetHomeOutputDirectory());
  2350. }
  2351. return 0;
  2352. }
  2353. void cmake::AddCacheEntry(const char* key, const char* value,
  2354. const char* helpString,
  2355. int type)
  2356. {
  2357. this->CacheManager->AddCacheEntry(key, value,
  2358. helpString,
  2359. cmCacheManager::CacheEntryType(type));
  2360. }
  2361. const char* cmake::GetCacheDefinition(const char* name) const
  2362. {
  2363. return this->CacheManager->GetCacheValue(name);
  2364. }
  2365. void cmake::AddDefaultCommands()
  2366. {
  2367. std::list<cmCommand*> commands;
  2368. GetBootstrapCommands(commands);
  2369. GetPredefinedCommands(commands);
  2370. for(std::list<cmCommand*>::iterator i = commands.begin();
  2371. i != commands.end(); ++i)
  2372. {
  2373. this->AddCommand(*i);
  2374. }
  2375. }
  2376. void cmake::AddDefaultGenerators()
  2377. {
  2378. #if defined(_WIN32) && !defined(__CYGWIN__)
  2379. # if !defined(CMAKE_BOOT_MINGW)
  2380. this->Generators[cmGlobalVisualStudio6Generator::GetActualName()] =
  2381. &cmGlobalVisualStudio6Generator::New;
  2382. this->Generators[cmGlobalVisualStudio7Generator::GetActualName()] =
  2383. &cmGlobalVisualStudio7Generator::New;
  2384. this->Generators[cmGlobalVisualStudio10Generator::GetActualName()] =
  2385. &cmGlobalVisualStudio10Generator::New;
  2386. this->Generators[cmGlobalVisualStudio10IA64Generator::GetActualName()] =
  2387. &cmGlobalVisualStudio10IA64Generator::New;
  2388. this->Generators[cmGlobalVisualStudio10Win64Generator::GetActualName()] =
  2389. &cmGlobalVisualStudio10Win64Generator::New;
  2390. this->Generators[cmGlobalVisualStudio11Generator::GetActualName()] =
  2391. &cmGlobalVisualStudio11Generator::New;
  2392. this->Generators[cmGlobalVisualStudio11Win64Generator::GetActualName()] =
  2393. &cmGlobalVisualStudio11Win64Generator::New;
  2394. this->Generators[cmGlobalVisualStudio71Generator::GetActualName()] =
  2395. &cmGlobalVisualStudio71Generator::New;
  2396. this->Generators[cmGlobalVisualStudio8Generator::GetActualName()] =
  2397. &cmGlobalVisualStudio8Generator::New;
  2398. this->Generators[cmGlobalVisualStudio9Generator::GetActualName()] =
  2399. &cmGlobalVisualStudio9Generator::New;
  2400. this->Generators[cmGlobalVisualStudio9IA64Generator::GetActualName()] =
  2401. &cmGlobalVisualStudio9IA64Generator::New;
  2402. this->Generators[cmGlobalVisualStudio9Win64Generator::GetActualName()] =
  2403. &cmGlobalVisualStudio9Win64Generator::New;
  2404. this->Generators[cmGlobalVisualStudio8Win64Generator::GetActualName()] =
  2405. &cmGlobalVisualStudio8Win64Generator::New;
  2406. this->Generators[cmGlobalBorlandMakefileGenerator::GetActualName()] =
  2407. &cmGlobalBorlandMakefileGenerator::New;
  2408. this->Generators[cmGlobalNMakeMakefileGenerator::GetActualName()] =
  2409. &cmGlobalNMakeMakefileGenerator::New;
  2410. this->Generators[cmGlobalJOMMakefileGenerator::GetActualName()] =
  2411. &cmGlobalJOMMakefileGenerator::New;
  2412. this->Generators[cmGlobalWatcomWMakeGenerator::GetActualName()] =
  2413. &cmGlobalWatcomWMakeGenerator::New;
  2414. # endif
  2415. this->Generators[cmGlobalMSYSMakefileGenerator::GetActualName()] =
  2416. &cmGlobalMSYSMakefileGenerator::New;
  2417. this->Generators[cmGlobalMinGWMakefileGenerator::GetActualName()] =
  2418. &cmGlobalMinGWMakefileGenerator::New;
  2419. #endif
  2420. this->Generators[cmGlobalUnixMakefileGenerator3::GetActualName()] =
  2421. &cmGlobalUnixMakefileGenerator3::New;
  2422. #ifdef CMAKE_USE_XCODE
  2423. this->Generators[cmGlobalXCodeGenerator::GetActualName()] =
  2424. &cmGlobalXCodeGenerator::New;
  2425. #endif
  2426. }
  2427. int cmake::LoadCache()
  2428. {
  2429. // could we not read the cache
  2430. if (!this->CacheManager->LoadCache(this->GetHomeOutputDirectory()))
  2431. {
  2432. // if it does exist, but isn;t readable then warn the user
  2433. std::string cacheFile = this->GetHomeOutputDirectory();
  2434. cacheFile += "/CMakeCache.txt";
  2435. if(cmSystemTools::FileExists(cacheFile.c_str()))
  2436. {
  2437. cmSystemTools::Error(
  2438. "There is a CMakeCache.txt file for the current binary tree but "
  2439. "cmake does not have permission to read it. Please check the "
  2440. "permissions of the directory you are trying to run CMake on.");
  2441. return -1;
  2442. }
  2443. }
  2444. if (this->CMakeCommand.size() < 2)
  2445. {
  2446. cmSystemTools::Error(
  2447. "cmake command was not specified prior to loading the cache in "
  2448. "cmake.cxx");
  2449. return -1;
  2450. }
  2451. // setup CMAKE_ROOT and CMAKE_COMMAND
  2452. if(!this->AddCMakePaths())
  2453. {
  2454. return -3;
  2455. }
  2456. return 0;
  2457. }
  2458. void cmake::SetProgressCallback(ProgressCallbackType f, void *cd)
  2459. {
  2460. this->ProgressCallback = f;
  2461. this->ProgressCallbackClientData = cd;
  2462. }
  2463. void cmake::UpdateProgress(const char *msg, float prog)
  2464. {
  2465. if(this->ProgressCallback && !this->InTryCompile)
  2466. {
  2467. (*this->ProgressCallback)(msg, prog, this->ProgressCallbackClientData);
  2468. return;
  2469. }
  2470. }
  2471. void cmake::GetCommandDocumentation(std::vector<cmDocumentationEntry>& v,
  2472. bool withCurrentCommands,
  2473. bool withCompatCommands) const
  2474. {
  2475. for(RegisteredCommandsMap::const_iterator j = this->Commands.begin();
  2476. j != this->Commands.end(); ++j)
  2477. {
  2478. if ((( withCompatCommands == false) && ( (*j).second->IsDiscouraged()))
  2479. || ((withCurrentCommands == false) && (!(*j).second->IsDiscouraged()))
  2480. || (!((*j).second->ShouldAppearInDocumentation()))
  2481. )
  2482. {
  2483. continue;
  2484. }
  2485. cmDocumentationEntry e((*j).second->GetName(),
  2486. (*j).second->GetTerseDocumentation(),
  2487. (*j).second->GetFullDocumentation());
  2488. v.push_back(e);
  2489. }
  2490. }
  2491. void cmake::GetPolicyDocumentation(std::vector<cmDocumentationEntry>& v)
  2492. {
  2493. this->Policies->GetDocumentation(v);
  2494. }
  2495. void cmake::GetPropertiesDocumentation(std::map<std::string,
  2496. cmDocumentationSection *>& v)
  2497. {
  2498. // loop over the properties and put them into the doc structure
  2499. std::map<cmProperty::ScopeType, cmPropertyDefinitionMap>::iterator i;
  2500. i = this->PropertyDefinitions.begin();
  2501. for (;i != this->PropertyDefinitions.end(); ++i)
  2502. {
  2503. i->second.GetPropertiesDocumentation(v);
  2504. }
  2505. }
  2506. void cmake::GetGeneratorDocumentation(std::vector<cmDocumentationEntry>& v)
  2507. {
  2508. for(RegisteredGeneratorsMap::const_iterator i = this->Generators.begin();
  2509. i != this->Generators.end(); ++i)
  2510. {
  2511. cmDocumentationEntry e;
  2512. cmGlobalGenerator* generator = (i->second)();
  2513. generator->GetDocumentation(e);
  2514. delete generator;
  2515. v.push_back(e);
  2516. }
  2517. for(RegisteredExtraGeneratorsMap::const_iterator
  2518. i = this->ExtraGenerators.begin(); i != this->ExtraGenerators.end(); ++i)
  2519. {
  2520. cmDocumentationEntry e;
  2521. cmExternalMakefileProjectGenerator* generator = (i->second)();
  2522. generator->GetDocumentation(e, i->first.c_str());
  2523. e.Name = i->first;
  2524. delete generator;
  2525. v.push_back(e);
  2526. }
  2527. }
  2528. void cmake::UpdateConversionPathTable()
  2529. {
  2530. // Update the path conversion table with any specified file:
  2531. const char* tablepath =
  2532. this->CacheManager->GetCacheValue("CMAKE_PATH_TRANSLATION_FILE");
  2533. if(tablepath)
  2534. {
  2535. std::ifstream table( tablepath );
  2536. if(!table)
  2537. {
  2538. cmSystemTools::Error("CMAKE_PATH_TRANSLATION_FILE set to ", tablepath,
  2539. ". CMake can not open file.");
  2540. cmSystemTools::ReportLastSystemError("CMake can not open file.");
  2541. }
  2542. else
  2543. {
  2544. std::string a, b;
  2545. while(!table.eof())
  2546. {
  2547. // two entries per line
  2548. table >> a; table >> b;
  2549. cmSystemTools::AddTranslationPath( a.c_str(), b.c_str());
  2550. }
  2551. }
  2552. }
  2553. }
  2554. //----------------------------------------------------------------------------
  2555. int cmake::CheckBuildSystem()
  2556. {
  2557. // We do not need to rerun CMake. Check dependency integrity. Use
  2558. // the make system's VERBOSE environment variable to enable verbose
  2559. // output. This can be skipped by setting CMAKE_NO_VERBOSE (which is set
  2560. // by the Eclipse and KDevelop generators).
  2561. bool verbose = ((cmSystemTools::GetEnv("VERBOSE") != 0)
  2562. && (cmSystemTools::GetEnv("CMAKE_NO_VERBOSE") == 0));
  2563. // This method will check the integrity of the build system if the
  2564. // option was given on the command line. It reads the given file to
  2565. // determine whether CMake should rerun.
  2566. // If no file is provided for the check, we have to rerun.
  2567. if(this->CheckBuildSystemArgument.size() == 0)
  2568. {
  2569. if(verbose)
  2570. {
  2571. cmOStringStream msg;
  2572. msg << "Re-run cmake no build system arguments\n";
  2573. cmSystemTools::Stdout(msg.str().c_str());
  2574. }
  2575. return 1;
  2576. }
  2577. // If the file provided does not exist, we have to rerun.
  2578. if(!cmSystemTools::FileExists(this->CheckBuildSystemArgument.c_str()))
  2579. {
  2580. if(verbose)
  2581. {
  2582. cmOStringStream msg;
  2583. msg << "Re-run cmake missing file: "
  2584. << this->CheckBuildSystemArgument.c_str() << "\n";
  2585. cmSystemTools::Stdout(msg.str().c_str());
  2586. }
  2587. return 1;
  2588. }
  2589. // Read the rerun check file and use it to decide whether to do the
  2590. // global generate.
  2591. cmake cm;
  2592. cmGlobalGenerator gg;
  2593. gg.SetCMakeInstance(&cm);
  2594. std::auto_ptr<cmLocalGenerator> lg(gg.CreateLocalGenerator());
  2595. cmMakefile* mf = lg->GetMakefile();
  2596. if(!mf->ReadListFile(0, this->CheckBuildSystemArgument.c_str()) ||
  2597. cmSystemTools::GetErrorOccuredFlag())
  2598. {
  2599. if(verbose)
  2600. {
  2601. cmOStringStream msg;
  2602. msg << "Re-run cmake error reading : "
  2603. << this->CheckBuildSystemArgument.c_str() << "\n";
  2604. cmSystemTools::Stdout(msg.str().c_str());
  2605. }
  2606. // There was an error reading the file. Just rerun.
  2607. return 1;
  2608. }
  2609. if(this->ClearBuildSystem)
  2610. {
  2611. // Get the generator used for this build system.
  2612. const char* genName = mf->GetDefinition("CMAKE_DEPENDS_GENERATOR");
  2613. if(!genName || genName[0] == '\0')
  2614. {
  2615. genName = "Unix Makefiles";
  2616. }
  2617. // Create the generator and use it to clear the dependencies.
  2618. std::auto_ptr<cmGlobalGenerator>
  2619. ggd(this->CreateGlobalGenerator(genName));
  2620. if(ggd.get())
  2621. {
  2622. std::auto_ptr<cmLocalGenerator> lgd(ggd->CreateLocalGenerator());
  2623. lgd->ClearDependencies(mf, verbose);
  2624. }
  2625. }
  2626. // If any byproduct of makefile generation is missing we must re-run.
  2627. std::vector<std::string> products;
  2628. if(const char* productStr = mf->GetDefinition("CMAKE_MAKEFILE_PRODUCTS"))
  2629. {
  2630. cmSystemTools::ExpandListArgument(productStr, products);
  2631. }
  2632. for(std::vector<std::string>::const_iterator pi = products.begin();
  2633. pi != products.end(); ++pi)
  2634. {
  2635. if(!(cmSystemTools::FileExists(pi->c_str()) ||
  2636. cmSystemTools::FileIsSymlink(pi->c_str())))
  2637. {
  2638. if(verbose)
  2639. {
  2640. cmOStringStream msg;
  2641. msg << "Re-run cmake, missing byproduct: " << *pi << "\n";
  2642. cmSystemTools::Stdout(msg.str().c_str());
  2643. }
  2644. return 1;
  2645. }
  2646. }
  2647. // Get the set of dependencies and outputs.
  2648. std::vector<std::string> depends;
  2649. std::vector<std::string> outputs;
  2650. const char* dependsStr = mf->GetDefinition("CMAKE_MAKEFILE_DEPENDS");
  2651. const char* outputsStr = mf->GetDefinition("CMAKE_MAKEFILE_OUTPUTS");
  2652. if(dependsStr && outputsStr)
  2653. {
  2654. cmSystemTools::ExpandListArgument(dependsStr, depends);
  2655. cmSystemTools::ExpandListArgument(outputsStr, outputs);
  2656. }
  2657. if(depends.empty() || outputs.empty())
  2658. {
  2659. // Not enough information was provided to do the test. Just rerun.
  2660. if(verbose)
  2661. {
  2662. cmOStringStream msg;
  2663. msg << "Re-run cmake no CMAKE_MAKEFILE_DEPENDS "
  2664. "or CMAKE_MAKEFILE_OUTPUTS :\n";
  2665. cmSystemTools::Stdout(msg.str().c_str());
  2666. }
  2667. return 1;
  2668. }
  2669. // Find the newest dependency.
  2670. std::vector<std::string>::iterator dep = depends.begin();
  2671. std::string dep_newest = *dep++;
  2672. for(;dep != depends.end(); ++dep)
  2673. {
  2674. int result = 0;
  2675. if(this->FileComparison->FileTimeCompare(dep_newest.c_str(),
  2676. dep->c_str(), &result))
  2677. {
  2678. if(result < 0)
  2679. {
  2680. dep_newest = *dep;
  2681. }
  2682. }
  2683. else
  2684. {
  2685. if(verbose)
  2686. {
  2687. cmOStringStream msg;
  2688. msg << "Re-run cmake: build system dependency is missing\n";
  2689. cmSystemTools::Stdout(msg.str().c_str());
  2690. }
  2691. return 1;
  2692. }
  2693. }
  2694. // Find the oldest output.
  2695. std::vector<std::string>::iterator out = outputs.begin();
  2696. std::string out_oldest = *out++;
  2697. for(;out != outputs.end(); ++out)
  2698. {
  2699. int result = 0;
  2700. if(this->FileComparison->FileTimeCompare(out_oldest.c_str(),
  2701. out->c_str(), &result))
  2702. {
  2703. if(result > 0)
  2704. {
  2705. out_oldest = *out;
  2706. }
  2707. }
  2708. else
  2709. {
  2710. if(verbose)
  2711. {
  2712. cmOStringStream msg;
  2713. msg << "Re-run cmake: build system output is missing\n";
  2714. cmSystemTools::Stdout(msg.str().c_str());
  2715. }
  2716. return 1;
  2717. }
  2718. }
  2719. // If any output is older than any dependency then rerun.
  2720. {
  2721. int result = 0;
  2722. if(!this->FileComparison->FileTimeCompare(out_oldest.c_str(),
  2723. dep_newest.c_str(),
  2724. &result) ||
  2725. result < 0)
  2726. {
  2727. if(verbose)
  2728. {
  2729. cmOStringStream msg;
  2730. msg << "Re-run cmake file: " << out_oldest.c_str()
  2731. << " older than: " << dep_newest.c_str() << "\n";
  2732. cmSystemTools::Stdout(msg.str().c_str());
  2733. }
  2734. return 1;
  2735. }
  2736. }
  2737. // No need to rerun.
  2738. return 0;
  2739. }
  2740. //----------------------------------------------------------------------------
  2741. void cmake::TruncateOutputLog(const char* fname)
  2742. {
  2743. std::string fullPath = this->GetHomeOutputDirectory();
  2744. fullPath += "/";
  2745. fullPath += fname;
  2746. struct stat st;
  2747. if ( ::stat(fullPath.c_str(), &st) )
  2748. {
  2749. return;
  2750. }
  2751. if ( !this->CacheManager->GetCacheValue("CMAKE_CACHEFILE_DIR") )
  2752. {
  2753. cmSystemTools::RemoveFile(fullPath.c_str());
  2754. return;
  2755. }
  2756. off_t fsize = st.st_size;
  2757. const off_t maxFileSize = 50 * 1024;
  2758. if ( fsize < maxFileSize )
  2759. {
  2760. //TODO: truncate file
  2761. return;
  2762. }
  2763. }
  2764. inline std::string removeQuotes(const std::string& s)
  2765. {
  2766. if(s[0] == '\"' && s[s.size()-1] == '\"')
  2767. {
  2768. return s.substr(1, s.size()-2);
  2769. }
  2770. return s;
  2771. }
  2772. std::string cmake::FindCMakeProgram(const char* name) const
  2773. {
  2774. std::string path;
  2775. if ((name) && (*name))
  2776. {
  2777. const cmMakefile* mf
  2778. = this->GetGlobalGenerator()->GetLocalGenerators()[0]->GetMakefile();
  2779. #ifdef CMAKE_BUILD_WITH_CMAKE
  2780. path = mf->GetRequiredDefinition("CMAKE_COMMAND");
  2781. path = removeQuotes(path);
  2782. path = cmSystemTools::GetFilenamePath(path.c_str());
  2783. path += "/";
  2784. path += name;
  2785. path += cmSystemTools::GetExecutableExtension();
  2786. if(!cmSystemTools::FileExists(path.c_str()))
  2787. {
  2788. path = mf->GetRequiredDefinition("CMAKE_COMMAND");
  2789. path = cmSystemTools::GetFilenamePath(path.c_str());
  2790. path += "/Debug/";
  2791. path += name;
  2792. path += cmSystemTools::GetExecutableExtension();
  2793. }
  2794. if(!cmSystemTools::FileExists(path.c_str()))
  2795. {
  2796. path = mf->GetRequiredDefinition("CMAKE_COMMAND");
  2797. path = cmSystemTools::GetFilenamePath(path.c_str());
  2798. path += "/Release/";
  2799. path += name;
  2800. path += cmSystemTools::GetExecutableExtension();
  2801. }
  2802. #else
  2803. // Only for bootstrap
  2804. path += mf->GetSafeDefinition("EXECUTABLE_OUTPUT_PATH");
  2805. path += "/";
  2806. path += name;
  2807. path += cmSystemTools::GetExecutableExtension();
  2808. #endif
  2809. }
  2810. return path;
  2811. }
  2812. const char* cmake::GetCTestCommand()
  2813. {
  2814. if ( this->CTestCommand.empty() )
  2815. {
  2816. this->CTestCommand = this->FindCMakeProgram("ctest");
  2817. }
  2818. if ( this->CTestCommand.empty() )
  2819. {
  2820. cmSystemTools::Error("Cannot find the CTest executable");
  2821. this->CTestCommand = "CTEST-COMMAND-NOT-FOUND";
  2822. }
  2823. return this->CTestCommand.c_str();
  2824. }
  2825. const char* cmake::GetCPackCommand()
  2826. {
  2827. if ( this->CPackCommand.empty() )
  2828. {
  2829. this->CPackCommand = this->FindCMakeProgram("cpack");
  2830. }
  2831. if ( this->CPackCommand.empty() )
  2832. {
  2833. cmSystemTools::Error("Cannot find the CPack executable");
  2834. this->CPackCommand = "CPACK-COMMAND-NOT-FOUND";
  2835. }
  2836. return this->CPackCommand.c_str();
  2837. }
  2838. const char* cmake::GetCMakeCommand()
  2839. {
  2840. return this->CMakeCommand.c_str();
  2841. }
  2842. void cmake::MarkCliAsUsed(const std::string& variable)
  2843. {
  2844. this->UsedCliVariables[variable] = true;
  2845. }
  2846. void cmake::GenerateGraphViz(const char* fileName) const
  2847. {
  2848. #ifdef CMAKE_BUILD_WITH_CMAKE
  2849. std::auto_ptr<cmGraphVizWriter> gvWriter(
  2850. new cmGraphVizWriter(this->GetGlobalGenerator()->GetLocalGenerators()));
  2851. std::string settingsFile = this->GetHomeOutputDirectory();
  2852. settingsFile += "/CMakeGraphVizOptions.cmake";
  2853. std::string fallbackSettingsFile = this->GetHomeDirectory();
  2854. fallbackSettingsFile += "/CMakeGraphVizOptions.cmake";
  2855. gvWriter->ReadSettings(settingsFile.c_str(), fallbackSettingsFile.c_str());
  2856. gvWriter->WritePerTargetFiles(fileName);
  2857. gvWriter->WriteTargetDependersFiles(fileName);
  2858. gvWriter->WriteGlobalFile(fileName);
  2859. #endif
  2860. }
  2861. //----------------------------------------------------------------------------
  2862. int cmake::SymlinkLibrary(std::vector<std::string>& args)
  2863. {
  2864. int result = 0;
  2865. std::string realName = args[2];
  2866. std::string soName = args[3];
  2867. std::string name = args[4];
  2868. if(soName != realName)
  2869. {
  2870. if(!cmake::SymlinkInternal(realName, soName))
  2871. {
  2872. cmSystemTools::ReportLastSystemError("cmake_symlink_library");
  2873. result = 1;
  2874. }
  2875. }
  2876. if(name != soName)
  2877. {
  2878. if(!cmake::SymlinkInternal(soName, name))
  2879. {
  2880. cmSystemTools::ReportLastSystemError("cmake_symlink_library");
  2881. result = 1;
  2882. }
  2883. }
  2884. return result;
  2885. }
  2886. //----------------------------------------------------------------------------
  2887. int cmake::SymlinkExecutable(std::vector<std::string>& args)
  2888. {
  2889. int result = 0;
  2890. std::string realName = args[2];
  2891. std::string name = args[3];
  2892. if(name != realName)
  2893. {
  2894. if(!cmake::SymlinkInternal(realName, name))
  2895. {
  2896. cmSystemTools::ReportLastSystemError("cmake_symlink_executable");
  2897. result = 1;
  2898. }
  2899. }
  2900. return result;
  2901. }
  2902. //----------------------------------------------------------------------------
  2903. bool cmake::SymlinkInternal(std::string const& file, std::string const& link)
  2904. {
  2905. if(cmSystemTools::FileExists(link.c_str()) ||
  2906. cmSystemTools::FileIsSymlink(link.c_str()))
  2907. {
  2908. cmSystemTools::RemoveFile(link.c_str());
  2909. }
  2910. #if defined(_WIN32) && !defined(__CYGWIN__)
  2911. return cmSystemTools::CopyFileAlways(file.c_str(), link.c_str());
  2912. #else
  2913. std::string linktext = cmSystemTools::GetFilenameName(file);
  2914. return cmSystemTools::CreateSymlink(linktext.c_str(), link.c_str());
  2915. #endif
  2916. }
  2917. //----------------------------------------------------------------------------
  2918. #ifdef CMAKE_BUILD_WITH_CMAKE
  2919. int cmake::ExecuteEchoColor(std::vector<std::string>& args)
  2920. {
  2921. // The arguments are
  2922. // argv[0] == <cmake-executable>
  2923. // argv[1] == cmake_echo_color
  2924. bool enabled = true;
  2925. int color = cmsysTerminal_Color_Normal;
  2926. bool newline = true;
  2927. for(unsigned int i=2; i < args.size(); ++i)
  2928. {
  2929. if(args[i].find("--switch=") == 0)
  2930. {
  2931. // Enable or disable color based on the switch value.
  2932. std::string value = args[i].substr(9);
  2933. if(!value.empty())
  2934. {
  2935. if(cmSystemTools::IsOn(value.c_str()))
  2936. {
  2937. enabled = true;
  2938. }
  2939. else
  2940. {
  2941. enabled = false;
  2942. }
  2943. }
  2944. }
  2945. else if(args[i] == "--normal")
  2946. {
  2947. color = cmsysTerminal_Color_Normal;
  2948. }
  2949. else if(args[i] == "--black")
  2950. {
  2951. color = cmsysTerminal_Color_ForegroundBlack;
  2952. }
  2953. else if(args[i] == "--red")
  2954. {
  2955. color = cmsysTerminal_Color_ForegroundRed;
  2956. }
  2957. else if(args[i] == "--green")
  2958. {
  2959. color = cmsysTerminal_Color_ForegroundGreen;
  2960. }
  2961. else if(args[i] == "--yellow")
  2962. {
  2963. color = cmsysTerminal_Color_ForegroundYellow;
  2964. }
  2965. else if(args[i] == "--blue")
  2966. {
  2967. color = cmsysTerminal_Color_ForegroundBlue;
  2968. }
  2969. else if(args[i] == "--magenta")
  2970. {
  2971. color = cmsysTerminal_Color_ForegroundMagenta;
  2972. }
  2973. else if(args[i] == "--cyan")
  2974. {
  2975. color = cmsysTerminal_Color_ForegroundCyan;
  2976. }
  2977. else if(args[i] == "--white")
  2978. {
  2979. color = cmsysTerminal_Color_ForegroundWhite;
  2980. }
  2981. else if(args[i] == "--bold")
  2982. {
  2983. color |= cmsysTerminal_Color_ForegroundBold;
  2984. }
  2985. else if(args[i] == "--no-newline")
  2986. {
  2987. newline = false;
  2988. }
  2989. else if(args[i] == "--newline")
  2990. {
  2991. newline = true;
  2992. }
  2993. else
  2994. {
  2995. // Color is enabled. Print with the current color.
  2996. cmSystemTools::MakefileColorEcho(color, args[i].c_str(),
  2997. newline, enabled);
  2998. }
  2999. }
  3000. return 0;
  3001. }
  3002. #else
  3003. int cmake::ExecuteEchoColor(std::vector<std::string>&)
  3004. {
  3005. return 1;
  3006. }
  3007. #endif
  3008. //----------------------------------------------------------------------------
  3009. int cmake::ExecuteLinkScript(std::vector<std::string>& args)
  3010. {
  3011. // The arguments are
  3012. // argv[0] == <cmake-executable>
  3013. // argv[1] == cmake_link_script
  3014. // argv[2] == <link-script-name>
  3015. // argv[3] == --verbose=?
  3016. bool verbose = false;
  3017. if(args.size() >= 4)
  3018. {
  3019. if(args[3].find("--verbose=") == 0)
  3020. {
  3021. if(!cmSystemTools::IsOff(args[3].substr(10).c_str()))
  3022. {
  3023. verbose = true;
  3024. }
  3025. }
  3026. }
  3027. // Allocate a process instance.
  3028. cmsysProcess* cp = cmsysProcess_New();
  3029. if(!cp)
  3030. {
  3031. std::cerr << "Error allocating process instance in link script."
  3032. << std::endl;
  3033. return 1;
  3034. }
  3035. // Children should share stdout and stderr with this process.
  3036. cmsysProcess_SetPipeShared(cp, cmsysProcess_Pipe_STDOUT, 1);
  3037. cmsysProcess_SetPipeShared(cp, cmsysProcess_Pipe_STDERR, 1);
  3038. // Run the command lines verbatim.
  3039. cmsysProcess_SetOption(cp, cmsysProcess_Option_Verbatim, 1);
  3040. // Read command lines from the script.
  3041. std::ifstream fin(args[2].c_str());
  3042. if(!fin)
  3043. {
  3044. std::cerr << "Error opening link script \""
  3045. << args[2] << "\"" << std::endl;
  3046. return 1;
  3047. }
  3048. // Run one command at a time.
  3049. std::string command;
  3050. int result = 0;
  3051. while(result == 0 && cmSystemTools::GetLineFromStream(fin, command))
  3052. {
  3053. // Setup this command line.
  3054. const char* cmd[2] = {command.c_str(), 0};
  3055. cmsysProcess_SetCommand(cp, cmd);
  3056. // Report the command if verbose output is enabled.
  3057. if(verbose)
  3058. {
  3059. std::cout << command << std::endl;
  3060. }
  3061. // Run the command and wait for it to exit.
  3062. cmsysProcess_Execute(cp);
  3063. cmsysProcess_WaitForExit(cp, 0);
  3064. // Report failure if any.
  3065. switch(cmsysProcess_GetState(cp))
  3066. {
  3067. case cmsysProcess_State_Exited:
  3068. {
  3069. int value = cmsysProcess_GetExitValue(cp);
  3070. if(value != 0)
  3071. {
  3072. result = value;
  3073. }
  3074. }
  3075. break;
  3076. case cmsysProcess_State_Exception:
  3077. std::cerr << "Error running link command: "
  3078. << cmsysProcess_GetExceptionString(cp) << std::endl;
  3079. result = 1;
  3080. break;
  3081. case cmsysProcess_State_Error:
  3082. std::cerr << "Error running link command: "
  3083. << cmsysProcess_GetErrorString(cp) << std::endl;
  3084. result = 2;
  3085. break;
  3086. default:
  3087. break;
  3088. };
  3089. }
  3090. // Free the process instance.
  3091. cmsysProcess_Delete(cp);
  3092. // Return the final resulting return value.
  3093. return result;
  3094. }
  3095. void cmake::DefineProperties(cmake *cm)
  3096. {
  3097. cm->DefineProperty
  3098. ("REPORT_UNDEFINED_PROPERTIES", cmProperty::GLOBAL,
  3099. "If set, report any undefined properties to this file.",
  3100. "If this property is set to a filename then when CMake runs "
  3101. "it will report any properties or variables that were accessed "
  3102. "but not defined into the filename specified in this property."
  3103. );
  3104. cm->DefineProperty
  3105. ("TARGET_SUPPORTS_SHARED_LIBS", cmProperty::GLOBAL,
  3106. "Does the target platform support shared libraries.",
  3107. "TARGET_SUPPORTS_SHARED_LIBS is a boolean specifying whether the target "
  3108. "platform supports shared libraries. Basically all current general "
  3109. "general purpose OS do so, the exception are usually embedded systems "
  3110. "with no or special OSs.");
  3111. cm->DefineProperty
  3112. ("TARGET_ARCHIVES_MAY_BE_SHARED_LIBS", cmProperty::GLOBAL,
  3113. "Set if shared libraries may be named like archives.",
  3114. "On AIX shared libraries may be named \"lib<name>.a\". "
  3115. "This property is set to true on such platforms.");
  3116. cm->DefineProperty
  3117. ("FIND_LIBRARY_USE_LIB64_PATHS", cmProperty::GLOBAL,
  3118. "Whether FIND_LIBRARY should automatically search lib64 directories.",
  3119. "FIND_LIBRARY_USE_LIB64_PATHS is a boolean specifying whether the "
  3120. "FIND_LIBRARY command should automatically search the lib64 variant of "
  3121. "directories called lib in the search path when building 64-bit "
  3122. "binaries.");
  3123. cm->DefineProperty
  3124. ("FIND_LIBRARY_USE_OPENBSD_VERSIONING", cmProperty::GLOBAL,
  3125. "Whether FIND_LIBRARY should find OpenBSD-style shared libraries.",
  3126. "This property is a boolean specifying whether the FIND_LIBRARY "
  3127. "command should find shared libraries with OpenBSD-style versioned "
  3128. "extension: \".so.<major>.<minor>\". "
  3129. "The property is set to true on OpenBSD and false on other platforms.");
  3130. cm->DefineProperty
  3131. ("ENABLED_FEATURES", cmProperty::GLOBAL,
  3132. "List of features which are enabled during the CMake run.",
  3133. "List of features which are enabled during the CMake run. Be default "
  3134. "it contains the names of all packages which were found. This is "
  3135. "determined using the <NAME>_FOUND variables. Packages which are "
  3136. "searched QUIET are not listed. A project can add its own features to "
  3137. "this list.This property is used by the macros in FeatureSummary.cmake.");
  3138. cm->DefineProperty
  3139. ("DISABLED_FEATURES", cmProperty::GLOBAL,
  3140. "List of features which are disabled during the CMake run.",
  3141. "List of features which are disabled during the CMake run. Be default "
  3142. "it contains the names of all packages which were not found. This is "
  3143. "determined using the <NAME>_FOUND variables. Packages which are "
  3144. "searched QUIET are not listed. A project can add its own features to "
  3145. "this list.This property is used by the macros in FeatureSummary.cmake.");
  3146. cm->DefineProperty
  3147. ("PACKAGES_FOUND", cmProperty::GLOBAL,
  3148. "List of packages which were found during the CMake run.",
  3149. "List of packages which were found during the CMake run. Whether a "
  3150. "package has been found is determined using the <NAME>_FOUND variables.");
  3151. cm->DefineProperty
  3152. ("PACKAGES_NOT_FOUND", cmProperty::GLOBAL,
  3153. "List of packages which were not found during the CMake run.",
  3154. "List of packages which were not found during the CMake run. Whether a "
  3155. "package has been found is determined using the <NAME>_FOUND variables.");
  3156. cm->DefineProperty(
  3157. "__CMAKE_DELETE_CACHE_CHANGE_VARS_", cmProperty::GLOBAL,
  3158. "Internal property",
  3159. "Used to detect compiler changes, Do not set.");
  3160. cm->DefineProperty(
  3161. "DEBUG_CONFIGURATIONS", cmProperty::GLOBAL,
  3162. "Specify which configurations are for debugging.",
  3163. "The value must be a semi-colon separated list of configuration names. "
  3164. "Currently this property is used only by the target_link_libraries "
  3165. "command (see its documentation for details). "
  3166. "Additional uses may be defined in the future. "
  3167. "\n"
  3168. "This property must be set at the top level of the project and before "
  3169. "the first target_link_libraries command invocation. "
  3170. "If any entry in the list does not match a valid configuration for "
  3171. "the project the behavior is undefined.");
  3172. cm->DefineProperty(
  3173. "GLOBAL_DEPENDS_DEBUG_MODE", cmProperty::GLOBAL,
  3174. "Enable global target dependency graph debug mode.",
  3175. "CMake automatically analyzes the global inter-target dependency graph "
  3176. "at the beginning of native build system generation. "
  3177. "This property causes it to display details of its analysis to stderr.");
  3178. cm->DefineProperty(
  3179. "GLOBAL_DEPENDS_NO_CYCLES", cmProperty::GLOBAL,
  3180. "Disallow global target dependency graph cycles.",
  3181. "CMake automatically analyzes the global inter-target dependency graph "
  3182. "at the beginning of native build system generation. "
  3183. "It reports an error if the dependency graph contains a cycle that "
  3184. "does not consist of all STATIC library targets. "
  3185. "This property tells CMake to disallow all cycles completely, even "
  3186. "among static libraries.");
  3187. cm->DefineProperty(
  3188. "ALLOW_DUPLICATE_CUSTOM_TARGETS", cmProperty::GLOBAL,
  3189. "Allow duplicate custom targets to be created.",
  3190. "Normally CMake requires that all targets built in a project have "
  3191. "globally unique logical names (see policy CMP0002). "
  3192. "This is necessary to generate meaningful project file names in "
  3193. "Xcode and VS IDE generators. "
  3194. "It also allows the target names to be referenced unambiguously.\n"
  3195. "Makefile generators are capable of supporting duplicate custom target "
  3196. "names. "
  3197. "For projects that care only about Makefile generators and do "
  3198. "not wish to support Xcode or VS IDE generators, one may set this "
  3199. "property to true to allow duplicate custom targets. "
  3200. "The property allows multiple add_custom_target command calls in "
  3201. "different directories to specify the same target name. "
  3202. "However, setting this property will cause non-Makefile generators "
  3203. "to produce an error and refuse to generate the project."
  3204. );
  3205. cm->DefineProperty
  3206. ("IN_TRY_COMPILE", cmProperty::GLOBAL,
  3207. "Read-only property that is true during a try-compile configuration.",
  3208. "True when building a project inside a TRY_COMPILE or TRY_RUN command.");
  3209. cm->DefineProperty
  3210. ("ENABLED_LANGUAGES", cmProperty::GLOBAL,
  3211. "Read-only property that contains the list of currently "
  3212. "enabled languages",
  3213. "Set to list of currently enabled languages.");
  3214. cm->DefineProperty
  3215. ("RULE_LAUNCH_COMPILE", cmProperty::GLOBAL,
  3216. "Specify a launcher for compile rules.",
  3217. "Makefile generators prefix compiler commands with the given "
  3218. "launcher command line. "
  3219. "This is intended to allow launchers to intercept build problems "
  3220. "with high granularity. "
  3221. "Non-Makefile generators currently ignore this property.");
  3222. cm->DefineProperty
  3223. ("RULE_LAUNCH_LINK", cmProperty::GLOBAL,
  3224. "Specify a launcher for link rules.",
  3225. "Makefile generators prefix link and archive commands with the given "
  3226. "launcher command line. "
  3227. "This is intended to allow launchers to intercept build problems "
  3228. "with high granularity. "
  3229. "Non-Makefile generators currently ignore this property.");
  3230. cm->DefineProperty
  3231. ("RULE_LAUNCH_CUSTOM", cmProperty::GLOBAL,
  3232. "Specify a launcher for custom rules.",
  3233. "Makefile generators prefix custom commands with the given "
  3234. "launcher command line. "
  3235. "This is intended to allow launchers to intercept build problems "
  3236. "with high granularity. "
  3237. "Non-Makefile generators currently ignore this property.");
  3238. cm->DefineProperty
  3239. ("RULE_MESSAGES", cmProperty::GLOBAL,
  3240. "Specify whether to report a message for each make rule.",
  3241. "This property specifies whether Makefile generators should add a "
  3242. "progress message describing what each build rule does. "
  3243. "If the property is not set the default is ON. "
  3244. "Set the property to OFF to disable granular messages and report only "
  3245. "as each target completes. "
  3246. "This is intended to allow scripted builds to avoid the build time "
  3247. "cost of detailed reports. "
  3248. "If a CMAKE_RULE_MESSAGES cache entry exists its value initializes "
  3249. "the value of this property. "
  3250. "Non-Makefile generators currently ignore this property.");
  3251. cm->DefineProperty
  3252. ("USE_FOLDERS", cmProperty::GLOBAL,
  3253. "Use the FOLDER target property to organize targets into folders.",
  3254. "If not set, CMake treats this property as OFF by default. "
  3255. "CMake generators that are capable of organizing into a "
  3256. "hierarchy of folders use the values of the FOLDER target "
  3257. "property to name those folders. See also the documentation "
  3258. "for the FOLDER target property.");
  3259. cm->DefineProperty
  3260. ("PREDEFINED_TARGETS_FOLDER", cmProperty::GLOBAL,
  3261. "Name of FOLDER for targets that are added automatically by CMake.",
  3262. "If not set, CMake uses \"CMakePredefinedTargets\" as a default "
  3263. "value for this property. Targets such as INSTALL, PACKAGE and "
  3264. "RUN_TESTS will be organized into this FOLDER. See also the "
  3265. "documentation for the FOLDER target property.");
  3266. // ================================================================
  3267. // define variables as well
  3268. // ================================================================
  3269. cmDocumentVariables::DefineVariables(cm);
  3270. }
  3271. void cmake::DefineProperty(const char *name, cmProperty::ScopeType scope,
  3272. const char *ShortDescription,
  3273. const char *FullDescription,
  3274. bool chained, const char *docSection)
  3275. {
  3276. this->PropertyDefinitions[scope].DefineProperty(name,scope,ShortDescription,
  3277. FullDescription,
  3278. docSection,
  3279. chained);
  3280. }
  3281. cmPropertyDefinition *cmake
  3282. ::GetPropertyDefinition(const char *name,
  3283. cmProperty::ScopeType scope)
  3284. {
  3285. if (this->IsPropertyDefined(name,scope))
  3286. {
  3287. return &(this->PropertyDefinitions[scope][name]);
  3288. }
  3289. return 0;
  3290. }
  3291. void cmake::RecordPropertyAccess(const char *name,
  3292. cmProperty::ScopeType scope)
  3293. {
  3294. this->AccessedProperties.insert
  3295. (std::pair<cmStdString,cmProperty::ScopeType>(name,scope));
  3296. }
  3297. void cmake::ReportUndefinedPropertyAccesses(const char *filename)
  3298. {
  3299. FILE *progFile = fopen(filename,"w");
  3300. if (!progFile || !this->GlobalGenerator)
  3301. {
  3302. return;
  3303. }
  3304. // what are the enabled languages?
  3305. std::vector<std::string> enLangs;
  3306. this->GlobalGenerator->GetEnabledLanguages(enLangs);
  3307. // Common configuration names.
  3308. // TODO: Compute current configuration(s).
  3309. std::vector<std::string> enConfigs;
  3310. enConfigs.push_back("");
  3311. enConfigs.push_back("DEBUG");
  3312. enConfigs.push_back("RELEASE");
  3313. enConfigs.push_back("MINSIZEREL");
  3314. enConfigs.push_back("RELWITHDEBINFO");
  3315. // take all the defined properties and add definitions for all the enabled
  3316. // languages
  3317. std::set<std::pair<cmStdString,cmProperty::ScopeType> > aliasedProperties;
  3318. std::map<cmProperty::ScopeType, cmPropertyDefinitionMap>::iterator i;
  3319. i = this->PropertyDefinitions.begin();
  3320. for (;i != this->PropertyDefinitions.end(); ++i)
  3321. {
  3322. cmPropertyDefinitionMap::iterator j;
  3323. for (j = i->second.begin(); j != i->second.end(); ++j)
  3324. {
  3325. // TODO: What if both <LANG> and <CONFIG> appear?
  3326. if (j->first.find("<CONFIG>") != std::string::npos)
  3327. {
  3328. std::vector<std::string>::const_iterator k;
  3329. for (k = enConfigs.begin(); k != enConfigs.end(); ++k)
  3330. {
  3331. std::string tmp = j->first;
  3332. cmSystemTools::ReplaceString(tmp, "<CONFIG>", k->c_str());
  3333. // add alias
  3334. aliasedProperties.insert
  3335. (std::pair<cmStdString,cmProperty::ScopeType>(tmp,i->first));
  3336. }
  3337. }
  3338. if (j->first.find("<LANG>") != std::string::npos)
  3339. {
  3340. std::vector<std::string>::const_iterator k;
  3341. for (k = enLangs.begin(); k != enLangs.end(); ++k)
  3342. {
  3343. std::string tmp = j->first;
  3344. cmSystemTools::ReplaceString(tmp, "<LANG>", k->c_str());
  3345. // add alias
  3346. aliasedProperties.insert
  3347. (std::pair<cmStdString,cmProperty::ScopeType>(tmp,i->first));
  3348. }
  3349. }
  3350. }
  3351. }
  3352. std::set<std::pair<cmStdString,cmProperty::ScopeType> >::const_iterator ap;
  3353. ap = this->AccessedProperties.begin();
  3354. for (;ap != this->AccessedProperties.end(); ++ap)
  3355. {
  3356. if (!this->IsPropertyDefined(ap->first.c_str(),ap->second) &&
  3357. aliasedProperties.find(std::pair<cmStdString,cmProperty::ScopeType>
  3358. (ap->first,ap->second)) ==
  3359. aliasedProperties.end())
  3360. {
  3361. const char *scopeStr = "";
  3362. switch (ap->second)
  3363. {
  3364. case cmProperty::TARGET:
  3365. scopeStr = "TARGET";
  3366. break;
  3367. case cmProperty::SOURCE_FILE:
  3368. scopeStr = "SOURCE_FILE";
  3369. break;
  3370. case cmProperty::DIRECTORY:
  3371. scopeStr = "DIRECTORY";
  3372. break;
  3373. case cmProperty::TEST:
  3374. scopeStr = "TEST";
  3375. break;
  3376. case cmProperty::VARIABLE:
  3377. scopeStr = "VARIABLE";
  3378. break;
  3379. case cmProperty::CACHED_VARIABLE:
  3380. scopeStr = "CACHED_VARIABLE";
  3381. break;
  3382. default:
  3383. scopeStr = "unknown";
  3384. break;
  3385. }
  3386. fprintf(progFile, "%s with scope %s\n", ap->first.c_str(), scopeStr);
  3387. }
  3388. }
  3389. fclose(progFile);
  3390. }
  3391. bool cmake::IsPropertyDefined(const char *name, cmProperty::ScopeType scope)
  3392. {
  3393. return this->PropertyDefinitions[scope].IsPropertyDefined(name);
  3394. }
  3395. bool cmake::IsPropertyChained(const char *name, cmProperty::ScopeType scope)
  3396. {
  3397. return this->PropertyDefinitions[scope].IsPropertyChained(name);
  3398. }
  3399. void cmake::SetProperty(const char* prop, const char* value)
  3400. {
  3401. if (!prop)
  3402. {
  3403. return;
  3404. }
  3405. // Special hook to invalidate cached value.
  3406. if(strcmp(prop, "DEBUG_CONFIGURATIONS") == 0)
  3407. {
  3408. this->DebugConfigs.clear();
  3409. }
  3410. this->Properties.SetProperty(prop, value, cmProperty::GLOBAL);
  3411. }
  3412. void cmake::AppendProperty(const char* prop, const char* value, bool asString)
  3413. {
  3414. if (!prop)
  3415. {
  3416. return;
  3417. }
  3418. // Special hook to invalidate cached value.
  3419. if(strcmp(prop, "DEBUG_CONFIGURATIONS") == 0)
  3420. {
  3421. this->DebugConfigs.clear();
  3422. }
  3423. this->Properties.AppendProperty(prop, value, cmProperty::GLOBAL, asString);
  3424. }
  3425. const char *cmake::GetProperty(const char* prop)
  3426. {
  3427. return this->GetProperty(prop, cmProperty::GLOBAL);
  3428. }
  3429. const char *cmake::GetProperty(const char* prop, cmProperty::ScopeType scope)
  3430. {
  3431. if(!prop)
  3432. {
  3433. return 0;
  3434. }
  3435. bool chain = false;
  3436. // watch for special properties
  3437. std::string propname = prop;
  3438. std::string output = "";
  3439. if ( propname == "CACHE_VARIABLES" )
  3440. {
  3441. cmCacheManager::CacheIterator cit =
  3442. this->GetCacheManager()->GetCacheIterator();
  3443. for ( cit.Begin(); !cit.IsAtEnd(); cit.Next() )
  3444. {
  3445. if ( output.size() )
  3446. {
  3447. output += ";";
  3448. }
  3449. output += cit.GetName();
  3450. }
  3451. this->SetProperty("CACHE_VARIABLES", output.c_str());
  3452. }
  3453. else if ( propname == "COMMANDS" )
  3454. {
  3455. cmake::RegisteredCommandsMap::iterator cmds
  3456. = this->GetCommands()->begin();
  3457. for (unsigned int cc=0 ; cmds != this->GetCommands()->end(); ++ cmds )
  3458. {
  3459. if ( cc > 0 )
  3460. {
  3461. output += ";";
  3462. }
  3463. output += cmds->first.c_str();
  3464. cc++;
  3465. }
  3466. this->SetProperty("COMMANDS",output.c_str());
  3467. }
  3468. else if ( propname == "IN_TRY_COMPILE" )
  3469. {
  3470. this->SetProperty("IN_TRY_COMPILE",
  3471. this->GetIsInTryCompile()? "1":"0");
  3472. }
  3473. else if ( propname == "ENABLED_LANGUAGES" )
  3474. {
  3475. std::string lang;
  3476. if(this->GlobalGenerator)
  3477. {
  3478. std::vector<std::string> enLangs;
  3479. this->GlobalGenerator->GetEnabledLanguages(enLangs);
  3480. const char* sep = "";
  3481. for(std::vector<std::string>::iterator i = enLangs.begin();
  3482. i != enLangs.end(); ++i)
  3483. {
  3484. lang += sep;
  3485. sep = ";";
  3486. lang += *i;
  3487. }
  3488. }
  3489. this->SetProperty("ENABLED_LANGUAGES", lang.c_str());
  3490. }
  3491. return this->Properties.GetPropertyValue(prop, scope, chain);
  3492. }
  3493. bool cmake::GetPropertyAsBool(const char* prop)
  3494. {
  3495. return cmSystemTools::IsOn(this->GetProperty(prop));
  3496. }
  3497. int cmake::GetSystemInformation(std::vector<std::string>& args)
  3498. {
  3499. // so create the directory
  3500. std::string resultFile;
  3501. std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
  3502. std::string destPath = cwd + "/__cmake_systeminformation";
  3503. cmSystemTools::RemoveADirectory(destPath.c_str());
  3504. if (!cmSystemTools::MakeDirectory(destPath.c_str()))
  3505. {
  3506. std::cerr << "Error: --system-information must be run from a "
  3507. "writable directory!\n";
  3508. return 1;
  3509. }
  3510. // process the arguments
  3511. bool writeToStdout = true;
  3512. for(unsigned int i=1; i < args.size(); ++i)
  3513. {
  3514. std::string arg = args[i];
  3515. if(arg.find("-V",0) == 0)
  3516. {
  3517. this->Verbose = true;
  3518. }
  3519. else if(arg.find("-G",0) == 0)
  3520. {
  3521. std::string value = arg.substr(2);
  3522. if(value.size() == 0)
  3523. {
  3524. ++i;
  3525. if(i >= args.size())
  3526. {
  3527. cmSystemTools::Error("No generator specified for -G");
  3528. return -1;
  3529. }
  3530. value = args[i];
  3531. }
  3532. cmGlobalGenerator* gen =
  3533. this->CreateGlobalGenerator(value.c_str());
  3534. if(!gen)
  3535. {
  3536. cmSystemTools::Error("Could not create named generator ",
  3537. value.c_str());
  3538. }
  3539. else
  3540. {
  3541. this->SetGlobalGenerator(gen);
  3542. }
  3543. }
  3544. // no option assume it is the output file
  3545. else
  3546. {
  3547. if (!cmSystemTools::FileIsFullPath(arg.c_str()))
  3548. {
  3549. resultFile = cwd;
  3550. resultFile += "/";
  3551. }
  3552. resultFile += arg;
  3553. writeToStdout = false;
  3554. }
  3555. }
  3556. // we have to find the module directory, so we can copy the files
  3557. this->AddCMakePaths();
  3558. std::string modulesPath =
  3559. this->CacheManager->GetCacheValue("CMAKE_ROOT");
  3560. modulesPath += "/Modules";
  3561. std::string inFile = modulesPath;
  3562. inFile += "/SystemInformation.cmake";
  3563. std::string outFile = destPath;
  3564. outFile += "/CMakeLists.txt";
  3565. // Copy file
  3566. if(!cmSystemTools::cmCopyFile(inFile.c_str(), outFile.c_str()))
  3567. {
  3568. std::cerr << "Error copying file \"" << inFile.c_str()
  3569. << "\" to \"" << outFile.c_str() << "\".\n";
  3570. return 1;
  3571. }
  3572. // do we write to a file or to stdout?
  3573. if (resultFile.size() == 0)
  3574. {
  3575. resultFile = cwd;
  3576. resultFile += "/__cmake_systeminformation/results.txt";
  3577. }
  3578. // now run cmake on the CMakeLists file
  3579. cmSystemTools::ChangeDirectory(destPath.c_str());
  3580. std::vector<std::string> args2;
  3581. args2.push_back(args[0]);
  3582. args2.push_back(destPath);
  3583. std::string resultArg = "-DRESULT_FILE=";
  3584. resultArg += resultFile;
  3585. args2.push_back(resultArg);
  3586. int res = this->Run(args2, false);
  3587. if (res != 0)
  3588. {
  3589. std::cerr << "Error: --system-information failed on internal CMake!\n";
  3590. return res;
  3591. }
  3592. // change back to the original directory
  3593. cmSystemTools::ChangeDirectory(cwd.c_str());
  3594. // echo results to stdout if needed
  3595. if (writeToStdout)
  3596. {
  3597. FILE* fin = fopen(resultFile.c_str(), "r");
  3598. if(fin)
  3599. {
  3600. const int bufferSize = 4096;
  3601. char buffer[bufferSize];
  3602. size_t n;
  3603. while((n = fread(buffer, 1, bufferSize, fin)) > 0)
  3604. {
  3605. for(char* c = buffer; c < buffer+n; ++c)
  3606. {
  3607. putc(*c, stdout);
  3608. }
  3609. fflush(stdout);
  3610. }
  3611. fclose(fin);
  3612. }
  3613. }
  3614. // clean up the directory
  3615. cmSystemTools::RemoveADirectory(destPath.c_str());
  3616. return 0;
  3617. }
  3618. //----------------------------------------------------------------------------
  3619. static bool cmakeCheckStampFile(const char* stampName)
  3620. {
  3621. // The stamp file does not exist. Use the stamp dependencies to
  3622. // determine whether it is really out of date. This works in
  3623. // conjunction with cmLocalVisualStudio7Generator to avoid
  3624. // repeatedly re-running CMake when the user rebuilds the entire
  3625. // solution.
  3626. std::string stampDepends = stampName;
  3627. stampDepends += ".depend";
  3628. #if defined(_WIN32) || defined(__CYGWIN__)
  3629. std::ifstream fin(stampDepends.c_str(), std::ios::in | std::ios::binary);
  3630. #else
  3631. std::ifstream fin(stampDepends.c_str(), std::ios::in);
  3632. #endif
  3633. if(!fin)
  3634. {
  3635. // The stamp dependencies file cannot be read. Just assume the
  3636. // build system is really out of date.
  3637. std::cout << "CMake is re-running because " << stampName
  3638. << " dependency file is missing.\n";
  3639. return false;
  3640. }
  3641. // Compare the stamp dependencies against the dependency file itself.
  3642. cmFileTimeComparison ftc;
  3643. std::string dep;
  3644. while(cmSystemTools::GetLineFromStream(fin, dep))
  3645. {
  3646. int result;
  3647. if(dep.length() >= 1 && dep[0] != '#' &&
  3648. (!ftc.FileTimeCompare(stampDepends.c_str(), dep.c_str(), &result)
  3649. || result < 0))
  3650. {
  3651. // The stamp depends file is older than this dependency. The
  3652. // build system is really out of date.
  3653. std::cout << "CMake is re-running because " << stampName
  3654. << " is out-of-date.\n";
  3655. std::cout << " the file '" << dep << "'\n";
  3656. std::cout << " is newer than '" << stampDepends << "'\n";
  3657. std::cout << " result='" << result << "'\n";
  3658. return false;
  3659. }
  3660. }
  3661. // The build system is up to date. The stamp file has been removed
  3662. // by the VS IDE due to a "rebuild" request. Just restore it.
  3663. std::ofstream stamp(stampName);
  3664. stamp << "# CMake generation timestamp file this directory.\n";
  3665. if(stamp)
  3666. {
  3667. // Notify the user why CMake is not re-running. It is safe to
  3668. // just print to stdout here because this code is only reachable
  3669. // through an undocumented flag used by the VS generator.
  3670. std::cout << "CMake does not need to re-run because "
  3671. << stampName << " is up-to-date.\n";
  3672. return true;
  3673. }
  3674. else
  3675. {
  3676. cmSystemTools::Error("Cannot restore timestamp ", stampName);
  3677. return false;
  3678. }
  3679. }
  3680. //----------------------------------------------------------------------------
  3681. static bool cmakeCheckStampList(const char* stampList)
  3682. {
  3683. // If the stamp list does not exist CMake must rerun to generate it.
  3684. if(!cmSystemTools::FileExists(stampList))
  3685. {
  3686. std::cout << "CMake is re-running because generate.stamp.list "
  3687. << "is missing.\n";
  3688. return false;
  3689. }
  3690. std::ifstream fin(stampList);
  3691. if(!fin)
  3692. {
  3693. std::cout << "CMake is re-running because generate.stamp.list "
  3694. << "could not be read.\n";
  3695. return false;
  3696. }
  3697. // Check each stamp.
  3698. std::string stampName;
  3699. while(cmSystemTools::GetLineFromStream(fin, stampName))
  3700. {
  3701. if(!cmakeCheckStampFile(stampName.c_str()))
  3702. {
  3703. return false;
  3704. }
  3705. }
  3706. return true;
  3707. }
  3708. // For visual studio 2005 and newer manifest files need to be embeded into
  3709. // exe and dll's. This code does that in such a way that incremental linking
  3710. // still works.
  3711. int cmake::VisualStudioLink(std::vector<std::string>& args, int type)
  3712. {
  3713. if(args.size() < 2)
  3714. {
  3715. return -1;
  3716. }
  3717. bool verbose = false;
  3718. if(cmSystemTools::GetEnv("VERBOSE"))
  3719. {
  3720. verbose = true;
  3721. }
  3722. std::vector<std::string> expandedArgs;
  3723. for(std::vector<std::string>::iterator i = args.begin();
  3724. i != args.end(); ++i)
  3725. {
  3726. // check for nmake temporary files
  3727. if((*i)[0] == '@' && i->find("@CMakeFiles") != 0 )
  3728. {
  3729. std::ifstream fin(i->substr(1).c_str());
  3730. std::string line;
  3731. while(cmSystemTools::GetLineFromStream(fin,
  3732. line))
  3733. {
  3734. cmSystemTools::ParseWindowsCommandLine(line.c_str(), expandedArgs);
  3735. }
  3736. }
  3737. else
  3738. {
  3739. expandedArgs.push_back(*i);
  3740. }
  3741. }
  3742. bool hasIncremental = false;
  3743. bool hasManifest = true;
  3744. for(std::vector<std::string>::iterator i = expandedArgs.begin();
  3745. i != expandedArgs.end(); ++i)
  3746. {
  3747. if(cmSystemTools::Strucmp(i->c_str(), "/INCREMENTAL:YES") == 0)
  3748. {
  3749. hasIncremental = true;
  3750. }
  3751. if(cmSystemTools::Strucmp(i->c_str(), "/INCREMENTAL") == 0)
  3752. {
  3753. hasIncremental = true;
  3754. }
  3755. if(cmSystemTools::Strucmp(i->c_str(), "/MANIFEST:NO") == 0)
  3756. {
  3757. hasManifest = false;
  3758. }
  3759. }
  3760. if(hasIncremental && hasManifest)
  3761. {
  3762. if(verbose)
  3763. {
  3764. std::cout << "Visual Studio Incremental Link with embeded manifests\n";
  3765. }
  3766. return cmake::VisualStudioLinkIncremental(expandedArgs, type, verbose);
  3767. }
  3768. if(verbose)
  3769. {
  3770. if(!hasIncremental)
  3771. {
  3772. std::cout << "Visual Studio Non-Incremental Link\n";
  3773. }
  3774. else
  3775. {
  3776. std::cout << "Visual Studio Incremental Link without manifests\n";
  3777. }
  3778. }
  3779. return cmake::VisualStudioLinkNonIncremental(expandedArgs,
  3780. type, hasManifest, verbose);
  3781. }
  3782. int cmake::ParseVisualStudioLinkCommand(std::vector<std::string>& args,
  3783. std::vector<cmStdString>& command,
  3784. std::string& targetName)
  3785. {
  3786. std::vector<std::string>::iterator i = args.begin();
  3787. i++; // skip -E
  3788. i++; // skip vs_link_dll or vs_link_exe
  3789. command.push_back(*i);
  3790. i++; // move past link command
  3791. for(; i != args.end(); ++i)
  3792. {
  3793. command.push_back(*i);
  3794. if(i->find("/Fe") == 0)
  3795. {
  3796. targetName = i->substr(3);
  3797. }
  3798. if(i->find("/out:") == 0)
  3799. {
  3800. targetName = i->substr(5);
  3801. }
  3802. }
  3803. if(targetName.size() == 0 || command.size() == 0)
  3804. {
  3805. return -1;
  3806. }
  3807. return 0;
  3808. }
  3809. bool cmake::RunCommand(const char* comment,
  3810. std::vector<cmStdString>& command,
  3811. bool verbose,
  3812. int* retCodeOut)
  3813. {
  3814. if(verbose)
  3815. {
  3816. std::cout << comment << ":\n";
  3817. for(std::vector<cmStdString>::iterator i = command.begin();
  3818. i != command.end(); ++i)
  3819. {
  3820. std::cout << i->c_str() << " ";
  3821. }
  3822. std::cout << "\n";
  3823. }
  3824. std::string output;
  3825. int retCode =0;
  3826. // use rc command to create .res file
  3827. cmSystemTools::RunSingleCommand(command,
  3828. &output,
  3829. &retCode, 0, cmSystemTools::OUTPUT_NONE);
  3830. // always print the output of the command, unless
  3831. // it is the dumb rc command banner, but if the command
  3832. // returned an error code then print the output anyway as
  3833. // the banner may be mixed with some other important information.
  3834. if(output.find("Resource Compiler Version") == output.npos
  3835. || retCode !=0)
  3836. {
  3837. std::cout << output;
  3838. }
  3839. // if retCodeOut is requested then always return true
  3840. // and set the retCodeOut to retCode
  3841. if(retCodeOut)
  3842. {
  3843. *retCodeOut = retCode;
  3844. return true;
  3845. }
  3846. if(retCode != 0)
  3847. {
  3848. std::cout << comment << " failed. with " << retCode << "\n";
  3849. }
  3850. return retCode == 0;
  3851. }
  3852. int cmake::VisualStudioLinkIncremental(std::vector<std::string>& args,
  3853. int type, bool verbose)
  3854. {
  3855. // This follows the steps listed here:
  3856. // http://blogs.msdn.com/zakramer/archive/2006/05/22/603558.aspx
  3857. // 1. Compiler compiles the application and generates the *.obj files.
  3858. // 2. An empty manifest file is generated if this is a clean build and if
  3859. // not the previous one is reused.
  3860. // 3. The resource compiler (rc.exe) compiles the *.manifest file to a
  3861. // *.res file.
  3862. // 4. Linker generates the binary (EXE or DLL) with the /incremental
  3863. // switch and embeds the dummy manifest file. The linker also generates
  3864. // the real manifest file based on the binaries that your binary depends
  3865. // on.
  3866. // 5. The manifest tool (mt.exe) is then used to generate the final
  3867. // manifest.
  3868. // If the final manifest is changed, then 6 and 7 are run, if not
  3869. // they are skipped, and it is done.
  3870. // 6. The resource compiler is invoked one more time.
  3871. // 7. Finally, the Linker does another incremental link, but since the
  3872. // only thing that has changed is the *.res file that contains the
  3873. // manifest it is a short link.
  3874. std::vector<cmStdString> linkCommand;
  3875. std::string targetName;
  3876. if(cmake::ParseVisualStudioLinkCommand(args, linkCommand, targetName) == -1)
  3877. {
  3878. return -1;
  3879. }
  3880. std::string manifestArg = "/MANIFESTFILE:";
  3881. std::vector<cmStdString> rcCommand;
  3882. rcCommand.push_back(cmSystemTools::FindProgram("rc.exe"));
  3883. std::vector<cmStdString> mtCommand;
  3884. mtCommand.push_back(cmSystemTools::FindProgram("mt.exe"));
  3885. std::string tempManifest;
  3886. tempManifest = targetName;
  3887. tempManifest += ".intermediate.manifest";
  3888. std::string resourceInputFile = targetName;
  3889. resourceInputFile += ".resource.txt";
  3890. if(verbose)
  3891. {
  3892. std::cout << "Create " << resourceInputFile.c_str() << "\n";
  3893. }
  3894. // Create input file for rc command
  3895. std::ofstream fout(resourceInputFile.c_str());
  3896. if(!fout)
  3897. {
  3898. return -1;
  3899. }
  3900. std::string manifestFile = targetName;
  3901. manifestFile += ".embed.manifest";
  3902. std::string fullPath= cmSystemTools::CollapseFullPath(manifestFile.c_str());
  3903. fout << type << " /* CREATEPROCESS_MANIFEST_RESOURCE_ID "
  3904. "*/ 24 /* RT_MANIFEST */ " << "\"" << fullPath.c_str() << "\"";
  3905. fout.close();
  3906. manifestArg += tempManifest;
  3907. // add the manifest arg to the linkCommand
  3908. linkCommand.push_back("/MANIFEST");
  3909. linkCommand.push_back(manifestArg);
  3910. // if manifestFile is not yet created, create an
  3911. // empty one
  3912. if(!cmSystemTools::FileExists(manifestFile.c_str()))
  3913. {
  3914. if(verbose)
  3915. {
  3916. std::cout << "Create empty: " << manifestFile.c_str() << "\n";
  3917. }
  3918. std::ofstream foutTmp(manifestFile.c_str());
  3919. }
  3920. std::string resourceFile = manifestFile;
  3921. resourceFile += ".res";
  3922. // add the resource file to the end of the link command
  3923. linkCommand.push_back(resourceFile);
  3924. std::string outputOpt = "/fo";
  3925. outputOpt += resourceFile;
  3926. rcCommand.push_back(outputOpt);
  3927. rcCommand.push_back(resourceInputFile);
  3928. // Run rc command to create resource
  3929. if(!cmake::RunCommand("RC Pass 1", rcCommand, verbose))
  3930. {
  3931. return -1;
  3932. }
  3933. // Now run the link command to link and create manifest
  3934. if(!cmake::RunCommand("LINK Pass 1", linkCommand, verbose))
  3935. {
  3936. return -1;
  3937. }
  3938. // create mt command
  3939. std::string outArg("/out:");
  3940. outArg+= manifestFile;
  3941. mtCommand.push_back("/nologo");
  3942. mtCommand.push_back(outArg);
  3943. mtCommand.push_back("/notify_update");
  3944. mtCommand.push_back("/manifest");
  3945. mtCommand.push_back(tempManifest);
  3946. // now run mt.exe to create the final manifest file
  3947. int mtRet =0;
  3948. cmake::RunCommand("MT", mtCommand, verbose, &mtRet);
  3949. // if mt returns 0, then the manifest was not changed and
  3950. // we do not need to do another link step
  3951. if(mtRet == 0)
  3952. {
  3953. return 0;
  3954. }
  3955. // check for magic mt return value if mt returns the magic number
  3956. // 1090650113 then it means that it updated the manifest file and we need
  3957. // to do the final link. If mt has any value other than 0 or 1090650113
  3958. // then there was some problem with the command itself and there was an
  3959. // error so return the error code back out of cmake so make can report it.
  3960. if(mtRet != 1090650113)
  3961. {
  3962. return mtRet;
  3963. }
  3964. // update the resource file with the new manifest from the mt command.
  3965. if(!cmake::RunCommand("RC Pass 2", rcCommand, verbose))
  3966. {
  3967. return -1;
  3968. }
  3969. // Run the final incremental link that will put the new manifest resource
  3970. // into the file incrementally.
  3971. if(!cmake::RunCommand("FINAL LINK", linkCommand, verbose))
  3972. {
  3973. return -1;
  3974. }
  3975. return 0;
  3976. }
  3977. int cmake::VisualStudioLinkNonIncremental(std::vector<std::string>& args,
  3978. int type,
  3979. bool hasManifest,
  3980. bool verbose)
  3981. {
  3982. std::vector<cmStdString> linkCommand;
  3983. std::string targetName;
  3984. if(cmake::ParseVisualStudioLinkCommand(args, linkCommand, targetName) == -1)
  3985. {
  3986. return -1;
  3987. }
  3988. // Run the link command as given
  3989. if (hasManifest)
  3990. {
  3991. linkCommand.push_back("/MANIFEST");
  3992. }
  3993. if(!cmake::RunCommand("LINK", linkCommand, verbose))
  3994. {
  3995. return -1;
  3996. }
  3997. if(!hasManifest)
  3998. {
  3999. return 0;
  4000. }
  4001. std::vector<cmStdString> mtCommand;
  4002. mtCommand.push_back(cmSystemTools::FindProgram("mt.exe"));
  4003. mtCommand.push_back("/nologo");
  4004. mtCommand.push_back("/manifest");
  4005. std::string manifestFile = targetName;
  4006. manifestFile += ".manifest";
  4007. mtCommand.push_back(manifestFile);
  4008. std::string outresource = "/outputresource:";
  4009. outresource += targetName;
  4010. outresource += ";#";
  4011. if(type == 1)
  4012. {
  4013. outresource += "1";
  4014. }
  4015. else if(type == 2)
  4016. {
  4017. outresource += "2";
  4018. }
  4019. mtCommand.push_back(outresource);
  4020. // Now use the mt tool to embed the manifest into the exe or dll
  4021. if(!cmake::RunCommand("MT", mtCommand, verbose))
  4022. {
  4023. return -1;
  4024. }
  4025. return 0;
  4026. }
  4027. //----------------------------------------------------------------------------
  4028. void cmake::IssueMessage(cmake::MessageType t, std::string const& text,
  4029. cmListFileBacktrace const& backtrace)
  4030. {
  4031. cmOStringStream msg;
  4032. bool isError = false;
  4033. // Construct the message header.
  4034. if(t == cmake::FATAL_ERROR)
  4035. {
  4036. isError = true;
  4037. msg << "CMake Error";
  4038. }
  4039. else if(t == cmake::INTERNAL_ERROR)
  4040. {
  4041. isError = true;
  4042. msg << "CMake Internal Error (please report a bug)";
  4043. }
  4044. else
  4045. {
  4046. msg << "CMake Warning";
  4047. if(t == cmake::AUTHOR_WARNING)
  4048. {
  4049. // Allow suppression of these warnings.
  4050. cmCacheManager::CacheIterator it = this->CacheManager
  4051. ->GetCacheIterator("CMAKE_SUPPRESS_DEVELOPER_WARNINGS");
  4052. if(!it.IsAtEnd() && it.GetValueAsBool())
  4053. {
  4054. return;
  4055. }
  4056. msg << " (dev)";
  4057. }
  4058. }
  4059. // Add the immediate context.
  4060. cmListFileBacktrace::const_iterator i = backtrace.begin();
  4061. if(i != backtrace.end())
  4062. {
  4063. cmListFileContext const& lfc = *i;
  4064. msg << (lfc.Line? " at ": " in ") << lfc;
  4065. ++i;
  4066. }
  4067. // Add the message text.
  4068. {
  4069. msg << ":\n";
  4070. cmDocumentationFormatterText formatter;
  4071. formatter.SetIndent(" ");
  4072. formatter.PrintFormatted(msg, text.c_str());
  4073. }
  4074. // Add the rest of the context.
  4075. if(i != backtrace.end())
  4076. {
  4077. msg << "Call Stack (most recent call first):\n";
  4078. while(i != backtrace.end())
  4079. {
  4080. cmListFileContext const& lfc = *i;
  4081. msg << " " << lfc << "\n";
  4082. ++i;
  4083. }
  4084. }
  4085. // Add a note about warning suppression.
  4086. if(t == cmake::AUTHOR_WARNING)
  4087. {
  4088. msg <<
  4089. "This warning is for project developers. Use -Wno-dev to suppress it.";
  4090. }
  4091. // Add a terminating blank line.
  4092. msg << "\n";
  4093. // Output the message.
  4094. if(isError)
  4095. {
  4096. cmSystemTools::SetErrorOccured();
  4097. cmSystemTools::Message(msg.str().c_str(), "Error");
  4098. }
  4099. else
  4100. {
  4101. cmSystemTools::Message(msg.str().c_str(), "Warning");
  4102. }
  4103. }
  4104. //----------------------------------------------------------------------------
  4105. std::vector<std::string> const& cmake::GetDebugConfigs()
  4106. {
  4107. // Compute on-demand.
  4108. if(this->DebugConfigs.empty())
  4109. {
  4110. if(const char* config_list = this->GetProperty("DEBUG_CONFIGURATIONS"))
  4111. {
  4112. // Expand the specified list and convert to upper-case.
  4113. cmSystemTools::ExpandListArgument(config_list, this->DebugConfigs);
  4114. for(std::vector<std::string>::iterator i = this->DebugConfigs.begin();
  4115. i != this->DebugConfigs.end(); ++i)
  4116. {
  4117. *i = cmSystemTools::UpperCase(*i);
  4118. }
  4119. }
  4120. // If no configurations were specified, use a default list.
  4121. if(this->DebugConfigs.empty())
  4122. {
  4123. this->DebugConfigs.push_back("DEBUG");
  4124. }
  4125. }
  4126. return this->DebugConfigs;
  4127. }
  4128. int cmake::Build(const std::string& dir,
  4129. const std::string& target,
  4130. const std::string& config,
  4131. const std::vector<std::string>& nativeOptions,
  4132. bool clean,
  4133. cmSystemTools::OutputOption outputflag)
  4134. {
  4135. if(!cmSystemTools::FileIsDirectory(dir.c_str()))
  4136. {
  4137. std::cerr << "Error: " << dir << " is not a directory\n";
  4138. return 1;
  4139. }
  4140. std::string cachePath = dir;
  4141. cmSystemTools::ConvertToUnixSlashes(cachePath);
  4142. cmCacheManager* cachem = this->GetCacheManager();
  4143. cmCacheManager::CacheIterator it = cachem->NewIterator();
  4144. if(!cachem->LoadCache(cachePath.c_str()))
  4145. {
  4146. std::cerr << "Error: could not load cache\n";
  4147. return 1;
  4148. }
  4149. if(!it.Find("CMAKE_GENERATOR"))
  4150. {
  4151. std::cerr << "Error: could find generator in Cache\n";
  4152. return 1;
  4153. }
  4154. std::auto_ptr<cmGlobalGenerator> gen(
  4155. this->CreateGlobalGenerator(it.GetValue()));
  4156. std::string output;
  4157. std::string projName;
  4158. std::string makeProgram;
  4159. if(!it.Find("CMAKE_PROJECT_NAME"))
  4160. {
  4161. std::cerr << "Error: could not find CMAKE_PROJECT_NAME in Cache\n";
  4162. return 1;
  4163. }
  4164. projName = it.GetValue();
  4165. if(!it.Find("CMAKE_MAKE_PROGRAM"))
  4166. {
  4167. std::cerr << "Error: could not find CMAKE_MAKE_PROGRAM in Cache\n";
  4168. return 1;
  4169. }
  4170. makeProgram = it.GetValue();
  4171. return gen->Build(0, dir.c_str(),
  4172. projName.c_str(), target.c_str(),
  4173. &output,
  4174. makeProgram.c_str(),
  4175. config.c_str(), clean, false, 0, outputflag,
  4176. 0, nativeOptions);
  4177. }
  4178. void cmake::WatchUnusedCli(const char* var)
  4179. {
  4180. #ifdef CMAKE_BUILD_WITH_CMAKE
  4181. this->VariableWatch->AddWatch(var, cmWarnUnusedCliWarning, this);
  4182. if(this->UsedCliVariables.find(var) == this->UsedCliVariables.end())
  4183. {
  4184. this->UsedCliVariables[var] = false;
  4185. }
  4186. #endif
  4187. }
  4188. void cmake::UnwatchUnusedCli(const char* var)
  4189. {
  4190. #ifdef CMAKE_BUILD_WITH_CMAKE
  4191. this->VariableWatch->RemoveWatch(var, cmWarnUnusedCliWarning);
  4192. this->UsedCliVariables.erase(var);
  4193. #endif
  4194. }
  4195. void cmake::RunCheckForUnusedVariables()
  4196. {
  4197. #ifdef CMAKE_BUILD_WITH_CMAKE
  4198. bool haveUnused = false;
  4199. cmOStringStream msg;
  4200. msg << "Manually-specified variables were not used by the project:";
  4201. for(std::map<cmStdString, bool>::const_iterator
  4202. it = this->UsedCliVariables.begin();
  4203. it != this->UsedCliVariables.end(); ++it)
  4204. {
  4205. if(!it->second)
  4206. {
  4207. haveUnused = true;
  4208. msg << "\n " << it->first;
  4209. }
  4210. }
  4211. if(haveUnused)
  4212. {
  4213. this->IssueMessage(cmake::WARNING, msg.str(), cmListFileBacktrace());
  4214. }
  4215. #endif
  4216. }