cmGlobalGenerator.cxx 96 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #if defined(_WIN32) && !defined(__CYGWIN__)
  11. #include "windows.h" // this must be first to define GetCurrentDirectory
  12. #endif
  13. #include "cmGlobalGenerator.h"
  14. #include "cmLocalGenerator.h"
  15. #include "cmExternalMakefileProjectGenerator.h"
  16. #include "cmake.h"
  17. #include "cmMakefile.h"
  18. #include "cmQtAutoGenerators.h"
  19. #include "cmSourceFile.h"
  20. #include "cmVersion.h"
  21. #include "cmTargetExport.h"
  22. #include "cmComputeTargetDepends.h"
  23. #include "cmGeneratedFileStream.h"
  24. #include "cmGeneratorTarget.h"
  25. #include "cmGeneratorExpression.h"
  26. #include "cmGeneratorExpressionEvaluationFile.h"
  27. #include "cmExportBuildFileGenerator.h"
  28. #include <cmsys/Directory.hxx>
  29. #include <cmsys/FStream.hxx>
  30. #if defined(CMAKE_BUILD_WITH_CMAKE)
  31. # include <cmsys/MD5.h>
  32. #endif
  33. #include <stdlib.h> // required for atof
  34. #include <assert.h>
  35. cmGlobalGenerator::cmGlobalGenerator()
  36. {
  37. // By default the .SYMBOLIC dependency is not needed on symbolic rules.
  38. this->NeedSymbolicMark = false;
  39. // by default use the native paths
  40. this->ForceUnixPaths = false;
  41. // By default do not try to support color.
  42. this->ToolSupportsColor = false;
  43. // By default do not use link scripts.
  44. this->UseLinkScript = false;
  45. // Whether an install target is needed.
  46. this->InstallTargetEnabled = false;
  47. // how long to let try compiles run
  48. this->TryCompileTimeout = 0;
  49. this->ExtraGenerator = 0;
  50. this->CurrentLocalGenerator = 0;
  51. this->TryCompileOuterMakefile = 0;
  52. }
  53. cmGlobalGenerator::~cmGlobalGenerator()
  54. {
  55. this->ClearGeneratorMembers();
  56. if (this->ExtraGenerator)
  57. {
  58. delete this->ExtraGenerator;
  59. }
  60. }
  61. bool cmGlobalGenerator::SetGeneratorToolset(std::string const& ts)
  62. {
  63. cmOStringStream e;
  64. e <<
  65. "Generator\n"
  66. " " << this->GetName() << "\n"
  67. "does not support toolset specification, but toolset\n"
  68. " " << ts << "\n"
  69. "was specified.";
  70. this->CMakeInstance->IssueMessage(cmake::FATAL_ERROR, e.str(),
  71. cmListFileBacktrace());
  72. return false;
  73. }
  74. std::string cmGlobalGenerator::SelectMakeProgram(
  75. const std::string& inMakeProgram,
  76. const std::string& makeDefault) const
  77. {
  78. std::string makeProgram = inMakeProgram;
  79. if(cmSystemTools::IsOff(makeProgram.c_str()))
  80. {
  81. const char* makeProgramCSTR =
  82. this->CMakeInstance->GetCacheDefinition("CMAKE_MAKE_PROGRAM");
  83. if(cmSystemTools::IsOff(makeProgramCSTR))
  84. {
  85. makeProgram = makeDefault;
  86. }
  87. else
  88. {
  89. makeProgram = makeProgramCSTR;
  90. }
  91. if(cmSystemTools::IsOff(makeProgram.c_str()) &&
  92. !makeProgram.empty())
  93. {
  94. makeProgram = "CMAKE_MAKE_PROGRAM-NOTFOUND";
  95. }
  96. }
  97. return makeProgram;
  98. }
  99. void cmGlobalGenerator::ResolveLanguageCompiler(const std::string &lang,
  100. cmMakefile *mf,
  101. bool optional) const
  102. {
  103. std::string langComp = "CMAKE_";
  104. langComp += lang;
  105. langComp += "_COMPILER";
  106. if(!mf->GetDefinition(langComp))
  107. {
  108. if(!optional)
  109. {
  110. cmSystemTools::Error(langComp.c_str(),
  111. " not set, after EnableLanguage");
  112. }
  113. return;
  114. }
  115. const char* name = mf->GetRequiredDefinition(langComp);
  116. std::string path;
  117. if(!cmSystemTools::FileIsFullPath(name))
  118. {
  119. path = cmSystemTools::FindProgram(name);
  120. }
  121. else
  122. {
  123. path = name;
  124. }
  125. if((path.size() == 0 || !cmSystemTools::FileExists(path.c_str()))
  126. && (optional==false))
  127. {
  128. return;
  129. }
  130. std::string doc = lang;
  131. doc += " compiler.";
  132. const char* cname = this->GetCMakeInstance()->
  133. GetCacheManager()->GetCacheValue(langComp);
  134. std::string changeVars;
  135. if(cname && !optional)
  136. {
  137. std::string cnameString;
  138. if(!cmSystemTools::FileIsFullPath(cname))
  139. {
  140. cnameString = cmSystemTools::FindProgram(cname);
  141. }
  142. else
  143. {
  144. cnameString = cname;
  145. }
  146. std::string pathString = path;
  147. // get rid of potentially multiple slashes:
  148. cmSystemTools::ConvertToUnixSlashes(cnameString);
  149. cmSystemTools::ConvertToUnixSlashes(pathString);
  150. if (cnameString != pathString)
  151. {
  152. const char* cvars =
  153. this->GetCMakeInstance()->GetProperty(
  154. "__CMAKE_DELETE_CACHE_CHANGE_VARS_");
  155. if(cvars)
  156. {
  157. changeVars += cvars;
  158. changeVars += ";";
  159. }
  160. changeVars += langComp;
  161. changeVars += ";";
  162. changeVars += cname;
  163. this->GetCMakeInstance()->SetProperty(
  164. "__CMAKE_DELETE_CACHE_CHANGE_VARS_",
  165. changeVars.c_str());
  166. }
  167. }
  168. mf->AddCacheDefinition(langComp, path.c_str(),
  169. doc.c_str(), cmCacheManager::FILEPATH);
  170. }
  171. void cmGlobalGenerator::AddBuildExportSet(cmExportBuildFileGenerator* gen)
  172. {
  173. this->BuildExportSets[gen->GetMainExportFileName()] = gen;
  174. }
  175. void
  176. cmGlobalGenerator::AddBuildExportExportSet(cmExportBuildFileGenerator* gen)
  177. {
  178. this->BuildExportSets[gen->GetMainExportFileName()] = gen;
  179. this->BuildExportExportSets[gen->GetMainExportFileName()] = gen;
  180. }
  181. bool cmGlobalGenerator::GenerateImportFile(const std::string &file)
  182. {
  183. std::map<std::string, cmExportBuildFileGenerator*>::iterator it
  184. = this->BuildExportSets.find(file);
  185. if (it != this->BuildExportSets.end())
  186. {
  187. bool result = it->second->GenerateImportFile();
  188. delete it->second;
  189. it->second = 0;
  190. this->BuildExportSets.erase(it);
  191. return result;
  192. }
  193. return false;
  194. }
  195. void cmGlobalGenerator::ForceLinkerLanguages()
  196. {
  197. }
  198. bool
  199. cmGlobalGenerator::IsExportedTargetsFile(const std::string &filename) const
  200. {
  201. const std::map<std::string, cmExportBuildFileGenerator*>::const_iterator it
  202. = this->BuildExportSets.find(filename);
  203. if (it == this->BuildExportSets.end())
  204. {
  205. return false;
  206. }
  207. return this->BuildExportExportSets.find(filename)
  208. == this->BuildExportExportSets.end();
  209. }
  210. // Find the make program for the generator, required for try compiles
  211. void cmGlobalGenerator::FindMakeProgram(cmMakefile* mf)
  212. {
  213. if(this->FindMakeProgramFile.size() == 0)
  214. {
  215. cmSystemTools::Error(
  216. "Generator implementation error, "
  217. "all generators must specify this->FindMakeProgramFile");
  218. }
  219. if(!mf->GetDefinition("CMAKE_MAKE_PROGRAM")
  220. || cmSystemTools::IsOff(mf->GetDefinition("CMAKE_MAKE_PROGRAM")))
  221. {
  222. std::string setMakeProgram =
  223. mf->GetModulesFile(this->FindMakeProgramFile.c_str());
  224. if(setMakeProgram.size())
  225. {
  226. mf->ReadListFile(0, setMakeProgram.c_str());
  227. }
  228. }
  229. if(!mf->GetDefinition("CMAKE_MAKE_PROGRAM")
  230. || cmSystemTools::IsOff(mf->GetDefinition("CMAKE_MAKE_PROGRAM")))
  231. {
  232. cmOStringStream err;
  233. err << "CMake was unable to find a build program corresponding to \""
  234. << this->GetName() << "\". CMAKE_MAKE_PROGRAM is not set. You "
  235. << "probably need to select a different build tool.";
  236. cmSystemTools::Error(err.str().c_str());
  237. cmSystemTools::SetFatalErrorOccured();
  238. return;
  239. }
  240. std::string makeProgram = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
  241. // if there are spaces in the make program use short path
  242. // but do not short path the actual program name, as
  243. // this can cause trouble with VSExpress
  244. if(makeProgram.find(' ') != makeProgram.npos)
  245. {
  246. std::string dir;
  247. std::string file;
  248. cmSystemTools::SplitProgramPath(makeProgram.c_str(),
  249. dir, file);
  250. std::string saveFile = file;
  251. cmSystemTools::GetShortPath(makeProgram.c_str(), makeProgram);
  252. cmSystemTools::SplitProgramPath(makeProgram.c_str(),
  253. dir, file);
  254. makeProgram = dir;
  255. makeProgram += "/";
  256. makeProgram += saveFile;
  257. mf->AddCacheDefinition("CMAKE_MAKE_PROGRAM", makeProgram.c_str(),
  258. "make program",
  259. cmCacheManager::FILEPATH);
  260. }
  261. if(makeProgram.find("xcodebuild") != makeProgram.npos)
  262. {
  263. // due to the text file busy /bin/sh problem with xcodebuild
  264. // use the cmakexbuild wrapper instead. This program
  265. // will run xcodebuild and if it sees the error text file busy
  266. // it will stop forwarding output, and let the build finish.
  267. // Then it will retry the build. It will continue this
  268. // untill no text file busy errors occur.
  269. std::string cmakexbuild =
  270. this->CMakeInstance->GetCacheManager()->GetCacheValue("CMAKE_COMMAND");
  271. cmakexbuild = cmakexbuild.substr(0, cmakexbuild.length()-5);
  272. cmakexbuild += "cmakexbuild";
  273. mf->AddCacheDefinition("CMAKE_MAKE_PROGRAM",
  274. cmakexbuild.c_str(),
  275. "make program",
  276. cmCacheManager::FILEPATH);
  277. }
  278. }
  279. // enable the given language
  280. //
  281. // The following files are loaded in this order:
  282. //
  283. // First figure out what OS we are running on:
  284. //
  285. // CMakeSystem.cmake - configured file created by CMakeDetermineSystem.cmake
  286. // CMakeDetermineSystem.cmake - figure out os info and create
  287. // CMakeSystem.cmake IF CMAKE_SYSTEM
  288. // not set
  289. // CMakeSystem.cmake - configured file created by
  290. // CMakeDetermineSystem.cmake IF CMAKE_SYSTEM_LOADED
  291. // Next try and enable all languages found in the languages vector
  292. //
  293. // FOREACH LANG in languages
  294. // CMake(LANG)Compiler.cmake - configured file create by
  295. // CMakeDetermine(LANG)Compiler.cmake
  296. // CMakeDetermine(LANG)Compiler.cmake - Finds compiler for LANG and
  297. // creates CMake(LANG)Compiler.cmake
  298. // CMake(LANG)Compiler.cmake - configured file created by
  299. // CMakeDetermine(LANG)Compiler.cmake
  300. //
  301. // CMakeSystemSpecificInformation.cmake
  302. // - includes Platform/${CMAKE_SYSTEM_NAME}.cmake
  303. // may use compiler stuff
  304. // FOREACH LANG in languages
  305. // CMake(LANG)Information.cmake
  306. // - loads Platform/${CMAKE_SYSTEM_NAME}-${COMPILER}.cmake
  307. // CMakeTest(LANG)Compiler.cmake
  308. // - Make sure the compiler works with a try compile if
  309. // CMakeDetermine(LANG) was loaded
  310. //
  311. // Now load a few files that can override values set in any of the above
  312. // (PROJECTNAME)Compatibility.cmake
  313. // - load any backwards compatibility stuff for current project
  314. // ${CMAKE_USER_MAKE_RULES_OVERRIDE}
  315. // - allow users a chance to override system variables
  316. //
  317. //
  318. void
  319. cmGlobalGenerator::EnableLanguage(std::vector<std::string>const& languages,
  320. cmMakefile *mf, bool optional)
  321. {
  322. if(languages.size() == 0)
  323. {
  324. cmSystemTools::Error("EnableLanguage must have a lang specified!");
  325. cmSystemTools::SetFatalErrorOccured();
  326. return;
  327. }
  328. if(this->TryCompileOuterMakefile)
  329. {
  330. // In a try-compile we can only enable languages provided by caller.
  331. for(std::vector<std::string>::const_iterator li = languages.begin();
  332. li != languages.end(); ++li)
  333. {
  334. if(*li == "NONE")
  335. {
  336. this->SetLanguageEnabled("NONE", mf);
  337. }
  338. else
  339. {
  340. const char* lang = li->c_str();
  341. if(this->LanguagesReady.find(lang) == this->LanguagesReady.end())
  342. {
  343. cmOStringStream e;
  344. e << "The test project needs language "
  345. << lang << " which is not enabled.";
  346. this->TryCompileOuterMakefile
  347. ->IssueMessage(cmake::FATAL_ERROR, e.str());
  348. cmSystemTools::SetFatalErrorOccured();
  349. return;
  350. }
  351. }
  352. }
  353. }
  354. bool fatalError = false;
  355. mf->AddDefinition("RUN_CONFIGURE", true);
  356. std::string rootBin = mf->GetHomeOutputDirectory();
  357. rootBin += cmake::GetCMakeFilesDirectory();
  358. // If the configuration files path has been set,
  359. // then we are in a try compile and need to copy the enable language
  360. // files from the parent cmake bin dir, into the try compile bin dir
  361. if(this->ConfiguredFilesPath.size())
  362. {
  363. rootBin = this->ConfiguredFilesPath;
  364. }
  365. rootBin += "/";
  366. rootBin += cmVersion::GetCMakeVersion();
  367. // set the dir for parent files so they can be used by modules
  368. mf->AddDefinition("CMAKE_PLATFORM_INFO_DIR",rootBin.c_str());
  369. // find and make sure CMAKE_MAKE_PROGRAM is defined
  370. this->FindMakeProgram(mf);
  371. // try and load the CMakeSystem.cmake if it is there
  372. std::string fpath = rootBin;
  373. if(!mf->GetDefinition("CMAKE_SYSTEM_LOADED"))
  374. {
  375. fpath += "/CMakeSystem.cmake";
  376. if(cmSystemTools::FileExists(fpath.c_str()))
  377. {
  378. mf->ReadListFile(0,fpath.c_str());
  379. }
  380. }
  381. // Load the CMakeDetermineSystem.cmake file and find out
  382. // what platform we are running on
  383. if (!mf->GetDefinition("CMAKE_SYSTEM"))
  384. {
  385. #if defined(_WIN32) && !defined(__CYGWIN__)
  386. /* Windows version number data. */
  387. OSVERSIONINFO osvi;
  388. ZeroMemory(&osvi, sizeof(osvi));
  389. osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  390. GetVersionEx (&osvi);
  391. cmOStringStream windowsVersionString;
  392. windowsVersionString << osvi.dwMajorVersion << "." << osvi.dwMinorVersion;
  393. windowsVersionString.str();
  394. mf->AddDefinition("CMAKE_HOST_SYSTEM_VERSION",
  395. windowsVersionString.str().c_str());
  396. #endif
  397. // Read the DetermineSystem file
  398. std::string systemFile = mf->GetModulesFile("CMakeDetermineSystem.cmake");
  399. mf->ReadListFile(0, systemFile.c_str());
  400. // load the CMakeSystem.cmake from the binary directory
  401. // this file is configured by the CMakeDetermineSystem.cmake file
  402. fpath = rootBin;
  403. fpath += "/CMakeSystem.cmake";
  404. mf->ReadListFile(0,fpath.c_str());
  405. }
  406. std::map<std::string, bool> needTestLanguage;
  407. std::map<std::string, bool> needSetLanguageEnabledMaps;
  408. // foreach language
  409. // load the CMakeDetermine(LANG)Compiler.cmake file to find
  410. // the compiler
  411. for(std::vector<std::string>::const_iterator l = languages.begin();
  412. l != languages.end(); ++l)
  413. {
  414. const char* lang = l->c_str();
  415. needSetLanguageEnabledMaps[lang] = false;
  416. if(*l == "NONE")
  417. {
  418. this->SetLanguageEnabled("NONE", mf);
  419. continue;
  420. }
  421. std::string loadedLang = "CMAKE_";
  422. loadedLang += lang;
  423. loadedLang += "_COMPILER_LOADED";
  424. if(!mf->GetDefinition(loadedLang))
  425. {
  426. fpath = rootBin;
  427. fpath += "/CMake";
  428. fpath += lang;
  429. fpath += "Compiler.cmake";
  430. // If the existing build tree was already configured with this
  431. // version of CMake then try to load the configured file first
  432. // to avoid duplicate compiler tests.
  433. if(cmSystemTools::FileExists(fpath.c_str()))
  434. {
  435. if(!mf->ReadListFile(0,fpath.c_str()))
  436. {
  437. cmSystemTools::Error("Could not find cmake module file: ",
  438. fpath.c_str());
  439. }
  440. // if this file was found then the language was already determined
  441. // to be working
  442. needTestLanguage[lang] = false;
  443. this->SetLanguageEnabledFlag(lang, mf);
  444. needSetLanguageEnabledMaps[lang] = true;
  445. // this can only be called after loading CMake(LANG)Compiler.cmake
  446. }
  447. }
  448. if(!this->GetLanguageEnabled(lang) )
  449. {
  450. if (this->CMakeInstance->GetIsInTryCompile())
  451. {
  452. cmSystemTools::Error("This should not have happened. "
  453. "If you see this message, you are probably "
  454. "using a broken CMakeLists.txt file or a "
  455. "problematic release of CMake");
  456. }
  457. // if the CMake(LANG)Compiler.cmake file was not found then
  458. // load CMakeDetermine(LANG)Compiler.cmake
  459. std::string determineCompiler = "CMakeDetermine";
  460. determineCompiler += lang;
  461. determineCompiler += "Compiler.cmake";
  462. std::string determineFile =
  463. mf->GetModulesFile(determineCompiler.c_str());
  464. if(!mf->ReadListFile(0,determineFile.c_str()))
  465. {
  466. cmSystemTools::Error("Could not find cmake module file: ",
  467. determineFile.c_str());
  468. }
  469. needTestLanguage[lang] = true;
  470. // Some generators like visual studio should not use the env variables
  471. // So the global generator can specify that in this variable
  472. if(!mf->GetDefinition("CMAKE_GENERATOR_NO_COMPILER_ENV"))
  473. {
  474. // put ${CMake_(LANG)_COMPILER_ENV_VAR}=${CMAKE_(LANG)_COMPILER
  475. // into the environment, in case user scripts want to run
  476. // configure, or sub cmakes
  477. std::string compilerName = "CMAKE_";
  478. compilerName += lang;
  479. compilerName += "_COMPILER";
  480. std::string compilerEnv = "CMAKE_";
  481. compilerEnv += lang;
  482. compilerEnv += "_COMPILER_ENV_VAR";
  483. std::string envVar = mf->GetRequiredDefinition(compilerEnv);
  484. std::string envVarValue =
  485. mf->GetRequiredDefinition(compilerName);
  486. std::string env = envVar;
  487. env += "=";
  488. env += envVarValue;
  489. cmSystemTools::PutEnv(env.c_str());
  490. }
  491. // if determineLanguage was called then load the file it
  492. // configures CMake(LANG)Compiler.cmake
  493. fpath = rootBin;
  494. fpath += "/CMake";
  495. fpath += lang;
  496. fpath += "Compiler.cmake";
  497. if(!mf->ReadListFile(0,fpath.c_str()))
  498. {
  499. cmSystemTools::Error("Could not find cmake module file: ",
  500. fpath.c_str());
  501. }
  502. this->SetLanguageEnabledFlag(lang, mf);
  503. needSetLanguageEnabledMaps[lang] = true;
  504. // this can only be called after loading CMake(LANG)Compiler.cmake
  505. // the language must be enabled for try compile to work, but we do
  506. // not know if it is a working compiler yet so set the test language
  507. // flag
  508. needTestLanguage[lang] = true;
  509. } // end if(!this->GetLanguageEnabled(lang) )
  510. } // end loop over languages
  511. // **** Load the system specific information if not yet loaded
  512. if (!mf->GetDefinition("CMAKE_SYSTEM_SPECIFIC_INFORMATION_LOADED"))
  513. {
  514. fpath = mf->GetModulesFile("CMakeSystemSpecificInformation.cmake");
  515. if(!mf->ReadListFile(0,fpath.c_str()))
  516. {
  517. cmSystemTools::Error("Could not find cmake module file: ",
  518. fpath.c_str());
  519. }
  520. }
  521. // loop over languages again loading CMake(LANG)Information.cmake
  522. //
  523. for(std::vector<std::string>::const_iterator l = languages.begin();
  524. l != languages.end(); ++l)
  525. {
  526. const char* lang = l->c_str();
  527. if(*l == "NONE")
  528. {
  529. this->SetLanguageEnabled("NONE", mf);
  530. continue;
  531. }
  532. // Check that the compiler was found.
  533. std::string compilerName = "CMAKE_";
  534. compilerName += lang;
  535. compilerName += "_COMPILER";
  536. std::string compilerEnv = "CMAKE_";
  537. compilerEnv += lang;
  538. compilerEnv += "_COMPILER_ENV_VAR";
  539. cmOStringStream noCompiler;
  540. const char* compilerFile = mf->GetDefinition(compilerName);
  541. if(!compilerFile || !*compilerFile ||
  542. cmSystemTools::IsNOTFOUND(compilerFile))
  543. {
  544. noCompiler <<
  545. "No " << compilerName << " could be found.\n"
  546. ;
  547. }
  548. else if(strcmp(lang, "RC") != 0)
  549. {
  550. if(!cmSystemTools::FileIsFullPath(compilerFile))
  551. {
  552. noCompiler <<
  553. "The " << compilerName << ":\n"
  554. " " << compilerFile << "\n"
  555. "is not a full path and was not found in the PATH.\n"
  556. ;
  557. }
  558. else if(!cmSystemTools::FileExists(compilerFile))
  559. {
  560. noCompiler <<
  561. "The " << compilerName << ":\n"
  562. " " << compilerFile << "\n"
  563. "is not a full path to an existing compiler tool.\n"
  564. ;
  565. }
  566. }
  567. if(!noCompiler.str().empty())
  568. {
  569. // Skip testing this language since the compiler is not found.
  570. needTestLanguage[lang] = false;
  571. if(!optional)
  572. {
  573. // The compiler was not found and it is not optional. Remove
  574. // CMake(LANG)Compiler.cmake so we try again next time CMake runs.
  575. std::string compilerLangFile = rootBin;
  576. compilerLangFile += "/CMake";
  577. compilerLangFile += lang;
  578. compilerLangFile += "Compiler.cmake";
  579. cmSystemTools::RemoveFile(compilerLangFile.c_str());
  580. if(!this->CMakeInstance->GetIsInTryCompile())
  581. {
  582. this->PrintCompilerAdvice(noCompiler, lang,
  583. mf->GetDefinition(compilerEnv));
  584. mf->IssueMessage(cmake::FATAL_ERROR, noCompiler.str());
  585. fatalError = true;
  586. }
  587. }
  588. }
  589. std::string langLoadedVar = "CMAKE_";
  590. langLoadedVar += lang;
  591. langLoadedVar += "_INFORMATION_LOADED";
  592. if (!mf->GetDefinition(langLoadedVar))
  593. {
  594. fpath = "CMake";
  595. fpath += lang;
  596. fpath += "Information.cmake";
  597. std::string informationFile = mf->GetModulesFile(fpath.c_str());
  598. if (informationFile.empty())
  599. {
  600. cmSystemTools::Error("Could not find cmake module file: ",
  601. fpath.c_str());
  602. }
  603. else if(!mf->ReadListFile(0, informationFile.c_str()))
  604. {
  605. cmSystemTools::Error("Could not process cmake module file: ",
  606. informationFile.c_str());
  607. }
  608. }
  609. if (needSetLanguageEnabledMaps[lang])
  610. {
  611. this->SetLanguageEnabledMaps(lang, mf);
  612. }
  613. this->LanguagesReady.insert(lang);
  614. // Test the compiler for the language just setup
  615. // (but only if a compiler has been actually found)
  616. // At this point we should have enough info for a try compile
  617. // which is used in the backward stuff
  618. // If the language is untested then test it now with a try compile.
  619. if(needTestLanguage[lang])
  620. {
  621. if (!this->CMakeInstance->GetIsInTryCompile())
  622. {
  623. std::string testLang = "CMakeTest";
  624. testLang += lang;
  625. testLang += "Compiler.cmake";
  626. std::string ifpath = mf->GetModulesFile(testLang.c_str());
  627. if(!mf->ReadListFile(0,ifpath.c_str()))
  628. {
  629. cmSystemTools::Error("Could not find cmake module file: ",
  630. ifpath.c_str());
  631. }
  632. std::string compilerWorks = "CMAKE_";
  633. compilerWorks += lang;
  634. compilerWorks += "_COMPILER_WORKS";
  635. // if the compiler did not work, then remove the
  636. // CMake(LANG)Compiler.cmake file so that it will get tested the
  637. // next time cmake is run
  638. if(!mf->IsOn(compilerWorks))
  639. {
  640. std::string compilerLangFile = rootBin;
  641. compilerLangFile += "/CMake";
  642. compilerLangFile += lang;
  643. compilerLangFile += "Compiler.cmake";
  644. cmSystemTools::RemoveFile(compilerLangFile.c_str());
  645. }
  646. } // end if in try compile
  647. } // end need test language
  648. // Store the shared library flags so that we can satisfy CMP0018
  649. std::string sharedLibFlagsVar = "CMAKE_SHARED_LIBRARY_";
  650. sharedLibFlagsVar += lang;
  651. sharedLibFlagsVar += "_FLAGS";
  652. const char* sharedLibFlags =
  653. mf->GetSafeDefinition(sharedLibFlagsVar);
  654. if (sharedLibFlags)
  655. {
  656. this->LanguageToOriginalSharedLibFlags[lang] = sharedLibFlags;
  657. }
  658. // Translate compiler ids for compatibility.
  659. this->CheckCompilerIdCompatibility(mf, lang);
  660. } // end for each language
  661. // Now load files that can override any settings on the platform or for
  662. // the project First load the project compatibility file if it is in
  663. // cmake
  664. std::string projectCompatibility = mf->GetDefinition("CMAKE_ROOT");
  665. projectCompatibility += "/Modules/";
  666. projectCompatibility += mf->GetSafeDefinition("PROJECT_NAME");
  667. projectCompatibility += "Compatibility.cmake";
  668. if(cmSystemTools::FileExists(projectCompatibility.c_str()))
  669. {
  670. mf->ReadListFile(0,projectCompatibility.c_str());
  671. }
  672. // Inform any extra generator of the new language.
  673. if (this->ExtraGenerator)
  674. {
  675. this->ExtraGenerator->EnableLanguage(languages, mf, false);
  676. }
  677. if(fatalError)
  678. {
  679. cmSystemTools::SetFatalErrorOccured();
  680. }
  681. }
  682. //----------------------------------------------------------------------------
  683. void cmGlobalGenerator::PrintCompilerAdvice(std::ostream& os,
  684. std::string const& lang,
  685. const char* envVar) const
  686. {
  687. // Subclasses override this method if they do not support this advice.
  688. os <<
  689. "Tell CMake where to find the compiler by setting "
  690. ;
  691. if(envVar)
  692. {
  693. os <<
  694. "either the environment variable \"" << envVar << "\" or "
  695. ;
  696. }
  697. os <<
  698. "the CMake cache entry CMAKE_" << lang << "_COMPILER "
  699. "to the full path to the compiler, or to the compiler name "
  700. "if it is in the PATH."
  701. ;
  702. }
  703. //----------------------------------------------------------------------------
  704. void cmGlobalGenerator::CheckCompilerIdCompatibility(cmMakefile* mf,
  705. std::string const& lang) const
  706. {
  707. std::string compilerIdVar = "CMAKE_" + lang + "_COMPILER_ID";
  708. const char* compilerId = mf->GetDefinition(compilerIdVar);
  709. if(!compilerId)
  710. {
  711. return;
  712. }
  713. if(strcmp(compilerId, "AppleClang") == 0)
  714. {
  715. cmPolicies* policies = this->CMakeInstance->GetPolicies();
  716. switch(mf->GetPolicyStatus(cmPolicies::CMP0025))
  717. {
  718. case cmPolicies::WARN:
  719. if(!this->CMakeInstance->GetIsInTryCompile())
  720. {
  721. cmOStringStream w;
  722. w << policies->GetPolicyWarning(cmPolicies::CMP0025) << "\n"
  723. "Converting " << lang <<
  724. " compiler id \"AppleClang\" to \"Clang\" for compatibility."
  725. ;
  726. mf->IssueMessage(cmake::AUTHOR_WARNING, w.str());
  727. }
  728. case cmPolicies::OLD:
  729. // OLD behavior is to convert AppleClang to Clang.
  730. mf->AddDefinition(compilerIdVar, "Clang");
  731. break;
  732. case cmPolicies::REQUIRED_IF_USED:
  733. case cmPolicies::REQUIRED_ALWAYS:
  734. mf->IssueMessage(
  735. cmake::FATAL_ERROR,
  736. policies->GetRequiredPolicyError(cmPolicies::CMP0025)
  737. );
  738. case cmPolicies::NEW:
  739. // NEW behavior is to keep AppleClang.
  740. break;
  741. }
  742. }
  743. if(strcmp(compilerId, "QCC") == 0)
  744. {
  745. cmPolicies* policies = this->CMakeInstance->GetPolicies();
  746. switch(mf->GetPolicyStatus(cmPolicies::CMP0047))
  747. {
  748. case cmPolicies::WARN:
  749. if(!this->CMakeInstance->GetIsInTryCompile())
  750. {
  751. cmOStringStream w;
  752. w << policies->GetPolicyWarning(cmPolicies::CMP0047) << "\n"
  753. "Converting " << lang <<
  754. " compiler id \"QCC\" to \"GNU\" for compatibility."
  755. ;
  756. mf->IssueMessage(cmake::AUTHOR_WARNING, w.str());
  757. }
  758. case cmPolicies::OLD:
  759. // OLD behavior is to convert QCC to GNU.
  760. mf->AddDefinition(compilerIdVar, "GNU");
  761. break;
  762. case cmPolicies::REQUIRED_IF_USED:
  763. case cmPolicies::REQUIRED_ALWAYS:
  764. mf->IssueMessage(
  765. cmake::FATAL_ERROR,
  766. policies->GetRequiredPolicyError(cmPolicies::CMP0047)
  767. );
  768. case cmPolicies::NEW:
  769. // NEW behavior is to keep QCC.
  770. break;
  771. }
  772. }
  773. }
  774. //----------------------------------------------------------------------------
  775. std::string
  776. cmGlobalGenerator::GetLanguageOutputExtension(cmSourceFile const& source) const
  777. {
  778. const std::string& lang = source.GetLanguage();
  779. if(!lang.empty())
  780. {
  781. std::map<std::string, std::string>::const_iterator it =
  782. this->LanguageToOutputExtension.find(lang);
  783. if(it != this->LanguageToOutputExtension.end())
  784. {
  785. return it->second;
  786. }
  787. }
  788. else
  789. {
  790. // if no language is found then check to see if it is already an
  791. // ouput extension for some language. In that case it should be ignored
  792. // and in this map, so it will not be compiled but will just be used.
  793. std::string const& ext = source.GetExtension();
  794. if(!ext.empty())
  795. {
  796. if(this->OutputExtensions.count(ext))
  797. {
  798. return ext;
  799. }
  800. }
  801. }
  802. return "";
  803. }
  804. std::string cmGlobalGenerator::GetLanguageFromExtension(const char* ext) const
  805. {
  806. // if there is an extension and it starts with . then move past the
  807. // . because the extensions are not stored with a . in the map
  808. if(ext && *ext == '.')
  809. {
  810. ++ext;
  811. }
  812. std::map<std::string, std::string>::const_iterator it
  813. = this->ExtensionToLanguage.find(ext);
  814. if(it != this->ExtensionToLanguage.end())
  815. {
  816. return it->second;
  817. }
  818. return "";
  819. }
  820. /* SetLanguageEnabled() is now split in two parts:
  821. at first the enabled-flag is set. This can then be used in EnabledLanguage()
  822. for checking whether the language is already enabled. After setting this
  823. flag still the values from the cmake variables have to be copied into the
  824. internal maps, this is done in SetLanguageEnabledMaps() which is called
  825. after the system- and compiler specific files have been loaded.
  826. This split was done originally so that compiler-specific configuration
  827. files could change the object file extension
  828. (CMAKE_<LANG>_OUTPUT_EXTENSION) before the CMake variables were copied
  829. to the C++ maps.
  830. */
  831. void cmGlobalGenerator::SetLanguageEnabled(const std::string& l,
  832. cmMakefile* mf)
  833. {
  834. this->SetLanguageEnabledFlag(l, mf);
  835. this->SetLanguageEnabledMaps(l, mf);
  836. }
  837. void cmGlobalGenerator::SetLanguageEnabledFlag(const std::string& l,
  838. cmMakefile* mf)
  839. {
  840. this->LanguageEnabled[l] = true;
  841. // Fill the language-to-extension map with the current variable
  842. // settings to make sure it is available for the try_compile()
  843. // command source file signature. In SetLanguageEnabledMaps this
  844. // will be done again to account for any compiler- or
  845. // platform-specific entries.
  846. this->FillExtensionToLanguageMap(l, mf);
  847. }
  848. void cmGlobalGenerator::SetLanguageEnabledMaps(const std::string& l,
  849. cmMakefile* mf)
  850. {
  851. // use LanguageToLinkerPreference to detect whether this functions has
  852. // run before
  853. if (this->LanguageToLinkerPreference.find(l) !=
  854. this->LanguageToLinkerPreference.end())
  855. {
  856. return;
  857. }
  858. std::string linkerPrefVar = std::string("CMAKE_") +
  859. std::string(l) + std::string("_LINKER_PREFERENCE");
  860. const char* linkerPref = mf->GetDefinition(linkerPrefVar);
  861. int preference = 0;
  862. if(linkerPref)
  863. {
  864. if (sscanf(linkerPref, "%d", &preference)!=1)
  865. {
  866. // backward compatibility: before 2.6 LINKER_PREFERENCE
  867. // was either "None" or "Prefered", and only the first character was
  868. // tested. So if there is a custom language out there and it is
  869. // "Prefered", set its preference high
  870. if (linkerPref[0]=='P')
  871. {
  872. preference = 100;
  873. }
  874. else
  875. {
  876. preference = 0;
  877. }
  878. }
  879. }
  880. if (preference < 0)
  881. {
  882. std::string msg = linkerPrefVar;
  883. msg += " is negative, adjusting it to 0";
  884. cmSystemTools::Message(msg.c_str(), "Warning");
  885. preference = 0;
  886. }
  887. this->LanguageToLinkerPreference[l] = preference;
  888. std::string outputExtensionVar = std::string("CMAKE_") +
  889. std::string(l) + std::string("_OUTPUT_EXTENSION");
  890. const char* outputExtension = mf->GetDefinition(outputExtensionVar);
  891. if(outputExtension)
  892. {
  893. this->LanguageToOutputExtension[l] = outputExtension;
  894. this->OutputExtensions[outputExtension] = outputExtension;
  895. if(outputExtension[0] == '.')
  896. {
  897. this->OutputExtensions[outputExtension+1] = outputExtension+1;
  898. }
  899. }
  900. // The map was originally filled by SetLanguageEnabledFlag, but
  901. // since then the compiler- and platform-specific files have been
  902. // loaded which might have added more entries.
  903. this->FillExtensionToLanguageMap(l, mf);
  904. std::string ignoreExtensionsVar = std::string("CMAKE_") +
  905. std::string(l) + std::string("_IGNORE_EXTENSIONS");
  906. std::string ignoreExts = mf->GetSafeDefinition(ignoreExtensionsVar);
  907. std::vector<std::string> extensionList;
  908. cmSystemTools::ExpandListArgument(ignoreExts, extensionList);
  909. for(std::vector<std::string>::iterator i = extensionList.begin();
  910. i != extensionList.end(); ++i)
  911. {
  912. this->IgnoreExtensions[*i] = true;
  913. }
  914. }
  915. void cmGlobalGenerator::FillExtensionToLanguageMap(const std::string& l,
  916. cmMakefile* mf)
  917. {
  918. std::string extensionsVar = std::string("CMAKE_") +
  919. std::string(l) + std::string("_SOURCE_FILE_EXTENSIONS");
  920. std::string exts = mf->GetSafeDefinition(extensionsVar);
  921. std::vector<std::string> extensionList;
  922. cmSystemTools::ExpandListArgument(exts, extensionList);
  923. for(std::vector<std::string>::iterator i = extensionList.begin();
  924. i != extensionList.end(); ++i)
  925. {
  926. this->ExtensionToLanguage[*i] = l;
  927. }
  928. }
  929. bool cmGlobalGenerator::IgnoreFile(const char* ext) const
  930. {
  931. if(!this->GetLanguageFromExtension(ext).empty())
  932. {
  933. return false;
  934. }
  935. return (this->IgnoreExtensions.count(ext) > 0);
  936. }
  937. bool cmGlobalGenerator::GetLanguageEnabled(const std::string& l) const
  938. {
  939. return (this->LanguageEnabled.find(l)!= this->LanguageEnabled.end());
  940. }
  941. void cmGlobalGenerator::ClearEnabledLanguages()
  942. {
  943. this->LanguageEnabled.clear();
  944. }
  945. bool cmGlobalGenerator::IsDependedOn(const std::string& project,
  946. cmTarget const* targetIn)
  947. {
  948. // Get all local gens for this project
  949. std::map<std::string, std::vector<cmLocalGenerator*> >::const_iterator it =
  950. this->ProjectMap.find(project);
  951. if (it == this->ProjectMap.end())
  952. {
  953. return false;
  954. }
  955. // loop over local gens and get the targets for each one
  956. for(std::vector<cmLocalGenerator*>::const_iterator geIt = it->second.begin();
  957. geIt != it->second.end(); ++geIt)
  958. {
  959. cmTargets const& targets = (*geIt)->GetMakefile()->GetTargets();
  960. for (cmTargets::const_iterator l = targets.begin();
  961. l != targets.end(); l++)
  962. {
  963. cmTarget const& target = l->second;
  964. TargetDependSet const& tgtdeps = this->GetTargetDirectDepends(target);
  965. if(tgtdeps.count(targetIn))
  966. {
  967. return true;
  968. }
  969. }
  970. }
  971. return false;
  972. }
  973. void cmGlobalGenerator::Configure()
  974. {
  975. this->FirstTimeProgress = 0.0f;
  976. this->ClearGeneratorMembers();
  977. // start with this directory
  978. cmLocalGenerator *lg = this->CreateLocalGenerator();
  979. this->LocalGenerators.push_back(lg);
  980. // set the Start directories
  981. cmMakefile* mf = lg->GetMakefile();
  982. lg->GetMakefile()->SetStartDirectory
  983. (this->CMakeInstance->GetStartDirectory());
  984. lg->GetMakefile()->SetStartOutputDirectory
  985. (this->CMakeInstance->GetStartOutputDirectory());
  986. lg->GetMakefile()->MakeStartDirectoriesCurrent();
  987. this->BinaryDirectories.insert(mf->GetStartOutputDirectory());
  988. // now do it
  989. lg->Configure();
  990. // update the cache entry for the number of local generators, this is used
  991. // for progress
  992. char num[100];
  993. sprintf(num,"%d",static_cast<int>(this->LocalGenerators.size()));
  994. this->GetCMakeInstance()->AddCacheEntry
  995. ("CMAKE_NUMBER_OF_LOCAL_GENERATORS", num,
  996. "number of local generators", cmCacheManager::INTERNAL);
  997. // check for link libraries and include directories containing "NOTFOUND"
  998. // and for infinite loops
  999. this->CheckLocalGenerators();
  1000. // at this point this->LocalGenerators has been filled,
  1001. // so create the map from project name to vector of local generators
  1002. this->FillProjectMap();
  1003. if ( this->CMakeInstance->GetWorkingMode() == cmake::NORMAL_MODE)
  1004. {
  1005. cmOStringStream msg;
  1006. if(cmSystemTools::GetErrorOccuredFlag())
  1007. {
  1008. msg << "Configuring incomplete, errors occurred!";
  1009. const char* logs[] = {"CMakeOutput.log", "CMakeError.log", 0};
  1010. for(const char** log = logs; *log; ++log)
  1011. {
  1012. std::string f = this->CMakeInstance->GetHomeOutputDirectory();
  1013. f += this->CMakeInstance->GetCMakeFilesDirectory();
  1014. f += "/";
  1015. f += *log;
  1016. if(cmSystemTools::FileExists(f.c_str()))
  1017. {
  1018. msg << "\nSee also \"" << f << "\".";
  1019. }
  1020. }
  1021. }
  1022. else
  1023. {
  1024. msg << "Configuring done";
  1025. }
  1026. this->CMakeInstance->UpdateProgress(msg.str().c_str(), -1);
  1027. }
  1028. }
  1029. cmExportBuildFileGenerator*
  1030. cmGlobalGenerator::GetExportedTargetsFile(const std::string &filename) const
  1031. {
  1032. std::map<std::string, cmExportBuildFileGenerator*>::const_iterator it
  1033. = this->BuildExportSets.find(filename);
  1034. return it == this->BuildExportSets.end() ? 0 : it->second;
  1035. }
  1036. //----------------------------------------------------------------------------
  1037. void cmGlobalGenerator::AddCMP0042WarnTarget(const std::string& target)
  1038. {
  1039. this->CMP0042WarnTargets.insert(target);
  1040. }
  1041. bool cmGlobalGenerator::CheckALLOW_DUPLICATE_CUSTOM_TARGETS() const
  1042. {
  1043. // If the property is not enabled then okay.
  1044. if(!this->CMakeInstance
  1045. ->GetPropertyAsBool("ALLOW_DUPLICATE_CUSTOM_TARGETS"))
  1046. {
  1047. return true;
  1048. }
  1049. // This generator does not support duplicate custom targets.
  1050. cmOStringStream e;
  1051. e << "This project has enabled the ALLOW_DUPLICATE_CUSTOM_TARGETS "
  1052. << "global property. "
  1053. << "The \"" << this->GetName() << "\" generator does not support "
  1054. << "duplicate custom targets. "
  1055. << "Consider using a Makefiles generator or fix the project to not "
  1056. << "use duplicate target names.";
  1057. cmSystemTools::Error(e.str().c_str());
  1058. return false;
  1059. }
  1060. void cmGlobalGenerator::Generate()
  1061. {
  1062. // Some generators track files replaced during the Generate.
  1063. // Start with an empty vector:
  1064. this->FilesReplacedDuringGenerate.clear();
  1065. // clear targets to issue warning CMP0042 for
  1066. this->CMP0042WarnTargets.clear();
  1067. // Check whether this generator is allowed to run.
  1068. if(!this->CheckALLOW_DUPLICATE_CUSTOM_TARGETS())
  1069. {
  1070. return;
  1071. }
  1072. this->FinalizeTargetCompileInfo();
  1073. #ifdef CMAKE_BUILD_WITH_CMAKE
  1074. // Iterate through all targets and set up automoc for those which have
  1075. // the AUTOMOC, AUTOUIC or AUTORCC property set
  1076. AutogensType autogens;
  1077. this->CreateQtAutoGeneratorsTargets(autogens);
  1078. #endif
  1079. // For each existing cmLocalGenerator
  1080. unsigned int i;
  1081. // Put a copy of each global target in every directory.
  1082. cmTargets globalTargets;
  1083. this->CreateDefaultGlobalTargets(&globalTargets);
  1084. for (i = 0; i < this->LocalGenerators.size(); ++i)
  1085. {
  1086. cmMakefile* mf = this->LocalGenerators[i]->GetMakefile();
  1087. cmTargets* targets = &(mf->GetTargets());
  1088. cmTargets::iterator tit;
  1089. for ( tit = globalTargets.begin(); tit != globalTargets.end(); ++ tit )
  1090. {
  1091. (*targets)[tit->first] = tit->second;
  1092. (*targets)[tit->first].SetMakefile(mf);
  1093. }
  1094. }
  1095. // Add generator specific helper commands
  1096. for (i = 0; i < this->LocalGenerators.size(); ++i)
  1097. {
  1098. this->LocalGenerators[i]->AddHelperCommands();
  1099. }
  1100. // Create per-target generator information.
  1101. this->CreateGeneratorTargets();
  1102. this->ForceLinkerLanguages();
  1103. #ifdef CMAKE_BUILD_WITH_CMAKE
  1104. for (AutogensType::iterator it = autogens.begin(); it != autogens.end();
  1105. ++it)
  1106. {
  1107. it->first.SetupAutoGenerateTarget(it->second);
  1108. }
  1109. #endif
  1110. // Trace the dependencies, after that no custom commands should be added
  1111. // because their dependencies might not be handled correctly
  1112. for (i = 0; i < this->LocalGenerators.size(); ++i)
  1113. {
  1114. this->LocalGenerators[i]->TraceDependencies();
  1115. }
  1116. // Compute the manifest of main targets generated.
  1117. for (i = 0; i < this->LocalGenerators.size(); ++i)
  1118. {
  1119. this->LocalGenerators[i]->GenerateTargetManifest();
  1120. }
  1121. this->ComputeGeneratorTargetObjects();
  1122. this->ProcessEvaluationFiles();
  1123. // Compute the inter-target dependencies.
  1124. if(!this->ComputeTargetDepends())
  1125. {
  1126. return;
  1127. }
  1128. // Create a map from local generator to the complete set of targets
  1129. // it builds by default.
  1130. this->FillLocalGeneratorToTargetMap();
  1131. // Generate project files
  1132. for (i = 0; i < this->LocalGenerators.size(); ++i)
  1133. {
  1134. this->LocalGenerators[i]->GetMakefile()->SetGeneratingBuildSystem();
  1135. this->SetCurrentLocalGenerator(this->LocalGenerators[i]);
  1136. this->LocalGenerators[i]->Generate();
  1137. if(!this->LocalGenerators[i]->GetMakefile()->IsOn(
  1138. "CMAKE_SKIP_INSTALL_RULES"))
  1139. {
  1140. this->LocalGenerators[i]->GenerateInstallRules();
  1141. }
  1142. this->LocalGenerators[i]->GenerateTestFiles();
  1143. this->CMakeInstance->UpdateProgress("Generating",
  1144. (static_cast<float>(i)+1.0f)/
  1145. static_cast<float>(this->LocalGenerators.size()));
  1146. }
  1147. this->SetCurrentLocalGenerator(0);
  1148. for (std::map<std::string, cmExportBuildFileGenerator*>::iterator
  1149. it = this->BuildExportSets.begin(); it != this->BuildExportSets.end();
  1150. ++it)
  1151. {
  1152. if (!it->second->GenerateImportFile()
  1153. && !cmSystemTools::GetErrorOccuredFlag())
  1154. {
  1155. this->GetCMakeInstance()
  1156. ->IssueMessage(cmake::FATAL_ERROR, "Could not write export file.",
  1157. cmListFileBacktrace());
  1158. return;
  1159. }
  1160. }
  1161. // Update rule hashes.
  1162. this->CheckRuleHashes();
  1163. this->WriteSummary();
  1164. if (this->ExtraGenerator != 0)
  1165. {
  1166. this->ExtraGenerator->Generate();
  1167. }
  1168. if(!this->CMP0042WarnTargets.empty())
  1169. {
  1170. cmOStringStream w;
  1171. w <<
  1172. (this->GetCMakeInstance()->GetPolicies()->
  1173. GetPolicyWarning(cmPolicies::CMP0042)) << "\n";
  1174. w << "MACOSX_RPATH is not specified for"
  1175. " the following targets:\n";
  1176. for(std::set<std::string>::iterator
  1177. iter = this->CMP0042WarnTargets.begin();
  1178. iter != this->CMP0042WarnTargets.end();
  1179. ++iter)
  1180. {
  1181. w << " " << *iter << "\n";
  1182. }
  1183. this->GetCMakeInstance()->IssueMessage(cmake::AUTHOR_WARNING, w.str(),
  1184. cmListFileBacktrace());
  1185. }
  1186. this->CMakeInstance->UpdateProgress("Generating done", -1);
  1187. }
  1188. //----------------------------------------------------------------------------
  1189. bool cmGlobalGenerator::ComputeTargetDepends()
  1190. {
  1191. cmComputeTargetDepends ctd(this);
  1192. if(!ctd.Compute())
  1193. {
  1194. return false;
  1195. }
  1196. std::vector<cmTarget const*> const& targets = ctd.GetTargets();
  1197. for(std::vector<cmTarget const*>::const_iterator ti = targets.begin();
  1198. ti != targets.end(); ++ti)
  1199. {
  1200. ctd.GetTargetDirectDepends(*ti, this->TargetDependencies[*ti]);
  1201. }
  1202. return true;
  1203. }
  1204. //----------------------------------------------------------------------------
  1205. void cmGlobalGenerator::CreateQtAutoGeneratorsTargets(AutogensType &autogens)
  1206. {
  1207. #ifdef CMAKE_BUILD_WITH_CMAKE
  1208. for(unsigned int i=0; i < this->LocalGenerators.size(); ++i)
  1209. {
  1210. cmTargets& targets =
  1211. this->LocalGenerators[i]->GetMakefile()->GetTargets();
  1212. for(cmTargets::iterator ti = targets.begin();
  1213. ti != targets.end(); ++ti)
  1214. {
  1215. cmTarget& target = ti->second;
  1216. if(target.GetType() == cmTarget::EXECUTABLE ||
  1217. target.GetType() == cmTarget::STATIC_LIBRARY ||
  1218. target.GetType() == cmTarget::SHARED_LIBRARY ||
  1219. target.GetType() == cmTarget::MODULE_LIBRARY ||
  1220. target.GetType() == cmTarget::OBJECT_LIBRARY)
  1221. {
  1222. if((target.GetPropertyAsBool("AUTOMOC")
  1223. || target.GetPropertyAsBool("AUTOUIC")
  1224. || target.GetPropertyAsBool("AUTORCC"))
  1225. && !target.IsImported())
  1226. {
  1227. cmQtAutoGenerators autogen;
  1228. if(autogen.InitializeAutogenTarget(&target))
  1229. {
  1230. autogens.push_back(AutogensType::value_type(autogen, &target));
  1231. }
  1232. }
  1233. }
  1234. }
  1235. }
  1236. #else
  1237. (void)autogens;
  1238. #endif
  1239. }
  1240. //----------------------------------------------------------------------------
  1241. void cmGlobalGenerator::FinalizeTargetCompileInfo()
  1242. {
  1243. // Construct per-target generator information.
  1244. for(unsigned int i=0; i < this->LocalGenerators.size(); ++i)
  1245. {
  1246. cmMakefile *mf = this->LocalGenerators[i]->GetMakefile();
  1247. const std::vector<cmValueWithOrigin> noconfig_compile_definitions =
  1248. mf->GetCompileDefinitionsEntries();
  1249. cmTargets& targets = mf->GetTargets();
  1250. for(cmTargets::iterator ti = targets.begin();
  1251. ti != targets.end(); ++ti)
  1252. {
  1253. cmTarget* t = &ti->second;
  1254. t->AppendBuildInterfaceIncludes();
  1255. if (t->GetType() == cmTarget::INTERFACE_LIBRARY)
  1256. {
  1257. continue;
  1258. }
  1259. for (std::vector<cmValueWithOrigin>::const_iterator it
  1260. = noconfig_compile_definitions.begin();
  1261. it != noconfig_compile_definitions.end(); ++it)
  1262. {
  1263. t->InsertCompileDefinition(*it);
  1264. }
  1265. cmPolicies::PolicyStatus polSt
  1266. = mf->GetPolicyStatus(cmPolicies::CMP0043);
  1267. if (polSt == cmPolicies::WARN || polSt == cmPolicies::OLD)
  1268. {
  1269. std::vector<std::string> configs;
  1270. mf->GetConfigurations(configs);
  1271. for(std::vector<std::string>::const_iterator ci = configs.begin();
  1272. ci != configs.end(); ++ci)
  1273. {
  1274. std::string defPropName = "COMPILE_DEFINITIONS_";
  1275. defPropName += cmSystemTools::UpperCase(*ci);
  1276. t->AppendProperty(defPropName,
  1277. mf->GetProperty(defPropName));
  1278. }
  1279. }
  1280. }
  1281. }
  1282. }
  1283. //----------------------------------------------------------------------------
  1284. void cmGlobalGenerator::CreateGeneratorTargets(cmMakefile *mf)
  1285. {
  1286. cmGeneratorTargetsType generatorTargets;
  1287. cmTargets& targets = mf->GetTargets();
  1288. for(cmTargets::iterator ti = targets.begin();
  1289. ti != targets.end(); ++ti)
  1290. {
  1291. cmTarget* t = &ti->second;
  1292. cmGeneratorTarget* gt = new cmGeneratorTarget(t);
  1293. this->ComputeTargetObjectDirectory(gt);
  1294. this->GeneratorTargets[t] = gt;
  1295. generatorTargets[t] = gt;
  1296. }
  1297. for(std::vector<cmTarget*>::const_iterator
  1298. j = mf->GetOwnedImportedTargets().begin();
  1299. j != mf->GetOwnedImportedTargets().end(); ++j)
  1300. {
  1301. cmGeneratorTarget* gt = new cmGeneratorTarget(*j);
  1302. this->GeneratorTargets[*j] = gt;
  1303. generatorTargets[*j] = gt;
  1304. }
  1305. mf->SetGeneratorTargets(generatorTargets);
  1306. }
  1307. //----------------------------------------------------------------------------
  1308. void cmGlobalGenerator::CreateGeneratorTargets()
  1309. {
  1310. // Construct per-target generator information.
  1311. for(unsigned int i=0; i < this->LocalGenerators.size(); ++i)
  1312. {
  1313. this->CreateGeneratorTargets(this->LocalGenerators[i]->GetMakefile());
  1314. }
  1315. }
  1316. //----------------------------------------------------------------------------
  1317. void cmGlobalGenerator::ComputeGeneratorTargetObjects()
  1318. {
  1319. // Construct per-target generator information.
  1320. for(unsigned int i=0; i < this->LocalGenerators.size(); ++i)
  1321. {
  1322. cmMakefile *mf = this->LocalGenerators[i]->GetMakefile();
  1323. cmGeneratorTargetsType targets = mf->GetGeneratorTargets();
  1324. for(cmGeneratorTargetsType::iterator ti = targets.begin();
  1325. ti != targets.end(); ++ti)
  1326. {
  1327. if (ti->second->Target->IsImported()
  1328. || ti->second->Target->GetType() == cmTarget::INTERFACE_LIBRARY)
  1329. {
  1330. continue;
  1331. }
  1332. cmGeneratorTarget* gt = ti->second;
  1333. this->ComputeTargetObjects(gt);
  1334. }
  1335. }
  1336. }
  1337. //----------------------------------------------------------------------------
  1338. void cmGlobalGenerator::ClearGeneratorMembers()
  1339. {
  1340. for(cmGeneratorTargetsType::iterator i = this->GeneratorTargets.begin();
  1341. i != this->GeneratorTargets.end(); ++i)
  1342. {
  1343. delete i->second;
  1344. }
  1345. this->GeneratorTargets.clear();
  1346. for(std::vector<cmGeneratorExpressionEvaluationFile*>::const_iterator
  1347. li = this->EvaluationFiles.begin();
  1348. li != this->EvaluationFiles.end();
  1349. ++li)
  1350. {
  1351. delete *li;
  1352. }
  1353. this->EvaluationFiles.clear();
  1354. for(std::map<std::string, cmExportBuildFileGenerator*>::iterator
  1355. i = this->BuildExportSets.begin();
  1356. i != this->BuildExportSets.end(); ++i)
  1357. {
  1358. delete i->second;
  1359. }
  1360. this->BuildExportSets.clear();
  1361. for (unsigned int i = 0; i < this->LocalGenerators.size(); ++i)
  1362. {
  1363. delete this->LocalGenerators[i];
  1364. }
  1365. this->LocalGenerators.clear();
  1366. this->ExportSets.clear();
  1367. this->TargetDependencies.clear();
  1368. this->TotalTargets.clear();
  1369. this->ImportedTargets.clear();
  1370. this->LocalGeneratorToTargetMap.clear();
  1371. this->ProjectMap.clear();
  1372. this->RuleHashes.clear();
  1373. this->DirectoryContentMap.clear();
  1374. this->BinaryDirectories.clear();
  1375. }
  1376. //----------------------------------------------------------------------------
  1377. cmGeneratorTarget*
  1378. cmGlobalGenerator::GetGeneratorTarget(cmTarget const* t) const
  1379. {
  1380. cmGeneratorTargetsType::const_iterator ti = this->GeneratorTargets.find(t);
  1381. if(ti == this->GeneratorTargets.end())
  1382. {
  1383. this->CMakeInstance->IssueMessage(
  1384. cmake::INTERNAL_ERROR, "Missing cmGeneratorTarget instance!",
  1385. cmListFileBacktrace());
  1386. return 0;
  1387. }
  1388. return ti->second;
  1389. }
  1390. //----------------------------------------------------------------------------
  1391. void cmGlobalGenerator::ComputeTargetObjects(cmGeneratorTarget* gt) const
  1392. {
  1393. std::vector<cmSourceFile const*> objectSources;
  1394. gt->GetObjectSources(objectSources);
  1395. std::map<cmSourceFile const*, std::string> mapping;
  1396. for(std::vector<cmSourceFile const*>::const_iterator it
  1397. = objectSources.begin(); it != objectSources.end(); ++it)
  1398. {
  1399. mapping[*it];
  1400. }
  1401. gt->LocalGenerator->ComputeObjectFilenames(mapping, gt);
  1402. for(std::map<cmSourceFile const*, std::string>::const_iterator it
  1403. = mapping.begin(); it != mapping.end(); ++it)
  1404. {
  1405. assert(!it->second.empty());
  1406. gt->AddObject(it->first, it->second);
  1407. }
  1408. }
  1409. //----------------------------------------------------------------------------
  1410. void cmGlobalGenerator::ComputeTargetObjectDirectory(cmGeneratorTarget*) const
  1411. {
  1412. }
  1413. void cmGlobalGenerator::CheckLocalGenerators()
  1414. {
  1415. std::map<std::string, std::string> notFoundMap;
  1416. // std::set<std::string> notFoundMap;
  1417. // after it is all done do a ConfigureFinalPass
  1418. cmCacheManager* manager = 0;
  1419. for (unsigned int i = 0; i < this->LocalGenerators.size(); ++i)
  1420. {
  1421. manager = this->LocalGenerators[i]->GetMakefile()->GetCacheManager();
  1422. this->LocalGenerators[i]->ConfigureFinalPass();
  1423. cmTargets &targets =
  1424. this->LocalGenerators[i]->GetMakefile()->GetTargets();
  1425. for (cmTargets::iterator l = targets.begin();
  1426. l != targets.end(); l++)
  1427. {
  1428. if (l->second.GetType() == cmTarget::INTERFACE_LIBRARY)
  1429. {
  1430. continue;
  1431. }
  1432. const cmTarget::LinkLibraryVectorType& libs =
  1433. l->second.GetOriginalLinkLibraries();
  1434. for(cmTarget::LinkLibraryVectorType::const_iterator lib = libs.begin();
  1435. lib != libs.end(); ++lib)
  1436. {
  1437. if(lib->first.size() > 9 &&
  1438. cmSystemTools::IsNOTFOUND(lib->first.c_str()))
  1439. {
  1440. std::string varName = lib->first.substr(0, lib->first.size()-9);
  1441. cmCacheManager::CacheIterator it =
  1442. manager->GetCacheIterator(varName.c_str());
  1443. if(it.GetPropertyAsBool("ADVANCED"))
  1444. {
  1445. varName += " (ADVANCED)";
  1446. }
  1447. std::string text = notFoundMap[varName];
  1448. text += "\n linked by target \"";
  1449. text += l->second.GetName();
  1450. text += "\" in directory ";
  1451. text+=this->LocalGenerators[i]->GetMakefile()->GetCurrentDirectory();
  1452. notFoundMap[varName] = text;
  1453. }
  1454. }
  1455. std::vector<std::string> incs;
  1456. const char *incDirProp = l->second.GetProperty("INCLUDE_DIRECTORIES");
  1457. if (!incDirProp)
  1458. {
  1459. continue;
  1460. }
  1461. std::string incDirs = cmGeneratorExpression::Preprocess(incDirProp,
  1462. cmGeneratorExpression::StripAllGeneratorExpressions);
  1463. cmSystemTools::ExpandListArgument(incDirs, incs);
  1464. for( std::vector<std::string>::const_iterator incDir = incs.begin();
  1465. incDir != incs.end(); ++incDir)
  1466. {
  1467. if(incDir->size() > 9 &&
  1468. cmSystemTools::IsNOTFOUND(incDir->c_str()))
  1469. {
  1470. std::string varName = incDir->substr(0, incDir->size()-9);
  1471. cmCacheManager::CacheIterator it =
  1472. manager->GetCacheIterator(varName.c_str());
  1473. if(it.GetPropertyAsBool("ADVANCED"))
  1474. {
  1475. varName += " (ADVANCED)";
  1476. }
  1477. std::string text = notFoundMap[varName];
  1478. text += "\n used as include directory in directory ";
  1479. text += this->LocalGenerators[i]
  1480. ->GetMakefile()->GetCurrentDirectory();
  1481. notFoundMap[varName] = text;
  1482. }
  1483. }
  1484. }
  1485. this->CMakeInstance->UpdateProgress
  1486. ("Configuring", 0.9f+0.1f*(static_cast<float>(i)+1.0f)/
  1487. static_cast<float>(this->LocalGenerators.size()));
  1488. }
  1489. if(notFoundMap.size())
  1490. {
  1491. std::string notFoundVars;
  1492. for(std::map<std::string, std::string>::const_iterator
  1493. ii = notFoundMap.begin();
  1494. ii != notFoundMap.end();
  1495. ++ii)
  1496. {
  1497. notFoundVars += ii->first;
  1498. notFoundVars += ii->second;
  1499. notFoundVars += "\n";
  1500. }
  1501. cmSystemTools::Error("The following variables are used in this project, "
  1502. "but they are set to NOTFOUND.\n"
  1503. "Please set them or make sure they are set and "
  1504. "tested correctly in the CMake files:\n",
  1505. notFoundVars.c_str());
  1506. }
  1507. }
  1508. int cmGlobalGenerator::TryCompile(const std::string& srcdir,
  1509. const std::string& bindir,
  1510. const std::string& projectName,
  1511. const std::string& target, bool fast,
  1512. std::string *output, cmMakefile *mf)
  1513. {
  1514. // if this is not set, then this is a first time configure
  1515. // and there is a good chance that the try compile stuff will
  1516. // take the bulk of the time, so try and guess some progress
  1517. // by getting closer and closer to 100 without actually getting there.
  1518. if (!this->CMakeInstance->GetCacheManager()->GetCacheValue
  1519. ("CMAKE_NUMBER_OF_LOCAL_GENERATORS"))
  1520. {
  1521. // If CMAKE_NUMBER_OF_LOCAL_GENERATORS is not set
  1522. // we are in the first time progress and we have no
  1523. // idea how long it will be. So, just move 1/10th of the way
  1524. // there each time, and don't go over 95%
  1525. this->FirstTimeProgress += ((1.0f - this->FirstTimeProgress) /30.0f);
  1526. if(this->FirstTimeProgress > 0.95f)
  1527. {
  1528. this->FirstTimeProgress = 0.95f;
  1529. }
  1530. this->CMakeInstance->UpdateProgress("Configuring",
  1531. this->FirstTimeProgress);
  1532. }
  1533. std::string newTarget;
  1534. if (!target.empty())
  1535. {
  1536. newTarget += target;
  1537. #if 0
  1538. #if defined(_WIN32) || defined(__CYGWIN__)
  1539. std::string tmp = target;
  1540. // if the target does not already end in . something
  1541. // then assume .exe
  1542. if(tmp.size() < 4 || tmp[tmp.size()-4] != '.')
  1543. {
  1544. newTarget += ".exe";
  1545. }
  1546. #endif // WIN32
  1547. #endif
  1548. }
  1549. std::string config =
  1550. mf->GetSafeDefinition("CMAKE_TRY_COMPILE_CONFIGURATION");
  1551. return this->Build(srcdir,bindir,projectName,
  1552. newTarget,
  1553. output,"",config,false,fast,
  1554. this->TryCompileTimeout);
  1555. }
  1556. void cmGlobalGenerator::GenerateBuildCommand(
  1557. std::vector<std::string>& makeCommand, const std::string&,
  1558. const std::string&, const std::string&, const std::string&,
  1559. const std::string&, bool,
  1560. std::vector<std::string> const&)
  1561. {
  1562. makeCommand.push_back(
  1563. "cmGlobalGenerator::GenerateBuildCommand not implemented");
  1564. }
  1565. int cmGlobalGenerator::Build(
  1566. const std::string&, const std::string& bindir,
  1567. const std::string& projectName, const std::string& target,
  1568. std::string *output,
  1569. const std::string& makeCommandCSTR,
  1570. const std::string& config,
  1571. bool clean, bool fast,
  1572. double timeout,
  1573. cmSystemTools::OutputOption outputflag,
  1574. std::vector<std::string> const& nativeOptions)
  1575. {
  1576. /**
  1577. * Run an executable command and put the stdout in output.
  1578. */
  1579. std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
  1580. cmSystemTools::ChangeDirectory(bindir.c_str());
  1581. if(output)
  1582. {
  1583. *output += "Change Dir: ";
  1584. *output += bindir;
  1585. *output += "\n";
  1586. }
  1587. int retVal;
  1588. bool hideconsole = cmSystemTools::GetRunCommandHideConsole();
  1589. cmSystemTools::SetRunCommandHideConsole(true);
  1590. std::string outputBuffer;
  1591. std::string* outputPtr = 0;
  1592. if(output)
  1593. {
  1594. outputPtr = &outputBuffer;
  1595. }
  1596. // should we do a clean first?
  1597. if (clean)
  1598. {
  1599. std::vector<std::string> cleanCommand;
  1600. this->GenerateBuildCommand(cleanCommand, makeCommandCSTR, projectName,
  1601. bindir, "clean", config, fast);
  1602. if(output)
  1603. {
  1604. *output += "\nRun Clean Command:";
  1605. *output += cmSystemTools::PrintSingleCommand(cleanCommand);
  1606. *output += "\n";
  1607. }
  1608. if (!cmSystemTools::RunSingleCommand(cleanCommand, outputPtr,
  1609. &retVal, 0, outputflag, timeout))
  1610. {
  1611. cmSystemTools::SetRunCommandHideConsole(hideconsole);
  1612. cmSystemTools::Error("Generator: execution of make clean failed.");
  1613. if (output)
  1614. {
  1615. *output += *outputPtr;
  1616. *output += "\nGenerator: execution of make clean failed.\n";
  1617. }
  1618. // return to the original directory
  1619. cmSystemTools::ChangeDirectory(cwd.c_str());
  1620. return 1;
  1621. }
  1622. if (output)
  1623. {
  1624. *output += *outputPtr;
  1625. }
  1626. }
  1627. // now build
  1628. std::vector<std::string> makeCommand;
  1629. this->GenerateBuildCommand(makeCommand, makeCommandCSTR, projectName,
  1630. bindir, target, config, fast, nativeOptions);
  1631. std::string makeCommandStr = cmSystemTools::PrintSingleCommand(makeCommand);
  1632. if(output)
  1633. {
  1634. *output += "\nRun Build Command:";
  1635. *output += makeCommandStr;
  1636. *output += "\n";
  1637. }
  1638. if (!cmSystemTools::RunSingleCommand(makeCommand, outputPtr,
  1639. &retVal, 0, outputflag, timeout))
  1640. {
  1641. cmSystemTools::SetRunCommandHideConsole(hideconsole);
  1642. cmSystemTools::Error
  1643. ("Generator: execution of make failed. Make command was: ",
  1644. makeCommandStr.c_str());
  1645. if (output)
  1646. {
  1647. *output += *outputPtr;
  1648. *output += "\nGenerator: execution of make failed. Make command was: "
  1649. + makeCommandStr + "\n";
  1650. }
  1651. // return to the original directory
  1652. cmSystemTools::ChangeDirectory(cwd.c_str());
  1653. return 1;
  1654. }
  1655. if (output)
  1656. {
  1657. *output += *outputPtr;
  1658. }
  1659. cmSystemTools::SetRunCommandHideConsole(hideconsole);
  1660. // The SGI MipsPro 7.3 compiler does not return an error code when
  1661. // the source has a #error in it! This is a work-around for such
  1662. // compilers.
  1663. if((retVal == 0) && (output->find("#error") != std::string::npos))
  1664. {
  1665. retVal = 1;
  1666. }
  1667. cmSystemTools::ChangeDirectory(cwd.c_str());
  1668. return retVal;
  1669. }
  1670. //----------------------------------------------------------------------------
  1671. std::string cmGlobalGenerator::GenerateCMakeBuildCommand(
  1672. const std::string& target, const std::string& config,
  1673. const std::string& native,
  1674. bool ignoreErrors)
  1675. {
  1676. std::string makeCommand = cmSystemTools::GetCMakeCommand();
  1677. makeCommand = cmSystemTools::ConvertToOutputPath(makeCommand.c_str());
  1678. makeCommand += " --build .";
  1679. if(!config.empty())
  1680. {
  1681. makeCommand += " --config \"";
  1682. makeCommand += config;
  1683. makeCommand += "\"";
  1684. }
  1685. if(!target.empty())
  1686. {
  1687. makeCommand += " --target \"";
  1688. makeCommand += target;
  1689. makeCommand += "\"";
  1690. }
  1691. const char* sep = " -- ";
  1692. if(ignoreErrors)
  1693. {
  1694. const char* iflag = this->GetBuildIgnoreErrorsFlag();
  1695. if(iflag && *iflag)
  1696. {
  1697. makeCommand += sep;
  1698. makeCommand += iflag;
  1699. sep = " ";
  1700. }
  1701. }
  1702. if(!native.empty())
  1703. {
  1704. makeCommand += sep;
  1705. makeCommand += native;
  1706. }
  1707. return makeCommand;
  1708. }
  1709. //----------------------------------------------------------------------------
  1710. void cmGlobalGenerator::AddLocalGenerator(cmLocalGenerator *lg)
  1711. {
  1712. this->LocalGenerators.push_back(lg);
  1713. // update progress
  1714. // estimate how many lg there will be
  1715. const char *numGenC =
  1716. this->CMakeInstance->GetCacheManager()->GetCacheValue
  1717. ("CMAKE_NUMBER_OF_LOCAL_GENERATORS");
  1718. if (!numGenC)
  1719. {
  1720. // If CMAKE_NUMBER_OF_LOCAL_GENERATORS is not set
  1721. // we are in the first time progress and we have no
  1722. // idea how long it will be. So, just move half way
  1723. // there each time, and don't go over 95%
  1724. this->FirstTimeProgress += ((1.0f - this->FirstTimeProgress) /30.0f);
  1725. if(this->FirstTimeProgress > 0.95f)
  1726. {
  1727. this->FirstTimeProgress = 0.95f;
  1728. }
  1729. this->CMakeInstance->UpdateProgress("Configuring",
  1730. this->FirstTimeProgress);
  1731. return;
  1732. }
  1733. int numGen = atoi(numGenC);
  1734. float prog = 0.9f*static_cast<float>(this->LocalGenerators.size())/
  1735. static_cast<float>(numGen);
  1736. if (prog > 0.9f)
  1737. {
  1738. prog = 0.9f;
  1739. }
  1740. this->CMakeInstance->UpdateProgress("Configuring", prog);
  1741. }
  1742. void cmGlobalGenerator::AddInstallComponent(const char* component)
  1743. {
  1744. if(component && *component)
  1745. {
  1746. this->InstallComponents.insert(component);
  1747. }
  1748. }
  1749. void cmGlobalGenerator::EnableInstallTarget()
  1750. {
  1751. this->InstallTargetEnabled = true;
  1752. }
  1753. cmLocalGenerator *cmGlobalGenerator::CreateLocalGenerator()
  1754. {
  1755. cmLocalGenerator *lg = new cmLocalGenerator;
  1756. lg->SetGlobalGenerator(this);
  1757. return lg;
  1758. }
  1759. void cmGlobalGenerator::EnableLanguagesFromGenerator(cmGlobalGenerator *gen,
  1760. cmMakefile* mf)
  1761. {
  1762. this->SetConfiguredFilesPath(gen);
  1763. this->TryCompileOuterMakefile = mf;
  1764. const char* make =
  1765. gen->GetCMakeInstance()->GetCacheDefinition("CMAKE_MAKE_PROGRAM");
  1766. this->GetCMakeInstance()->AddCacheEntry("CMAKE_MAKE_PROGRAM", make,
  1767. "make program",
  1768. cmCacheManager::FILEPATH);
  1769. // copy the enabled languages
  1770. this->LanguageEnabled = gen->LanguageEnabled;
  1771. this->LanguagesReady = gen->LanguagesReady;
  1772. this->ExtensionToLanguage = gen->ExtensionToLanguage;
  1773. this->IgnoreExtensions = gen->IgnoreExtensions;
  1774. this->LanguageToOutputExtension = gen->LanguageToOutputExtension;
  1775. this->LanguageToLinkerPreference = gen->LanguageToLinkerPreference;
  1776. this->OutputExtensions = gen->OutputExtensions;
  1777. }
  1778. //----------------------------------------------------------------------------
  1779. void cmGlobalGenerator::SetConfiguredFilesPath(cmGlobalGenerator* gen)
  1780. {
  1781. if(!gen->ConfiguredFilesPath.empty())
  1782. {
  1783. this->ConfiguredFilesPath = gen->ConfiguredFilesPath;
  1784. }
  1785. else
  1786. {
  1787. this->ConfiguredFilesPath = gen->CMakeInstance->GetHomeOutputDirectory();
  1788. this->ConfiguredFilesPath += cmake::GetCMakeFilesDirectory();
  1789. }
  1790. }
  1791. bool cmGlobalGenerator::IsExcluded(cmLocalGenerator* root,
  1792. cmLocalGenerator* gen) const
  1793. {
  1794. if(!gen || gen == root)
  1795. {
  1796. // No directory excludes itself.
  1797. return false;
  1798. }
  1799. if(gen->GetMakefile()->GetPropertyAsBool("EXCLUDE_FROM_ALL"))
  1800. {
  1801. // This directory is excluded from its parent.
  1802. return true;
  1803. }
  1804. // This directory is included in its parent. Check whether the
  1805. // parent is excluded.
  1806. return this->IsExcluded(root, gen->GetParent());
  1807. }
  1808. bool cmGlobalGenerator::IsExcluded(cmLocalGenerator* root,
  1809. cmTarget const& target) const
  1810. {
  1811. if(target.GetType() == cmTarget::INTERFACE_LIBRARY
  1812. || target.GetPropertyAsBool("EXCLUDE_FROM_ALL"))
  1813. {
  1814. // This target is excluded from its directory.
  1815. return true;
  1816. }
  1817. else
  1818. {
  1819. // This target is included in its directory. Check whether the
  1820. // directory is excluded.
  1821. return this->IsExcluded(root, target.GetMakefile()->GetLocalGenerator());
  1822. }
  1823. }
  1824. void
  1825. cmGlobalGenerator::GetEnabledLanguages(std::vector<std::string>& lang) const
  1826. {
  1827. for(std::map<std::string, bool>::const_iterator i =
  1828. this->LanguageEnabled.begin(); i != this->LanguageEnabled.end(); ++i)
  1829. {
  1830. lang.push_back(i->first);
  1831. }
  1832. }
  1833. int cmGlobalGenerator::GetLinkerPreference(const std::string& lang) const
  1834. {
  1835. std::map<std::string, int>::const_iterator it =
  1836. this->LanguageToLinkerPreference.find(lang);
  1837. if (it != this->LanguageToLinkerPreference.end())
  1838. {
  1839. return it->second;
  1840. }
  1841. return 0;
  1842. }
  1843. void cmGlobalGenerator::FillProjectMap()
  1844. {
  1845. this->ProjectMap.clear(); // make sure we start with a clean map
  1846. unsigned int i;
  1847. for(i = 0; i < this->LocalGenerators.size(); ++i)
  1848. {
  1849. // for each local generator add all projects
  1850. cmLocalGenerator *lg = this->LocalGenerators[i];
  1851. std::string name;
  1852. do
  1853. {
  1854. if (name != lg->GetMakefile()->GetProjectName())
  1855. {
  1856. name = lg->GetMakefile()->GetProjectName();
  1857. this->ProjectMap[name].push_back(this->LocalGenerators[i]);
  1858. }
  1859. lg = lg->GetParent();
  1860. }
  1861. while (lg);
  1862. }
  1863. }
  1864. // Build a map that contains a the set of targets used by each local
  1865. // generator directory level.
  1866. void cmGlobalGenerator::FillLocalGeneratorToTargetMap()
  1867. {
  1868. this->LocalGeneratorToTargetMap.clear();
  1869. // Loop over all targets in all local generators.
  1870. for(std::vector<cmLocalGenerator*>::const_iterator
  1871. lgi = this->LocalGenerators.begin();
  1872. lgi != this->LocalGenerators.end(); ++lgi)
  1873. {
  1874. cmLocalGenerator* lg = *lgi;
  1875. cmMakefile* mf = lg->GetMakefile();
  1876. cmTargets const& targets = mf->GetTargets();
  1877. for(cmTargets::const_iterator t = targets.begin(); t != targets.end(); ++t)
  1878. {
  1879. cmTarget const& target = t->second;
  1880. // Consider the directory containing the target and all its
  1881. // parents until something excludes the target.
  1882. for(cmLocalGenerator* clg = lg; clg && !this->IsExcluded(clg, target);
  1883. clg = clg->GetParent())
  1884. {
  1885. // This local generator includes the target.
  1886. std::set<cmTarget const*>& targetSet =
  1887. this->LocalGeneratorToTargetMap[clg];
  1888. targetSet.insert(&target);
  1889. // Add dependencies of the included target. An excluded
  1890. // target may still be included if it is a dependency of a
  1891. // non-excluded target.
  1892. TargetDependSet const& tgtdeps = this->GetTargetDirectDepends(target);
  1893. for(TargetDependSet::const_iterator ti = tgtdeps.begin();
  1894. ti != tgtdeps.end(); ++ti)
  1895. {
  1896. cmTarget const* ttt = *ti;
  1897. targetSet.insert(ttt);
  1898. }
  1899. }
  1900. }
  1901. }
  1902. }
  1903. ///! Find a local generator by its startdirectory
  1904. cmLocalGenerator*
  1905. cmGlobalGenerator::FindLocalGenerator(const std::string& start_dir) const
  1906. {
  1907. for(std::vector<cmLocalGenerator*>::const_iterator it =
  1908. this->LocalGenerators.begin(); it != this->LocalGenerators.end(); ++it)
  1909. {
  1910. std::string sd = (*it)->GetMakefile()->GetStartDirectory();
  1911. if (sd == start_dir)
  1912. {
  1913. return *it;
  1914. }
  1915. }
  1916. return 0;
  1917. }
  1918. //----------------------------------------------------------------------------
  1919. void cmGlobalGenerator::AddAlias(const std::string& name, cmTarget *tgt)
  1920. {
  1921. this->AliasTargets[name] = tgt;
  1922. }
  1923. //----------------------------------------------------------------------------
  1924. bool cmGlobalGenerator::IsAlias(const std::string& name) const
  1925. {
  1926. return this->AliasTargets.find(name) != this->AliasTargets.end();
  1927. }
  1928. //----------------------------------------------------------------------------
  1929. cmTarget*
  1930. cmGlobalGenerator::FindTarget(const std::string& name,
  1931. bool excludeAliases) const
  1932. {
  1933. if (!excludeAliases)
  1934. {
  1935. std::map<std::string, cmTarget*>::const_iterator ai
  1936. = this->AliasTargets.find(name);
  1937. if (ai != this->AliasTargets.end())
  1938. {
  1939. return ai->second;
  1940. }
  1941. }
  1942. std::map<std::string,cmTarget *>::const_iterator i =
  1943. this->TotalTargets.find ( name );
  1944. if ( i != this->TotalTargets.end() )
  1945. {
  1946. return i->second;
  1947. }
  1948. i = this->ImportedTargets.find(name);
  1949. if ( i != this->ImportedTargets.end() )
  1950. {
  1951. return i->second;
  1952. }
  1953. return 0;
  1954. }
  1955. //----------------------------------------------------------------------------
  1956. bool
  1957. cmGlobalGenerator::NameResolvesToFramework(const std::string& libname) const
  1958. {
  1959. if(cmSystemTools::IsPathToFramework(libname.c_str()))
  1960. {
  1961. return true;
  1962. }
  1963. if(cmTarget* tgt = this->FindTarget(libname))
  1964. {
  1965. if(tgt->IsFrameworkOnApple())
  1966. {
  1967. return true;
  1968. }
  1969. }
  1970. return false;
  1971. }
  1972. //----------------------------------------------------------------------------
  1973. inline std::string removeQuotes(const std::string& s)
  1974. {
  1975. if(s[0] == '\"' && s[s.size()-1] == '\"')
  1976. {
  1977. return s.substr(1, s.size()-2);
  1978. }
  1979. return s;
  1980. }
  1981. void cmGlobalGenerator::SetCMakeInstance(cmake* cm)
  1982. {
  1983. // Store a pointer to the cmake object instance.
  1984. this->CMakeInstance = cm;
  1985. }
  1986. void cmGlobalGenerator::CreateDefaultGlobalTargets(cmTargets* targets)
  1987. {
  1988. cmMakefile* mf = this->LocalGenerators[0]->GetMakefile();
  1989. const char* cmakeCfgIntDir = this->GetCMakeCFGIntDir();
  1990. const char* cmakeCommand = mf->GetRequiredDefinition("CMAKE_COMMAND");
  1991. // CPack
  1992. std::string workingDir = mf->GetStartOutputDirectory();
  1993. cmCustomCommandLines cpackCommandLines;
  1994. std::vector<std::string> depends;
  1995. cmCustomCommandLine singleLine;
  1996. singleLine.push_back(cmSystemTools::GetCPackCommand());
  1997. if ( cmakeCfgIntDir && *cmakeCfgIntDir && cmakeCfgIntDir[0] != '.' )
  1998. {
  1999. singleLine.push_back("-C");
  2000. singleLine.push_back(cmakeCfgIntDir);
  2001. }
  2002. singleLine.push_back("--config");
  2003. std::string configFile = mf->GetStartOutputDirectory();;
  2004. configFile += "/CPackConfig.cmake";
  2005. std::string relConfigFile = "./CPackConfig.cmake";
  2006. singleLine.push_back(relConfigFile);
  2007. cpackCommandLines.push_back(singleLine);
  2008. if ( this->GetPreinstallTargetName() )
  2009. {
  2010. depends.push_back(this->GetPreinstallTargetName());
  2011. }
  2012. else
  2013. {
  2014. const char* noPackageAll =
  2015. mf->GetDefinition("CMAKE_SKIP_PACKAGE_ALL_DEPENDENCY");
  2016. if(!noPackageAll || cmSystemTools::IsOff(noPackageAll))
  2017. {
  2018. depends.push_back(this->GetAllTargetName());
  2019. }
  2020. }
  2021. if(cmSystemTools::FileExists(configFile.c_str()))
  2022. {
  2023. (*targets)[this->GetPackageTargetName()]
  2024. = this->CreateGlobalTarget(this->GetPackageTargetName(),
  2025. "Run CPack packaging tool...",
  2026. &cpackCommandLines, depends,
  2027. workingDir.c_str());
  2028. }
  2029. // CPack source
  2030. const char* packageSourceTargetName = this->GetPackageSourceTargetName();
  2031. if ( packageSourceTargetName )
  2032. {
  2033. cpackCommandLines.erase(cpackCommandLines.begin(),
  2034. cpackCommandLines.end());
  2035. singleLine.erase(singleLine.begin(), singleLine.end());
  2036. depends.erase(depends.begin(), depends.end());
  2037. singleLine.push_back(cmSystemTools::GetCPackCommand());
  2038. singleLine.push_back("--config");
  2039. configFile = mf->GetStartOutputDirectory();;
  2040. configFile += "/CPackSourceConfig.cmake";
  2041. relConfigFile = "./CPackSourceConfig.cmake";
  2042. singleLine.push_back(relConfigFile);
  2043. if(cmSystemTools::FileExists(configFile.c_str()))
  2044. {
  2045. singleLine.push_back(configFile);
  2046. cpackCommandLines.push_back(singleLine);
  2047. (*targets)[packageSourceTargetName]
  2048. = this->CreateGlobalTarget(packageSourceTargetName,
  2049. "Run CPack packaging tool for source...",
  2050. &cpackCommandLines, depends,
  2051. workingDir.c_str()
  2052. );
  2053. }
  2054. }
  2055. // Test
  2056. if(mf->IsOn("CMAKE_TESTING_ENABLED"))
  2057. {
  2058. cpackCommandLines.erase(cpackCommandLines.begin(),
  2059. cpackCommandLines.end());
  2060. singleLine.erase(singleLine.begin(), singleLine.end());
  2061. depends.erase(depends.begin(), depends.end());
  2062. singleLine.push_back(cmSystemTools::GetCTestCommand());
  2063. singleLine.push_back("--force-new-ctest-process");
  2064. if(cmakeCfgIntDir && *cmakeCfgIntDir && cmakeCfgIntDir[0] != '.')
  2065. {
  2066. singleLine.push_back("-C");
  2067. singleLine.push_back(cmakeCfgIntDir);
  2068. }
  2069. else // TODO: This is a hack. Should be something to do with the generator
  2070. {
  2071. singleLine.push_back("$(ARGS)");
  2072. }
  2073. cpackCommandLines.push_back(singleLine);
  2074. (*targets)[this->GetTestTargetName()]
  2075. = this->CreateGlobalTarget(this->GetTestTargetName(),
  2076. "Running tests...", &cpackCommandLines, depends, 0);
  2077. }
  2078. //Edit Cache
  2079. const char* editCacheTargetName = this->GetEditCacheTargetName();
  2080. if ( editCacheTargetName )
  2081. {
  2082. cpackCommandLines.erase(cpackCommandLines.begin(),
  2083. cpackCommandLines.end());
  2084. singleLine.erase(singleLine.begin(), singleLine.end());
  2085. depends.erase(depends.begin(), depends.end());
  2086. // Use generator preference for the edit_cache rule if it is defined.
  2087. std::string edit_cmd = this->GetEditCacheCommand();
  2088. if (!edit_cmd.empty())
  2089. {
  2090. singleLine.push_back(edit_cmd);
  2091. singleLine.push_back("-H$(CMAKE_SOURCE_DIR)");
  2092. singleLine.push_back("-B$(CMAKE_BINARY_DIR)");
  2093. cpackCommandLines.push_back(singleLine);
  2094. (*targets)[editCacheTargetName] =
  2095. this->CreateGlobalTarget(
  2096. editCacheTargetName, "Running CMake cache editor...",
  2097. &cpackCommandLines, depends, 0);
  2098. }
  2099. else
  2100. {
  2101. singleLine.push_back(cmakeCommand);
  2102. singleLine.push_back("-E");
  2103. singleLine.push_back("echo");
  2104. singleLine.push_back("No interactive CMake dialog available.");
  2105. cpackCommandLines.push_back(singleLine);
  2106. (*targets)[editCacheTargetName] =
  2107. this->CreateGlobalTarget(
  2108. editCacheTargetName,
  2109. "No interactive CMake dialog available...",
  2110. &cpackCommandLines, depends, 0);
  2111. }
  2112. }
  2113. //Rebuild Cache
  2114. const char* rebuildCacheTargetName = this->GetRebuildCacheTargetName();
  2115. if ( rebuildCacheTargetName )
  2116. {
  2117. cpackCommandLines.erase(cpackCommandLines.begin(),
  2118. cpackCommandLines.end());
  2119. singleLine.erase(singleLine.begin(), singleLine.end());
  2120. depends.erase(depends.begin(), depends.end());
  2121. singleLine.push_back(cmakeCommand);
  2122. singleLine.push_back("-H$(CMAKE_SOURCE_DIR)");
  2123. singleLine.push_back("-B$(CMAKE_BINARY_DIR)");
  2124. cpackCommandLines.push_back(singleLine);
  2125. (*targets)[rebuildCacheTargetName] =
  2126. this->CreateGlobalTarget(
  2127. rebuildCacheTargetName, "Running CMake to regenerate build system...",
  2128. &cpackCommandLines, depends, 0);
  2129. }
  2130. //Install
  2131. bool skipInstallRules = mf->IsOn("CMAKE_SKIP_INSTALL_RULES");
  2132. if(this->InstallTargetEnabled && skipInstallRules)
  2133. {
  2134. mf->IssueMessage(cmake::WARNING,
  2135. "CMAKE_SKIP_INSTALL_RULES was enabled even though "
  2136. "installation rules have been specified");
  2137. }
  2138. else if(this->InstallTargetEnabled && !skipInstallRules)
  2139. {
  2140. if(!cmakeCfgIntDir || !*cmakeCfgIntDir || cmakeCfgIntDir[0] == '.')
  2141. {
  2142. std::set<std::string>* componentsSet = &this->InstallComponents;
  2143. cpackCommandLines.erase(cpackCommandLines.begin(),
  2144. cpackCommandLines.end());
  2145. depends.erase(depends.begin(), depends.end());
  2146. cmOStringStream ostr;
  2147. if ( componentsSet->size() > 0 )
  2148. {
  2149. ostr << "Available install components are:";
  2150. std::set<std::string>::iterator it;
  2151. for (
  2152. it = componentsSet->begin();
  2153. it != componentsSet->end();
  2154. ++ it )
  2155. {
  2156. ostr << " \"" << *it << "\"";
  2157. }
  2158. }
  2159. else
  2160. {
  2161. ostr << "Only default component available";
  2162. }
  2163. singleLine.push_back(ostr.str());
  2164. (*targets)["list_install_components"]
  2165. = this->CreateGlobalTarget("list_install_components",
  2166. ostr.str().c_str(),
  2167. &cpackCommandLines, depends, 0);
  2168. }
  2169. std::string cmd = cmakeCommand;
  2170. cpackCommandLines.erase(cpackCommandLines.begin(),
  2171. cpackCommandLines.end());
  2172. singleLine.erase(singleLine.begin(), singleLine.end());
  2173. depends.erase(depends.begin(), depends.end());
  2174. if ( this->GetPreinstallTargetName() )
  2175. {
  2176. depends.push_back(this->GetPreinstallTargetName());
  2177. }
  2178. else
  2179. {
  2180. const char* noall =
  2181. mf->GetDefinition("CMAKE_SKIP_INSTALL_ALL_DEPENDENCY");
  2182. if(!noall || cmSystemTools::IsOff(noall))
  2183. {
  2184. depends.push_back(this->GetAllTargetName());
  2185. }
  2186. }
  2187. if(mf->GetDefinition("CMake_BINARY_DIR"))
  2188. {
  2189. // We are building CMake itself. We cannot use the original
  2190. // executable to install over itself. The generator will
  2191. // automatically convert this name to the build-time location.
  2192. cmd = "cmake";
  2193. }
  2194. singleLine.push_back(cmd);
  2195. if ( cmakeCfgIntDir && *cmakeCfgIntDir && cmakeCfgIntDir[0] != '.' )
  2196. {
  2197. std::string cfgArg = "-DBUILD_TYPE=";
  2198. cfgArg += mf->GetDefinition("CMAKE_CFG_INTDIR");
  2199. singleLine.push_back(cfgArg);
  2200. }
  2201. singleLine.push_back("-P");
  2202. singleLine.push_back("cmake_install.cmake");
  2203. cpackCommandLines.push_back(singleLine);
  2204. (*targets)[this->GetInstallTargetName()] =
  2205. this->CreateGlobalTarget(
  2206. this->GetInstallTargetName(), "Install the project...",
  2207. &cpackCommandLines, depends, 0);
  2208. // install_local
  2209. if(const char* install_local = this->GetInstallLocalTargetName())
  2210. {
  2211. cmCustomCommandLine localCmdLine = singleLine;
  2212. localCmdLine.insert(localCmdLine.begin()+1,
  2213. "-DCMAKE_INSTALL_LOCAL_ONLY=1");
  2214. cpackCommandLines.erase(cpackCommandLines.begin(),
  2215. cpackCommandLines.end());
  2216. cpackCommandLines.push_back(localCmdLine);
  2217. (*targets)[install_local] =
  2218. this->CreateGlobalTarget(
  2219. install_local, "Installing only the local directory...",
  2220. &cpackCommandLines, depends, 0);
  2221. }
  2222. // install_strip
  2223. const char* install_strip = this->GetInstallStripTargetName();
  2224. if((install_strip !=0) && (mf->IsSet("CMAKE_STRIP")))
  2225. {
  2226. cmCustomCommandLine stripCmdLine = singleLine;
  2227. stripCmdLine.insert(stripCmdLine.begin()+1,"-DCMAKE_INSTALL_DO_STRIP=1");
  2228. cpackCommandLines.erase(cpackCommandLines.begin(),
  2229. cpackCommandLines.end());
  2230. cpackCommandLines.push_back(stripCmdLine);
  2231. (*targets)[install_strip] =
  2232. this->CreateGlobalTarget(
  2233. install_strip, "Installing the project stripped...",
  2234. &cpackCommandLines, depends, 0);
  2235. }
  2236. }
  2237. }
  2238. //----------------------------------------------------------------------------
  2239. const char* cmGlobalGenerator::GetPredefinedTargetsFolder()
  2240. {
  2241. const char* prop =
  2242. this->GetCMakeInstance()->GetProperty("PREDEFINED_TARGETS_FOLDER");
  2243. if (prop)
  2244. {
  2245. return prop;
  2246. }
  2247. return "CMakePredefinedTargets";
  2248. }
  2249. //----------------------------------------------------------------------------
  2250. bool cmGlobalGenerator::UseFolderProperty()
  2251. {
  2252. const char* prop = this->GetCMakeInstance()->GetProperty("USE_FOLDERS");
  2253. // If this property is defined, let the setter turn this on or off...
  2254. //
  2255. if (prop)
  2256. {
  2257. return cmSystemTools::IsOn(prop);
  2258. }
  2259. // By default, this feature is OFF, since it is not supported in the
  2260. // Visual Studio Express editions until VS11:
  2261. //
  2262. return false;
  2263. }
  2264. //----------------------------------------------------------------------------
  2265. void cmGlobalGenerator::EnableMinGWLanguage(cmMakefile *mf)
  2266. {
  2267. this->FindMakeProgram(mf);
  2268. std::string makeProgram = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
  2269. std::vector<std::string> locations;
  2270. locations.push_back(cmSystemTools::GetProgramPath(makeProgram.c_str()));
  2271. locations.push_back("/mingw/bin");
  2272. locations.push_back("c:/mingw/bin");
  2273. std::string tgcc = cmSystemTools::FindProgram("gcc", locations);
  2274. std::string gcc = "gcc.exe";
  2275. if(tgcc.size())
  2276. {
  2277. gcc = tgcc;
  2278. }
  2279. std::string tgxx = cmSystemTools::FindProgram("g++", locations);
  2280. std::string gxx = "g++.exe";
  2281. if(tgxx.size())
  2282. {
  2283. gxx = tgxx;
  2284. }
  2285. std::string trc = cmSystemTools::FindProgram("windres", locations);
  2286. std::string rc = "windres.exe";
  2287. if(trc.size())
  2288. {
  2289. rc = trc;
  2290. }
  2291. mf->AddDefinition("CMAKE_GENERATOR_CC", gcc.c_str());
  2292. mf->AddDefinition("CMAKE_GENERATOR_CXX", gxx.c_str());
  2293. mf->AddDefinition("CMAKE_GENERATOR_RC", rc.c_str());
  2294. }
  2295. //----------------------------------------------------------------------------
  2296. cmTarget cmGlobalGenerator::CreateGlobalTarget(
  2297. const std::string& name, const char* message,
  2298. const cmCustomCommandLines* commandLines,
  2299. std::vector<std::string> depends,
  2300. const char* workingDirectory)
  2301. {
  2302. // Package
  2303. cmTarget target;
  2304. target.GetProperties().SetCMakeInstance(this->CMakeInstance);
  2305. target.SetType(cmTarget::GLOBAL_TARGET, name);
  2306. target.SetProperty("EXCLUDE_FROM_ALL","TRUE");
  2307. std::vector<std::string> no_outputs;
  2308. std::vector<std::string> no_depends;
  2309. // Store the custom command in the target.
  2310. cmCustomCommand cc(0, no_outputs, no_depends, *commandLines, 0,
  2311. workingDirectory);
  2312. target.AddPostBuildCommand(cc);
  2313. target.SetProperty("EchoString", message);
  2314. std::vector<std::string>::iterator dit;
  2315. for ( dit = depends.begin(); dit != depends.end(); ++ dit )
  2316. {
  2317. target.AddUtility(*dit);
  2318. }
  2319. // Organize in the "predefined targets" folder:
  2320. //
  2321. if (this->UseFolderProperty())
  2322. {
  2323. target.SetProperty("FOLDER", this->GetPredefinedTargetsFolder());
  2324. }
  2325. return target;
  2326. }
  2327. //----------------------------------------------------------------------------
  2328. std::string
  2329. cmGlobalGenerator::GenerateRuleFile(std::string const& output) const
  2330. {
  2331. std::string ruleFile = output;
  2332. ruleFile += ".rule";
  2333. const char* dir = this->GetCMakeCFGIntDir();
  2334. if(dir && dir[0] == '$')
  2335. {
  2336. cmSystemTools::ReplaceString(ruleFile, dir,
  2337. cmake::GetCMakeFilesDirectory());
  2338. }
  2339. return ruleFile;
  2340. }
  2341. //----------------------------------------------------------------------------
  2342. std::string cmGlobalGenerator::GetSharedLibFlagsForLanguage(
  2343. std::string const& l) const
  2344. {
  2345. std::map<std::string, std::string>::const_iterator it =
  2346. this->LanguageToOriginalSharedLibFlags.find(l);
  2347. if(it != this->LanguageToOriginalSharedLibFlags.end())
  2348. {
  2349. return it->second;
  2350. }
  2351. return "";
  2352. }
  2353. //----------------------------------------------------------------------------
  2354. void cmGlobalGenerator::AppendDirectoryForConfig(const std::string&,
  2355. const std::string&,
  2356. const std::string&,
  2357. std::string&)
  2358. {
  2359. // Subclasses that support multiple configurations should implement
  2360. // this method to append the subdirectory for the given build
  2361. // configuration.
  2362. }
  2363. //----------------------------------------------------------------------------
  2364. cmGlobalGenerator::TargetDependSet const&
  2365. cmGlobalGenerator::GetTargetDirectDepends(cmTarget const& target)
  2366. {
  2367. return this->TargetDependencies[&target];
  2368. }
  2369. void cmGlobalGenerator::AddTarget(cmTarget* t)
  2370. {
  2371. if(t->IsImported())
  2372. {
  2373. this->ImportedTargets[t->GetName()] = t;
  2374. }
  2375. else
  2376. {
  2377. this->TotalTargets[t->GetName()] = t;
  2378. }
  2379. }
  2380. bool cmGlobalGenerator::IsReservedTarget(std::string const& name)
  2381. {
  2382. // The following is a list of targets reserved
  2383. // by one or more of the cmake generators.
  2384. // Adding additional targets to this list will require a policy!
  2385. const char* reservedTargets[] =
  2386. {
  2387. "all", "ALL_BUILD",
  2388. "help",
  2389. "install", "INSTALL",
  2390. "preinstall",
  2391. "clean",
  2392. "edit_cache",
  2393. "rebuild_cache",
  2394. "test", "RUN_TESTS",
  2395. "package", "PACKAGE",
  2396. "package_source",
  2397. "ZERO_CHECK",
  2398. 0
  2399. };
  2400. for(const char** reservedTarget = reservedTargets;
  2401. *reservedTarget; ++reservedTarget)
  2402. {
  2403. if(name == *reservedTarget) return true;
  2404. }
  2405. return false;
  2406. }
  2407. void cmGlobalGenerator::SetExternalMakefileProjectGenerator(
  2408. cmExternalMakefileProjectGenerator *extraGenerator)
  2409. {
  2410. this->ExtraGenerator = extraGenerator;
  2411. if (this->ExtraGenerator!=0)
  2412. {
  2413. this->ExtraGenerator->SetGlobalGenerator(this);
  2414. }
  2415. }
  2416. std::string cmGlobalGenerator::GetExtraGeneratorName() const
  2417. {
  2418. return this->ExtraGenerator? this->ExtraGenerator->GetName() : std::string();
  2419. }
  2420. void cmGlobalGenerator::FileReplacedDuringGenerate(const std::string& filename)
  2421. {
  2422. this->FilesReplacedDuringGenerate.push_back(filename);
  2423. }
  2424. void
  2425. cmGlobalGenerator
  2426. ::GetFilesReplacedDuringGenerate(std::vector<std::string>& filenames)
  2427. {
  2428. filenames.clear();
  2429. std::copy(
  2430. this->FilesReplacedDuringGenerate.begin(),
  2431. this->FilesReplacedDuringGenerate.end(),
  2432. std::back_inserter(filenames));
  2433. }
  2434. //----------------------------------------------------------------------------
  2435. void cmGlobalGenerator::GetTargetSets(TargetDependSet& projectTargets,
  2436. TargetDependSet& originalTargets,
  2437. cmLocalGenerator* root,
  2438. GeneratorVector const& generators)
  2439. {
  2440. // loop over all local generators
  2441. for(std::vector<cmLocalGenerator*>::const_iterator i = generators.begin();
  2442. i != generators.end(); ++i)
  2443. {
  2444. // check to make sure generator is not excluded
  2445. if(this->IsExcluded(root, *i))
  2446. {
  2447. continue;
  2448. }
  2449. cmMakefile* mf = (*i)->GetMakefile();
  2450. // Get the targets in the makefile
  2451. cmTargets &tgts = mf->GetTargets();
  2452. // loop over all the targets
  2453. for (cmTargets::iterator l = tgts.begin(); l != tgts.end(); ++l)
  2454. {
  2455. cmTarget* target = &l->second;
  2456. if(this->IsRootOnlyTarget(target) &&
  2457. target->GetMakefile() != root->GetMakefile())
  2458. {
  2459. continue;
  2460. }
  2461. // put the target in the set of original targets
  2462. originalTargets.insert(target);
  2463. // Get the set of targets that depend on target
  2464. this->AddTargetDepends(target, projectTargets);
  2465. }
  2466. }
  2467. }
  2468. //----------------------------------------------------------------------------
  2469. bool cmGlobalGenerator::IsRootOnlyTarget(cmTarget* target) const
  2470. {
  2471. return (target->GetType() == cmTarget::GLOBAL_TARGET ||
  2472. target->GetName() == this->GetAllTargetName());
  2473. }
  2474. //----------------------------------------------------------------------------
  2475. void cmGlobalGenerator::AddTargetDepends(cmTarget const* target,
  2476. TargetDependSet& projectTargets)
  2477. {
  2478. // add the target itself
  2479. if(projectTargets.insert(target).second)
  2480. {
  2481. // This is the first time we have encountered the target.
  2482. // Recursively follow its dependencies.
  2483. TargetDependSet const& ts = this->GetTargetDirectDepends(*target);
  2484. for(TargetDependSet::const_iterator i = ts.begin(); i != ts.end(); ++i)
  2485. {
  2486. cmTarget const* dtarget = *i;
  2487. this->AddTargetDepends(dtarget, projectTargets);
  2488. }
  2489. }
  2490. }
  2491. //----------------------------------------------------------------------------
  2492. void cmGlobalGenerator::AddToManifest(const std::string& config,
  2493. std::string const& f)
  2494. {
  2495. // Add to the main manifest for this configuration.
  2496. this->TargetManifest[config].insert(f);
  2497. // Add to the content listing for the file's directory.
  2498. std::string dir = cmSystemTools::GetFilenamePath(f);
  2499. std::string file = cmSystemTools::GetFilenameName(f);
  2500. this->DirectoryContentMap[dir].insert(file);
  2501. }
  2502. //----------------------------------------------------------------------------
  2503. std::set<std::string> const&
  2504. cmGlobalGenerator::GetDirectoryContent(std::string const& dir, bool needDisk)
  2505. {
  2506. DirectoryContent& dc = this->DirectoryContentMap[dir];
  2507. if(needDisk && !dc.LoadedFromDisk)
  2508. {
  2509. // Load the directory content from disk.
  2510. cmsys::Directory d;
  2511. if(d.Load(dir.c_str()))
  2512. {
  2513. unsigned long n = d.GetNumberOfFiles();
  2514. for(unsigned long i = 0; i < n; ++i)
  2515. {
  2516. const char* f = d.GetFile(i);
  2517. if(strcmp(f, ".") != 0 && strcmp(f, "..") != 0)
  2518. {
  2519. dc.insert(f);
  2520. }
  2521. }
  2522. }
  2523. dc.LoadedFromDisk = true;
  2524. }
  2525. return dc;
  2526. }
  2527. //----------------------------------------------------------------------------
  2528. void
  2529. cmGlobalGenerator::AddRuleHash(const std::vector<std::string>& outputs,
  2530. std::string const& content)
  2531. {
  2532. #if defined(CMAKE_BUILD_WITH_CMAKE)
  2533. // Ignore if there are no outputs.
  2534. if(outputs.empty())
  2535. {
  2536. return;
  2537. }
  2538. // Compute a hash of the rule.
  2539. RuleHash hash;
  2540. {
  2541. unsigned char const* data =
  2542. reinterpret_cast<unsigned char const*>(content.c_str());
  2543. int length = static_cast<int>(content.length());
  2544. cmsysMD5* sum = cmsysMD5_New();
  2545. cmsysMD5_Initialize(sum);
  2546. cmsysMD5_Append(sum, data, length);
  2547. cmsysMD5_FinalizeHex(sum, hash.Data);
  2548. cmsysMD5_Delete(sum);
  2549. }
  2550. // Shorten the output name (in expected use case).
  2551. cmLocalGenerator* lg = this->GetLocalGenerators()[0];
  2552. std::string fname = lg->Convert(outputs[0],
  2553. cmLocalGenerator::HOME_OUTPUT);
  2554. // Associate the hash with this output.
  2555. this->RuleHashes[fname] = hash;
  2556. #else
  2557. (void)outputs;
  2558. (void)content;
  2559. #endif
  2560. }
  2561. //----------------------------------------------------------------------------
  2562. void cmGlobalGenerator::CheckRuleHashes()
  2563. {
  2564. #if defined(CMAKE_BUILD_WITH_CMAKE)
  2565. std::string home = this->GetCMakeInstance()->GetHomeOutputDirectory();
  2566. std::string pfile = home;
  2567. pfile += this->GetCMakeInstance()->GetCMakeFilesDirectory();
  2568. pfile += "/CMakeRuleHashes.txt";
  2569. this->CheckRuleHashes(pfile, home);
  2570. this->WriteRuleHashes(pfile);
  2571. #endif
  2572. }
  2573. //----------------------------------------------------------------------------
  2574. void cmGlobalGenerator::CheckRuleHashes(std::string const& pfile,
  2575. std::string const& home)
  2576. {
  2577. #if defined(_WIN32) || defined(__CYGWIN__)
  2578. cmsys::ifstream fin(pfile.c_str(), std::ios::in | std::ios::binary);
  2579. #else
  2580. cmsys::ifstream fin(pfile.c_str(), std::ios::in);
  2581. #endif
  2582. if(!fin)
  2583. {
  2584. return;
  2585. }
  2586. std::string line;
  2587. std::string fname;
  2588. while(cmSystemTools::GetLineFromStream(fin, line))
  2589. {
  2590. // Line format is a 32-byte hex string followed by a space
  2591. // followed by a file name (with no escaping).
  2592. // Skip blank and comment lines.
  2593. if(line.size() < 34 || line[0] == '#')
  2594. {
  2595. continue;
  2596. }
  2597. // Get the filename.
  2598. fname = line.substr(33, line.npos);
  2599. // Look for a hash for this file's rule.
  2600. std::map<std::string, RuleHash>::const_iterator rhi =
  2601. this->RuleHashes.find(fname);
  2602. if(rhi != this->RuleHashes.end())
  2603. {
  2604. // Compare the rule hash in the file to that we were given.
  2605. if(strncmp(line.c_str(), rhi->second.Data, 32) != 0)
  2606. {
  2607. // The rule has changed. Delete the output so it will be
  2608. // built again.
  2609. fname = cmSystemTools::CollapseFullPath(fname.c_str(), home.c_str());
  2610. cmSystemTools::RemoveFile(fname.c_str());
  2611. }
  2612. }
  2613. else
  2614. {
  2615. // We have no hash for a rule previously listed. This may be a
  2616. // case where a user has turned off a build option and might
  2617. // want to turn it back on later, so do not delete the file.
  2618. // Instead, we keep the rule hash as long as the file exists so
  2619. // that if the feature is turned back on and the rule has
  2620. // changed the file is still rebuilt.
  2621. std::string fpath =
  2622. cmSystemTools::CollapseFullPath(fname.c_str(), home.c_str());
  2623. if(cmSystemTools::FileExists(fpath.c_str()))
  2624. {
  2625. RuleHash hash;
  2626. strncpy(hash.Data, line.c_str(), 32);
  2627. this->RuleHashes[fname] = hash;
  2628. }
  2629. }
  2630. }
  2631. }
  2632. //----------------------------------------------------------------------------
  2633. void cmGlobalGenerator::WriteRuleHashes(std::string const& pfile)
  2634. {
  2635. // Now generate a new persistence file with the current hashes.
  2636. if(this->RuleHashes.empty())
  2637. {
  2638. cmSystemTools::RemoveFile(pfile.c_str());
  2639. }
  2640. else
  2641. {
  2642. cmGeneratedFileStream fout(pfile.c_str());
  2643. fout << "# Hashes of file build rules.\n";
  2644. for(std::map<std::string, RuleHash>::const_iterator
  2645. rhi = this->RuleHashes.begin(); rhi != this->RuleHashes.end(); ++rhi)
  2646. {
  2647. fout.write(rhi->second.Data, 32);
  2648. fout << " " << rhi->first << "\n";
  2649. }
  2650. }
  2651. }
  2652. //----------------------------------------------------------------------------
  2653. void cmGlobalGenerator::WriteSummary()
  2654. {
  2655. cmMakefile* mf = this->LocalGenerators[0]->GetMakefile();
  2656. // Record all target directories in a central location.
  2657. std::string fname = mf->GetHomeOutputDirectory();
  2658. fname += cmake::GetCMakeFilesDirectory();
  2659. fname += "/TargetDirectories.txt";
  2660. cmGeneratedFileStream fout(fname.c_str());
  2661. // Generate summary information files for each target.
  2662. for(std::map<std::string,cmTarget *>::const_iterator ti =
  2663. this->TotalTargets.begin(); ti != this->TotalTargets.end(); ++ti)
  2664. {
  2665. if ((ti->second)->GetType() == cmTarget::INTERFACE_LIBRARY)
  2666. {
  2667. continue;
  2668. }
  2669. this->WriteSummary(ti->second);
  2670. fout << ti->second->GetSupportDirectory() << "\n";
  2671. }
  2672. }
  2673. //----------------------------------------------------------------------------
  2674. void cmGlobalGenerator::WriteSummary(cmTarget* target)
  2675. {
  2676. // Place the labels file in a per-target support directory.
  2677. std::string dir = target->GetSupportDirectory();
  2678. std::string file = dir;
  2679. file += "/Labels.txt";
  2680. // Check whether labels are enabled for this target.
  2681. if(const char* value = target->GetProperty("LABELS"))
  2682. {
  2683. cmSystemTools::MakeDirectory(dir.c_str());
  2684. cmGeneratedFileStream fout(file.c_str());
  2685. // List the target-wide labels. All sources in the target get
  2686. // these labels.
  2687. std::vector<std::string> labels;
  2688. cmSystemTools::ExpandListArgument(value, labels);
  2689. if(!labels.empty())
  2690. {
  2691. fout << "# Target labels\n";
  2692. for(std::vector<std::string>::const_iterator li = labels.begin();
  2693. li != labels.end(); ++li)
  2694. {
  2695. fout << " " << *li << "\n";
  2696. }
  2697. }
  2698. // List the source files with any per-source labels.
  2699. fout << "# Source files and their labels\n";
  2700. std::vector<cmSourceFile*> sources;
  2701. target->GetSourceFiles(sources);
  2702. for(std::vector<cmSourceFile*>::const_iterator si = sources.begin();
  2703. si != sources.end(); ++si)
  2704. {
  2705. cmSourceFile* sf = *si;
  2706. fout << sf->GetFullPath() << "\n";
  2707. if(const char* svalue = sf->GetProperty("LABELS"))
  2708. {
  2709. labels.clear();
  2710. cmSystemTools::ExpandListArgument(svalue, labels);
  2711. for(std::vector<std::string>::const_iterator li = labels.begin();
  2712. li != labels.end(); ++li)
  2713. {
  2714. fout << " " << *li << "\n";
  2715. }
  2716. }
  2717. }
  2718. }
  2719. else
  2720. {
  2721. cmSystemTools::RemoveFile(file.c_str());
  2722. }
  2723. }
  2724. //----------------------------------------------------------------------------
  2725. // static
  2726. std::string cmGlobalGenerator::EscapeJSON(const std::string& s) {
  2727. std::string result;
  2728. for (std::string::size_type i = 0; i < s.size(); ++i) {
  2729. if (s[i] == '"' || s[i] == '\\') {
  2730. result += '\\';
  2731. }
  2732. result += s[i];
  2733. }
  2734. return result;
  2735. }
  2736. //----------------------------------------------------------------------------
  2737. void cmGlobalGenerator::AddEvaluationFile(const std::string &inputFile,
  2738. cmsys::auto_ptr<cmCompiledGeneratorExpression> outputExpr,
  2739. cmMakefile *makefile,
  2740. cmsys::auto_ptr<cmCompiledGeneratorExpression> condition,
  2741. bool inputIsContent)
  2742. {
  2743. this->EvaluationFiles.push_back(
  2744. new cmGeneratorExpressionEvaluationFile(inputFile, outputExpr,
  2745. makefile, condition,
  2746. inputIsContent));
  2747. }
  2748. //----------------------------------------------------------------------------
  2749. void cmGlobalGenerator::ProcessEvaluationFiles()
  2750. {
  2751. std::set<std::string> generatedFiles;
  2752. for(std::vector<cmGeneratorExpressionEvaluationFile*>::const_iterator
  2753. li = this->EvaluationFiles.begin();
  2754. li != this->EvaluationFiles.end();
  2755. ++li)
  2756. {
  2757. (*li)->Generate();
  2758. if (cmSystemTools::GetFatalErrorOccured())
  2759. {
  2760. return;
  2761. }
  2762. std::vector<std::string> files = (*li)->GetFiles();
  2763. for(std::vector<std::string>::const_iterator fi = files.begin();
  2764. fi != files.end(); ++fi)
  2765. {
  2766. if (!generatedFiles.insert(*fi).second)
  2767. {
  2768. cmSystemTools::Error("File to be generated by multiple different "
  2769. "commands: ", fi->c_str());
  2770. return;
  2771. }
  2772. }
  2773. }
  2774. }
  2775. //----------------------------------------------------------------------------
  2776. std::string cmGlobalGenerator::ExpandCFGIntDir(const std::string& str,
  2777. const std::string& /*config*/) const
  2778. {
  2779. return str;
  2780. }