cmGlobalGenerator.cxx 99 KB

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