cmGlobalGenerator.cxx 98 KB

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