cmake.cxx 136 KB

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