cmake.cxx 134 KB

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