cmake.cxx 136 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541
  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. vsVerions.push_back("WDExpress\\");
  2039. struct VSRegistryEntryName
  2040. {
  2041. const char* MSVersion;
  2042. const char* GeneratorName;
  2043. };
  2044. VSRegistryEntryName version[] = {
  2045. {"6.0", "Visual Studio 6"},
  2046. {"7.0", "Visual Studio 7"},
  2047. {"7.1", "Visual Studio 7 .NET 2003"},
  2048. {"8.0", "Visual Studio 8 2005"},
  2049. {"9.0", "Visual Studio 9 2008"},
  2050. {"10.0", "Visual Studio 10"},
  2051. {"11.0", "Visual Studio 11"},
  2052. {0, 0}};
  2053. for(int i=0; version[i].MSVersion != 0; i++)
  2054. {
  2055. for(size_t b=0; b < vsVerions.size(); b++)
  2056. {
  2057. std::string reg = vsregBase + vsVerions[b] + version[i].MSVersion;
  2058. reg += ";InstallDir]";
  2059. cmSystemTools::ExpandRegistryValues(reg,
  2060. cmSystemTools::KeyWOW64_32);
  2061. if (!(reg == "/registry"))
  2062. {
  2063. installedCompiler = version[i].GeneratorName;
  2064. break;
  2065. }
  2066. }
  2067. }
  2068. cmGlobalGenerator* gen
  2069. = this->CreateGlobalGenerator(installedCompiler.c_str());
  2070. if(!gen)
  2071. {
  2072. gen = new cmGlobalNMakeMakefileGenerator;
  2073. }
  2074. this->SetGlobalGenerator(gen);
  2075. std::cout << "-- Building for: " << gen->GetName() << "\n";
  2076. #else
  2077. this->SetGlobalGenerator(new cmGlobalUnixMakefileGenerator3);
  2078. #endif
  2079. }
  2080. if(!this->GlobalGenerator)
  2081. {
  2082. cmSystemTools::Error("Could not create generator");
  2083. return -1;
  2084. }
  2085. }
  2086. const char* genName = this->CacheManager->GetCacheValue("CMAKE_GENERATOR");
  2087. if(genName)
  2088. {
  2089. if(strcmp(this->GlobalGenerator->GetName(), genName) != 0)
  2090. {
  2091. std::string message = "Error: generator : ";
  2092. message += this->GlobalGenerator->GetName();
  2093. message += "\nDoes not match the generator used previously: ";
  2094. message += genName;
  2095. message +=
  2096. "\nEither remove the CMakeCache.txt file or choose a different"
  2097. " binary directory.";
  2098. cmSystemTools::Error(message.c_str());
  2099. return -2;
  2100. }
  2101. }
  2102. if(!this->CacheManager->GetCacheValue("CMAKE_GENERATOR"))
  2103. {
  2104. this->CacheManager->AddCacheEntry("CMAKE_GENERATOR",
  2105. this->GlobalGenerator->GetName(),
  2106. "Name of generator.",
  2107. cmCacheManager::INTERNAL);
  2108. this->CacheManager->AddCacheEntry("CMAKE_EXTRA_GENERATOR",
  2109. this->GlobalGenerator->GetExtraGeneratorName(),
  2110. "Name of external makefile project generator.",
  2111. cmCacheManager::INTERNAL);
  2112. }
  2113. // reset any system configuration information, except for when we are
  2114. // InTryCompile. With TryCompile the system info is taken from the parent's
  2115. // info to save time
  2116. if (!this->InTryCompile)
  2117. {
  2118. this->GlobalGenerator->ClearEnabledLanguages();
  2119. }
  2120. // Truncate log files
  2121. if (!this->InTryCompile)
  2122. {
  2123. this->TruncateOutputLog("CMakeOutput.log");
  2124. this->TruncateOutputLog("CMakeError.log");
  2125. }
  2126. // actually do the configure
  2127. this->GlobalGenerator->Configure();
  2128. // Before saving the cache
  2129. // if the project did not define one of the entries below, add them now
  2130. // so users can edit the values in the cache:
  2131. // We used to always present LIBRARY_OUTPUT_PATH and
  2132. // EXECUTABLE_OUTPUT_PATH. They are now documented as old-style and
  2133. // should no longer be used. Therefore we present them only if the
  2134. // project requires compatibility with CMake 2.4. We detect this
  2135. // here by looking for the old CMAKE_BACKWARDS_COMPATABILITY
  2136. // variable created when CMP0001 is not set to NEW.
  2137. if(this->GetCacheManager()->GetCacheValue("CMAKE_BACKWARDS_COMPATIBILITY"))
  2138. {
  2139. if(!this->CacheManager->GetCacheValue("LIBRARY_OUTPUT_PATH"))
  2140. {
  2141. this->CacheManager->AddCacheEntry
  2142. ("LIBRARY_OUTPUT_PATH", "",
  2143. "Single output directory for building all libraries.",
  2144. cmCacheManager::PATH);
  2145. }
  2146. if(!this->CacheManager->GetCacheValue("EXECUTABLE_OUTPUT_PATH"))
  2147. {
  2148. this->CacheManager->AddCacheEntry
  2149. ("EXECUTABLE_OUTPUT_PATH", "",
  2150. "Single output directory for building all executables.",
  2151. cmCacheManager::PATH);
  2152. }
  2153. }
  2154. if(!this->CacheManager->GetCacheValue("CMAKE_USE_RELATIVE_PATHS"))
  2155. {
  2156. this->CacheManager->AddCacheEntry
  2157. ("CMAKE_USE_RELATIVE_PATHS", "OFF",
  2158. "If true, cmake will use relative paths in makefiles and projects.",
  2159. cmCacheManager::BOOL);
  2160. cmCacheManager::CacheIterator it =
  2161. this->CacheManager->GetCacheIterator("CMAKE_USE_RELATIVE_PATHS");
  2162. if ( !it.PropertyExists("ADVANCED") )
  2163. {
  2164. it.SetProperty("ADVANCED", "1");
  2165. }
  2166. }
  2167. if(cmSystemTools::GetFatalErrorOccured() &&
  2168. (!this->CacheManager->GetCacheValue("CMAKE_MAKE_PROGRAM") ||
  2169. cmSystemTools::IsOff(this->CacheManager->
  2170. GetCacheValue("CMAKE_MAKE_PROGRAM"))))
  2171. {
  2172. // We must have a bad generator selection. Wipe the cache entry so the
  2173. // user can select another.
  2174. this->CacheManager->RemoveCacheEntry("CMAKE_GENERATOR");
  2175. this->CacheManager->RemoveCacheEntry("CMAKE_EXTRA_GENERATOR");
  2176. }
  2177. cmMakefile* mf=this->GlobalGenerator->GetLocalGenerators()[0]->GetMakefile();
  2178. if (mf->IsOn("CTEST_USE_LAUNCHERS")
  2179. && !this->GetProperty("RULE_LAUNCH_COMPILE", cmProperty::GLOBAL))
  2180. {
  2181. cmSystemTools::Error("CTEST_USE_LAUNCHERS is enabled, but the "
  2182. "RULE_LAUNCH_COMPILE global property is not defined.\n"
  2183. "Did you forget to include(CTest) in the toplevel "
  2184. "CMakeLists.txt ?");
  2185. }
  2186. // only save the cache if there were no fatal errors
  2187. if ( this->GetWorkingMode() == NORMAL_MODE )
  2188. {
  2189. this->CacheManager->SaveCache(this->GetHomeOutputDirectory());
  2190. }
  2191. if ( !this->GraphVizFile.empty() )
  2192. {
  2193. std::cout << "Generate graphviz: " << this->GraphVizFile << std::endl;
  2194. this->GenerateGraphViz(this->GraphVizFile.c_str());
  2195. }
  2196. if(cmSystemTools::GetErrorOccuredFlag())
  2197. {
  2198. return -1;
  2199. }
  2200. return 0;
  2201. }
  2202. void cmake::PreLoadCMakeFiles()
  2203. {
  2204. std::vector<std::string> args;
  2205. std::string pre_load = this->GetHomeDirectory();
  2206. if ( pre_load.size() > 0 )
  2207. {
  2208. pre_load += "/PreLoad.cmake";
  2209. if ( cmSystemTools::FileExists(pre_load.c_str()) )
  2210. {
  2211. this->ReadListFile(args, pre_load.c_str());
  2212. }
  2213. }
  2214. pre_load = this->GetHomeOutputDirectory();
  2215. if ( pre_load.size() > 0 )
  2216. {
  2217. pre_load += "/PreLoad.cmake";
  2218. if ( cmSystemTools::FileExists(pre_load.c_str()) )
  2219. {
  2220. this->ReadListFile(args, pre_load.c_str());
  2221. }
  2222. }
  2223. }
  2224. // handle a command line invocation
  2225. int cmake::Run(const std::vector<std::string>& args, bool noconfigure)
  2226. {
  2227. // Process the arguments
  2228. this->SetArgs(args);
  2229. if(cmSystemTools::GetErrorOccuredFlag())
  2230. {
  2231. return -1;
  2232. }
  2233. // If we are given a stamp list file check if it is really out of date.
  2234. if(!this->CheckStampList.empty() &&
  2235. cmakeCheckStampList(this->CheckStampList.c_str()))
  2236. {
  2237. return 0;
  2238. }
  2239. // If we are given a stamp file check if it is really out of date.
  2240. if(!this->CheckStampFile.empty() &&
  2241. cmakeCheckStampFile(this->CheckStampFile.c_str()))
  2242. {
  2243. return 0;
  2244. }
  2245. // set the cmake command
  2246. this->CMakeCommand = args[0];
  2247. if ( this->GetWorkingMode() == NORMAL_MODE )
  2248. {
  2249. // load the cache
  2250. if(this->LoadCache() < 0)
  2251. {
  2252. cmSystemTools::Error("Error executing cmake::LoadCache(). Aborting.\n");
  2253. return -1;
  2254. }
  2255. }
  2256. else
  2257. {
  2258. this->AddCMakePaths();
  2259. }
  2260. // Add any cache args
  2261. if ( !this->SetCacheArgs(args) )
  2262. {
  2263. cmSystemTools::Error("Problem processing arguments. Aborting.\n");
  2264. return -1;
  2265. }
  2266. // In script mode we terminate after running the script.
  2267. if(this->GetWorkingMode() != NORMAL_MODE)
  2268. {
  2269. if(cmSystemTools::GetErrorOccuredFlag())
  2270. {
  2271. return -1;
  2272. }
  2273. else
  2274. {
  2275. return 0;
  2276. }
  2277. }
  2278. // If MAKEFLAGS are given in the environment, remove the environment
  2279. // variable. This will prevent try-compile from succeeding when it
  2280. // should fail (if "-i" is an option). We cannot simply test
  2281. // whether "-i" is given and remove it because some make programs
  2282. // encode the MAKEFLAGS variable in a strange way.
  2283. if(getenv("MAKEFLAGS"))
  2284. {
  2285. cmSystemTools::PutEnv("MAKEFLAGS=");
  2286. }
  2287. this->PreLoadCMakeFiles();
  2288. if ( noconfigure )
  2289. {
  2290. return 0;
  2291. }
  2292. // now run the global generate
  2293. // Check the state of the build system to see if we need to regenerate.
  2294. if(!this->CheckBuildSystem())
  2295. {
  2296. return 0;
  2297. }
  2298. // If we are doing global generate, we better set start and start
  2299. // output directory to the root of the project.
  2300. std::string oldstartdir = this->GetStartDirectory();
  2301. std::string oldstartoutputdir = this->GetStartOutputDirectory();
  2302. this->SetStartDirectory(this->GetHomeDirectory());
  2303. this->SetStartOutputDirectory(this->GetHomeOutputDirectory());
  2304. int ret = this->Configure();
  2305. if (ret || this->GetWorkingMode() != NORMAL_MODE)
  2306. {
  2307. #if defined(CMAKE_HAVE_VS_GENERATORS)
  2308. if(!this->VSSolutionFile.empty() && this->GlobalGenerator)
  2309. {
  2310. // CMake is running to regenerate a Visual Studio build tree
  2311. // during a build from the VS IDE. The build files cannot be
  2312. // regenerated, so we should stop the build.
  2313. cmSystemTools::Message(
  2314. "CMake Configure step failed. "
  2315. "Build files cannot be regenerated correctly. "
  2316. "Attempting to stop IDE build.");
  2317. cmGlobalVisualStudioGenerator* gg =
  2318. static_cast<cmGlobalVisualStudioGenerator*>(this->GlobalGenerator);
  2319. gg->CallVisualStudioMacro(cmGlobalVisualStudioGenerator::MacroStop,
  2320. this->VSSolutionFile.c_str());
  2321. }
  2322. #endif
  2323. return ret;
  2324. }
  2325. ret = this->Generate();
  2326. std::string message = "Build files have been written to: ";
  2327. message += this->GetHomeOutputDirectory();
  2328. this->UpdateProgress(message.c_str(), -1);
  2329. if(ret)
  2330. {
  2331. return ret;
  2332. }
  2333. this->SetStartDirectory(oldstartdir.c_str());
  2334. this->SetStartOutputDirectory(oldstartoutputdir.c_str());
  2335. return ret;
  2336. }
  2337. int cmake::Generate()
  2338. {
  2339. if(!this->GlobalGenerator)
  2340. {
  2341. return -1;
  2342. }
  2343. this->GlobalGenerator->Generate();
  2344. if(this->WarnUnusedCli)
  2345. {
  2346. this->RunCheckForUnusedVariables();
  2347. }
  2348. if(cmSystemTools::GetErrorOccuredFlag())
  2349. {
  2350. return -1;
  2351. }
  2352. if (this->GetProperty("REPORT_UNDEFINED_PROPERTIES"))
  2353. {
  2354. this->ReportUndefinedPropertyAccesses
  2355. (this->GetProperty("REPORT_UNDEFINED_PROPERTIES"));
  2356. }
  2357. // Save the cache again after a successful Generate so that any internal
  2358. // variables created during Generate are saved. (Specifically target GUIDs
  2359. // for the Visual Studio and Xcode generators.)
  2360. if ( this->GetWorkingMode() == NORMAL_MODE )
  2361. {
  2362. this->CacheManager->SaveCache(this->GetHomeOutputDirectory());
  2363. }
  2364. return 0;
  2365. }
  2366. void cmake::AddCacheEntry(const char* key, const char* value,
  2367. const char* helpString,
  2368. int type)
  2369. {
  2370. this->CacheManager->AddCacheEntry(key, value,
  2371. helpString,
  2372. cmCacheManager::CacheEntryType(type));
  2373. }
  2374. const char* cmake::GetCacheDefinition(const char* name) const
  2375. {
  2376. return this->CacheManager->GetCacheValue(name);
  2377. }
  2378. void cmake::AddDefaultCommands()
  2379. {
  2380. std::list<cmCommand*> commands;
  2381. GetBootstrapCommands(commands);
  2382. GetPredefinedCommands(commands);
  2383. for(std::list<cmCommand*>::iterator i = commands.begin();
  2384. i != commands.end(); ++i)
  2385. {
  2386. this->AddCommand(*i);
  2387. }
  2388. }
  2389. void cmake::AddDefaultGenerators()
  2390. {
  2391. #if defined(_WIN32) && !defined(__CYGWIN__)
  2392. # if !defined(CMAKE_BOOT_MINGW)
  2393. this->Generators[cmGlobalVisualStudio6Generator::GetActualName()] =
  2394. &cmGlobalVisualStudio6Generator::New;
  2395. this->Generators[cmGlobalVisualStudio7Generator::GetActualName()] =
  2396. &cmGlobalVisualStudio7Generator::New;
  2397. this->Generators[cmGlobalVisualStudio10Generator::GetActualName()] =
  2398. &cmGlobalVisualStudio10Generator::New;
  2399. this->Generators[cmGlobalVisualStudio10IA64Generator::GetActualName()] =
  2400. &cmGlobalVisualStudio10IA64Generator::New;
  2401. this->Generators[cmGlobalVisualStudio10Win64Generator::GetActualName()] =
  2402. &cmGlobalVisualStudio10Win64Generator::New;
  2403. this->Generators[cmGlobalVisualStudio11Generator::GetActualName()] =
  2404. &cmGlobalVisualStudio11Generator::New;
  2405. this->Generators[cmGlobalVisualStudio11Win64Generator::GetActualName()] =
  2406. &cmGlobalVisualStudio11Win64Generator::New;
  2407. this->Generators[cmGlobalVisualStudio11ARMGenerator::GetActualName()] =
  2408. &cmGlobalVisualStudio11ARMGenerator::New;
  2409. this->Generators[cmGlobalVisualStudio71Generator::GetActualName()] =
  2410. &cmGlobalVisualStudio71Generator::New;
  2411. this->Generators[cmGlobalVisualStudio8Generator::GetActualName()] =
  2412. &cmGlobalVisualStudio8Generator::New;
  2413. this->Generators[cmGlobalVisualStudio9Generator::GetActualName()] =
  2414. &cmGlobalVisualStudio9Generator::New;
  2415. this->Generators[cmGlobalVisualStudio9IA64Generator::GetActualName()] =
  2416. &cmGlobalVisualStudio9IA64Generator::New;
  2417. this->Generators[cmGlobalVisualStudio9Win64Generator::GetActualName()] =
  2418. &cmGlobalVisualStudio9Win64Generator::New;
  2419. this->Generators[cmGlobalVisualStudio8Win64Generator::GetActualName()] =
  2420. &cmGlobalVisualStudio8Win64Generator::New;
  2421. this->Generators[cmGlobalBorlandMakefileGenerator::GetActualName()] =
  2422. &cmGlobalBorlandMakefileGenerator::New;
  2423. this->Generators[cmGlobalNMakeMakefileGenerator::GetActualName()] =
  2424. &cmGlobalNMakeMakefileGenerator::New;
  2425. this->Generators[cmGlobalJOMMakefileGenerator::GetActualName()] =
  2426. &cmGlobalJOMMakefileGenerator::New;
  2427. this->Generators[cmGlobalWatcomWMakeGenerator::GetActualName()] =
  2428. &cmGlobalWatcomWMakeGenerator::New;
  2429. # endif
  2430. this->Generators[cmGlobalMSYSMakefileGenerator::GetActualName()] =
  2431. &cmGlobalMSYSMakefileGenerator::New;
  2432. this->Generators[cmGlobalMinGWMakefileGenerator::GetActualName()] =
  2433. &cmGlobalMinGWMakefileGenerator::New;
  2434. #endif
  2435. this->Generators[cmGlobalUnixMakefileGenerator3::GetActualName()] =
  2436. &cmGlobalUnixMakefileGenerator3::New;
  2437. this->Generators[cmGlobalNinjaGenerator::GetActualName()] =
  2438. &cmGlobalNinjaGenerator::New;
  2439. #ifdef CMAKE_USE_XCODE
  2440. this->Generators[cmGlobalXCodeGenerator::GetActualName()] =
  2441. &cmGlobalXCodeGenerator::New;
  2442. #endif
  2443. }
  2444. int cmake::LoadCache()
  2445. {
  2446. // could we not read the cache
  2447. if (!this->CacheManager->LoadCache(this->GetHomeOutputDirectory()))
  2448. {
  2449. // if it does exist, but isn't readable then warn the user
  2450. std::string cacheFile = this->GetHomeOutputDirectory();
  2451. cacheFile += "/CMakeCache.txt";
  2452. if(cmSystemTools::FileExists(cacheFile.c_str()))
  2453. {
  2454. cmSystemTools::Error(
  2455. "There is a CMakeCache.txt file for the current binary tree but "
  2456. "cmake does not have permission to read it. Please check the "
  2457. "permissions of the directory you are trying to run CMake on.");
  2458. return -1;
  2459. }
  2460. }
  2461. if (this->CMakeCommand.size() < 2)
  2462. {
  2463. cmSystemTools::Error(
  2464. "cmake command was not specified prior to loading the cache in "
  2465. "cmake.cxx");
  2466. return -1;
  2467. }
  2468. // setup CMAKE_ROOT and CMAKE_COMMAND
  2469. if(!this->AddCMakePaths())
  2470. {
  2471. return -3;
  2472. }
  2473. return 0;
  2474. }
  2475. void cmake::SetProgressCallback(ProgressCallbackType f, void *cd)
  2476. {
  2477. this->ProgressCallback = f;
  2478. this->ProgressCallbackClientData = cd;
  2479. }
  2480. void cmake::UpdateProgress(const char *msg, float prog)
  2481. {
  2482. if(this->ProgressCallback && !this->InTryCompile)
  2483. {
  2484. (*this->ProgressCallback)(msg, prog, this->ProgressCallbackClientData);
  2485. return;
  2486. }
  2487. }
  2488. void cmake::GetCommandDocumentation(std::vector<cmDocumentationEntry>& v,
  2489. bool withCurrentCommands,
  2490. bool withCompatCommands) const
  2491. {
  2492. for(RegisteredCommandsMap::const_iterator j = this->Commands.begin();
  2493. j != this->Commands.end(); ++j)
  2494. {
  2495. if ((( withCompatCommands == false) && ( (*j).second->IsDiscouraged()))
  2496. || ((withCurrentCommands == false) && (!(*j).second->IsDiscouraged()))
  2497. || (!((*j).second->ShouldAppearInDocumentation()))
  2498. )
  2499. {
  2500. continue;
  2501. }
  2502. cmDocumentationEntry e((*j).second->GetName(),
  2503. (*j).second->GetTerseDocumentation(),
  2504. (*j).second->GetFullDocumentation());
  2505. v.push_back(e);
  2506. }
  2507. }
  2508. void cmake::GetPolicyDocumentation(std::vector<cmDocumentationEntry>& v)
  2509. {
  2510. this->Policies->GetDocumentation(v);
  2511. }
  2512. void cmake::GetPropertiesDocumentation(std::map<std::string,
  2513. cmDocumentationSection *>& v)
  2514. {
  2515. // loop over the properties and put them into the doc structure
  2516. std::map<cmProperty::ScopeType, cmPropertyDefinitionMap>::iterator i;
  2517. i = this->PropertyDefinitions.begin();
  2518. for (;i != this->PropertyDefinitions.end(); ++i)
  2519. {
  2520. i->second.GetPropertiesDocumentation(v);
  2521. }
  2522. }
  2523. void cmake::GetGeneratorDocumentation(std::vector<cmDocumentationEntry>& v)
  2524. {
  2525. for(RegisteredGeneratorsMap::const_iterator i = this->Generators.begin();
  2526. i != this->Generators.end(); ++i)
  2527. {
  2528. cmDocumentationEntry e;
  2529. cmGlobalGenerator* generator = (i->second)();
  2530. generator->GetDocumentation(e);
  2531. delete generator;
  2532. v.push_back(e);
  2533. }
  2534. for(RegisteredExtraGeneratorsMap::const_iterator
  2535. i = this->ExtraGenerators.begin(); i != this->ExtraGenerators.end(); ++i)
  2536. {
  2537. cmDocumentationEntry e;
  2538. cmExternalMakefileProjectGenerator* generator = (i->second)();
  2539. generator->GetDocumentation(e, i->first.c_str());
  2540. e.Name = i->first;
  2541. delete generator;
  2542. v.push_back(e);
  2543. }
  2544. }
  2545. void cmake::UpdateConversionPathTable()
  2546. {
  2547. // Update the path conversion table with any specified file:
  2548. const char* tablepath =
  2549. this->CacheManager->GetCacheValue("CMAKE_PATH_TRANSLATION_FILE");
  2550. if(tablepath)
  2551. {
  2552. std::ifstream table( tablepath );
  2553. if(!table)
  2554. {
  2555. cmSystemTools::Error("CMAKE_PATH_TRANSLATION_FILE set to ", tablepath,
  2556. ". CMake can not open file.");
  2557. cmSystemTools::ReportLastSystemError("CMake can not open file.");
  2558. }
  2559. else
  2560. {
  2561. std::string a, b;
  2562. while(!table.eof())
  2563. {
  2564. // two entries per line
  2565. table >> a; table >> b;
  2566. cmSystemTools::AddTranslationPath( a.c_str(), b.c_str());
  2567. }
  2568. }
  2569. }
  2570. }
  2571. //----------------------------------------------------------------------------
  2572. int cmake::CheckBuildSystem()
  2573. {
  2574. // We do not need to rerun CMake. Check dependency integrity. Use
  2575. // the make system's VERBOSE environment variable to enable verbose
  2576. // output. This can be skipped by setting CMAKE_NO_VERBOSE (which is set
  2577. // by the Eclipse and KDevelop generators).
  2578. bool verbose = ((cmSystemTools::GetEnv("VERBOSE") != 0)
  2579. && (cmSystemTools::GetEnv("CMAKE_NO_VERBOSE") == 0));
  2580. // This method will check the integrity of the build system if the
  2581. // option was given on the command line. It reads the given file to
  2582. // determine whether CMake should rerun.
  2583. // If no file is provided for the check, we have to rerun.
  2584. if(this->CheckBuildSystemArgument.size() == 0)
  2585. {
  2586. if(verbose)
  2587. {
  2588. cmOStringStream msg;
  2589. msg << "Re-run cmake no build system arguments\n";
  2590. cmSystemTools::Stdout(msg.str().c_str());
  2591. }
  2592. return 1;
  2593. }
  2594. // If the file provided does not exist, we have to rerun.
  2595. if(!cmSystemTools::FileExists(this->CheckBuildSystemArgument.c_str()))
  2596. {
  2597. if(verbose)
  2598. {
  2599. cmOStringStream msg;
  2600. msg << "Re-run cmake missing file: "
  2601. << this->CheckBuildSystemArgument.c_str() << "\n";
  2602. cmSystemTools::Stdout(msg.str().c_str());
  2603. }
  2604. return 1;
  2605. }
  2606. // Read the rerun check file and use it to decide whether to do the
  2607. // global generate.
  2608. cmake cm;
  2609. cmGlobalGenerator gg;
  2610. gg.SetCMakeInstance(&cm);
  2611. std::auto_ptr<cmLocalGenerator> lg(gg.CreateLocalGenerator());
  2612. cmMakefile* mf = lg->GetMakefile();
  2613. if(!mf->ReadListFile(0, this->CheckBuildSystemArgument.c_str()) ||
  2614. cmSystemTools::GetErrorOccuredFlag())
  2615. {
  2616. if(verbose)
  2617. {
  2618. cmOStringStream msg;
  2619. msg << "Re-run cmake error reading : "
  2620. << this->CheckBuildSystemArgument.c_str() << "\n";
  2621. cmSystemTools::Stdout(msg.str().c_str());
  2622. }
  2623. // There was an error reading the file. Just rerun.
  2624. return 1;
  2625. }
  2626. if(this->ClearBuildSystem)
  2627. {
  2628. // Get the generator used for this build system.
  2629. const char* genName = mf->GetDefinition("CMAKE_DEPENDS_GENERATOR");
  2630. if(!genName || genName[0] == '\0')
  2631. {
  2632. genName = "Unix Makefiles";
  2633. }
  2634. // Create the generator and use it to clear the dependencies.
  2635. std::auto_ptr<cmGlobalGenerator>
  2636. ggd(this->CreateGlobalGenerator(genName));
  2637. if(ggd.get())
  2638. {
  2639. std::auto_ptr<cmLocalGenerator> lgd(ggd->CreateLocalGenerator());
  2640. lgd->ClearDependencies(mf, verbose);
  2641. }
  2642. }
  2643. // If any byproduct of makefile generation is missing we must re-run.
  2644. std::vector<std::string> products;
  2645. if(const char* productStr = mf->GetDefinition("CMAKE_MAKEFILE_PRODUCTS"))
  2646. {
  2647. cmSystemTools::ExpandListArgument(productStr, products);
  2648. }
  2649. for(std::vector<std::string>::const_iterator pi = products.begin();
  2650. pi != products.end(); ++pi)
  2651. {
  2652. if(!(cmSystemTools::FileExists(pi->c_str()) ||
  2653. cmSystemTools::FileIsSymlink(pi->c_str())))
  2654. {
  2655. if(verbose)
  2656. {
  2657. cmOStringStream msg;
  2658. msg << "Re-run cmake, missing byproduct: " << *pi << "\n";
  2659. cmSystemTools::Stdout(msg.str().c_str());
  2660. }
  2661. return 1;
  2662. }
  2663. }
  2664. // Get the set of dependencies and outputs.
  2665. std::vector<std::string> depends;
  2666. std::vector<std::string> outputs;
  2667. const char* dependsStr = mf->GetDefinition("CMAKE_MAKEFILE_DEPENDS");
  2668. const char* outputsStr = mf->GetDefinition("CMAKE_MAKEFILE_OUTPUTS");
  2669. if(dependsStr && outputsStr)
  2670. {
  2671. cmSystemTools::ExpandListArgument(dependsStr, depends);
  2672. cmSystemTools::ExpandListArgument(outputsStr, outputs);
  2673. }
  2674. if(depends.empty() || outputs.empty())
  2675. {
  2676. // Not enough information was provided to do the test. Just rerun.
  2677. if(verbose)
  2678. {
  2679. cmOStringStream msg;
  2680. msg << "Re-run cmake no CMAKE_MAKEFILE_DEPENDS "
  2681. "or CMAKE_MAKEFILE_OUTPUTS :\n";
  2682. cmSystemTools::Stdout(msg.str().c_str());
  2683. }
  2684. return 1;
  2685. }
  2686. // Find the newest dependency.
  2687. std::vector<std::string>::iterator dep = depends.begin();
  2688. std::string dep_newest = *dep++;
  2689. for(;dep != depends.end(); ++dep)
  2690. {
  2691. int result = 0;
  2692. if(this->FileComparison->FileTimeCompare(dep_newest.c_str(),
  2693. dep->c_str(), &result))
  2694. {
  2695. if(result < 0)
  2696. {
  2697. dep_newest = *dep;
  2698. }
  2699. }
  2700. else
  2701. {
  2702. if(verbose)
  2703. {
  2704. cmOStringStream msg;
  2705. msg << "Re-run cmake: build system dependency is missing\n";
  2706. cmSystemTools::Stdout(msg.str().c_str());
  2707. }
  2708. return 1;
  2709. }
  2710. }
  2711. // Find the oldest output.
  2712. std::vector<std::string>::iterator out = outputs.begin();
  2713. std::string out_oldest = *out++;
  2714. for(;out != outputs.end(); ++out)
  2715. {
  2716. int result = 0;
  2717. if(this->FileComparison->FileTimeCompare(out_oldest.c_str(),
  2718. out->c_str(), &result))
  2719. {
  2720. if(result > 0)
  2721. {
  2722. out_oldest = *out;
  2723. }
  2724. }
  2725. else
  2726. {
  2727. if(verbose)
  2728. {
  2729. cmOStringStream msg;
  2730. msg << "Re-run cmake: build system output is missing\n";
  2731. cmSystemTools::Stdout(msg.str().c_str());
  2732. }
  2733. return 1;
  2734. }
  2735. }
  2736. // If any output is older than any dependency then rerun.
  2737. {
  2738. int result = 0;
  2739. if(!this->FileComparison->FileTimeCompare(out_oldest.c_str(),
  2740. dep_newest.c_str(),
  2741. &result) ||
  2742. result < 0)
  2743. {
  2744. if(verbose)
  2745. {
  2746. cmOStringStream msg;
  2747. msg << "Re-run cmake file: " << out_oldest.c_str()
  2748. << " older than: " << dep_newest.c_str() << "\n";
  2749. cmSystemTools::Stdout(msg.str().c_str());
  2750. }
  2751. return 1;
  2752. }
  2753. }
  2754. // No need to rerun.
  2755. return 0;
  2756. }
  2757. //----------------------------------------------------------------------------
  2758. void cmake::TruncateOutputLog(const char* fname)
  2759. {
  2760. std::string fullPath = this->GetHomeOutputDirectory();
  2761. fullPath += "/";
  2762. fullPath += fname;
  2763. struct stat st;
  2764. if ( ::stat(fullPath.c_str(), &st) )
  2765. {
  2766. return;
  2767. }
  2768. if ( !this->CacheManager->GetCacheValue("CMAKE_CACHEFILE_DIR") )
  2769. {
  2770. cmSystemTools::RemoveFile(fullPath.c_str());
  2771. return;
  2772. }
  2773. off_t fsize = st.st_size;
  2774. const off_t maxFileSize = 50 * 1024;
  2775. if ( fsize < maxFileSize )
  2776. {
  2777. //TODO: truncate file
  2778. return;
  2779. }
  2780. }
  2781. inline std::string removeQuotes(const std::string& s)
  2782. {
  2783. if(s[0] == '\"' && s[s.size()-1] == '\"')
  2784. {
  2785. return s.substr(1, s.size()-2);
  2786. }
  2787. return s;
  2788. }
  2789. std::string cmake::FindCMakeProgram(const char* name) const
  2790. {
  2791. std::string path;
  2792. if ((name) && (*name))
  2793. {
  2794. const cmMakefile* mf
  2795. = this->GetGlobalGenerator()->GetLocalGenerators()[0]->GetMakefile();
  2796. #ifdef CMAKE_BUILD_WITH_CMAKE
  2797. path = mf->GetRequiredDefinition("CMAKE_COMMAND");
  2798. path = removeQuotes(path);
  2799. path = cmSystemTools::GetFilenamePath(path.c_str());
  2800. path += "/";
  2801. path += name;
  2802. path += cmSystemTools::GetExecutableExtension();
  2803. if(!cmSystemTools::FileExists(path.c_str()))
  2804. {
  2805. path = mf->GetRequiredDefinition("CMAKE_COMMAND");
  2806. path = cmSystemTools::GetFilenamePath(path.c_str());
  2807. path += "/Debug/";
  2808. path += name;
  2809. path += cmSystemTools::GetExecutableExtension();
  2810. }
  2811. if(!cmSystemTools::FileExists(path.c_str()))
  2812. {
  2813. path = mf->GetRequiredDefinition("CMAKE_COMMAND");
  2814. path = cmSystemTools::GetFilenamePath(path.c_str());
  2815. path += "/Release/";
  2816. path += name;
  2817. path += cmSystemTools::GetExecutableExtension();
  2818. }
  2819. #else
  2820. // Only for bootstrap
  2821. path += mf->GetSafeDefinition("EXECUTABLE_OUTPUT_PATH");
  2822. path += "/";
  2823. path += name;
  2824. path += cmSystemTools::GetExecutableExtension();
  2825. #endif
  2826. }
  2827. return path;
  2828. }
  2829. const char* cmake::GetCTestCommand()
  2830. {
  2831. if ( this->CTestCommand.empty() )
  2832. {
  2833. this->CTestCommand = this->FindCMakeProgram("ctest");
  2834. }
  2835. if ( this->CTestCommand.empty() )
  2836. {
  2837. cmSystemTools::Error("Cannot find the CTest executable");
  2838. this->CTestCommand = "CTEST-COMMAND-NOT-FOUND";
  2839. }
  2840. return this->CTestCommand.c_str();
  2841. }
  2842. const char* cmake::GetCPackCommand()
  2843. {
  2844. if ( this->CPackCommand.empty() )
  2845. {
  2846. this->CPackCommand = this->FindCMakeProgram("cpack");
  2847. }
  2848. if ( this->CPackCommand.empty() )
  2849. {
  2850. cmSystemTools::Error("Cannot find the CPack executable");
  2851. this->CPackCommand = "CPACK-COMMAND-NOT-FOUND";
  2852. }
  2853. return this->CPackCommand.c_str();
  2854. }
  2855. const char* cmake::GetCMakeCommand()
  2856. {
  2857. return this->CMakeCommand.c_str();
  2858. }
  2859. void cmake::MarkCliAsUsed(const std::string& variable)
  2860. {
  2861. this->UsedCliVariables[variable] = true;
  2862. }
  2863. void cmake::GenerateGraphViz(const char* fileName) const
  2864. {
  2865. #ifdef CMAKE_BUILD_WITH_CMAKE
  2866. std::auto_ptr<cmGraphVizWriter> gvWriter(
  2867. new cmGraphVizWriter(this->GetGlobalGenerator()->GetLocalGenerators()));
  2868. std::string settingsFile = this->GetHomeOutputDirectory();
  2869. settingsFile += "/CMakeGraphVizOptions.cmake";
  2870. std::string fallbackSettingsFile = this->GetHomeDirectory();
  2871. fallbackSettingsFile += "/CMakeGraphVizOptions.cmake";
  2872. gvWriter->ReadSettings(settingsFile.c_str(), fallbackSettingsFile.c_str());
  2873. gvWriter->WritePerTargetFiles(fileName);
  2874. gvWriter->WriteTargetDependersFiles(fileName);
  2875. gvWriter->WriteGlobalFile(fileName);
  2876. #endif
  2877. }
  2878. //----------------------------------------------------------------------------
  2879. int cmake::SymlinkLibrary(std::vector<std::string>& args)
  2880. {
  2881. int result = 0;
  2882. std::string realName = args[2];
  2883. std::string soName = args[3];
  2884. std::string name = args[4];
  2885. if(soName != realName)
  2886. {
  2887. if(!cmake::SymlinkInternal(realName, soName))
  2888. {
  2889. cmSystemTools::ReportLastSystemError("cmake_symlink_library");
  2890. result = 1;
  2891. }
  2892. }
  2893. if(name != soName)
  2894. {
  2895. if(!cmake::SymlinkInternal(soName, name))
  2896. {
  2897. cmSystemTools::ReportLastSystemError("cmake_symlink_library");
  2898. result = 1;
  2899. }
  2900. }
  2901. return result;
  2902. }
  2903. //----------------------------------------------------------------------------
  2904. int cmake::SymlinkExecutable(std::vector<std::string>& args)
  2905. {
  2906. int result = 0;
  2907. std::string realName = args[2];
  2908. std::string name = args[3];
  2909. if(name != realName)
  2910. {
  2911. if(!cmake::SymlinkInternal(realName, name))
  2912. {
  2913. cmSystemTools::ReportLastSystemError("cmake_symlink_executable");
  2914. result = 1;
  2915. }
  2916. }
  2917. return result;
  2918. }
  2919. //----------------------------------------------------------------------------
  2920. bool cmake::SymlinkInternal(std::string const& file, std::string const& link)
  2921. {
  2922. if(cmSystemTools::FileExists(link.c_str()) ||
  2923. cmSystemTools::FileIsSymlink(link.c_str()))
  2924. {
  2925. cmSystemTools::RemoveFile(link.c_str());
  2926. }
  2927. #if defined(_WIN32) && !defined(__CYGWIN__)
  2928. return cmSystemTools::CopyFileAlways(file.c_str(), link.c_str());
  2929. #else
  2930. std::string linktext = cmSystemTools::GetFilenameName(file);
  2931. return cmSystemTools::CreateSymlink(linktext.c_str(), link.c_str());
  2932. #endif
  2933. }
  2934. //----------------------------------------------------------------------------
  2935. #ifdef CMAKE_BUILD_WITH_CMAKE
  2936. int cmake::ExecuteEchoColor(std::vector<std::string>& args)
  2937. {
  2938. // The arguments are
  2939. // argv[0] == <cmake-executable>
  2940. // argv[1] == cmake_echo_color
  2941. bool enabled = true;
  2942. int color = cmsysTerminal_Color_Normal;
  2943. bool newline = true;
  2944. for(unsigned int i=2; i < args.size(); ++i)
  2945. {
  2946. if(args[i].find("--switch=") == 0)
  2947. {
  2948. // Enable or disable color based on the switch value.
  2949. std::string value = args[i].substr(9);
  2950. if(!value.empty())
  2951. {
  2952. if(cmSystemTools::IsOn(value.c_str()))
  2953. {
  2954. enabled = true;
  2955. }
  2956. else
  2957. {
  2958. enabled = false;
  2959. }
  2960. }
  2961. }
  2962. else if(args[i] == "--normal")
  2963. {
  2964. color = cmsysTerminal_Color_Normal;
  2965. }
  2966. else if(args[i] == "--black")
  2967. {
  2968. color = cmsysTerminal_Color_ForegroundBlack;
  2969. }
  2970. else if(args[i] == "--red")
  2971. {
  2972. color = cmsysTerminal_Color_ForegroundRed;
  2973. }
  2974. else if(args[i] == "--green")
  2975. {
  2976. color = cmsysTerminal_Color_ForegroundGreen;
  2977. }
  2978. else if(args[i] == "--yellow")
  2979. {
  2980. color = cmsysTerminal_Color_ForegroundYellow;
  2981. }
  2982. else if(args[i] == "--blue")
  2983. {
  2984. color = cmsysTerminal_Color_ForegroundBlue;
  2985. }
  2986. else if(args[i] == "--magenta")
  2987. {
  2988. color = cmsysTerminal_Color_ForegroundMagenta;
  2989. }
  2990. else if(args[i] == "--cyan")
  2991. {
  2992. color = cmsysTerminal_Color_ForegroundCyan;
  2993. }
  2994. else if(args[i] == "--white")
  2995. {
  2996. color = cmsysTerminal_Color_ForegroundWhite;
  2997. }
  2998. else if(args[i] == "--bold")
  2999. {
  3000. color |= cmsysTerminal_Color_ForegroundBold;
  3001. }
  3002. else if(args[i] == "--no-newline")
  3003. {
  3004. newline = false;
  3005. }
  3006. else if(args[i] == "--newline")
  3007. {
  3008. newline = true;
  3009. }
  3010. else
  3011. {
  3012. // Color is enabled. Print with the current color.
  3013. cmSystemTools::MakefileColorEcho(color, args[i].c_str(),
  3014. newline, enabled);
  3015. }
  3016. }
  3017. return 0;
  3018. }
  3019. #else
  3020. int cmake::ExecuteEchoColor(std::vector<std::string>&)
  3021. {
  3022. return 1;
  3023. }
  3024. #endif
  3025. //----------------------------------------------------------------------------
  3026. int cmake::ExecuteLinkScript(std::vector<std::string>& args)
  3027. {
  3028. // The arguments are
  3029. // argv[0] == <cmake-executable>
  3030. // argv[1] == cmake_link_script
  3031. // argv[2] == <link-script-name>
  3032. // argv[3] == --verbose=?
  3033. bool verbose = false;
  3034. if(args.size() >= 4)
  3035. {
  3036. if(args[3].find("--verbose=") == 0)
  3037. {
  3038. if(!cmSystemTools::IsOff(args[3].substr(10).c_str()))
  3039. {
  3040. verbose = true;
  3041. }
  3042. }
  3043. }
  3044. // Allocate a process instance.
  3045. cmsysProcess* cp = cmsysProcess_New();
  3046. if(!cp)
  3047. {
  3048. std::cerr << "Error allocating process instance in link script."
  3049. << std::endl;
  3050. return 1;
  3051. }
  3052. // Children should share stdout and stderr with this process.
  3053. cmsysProcess_SetPipeShared(cp, cmsysProcess_Pipe_STDOUT, 1);
  3054. cmsysProcess_SetPipeShared(cp, cmsysProcess_Pipe_STDERR, 1);
  3055. // Run the command lines verbatim.
  3056. cmsysProcess_SetOption(cp, cmsysProcess_Option_Verbatim, 1);
  3057. // Read command lines from the script.
  3058. std::ifstream fin(args[2].c_str());
  3059. if(!fin)
  3060. {
  3061. std::cerr << "Error opening link script \""
  3062. << args[2] << "\"" << std::endl;
  3063. return 1;
  3064. }
  3065. // Run one command at a time.
  3066. std::string command;
  3067. int result = 0;
  3068. while(result == 0 && cmSystemTools::GetLineFromStream(fin, command))
  3069. {
  3070. // Setup this command line.
  3071. const char* cmd[2] = {command.c_str(), 0};
  3072. cmsysProcess_SetCommand(cp, cmd);
  3073. // Report the command if verbose output is enabled.
  3074. if(verbose)
  3075. {
  3076. std::cout << command << std::endl;
  3077. }
  3078. // Run the command and wait for it to exit.
  3079. cmsysProcess_Execute(cp);
  3080. cmsysProcess_WaitForExit(cp, 0);
  3081. // Report failure if any.
  3082. switch(cmsysProcess_GetState(cp))
  3083. {
  3084. case cmsysProcess_State_Exited:
  3085. {
  3086. int value = cmsysProcess_GetExitValue(cp);
  3087. if(value != 0)
  3088. {
  3089. result = value;
  3090. }
  3091. }
  3092. break;
  3093. case cmsysProcess_State_Exception:
  3094. std::cerr << "Error running link command: "
  3095. << cmsysProcess_GetExceptionString(cp) << std::endl;
  3096. result = 1;
  3097. break;
  3098. case cmsysProcess_State_Error:
  3099. std::cerr << "Error running link command: "
  3100. << cmsysProcess_GetErrorString(cp) << std::endl;
  3101. result = 2;
  3102. break;
  3103. default:
  3104. break;
  3105. };
  3106. }
  3107. // Free the process instance.
  3108. cmsysProcess_Delete(cp);
  3109. // Return the final resulting return value.
  3110. return result;
  3111. }
  3112. void cmake::DefineProperties(cmake *cm)
  3113. {
  3114. cm->DefineProperty
  3115. ("REPORT_UNDEFINED_PROPERTIES", cmProperty::GLOBAL,
  3116. "If set, report any undefined properties to this file.",
  3117. "If this property is set to a filename then when CMake runs "
  3118. "it will report any properties or variables that were accessed "
  3119. "but not defined into the filename specified in this property."
  3120. );
  3121. cm->DefineProperty
  3122. ("TARGET_SUPPORTS_SHARED_LIBS", cmProperty::GLOBAL,
  3123. "Does the target platform support shared libraries.",
  3124. "TARGET_SUPPORTS_SHARED_LIBS is a boolean specifying whether the target "
  3125. "platform supports shared libraries. Basically all current general "
  3126. "general purpose OS do so, the exception are usually embedded systems "
  3127. "with no or special OSs.");
  3128. cm->DefineProperty
  3129. ("TARGET_ARCHIVES_MAY_BE_SHARED_LIBS", cmProperty::GLOBAL,
  3130. "Set if shared libraries may be named like archives.",
  3131. "On AIX shared libraries may be named \"lib<name>.a\". "
  3132. "This property is set to true on such platforms.");
  3133. cm->DefineProperty
  3134. ("FIND_LIBRARY_USE_LIB64_PATHS", cmProperty::GLOBAL,
  3135. "Whether FIND_LIBRARY should automatically search lib64 directories.",
  3136. "FIND_LIBRARY_USE_LIB64_PATHS is a boolean specifying whether the "
  3137. "FIND_LIBRARY command should automatically search the lib64 variant of "
  3138. "directories called lib in the search path when building 64-bit "
  3139. "binaries.");
  3140. cm->DefineProperty
  3141. ("FIND_LIBRARY_USE_OPENBSD_VERSIONING", cmProperty::GLOBAL,
  3142. "Whether FIND_LIBRARY should find OpenBSD-style shared libraries.",
  3143. "This property is a boolean specifying whether the FIND_LIBRARY "
  3144. "command should find shared libraries with OpenBSD-style versioned "
  3145. "extension: \".so.<major>.<minor>\". "
  3146. "The property is set to true on OpenBSD and false on other platforms.");
  3147. cm->DefineProperty
  3148. ("ENABLED_FEATURES", cmProperty::GLOBAL,
  3149. "List of features which are enabled during the CMake run.",
  3150. "List of features which are enabled during the CMake run. By default "
  3151. "it contains the names of all packages which were found. This is "
  3152. "determined using the <NAME>_FOUND variables. Packages which are "
  3153. "searched QUIET are not listed. A project can add its own features to "
  3154. "this list. "
  3155. "This property is used by the macros in FeatureSummary.cmake.");
  3156. cm->DefineProperty
  3157. ("DISABLED_FEATURES", cmProperty::GLOBAL,
  3158. "List of features which are disabled during the CMake run.",
  3159. "List of features which are disabled during the CMake run. By default "
  3160. "it contains the names of all packages which were not found. This is "
  3161. "determined using the <NAME>_FOUND variables. Packages which are "
  3162. "searched QUIET are not listed. A project can add its own features to "
  3163. "this list. "
  3164. "This property is used by the macros in FeatureSummary.cmake.");
  3165. cm->DefineProperty
  3166. ("PACKAGES_FOUND", cmProperty::GLOBAL,
  3167. "List of packages which were found during the CMake run.",
  3168. "List of packages which were found during the CMake run. Whether a "
  3169. "package has been found is determined using the <NAME>_FOUND variables.");
  3170. cm->DefineProperty
  3171. ("PACKAGES_NOT_FOUND", cmProperty::GLOBAL,
  3172. "List of packages which were not found during the CMake run.",
  3173. "List of packages which were not found during the CMake run. Whether a "
  3174. "package has been found is determined using the <NAME>_FOUND variables.");
  3175. cm->DefineProperty(
  3176. "__CMAKE_DELETE_CACHE_CHANGE_VARS_", cmProperty::GLOBAL,
  3177. "Internal property",
  3178. "Used to detect compiler changes, Do not set.");
  3179. cm->DefineProperty(
  3180. "DEBUG_CONFIGURATIONS", cmProperty::GLOBAL,
  3181. "Specify which configurations are for debugging.",
  3182. "The value must be a semi-colon separated list of configuration names. "
  3183. "Currently this property is used only by the target_link_libraries "
  3184. "command (see its documentation for details). "
  3185. "Additional uses may be defined in the future. "
  3186. "\n"
  3187. "This property must be set at the top level of the project and before "
  3188. "the first target_link_libraries command invocation. "
  3189. "If any entry in the list does not match a valid configuration for "
  3190. "the project the behavior is undefined.");
  3191. cm->DefineProperty(
  3192. "GLOBAL_DEPENDS_DEBUG_MODE", cmProperty::GLOBAL,
  3193. "Enable global target dependency graph debug mode.",
  3194. "CMake automatically analyzes the global inter-target dependency graph "
  3195. "at the beginning of native build system generation. "
  3196. "This property causes it to display details of its analysis to stderr.");
  3197. cm->DefineProperty(
  3198. "GLOBAL_DEPENDS_NO_CYCLES", cmProperty::GLOBAL,
  3199. "Disallow global target dependency graph cycles.",
  3200. "CMake automatically analyzes the global inter-target dependency graph "
  3201. "at the beginning of native build system generation. "
  3202. "It reports an error if the dependency graph contains a cycle that "
  3203. "does not consist of all STATIC library targets. "
  3204. "This property tells CMake to disallow all cycles completely, even "
  3205. "among static libraries.");
  3206. cm->DefineProperty(
  3207. "ALLOW_DUPLICATE_CUSTOM_TARGETS", cmProperty::GLOBAL,
  3208. "Allow duplicate custom targets to be created.",
  3209. "Normally CMake requires that all targets built in a project have "
  3210. "globally unique logical names (see policy CMP0002). "
  3211. "This is necessary to generate meaningful project file names in "
  3212. "Xcode and VS IDE generators. "
  3213. "It also allows the target names to be referenced unambiguously.\n"
  3214. "Makefile generators are capable of supporting duplicate custom target "
  3215. "names. "
  3216. "For projects that care only about Makefile generators and do "
  3217. "not wish to support Xcode or VS IDE generators, one may set this "
  3218. "property to true to allow duplicate custom targets. "
  3219. "The property allows multiple add_custom_target command calls in "
  3220. "different directories to specify the same target name. "
  3221. "However, setting this property will cause non-Makefile generators "
  3222. "to produce an error and refuse to generate the project."
  3223. );
  3224. cm->DefineProperty
  3225. ("IN_TRY_COMPILE", cmProperty::GLOBAL,
  3226. "Read-only property that is true during a try-compile configuration.",
  3227. "True when building a project inside a TRY_COMPILE or TRY_RUN command.");
  3228. cm->DefineProperty
  3229. ("ENABLED_LANGUAGES", cmProperty::GLOBAL,
  3230. "Read-only property that contains the list of currently "
  3231. "enabled languages",
  3232. "Set to list of currently enabled languages.");
  3233. cm->DefineProperty
  3234. ("RULE_LAUNCH_COMPILE", cmProperty::GLOBAL,
  3235. "Specify a launcher for compile rules.",
  3236. "Makefile generators prefix compiler commands with the given "
  3237. "launcher command line. "
  3238. "This is intended to allow launchers to intercept build problems "
  3239. "with high granularity. "
  3240. "Non-Makefile generators currently ignore this property.");
  3241. cm->DefineProperty
  3242. ("RULE_LAUNCH_LINK", cmProperty::GLOBAL,
  3243. "Specify a launcher for link rules.",
  3244. "Makefile generators prefix link and archive commands with the given "
  3245. "launcher command line. "
  3246. "This is intended to allow launchers to intercept build problems "
  3247. "with high granularity. "
  3248. "Non-Makefile generators currently ignore this property.");
  3249. cm->DefineProperty
  3250. ("RULE_LAUNCH_CUSTOM", cmProperty::GLOBAL,
  3251. "Specify a launcher for custom rules.",
  3252. "Makefile generators prefix custom commands with the given "
  3253. "launcher command line. "
  3254. "This is intended to allow launchers to intercept build problems "
  3255. "with high granularity. "
  3256. "Non-Makefile generators currently ignore this property.");
  3257. cm->DefineProperty
  3258. ("RULE_MESSAGES", cmProperty::GLOBAL,
  3259. "Specify whether to report a message for each make rule.",
  3260. "This property specifies whether Makefile generators should add a "
  3261. "progress message describing what each build rule does. "
  3262. "If the property is not set the default is ON. "
  3263. "Set the property to OFF to disable granular messages and report only "
  3264. "as each target completes. "
  3265. "This is intended to allow scripted builds to avoid the build time "
  3266. "cost of detailed reports. "
  3267. "If a CMAKE_RULE_MESSAGES cache entry exists its value initializes "
  3268. "the value of this property. "
  3269. "Non-Makefile generators currently ignore this property.");
  3270. cm->DefineProperty
  3271. ("USE_FOLDERS", cmProperty::GLOBAL,
  3272. "Use the FOLDER target property to organize targets into folders.",
  3273. "If not set, CMake treats this property as OFF by default. "
  3274. "CMake generators that are capable of organizing into a "
  3275. "hierarchy of folders use the values of the FOLDER target "
  3276. "property to name those folders. See also the documentation "
  3277. "for the FOLDER target property.");
  3278. cm->DefineProperty
  3279. ("PREDEFINED_TARGETS_FOLDER", cmProperty::GLOBAL,
  3280. "Name of FOLDER for targets that are added automatically by CMake.",
  3281. "If not set, CMake uses \"CMakePredefinedTargets\" as a default "
  3282. "value for this property. Targets such as INSTALL, PACKAGE and "
  3283. "RUN_TESTS will be organized into this FOLDER. See also the "
  3284. "documentation for the FOLDER target property.");
  3285. // ================================================================
  3286. // define variables as well
  3287. // ================================================================
  3288. cmDocumentVariables::DefineVariables(cm);
  3289. }
  3290. void cmake::DefineProperty(const char *name, cmProperty::ScopeType scope,
  3291. const char *ShortDescription,
  3292. const char *FullDescription,
  3293. bool chained, const char *docSection)
  3294. {
  3295. this->PropertyDefinitions[scope].DefineProperty(name,scope,ShortDescription,
  3296. FullDescription,
  3297. docSection,
  3298. chained);
  3299. }
  3300. cmPropertyDefinition *cmake
  3301. ::GetPropertyDefinition(const char *name,
  3302. cmProperty::ScopeType scope)
  3303. {
  3304. if (this->IsPropertyDefined(name,scope))
  3305. {
  3306. return &(this->PropertyDefinitions[scope][name]);
  3307. }
  3308. return 0;
  3309. }
  3310. void cmake::RecordPropertyAccess(const char *name,
  3311. cmProperty::ScopeType scope)
  3312. {
  3313. this->AccessedProperties.insert
  3314. (std::pair<cmStdString,cmProperty::ScopeType>(name,scope));
  3315. }
  3316. void cmake::ReportUndefinedPropertyAccesses(const char *filename)
  3317. {
  3318. FILE *progFile = fopen(filename,"w");
  3319. if (!progFile || !this->GlobalGenerator)
  3320. {
  3321. return;
  3322. }
  3323. // what are the enabled languages?
  3324. std::vector<std::string> enLangs;
  3325. this->GlobalGenerator->GetEnabledLanguages(enLangs);
  3326. // Common configuration names.
  3327. // TODO: Compute current configuration(s).
  3328. std::vector<std::string> enConfigs;
  3329. enConfigs.push_back("");
  3330. enConfigs.push_back("DEBUG");
  3331. enConfigs.push_back("RELEASE");
  3332. enConfigs.push_back("MINSIZEREL");
  3333. enConfigs.push_back("RELWITHDEBINFO");
  3334. // take all the defined properties and add definitions for all the enabled
  3335. // languages
  3336. std::set<std::pair<cmStdString,cmProperty::ScopeType> > aliasedProperties;
  3337. std::map<cmProperty::ScopeType, cmPropertyDefinitionMap>::iterator i;
  3338. i = this->PropertyDefinitions.begin();
  3339. for (;i != this->PropertyDefinitions.end(); ++i)
  3340. {
  3341. cmPropertyDefinitionMap::iterator j;
  3342. for (j = i->second.begin(); j != i->second.end(); ++j)
  3343. {
  3344. // TODO: What if both <LANG> and <CONFIG> appear?
  3345. if (j->first.find("<CONFIG>") != std::string::npos)
  3346. {
  3347. std::vector<std::string>::const_iterator k;
  3348. for (k = enConfigs.begin(); k != enConfigs.end(); ++k)
  3349. {
  3350. std::string tmp = j->first;
  3351. cmSystemTools::ReplaceString(tmp, "<CONFIG>", k->c_str());
  3352. // add alias
  3353. aliasedProperties.insert
  3354. (std::pair<cmStdString,cmProperty::ScopeType>(tmp,i->first));
  3355. }
  3356. }
  3357. if (j->first.find("<LANG>") != std::string::npos)
  3358. {
  3359. std::vector<std::string>::const_iterator k;
  3360. for (k = enLangs.begin(); k != enLangs.end(); ++k)
  3361. {
  3362. std::string tmp = j->first;
  3363. cmSystemTools::ReplaceString(tmp, "<LANG>", k->c_str());
  3364. // add alias
  3365. aliasedProperties.insert
  3366. (std::pair<cmStdString,cmProperty::ScopeType>(tmp,i->first));
  3367. }
  3368. }
  3369. }
  3370. }
  3371. std::set<std::pair<cmStdString,cmProperty::ScopeType> >::const_iterator ap;
  3372. ap = this->AccessedProperties.begin();
  3373. for (;ap != this->AccessedProperties.end(); ++ap)
  3374. {
  3375. if (!this->IsPropertyDefined(ap->first.c_str(),ap->second) &&
  3376. aliasedProperties.find(std::pair<cmStdString,cmProperty::ScopeType>
  3377. (ap->first,ap->second)) ==
  3378. aliasedProperties.end())
  3379. {
  3380. const char *scopeStr = "";
  3381. switch (ap->second)
  3382. {
  3383. case cmProperty::TARGET:
  3384. scopeStr = "TARGET";
  3385. break;
  3386. case cmProperty::SOURCE_FILE:
  3387. scopeStr = "SOURCE_FILE";
  3388. break;
  3389. case cmProperty::DIRECTORY:
  3390. scopeStr = "DIRECTORY";
  3391. break;
  3392. case cmProperty::TEST:
  3393. scopeStr = "TEST";
  3394. break;
  3395. case cmProperty::VARIABLE:
  3396. scopeStr = "VARIABLE";
  3397. break;
  3398. case cmProperty::CACHED_VARIABLE:
  3399. scopeStr = "CACHED_VARIABLE";
  3400. break;
  3401. default:
  3402. scopeStr = "unknown";
  3403. break;
  3404. }
  3405. fprintf(progFile, "%s with scope %s\n", ap->first.c_str(), scopeStr);
  3406. }
  3407. }
  3408. fclose(progFile);
  3409. }
  3410. bool cmake::IsPropertyDefined(const char *name, cmProperty::ScopeType scope)
  3411. {
  3412. return this->PropertyDefinitions[scope].IsPropertyDefined(name);
  3413. }
  3414. bool cmake::IsPropertyChained(const char *name, cmProperty::ScopeType scope)
  3415. {
  3416. return this->PropertyDefinitions[scope].IsPropertyChained(name);
  3417. }
  3418. void cmake::SetProperty(const char* prop, const char* value)
  3419. {
  3420. if (!prop)
  3421. {
  3422. return;
  3423. }
  3424. // Special hook to invalidate cached value.
  3425. if(strcmp(prop, "DEBUG_CONFIGURATIONS") == 0)
  3426. {
  3427. this->DebugConfigs.clear();
  3428. }
  3429. this->Properties.SetProperty(prop, value, cmProperty::GLOBAL);
  3430. }
  3431. void cmake::AppendProperty(const char* prop, const char* value, bool asString)
  3432. {
  3433. if (!prop)
  3434. {
  3435. return;
  3436. }
  3437. // Special hook to invalidate cached value.
  3438. if(strcmp(prop, "DEBUG_CONFIGURATIONS") == 0)
  3439. {
  3440. this->DebugConfigs.clear();
  3441. }
  3442. this->Properties.AppendProperty(prop, value, cmProperty::GLOBAL, asString);
  3443. }
  3444. const char *cmake::GetProperty(const char* prop)
  3445. {
  3446. return this->GetProperty(prop, cmProperty::GLOBAL);
  3447. }
  3448. const char *cmake::GetProperty(const char* prop, cmProperty::ScopeType scope)
  3449. {
  3450. if(!prop)
  3451. {
  3452. return 0;
  3453. }
  3454. bool chain = false;
  3455. // watch for special properties
  3456. std::string propname = prop;
  3457. std::string output = "";
  3458. if ( propname == "CACHE_VARIABLES" )
  3459. {
  3460. cmCacheManager::CacheIterator cit =
  3461. this->GetCacheManager()->GetCacheIterator();
  3462. for ( cit.Begin(); !cit.IsAtEnd(); cit.Next() )
  3463. {
  3464. if ( output.size() )
  3465. {
  3466. output += ";";
  3467. }
  3468. output += cit.GetName();
  3469. }
  3470. this->SetProperty("CACHE_VARIABLES", output.c_str());
  3471. }
  3472. else if ( propname == "COMMANDS" )
  3473. {
  3474. cmake::RegisteredCommandsMap::iterator cmds
  3475. = this->GetCommands()->begin();
  3476. for (unsigned int cc=0 ; cmds != this->GetCommands()->end(); ++ cmds )
  3477. {
  3478. if ( cc > 0 )
  3479. {
  3480. output += ";";
  3481. }
  3482. output += cmds->first.c_str();
  3483. cc++;
  3484. }
  3485. this->SetProperty("COMMANDS",output.c_str());
  3486. }
  3487. else if ( propname == "IN_TRY_COMPILE" )
  3488. {
  3489. this->SetProperty("IN_TRY_COMPILE",
  3490. this->GetIsInTryCompile()? "1":"0");
  3491. }
  3492. else if ( propname == "ENABLED_LANGUAGES" )
  3493. {
  3494. std::string lang;
  3495. if(this->GlobalGenerator)
  3496. {
  3497. std::vector<std::string> enLangs;
  3498. this->GlobalGenerator->GetEnabledLanguages(enLangs);
  3499. const char* sep = "";
  3500. for(std::vector<std::string>::iterator i = enLangs.begin();
  3501. i != enLangs.end(); ++i)
  3502. {
  3503. lang += sep;
  3504. sep = ";";
  3505. lang += *i;
  3506. }
  3507. }
  3508. this->SetProperty("ENABLED_LANGUAGES", lang.c_str());
  3509. }
  3510. return this->Properties.GetPropertyValue(prop, scope, chain);
  3511. }
  3512. bool cmake::GetPropertyAsBool(const char* prop)
  3513. {
  3514. return cmSystemTools::IsOn(this->GetProperty(prop));
  3515. }
  3516. int cmake::GetSystemInformation(std::vector<std::string>& args)
  3517. {
  3518. // so create the directory
  3519. std::string resultFile;
  3520. std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
  3521. std::string destPath = cwd + "/__cmake_systeminformation";
  3522. cmSystemTools::RemoveADirectory(destPath.c_str());
  3523. if (!cmSystemTools::MakeDirectory(destPath.c_str()))
  3524. {
  3525. std::cerr << "Error: --system-information must be run from a "
  3526. "writable directory!\n";
  3527. return 1;
  3528. }
  3529. // process the arguments
  3530. bool writeToStdout = true;
  3531. for(unsigned int i=1; i < args.size(); ++i)
  3532. {
  3533. std::string arg = args[i];
  3534. if(arg.find("-V",0) == 0)
  3535. {
  3536. this->Verbose = true;
  3537. }
  3538. else if(arg.find("-G",0) == 0)
  3539. {
  3540. std::string value = arg.substr(2);
  3541. if(value.size() == 0)
  3542. {
  3543. ++i;
  3544. if(i >= args.size())
  3545. {
  3546. cmSystemTools::Error("No generator specified for -G");
  3547. return -1;
  3548. }
  3549. value = args[i];
  3550. }
  3551. cmGlobalGenerator* gen =
  3552. this->CreateGlobalGenerator(value.c_str());
  3553. if(!gen)
  3554. {
  3555. cmSystemTools::Error("Could not create named generator ",
  3556. value.c_str());
  3557. }
  3558. else
  3559. {
  3560. this->SetGlobalGenerator(gen);
  3561. }
  3562. }
  3563. // no option assume it is the output file
  3564. else
  3565. {
  3566. if (!cmSystemTools::FileIsFullPath(arg.c_str()))
  3567. {
  3568. resultFile = cwd;
  3569. resultFile += "/";
  3570. }
  3571. resultFile += arg;
  3572. writeToStdout = false;
  3573. }
  3574. }
  3575. // we have to find the module directory, so we can copy the files
  3576. this->AddCMakePaths();
  3577. std::string modulesPath =
  3578. this->CacheManager->GetCacheValue("CMAKE_ROOT");
  3579. modulesPath += "/Modules";
  3580. std::string inFile = modulesPath;
  3581. inFile += "/SystemInformation.cmake";
  3582. std::string outFile = destPath;
  3583. outFile += "/CMakeLists.txt";
  3584. // Copy file
  3585. if(!cmSystemTools::cmCopyFile(inFile.c_str(), outFile.c_str()))
  3586. {
  3587. std::cerr << "Error copying file \"" << inFile.c_str()
  3588. << "\" to \"" << outFile.c_str() << "\".\n";
  3589. return 1;
  3590. }
  3591. // do we write to a file or to stdout?
  3592. if (resultFile.size() == 0)
  3593. {
  3594. resultFile = cwd;
  3595. resultFile += "/__cmake_systeminformation/results.txt";
  3596. }
  3597. // now run cmake on the CMakeLists file
  3598. cmSystemTools::ChangeDirectory(destPath.c_str());
  3599. std::vector<std::string> args2;
  3600. args2.push_back(args[0]);
  3601. args2.push_back(destPath);
  3602. std::string resultArg = "-DRESULT_FILE=";
  3603. resultArg += resultFile;
  3604. args2.push_back(resultArg);
  3605. int res = this->Run(args2, false);
  3606. if (res != 0)
  3607. {
  3608. std::cerr << "Error: --system-information failed on internal CMake!\n";
  3609. return res;
  3610. }
  3611. // change back to the original directory
  3612. cmSystemTools::ChangeDirectory(cwd.c_str());
  3613. // echo results to stdout if needed
  3614. if (writeToStdout)
  3615. {
  3616. FILE* fin = fopen(resultFile.c_str(), "r");
  3617. if(fin)
  3618. {
  3619. const int bufferSize = 4096;
  3620. char buffer[bufferSize];
  3621. size_t n;
  3622. while((n = fread(buffer, 1, bufferSize, fin)) > 0)
  3623. {
  3624. for(char* c = buffer; c < buffer+n; ++c)
  3625. {
  3626. putc(*c, stdout);
  3627. }
  3628. fflush(stdout);
  3629. }
  3630. fclose(fin);
  3631. }
  3632. }
  3633. // clean up the directory
  3634. cmSystemTools::RemoveADirectory(destPath.c_str());
  3635. return 0;
  3636. }
  3637. //----------------------------------------------------------------------------
  3638. static bool cmakeCheckStampFile(const char* stampName)
  3639. {
  3640. // The stamp file does not exist. Use the stamp dependencies to
  3641. // determine whether it is really out of date. This works in
  3642. // conjunction with cmLocalVisualStudio7Generator to avoid
  3643. // repeatedly re-running CMake when the user rebuilds the entire
  3644. // solution.
  3645. std::string stampDepends = stampName;
  3646. stampDepends += ".depend";
  3647. #if defined(_WIN32) || defined(__CYGWIN__)
  3648. std::ifstream fin(stampDepends.c_str(), std::ios::in | std::ios::binary);
  3649. #else
  3650. std::ifstream fin(stampDepends.c_str(), std::ios::in);
  3651. #endif
  3652. if(!fin)
  3653. {
  3654. // The stamp dependencies file cannot be read. Just assume the
  3655. // build system is really out of date.
  3656. std::cout << "CMake is re-running because " << stampName
  3657. << " dependency file is missing.\n";
  3658. return false;
  3659. }
  3660. // Compare the stamp dependencies against the dependency file itself.
  3661. cmFileTimeComparison ftc;
  3662. std::string dep;
  3663. while(cmSystemTools::GetLineFromStream(fin, dep))
  3664. {
  3665. int result;
  3666. if(dep.length() >= 1 && dep[0] != '#' &&
  3667. (!ftc.FileTimeCompare(stampDepends.c_str(), dep.c_str(), &result)
  3668. || result < 0))
  3669. {
  3670. // The stamp depends file is older than this dependency. The
  3671. // build system is really out of date.
  3672. std::cout << "CMake is re-running because " << stampName
  3673. << " is out-of-date.\n";
  3674. std::cout << " the file '" << dep << "'\n";
  3675. std::cout << " is newer than '" << stampDepends << "'\n";
  3676. std::cout << " result='" << result << "'\n";
  3677. return false;
  3678. }
  3679. }
  3680. // The build system is up to date. The stamp file has been removed
  3681. // by the VS IDE due to a "rebuild" request. Just restore it.
  3682. std::ofstream stamp(stampName);
  3683. stamp << "# CMake generation timestamp file this directory.\n";
  3684. if(stamp)
  3685. {
  3686. // Notify the user why CMake is not re-running. It is safe to
  3687. // just print to stdout here because this code is only reachable
  3688. // through an undocumented flag used by the VS generator.
  3689. std::cout << "CMake does not need to re-run because "
  3690. << stampName << " is up-to-date.\n";
  3691. return true;
  3692. }
  3693. else
  3694. {
  3695. cmSystemTools::Error("Cannot restore timestamp ", stampName);
  3696. return false;
  3697. }
  3698. }
  3699. //----------------------------------------------------------------------------
  3700. static bool cmakeCheckStampList(const char* stampList)
  3701. {
  3702. // If the stamp list does not exist CMake must rerun to generate it.
  3703. if(!cmSystemTools::FileExists(stampList))
  3704. {
  3705. std::cout << "CMake is re-running because generate.stamp.list "
  3706. << "is missing.\n";
  3707. return false;
  3708. }
  3709. std::ifstream fin(stampList);
  3710. if(!fin)
  3711. {
  3712. std::cout << "CMake is re-running because generate.stamp.list "
  3713. << "could not be read.\n";
  3714. return false;
  3715. }
  3716. // Check each stamp.
  3717. std::string stampName;
  3718. while(cmSystemTools::GetLineFromStream(fin, stampName))
  3719. {
  3720. if(!cmakeCheckStampFile(stampName.c_str()))
  3721. {
  3722. return false;
  3723. }
  3724. }
  3725. return true;
  3726. }
  3727. // For visual studio 2005 and newer manifest files need to be embeded into
  3728. // exe and dll's. This code does that in such a way that incremental linking
  3729. // still works.
  3730. int cmake::VisualStudioLink(std::vector<std::string>& args, int type)
  3731. {
  3732. if(args.size() < 2)
  3733. {
  3734. return -1;
  3735. }
  3736. bool verbose = false;
  3737. if(cmSystemTools::GetEnv("VERBOSE"))
  3738. {
  3739. verbose = true;
  3740. }
  3741. std::vector<std::string> expandedArgs;
  3742. for(std::vector<std::string>::iterator i = args.begin();
  3743. i != args.end(); ++i)
  3744. {
  3745. // check for nmake temporary files
  3746. if((*i)[0] == '@' && i->find("@CMakeFiles") != 0 )
  3747. {
  3748. std::ifstream fin(i->substr(1).c_str());
  3749. std::string line;
  3750. while(cmSystemTools::GetLineFromStream(fin,
  3751. line))
  3752. {
  3753. cmSystemTools::ParseWindowsCommandLine(line.c_str(), expandedArgs);
  3754. }
  3755. }
  3756. else
  3757. {
  3758. expandedArgs.push_back(*i);
  3759. }
  3760. }
  3761. bool hasIncremental = false;
  3762. bool hasManifest = true;
  3763. for(std::vector<std::string>::iterator i = expandedArgs.begin();
  3764. i != expandedArgs.end(); ++i)
  3765. {
  3766. if(cmSystemTools::Strucmp(i->c_str(), "/INCREMENTAL:YES") == 0)
  3767. {
  3768. hasIncremental = true;
  3769. }
  3770. if(cmSystemTools::Strucmp(i->c_str(), "/INCREMENTAL") == 0)
  3771. {
  3772. hasIncremental = true;
  3773. }
  3774. if(cmSystemTools::Strucmp(i->c_str(), "/MANIFEST:NO") == 0)
  3775. {
  3776. hasManifest = false;
  3777. }
  3778. }
  3779. if(hasIncremental && hasManifest)
  3780. {
  3781. if(verbose)
  3782. {
  3783. std::cout << "Visual Studio Incremental Link with embeded manifests\n";
  3784. }
  3785. return cmake::VisualStudioLinkIncremental(expandedArgs, type, verbose);
  3786. }
  3787. if(verbose)
  3788. {
  3789. if(!hasIncremental)
  3790. {
  3791. std::cout << "Visual Studio Non-Incremental Link\n";
  3792. }
  3793. else
  3794. {
  3795. std::cout << "Visual Studio Incremental Link without manifests\n";
  3796. }
  3797. }
  3798. return cmake::VisualStudioLinkNonIncremental(expandedArgs,
  3799. type, hasManifest, verbose);
  3800. }
  3801. int cmake::ParseVisualStudioLinkCommand(std::vector<std::string>& args,
  3802. std::vector<cmStdString>& command,
  3803. std::string& targetName)
  3804. {
  3805. std::vector<std::string>::iterator i = args.begin();
  3806. i++; // skip -E
  3807. i++; // skip vs_link_dll or vs_link_exe
  3808. command.push_back(*i);
  3809. i++; // move past link command
  3810. for(; i != args.end(); ++i)
  3811. {
  3812. command.push_back(*i);
  3813. if(i->find("/Fe") == 0)
  3814. {
  3815. targetName = i->substr(3);
  3816. }
  3817. if(i->find("/out:") == 0)
  3818. {
  3819. targetName = i->substr(5);
  3820. }
  3821. }
  3822. if(targetName.size() == 0 || command.size() == 0)
  3823. {
  3824. return -1;
  3825. }
  3826. return 0;
  3827. }
  3828. bool cmake::RunCommand(const char* comment,
  3829. std::vector<cmStdString>& command,
  3830. bool verbose,
  3831. int* retCodeOut)
  3832. {
  3833. if(verbose)
  3834. {
  3835. std::cout << comment << ":\n";
  3836. for(std::vector<cmStdString>::iterator i = command.begin();
  3837. i != command.end(); ++i)
  3838. {
  3839. std::cout << i->c_str() << " ";
  3840. }
  3841. std::cout << "\n";
  3842. }
  3843. std::string output;
  3844. int retCode =0;
  3845. // use rc command to create .res file
  3846. cmSystemTools::RunSingleCommand(command,
  3847. &output,
  3848. &retCode, 0, cmSystemTools::OUTPUT_NONE);
  3849. // always print the output of the command, unless
  3850. // it is the dumb rc command banner, but if the command
  3851. // returned an error code then print the output anyway as
  3852. // the banner may be mixed with some other important information.
  3853. if(output.find("Resource Compiler Version") == output.npos
  3854. || retCode !=0)
  3855. {
  3856. std::cout << output;
  3857. }
  3858. // if retCodeOut is requested then always return true
  3859. // and set the retCodeOut to retCode
  3860. if(retCodeOut)
  3861. {
  3862. *retCodeOut = retCode;
  3863. return true;
  3864. }
  3865. if(retCode != 0)
  3866. {
  3867. std::cout << comment << " failed. with " << retCode << "\n";
  3868. }
  3869. return retCode == 0;
  3870. }
  3871. int cmake::VisualStudioLinkIncremental(std::vector<std::string>& args,
  3872. int type, bool verbose)
  3873. {
  3874. // This follows the steps listed here:
  3875. // http://blogs.msdn.com/zakramer/archive/2006/05/22/603558.aspx
  3876. // 1. Compiler compiles the application and generates the *.obj files.
  3877. // 2. An empty manifest file is generated if this is a clean build and if
  3878. // not the previous one is reused.
  3879. // 3. The resource compiler (rc.exe) compiles the *.manifest file to a
  3880. // *.res file.
  3881. // 4. Linker generates the binary (EXE or DLL) with the /incremental
  3882. // switch and embeds the dummy manifest file. The linker also generates
  3883. // the real manifest file based on the binaries that your binary depends
  3884. // on.
  3885. // 5. The manifest tool (mt.exe) is then used to generate the final
  3886. // manifest.
  3887. // If the final manifest is changed, then 6 and 7 are run, if not
  3888. // they are skipped, and it is done.
  3889. // 6. The resource compiler is invoked one more time.
  3890. // 7. Finally, the Linker does another incremental link, but since the
  3891. // only thing that has changed is the *.res file that contains the
  3892. // manifest it is a short link.
  3893. std::vector<cmStdString> linkCommand;
  3894. std::string targetName;
  3895. if(cmake::ParseVisualStudioLinkCommand(args, linkCommand, targetName) == -1)
  3896. {
  3897. return -1;
  3898. }
  3899. std::string manifestArg = "/MANIFESTFILE:";
  3900. std::vector<cmStdString> rcCommand;
  3901. rcCommand.push_back(cmSystemTools::FindProgram("rc.exe"));
  3902. std::vector<cmStdString> mtCommand;
  3903. mtCommand.push_back(cmSystemTools::FindProgram("mt.exe"));
  3904. std::string tempManifest;
  3905. tempManifest = targetName;
  3906. tempManifest += ".intermediate.manifest";
  3907. std::string resourceInputFile = targetName;
  3908. resourceInputFile += ".resource.txt";
  3909. if(verbose)
  3910. {
  3911. std::cout << "Create " << resourceInputFile.c_str() << "\n";
  3912. }
  3913. // Create input file for rc command
  3914. std::ofstream fout(resourceInputFile.c_str());
  3915. if(!fout)
  3916. {
  3917. return -1;
  3918. }
  3919. std::string manifestFile = targetName;
  3920. manifestFile += ".embed.manifest";
  3921. std::string fullPath= cmSystemTools::CollapseFullPath(manifestFile.c_str());
  3922. fout << type << " /* CREATEPROCESS_MANIFEST_RESOURCE_ID "
  3923. "*/ 24 /* RT_MANIFEST */ " << "\"" << fullPath.c_str() << "\"";
  3924. fout.close();
  3925. manifestArg += tempManifest;
  3926. // add the manifest arg to the linkCommand
  3927. linkCommand.push_back("/MANIFEST");
  3928. linkCommand.push_back(manifestArg);
  3929. // if manifestFile is not yet created, create an
  3930. // empty one
  3931. if(!cmSystemTools::FileExists(manifestFile.c_str()))
  3932. {
  3933. if(verbose)
  3934. {
  3935. std::cout << "Create empty: " << manifestFile.c_str() << "\n";
  3936. }
  3937. std::ofstream foutTmp(manifestFile.c_str());
  3938. }
  3939. std::string resourceFile = manifestFile;
  3940. resourceFile += ".res";
  3941. // add the resource file to the end of the link command
  3942. linkCommand.push_back(resourceFile);
  3943. std::string outputOpt = "/fo";
  3944. outputOpt += resourceFile;
  3945. rcCommand.push_back(outputOpt);
  3946. rcCommand.push_back(resourceInputFile);
  3947. // Run rc command to create resource
  3948. if(!cmake::RunCommand("RC Pass 1", rcCommand, verbose))
  3949. {
  3950. return -1;
  3951. }
  3952. // Now run the link command to link and create manifest
  3953. if(!cmake::RunCommand("LINK Pass 1", linkCommand, verbose))
  3954. {
  3955. return -1;
  3956. }
  3957. // create mt command
  3958. std::string outArg("/out:");
  3959. outArg+= manifestFile;
  3960. mtCommand.push_back("/nologo");
  3961. mtCommand.push_back(outArg);
  3962. mtCommand.push_back("/notify_update");
  3963. mtCommand.push_back("/manifest");
  3964. mtCommand.push_back(tempManifest);
  3965. // now run mt.exe to create the final manifest file
  3966. int mtRet =0;
  3967. cmake::RunCommand("MT", mtCommand, verbose, &mtRet);
  3968. // if mt returns 0, then the manifest was not changed and
  3969. // we do not need to do another link step
  3970. if(mtRet == 0)
  3971. {
  3972. return 0;
  3973. }
  3974. // check for magic mt return value if mt returns the magic number
  3975. // 1090650113 then it means that it updated the manifest file and we need
  3976. // to do the final link. If mt has any value other than 0 or 1090650113
  3977. // then there was some problem with the command itself and there was an
  3978. // error so return the error code back out of cmake so make can report it.
  3979. if(mtRet != 1090650113)
  3980. {
  3981. return mtRet;
  3982. }
  3983. // update the resource file with the new manifest from the mt command.
  3984. if(!cmake::RunCommand("RC Pass 2", rcCommand, verbose))
  3985. {
  3986. return -1;
  3987. }
  3988. // Run the final incremental link that will put the new manifest resource
  3989. // into the file incrementally.
  3990. if(!cmake::RunCommand("FINAL LINK", linkCommand, verbose))
  3991. {
  3992. return -1;
  3993. }
  3994. return 0;
  3995. }
  3996. int cmake::VisualStudioLinkNonIncremental(std::vector<std::string>& args,
  3997. int type,
  3998. bool hasManifest,
  3999. bool verbose)
  4000. {
  4001. std::vector<cmStdString> linkCommand;
  4002. std::string targetName;
  4003. if(cmake::ParseVisualStudioLinkCommand(args, linkCommand, targetName) == -1)
  4004. {
  4005. return -1;
  4006. }
  4007. // Run the link command as given
  4008. if (hasManifest)
  4009. {
  4010. linkCommand.push_back("/MANIFEST");
  4011. }
  4012. if(!cmake::RunCommand("LINK", linkCommand, verbose))
  4013. {
  4014. return -1;
  4015. }
  4016. if(!hasManifest)
  4017. {
  4018. return 0;
  4019. }
  4020. std::vector<cmStdString> mtCommand;
  4021. mtCommand.push_back(cmSystemTools::FindProgram("mt.exe"));
  4022. mtCommand.push_back("/nologo");
  4023. mtCommand.push_back("/manifest");
  4024. std::string manifestFile = targetName;
  4025. manifestFile += ".manifest";
  4026. mtCommand.push_back(manifestFile);
  4027. std::string outresource = "/outputresource:";
  4028. outresource += targetName;
  4029. outresource += ";#";
  4030. if(type == 1)
  4031. {
  4032. outresource += "1";
  4033. }
  4034. else if(type == 2)
  4035. {
  4036. outresource += "2";
  4037. }
  4038. mtCommand.push_back(outresource);
  4039. // Now use the mt tool to embed the manifest into the exe or dll
  4040. if(!cmake::RunCommand("MT", mtCommand, verbose))
  4041. {
  4042. return -1;
  4043. }
  4044. return 0;
  4045. }
  4046. //----------------------------------------------------------------------------
  4047. void cmake::IssueMessage(cmake::MessageType t, std::string const& text,
  4048. cmListFileBacktrace const& backtrace)
  4049. {
  4050. cmOStringStream msg;
  4051. bool isError = false;
  4052. // Construct the message header.
  4053. if(t == cmake::FATAL_ERROR)
  4054. {
  4055. isError = true;
  4056. msg << "CMake Error";
  4057. }
  4058. else if(t == cmake::INTERNAL_ERROR)
  4059. {
  4060. isError = true;
  4061. msg << "CMake Internal Error (please report a bug)";
  4062. }
  4063. else
  4064. {
  4065. msg << "CMake Warning";
  4066. if(t == cmake::AUTHOR_WARNING)
  4067. {
  4068. // Allow suppression of these warnings.
  4069. cmCacheManager::CacheIterator it = this->CacheManager
  4070. ->GetCacheIterator("CMAKE_SUPPRESS_DEVELOPER_WARNINGS");
  4071. if(!it.IsAtEnd() && it.GetValueAsBool())
  4072. {
  4073. return;
  4074. }
  4075. msg << " (dev)";
  4076. }
  4077. }
  4078. // Add the immediate context.
  4079. cmListFileBacktrace::const_iterator i = backtrace.begin();
  4080. if(i != backtrace.end())
  4081. {
  4082. cmListFileContext const& lfc = *i;
  4083. msg << (lfc.Line? " at ": " in ") << lfc;
  4084. ++i;
  4085. }
  4086. // Add the message text.
  4087. {
  4088. msg << ":\n";
  4089. cmDocumentationFormatterText formatter;
  4090. formatter.SetIndent(" ");
  4091. formatter.PrintFormatted(msg, text.c_str());
  4092. }
  4093. // Add the rest of the context.
  4094. if(i != backtrace.end())
  4095. {
  4096. msg << "Call Stack (most recent call first):\n";
  4097. while(i != backtrace.end())
  4098. {
  4099. cmListFileContext const& lfc = *i;
  4100. msg << " " << lfc << "\n";
  4101. ++i;
  4102. }
  4103. }
  4104. // Add a note about warning suppression.
  4105. if(t == cmake::AUTHOR_WARNING)
  4106. {
  4107. msg <<
  4108. "This warning is for project developers. Use -Wno-dev to suppress it.";
  4109. }
  4110. // Add a terminating blank line.
  4111. msg << "\n";
  4112. // Output the message.
  4113. if(isError)
  4114. {
  4115. cmSystemTools::SetErrorOccured();
  4116. cmSystemTools::Message(msg.str().c_str(), "Error");
  4117. }
  4118. else
  4119. {
  4120. cmSystemTools::Message(msg.str().c_str(), "Warning");
  4121. }
  4122. }
  4123. //----------------------------------------------------------------------------
  4124. std::vector<std::string> const& cmake::GetDebugConfigs()
  4125. {
  4126. // Compute on-demand.
  4127. if(this->DebugConfigs.empty())
  4128. {
  4129. if(const char* config_list = this->GetProperty("DEBUG_CONFIGURATIONS"))
  4130. {
  4131. // Expand the specified list and convert to upper-case.
  4132. cmSystemTools::ExpandListArgument(config_list, this->DebugConfigs);
  4133. for(std::vector<std::string>::iterator i = this->DebugConfigs.begin();
  4134. i != this->DebugConfigs.end(); ++i)
  4135. {
  4136. *i = cmSystemTools::UpperCase(*i);
  4137. }
  4138. }
  4139. // If no configurations were specified, use a default list.
  4140. if(this->DebugConfigs.empty())
  4141. {
  4142. this->DebugConfigs.push_back("DEBUG");
  4143. }
  4144. }
  4145. return this->DebugConfigs;
  4146. }
  4147. int cmake::Build(const std::string& dir,
  4148. const std::string& target,
  4149. const std::string& config,
  4150. const std::vector<std::string>& nativeOptions,
  4151. bool clean,
  4152. cmSystemTools::OutputOption outputflag)
  4153. {
  4154. if(!cmSystemTools::FileIsDirectory(dir.c_str()))
  4155. {
  4156. std::cerr << "Error: " << dir << " is not a directory\n";
  4157. return 1;
  4158. }
  4159. std::string cachePath = dir;
  4160. cmSystemTools::ConvertToUnixSlashes(cachePath);
  4161. cmCacheManager* cachem = this->GetCacheManager();
  4162. cmCacheManager::CacheIterator it = cachem->NewIterator();
  4163. if(!cachem->LoadCache(cachePath.c_str()))
  4164. {
  4165. std::cerr << "Error: could not load cache\n";
  4166. return 1;
  4167. }
  4168. if(!it.Find("CMAKE_GENERATOR"))
  4169. {
  4170. std::cerr << "Error: could find generator in Cache\n";
  4171. return 1;
  4172. }
  4173. std::auto_ptr<cmGlobalGenerator> gen(
  4174. this->CreateGlobalGenerator(it.GetValue()));
  4175. std::string output;
  4176. std::string projName;
  4177. std::string makeProgram;
  4178. if(!it.Find("CMAKE_PROJECT_NAME"))
  4179. {
  4180. std::cerr << "Error: could not find CMAKE_PROJECT_NAME in Cache\n";
  4181. return 1;
  4182. }
  4183. projName = it.GetValue();
  4184. if(!it.Find("CMAKE_MAKE_PROGRAM"))
  4185. {
  4186. std::cerr << "Error: could not find CMAKE_MAKE_PROGRAM in Cache\n";
  4187. return 1;
  4188. }
  4189. makeProgram = it.GetValue();
  4190. return gen->Build(0, dir.c_str(),
  4191. projName.c_str(), target.c_str(),
  4192. &output,
  4193. makeProgram.c_str(),
  4194. config.c_str(), clean, false, 0, outputflag,
  4195. 0, nativeOptions);
  4196. }
  4197. void cmake::WatchUnusedCli(const char* var)
  4198. {
  4199. #ifdef CMAKE_BUILD_WITH_CMAKE
  4200. this->VariableWatch->AddWatch(var, cmWarnUnusedCliWarning, this);
  4201. if(this->UsedCliVariables.find(var) == this->UsedCliVariables.end())
  4202. {
  4203. this->UsedCliVariables[var] = false;
  4204. }
  4205. #endif
  4206. }
  4207. void cmake::UnwatchUnusedCli(const char* var)
  4208. {
  4209. #ifdef CMAKE_BUILD_WITH_CMAKE
  4210. this->VariableWatch->RemoveWatch(var, cmWarnUnusedCliWarning);
  4211. this->UsedCliVariables.erase(var);
  4212. #endif
  4213. }
  4214. void cmake::RunCheckForUnusedVariables()
  4215. {
  4216. #ifdef CMAKE_BUILD_WITH_CMAKE
  4217. bool haveUnused = false;
  4218. cmOStringStream msg;
  4219. msg << "Manually-specified variables were not used by the project:";
  4220. for(std::map<cmStdString, bool>::const_iterator
  4221. it = this->UsedCliVariables.begin();
  4222. it != this->UsedCliVariables.end(); ++it)
  4223. {
  4224. if(!it->second)
  4225. {
  4226. haveUnused = true;
  4227. msg << "\n " << it->first;
  4228. }
  4229. }
  4230. if(haveUnused)
  4231. {
  4232. this->IssueMessage(cmake::WARNING, msg.str(), cmListFileBacktrace());
  4233. }
  4234. #endif
  4235. }