cmake.cxx 130 KB

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