cmake.cxx 135 KB

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