cmake.cxx 132 KB

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