cmake.cxx 135 KB

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