cmake.cxx 135 KB

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