cmake.cxx 134 KB

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