cmGlobalGenerator.cxx 98 KB

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