cmake.cxx 130 KB

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