cmGlobalGenerator.cxx 98 KB

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