cmGlobalGenerator.cxx 98 KB

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