cmake.cxx 136 KB

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