cmake.cxx 136 KB

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