cmake.cxx 107 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmake.h"
  14. #include "cmDocumentVariables.h"
  15. #include "time.h"
  16. #include "cmCacheManager.h"
  17. #include "cmMakefile.h"
  18. #include "cmLocalGenerator.h"
  19. #include "cmExternalMakefileProjectGenerator.h"
  20. #include "cmCommands.h"
  21. #include "cmCommand.h"
  22. #include "cmFileTimeComparison.h"
  23. #include "cmGeneratedFileStream.h"
  24. #include "cmSourceFile.h"
  25. #include "cmVersion.h"
  26. #include "cmTest.h"
  27. #if defined(CMAKE_BUILD_WITH_CMAKE)
  28. # include "cmDependsFortran.h" // For -E cmake_copy_f90_mod callback.
  29. # include "cmVariableWatch.h"
  30. # include <cmsys/Terminal.h>
  31. #endif
  32. #include <cmsys/Directory.hxx>
  33. #include <cmsys/Process.h>
  34. #include <cmsys/Glob.hxx>
  35. #include <cmsys/RegularExpression.hxx>
  36. // only build kdevelop generator on non-windows platforms
  37. // when not bootstrapping cmake
  38. #if !defined(_WIN32)
  39. # if defined(CMAKE_BUILD_WITH_CMAKE)
  40. # define CMAKE_USE_KDEVELOP
  41. # endif
  42. #endif
  43. #if defined(CMAKE_BUILD_WITH_CMAKE)
  44. # define CMAKE_USE_ECLIPSE
  45. #endif
  46. #if defined(__MINGW32__) && !defined(CMAKE_BUILD_WITH_CMAKE)
  47. # define CMAKE_BOOT_MINGW
  48. #endif
  49. // include the generator
  50. #if defined(_WIN32) && !defined(__CYGWIN__)
  51. # if !defined(CMAKE_BOOT_MINGW)
  52. # include "cmGlobalVisualStudio6Generator.h"
  53. # include "cmGlobalVisualStudio7Generator.h"
  54. # include "cmGlobalVisualStudio71Generator.h"
  55. # include "cmGlobalVisualStudio8Generator.h"
  56. # include "cmGlobalVisualStudio9Generator.h"
  57. # include "cmGlobalVisualStudio8Win64Generator.h"
  58. # include "cmGlobalBorlandMakefileGenerator.h"
  59. # include "cmGlobalNMakeMakefileGenerator.h"
  60. # include "cmGlobalWatcomWMakeGenerator.h"
  61. # define CMAKE_HAVE_VS_GENERATORS
  62. # endif
  63. # include "cmGlobalMSYSMakefileGenerator.h"
  64. # include "cmGlobalMinGWMakefileGenerator.h"
  65. # include "cmWin32ProcessExecution.h"
  66. #else
  67. #endif
  68. #include "cmGlobalUnixMakefileGenerator3.h"
  69. #if defined(_WIN32)
  70. #include "cmCallVisualStudioMacro.h"
  71. #endif
  72. #if !defined(__CYGWIN__) && !defined(CMAKE_BOOT_MINGW)
  73. # include "cmExtraCodeBlocksGenerator.h"
  74. #endif
  75. #ifdef CMAKE_USE_KDEVELOP
  76. # include "cmGlobalKdevelopGenerator.h"
  77. #endif
  78. #ifdef CMAKE_USE_ECLIPSE
  79. # include "cmExtraEclipseCDT4Generator.h"
  80. #endif
  81. #include <stdlib.h> // required for atoi
  82. #if defined( __APPLE__ )
  83. # if defined(CMAKE_BUILD_WITH_CMAKE)
  84. # include "cmGlobalXCodeGenerator.h"
  85. # define CMAKE_USE_XCODE 1
  86. # endif
  87. # include <sys/types.h>
  88. # include <sys/time.h>
  89. # include <sys/resource.h>
  90. #endif
  91. #include <sys/stat.h> // struct stat
  92. #include <memory> // auto_ptr
  93. static bool cmakeCheckStampFile(const char* stampName);
  94. void cmNeedBackwardsCompatibility(const std::string& variable,
  95. int access_type, void*, const char*, const cmMakefile*)
  96. {
  97. #ifdef CMAKE_BUILD_WITH_CMAKE
  98. if (access_type == cmVariableWatch::UNKNOWN_VARIABLE_READ_ACCESS)
  99. {
  100. std::string message = "An attempt was made to access a variable: ";
  101. message += variable;
  102. message +=
  103. " that has not been defined. Some variables were always defined "
  104. "by CMake in versions prior to 1.6. To fix this you might need to set "
  105. "the cache value of CMAKE_BACKWARDS_COMPATIBILITY to 1.4 or less. If "
  106. "you are writing a CMakeList file, (or have already set "
  107. "CMAKE_BACKWARDS_COMPATABILITY to 1.4 or less) then you probably need "
  108. "to include a CMake module to test for the feature this variable "
  109. "defines.";
  110. cmSystemTools::Error(message.c_str());
  111. }
  112. #else
  113. (void)variable;
  114. (void)access_type;
  115. #endif
  116. }
  117. cmake::cmake()
  118. {
  119. this->DebugOutput = false;
  120. this->DebugTryCompile = false;
  121. this->ClearBuildSystem = false;
  122. this->FileComparison = new cmFileTimeComparison;
  123. this->Properties.SetCMakeInstance(this);
  124. // initialize properties
  125. cmSourceFile::DefineProperties(this);
  126. cmTarget::DefineProperties(this);
  127. cmMakefile::DefineProperties(this);
  128. cmTest::DefineProperties(this);
  129. cmake::DefineProperties(this);
  130. #ifdef __APPLE__
  131. struct rlimit rlp;
  132. if(!getrlimit(RLIMIT_STACK, &rlp))
  133. {
  134. if(rlp.rlim_cur != rlp.rlim_max)
  135. {
  136. rlp.rlim_cur = rlp.rlim_max;
  137. setrlimit(RLIMIT_STACK, &rlp);
  138. }
  139. }
  140. #endif
  141. // If MAKEFLAGS are given in the environment, remove the environment
  142. // variable. This will prevent try-compile from succeeding when it
  143. // should fail (if "-i" is an option). We cannot simply test
  144. // whether "-i" is given and remove it because some make programs
  145. // encode the MAKEFLAGS variable in a strange way.
  146. if(getenv("MAKEFLAGS"))
  147. {
  148. cmSystemTools::PutEnv("MAKEFLAGS=");
  149. }
  150. this->Verbose = false;
  151. this->InTryCompile = false;
  152. this->CacheManager = new cmCacheManager;
  153. this->GlobalGenerator = 0;
  154. this->ProgressCallback = 0;
  155. this->ProgressCallbackClientData = 0;
  156. this->ScriptMode = false;
  157. #ifdef CMAKE_BUILD_WITH_CMAKE
  158. this->VariableWatch = new cmVariableWatch;
  159. this->VariableWatch->AddWatch("CMAKE_WORDS_BIGENDIAN",
  160. cmNeedBackwardsCompatibility);
  161. this->VariableWatch->AddWatch("CMAKE_SIZEOF_INT",
  162. cmNeedBackwardsCompatibility);
  163. this->VariableWatch->AddWatch("CMAKE_X_LIBS",
  164. cmNeedBackwardsCompatibility);
  165. #endif
  166. this->AddDefaultGenerators();
  167. this->AddDefaultExtraGenerators();
  168. this->AddDefaultCommands();
  169. // Make sure we can capture the build tool output.
  170. cmSystemTools::EnableVSConsoleOutput();
  171. }
  172. cmake::~cmake()
  173. {
  174. delete this->CacheManager;
  175. if (this->GlobalGenerator)
  176. {
  177. delete this->GlobalGenerator;
  178. this->GlobalGenerator = 0;
  179. }
  180. for(RegisteredCommandsMap::iterator j = this->Commands.begin();
  181. j != this->Commands.end(); ++j)
  182. {
  183. delete (*j).second;
  184. }
  185. #ifdef CMAKE_BUILD_WITH_CMAKE
  186. delete this->VariableWatch;
  187. #endif
  188. delete this->FileComparison;
  189. }
  190. void cmake::CleanupCommandsAndMacros()
  191. {
  192. std::vector<cmCommand*> commands;
  193. for(RegisteredCommandsMap::iterator j = this->Commands.begin();
  194. j != this->Commands.end(); ++j)
  195. {
  196. if ( !j->second->IsA("cmMacroHelpperCommand") &&
  197. !j->second->IsA("cmFunctionHelperCommand"))
  198. {
  199. commands.push_back(j->second);
  200. }
  201. else
  202. {
  203. delete j->second;
  204. }
  205. }
  206. this->Commands.erase(this->Commands.begin(), this->Commands.end());
  207. std::vector<cmCommand*>::iterator it;
  208. for ( it = commands.begin(); it != commands.end();
  209. ++ it )
  210. {
  211. this->Commands[cmSystemTools::LowerCase((*it)->GetName())] = *it;
  212. }
  213. }
  214. bool cmake::CommandExists(const char* name) const
  215. {
  216. std::string sName = cmSystemTools::LowerCase(name);
  217. return (this->Commands.find(sName) != this->Commands.end());
  218. }
  219. cmCommand *cmake::GetCommand(const char *name)
  220. {
  221. cmCommand* rm = 0;
  222. std::string sName = cmSystemTools::LowerCase(name);
  223. RegisteredCommandsMap::iterator pos = this->Commands.find(sName);
  224. if (pos != this->Commands.end())
  225. {
  226. rm = (*pos).second;
  227. }
  228. return rm;
  229. }
  230. void cmake::RenameCommand(const char*oldName, const char* newName)
  231. {
  232. // if the command already exists, free the old one
  233. std::string sOldName = cmSystemTools::LowerCase(oldName);
  234. std::string sNewName = cmSystemTools::LowerCase(newName);
  235. RegisteredCommandsMap::iterator pos = this->Commands.find(sOldName);
  236. if ( pos == this->Commands.end() )
  237. {
  238. return;
  239. }
  240. cmCommand* cmd = pos->second;
  241. pos = this->Commands.find(sNewName);
  242. if (pos != this->Commands.end())
  243. {
  244. delete pos->second;
  245. this->Commands.erase(pos);
  246. }
  247. this->Commands.insert(RegisteredCommandsMap::value_type(sNewName, cmd));
  248. pos = this->Commands.find(sOldName);
  249. this->Commands.erase(pos);
  250. }
  251. void cmake::RemoveCommand(const char* name)
  252. {
  253. std::string sName = cmSystemTools::LowerCase(name);
  254. RegisteredCommandsMap::iterator pos = this->Commands.find(sName);
  255. if ( pos != this->Commands.end() )
  256. {
  257. delete pos->second;
  258. this->Commands.erase(pos);
  259. }
  260. }
  261. void cmake::AddCommand(cmCommand* wg)
  262. {
  263. std::string name = cmSystemTools::LowerCase(wg->GetName());
  264. // if the command already exists, free the old one
  265. RegisteredCommandsMap::iterator pos = this->Commands.find(name);
  266. if (pos != this->Commands.end())
  267. {
  268. delete pos->second;
  269. this->Commands.erase(pos);
  270. }
  271. this->Commands.insert( RegisteredCommandsMap::value_type(name, wg));
  272. }
  273. void cmake::RemoveUnscriptableCommands()
  274. {
  275. std::vector<std::string> unscriptableCommands;
  276. cmake::RegisteredCommandsMap* commands = this->GetCommands();
  277. for (cmake::RegisteredCommandsMap::const_iterator pos = commands->begin();
  278. pos != commands->end();
  279. ++pos)
  280. {
  281. if (!pos->second->IsScriptable())
  282. {
  283. unscriptableCommands.push_back(pos->first);
  284. }
  285. }
  286. for(std::vector<std::string>::const_iterator it=unscriptableCommands.begin();
  287. it != unscriptableCommands.end();
  288. ++it)
  289. {
  290. this->RemoveCommand(it->c_str());
  291. }
  292. }
  293. // Parse the args
  294. bool cmake::SetCacheArgs(const std::vector<std::string>& args)
  295. {
  296. for(unsigned int i=1; i < args.size(); ++i)
  297. {
  298. std::string arg = args[i];
  299. if(arg.find("-D",0) == 0)
  300. {
  301. std::string entry = arg.substr(2);
  302. if(entry.size() == 0)
  303. {
  304. ++i;
  305. if(i < args.size())
  306. {
  307. entry = args[i];
  308. }
  309. else
  310. {
  311. cmSystemTools::Error("-D must be followed with VAR=VALUE.");
  312. return false;
  313. }
  314. }
  315. std::string var, value;
  316. cmCacheManager::CacheEntryType type = cmCacheManager::UNINITIALIZED;
  317. if(cmCacheManager::ParseEntry(entry.c_str(), var, value, type) ||
  318. cmCacheManager::ParseEntry(entry.c_str(), var, value))
  319. {
  320. this->CacheManager->AddCacheEntry(var.c_str(), value.c_str(),
  321. "No help, variable specified on the command line.", type);
  322. }
  323. else
  324. {
  325. std::cerr << "Parse error in command line argument: " << arg << "\n"
  326. << "Should be: VAR:type=value\n";
  327. cmSystemTools::Error("No cmake scrpt provided.");
  328. return false;
  329. }
  330. }
  331. else if(arg.find("-U",0) == 0)
  332. {
  333. std::string entryPattern = arg.substr(2);
  334. if(entryPattern.size() == 0)
  335. {
  336. ++i;
  337. if(i < args.size())
  338. {
  339. entryPattern = args[i];
  340. }
  341. else
  342. {
  343. cmSystemTools::Error("-U must be followed with VAR.");
  344. return false;
  345. }
  346. }
  347. cmsys::RegularExpression regex(
  348. cmsys::Glob::PatternToRegex(entryPattern.c_str(), true).c_str());
  349. //go through all cache entries and collect the vars which will be removed
  350. std::vector<std::string> entriesToDelete;
  351. cmCacheManager::CacheIterator it =
  352. this->CacheManager->GetCacheIterator();
  353. for ( it.Begin(); !it.IsAtEnd(); it.Next() )
  354. {
  355. cmCacheManager::CacheEntryType t = it.GetType();
  356. if(t != cmCacheManager::STATIC)
  357. {
  358. std::string entryName = it.GetName();
  359. if (regex.find(entryName.c_str()))
  360. {
  361. entriesToDelete.push_back(entryName);
  362. }
  363. }
  364. }
  365. // now remove them from the cache
  366. for(std::vector<std::string>::const_iterator currentEntry =
  367. entriesToDelete.begin();
  368. currentEntry != entriesToDelete.end();
  369. ++currentEntry)
  370. {
  371. this->CacheManager->RemoveCacheEntry(currentEntry->c_str());
  372. }
  373. }
  374. else if(arg.find("-C",0) == 0)
  375. {
  376. std::string path = arg.substr(2);
  377. if ( path.size() == 0 )
  378. {
  379. ++i;
  380. if(i < args.size())
  381. {
  382. path = args[i];
  383. }
  384. else
  385. {
  386. cmSystemTools::Error("-C must be followed by a file name.");
  387. return false;
  388. }
  389. }
  390. std::cerr << "loading initial cache file " << path.c_str() << "\n";
  391. this->ReadListFile(path.c_str());
  392. }
  393. else if(arg.find("-P",0) == 0)
  394. {
  395. i++;
  396. if(i >= args.size())
  397. {
  398. cmSystemTools::Error("-P must be followed by a file name.");
  399. return false;
  400. }
  401. std::string path = args[i];
  402. if ( path.size() == 0 )
  403. {
  404. cmSystemTools::Error("No cmake script provided.");
  405. return false;
  406. }
  407. this->ReadListFile(path.c_str());
  408. }
  409. }
  410. return true;
  411. }
  412. void cmake::ReadListFile(const char *path)
  413. {
  414. // if a generator was not yet created, temporarily create one
  415. cmGlobalGenerator *gg = this->GetGlobalGenerator();
  416. bool created = false;
  417. // if a generator was not specified use a generic one
  418. if (!gg)
  419. {
  420. gg = new cmGlobalGenerator;
  421. gg->SetCMakeInstance(this);
  422. created = true;
  423. }
  424. // read in the list file to fill the cache
  425. if(path)
  426. {
  427. std::auto_ptr<cmLocalGenerator> lg(gg->CreateLocalGenerator());
  428. lg->SetGlobalGenerator(gg);
  429. lg->GetMakefile()->SetHomeOutputDirectory
  430. (cmSystemTools::GetCurrentWorkingDirectory().c_str());
  431. lg->GetMakefile()->SetStartOutputDirectory
  432. (cmSystemTools::GetCurrentWorkingDirectory().c_str());
  433. lg->GetMakefile()->SetHomeDirectory
  434. (cmSystemTools::GetCurrentWorkingDirectory().c_str());
  435. lg->GetMakefile()->SetStartDirectory
  436. (cmSystemTools::GetCurrentWorkingDirectory().c_str());
  437. if (!lg->GetMakefile()->ReadListFile(0, path))
  438. {
  439. cmSystemTools::Error("Error processing file:", path);
  440. }
  441. }
  442. // free generic one if generated
  443. if (created)
  444. {
  445. delete gg;
  446. }
  447. }
  448. // Parse the args
  449. void cmake::SetArgs(const std::vector<std::string>& args)
  450. {
  451. bool directoriesSet = false;
  452. for(unsigned int i=1; i < args.size(); ++i)
  453. {
  454. std::string arg = args[i];
  455. if(arg.find("-H",0) == 0)
  456. {
  457. directoriesSet = true;
  458. std::string path = arg.substr(2);
  459. path = cmSystemTools::CollapseFullPath(path.c_str());
  460. cmSystemTools::ConvertToUnixSlashes(path);
  461. this->SetHomeDirectory(path.c_str());
  462. }
  463. else if(arg.find("-S",0) == 0)
  464. {
  465. // There is no local generate anymore. Ignore -S option.
  466. }
  467. else if(arg.find("-O",0) == 0)
  468. {
  469. // There is no local generate anymore. Ignore -O option.
  470. }
  471. else if(arg.find("-B",0) == 0)
  472. {
  473. directoriesSet = true;
  474. std::string path = arg.substr(2);
  475. path = cmSystemTools::CollapseFullPath(path.c_str());
  476. cmSystemTools::ConvertToUnixSlashes(path);
  477. this->SetHomeOutputDirectory(path.c_str());
  478. }
  479. else if((i < args.size()-1) && (arg.find("--check-build-system",0) == 0))
  480. {
  481. this->CheckBuildSystemArgument = args[++i];
  482. this->ClearBuildSystem = (atoi(args[++i].c_str()) > 0);
  483. }
  484. else if((i < args.size()-1) && (arg.find("--check-stamp-file",0) == 0))
  485. {
  486. this->CheckStampFile = args[++i];
  487. }
  488. #if defined(CMAKE_HAVE_VS_GENERATORS)
  489. else if((i < args.size()-1) && (arg.find("--vs-solution-file",0) == 0))
  490. {
  491. this->VSSolutionFile = args[++i];
  492. }
  493. #endif
  494. else if(arg.find("-V",0) == 0)
  495. {
  496. this->Verbose = true;
  497. }
  498. else if(arg.find("-D",0) == 0)
  499. {
  500. // skip for now
  501. }
  502. else if(arg.find("-U",0) == 0)
  503. {
  504. // skip for now
  505. }
  506. else if(arg.find("-C",0) == 0)
  507. {
  508. // skip for now
  509. }
  510. else if(arg.find("-P",0) == 0)
  511. {
  512. // skip for now
  513. i++;
  514. }
  515. else if(arg.find("--graphviz=",0) == 0)
  516. {
  517. std::string path = arg.substr(strlen("--graphviz="));
  518. path = cmSystemTools::CollapseFullPath(path.c_str());
  519. cmSystemTools::ConvertToUnixSlashes(path);
  520. this->GraphVizFile = path;
  521. if ( this->GraphVizFile.empty() )
  522. {
  523. cmSystemTools::Error("No file specified for --graphviz");
  524. }
  525. }
  526. else if(arg.find("--debug-trycompile",0) == 0)
  527. {
  528. std::cout << "debug trycompile on\n";
  529. this->DebugTryCompileOn();
  530. }
  531. else if(arg.find("--debug-output",0) == 0)
  532. {
  533. std::cout << "Running with debug output on.\n";
  534. this->DebugOutputOn();
  535. }
  536. else if(arg.find("-G",0) == 0)
  537. {
  538. std::string value = arg.substr(2);
  539. if(value.size() == 0)
  540. {
  541. ++i;
  542. if(i >= args.size())
  543. {
  544. cmSystemTools::Error("No generator specified for -G");
  545. return;
  546. }
  547. value = args[i];
  548. }
  549. cmGlobalGenerator* gen =
  550. this->CreateGlobalGenerator(value.c_str());
  551. if(!gen)
  552. {
  553. cmSystemTools::Error("Could not create named generator ",
  554. value.c_str());
  555. }
  556. else
  557. {
  558. this->SetGlobalGenerator(gen);
  559. }
  560. }
  561. // no option assume it is the path to the source
  562. else
  563. {
  564. directoriesSet = true;
  565. this->SetDirectoriesFromFile(arg.c_str());
  566. }
  567. }
  568. if(!directoriesSet)
  569. {
  570. this->SetHomeOutputDirectory
  571. (cmSystemTools::GetCurrentWorkingDirectory().c_str());
  572. this->SetStartOutputDirectory
  573. (cmSystemTools::GetCurrentWorkingDirectory().c_str());
  574. this->SetHomeDirectory
  575. (cmSystemTools::GetCurrentWorkingDirectory().c_str());
  576. this->SetStartDirectory
  577. (cmSystemTools::GetCurrentWorkingDirectory().c_str());
  578. }
  579. this->SetStartDirectory(this->GetHomeDirectory());
  580. this->SetStartOutputDirectory(this->GetHomeOutputDirectory());
  581. }
  582. //----------------------------------------------------------------------------
  583. void cmake::SetDirectoriesFromFile(const char* arg)
  584. {
  585. // Check if the argument refers to a CMakeCache.txt or
  586. // CMakeLists.txt file.
  587. std::string listPath;
  588. std::string cachePath;
  589. bool argIsFile = false;
  590. if(cmSystemTools::FileIsDirectory(arg))
  591. {
  592. std::string path = cmSystemTools::CollapseFullPath(arg);
  593. cmSystemTools::ConvertToUnixSlashes(path);
  594. std::string cacheFile = path;
  595. cacheFile += "/CMakeCache.txt";
  596. std::string listFile = path;
  597. listFile += "/CMakeLists.txt";
  598. if(cmSystemTools::FileExists(cacheFile.c_str()))
  599. {
  600. cachePath = path;
  601. }
  602. if(cmSystemTools::FileExists(listFile.c_str()))
  603. {
  604. listPath = path;
  605. }
  606. }
  607. else if(cmSystemTools::FileExists(arg))
  608. {
  609. argIsFile = true;
  610. std::string fullPath = cmSystemTools::CollapseFullPath(arg);
  611. std::string name = cmSystemTools::GetFilenameName(fullPath.c_str());
  612. name = cmSystemTools::LowerCase(name);
  613. if(name == "cmakecache.txt")
  614. {
  615. cachePath = cmSystemTools::GetFilenamePath(fullPath.c_str());
  616. }
  617. else if(name == "cmakelists.txt")
  618. {
  619. listPath = cmSystemTools::GetFilenamePath(fullPath.c_str());
  620. }
  621. }
  622. else
  623. {
  624. // Specified file or directory does not exist. Try to set things
  625. // up to produce a meaningful error message.
  626. std::string fullPath = cmSystemTools::CollapseFullPath(arg);
  627. std::string name = cmSystemTools::GetFilenameName(fullPath.c_str());
  628. name = cmSystemTools::LowerCase(name);
  629. if(name == "cmakecache.txt" || name == "cmakelists.txt")
  630. {
  631. argIsFile = true;
  632. listPath = cmSystemTools::GetFilenamePath(fullPath.c_str());
  633. }
  634. else
  635. {
  636. listPath = fullPath;
  637. }
  638. }
  639. // If there is a CMakeCache.txt file, use its settings.
  640. if(cachePath.length() > 0)
  641. {
  642. cmCacheManager* cachem = this->GetCacheManager();
  643. cmCacheManager::CacheIterator it = cachem->NewIterator();
  644. if(cachem->LoadCache(cachePath.c_str()) &&
  645. it.Find("CMAKE_HOME_DIRECTORY"))
  646. {
  647. this->SetHomeOutputDirectory(cachePath.c_str());
  648. this->SetStartOutputDirectory(cachePath.c_str());
  649. this->SetHomeDirectory(it.GetValue());
  650. this->SetStartDirectory(it.GetValue());
  651. return;
  652. }
  653. }
  654. // If there is a CMakeLists.txt file, use it as the source tree.
  655. if(listPath.length() > 0)
  656. {
  657. this->SetHomeDirectory(listPath.c_str());
  658. this->SetStartDirectory(listPath.c_str());
  659. if(argIsFile)
  660. {
  661. // Source CMakeLists.txt file given. It was probably dropped
  662. // onto the executable in a GUI. Default to an in-source build.
  663. this->SetHomeOutputDirectory(listPath.c_str());
  664. this->SetStartOutputDirectory(listPath.c_str());
  665. }
  666. else
  667. {
  668. // Source directory given on command line. Use current working
  669. // directory as build tree.
  670. std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
  671. this->SetHomeOutputDirectory(cwd.c_str());
  672. this->SetStartOutputDirectory(cwd.c_str());
  673. }
  674. return;
  675. }
  676. // We didn't find a CMakeLists.txt or CMakeCache.txt file from the
  677. // argument. Assume it is the path to the source tree, and use the
  678. // current working directory as the build tree.
  679. std::string full = cmSystemTools::CollapseFullPath(arg);
  680. std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
  681. this->SetHomeDirectory(full.c_str());
  682. this->SetStartDirectory(full.c_str());
  683. this->SetHomeOutputDirectory(cwd.c_str());
  684. this->SetStartOutputDirectory(cwd.c_str());
  685. }
  686. // at the end of this CMAKE_ROOT and CMAKE_COMMAND should be added to the
  687. // cache
  688. int cmake::AddCMakePaths(const char *arg0)
  689. {
  690. // Find the cmake executable
  691. std::vector<cmStdString> failures;
  692. std::string cMakeSelf = arg0;
  693. cmSystemTools::ConvertToUnixSlashes(cMakeSelf);
  694. if ((strstr(arg0, "cpack")!=0) || (strstr(arg0, "ctest")!=0))
  695. {
  696. // when called from cpack or ctest CMAKE_COMMAND would otherwise point
  697. // to cpack or ctest and not cmake
  698. cMakeSelf = cmSystemTools::GetFilenamePath(cMakeSelf) +
  699. "/cmake" + cmSystemTools::GetFilenameExtension(cMakeSelf);
  700. }
  701. failures.push_back(cMakeSelf);
  702. cMakeSelf = cmSystemTools::FindProgram(cMakeSelf.c_str());
  703. cmSystemTools::ConvertToUnixSlashes(cMakeSelf);
  704. if(!cmSystemTools::FileExists(cMakeSelf.c_str()))
  705. {
  706. #ifdef CMAKE_BUILD_DIR
  707. std::string intdir = ".";
  708. #ifdef CMAKE_INTDIR
  709. intdir = CMAKE_INTDIR;
  710. #endif
  711. cMakeSelf = CMAKE_BUILD_DIR;
  712. cMakeSelf += "/bin/";
  713. cMakeSelf += intdir;
  714. cMakeSelf += "/cmake";
  715. cMakeSelf += cmSystemTools::GetExecutableExtension();
  716. #endif
  717. }
  718. #ifdef CMAKE_PREFIX
  719. if(!cmSystemTools::FileExists(cMakeSelf.c_str()))
  720. {
  721. failures.push_back(cMakeSelf);
  722. cMakeSelf = CMAKE_PREFIX "/bin/cmake";
  723. }
  724. #endif
  725. if(!cmSystemTools::FileExists(cMakeSelf.c_str()))
  726. {
  727. failures.push_back(cMakeSelf);
  728. cmOStringStream msg;
  729. msg << "CMAKE can not find the command line program cmake.\n";
  730. msg << " argv[0] = \"" << arg0 << "\"\n";
  731. msg << " Attempted paths:\n";
  732. std::vector<cmStdString>::iterator i;
  733. for(i=failures.begin(); i != failures.end(); ++i)
  734. {
  735. msg << " \"" << i->c_str() << "\"\n";
  736. }
  737. cmSystemTools::Error(msg.str().c_str());
  738. return 0;
  739. }
  740. // Save the value in the cache
  741. this->CacheManager->AddCacheEntry
  742. ("CMAKE_COMMAND",cMakeSelf.c_str(), "Path to CMake executable.",
  743. cmCacheManager::INTERNAL);
  744. // Find and save the command to edit the cache
  745. std::string editCacheCommand = cmSystemTools::GetFilenamePath(cMakeSelf) +
  746. "/ccmake" + cmSystemTools::GetFilenameExtension(cMakeSelf);
  747. if( !cmSystemTools::FileExists(editCacheCommand.c_str()))
  748. {
  749. editCacheCommand = cmSystemTools::GetFilenamePath(cMakeSelf) +
  750. "/CMakeSetup" + cmSystemTools::GetFilenameExtension(cMakeSelf);
  751. }
  752. if(cmSystemTools::FileExists(editCacheCommand.c_str()))
  753. {
  754. this->CacheManager->AddCacheEntry
  755. ("CMAKE_EDIT_COMMAND", editCacheCommand.c_str(),
  756. "Path to cache edit program executable.", cmCacheManager::INTERNAL);
  757. }
  758. std::string ctestCommand = cmSystemTools::GetFilenamePath(cMakeSelf) +
  759. "/ctest" + cmSystemTools::GetFilenameExtension(cMakeSelf);
  760. if(cmSystemTools::FileExists(ctestCommand.c_str()))
  761. {
  762. this->CacheManager->AddCacheEntry
  763. ("CMAKE_CTEST_COMMAND", ctestCommand.c_str(),
  764. "Path to ctest program executable.", cmCacheManager::INTERNAL);
  765. }
  766. std::string cpackCommand = cmSystemTools::GetFilenamePath(cMakeSelf) +
  767. "/cpack" + cmSystemTools::GetFilenameExtension(cMakeSelf);
  768. if(cmSystemTools::FileExists(ctestCommand.c_str()))
  769. {
  770. this->CacheManager->AddCacheEntry
  771. ("CMAKE_CPACK_COMMAND", cpackCommand.c_str(),
  772. "Path to cpack program executable.", cmCacheManager::INTERNAL);
  773. }
  774. // do CMAKE_ROOT, look for the environment variable first
  775. std::string cMakeRoot;
  776. std::string modules;
  777. if (getenv("CMAKE_ROOT"))
  778. {
  779. cMakeRoot = getenv("CMAKE_ROOT");
  780. modules = cMakeRoot + "/Modules/CMake.cmake";
  781. }
  782. if(!cmSystemTools::FileExists(modules.c_str()))
  783. {
  784. // next try exe/..
  785. cMakeRoot = cmSystemTools::GetProgramPath(cMakeSelf.c_str());
  786. std::string::size_type slashPos = cMakeRoot.rfind("/");
  787. if(slashPos != std::string::npos)
  788. {
  789. cMakeRoot = cMakeRoot.substr(0, slashPos);
  790. }
  791. // is there no Modules direcory there?
  792. modules = cMakeRoot + "/Modules/CMake.cmake";
  793. }
  794. if (!cmSystemTools::FileExists(modules.c_str()))
  795. {
  796. // try exe/../share/cmake
  797. cMakeRoot += CMAKE_DATA_DIR;
  798. modules = cMakeRoot + "/Modules/CMake.cmake";
  799. }
  800. #ifdef CMAKE_ROOT_DIR
  801. if (!cmSystemTools::FileExists(modules.c_str()))
  802. {
  803. // try compiled in root directory
  804. cMakeRoot = CMAKE_ROOT_DIR;
  805. modules = cMakeRoot + "/Modules/CMake.cmake";
  806. }
  807. #endif
  808. #ifdef CMAKE_PREFIX
  809. if (!cmSystemTools::FileExists(modules.c_str()))
  810. {
  811. // try compiled in install prefix
  812. cMakeRoot = CMAKE_PREFIX CMAKE_DATA_DIR;
  813. modules = cMakeRoot + "/Modules/CMake.cmake";
  814. }
  815. #endif
  816. if (!cmSystemTools::FileExists(modules.c_str()))
  817. {
  818. // try
  819. cMakeRoot = cmSystemTools::GetProgramPath(cMakeSelf.c_str());
  820. cMakeRoot += CMAKE_DATA_DIR;
  821. modules = cMakeRoot + "/Modules/CMake.cmake";
  822. }
  823. if(!cmSystemTools::FileExists(modules.c_str()))
  824. {
  825. // next try exe
  826. cMakeRoot = cmSystemTools::GetProgramPath(cMakeSelf.c_str());
  827. // is there no Modules direcory there?
  828. modules = cMakeRoot + "/Modules/CMake.cmake";
  829. }
  830. if (!cmSystemTools::FileExists(modules.c_str()))
  831. {
  832. // couldn't find modules
  833. cmSystemTools::Error("Could not find CMAKE_ROOT !!!\n"
  834. "CMake has most likely not been installed correctly.\n"
  835. "Modules directory not found in\n",
  836. cMakeRoot.c_str());
  837. return 0;
  838. }
  839. this->CacheManager->AddCacheEntry
  840. ("CMAKE_ROOT", cMakeRoot.c_str(),
  841. "Path to CMake installation.", cmCacheManager::INTERNAL);
  842. #ifdef _WIN32
  843. std::string comspec = "cmw9xcom.exe";
  844. cmSystemTools::SetWindows9xComspecSubstitute(comspec.c_str());
  845. #endif
  846. return 1;
  847. }
  848. void CMakeCommandUsage(const char* program)
  849. {
  850. cmOStringStream errorStream;
  851. #ifdef CMAKE_BUILD_WITH_CMAKE
  852. errorStream
  853. << "cmake version " << cmVersion::GetCMakeVersion() << "\n";
  854. #else
  855. errorStream
  856. << "cmake bootstrap\n";
  857. #endif
  858. errorStream
  859. << "Usage: " << program << " -E [command] [arguments ...]\n"
  860. << "Available commands: \n"
  861. << " chdir dir cmd [args]... - run command in a given directory\n"
  862. << " copy file destination - copy file to destination (either file "
  863. "or directory)\n"
  864. << " copy_if_different in-file out-file - copy file if input has "
  865. "changed\n"
  866. << " copy_directory source destination - copy directory 'source' "
  867. "content to directory 'destination'\n"
  868. << " compare_files file1 file2 - check if file1 is same as file2\n"
  869. << " echo [string]... - displays arguments as text\n"
  870. << " echo_append [string]... - displays arguments as text but no new "
  871. "line\n"
  872. << " environment - display the current enviroment\n"
  873. << " make_directory dir - create a directory\n"
  874. << " md5sum file1 [...] - compute md5sum of files\n"
  875. << " remove_directory dir - remove a directory and its contents\n"
  876. << " remove [-f] file1 file2 ... - remove the file(s), use -f to force "
  877. "it\n"
  878. << " tar [cxt][vfz] file.tar file/dir1 file/dir2 ... - create a tar "
  879. "archive\n"
  880. << " time command [args] ... - run command and return elapsed time\n"
  881. << " touch file - touch a file.\n"
  882. << " touch_nocreate file - touch a file but do not create it.\n"
  883. #if defined(_WIN32) && !defined(__CYGWIN__)
  884. << " write_regv key value - write registry value\n"
  885. << " delete_regv key - delete registry value\n"
  886. << " comspec - on windows 9x use this for RunCommand\n"
  887. #else
  888. << " create_symlink old new - create a symbolic link new -> old\n"
  889. #endif
  890. ;
  891. cmSystemTools::Error(errorStream.str().c_str());
  892. }
  893. int cmake::ExecuteCMakeCommand(std::vector<std::string>& args)
  894. {
  895. if (args.size() > 1)
  896. {
  897. // Copy file
  898. if (args[1] == "copy" && args.size() == 4)
  899. {
  900. if(!cmSystemTools::cmCopyFile(args[2].c_str(), args[3].c_str()))
  901. {
  902. std::cerr << "Error copying file \"" << args[2].c_str()
  903. << "\" to \"" << args[3].c_str() << "\".\n";
  904. return 1;
  905. }
  906. return 0;
  907. }
  908. // Copy file if different.
  909. if (args[1] == "copy_if_different" && args.size() == 4)
  910. {
  911. if(!cmSystemTools::CopyFileIfDifferent(args[2].c_str(),
  912. args[3].c_str()))
  913. {
  914. std::cerr << "Error copying file (if different) from \""
  915. << args[2].c_str() << "\" to \"" << args[3].c_str()
  916. << "\".\n";
  917. return 1;
  918. }
  919. return 0;
  920. }
  921. // Copy directory content
  922. if (args[1] == "copy_directory" && args.size() == 4)
  923. {
  924. if(!cmSystemTools::CopyADirectory(args[2].c_str(), args[3].c_str()))
  925. {
  926. std::cerr << "Error copying directory from \""
  927. << args[2].c_str() << "\" to \"" << args[3].c_str()
  928. << "\".\n";
  929. return 1;
  930. }
  931. return 0;
  932. }
  933. // Compare files
  934. if (args[1] == "compare_files" && args.size() == 4)
  935. {
  936. if(cmSystemTools::FilesDiffer(args[2].c_str(), args[3].c_str()))
  937. {
  938. std::cerr << "Files \""
  939. << args[2].c_str() << "\" to \"" << args[3].c_str()
  940. << "\" are different.\n";
  941. return 1;
  942. }
  943. return 0;
  944. }
  945. // Echo string
  946. else if (args[1] == "echo" )
  947. {
  948. unsigned int cc;
  949. const char* space = "";
  950. for ( cc = 2; cc < args.size(); cc ++ )
  951. {
  952. std::cout << space << args[cc];
  953. space = " ";
  954. }
  955. std::cout << std::endl;
  956. return 0;
  957. }
  958. // Echo string no new line
  959. else if (args[1] == "echo_append" )
  960. {
  961. unsigned int cc;
  962. const char* space = "";
  963. for ( cc = 2; cc < args.size(); cc ++ )
  964. {
  965. std::cout << space << args[cc];
  966. space = " ";
  967. }
  968. return 0;
  969. }
  970. #if defined(CMAKE_BUILD_WITH_CMAKE)
  971. // Command to create a symbolic link. Fails on platforms not
  972. // supporting them.
  973. else if (args[1] == "environment" )
  974. {
  975. std::vector<std::string> env = cmSystemTools::GetEnvironmentVariables();
  976. std::vector<std::string>::iterator it;
  977. for ( it = env.begin(); it != env.end(); ++ it )
  978. {
  979. std::cout << it->c_str() << std::endl;
  980. }
  981. return 0;
  982. }
  983. #endif
  984. else if (args[1] == "make_directory" && args.size() == 3)
  985. {
  986. if(!cmSystemTools::MakeDirectory(args[2].c_str()))
  987. {
  988. std::cerr << "Error making directory \"" << args[2].c_str()
  989. << "\".\n";
  990. return 1;
  991. }
  992. return 0;
  993. }
  994. else if (args[1] == "remove_directory" && args.size() == 3)
  995. {
  996. if(!cmSystemTools::RemoveADirectory(args[2].c_str()))
  997. {
  998. std::cerr << "Error removing directory \"" << args[2].c_str()
  999. << "\".\n";
  1000. return 1;
  1001. }
  1002. return 0;
  1003. }
  1004. // Remove file
  1005. else if (args[1] == "remove" && args.size() > 2)
  1006. {
  1007. bool force = false;
  1008. for (std::string::size_type cc = 2; cc < args.size(); cc ++)
  1009. {
  1010. if(args[cc] == "\\-f" || args[cc] == "-f")
  1011. {
  1012. force = true;
  1013. }
  1014. else
  1015. {
  1016. // Complain if the file could not be removed, still exists,
  1017. // and the -f option was not given.
  1018. if(!cmSystemTools::RemoveFile(args[cc].c_str()) && !force &&
  1019. cmSystemTools::FileExists(args[cc].c_str()))
  1020. {
  1021. return 1;
  1022. }
  1023. }
  1024. }
  1025. return 0;
  1026. }
  1027. // Touch file
  1028. else if (args[1] == "touch" && args.size() > 2)
  1029. {
  1030. for (std::string::size_type cc = 2; cc < args.size(); cc ++)
  1031. {
  1032. // Complain if the file could not be removed, still exists,
  1033. // and the -f option was not given.
  1034. if(!cmSystemTools::Touch(args[cc].c_str(), true))
  1035. {
  1036. return 1;
  1037. }
  1038. }
  1039. return 0;
  1040. }
  1041. // Touch file
  1042. else if (args[1] == "touch_nocreate" && args.size() > 2)
  1043. {
  1044. for (std::string::size_type cc = 2; cc < args.size(); cc ++)
  1045. {
  1046. // Complain if the file could not be removed, still exists,
  1047. // and the -f option was not given.
  1048. if(!cmSystemTools::Touch(args[cc].c_str(), false))
  1049. {
  1050. return 1;
  1051. }
  1052. }
  1053. return 0;
  1054. }
  1055. // Clock command
  1056. else if (args[1] == "time" && args.size() > 2)
  1057. {
  1058. std::string command = args[2];
  1059. for (std::string::size_type cc = 3; cc < args.size(); cc ++)
  1060. {
  1061. command += " ";
  1062. command += args[cc];
  1063. }
  1064. clock_t clock_start, clock_finish;
  1065. time_t time_start, time_finish;
  1066. time(&time_start);
  1067. clock_start = clock();
  1068. cmSystemTools::RunSingleCommand(command.c_str());
  1069. clock_finish = clock();
  1070. time(&time_finish);
  1071. double clocks_per_sec = static_cast<double>(CLOCKS_PER_SEC);
  1072. std::cout << "Elapsed time: "
  1073. << static_cast<long>(time_finish - time_start) << " s. (time)"
  1074. << ", "
  1075. << static_cast<double>(clock_finish - clock_start) / clocks_per_sec
  1076. << " s. (clock)"
  1077. << "\n";
  1078. return 0;
  1079. }
  1080. // Command to calculate the md5sum of a file
  1081. else if (args[1] == "md5sum" && args.size() >= 3)
  1082. {
  1083. char md5out[32];
  1084. int retval = 0;
  1085. for (std::string::size_type cc = 2; cc < args.size(); cc ++)
  1086. {
  1087. const char *filename = args[cc].c_str();
  1088. // Cannot compute md5sum of a directory
  1089. if(cmSystemTools::FileIsDirectory(filename))
  1090. {
  1091. std::cerr << "Error: " << filename << " is a directory" << std::endl;
  1092. retval++;
  1093. }
  1094. else if(!cmSystemTools::ComputeFileMD5(filename, md5out))
  1095. {
  1096. // To mimic md5sum behavior in a shell:
  1097. std::cerr << filename << ": No such file or directory" << std::endl;
  1098. retval++;
  1099. }
  1100. else
  1101. {
  1102. std::cout << std::string(md5out,32) << " " << filename << std::endl;
  1103. }
  1104. }
  1105. return retval;
  1106. }
  1107. // Command to change directory and run a program.
  1108. else if (args[1] == "chdir" && args.size() >= 4)
  1109. {
  1110. std::string directory = args[2];
  1111. if(!cmSystemTools::FileExists(directory.c_str()))
  1112. {
  1113. cmSystemTools::Error("Directory does not exist for chdir command: ",
  1114. args[2].c_str());
  1115. return 0;
  1116. }
  1117. std::string command = "\"";
  1118. command += args[3];
  1119. command += "\"";
  1120. for (std::string::size_type cc = 4; cc < args.size(); cc ++)
  1121. {
  1122. command += " \"";
  1123. command += args[cc];
  1124. command += "\"";
  1125. }
  1126. int retval = 0;
  1127. int timeout = 0;
  1128. if ( cmSystemTools::RunSingleCommand(command.c_str(), 0, &retval,
  1129. directory.c_str(), true, timeout) )
  1130. {
  1131. return retval;
  1132. }
  1133. return 1;
  1134. }
  1135. // Command to start progress for a build
  1136. else if (args[1] == "cmake_progress_start" && args.size() == 4)
  1137. {
  1138. // bascially remove the directory
  1139. std::string dirName = args[2];
  1140. dirName += "/Progress";
  1141. cmSystemTools::RemoveADirectory(dirName.c_str());
  1142. int count = atoi(args[3].c_str());
  1143. if (count)
  1144. {
  1145. cmSystemTools::MakeDirectory(dirName.c_str());
  1146. // write the count into the directory
  1147. std::string fName = dirName;
  1148. fName += "/count.txt";
  1149. FILE *progFile = fopen(fName.c_str(),"w");
  1150. if (progFile)
  1151. {
  1152. fprintf(progFile,"%i\n",count);
  1153. fclose(progFile);
  1154. }
  1155. }
  1156. return 0;
  1157. }
  1158. // Command to report progress for a build
  1159. else if (args[1] == "cmake_progress_report" && args.size() >= 3)
  1160. {
  1161. std::string dirName = args[2];
  1162. dirName += "/Progress";
  1163. std::string fName;
  1164. FILE *progFile;
  1165. // read the count
  1166. fName = dirName;
  1167. fName += "/count.txt";
  1168. progFile = fopen(fName.c_str(),"r");
  1169. int count = 0;
  1170. if (!progFile)
  1171. {
  1172. return 0;
  1173. }
  1174. else
  1175. {
  1176. fscanf(progFile,"%i",&count);
  1177. fclose(progFile);
  1178. }
  1179. unsigned int i;
  1180. for (i = 3; i < args.size(); ++i)
  1181. {
  1182. fName = dirName;
  1183. fName += "/";
  1184. fName += args[i];
  1185. progFile = fopen(fName.c_str(),"w");
  1186. if (progFile)
  1187. {
  1188. fprintf(progFile,"empty");
  1189. fclose(progFile);
  1190. }
  1191. }
  1192. int fileNum = static_cast<int>
  1193. (cmsys::Directory::GetNumberOfFilesInDirectory(dirName.c_str()));
  1194. if (count > 0)
  1195. {
  1196. // print the progress
  1197. fprintf(stdout,"[%3i%%] ",((fileNum-3)*100)/count);
  1198. }
  1199. return 0;
  1200. }
  1201. // Command to create a symbolic link. Fails on platforms not
  1202. // supporting them.
  1203. else if (args[1] == "create_symlink" && args.size() == 4)
  1204. {
  1205. const char* destinationFileName = args[3].c_str();
  1206. if ( cmSystemTools::FileExists(destinationFileName) )
  1207. {
  1208. if ( cmSystemTools::FileIsSymlink(destinationFileName) )
  1209. {
  1210. if ( !cmSystemTools::RemoveFile(destinationFileName) ||
  1211. cmSystemTools::FileExists(destinationFileName) )
  1212. {
  1213. return 0;
  1214. }
  1215. }
  1216. else
  1217. {
  1218. return 0;
  1219. }
  1220. }
  1221. return cmSystemTools::CreateSymlink(args[2].c_str(),
  1222. args[3].c_str())? 0:1;
  1223. }
  1224. // Internal CMake shared library support.
  1225. else if (args[1] == "cmake_symlink_library" && args.size() == 5)
  1226. {
  1227. int result = 0;
  1228. std::string realName = args[2];
  1229. std::string soName = args[3];
  1230. std::string name = args[4];
  1231. if(soName != realName)
  1232. {
  1233. std::string fname = cmSystemTools::GetFilenameName(realName);
  1234. if(cmSystemTools::FileExists(soName.c_str()))
  1235. {
  1236. cmSystemTools::RemoveFile(soName.c_str());
  1237. }
  1238. if(!cmSystemTools::CreateSymlink(fname.c_str(), soName.c_str()))
  1239. {
  1240. result = 1;
  1241. }
  1242. }
  1243. if(name != soName)
  1244. {
  1245. std::string fname = cmSystemTools::GetFilenameName(soName);
  1246. if(cmSystemTools::FileExists(soName.c_str()))
  1247. {
  1248. cmSystemTools::RemoveFile(name.c_str());
  1249. }
  1250. if(!cmSystemTools::CreateSymlink(fname.c_str(), name.c_str()))
  1251. {
  1252. result = 1;
  1253. }
  1254. }
  1255. return result;
  1256. }
  1257. // Internal CMake versioned executable support.
  1258. else if (args[1] == "cmake_symlink_executable" && args.size() == 4)
  1259. {
  1260. int result = 0;
  1261. std::string realName = args[2];
  1262. std::string name = args[3];
  1263. if(name != realName)
  1264. {
  1265. std::string fname = cmSystemTools::GetFilenameName(realName);
  1266. if(cmSystemTools::FileExists(realName.c_str()))
  1267. {
  1268. cmSystemTools::RemoveFile(name.c_str());
  1269. }
  1270. if(!cmSystemTools::CreateSymlink(fname.c_str(), name.c_str()))
  1271. {
  1272. result = 1;
  1273. }
  1274. }
  1275. return result;
  1276. }
  1277. #if defined(_WIN32)
  1278. // Internal CMake support for calling Visual Studio macros.
  1279. else if (args[1] == "cmake_call_visual_studio_macro" && args.size() >= 4)
  1280. {
  1281. // args[2] = full path to .sln file or "ALL"
  1282. // args[3] = name of Visual Studio macro to call
  1283. // args[4..args.size()-1] = [optional] args for Visual Studio macro
  1284. std::string macroArgs;
  1285. if (args.size() > 4)
  1286. {
  1287. macroArgs = args[4];
  1288. for (size_t i = 5; i < args.size(); ++i)
  1289. {
  1290. macroArgs += " ";
  1291. macroArgs += args[i];
  1292. }
  1293. }
  1294. return cmCallVisualStudioMacro::CallMacro(args[2], args[3], macroArgs);
  1295. }
  1296. #endif
  1297. // Internal CMake dependency scanning support.
  1298. else if (args[1] == "cmake_depends" && args.size() >= 6)
  1299. {
  1300. // Create a cmake object instance to process dependencies.
  1301. cmake cm;
  1302. std::string gen;
  1303. std::string homeDir;
  1304. std::string startDir;
  1305. std::string homeOutDir;
  1306. std::string startOutDir;
  1307. std::string depInfo;
  1308. if(args.size() >= 8)
  1309. {
  1310. // Full signature:
  1311. //
  1312. // -E cmake_depends <generator>
  1313. // <home-src-dir> <start-src-dir>
  1314. // <home-out-dir> <start-out-dir>
  1315. // <dep-info>
  1316. //
  1317. // All paths are provided.
  1318. gen = args[2];
  1319. homeDir = args[3];
  1320. startDir = args[4];
  1321. homeOutDir = args[5];
  1322. startOutDir = args[6];
  1323. depInfo = args[7];
  1324. }
  1325. else
  1326. {
  1327. // Support older signature for existing makefiles:
  1328. //
  1329. // -E cmake_depends <generator>
  1330. // <home-out-dir> <start-out-dir>
  1331. // <dep-info>
  1332. //
  1333. // Just pretend the source directories are the same as the
  1334. // binary directories so at least scanning will work.
  1335. gen = args[2];
  1336. homeDir = args[3];
  1337. startDir = args[4];
  1338. homeOutDir = args[3];
  1339. startOutDir = args[3];
  1340. depInfo = args[5];
  1341. }
  1342. // Create a local generator configured for the directory in
  1343. // which dependencies will be scanned.
  1344. homeDir = cmSystemTools::CollapseFullPath(homeDir.c_str());
  1345. startDir = cmSystemTools::CollapseFullPath(startDir.c_str());
  1346. homeOutDir = cmSystemTools::CollapseFullPath(homeOutDir.c_str());
  1347. startOutDir = cmSystemTools::CollapseFullPath(startOutDir.c_str());
  1348. cm.SetHomeDirectory(homeDir.c_str());
  1349. cm.SetStartDirectory(startDir.c_str());
  1350. cm.SetHomeOutputDirectory(homeOutDir.c_str());
  1351. cm.SetStartOutputDirectory(startOutDir.c_str());
  1352. if(cmGlobalGenerator* ggd = cm.CreateGlobalGenerator(gen.c_str()))
  1353. {
  1354. cm.SetGlobalGenerator(ggd);
  1355. std::auto_ptr<cmLocalGenerator> lgd(ggd->CreateLocalGenerator());
  1356. lgd->SetGlobalGenerator(ggd);
  1357. lgd->GetMakefile()->SetStartDirectory(startDir.c_str());
  1358. lgd->GetMakefile()->SetStartOutputDirectory(startOutDir.c_str());
  1359. lgd->GetMakefile()->MakeStartDirectoriesCurrent();
  1360. // Actually scan dependencies.
  1361. return lgd->ScanDependencies(depInfo.c_str())? 0 : 2;
  1362. }
  1363. return 1;
  1364. }
  1365. // Internal CMake link script support.
  1366. else if (args[1] == "cmake_link_script" && args.size() >= 3)
  1367. {
  1368. return cmake::ExecuteLinkScript(args);
  1369. }
  1370. // Internal CMake unimplemented feature notification.
  1371. else if (args[1] == "cmake_unimplemented_variable")
  1372. {
  1373. std::cerr << "Feature not implemented for this platform.";
  1374. if(args.size() == 3)
  1375. {
  1376. std::cerr << " Variable " << args[2] << " is not set.";
  1377. }
  1378. std::cerr << std::endl;
  1379. return 1;
  1380. }
  1381. #ifdef CMAKE_BUILD_WITH_CMAKE
  1382. // Internal CMake color makefile support.
  1383. else if (args[1] == "cmake_echo_color")
  1384. {
  1385. return cmake::ExecuteEchoColor(args);
  1386. }
  1387. #endif
  1388. // Tar files
  1389. else if (args[1] == "tar" && args.size() > 3)
  1390. {
  1391. std::string flags = args[2];
  1392. std::string outFile = args[3];
  1393. std::vector<cmStdString> files;
  1394. for (std::string::size_type cc = 4; cc < args.size(); cc ++)
  1395. {
  1396. files.push_back(args[cc]);
  1397. }
  1398. bool gzip = false;
  1399. bool verbose = false;
  1400. if ( flags.find_first_of('z') != flags.npos )
  1401. {
  1402. gzip = true;
  1403. }
  1404. if ( flags.find_first_of('v') != flags.npos )
  1405. {
  1406. verbose = true;
  1407. }
  1408. if ( flags.find_first_of('t') != flags.npos )
  1409. {
  1410. if ( !cmSystemTools::ListTar(outFile.c_str(), files, gzip, verbose) )
  1411. {
  1412. cmSystemTools::Error("Problem creating tar: ", outFile.c_str());
  1413. return 1;
  1414. }
  1415. }
  1416. else if ( flags.find_first_of('c') != flags.npos )
  1417. {
  1418. if ( !cmSystemTools::CreateTar(
  1419. outFile.c_str(), files, gzip, verbose) )
  1420. {
  1421. cmSystemTools::Error("Problem creating tar: ", outFile.c_str());
  1422. return 1;
  1423. }
  1424. }
  1425. else if ( flags.find_first_of('x') != flags.npos )
  1426. {
  1427. if ( !cmSystemTools::ExtractTar(
  1428. outFile.c_str(), files, gzip, verbose) )
  1429. {
  1430. cmSystemTools::Error("Problem extracting tar: ", outFile.c_str());
  1431. return 1;
  1432. }
  1433. }
  1434. return 0;
  1435. }
  1436. #if defined(CMAKE_BUILD_WITH_CMAKE)
  1437. // Internal CMake Fortran module support.
  1438. else if (args[1] == "cmake_copy_f90_mod" && args.size() >= 4)
  1439. {
  1440. return cmDependsFortran::CopyModule(args)? 0 : 1;
  1441. }
  1442. #endif
  1443. #if defined(_WIN32) && !defined(__CYGWIN__)
  1444. // Write registry value
  1445. else if (args[1] == "write_regv" && args.size() > 3)
  1446. {
  1447. return cmSystemTools::WriteRegistryValue(args[2].c_str(),
  1448. args[3].c_str()) ? 0 : 1;
  1449. }
  1450. // Delete registry value
  1451. else if (args[1] == "delete_regv" && args.size() > 2)
  1452. {
  1453. return cmSystemTools::DeleteRegistryValue(args[2].c_str()) ? 0 : 1;
  1454. }
  1455. // Remove file
  1456. else if (args[1] == "comspec" && args.size() > 2)
  1457. {
  1458. unsigned int cc;
  1459. std::string command = args[2];
  1460. for ( cc = 3; cc < args.size(); cc ++ )
  1461. {
  1462. command += " " + args[cc];
  1463. }
  1464. return cmWin32ProcessExecution::Windows9xHack(command.c_str());
  1465. }
  1466. #endif
  1467. }
  1468. ::CMakeCommandUsage(args[0].c_str());
  1469. return 1;
  1470. }
  1471. void cmake::AddExtraGenerator(const char* name,
  1472. CreateExtraGeneratorFunctionType newFunction)
  1473. {
  1474. cmExternalMakefileProjectGenerator* extraGenerator = newFunction();
  1475. const std::vector<std::string>& supportedGlobalGenerators =
  1476. extraGenerator->GetSupportedGlobalGenerators();
  1477. for(std::vector<std::string>::const_iterator
  1478. it = supportedGlobalGenerators.begin();
  1479. it != supportedGlobalGenerators.end();
  1480. ++it )
  1481. {
  1482. std::string fullName = cmExternalMakefileProjectGenerator::
  1483. CreateFullGeneratorName(it->c_str(), name);
  1484. this->ExtraGenerators[fullName.c_str()] = newFunction;
  1485. }
  1486. delete extraGenerator;
  1487. }
  1488. void cmake::AddDefaultExtraGenerators()
  1489. {
  1490. #if defined(CMAKE_BUILD_WITH_CMAKE)
  1491. #if defined(_WIN32) && !defined(__CYGWIN__)
  1492. // e.g. kdevelop4 ?
  1493. #endif
  1494. #if !defined(__CYGWIN__)
  1495. this->AddExtraGenerator(cmExtraCodeBlocksGenerator::GetActualName(),
  1496. &cmExtraCodeBlocksGenerator::New);
  1497. #endif
  1498. #ifdef CMAKE_USE_ECLIPSE
  1499. this->AddExtraGenerator(cmExtraEclipseCDT4Generator::GetActualName(),
  1500. &cmExtraEclipseCDT4Generator::New);
  1501. #endif
  1502. #ifdef CMAKE_USE_KDEVELOP
  1503. this->AddExtraGenerator(cmGlobalKdevelopGenerator::GetActualName(),
  1504. &cmGlobalKdevelopGenerator::New);
  1505. // for kdevelop also add the generator with just the name of the
  1506. // extra generator, since it was this way since cmake 2.2
  1507. this->ExtraGenerators[cmGlobalKdevelopGenerator::GetActualName()]
  1508. = &cmGlobalKdevelopGenerator::New;
  1509. #endif
  1510. #endif
  1511. }
  1512. //----------------------------------------------------------------------------
  1513. void cmake::GetRegisteredGenerators(std::vector<std::string>& names)
  1514. {
  1515. for(RegisteredGeneratorsMap::const_iterator i = this->Generators.begin();
  1516. i != this->Generators.end(); ++i)
  1517. {
  1518. names.push_back(i->first);
  1519. }
  1520. for(RegisteredExtraGeneratorsMap::const_iterator
  1521. i = this->ExtraGenerators.begin();
  1522. i != this->ExtraGenerators.end(); ++i)
  1523. {
  1524. names.push_back(i->first);
  1525. }
  1526. }
  1527. cmGlobalGenerator* cmake::CreateGlobalGenerator(const char* name)
  1528. {
  1529. cmGlobalGenerator* generator = 0;
  1530. cmExternalMakefileProjectGenerator* extraGenerator = 0;
  1531. RegisteredGeneratorsMap::const_iterator genIt = this->Generators.find(name);
  1532. if(genIt == this->Generators.end())
  1533. {
  1534. RegisteredExtraGeneratorsMap::const_iterator extraGenIt =
  1535. this->ExtraGenerators.find(name);
  1536. if (extraGenIt == this->ExtraGenerators.end())
  1537. {
  1538. return 0;
  1539. }
  1540. extraGenerator = (extraGenIt->second)();
  1541. genIt=this->Generators.find(extraGenerator->GetGlobalGeneratorName(name));
  1542. if(genIt == this->Generators.end())
  1543. {
  1544. delete extraGenerator;
  1545. return 0;
  1546. }
  1547. }
  1548. generator = (genIt->second)();
  1549. generator->SetCMakeInstance(this);
  1550. generator->SetExternalMakefileProjectGenerator(extraGenerator);
  1551. return generator;
  1552. }
  1553. void cmake::SetHomeDirectory(const char* dir)
  1554. {
  1555. this->cmHomeDirectory = dir;
  1556. cmSystemTools::ConvertToUnixSlashes(this->cmHomeDirectory);
  1557. }
  1558. void cmake::SetHomeOutputDirectory(const char* lib)
  1559. {
  1560. this->HomeOutputDirectory = lib;
  1561. cmSystemTools::ConvertToUnixSlashes(this->HomeOutputDirectory);
  1562. }
  1563. void cmake::SetGlobalGenerator(cmGlobalGenerator *gg)
  1564. {
  1565. if(!gg)
  1566. {
  1567. cmSystemTools::Error("Error SetGlobalGenerator called with null");
  1568. return;
  1569. }
  1570. // delete the old generator
  1571. if (this->GlobalGenerator)
  1572. {
  1573. delete this->GlobalGenerator;
  1574. // restore the original environment variables CXX and CC
  1575. // Restor CC
  1576. std::string env = "CC=";
  1577. if(this->CCEnvironment.size())
  1578. {
  1579. env += this->CCEnvironment;
  1580. }
  1581. cmSystemTools::PutEnv(env.c_str());
  1582. env = "CXX=";
  1583. if(this->CXXEnvironment.size())
  1584. {
  1585. env += this->CXXEnvironment;
  1586. }
  1587. cmSystemTools::PutEnv(env.c_str());
  1588. }
  1589. // set the new
  1590. this->GlobalGenerator = gg;
  1591. // set the global flag for unix style paths on cmSystemTools as soon as
  1592. // the generator is set. This allows gmake to be used on windows.
  1593. cmSystemTools::SetForceUnixPaths
  1594. (this->GlobalGenerator->GetForceUnixPaths());
  1595. // Save the environment variables CXX and CC
  1596. const char* cxx = getenv("CXX");
  1597. const char* cc = getenv("CC");
  1598. if(cxx)
  1599. {
  1600. this->CXXEnvironment = cxx;
  1601. }
  1602. else
  1603. {
  1604. this->CXXEnvironment = "";
  1605. }
  1606. if(cc)
  1607. {
  1608. this->CCEnvironment = cc;
  1609. }
  1610. else
  1611. {
  1612. this->CCEnvironment = "";
  1613. }
  1614. // set the cmake instance just to be sure
  1615. gg->SetCMakeInstance(this);
  1616. }
  1617. int cmake::DoPreConfigureChecks()
  1618. {
  1619. // Make sure the Start directory contains a CMakeLists.txt file.
  1620. std::string srcList = this->GetHomeDirectory();
  1621. srcList += "/CMakeLists.txt";
  1622. if(!cmSystemTools::FileExists(srcList.c_str()))
  1623. {
  1624. cmOStringStream err;
  1625. if(cmSystemTools::FileIsDirectory(this->GetHomeDirectory()))
  1626. {
  1627. err << "The source directory \"" << this->GetHomeDirectory()
  1628. << "\" does not appear to contain CMakeLists.txt.\n";
  1629. }
  1630. else if(cmSystemTools::FileExists(this->GetHomeDirectory()))
  1631. {
  1632. err << "The source directory \"" << this->GetHomeDirectory()
  1633. << "\" is a file, not a directory.\n";
  1634. }
  1635. else
  1636. {
  1637. err << "The source directory \"" << this->GetHomeDirectory()
  1638. << "\" does not exist.\n";
  1639. }
  1640. err << "Specify --help for usage, or press the help button on the CMake "
  1641. "GUI.";
  1642. cmSystemTools::Error(err.str().c_str());
  1643. return -2;
  1644. }
  1645. // do a sanity check on some values
  1646. if(this->CacheManager->GetCacheValue("CMAKE_HOME_DIRECTORY"))
  1647. {
  1648. std::string cacheStart =
  1649. this->CacheManager->GetCacheValue("CMAKE_HOME_DIRECTORY");
  1650. cacheStart += "/CMakeLists.txt";
  1651. std::string currentStart = this->GetHomeDirectory();
  1652. currentStart += "/CMakeLists.txt";
  1653. if(!cmSystemTools::SameFile(cacheStart.c_str(), currentStart.c_str()))
  1654. {
  1655. std::string message = "The source \"";
  1656. message += currentStart;
  1657. message += "\" does not match the source \"";
  1658. message += cacheStart;
  1659. message += "\" used to generate cache. ";
  1660. message += "Re-run cmake with a different source directory.";
  1661. cmSystemTools::Error(message.c_str());
  1662. return -2;
  1663. }
  1664. }
  1665. else
  1666. {
  1667. return 0;
  1668. }
  1669. return 1;
  1670. }
  1671. struct SaveCacheEntry
  1672. {
  1673. std::string key;
  1674. std::string value;
  1675. std::string help;
  1676. cmCacheManager::CacheEntryType type;
  1677. };
  1678. int cmake::HandleDeleteCacheVariables(const char* var)
  1679. {
  1680. std::vector<std::string> argsSplit;
  1681. cmSystemTools::ExpandListArgument(std::string(var), argsSplit);
  1682. // erase the property to avoid infinite recursion
  1683. this->SetProperty("__CMAKE_DELETE_CACHE_CHANGE_VARS_", "");
  1684. cmCacheManager::CacheIterator ci = this->CacheManager->NewIterator();
  1685. std::vector<SaveCacheEntry> saved;
  1686. cmOStringStream warning;
  1687. warning
  1688. << "You have changed variables that require your cache to be deleted.\n"
  1689. << "Configure will be re-run and you may have to reset some variables.\n"
  1690. << "The following variables have changed:\n";
  1691. for(std::vector<std::string>::iterator i = argsSplit.begin();
  1692. i != argsSplit.end(); ++i)
  1693. {
  1694. SaveCacheEntry save;
  1695. save.key = *i;
  1696. warning << *i << "= ";
  1697. i++;
  1698. save.value = *i;
  1699. warning << *i << "\n";
  1700. if(ci.Find(save.key.c_str()))
  1701. {
  1702. save.type = ci.GetType();
  1703. save.help = ci.GetProperty("HELPSTRING");
  1704. }
  1705. saved.push_back(save);
  1706. }
  1707. // remove the cache
  1708. this->CacheManager->DeleteCache(this->GetStartOutputDirectory());
  1709. // load the empty cache
  1710. this->LoadCache();
  1711. // restore the changed compilers
  1712. for(std::vector<SaveCacheEntry>::iterator i = saved.begin();
  1713. i != saved.end(); ++i)
  1714. {
  1715. this->AddCacheEntry(i->key.c_str(), i->value.c_str(),
  1716. i->help.c_str(), i->type);
  1717. }
  1718. cmSystemTools::Message(warning.str().c_str());
  1719. // avoid reconfigure if there were errors
  1720. if(!cmSystemTools::GetErrorOccuredFlag())
  1721. {
  1722. // re-run configure
  1723. return this->Configure();
  1724. }
  1725. }
  1726. int cmake::Configure()
  1727. {
  1728. int ret = this->ActualConfigure();
  1729. const char* delCacheVars = this->GetProperty("__CMAKE_DELETE_CACHE_CHANGE_VARS_");
  1730. if(delCacheVars && delCacheVars[0] != 0)
  1731. {
  1732. return this->HandleDeleteCacheVariables(delCacheVars);
  1733. }
  1734. return ret;
  1735. }
  1736. int cmake::ActualConfigure()
  1737. {
  1738. // Construct right now our path conversion table before it's too late:
  1739. this->UpdateConversionPathTable();
  1740. this->CleanupCommandsAndMacros();
  1741. int res = 0;
  1742. if ( !this->ScriptMode )
  1743. {
  1744. res = this->DoPreConfigureChecks();
  1745. }
  1746. if ( res < 0 )
  1747. {
  1748. return -2;
  1749. }
  1750. if ( !res )
  1751. {
  1752. this->CacheManager->AddCacheEntry
  1753. ("CMAKE_HOME_DIRECTORY",
  1754. this->GetHomeDirectory(),
  1755. "Start directory with the top level CMakeLists.txt file for this "
  1756. "project",
  1757. cmCacheManager::INTERNAL);
  1758. }
  1759. // set the default BACKWARDS compatibility to the current version
  1760. if(!this->CacheManager->GetCacheValue("CMAKE_BACKWARDS_COMPATIBILITY"))
  1761. {
  1762. char ver[256];
  1763. sprintf(ver,"%i.%i",cmVersion::GetMajorVersion(),
  1764. cmVersion::GetMinorVersion());
  1765. this->CacheManager->AddCacheEntry
  1766. ("CMAKE_BACKWARDS_COMPATIBILITY",ver,
  1767. "For backwards compatibility, what version of CMake commands and "
  1768. "syntax should this version of CMake allow.",
  1769. cmCacheManager::STRING);
  1770. }
  1771. // no generator specified on the command line
  1772. if(!this->GlobalGenerator)
  1773. {
  1774. const char* genName =
  1775. this->CacheManager->GetCacheValue("CMAKE_GENERATOR");
  1776. const char* extraGenName =
  1777. this->CacheManager->GetCacheValue("CMAKE_EXTRA_GENERATOR");
  1778. if(genName)
  1779. {
  1780. std::string fullName = cmExternalMakefileProjectGenerator::
  1781. CreateFullGeneratorName(genName, extraGenName);
  1782. this->GlobalGenerator = this->CreateGlobalGenerator(fullName.c_str());
  1783. }
  1784. if(this->GlobalGenerator)
  1785. {
  1786. // set the global flag for unix style paths on cmSystemTools as
  1787. // soon as the generator is set. This allows gmake to be used
  1788. // on windows.
  1789. cmSystemTools::SetForceUnixPaths
  1790. (this->GlobalGenerator->GetForceUnixPaths());
  1791. }
  1792. else
  1793. {
  1794. #if defined(__BORLANDC__) && defined(_WIN32)
  1795. this->SetGlobalGenerator(new cmGlobalBorlandMakefileGenerator);
  1796. #elif defined(_WIN32) && !defined(__CYGWIN__) && !defined(CMAKE_BOOT_MINGW)
  1797. std::string installedCompiler;
  1798. std::string mp = "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft"
  1799. "\\VisualStudio\\8.0\\Setup;Dbghelp_path]";
  1800. cmSystemTools::ExpandRegistryValues(mp);
  1801. if (!(mp == "/registry"))
  1802. {
  1803. installedCompiler = "Visual Studio 8 2005";
  1804. }
  1805. else
  1806. {
  1807. mp = "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft"
  1808. "\\VisualStudio\\7.1;InstallDir]";
  1809. cmSystemTools::ExpandRegistryValues(mp);
  1810. if (!(mp == "/registry"))
  1811. {
  1812. installedCompiler = "Visual Studio 7 .NET 2003";
  1813. }
  1814. else
  1815. {
  1816. mp = "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft"
  1817. "\\VisualStudio\\7.0;InstallDir]";
  1818. cmSystemTools::ExpandRegistryValues(mp);
  1819. if (!(mp == "/registry"))
  1820. {
  1821. installedCompiler = "Visual Studio 7";
  1822. }
  1823. else
  1824. {
  1825. installedCompiler = "Visual Studio 6";
  1826. }
  1827. }
  1828. }
  1829. cmGlobalGenerator* gen
  1830. = this->CreateGlobalGenerator(installedCompiler.c_str());
  1831. if(!gen)
  1832. {
  1833. gen = new cmGlobalNMakeMakefileGenerator;
  1834. }
  1835. this->SetGlobalGenerator(gen);
  1836. #else
  1837. this->SetGlobalGenerator(new cmGlobalUnixMakefileGenerator3);
  1838. #endif
  1839. }
  1840. if(!this->GlobalGenerator)
  1841. {
  1842. cmSystemTools::Error("Could not create generator");
  1843. return -1;
  1844. }
  1845. }
  1846. const char* genName = this->CacheManager->GetCacheValue("CMAKE_GENERATOR");
  1847. if(genName)
  1848. {
  1849. if(strcmp(this->GlobalGenerator->GetName(), genName) != 0)
  1850. {
  1851. std::string message = "Error: generator : ";
  1852. message += this->GlobalGenerator->GetName();
  1853. message += "\nDoes not match the generator used previously: ";
  1854. message += genName;
  1855. message +=
  1856. "\nEither remove the CMakeCache.txt file or choose a different"
  1857. " binary directory.";
  1858. cmSystemTools::Error(message.c_str());
  1859. return -2;
  1860. }
  1861. }
  1862. if(!this->CacheManager->GetCacheValue("CMAKE_GENERATOR"))
  1863. {
  1864. this->CacheManager->AddCacheEntry("CMAKE_GENERATOR",
  1865. this->GlobalGenerator->GetName(),
  1866. "Name of generator.",
  1867. cmCacheManager::INTERNAL);
  1868. this->CacheManager->AddCacheEntry("CMAKE_EXTRA_GENERATOR",
  1869. this->GlobalGenerator->GetExtraGeneratorName(),
  1870. "Name of external makefile project generator.",
  1871. cmCacheManager::INTERNAL);
  1872. }
  1873. // reset any system configuration information, except for when we are
  1874. // InTryCompile. With TryCompile the system info is taken from the parent's
  1875. // info to save time
  1876. if (!this->InTryCompile)
  1877. {
  1878. this->GlobalGenerator->ClearEnabledLanguages();
  1879. }
  1880. this->CleanupWrittenFiles();
  1881. // Truncate log files
  1882. if (!this->InTryCompile)
  1883. {
  1884. this->TruncateOutputLog("CMakeOutput.log");
  1885. this->TruncateOutputLog("CMakeError.log");
  1886. }
  1887. // actually do the configure
  1888. this->GlobalGenerator->Configure();
  1889. // Before saving the cache
  1890. // if the project did not define one of the entries below, add them now
  1891. // so users can edit the values in the cache:
  1892. // LIBRARY_OUTPUT_PATH
  1893. // EXECUTABLE_OUTPUT_PATH
  1894. if(!this->CacheManager->GetCacheValue("LIBRARY_OUTPUT_PATH"))
  1895. {
  1896. this->CacheManager->AddCacheEntry
  1897. ("LIBRARY_OUTPUT_PATH", "",
  1898. "Single output directory for building all libraries.",
  1899. cmCacheManager::PATH);
  1900. }
  1901. if(!this->CacheManager->GetCacheValue("EXECUTABLE_OUTPUT_PATH"))
  1902. {
  1903. this->CacheManager->AddCacheEntry
  1904. ("EXECUTABLE_OUTPUT_PATH", "",
  1905. "Single output directory for building all executables.",
  1906. cmCacheManager::PATH);
  1907. }
  1908. if(!this->CacheManager->GetCacheValue("CMAKE_USE_RELATIVE_PATHS"))
  1909. {
  1910. this->CacheManager->AddCacheEntry
  1911. ("CMAKE_USE_RELATIVE_PATHS", false,
  1912. "If true, cmake will use relative paths in makefiles and projects.");
  1913. cmCacheManager::CacheIterator it =
  1914. this->CacheManager->GetCacheIterator("CMAKE_USE_RELATIVE_PATHS");
  1915. if ( !it.PropertyExists("ADVANCED") )
  1916. {
  1917. it.SetProperty("ADVANCED", "1");
  1918. }
  1919. }
  1920. if(cmSystemTools::GetFatalErrorOccured() &&
  1921. (!this->CacheManager->GetCacheValue("CMAKE_MAKE_PROGRAM") ||
  1922. cmSystemTools::IsOff(this->CacheManager->
  1923. GetCacheValue("CMAKE_MAKE_PROGRAM"))))
  1924. {
  1925. // We must have a bad generator selection. Wipe the cache entry so the
  1926. // user can select another.
  1927. this->CacheManager->RemoveCacheEntry("CMAKE_GENERATOR");
  1928. this->CacheManager->RemoveCacheEntry("CMAKE_EXTRA_GENERATOR");
  1929. }
  1930. // only save the cache if there were no fatal errors
  1931. if ( !this->ScriptMode )
  1932. {
  1933. this->CacheManager->SaveCache(this->GetHomeOutputDirectory());
  1934. }
  1935. if ( !this->GraphVizFile.empty() )
  1936. {
  1937. std::cout << "Generate graphviz: " << this->GraphVizFile << std::endl;
  1938. this->GenerateGraphViz(this->GraphVizFile.c_str());
  1939. }
  1940. if(cmSystemTools::GetErrorOccuredFlag())
  1941. {
  1942. return -1;
  1943. }
  1944. return 0;
  1945. }
  1946. bool cmake::CacheVersionMatches()
  1947. {
  1948. const char* majv =
  1949. this->CacheManager->GetCacheValue("CMAKE_CACHE_MAJOR_VERSION");
  1950. const char* minv =
  1951. this->CacheManager->GetCacheValue("CMAKE_CACHE_MINOR_VERSION");
  1952. const char* relv =
  1953. this->CacheManager->GetCacheValue("CMAKE_CACHE_RELEASE_VERSION");
  1954. bool cacheSameCMake = false;
  1955. if(majv &&
  1956. atoi(majv) == static_cast<int>(cmVersion::GetMajorVersion())
  1957. && minv &&
  1958. atoi(minv) == static_cast<int>(cmVersion::GetMinorVersion())
  1959. && relv && (strcmp(relv, cmVersion::GetReleaseVersion().c_str()) == 0))
  1960. {
  1961. cacheSameCMake = true;
  1962. }
  1963. return cacheSameCMake;
  1964. }
  1965. void cmake::PreLoadCMakeFiles()
  1966. {
  1967. std::string pre_load = this->GetHomeDirectory();
  1968. if ( pre_load.size() > 0 )
  1969. {
  1970. pre_load += "/PreLoad.cmake";
  1971. if ( cmSystemTools::FileExists(pre_load.c_str()) )
  1972. {
  1973. this->ReadListFile(pre_load.c_str());
  1974. }
  1975. }
  1976. pre_load = this->GetHomeOutputDirectory();
  1977. if ( pre_load.size() > 0 )
  1978. {
  1979. pre_load += "/PreLoad.cmake";
  1980. if ( cmSystemTools::FileExists(pre_load.c_str()) )
  1981. {
  1982. this->ReadListFile(pre_load.c_str());
  1983. }
  1984. }
  1985. }
  1986. // handle a command line invocation
  1987. int cmake::Run(const std::vector<std::string>& args, bool noconfigure)
  1988. {
  1989. // Process the arguments
  1990. this->SetArgs(args);
  1991. if(cmSystemTools::GetErrorOccuredFlag())
  1992. {
  1993. return -1;
  1994. }
  1995. // If we are given a stamp file check if it is really out of date.
  1996. if(!this->CheckStampFile.empty() &&
  1997. cmakeCheckStampFile(this->CheckStampFile.c_str()))
  1998. {
  1999. return 0;
  2000. }
  2001. // set the cmake command
  2002. this->CMakeCommand = args[0];
  2003. if ( !this->ScriptMode )
  2004. {
  2005. // load the cache
  2006. if(this->LoadCache() < 0)
  2007. {
  2008. cmSystemTools::Error("Error executing cmake::LoadCache(). Aborting.\n");
  2009. return -1;
  2010. }
  2011. }
  2012. else
  2013. {
  2014. this->AddCMakePaths(this->CMakeCommand.c_str());
  2015. }
  2016. // Add any cache args
  2017. if ( !this->SetCacheArgs(args) )
  2018. {
  2019. cmSystemTools::Error("Problem processing arguments. Aborting.\n");
  2020. return -1;
  2021. }
  2022. // In script mode we terminate after running the script.
  2023. if(this->ScriptMode)
  2024. {
  2025. if(cmSystemTools::GetErrorOccuredFlag())
  2026. {
  2027. return -1;
  2028. }
  2029. else
  2030. {
  2031. return 0;
  2032. }
  2033. }
  2034. this->PreLoadCMakeFiles();
  2035. std::string systemFile = this->GetHomeOutputDirectory();
  2036. systemFile += "/CMakeSystem.cmake";
  2037. if ( noconfigure )
  2038. {
  2039. return 0;
  2040. }
  2041. // now run the global generate
  2042. // Check the state of the build system to see if we need to regenerate.
  2043. if(!this->CheckBuildSystem())
  2044. {
  2045. return 0;
  2046. }
  2047. // If we are doing global generate, we better set start and start
  2048. // output directory to the root of the project.
  2049. std::string oldstartdir = this->GetStartDirectory();
  2050. std::string oldstartoutputdir = this->GetStartOutputDirectory();
  2051. this->SetStartDirectory(this->GetHomeDirectory());
  2052. this->SetStartOutputDirectory(this->GetHomeOutputDirectory());
  2053. int ret = this->Configure();
  2054. if (ret || this->ScriptMode)
  2055. {
  2056. #if defined(CMAKE_HAVE_VS_GENERATORS)
  2057. if(!this->VSSolutionFile.empty() && this->GlobalGenerator)
  2058. {
  2059. // CMake is running to regenerate a Visual Studio build tree
  2060. // during a build from the VS IDE. The build files cannot be
  2061. // regenerated, so we should stop the build.
  2062. cmSystemTools::Message(
  2063. "CMake Configure step failed. "
  2064. "Build files cannot be regenerated correctly. "
  2065. "Attempting to stop IDE build.");
  2066. cmGlobalVisualStudioGenerator* gg =
  2067. static_cast<cmGlobalVisualStudioGenerator*>(this->GlobalGenerator);
  2068. gg->CallVisualStudioMacro(cmGlobalVisualStudioGenerator::MacroStop,
  2069. this->VSSolutionFile.c_str());
  2070. }
  2071. #endif
  2072. return ret;
  2073. }
  2074. ret = this->Generate();
  2075. std::string message = "Build files have been written to: ";
  2076. message += this->GetHomeOutputDirectory();
  2077. this->UpdateProgress(message.c_str(), -1);
  2078. if(ret)
  2079. {
  2080. return ret;
  2081. }
  2082. this->SetStartDirectory(oldstartdir.c_str());
  2083. this->SetStartOutputDirectory(oldstartoutputdir.c_str());
  2084. return ret;
  2085. }
  2086. int cmake::Generate()
  2087. {
  2088. if(!this->GlobalGenerator)
  2089. {
  2090. return -1;
  2091. }
  2092. this->GlobalGenerator->Generate();
  2093. if(cmSystemTools::GetErrorOccuredFlag())
  2094. {
  2095. return -1;
  2096. }
  2097. if (this->GetProperty("REPORT_UNDEFINED_PROPERTIES"))
  2098. {
  2099. this->ReportUndefinedPropertyAccesses
  2100. (this->GetProperty("REPORT_UNDEFINED_PROPERTIES"));
  2101. }
  2102. return 0;
  2103. }
  2104. void cmake::AddCacheEntry(const char* key, const char* value,
  2105. const char* helpString,
  2106. int type)
  2107. {
  2108. this->CacheManager->AddCacheEntry(key, value,
  2109. helpString,
  2110. cmCacheManager::CacheEntryType(type));
  2111. }
  2112. const char* cmake::GetCacheDefinition(const char* name) const
  2113. {
  2114. return this->CacheManager->GetCacheValue(name);
  2115. }
  2116. int cmake::DumpDocumentationToFile(std::ostream& f)
  2117. {
  2118. #ifdef CMAKE_BUILD_WITH_CMAKE
  2119. // Loop over all registered commands and print out documentation
  2120. const char *name;
  2121. const char *terse;
  2122. const char *full;
  2123. char tmp[1024];
  2124. sprintf(tmp,"Version %d.%d (%s)", cmVersion::GetMajorVersion(),
  2125. cmVersion::GetMinorVersion(),
  2126. cmVersion::GetReleaseVersion().c_str());
  2127. f << "<html>\n";
  2128. f << "<h1>Documentation for commands of CMake " << tmp << "</h1>\n";
  2129. f << "<ul>\n";
  2130. for(RegisteredCommandsMap::iterator j = this->Commands.begin();
  2131. j != this->Commands.end(); ++j)
  2132. {
  2133. name = (*j).second->GetName();
  2134. terse = (*j).second->GetTerseDocumentation();
  2135. full = (*j).second->GetFullDocumentation();
  2136. f << "<li><b>" << name << "</b> - " << terse << std::endl
  2137. << "<br><i>Usage:</i> " << full << "</li>" << std::endl << std::endl;
  2138. }
  2139. f << "</ul></html>\n";
  2140. #else
  2141. (void)f;
  2142. #endif
  2143. return 1;
  2144. }
  2145. void cmake::AddDefaultCommands()
  2146. {
  2147. std::list<cmCommand*> commands;
  2148. GetBootstrapCommands(commands);
  2149. GetPredefinedCommands(commands);
  2150. for(std::list<cmCommand*>::iterator i = commands.begin();
  2151. i != commands.end(); ++i)
  2152. {
  2153. this->AddCommand(*i);
  2154. }
  2155. }
  2156. void cmake::AddDefaultGenerators()
  2157. {
  2158. #if defined(_WIN32) && !defined(__CYGWIN__)
  2159. # if !defined(CMAKE_BOOT_MINGW)
  2160. this->Generators[cmGlobalVisualStudio6Generator::GetActualName()] =
  2161. &cmGlobalVisualStudio6Generator::New;
  2162. this->Generators[cmGlobalVisualStudio7Generator::GetActualName()] =
  2163. &cmGlobalVisualStudio7Generator::New;
  2164. this->Generators[cmGlobalVisualStudio71Generator::GetActualName()] =
  2165. &cmGlobalVisualStudio71Generator::New;
  2166. this->Generators[cmGlobalVisualStudio8Generator::GetActualName()] =
  2167. &cmGlobalVisualStudio8Generator::New;
  2168. this->Generators[cmGlobalVisualStudio9Generator::GetActualName()] =
  2169. &cmGlobalVisualStudio9Generator::New;
  2170. this->Generators[cmGlobalVisualStudio8Win64Generator::GetActualName()] =
  2171. &cmGlobalVisualStudio8Win64Generator::New;
  2172. this->Generators[cmGlobalBorlandMakefileGenerator::GetActualName()] =
  2173. &cmGlobalBorlandMakefileGenerator::New;
  2174. this->Generators[cmGlobalNMakeMakefileGenerator::GetActualName()] =
  2175. &cmGlobalNMakeMakefileGenerator::New;
  2176. this->Generators[cmGlobalWatcomWMakeGenerator::GetActualName()] =
  2177. &cmGlobalWatcomWMakeGenerator::New;
  2178. # endif
  2179. this->Generators[cmGlobalMSYSMakefileGenerator::GetActualName()] =
  2180. &cmGlobalMSYSMakefileGenerator::New;
  2181. this->Generators[cmGlobalMinGWMakefileGenerator::GetActualName()] =
  2182. &cmGlobalMinGWMakefileGenerator::New;
  2183. #endif
  2184. this->Generators[cmGlobalUnixMakefileGenerator3::GetActualName()] =
  2185. &cmGlobalUnixMakefileGenerator3::New;
  2186. #ifdef CMAKE_USE_XCODE
  2187. this->Generators[cmGlobalXCodeGenerator::GetActualName()] =
  2188. &cmGlobalXCodeGenerator::New;
  2189. #endif
  2190. }
  2191. int cmake::LoadCache()
  2192. {
  2193. // could we not read the cache
  2194. if (!this->CacheManager->LoadCache(this->GetHomeOutputDirectory()))
  2195. {
  2196. // if it does exist, but isn;t readable then warn the user
  2197. std::string cacheFile = this->GetHomeOutputDirectory();
  2198. cacheFile += "/CMakeCache.txt";
  2199. if(cmSystemTools::FileExists(cacheFile.c_str()))
  2200. {
  2201. cmSystemTools::Error(
  2202. "There is a CMakeCache.txt file for the current binary tree but "
  2203. "cmake does not have permission to read it. Please check the "
  2204. "permissions of the directory you are trying to run CMake on.");
  2205. return -1;
  2206. }
  2207. }
  2208. if (this->CMakeCommand.size() < 2)
  2209. {
  2210. cmSystemTools::Error(
  2211. "cmake command was not specified prior to loading the cache in "
  2212. "cmake.cxx");
  2213. return -1;
  2214. }
  2215. // setup CMAKE_ROOT and CMAKE_COMMAND
  2216. if(!this->AddCMakePaths(this->CMakeCommand.c_str()))
  2217. {
  2218. return -3;
  2219. }
  2220. // set the default BACKWARDS compatibility to the current version
  2221. if(!this->CacheManager->GetCacheValue("CMAKE_BACKWARDS_COMPATIBILITY"))
  2222. {
  2223. char ver[256];
  2224. sprintf(ver,"%i.%i",cmVersion::GetMajorVersion(),
  2225. cmVersion::GetMinorVersion());
  2226. this->CacheManager->AddCacheEntry
  2227. ("CMAKE_BACKWARDS_COMPATIBILITY",ver,
  2228. "For backwards compatibility, what version of CMake commands and "
  2229. "syntax should this version of CMake allow.",
  2230. cmCacheManager::STRING);
  2231. }
  2232. return 0;
  2233. }
  2234. void cmake::SetProgressCallback(ProgressCallbackType f, void *cd)
  2235. {
  2236. this->ProgressCallback = f;
  2237. this->ProgressCallbackClientData = cd;
  2238. }
  2239. void cmake::UpdateProgress(const char *msg, float prog)
  2240. {
  2241. if(this->ProgressCallback && !this->InTryCompile)
  2242. {
  2243. (*this->ProgressCallback)(msg, prog, this->ProgressCallbackClientData);
  2244. return;
  2245. }
  2246. }
  2247. void cmake::GetCommandDocumentation(std::vector<cmDocumentationEntry>& v,
  2248. bool withCurrentCommands,
  2249. bool withCompatCommands) const
  2250. {
  2251. for(RegisteredCommandsMap::const_iterator j = this->Commands.begin();
  2252. j != this->Commands.end(); ++j)
  2253. {
  2254. if ((( withCompatCommands == false) && ( (*j).second->IsDiscouraged()))
  2255. || ((withCurrentCommands == false) && (!(*j).second->IsDiscouraged())))
  2256. {
  2257. continue;
  2258. }
  2259. cmDocumentationEntry e((*j).second->GetName(),
  2260. (*j).second->GetTerseDocumentation(),
  2261. (*j).second->GetFullDocumentation());
  2262. v.push_back(e);
  2263. }
  2264. }
  2265. void cmake::GetPropertiesDocumentation(std::map<std::string,
  2266. cmDocumentationSection *>& v)
  2267. {
  2268. // loop over the properties and put them into the doc structure
  2269. std::map<cmProperty::ScopeType, cmPropertyDefinitionMap>::iterator i;
  2270. i = this->PropertyDefinitions.begin();
  2271. for (;i != this->PropertyDefinitions.end(); ++i)
  2272. {
  2273. i->second.GetPropertiesDocumentation(v);
  2274. }
  2275. }
  2276. void cmake::GetGeneratorDocumentation(std::vector<cmDocumentationEntry>& v)
  2277. {
  2278. for(RegisteredGeneratorsMap::const_iterator i = this->Generators.begin();
  2279. i != this->Generators.end(); ++i)
  2280. {
  2281. cmDocumentationEntry e;
  2282. cmGlobalGenerator* generator = (i->second)();
  2283. generator->GetDocumentation(e);
  2284. delete generator;
  2285. v.push_back(e);
  2286. }
  2287. for(RegisteredExtraGeneratorsMap::const_iterator
  2288. i = this->ExtraGenerators.begin(); i != this->ExtraGenerators.end(); ++i)
  2289. {
  2290. cmDocumentationEntry e;
  2291. cmExternalMakefileProjectGenerator* generator = (i->second)();
  2292. generator->GetDocumentation(e, i->first.c_str());
  2293. e.Name = i->first;
  2294. delete generator;
  2295. v.push_back(e);
  2296. }
  2297. }
  2298. void cmake::AddWrittenFile(const char* file)
  2299. {
  2300. this->WrittenFiles.insert(file);
  2301. }
  2302. bool cmake::HasWrittenFile(const char* file)
  2303. {
  2304. return this->WrittenFiles.find(file) != this->WrittenFiles.end();
  2305. }
  2306. void cmake::CleanupWrittenFiles()
  2307. {
  2308. this->WrittenFiles.clear();
  2309. }
  2310. void cmake::UpdateConversionPathTable()
  2311. {
  2312. // Update the path conversion table with any specified file:
  2313. const char* tablepath =
  2314. this->CacheManager->GetCacheValue("CMAKE_PATH_TRANSLATION_FILE");
  2315. if(tablepath)
  2316. {
  2317. std::ifstream table( tablepath );
  2318. if(!table)
  2319. {
  2320. cmSystemTools::Error("CMAKE_PATH_TRANSLATION_FILE set to ", tablepath,
  2321. ". CMake can not open file.");
  2322. cmSystemTools::ReportLastSystemError("CMake can not open file.");
  2323. }
  2324. else
  2325. {
  2326. std::string a, b;
  2327. while(!table.eof())
  2328. {
  2329. // two entries per line
  2330. table >> a; table >> b;
  2331. cmSystemTools::AddTranslationPath( a.c_str(), b.c_str());
  2332. }
  2333. }
  2334. }
  2335. }
  2336. //----------------------------------------------------------------------------
  2337. int cmake::CheckBuildSystem()
  2338. {
  2339. // We do not need to rerun CMake. Check dependency integrity. Use
  2340. // the make system's VERBOSE environment variable to enable verbose
  2341. // output.
  2342. bool verbose = cmSystemTools::GetEnv("VERBOSE") != 0;
  2343. // This method will check the integrity of the build system if the
  2344. // option was given on the command line. It reads the given file to
  2345. // determine whether CMake should rerun.
  2346. // If no file is provided for the check, we have to rerun.
  2347. if(this->CheckBuildSystemArgument.size() == 0)
  2348. {
  2349. if(verbose)
  2350. {
  2351. cmOStringStream msg;
  2352. msg << "Re-run cmake no build system arguments\n";
  2353. cmSystemTools::Stdout(msg.str().c_str());
  2354. }
  2355. return 1;
  2356. }
  2357. // If the file provided does not exist, we have to rerun.
  2358. if(!cmSystemTools::FileExists(this->CheckBuildSystemArgument.c_str()))
  2359. {
  2360. if(verbose)
  2361. {
  2362. cmOStringStream msg;
  2363. msg << "Re-run cmake missing file: "
  2364. << this->CheckBuildSystemArgument.c_str() << "\n";
  2365. cmSystemTools::Stdout(msg.str().c_str());
  2366. }
  2367. return 1;
  2368. }
  2369. // Read the rerun check file and use it to decide whether to do the
  2370. // global generate.
  2371. cmake cm;
  2372. cmGlobalGenerator gg;
  2373. gg.SetCMakeInstance(&cm);
  2374. std::auto_ptr<cmLocalGenerator> lg(gg.CreateLocalGenerator());
  2375. lg->SetGlobalGenerator(&gg);
  2376. cmMakefile* mf = lg->GetMakefile();
  2377. if(!mf->ReadListFile(0, this->CheckBuildSystemArgument.c_str()) ||
  2378. cmSystemTools::GetErrorOccuredFlag())
  2379. {
  2380. if(verbose)
  2381. {
  2382. cmOStringStream msg;
  2383. msg << "Re-run cmake error reading : "
  2384. << this->CheckBuildSystemArgument.c_str() << "\n";
  2385. cmSystemTools::Stdout(msg.str().c_str());
  2386. }
  2387. // There was an error reading the file. Just rerun.
  2388. return 1;
  2389. }
  2390. // Now that we know the generator used to build the project, use it
  2391. // to check the dependency integrity.
  2392. const char* genName = mf->GetDefinition("CMAKE_DEPENDS_GENERATOR");
  2393. if (!genName || genName[0] == '\0')
  2394. {
  2395. genName = "Unix Makefiles";
  2396. }
  2397. // this global generator is never set to the cmake object so it is never
  2398. // deleted, so make it an auto_ptr
  2399. std::auto_ptr<cmGlobalGenerator> ggd(this->CreateGlobalGenerator(genName));
  2400. if (ggd.get())
  2401. {
  2402. // Check the dependencies in case source files were removed.
  2403. std::auto_ptr<cmLocalGenerator> lgd(ggd->CreateLocalGenerator());
  2404. lgd->SetGlobalGenerator(ggd.get());
  2405. lgd->CheckDependencies(mf, verbose, this->ClearBuildSystem);
  2406. // Check for multiple output pairs.
  2407. ggd->CheckMultipleOutputs(mf, verbose);
  2408. }
  2409. // Get the set of dependencies and outputs.
  2410. const char* dependsStr = mf->GetDefinition("CMAKE_MAKEFILE_DEPENDS");
  2411. const char* outputsStr = mf->GetDefinition("CMAKE_MAKEFILE_OUTPUTS");
  2412. if(!dependsStr || !outputsStr)
  2413. {
  2414. // Not enough information was provided to do the test. Just rerun.
  2415. if(verbose)
  2416. {
  2417. cmOStringStream msg;
  2418. msg << "Re-run cmake no CMAKE_MAKEFILE_DEPENDS "
  2419. "or CMAKE_MAKEFILE_OUTPUTS :\n";
  2420. cmSystemTools::Stdout(msg.str().c_str());
  2421. }
  2422. return 1;
  2423. }
  2424. std::vector<std::string> depends;
  2425. std::vector<std::string> outputs;
  2426. cmSystemTools::ExpandListArgument(dependsStr, depends);
  2427. cmSystemTools::ExpandListArgument(outputsStr, outputs);
  2428. // If any output is older than any dependency then rerun.
  2429. for(std::vector<std::string>::iterator dep = depends.begin();
  2430. dep != depends.end(); ++dep)
  2431. {
  2432. for(std::vector<std::string>::iterator out = outputs.begin();
  2433. out != outputs.end(); ++out)
  2434. {
  2435. int result = 0;
  2436. if(!this->FileComparison->FileTimeCompare(out->c_str(),
  2437. dep->c_str(), &result) ||
  2438. result < 0)
  2439. {
  2440. if(verbose)
  2441. {
  2442. cmOStringStream msg;
  2443. msg << "Re-run cmake file: " << out->c_str()
  2444. << " older than: " << dep->c_str() << "\n";
  2445. cmSystemTools::Stdout(msg.str().c_str());
  2446. }
  2447. return 1;
  2448. }
  2449. }
  2450. }
  2451. // No need to rerun.
  2452. return 0;
  2453. }
  2454. //----------------------------------------------------------------------------
  2455. void cmake::TruncateOutputLog(const char* fname)
  2456. {
  2457. std::string fullPath = this->GetHomeOutputDirectory();
  2458. fullPath += "/";
  2459. fullPath += fname;
  2460. struct stat st;
  2461. if ( ::stat(fullPath.c_str(), &st) )
  2462. {
  2463. return;
  2464. }
  2465. if ( !this->CacheManager->GetCacheValue("CMAKE_CACHEFILE_DIR") )
  2466. {
  2467. cmSystemTools::RemoveFile(fullPath.c_str());
  2468. return;
  2469. }
  2470. off_t fsize = st.st_size;
  2471. const off_t maxFileSize = 50 * 1024;
  2472. if ( fsize < maxFileSize )
  2473. {
  2474. //TODO: truncate file
  2475. return;
  2476. }
  2477. }
  2478. inline std::string removeQuotes(const std::string& s)
  2479. {
  2480. if(s[0] == '\"' && s[s.size()-1] == '\"')
  2481. {
  2482. return s.substr(1, s.size()-2);
  2483. }
  2484. return s;
  2485. }
  2486. std::string cmake::FindCMakeProgram(const char* name) const
  2487. {
  2488. std::string path;
  2489. if ((name) && (*name))
  2490. {
  2491. const cmMakefile* mf
  2492. = this->GetGlobalGenerator()->GetLocalGenerators()[0]->GetMakefile();
  2493. #ifdef CMAKE_BUILD_WITH_CMAKE
  2494. path = mf->GetRequiredDefinition("CMAKE_COMMAND");
  2495. path = removeQuotes(path);
  2496. path = cmSystemTools::GetFilenamePath(path.c_str());
  2497. path += "/";
  2498. path += name;
  2499. path += cmSystemTools::GetExecutableExtension();
  2500. if(!cmSystemTools::FileExists(path.c_str()))
  2501. {
  2502. path = mf->GetRequiredDefinition("CMAKE_COMMAND");
  2503. path = cmSystemTools::GetFilenamePath(path.c_str());
  2504. path += "/Debug/";
  2505. path += name;
  2506. path += cmSystemTools::GetExecutableExtension();
  2507. }
  2508. if(!cmSystemTools::FileExists(path.c_str()))
  2509. {
  2510. path = mf->GetRequiredDefinition("CMAKE_COMMAND");
  2511. path = cmSystemTools::GetFilenamePath(path.c_str());
  2512. path += "/Release/";
  2513. path += name;
  2514. path += cmSystemTools::GetExecutableExtension();
  2515. }
  2516. #else
  2517. // Only for bootstrap
  2518. path += mf->GetSafeDefinition("EXECUTABLE_OUTPUT_PATH");
  2519. path += "/";
  2520. path += name;
  2521. path += cmSystemTools::GetExecutableExtension();
  2522. #endif
  2523. }
  2524. return path;
  2525. }
  2526. const char* cmake::GetCTestCommand()
  2527. {
  2528. if ( this->CTestCommand.empty() )
  2529. {
  2530. this->CTestCommand = this->FindCMakeProgram("ctest");
  2531. }
  2532. if ( this->CTestCommand.empty() )
  2533. {
  2534. cmSystemTools::Error("Cannot find the CTest executable");
  2535. this->CTestCommand = "CTEST-COMMAND-NOT-FOUND";
  2536. }
  2537. return this->CTestCommand.c_str();
  2538. }
  2539. const char* cmake::GetCPackCommand()
  2540. {
  2541. if ( this->CPackCommand.empty() )
  2542. {
  2543. this->CPackCommand = this->FindCMakeProgram("cpack");
  2544. }
  2545. if ( this->CPackCommand.empty() )
  2546. {
  2547. cmSystemTools::Error("Cannot find the CPack executable");
  2548. this->CPackCommand = "CPACK-COMMAND-NOT-FOUND";
  2549. }
  2550. return this->CPackCommand.c_str();
  2551. }
  2552. void cmake::GenerateGraphViz(const char* fileName) const
  2553. {
  2554. cmGeneratedFileStream str(fileName);
  2555. if ( !str )
  2556. {
  2557. return;
  2558. }
  2559. cmake cm;
  2560. cmGlobalGenerator ggi;
  2561. ggi.SetCMakeInstance(&cm);
  2562. std::auto_ptr<cmLocalGenerator> lg(ggi.CreateLocalGenerator());
  2563. lg->SetGlobalGenerator(&ggi);
  2564. cmMakefile *mf = lg->GetMakefile();
  2565. std::string infile = this->GetHomeOutputDirectory();
  2566. infile += "/CMakeGraphVizOptions.cmake";
  2567. if ( !cmSystemTools::FileExists(infile.c_str()) )
  2568. {
  2569. infile = this->GetHomeDirectory();
  2570. infile += "/CMakeGraphVizOptions.cmake";
  2571. if ( !cmSystemTools::FileExists(infile.c_str()) )
  2572. {
  2573. infile = "";
  2574. }
  2575. }
  2576. if ( !infile.empty() )
  2577. {
  2578. if ( !mf->ReadListFile(0, infile.c_str()) )
  2579. {
  2580. cmSystemTools::Error("Problem opening GraphViz options file: ",
  2581. infile.c_str());
  2582. return;
  2583. }
  2584. std::cout << "Read GraphViz options file: " << infile.c_str()
  2585. << std::endl;
  2586. }
  2587. #define __set_if_not_set(var, value, cmakeDefinition) \
  2588. const char* var = mf->GetDefinition(cmakeDefinition); \
  2589. if ( !var ) \
  2590. { \
  2591. var = value; \
  2592. }
  2593. __set_if_not_set(graphType, "digraph", "GRAPHVIZ_GRAPH_TYPE");
  2594. __set_if_not_set(graphName, "GG", "GRAPHVIZ_GRAPH_NAME");
  2595. __set_if_not_set(graphHeader, "node [\n fontsize = \"12\"\n];",
  2596. "GRAPHVIZ_GRAPH_HEADER");
  2597. __set_if_not_set(graphNodePrefix, "node", "GRAPHVIZ_NODE_PREFIX");
  2598. const char* ignoreTargets = mf->GetDefinition("GRAPHVIZ_IGNORE_TARGETS");
  2599. std::set<cmStdString> ignoreTargetsSet;
  2600. if ( ignoreTargets )
  2601. {
  2602. std::vector<std::string> ignoreTargetsVector;
  2603. cmSystemTools::ExpandListArgument(ignoreTargets,ignoreTargetsVector);
  2604. std::vector<std::string>::iterator itvIt;
  2605. for ( itvIt = ignoreTargetsVector.begin();
  2606. itvIt != ignoreTargetsVector.end();
  2607. ++ itvIt )
  2608. {
  2609. ignoreTargetsSet.insert(itvIt->c_str());
  2610. }
  2611. }
  2612. str << graphType << " " << graphName << " {" << std::endl;
  2613. str << graphHeader << std::endl;
  2614. const cmGlobalGenerator* gg = this->GetGlobalGenerator();
  2615. const std::vector<cmLocalGenerator*>& localGenerators =
  2616. gg->GetLocalGenerators();
  2617. std::vector<cmLocalGenerator*>::const_iterator lit;
  2618. // for target deps
  2619. // 1 - cmake target
  2620. // 2 - external target
  2621. // 0 - no deps
  2622. std::map<cmStdString, int> targetDeps;
  2623. std::map<cmStdString, const cmTarget*> targetPtrs;
  2624. std::map<cmStdString, cmStdString> targetNamesNodes;
  2625. int cnt = 0;
  2626. // First pass get the list of all cmake targets
  2627. for ( lit = localGenerators.begin(); lit != localGenerators.end(); ++ lit )
  2628. {
  2629. const cmTargets* targets = &((*lit)->GetMakefile()->GetTargets());
  2630. cmTargets::const_iterator tit;
  2631. for ( tit = targets->begin(); tit != targets->end(); ++ tit )
  2632. {
  2633. const char* realTargetName = tit->first.c_str();
  2634. if ( ignoreTargetsSet.find(realTargetName) != ignoreTargetsSet.end() )
  2635. {
  2636. // Skip ignored targets
  2637. continue;
  2638. }
  2639. //std::cout << "Found target: " << tit->first.c_str() << std::endl;
  2640. cmOStringStream ostr;
  2641. ostr << graphNodePrefix << cnt++;
  2642. targetNamesNodes[realTargetName] = ostr.str();
  2643. targetPtrs[realTargetName] = &tit->second;
  2644. }
  2645. }
  2646. // Ok, now find all the stuff we link to that is not in cmake
  2647. for ( lit = localGenerators.begin(); lit != localGenerators.end(); ++ lit )
  2648. {
  2649. const cmTargets* targets = &((*lit)->GetMakefile()->GetTargets());
  2650. cmTargets::const_iterator tit;
  2651. for ( tit = targets->begin(); tit != targets->end(); ++ tit )
  2652. {
  2653. const cmTarget::LinkLibraryVectorType* ll
  2654. = &(tit->second.GetOriginalLinkLibraries());
  2655. cmTarget::LinkLibraryVectorType::const_iterator llit;
  2656. const char* realTargetName = tit->first.c_str();
  2657. if ( ignoreTargetsSet.find(realTargetName) != ignoreTargetsSet.end() )
  2658. {
  2659. // Skip ignored targets
  2660. continue;
  2661. }
  2662. if ( ll->size() > 0 )
  2663. {
  2664. targetDeps[realTargetName] = 1;
  2665. }
  2666. for ( llit = ll->begin(); llit != ll->end(); ++ llit )
  2667. {
  2668. const char* libName = llit->first.c_str();
  2669. std::map<cmStdString, cmStdString>::const_iterator tarIt
  2670. = targetNamesNodes.find(libName);
  2671. if ( ignoreTargetsSet.find(libName) != ignoreTargetsSet.end() )
  2672. {
  2673. // Skip ignored targets
  2674. continue;
  2675. }
  2676. if ( tarIt == targetNamesNodes.end() )
  2677. {
  2678. cmOStringStream ostr;
  2679. ostr << graphNodePrefix << cnt++;
  2680. targetDeps[libName] = 2;
  2681. targetNamesNodes[libName] = ostr.str();
  2682. //str << " \"" << ostr.c_str() << "\" [ label=\"" << libName
  2683. //<< "\" shape=\"ellipse\"];" << std::endl;
  2684. }
  2685. else
  2686. {
  2687. std::map<cmStdString, int>::const_iterator depIt
  2688. = targetDeps.find(libName);
  2689. if ( depIt == targetDeps.end() )
  2690. {
  2691. targetDeps[libName] = 1;
  2692. }
  2693. }
  2694. }
  2695. }
  2696. }
  2697. // Write out nodes
  2698. std::map<cmStdString, int>::const_iterator depIt;
  2699. for ( depIt = targetDeps.begin(); depIt != targetDeps.end(); ++ depIt )
  2700. {
  2701. const char* newTargetName = depIt->first.c_str();
  2702. std::map<cmStdString, cmStdString>::const_iterator tarIt
  2703. = targetNamesNodes.find(newTargetName);
  2704. if ( tarIt == targetNamesNodes.end() )
  2705. {
  2706. // We should not be here.
  2707. std::cout << __LINE__ << " Cannot find library: " << newTargetName
  2708. << " even though it was added in the previous pass" << std::endl;
  2709. abort();
  2710. }
  2711. str << " \"" << tarIt->second.c_str() << "\" [ label=\""
  2712. << newTargetName << "\" shape=\"";
  2713. if ( depIt->second == 1 )
  2714. {
  2715. std::map<cmStdString, const cmTarget*>::const_iterator tarTypeIt =
  2716. targetPtrs.find(newTargetName);
  2717. if ( tarTypeIt == targetPtrs.end() )
  2718. {
  2719. // We should not be here.
  2720. std::cout << __LINE__ << " Cannot find library: " << newTargetName
  2721. << " even though it was added in the previous pass" << std::endl;
  2722. abort();
  2723. }
  2724. const cmTarget* tg = tarTypeIt->second;
  2725. switch ( tg->GetType() )
  2726. {
  2727. case cmTarget::EXECUTABLE:
  2728. str << "house";
  2729. break;
  2730. case cmTarget::STATIC_LIBRARY:
  2731. str << "diamond";
  2732. break;
  2733. case cmTarget::SHARED_LIBRARY:
  2734. str << "polygon";
  2735. break;
  2736. case cmTarget::MODULE_LIBRARY:
  2737. str << "octagon";
  2738. break;
  2739. default:
  2740. str << "box";
  2741. }
  2742. }
  2743. else
  2744. {
  2745. str << "ellipse";
  2746. }
  2747. str << "\"];" << std::endl;
  2748. }
  2749. // Now generate the connectivity
  2750. for ( lit = localGenerators.begin(); lit != localGenerators.end(); ++ lit )
  2751. {
  2752. const cmTargets* targets = &((*lit)->GetMakefile()->GetTargets());
  2753. cmTargets::const_iterator tit;
  2754. for ( tit = targets->begin(); tit != targets->end(); ++ tit )
  2755. {
  2756. std::map<cmStdString, int>::iterator dependIt
  2757. = targetDeps.find(tit->first.c_str());
  2758. if ( dependIt == targetDeps.end() )
  2759. {
  2760. continue;
  2761. }
  2762. std::map<cmStdString, cmStdString>::iterator cmakeTarIt
  2763. = targetNamesNodes.find(tit->first.c_str());
  2764. const cmTarget::LinkLibraryVectorType* ll
  2765. = &(tit->second.GetOriginalLinkLibraries());
  2766. cmTarget::LinkLibraryVectorType::const_iterator llit;
  2767. for ( llit = ll->begin(); llit != ll->end(); ++ llit )
  2768. {
  2769. const char* libName = llit->first.c_str();
  2770. std::map<cmStdString, cmStdString>::const_iterator tarIt
  2771. = targetNamesNodes.find(libName);
  2772. if ( tarIt == targetNamesNodes.end() )
  2773. {
  2774. // We should not be here.
  2775. std::cout << __LINE__ << " Cannot find library: " << libName
  2776. << " even though it was added in the previous pass" << std::endl;
  2777. abort();
  2778. }
  2779. str << " \"" << cmakeTarIt->second.c_str() << "\" -> \""
  2780. << tarIt->second.c_str() << "\"" << std::endl;
  2781. }
  2782. }
  2783. }
  2784. // TODO: Use dotted or something for external libraries
  2785. //str << " \"node0\":f4 -> \"node12\"[color=\"#0000ff\" style=dotted]"
  2786. //<< std::endl;
  2787. //
  2788. str << "}" << std::endl;
  2789. }
  2790. //----------------------------------------------------------------------------
  2791. #ifdef CMAKE_BUILD_WITH_CMAKE
  2792. int cmake::ExecuteEchoColor(std::vector<std::string>& args)
  2793. {
  2794. // The arguments are
  2795. // argv[0] == <cmake-executable>
  2796. // argv[1] == cmake_echo_color
  2797. // On some platforms (an MSYS prompt) cmsysTerminal may not be able
  2798. // to determine whether the stream is displayed on a tty. In this
  2799. // case it assumes no unless we tell it otherwise. Since we want
  2800. // color messages to be displayed for users we will assume yes.
  2801. // However, we can test for some situations when the answer is most
  2802. // likely no.
  2803. int assumeTTY = cmsysTerminal_Color_AssumeTTY;
  2804. if(cmSystemTools::GetEnv("DART_TEST_FROM_DART") ||
  2805. cmSystemTools::GetEnv("DASHBOARD_TEST_FROM_CTEST") ||
  2806. cmSystemTools::GetEnv("CTEST_INTERACTIVE_DEBUG_MODE"))
  2807. {
  2808. // Avoid printing color escapes during dashboard builds.
  2809. assumeTTY = 0;
  2810. }
  2811. bool enabled = true;
  2812. int color = cmsysTerminal_Color_Normal;
  2813. bool newline = true;
  2814. for(unsigned int i=2; i < args.size(); ++i)
  2815. {
  2816. if(args[i].find("--switch=") == 0)
  2817. {
  2818. // Enable or disable color based on the switch value.
  2819. std::string value = args[i].substr(9);
  2820. if(!value.empty())
  2821. {
  2822. if(cmSystemTools::IsOn(value.c_str()))
  2823. {
  2824. enabled = true;
  2825. }
  2826. else
  2827. {
  2828. enabled = false;
  2829. }
  2830. }
  2831. }
  2832. else if(args[i] == "--normal")
  2833. {
  2834. color = cmsysTerminal_Color_Normal;
  2835. }
  2836. else if(args[i] == "--black")
  2837. {
  2838. color = cmsysTerminal_Color_ForegroundBlack;
  2839. }
  2840. else if(args[i] == "--red")
  2841. {
  2842. color = cmsysTerminal_Color_ForegroundRed;
  2843. }
  2844. else if(args[i] == "--green")
  2845. {
  2846. color = cmsysTerminal_Color_ForegroundGreen;
  2847. }
  2848. else if(args[i] == "--yellow")
  2849. {
  2850. color = cmsysTerminal_Color_ForegroundYellow;
  2851. }
  2852. else if(args[i] == "--blue")
  2853. {
  2854. color = cmsysTerminal_Color_ForegroundBlue;
  2855. }
  2856. else if(args[i] == "--magenta")
  2857. {
  2858. color = cmsysTerminal_Color_ForegroundMagenta;
  2859. }
  2860. else if(args[i] == "--cyan")
  2861. {
  2862. color = cmsysTerminal_Color_ForegroundCyan;
  2863. }
  2864. else if(args[i] == "--white")
  2865. {
  2866. color = cmsysTerminal_Color_ForegroundWhite;
  2867. }
  2868. else if(args[i] == "--bold")
  2869. {
  2870. color |= cmsysTerminal_Color_ForegroundBold;
  2871. }
  2872. else if(args[i] == "--no-newline")
  2873. {
  2874. newline = false;
  2875. }
  2876. else if(args[i] == "--newline")
  2877. {
  2878. newline = true;
  2879. }
  2880. else if(enabled)
  2881. {
  2882. // Color is enabled. Print with the current color.
  2883. cmsysTerminal_cfprintf(color | assumeTTY, stdout, "%s%s",
  2884. args[i].c_str(), newline? "\n" : "");
  2885. }
  2886. else
  2887. {
  2888. // Color is disabled. Print without color.
  2889. fprintf(stdout, "%s%s", args[i].c_str(), newline? "\n" : "");
  2890. }
  2891. }
  2892. return 0;
  2893. }
  2894. #else
  2895. int cmake::ExecuteEchoColor(std::vector<std::string>&)
  2896. {
  2897. return 1;
  2898. }
  2899. #endif
  2900. //----------------------------------------------------------------------------
  2901. int cmake::ExecuteLinkScript(std::vector<std::string>& args)
  2902. {
  2903. // The arguments are
  2904. // argv[0] == <cmake-executable>
  2905. // argv[1] == cmake_link_script
  2906. // argv[2] == <link-script-name>
  2907. // argv[3] == --verbose=?
  2908. bool verbose = false;
  2909. if(args.size() >= 4)
  2910. {
  2911. if(args[3].find("--verbose=") == 0)
  2912. {
  2913. if(!cmSystemTools::IsOff(args[3].substr(10).c_str()))
  2914. {
  2915. verbose = true;
  2916. }
  2917. }
  2918. }
  2919. // Allocate a process instance.
  2920. cmsysProcess* cp = cmsysProcess_New();
  2921. if(!cp)
  2922. {
  2923. std::cerr << "Error allocating process instance in link script."
  2924. << std::endl;
  2925. return 1;
  2926. }
  2927. // Children should share stdout and stderr with this process.
  2928. cmsysProcess_SetPipeShared(cp, cmsysProcess_Pipe_STDOUT, 1);
  2929. cmsysProcess_SetPipeShared(cp, cmsysProcess_Pipe_STDERR, 1);
  2930. // Run the command lines verbatim.
  2931. cmsysProcess_SetOption(cp, cmsysProcess_Option_Verbatim, 1);
  2932. // Read command lines from the script.
  2933. std::ifstream fin(args[2].c_str());
  2934. if(!fin)
  2935. {
  2936. std::cerr << "Error opening link script \""
  2937. << args[2] << "\"" << std::endl;
  2938. return 1;
  2939. }
  2940. // Run one command at a time.
  2941. std::string command;
  2942. int result = 0;
  2943. while(result == 0 && cmSystemTools::GetLineFromStream(fin, command))
  2944. {
  2945. // Setup this command line.
  2946. const char* cmd[2] = {command.c_str(), 0};
  2947. cmsysProcess_SetCommand(cp, cmd);
  2948. // Report the command if verbose output is enabled.
  2949. if(verbose)
  2950. {
  2951. std::cout << command << std::endl;
  2952. }
  2953. // Run the command and wait for it to exit.
  2954. cmsysProcess_Execute(cp);
  2955. cmsysProcess_WaitForExit(cp, 0);
  2956. // Report failure if any.
  2957. switch(cmsysProcess_GetState(cp))
  2958. {
  2959. case cmsysProcess_State_Exited:
  2960. {
  2961. int value = cmsysProcess_GetExitValue(cp);
  2962. if(value != 0)
  2963. {
  2964. result = value;
  2965. }
  2966. }
  2967. break;
  2968. case cmsysProcess_State_Exception:
  2969. std::cerr << "Error running link command: "
  2970. << cmsysProcess_GetExceptionString(cp) << std::endl;
  2971. result = 1;
  2972. break;
  2973. case cmsysProcess_State_Error:
  2974. std::cerr << "Error running link command: "
  2975. << cmsysProcess_GetErrorString(cp) << std::endl;
  2976. result = 2;
  2977. break;
  2978. default:
  2979. break;
  2980. };
  2981. }
  2982. // Free the process instance.
  2983. cmsysProcess_Delete(cp);
  2984. // Return the final resulting return value.
  2985. return result;
  2986. }
  2987. void cmake::DefineProperties(cmake *cm)
  2988. {
  2989. cm->DefineProperty
  2990. ("REPORT_UNDEFINED_PROPERTIES", cmProperty::GLOBAL,
  2991. "If set, report any undefined properties to this file.",
  2992. "If this property is set to a filename then when CMake runs "
  2993. "it will report any properties or variables that were accessed "
  2994. "but not defined into the filename specified in this property."
  2995. );
  2996. cm->DefineProperty
  2997. ("TARGET_SUPPORTS_SHARED_LIBS", cmProperty::GLOBAL,
  2998. "Does the target platform support shared libraries.",
  2999. "TARGET_SUPPORTS_SHARED_LIBS is a boolean specifying whether the target "
  3000. "platform supports shared libraries. Basically all current general "
  3001. "general purpose OS do so, the exception are usually embedded systems "
  3002. "with no or special OSs.");
  3003. cm->DefineProperty
  3004. ("FIND_LIBRARY_USE_LIB64_PATHS", cmProperty::GLOBAL,
  3005. "Whether FIND_LIBRARY should automatically search lib64 directories.",
  3006. "FIND_LIBRARY_USE_LIB64_PATHS is a boolean specifying whether the "
  3007. "FIND_LIBRARY command should automatically search the lib64 variant of "
  3008. "directories called lib in the search path when building 64-bit "
  3009. "binaries.");
  3010. cm->DefineProperty
  3011. ("ENABLED_FEATURES", cmProperty::GLOBAL,
  3012. "List of features which are enabled during the CMake run.",
  3013. "List of features which are enabled during the CMake run. Be default "
  3014. "it contains the names of all packages which were found. This is "
  3015. "determined using the <NAME>_FOUND variables. Packages which are "
  3016. "searched QUIET are not listed. A project can add its own features to "
  3017. "this list.This property is used by the macros in FeatureSummary.cmake.");
  3018. cm->DefineProperty
  3019. ("DISABLED_FEATURES", cmProperty::GLOBAL,
  3020. "List of features which are disabled during the CMake run.",
  3021. "List of features which are disabled during the CMake run. Be default "
  3022. "it contains the names of all packages which were not found. This is "
  3023. "determined using the <NAME>_FOUND variables. Packages which are "
  3024. "searched QUIET are not listed. A project can add its own features to "
  3025. "this list.This property is used by the macros in FeatureSummary.cmake.");
  3026. cm->DefineProperty
  3027. ("PACKAGES_FOUND", cmProperty::GLOBAL,
  3028. "List of packages which were found during the CMake run.",
  3029. "List of packages which were found during the CMake run. Whether a "
  3030. "package has been found is determined using the <NAME>_FOUND variables.");
  3031. cm->DefineProperty
  3032. ("PACKAGES_NOT_FOUND", cmProperty::GLOBAL,
  3033. "List of packages which were not found during the CMake run.",
  3034. "List of packages which were not found during the CMake run. Whether a "
  3035. "package has been found is determined using the <NAME>_FOUND variables.");
  3036. // ================================================================
  3037. // define variables as well
  3038. // ================================================================
  3039. cmDocumentVariables::DefineVariables(cm);
  3040. }
  3041. void cmake::DefineProperty(const char *name, cmProperty::ScopeType scope,
  3042. const char *ShortDescription,
  3043. const char *FullDescription,
  3044. bool chained, const char *docSection)
  3045. {
  3046. this->PropertyDefinitions[scope].DefineProperty(name,scope,ShortDescription,
  3047. FullDescription,
  3048. docSection,
  3049. chained);
  3050. }
  3051. cmPropertyDefinition *cmake
  3052. ::GetPropertyDefinition(const char *name,
  3053. cmProperty::ScopeType scope)
  3054. {
  3055. if (this->IsPropertyDefined(name,scope))
  3056. {
  3057. return &(this->PropertyDefinitions[scope][name]);
  3058. }
  3059. return 0;
  3060. }
  3061. void cmake::RecordPropertyAccess(const char *name,
  3062. cmProperty::ScopeType scope)
  3063. {
  3064. this->AccessedProperties.insert
  3065. (std::pair<cmStdString,cmProperty::ScopeType>(name,scope));
  3066. }
  3067. void cmake::ReportUndefinedPropertyAccesses(const char *filename)
  3068. {
  3069. FILE *progFile = fopen(filename,"w");
  3070. if (!progFile || !this->GlobalGenerator)
  3071. {
  3072. return;
  3073. }
  3074. // what are the enabled languages?
  3075. std::vector<std::string> enLangs;
  3076. this->GlobalGenerator->GetEnabledLanguages(enLangs);
  3077. // take all the defined properties and add definitions for all the enabled
  3078. // languages
  3079. std::set<std::pair<cmStdString,cmProperty::ScopeType> > aliasedProperties;
  3080. std::map<cmProperty::ScopeType, cmPropertyDefinitionMap>::iterator i;
  3081. i = this->PropertyDefinitions.begin();
  3082. for (;i != this->PropertyDefinitions.end(); ++i)
  3083. {
  3084. cmPropertyDefinitionMap::iterator j;
  3085. for (j = i->second.begin(); j != i->second.end(); ++j)
  3086. {
  3087. if (j->first.find("<LANG>"))
  3088. {
  3089. std::vector<std::string>::const_iterator k;
  3090. for (k = enLangs.begin(); k != enLangs.end(); ++k)
  3091. {
  3092. std::string tmp = j->first;
  3093. cmSystemTools::ReplaceString(tmp, "<LANG>", k->c_str());
  3094. // add alias
  3095. aliasedProperties.insert
  3096. (std::pair<cmStdString,cmProperty::ScopeType>(tmp,i->first));
  3097. }
  3098. }
  3099. }
  3100. }
  3101. std::set<std::pair<cmStdString,cmProperty::ScopeType> >::const_iterator ap;
  3102. ap = this->AccessedProperties.begin();
  3103. for (;ap != this->AccessedProperties.end(); ++ap)
  3104. {
  3105. if (!this->IsPropertyDefined(ap->first.c_str(),ap->second) &&
  3106. aliasedProperties.find(std::pair<cmStdString,cmProperty::ScopeType>
  3107. (ap->first,ap->second)) ==
  3108. aliasedProperties.end())
  3109. {
  3110. const char *scopeStr = "";
  3111. switch (ap->second)
  3112. {
  3113. case cmProperty::TARGET:
  3114. scopeStr = "TARGET";
  3115. break;
  3116. case cmProperty::SOURCE_FILE:
  3117. scopeStr = "SOURCE_FILE";
  3118. break;
  3119. case cmProperty::DIRECTORY:
  3120. scopeStr = "DIRECTORY";
  3121. break;
  3122. case cmProperty::TEST:
  3123. scopeStr = "TEST";
  3124. break;
  3125. case cmProperty::VARIABLE:
  3126. scopeStr = "VARIABLE";
  3127. break;
  3128. case cmProperty::CACHED_VARIABLE:
  3129. scopeStr = "CACHED_VARIABLE";
  3130. break;
  3131. default:
  3132. scopeStr = "unknown";
  3133. break;
  3134. }
  3135. fprintf(progFile,"%s with scope %s\n",ap->first.c_str(),scopeStr);
  3136. }
  3137. }
  3138. fclose(progFile);
  3139. }
  3140. bool cmake::IsPropertyDefined(const char *name, cmProperty::ScopeType scope)
  3141. {
  3142. return this->PropertyDefinitions[scope].IsPropertyDefined(name);
  3143. }
  3144. bool cmake::IsPropertyChained(const char *name, cmProperty::ScopeType scope)
  3145. {
  3146. return this->PropertyDefinitions[scope].IsPropertyChained(name);
  3147. }
  3148. void cmake::SetProperty(const char* prop, const char* value)
  3149. {
  3150. if (!prop)
  3151. {
  3152. return;
  3153. }
  3154. if (!value)
  3155. {
  3156. value = "NOTFOUND";
  3157. }
  3158. this->Properties.SetProperty(prop, value, cmProperty::GLOBAL);
  3159. }
  3160. const char *cmake::GetProperty(const char* prop)
  3161. {
  3162. return this->GetProperty(prop, cmProperty::GLOBAL);
  3163. }
  3164. const char *cmake::GetProperty(const char* prop, cmProperty::ScopeType scope)
  3165. {
  3166. bool chain = false;
  3167. // watch for special properties
  3168. std::string propname = prop;
  3169. std::string output = "";
  3170. if ( propname == "CACHE_VARIABLES" )
  3171. {
  3172. cmCacheManager::CacheIterator cit =
  3173. this->GetCacheManager()->GetCacheIterator();
  3174. for ( cit.Begin(); !cit.IsAtEnd(); cit.Next() )
  3175. {
  3176. if ( output.size() )
  3177. {
  3178. output += ";";
  3179. }
  3180. output += cit.GetName();
  3181. }
  3182. this->SetProperty("CACHE_VARIABLES", output.c_str());
  3183. }
  3184. else if ( propname == "COMMANDS" )
  3185. {
  3186. cmake::RegisteredCommandsMap::iterator cmds
  3187. = this->GetCommands()->begin();
  3188. for (unsigned int cc=0 ; cmds != this->GetCommands()->end(); ++ cmds )
  3189. {
  3190. if ( cc > 0 )
  3191. {
  3192. output += ";";
  3193. }
  3194. output += cmds->first.c_str();
  3195. cc++;
  3196. }
  3197. this->SetProperty("COMMANDS",output.c_str());
  3198. }
  3199. return this->Properties.GetPropertyValue(prop, scope, chain);
  3200. }
  3201. bool cmake::GetPropertyAsBool(const char* prop)
  3202. {
  3203. return cmSystemTools::IsOn(this->GetProperty(prop));
  3204. }
  3205. int cmake::GetSystemInformation(std::vector<std::string>& args)
  3206. {
  3207. // so create the directory
  3208. std::string resultFile;
  3209. std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
  3210. std::string destPath = cwd + "/__cmake_systeminformation";
  3211. cmSystemTools::RemoveADirectory(destPath.c_str());
  3212. if (!cmSystemTools::MakeDirectory(destPath.c_str()))
  3213. {
  3214. std::cerr << "Error: --system-information must be run from a "
  3215. "writable directory!\n";
  3216. return 1;
  3217. }
  3218. // process the arguments
  3219. bool writeToStdout = true;
  3220. for(unsigned int i=1; i < args.size(); ++i)
  3221. {
  3222. std::string arg = args[i];
  3223. if(arg.find("-V",0) == 0)
  3224. {
  3225. this->Verbose = true;
  3226. }
  3227. else if(arg.find("-G",0) == 0)
  3228. {
  3229. std::string value = arg.substr(2);
  3230. if(value.size() == 0)
  3231. {
  3232. ++i;
  3233. if(i >= args.size())
  3234. {
  3235. cmSystemTools::Error("No generator specified for -G");
  3236. return -1;
  3237. }
  3238. value = args[i];
  3239. }
  3240. cmGlobalGenerator* gen =
  3241. this->CreateGlobalGenerator(value.c_str());
  3242. if(!gen)
  3243. {
  3244. cmSystemTools::Error("Could not create named generator ",
  3245. value.c_str());
  3246. }
  3247. else
  3248. {
  3249. this->SetGlobalGenerator(gen);
  3250. }
  3251. }
  3252. // no option assume it is the output file
  3253. else
  3254. {
  3255. if (!cmSystemTools::FileIsFullPath(arg.c_str()))
  3256. {
  3257. resultFile = cwd;
  3258. resultFile += "/";
  3259. }
  3260. resultFile += arg;
  3261. writeToStdout = false;
  3262. }
  3263. }
  3264. // we have to find the module directory, so we can copy the files
  3265. this->AddCMakePaths(args[0].c_str());
  3266. std::string modulesPath =
  3267. this->CacheManager->GetCacheValue("CMAKE_ROOT");
  3268. modulesPath += "/Modules";
  3269. std::string inFile = modulesPath;
  3270. inFile += "/SystemInformation.cmake";
  3271. std::string outFile = destPath;
  3272. outFile += "/CMakeLists.txt";
  3273. // Copy file
  3274. if(!cmSystemTools::cmCopyFile(inFile.c_str(), outFile.c_str()))
  3275. {
  3276. std::cerr << "Error copying file \"" << inFile.c_str()
  3277. << "\" to \"" << outFile.c_str() << "\".\n";
  3278. return 1;
  3279. }
  3280. // do we write to a file or to stdout?
  3281. if (resultFile.size() == 0)
  3282. {
  3283. resultFile = cwd;
  3284. resultFile += "/__cmake_systeminformation/results.txt";
  3285. }
  3286. // now run cmake on the CMakeLists file
  3287. cmSystemTools::ChangeDirectory(destPath.c_str());
  3288. std::vector<std::string> args2;
  3289. args2.push_back(args[0]);
  3290. args2.push_back(destPath);
  3291. std::string resultArg = "-DRESULT_FILE=";
  3292. resultArg += resultFile;
  3293. args2.push_back(resultArg);
  3294. int res = this->Run(args2, false);
  3295. if (res != 0)
  3296. {
  3297. std::cerr << "Error: --system-information failed on internal CMake!\n";
  3298. return res;
  3299. }
  3300. // change back to the original directory
  3301. cmSystemTools::ChangeDirectory(cwd.c_str());
  3302. // echo results to stdout if needed
  3303. if (writeToStdout)
  3304. {
  3305. FILE* fin = fopen(resultFile.c_str(), "r");
  3306. if(fin)
  3307. {
  3308. const int bufferSize = 4096;
  3309. char buffer[bufferSize];
  3310. size_t n;
  3311. while((n = fread(buffer, 1, bufferSize, fin)) > 0)
  3312. {
  3313. for(char* c = buffer; c < buffer+n; ++c)
  3314. {
  3315. putc(*c, stdout);
  3316. }
  3317. fflush(stdout);
  3318. }
  3319. fclose(fin);
  3320. }
  3321. }
  3322. // clean up the directory
  3323. cmSystemTools::RemoveADirectory(destPath.c_str());
  3324. return 0;
  3325. }
  3326. //----------------------------------------------------------------------------
  3327. static bool cmakeCheckStampFile(const char* stampName)
  3328. {
  3329. // If the stamp file still exists then it must really be out of
  3330. // date.
  3331. if(cmSystemTools::FileExists(stampName))
  3332. {
  3333. return false;
  3334. }
  3335. // The stamp file does not exist. Use the stamp dependencies to
  3336. // determine whether it is really out of date. This works in
  3337. // conjunction with cmLocalVisualStudio7Generator to avoid
  3338. // repeatedly re-running CMake when the user rebuilds the entire
  3339. // solution.
  3340. std::string stampDepends = stampName;
  3341. stampDepends += ".depend";
  3342. #if defined(_WIN32) || defined(__CYGWIN__)
  3343. std::ifstream fin(stampDepends.c_str(), std::ios::in | std::ios::binary);
  3344. #else
  3345. std::ifstream fin(stampDepends.c_str(), std::ios::in);
  3346. #endif
  3347. if(!fin)
  3348. {
  3349. // The stamp dependencies file cannot be read. Just assume the
  3350. // build system is really out of date.
  3351. return false;
  3352. }
  3353. // Compare the stamp dependencies against the dependency file itself.
  3354. cmFileTimeComparison ftc;
  3355. std::string dep;
  3356. while(cmSystemTools::GetLineFromStream(fin, dep))
  3357. {
  3358. int result;
  3359. if(dep.length() >= 1 && dep[0] != '#' &&
  3360. (!ftc.FileTimeCompare(stampDepends.c_str(), dep.c_str(), &result)
  3361. || result < 0))
  3362. {
  3363. // The stamp depends file is older than this dependency. The
  3364. // build system is really out of date.
  3365. return false;
  3366. }
  3367. }
  3368. // The build system is up to date. The stamp file has been removed
  3369. // by the VS IDE due to a "rebuild" request. Just restore it.
  3370. std::ofstream stamp(stampName);
  3371. stamp << "# CMake generation timestamp file this directory.\n";
  3372. if(stamp)
  3373. {
  3374. // Notify the user why CMake is not re-running. It is safe to
  3375. // just print to stdout here because this code is only reachable
  3376. // through an undocumented flag used by the VS generator.
  3377. std::cout << "CMake does not need to re-run because the "
  3378. << "generation timestamp is up-to-date.\n";
  3379. return true;
  3380. }
  3381. else
  3382. {
  3383. cmSystemTools::Error("Cannot restore timestamp ", stampName);
  3384. return false;
  3385. }
  3386. }