cmake.cxx 132 KB

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