cmake.cxx 131 KB

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