cmake.cxx 134 KB

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