cmake.cxx 131 KB

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