cmake.cxx 136 KB

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