cmake.cxx 134 KB

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