cmake.cxx 136 KB

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