cmGlobalGenerator.cxx 98 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124
  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. this->ComputeBuildFileGenerators();
  1105. }
  1106. void cmGlobalGenerator::CreateImportedGenerationObjects(cmMakefile* mf,
  1107. const std::vector<std::string>& targets,
  1108. std::vector<const cmGeneratorTarget*>& exports)
  1109. {
  1110. this->CreateGenerationObjects(ImportedOnly);
  1111. std::vector<cmMakefile*>::iterator mfit =
  1112. std::find(this->Makefiles.begin(), this->Makefiles.end(), mf);
  1113. cmLocalGenerator* lg =
  1114. this->LocalGenerators[std::distance(this->Makefiles.begin(), mfit)];
  1115. for (std::vector<std::string>::const_iterator it = targets.begin();
  1116. it != targets.end(); ++it)
  1117. {
  1118. cmGeneratorTarget* gt = lg->FindGeneratorTargetToUse(*it);
  1119. if (gt)
  1120. {
  1121. exports.push_back(gt);
  1122. }
  1123. }
  1124. }
  1125. cmExportBuildFileGenerator*
  1126. cmGlobalGenerator::GetExportedTargetsFile(const std::string &filename) const
  1127. {
  1128. std::map<std::string, cmExportBuildFileGenerator*>::const_iterator it
  1129. = this->BuildExportSets.find(filename);
  1130. return it == this->BuildExportSets.end() ? 0 : it->second;
  1131. }
  1132. //----------------------------------------------------------------------------
  1133. void cmGlobalGenerator::AddCMP0042WarnTarget(const std::string& target)
  1134. {
  1135. this->CMP0042WarnTargets.insert(target);
  1136. }
  1137. bool cmGlobalGenerator::CheckALLOW_DUPLICATE_CUSTOM_TARGETS() const
  1138. {
  1139. // If the property is not enabled then okay.
  1140. if(!this->CMakeInstance->GetState()
  1141. ->GetGlobalPropertyAsBool("ALLOW_DUPLICATE_CUSTOM_TARGETS"))
  1142. {
  1143. return true;
  1144. }
  1145. // This generator does not support duplicate custom targets.
  1146. std::ostringstream e;
  1147. e << "This project has enabled the ALLOW_DUPLICATE_CUSTOM_TARGETS "
  1148. << "global property. "
  1149. << "The \"" << this->GetName() << "\" generator does not support "
  1150. << "duplicate custom targets. "
  1151. << "Consider using a Makefiles generator or fix the project to not "
  1152. << "use duplicate target names.";
  1153. cmSystemTools::Error(e.str().c_str());
  1154. return false;
  1155. }
  1156. void cmGlobalGenerator::ComputeBuildFileGenerators()
  1157. {
  1158. for (unsigned int i = 0; i < this->LocalGenerators.size(); ++i)
  1159. {
  1160. std::vector<cmExportBuildFileGenerator*> gens =
  1161. this->Makefiles[i]->GetExportBuildFileGenerators();
  1162. for (std::vector<cmExportBuildFileGenerator*>::const_iterator it =
  1163. gens.begin(); it != gens.end(); ++it)
  1164. {
  1165. (*it)->Compute(this->LocalGenerators[i]);
  1166. }
  1167. }
  1168. }
  1169. bool cmGlobalGenerator::Compute()
  1170. {
  1171. // Some generators track files replaced during the Generate.
  1172. // Start with an empty vector:
  1173. this->FilesReplacedDuringGenerate.clear();
  1174. // clear targets to issue warning CMP0042 for
  1175. this->CMP0042WarnTargets.clear();
  1176. // Check whether this generator is allowed to run.
  1177. if(!this->CheckALLOW_DUPLICATE_CUSTOM_TARGETS())
  1178. {
  1179. return false;
  1180. }
  1181. this->FinalizeTargetCompileInfo();
  1182. this->CreateGenerationObjects();
  1183. // at this point this->LocalGenerators has been filled,
  1184. // so create the map from project name to vector of local generators
  1185. this->FillProjectMap();
  1186. #ifdef CMAKE_BUILD_WITH_CMAKE
  1187. // Iterate through all targets and set up automoc for those which have
  1188. // the AUTOMOC, AUTOUIC or AUTORCC property set
  1189. std::vector<cmGeneratorTarget const*> autogenTargets =
  1190. this->CreateQtAutoGeneratorsTargets();
  1191. #endif
  1192. unsigned int i;
  1193. // Add generator specific helper commands
  1194. for (i = 0; i < this->LocalGenerators.size(); ++i)
  1195. {
  1196. this->LocalGenerators[i]->AddHelperCommands();
  1197. }
  1198. #ifdef CMAKE_BUILD_WITH_CMAKE
  1199. for (std::vector<cmGeneratorTarget const*>::iterator it =
  1200. autogenTargets.begin(); it != autogenTargets.end(); ++it)
  1201. {
  1202. cmQtAutoGeneratorInitializer::SetupAutoGenerateTarget(*it);
  1203. }
  1204. #endif
  1205. for (i = 0; i < this->LocalGenerators.size(); ++i)
  1206. {
  1207. cmMakefile* mf = this->LocalGenerators[i]->GetMakefile();
  1208. std::vector<cmInstallGenerator*>& gens = mf->GetInstallGenerators();
  1209. for (std::vector<cmInstallGenerator*>::const_iterator git = gens.begin();
  1210. git != gens.end(); ++git)
  1211. {
  1212. (*git)->Compute(this->LocalGenerators[i]);
  1213. }
  1214. }
  1215. this->AddExtraIDETargets();
  1216. // Trace the dependencies, after that no custom commands should be added
  1217. // because their dependencies might not be handled correctly
  1218. for (i = 0; i < this->LocalGenerators.size(); ++i)
  1219. {
  1220. this->LocalGenerators[i]->TraceDependencies();
  1221. }
  1222. this->ForceLinkerLanguages();
  1223. // Compute the manifest of main targets generated.
  1224. for (i = 0; i < this->LocalGenerators.size(); ++i)
  1225. {
  1226. this->LocalGenerators[i]->ComputeTargetManifest();
  1227. }
  1228. // Compute the inter-target dependencies.
  1229. if(!this->ComputeTargetDepends())
  1230. {
  1231. return false;
  1232. }
  1233. for (i = 0; i < this->LocalGenerators.size(); ++i)
  1234. {
  1235. this->LocalGenerators[i]->ComputeHomeRelativeOutputPath();
  1236. }
  1237. return true;
  1238. }
  1239. void cmGlobalGenerator::Generate()
  1240. {
  1241. // Create a map from local generator to the complete set of targets
  1242. // it builds by default.
  1243. this->InitializeProgressMarks();
  1244. this->ProcessEvaluationFiles();
  1245. // Generate project files
  1246. for (unsigned int i = 0; i < this->LocalGenerators.size(); ++i)
  1247. {
  1248. this->SetCurrentMakefile(this->LocalGenerators[i]->GetMakefile());
  1249. this->LocalGenerators[i]->Generate();
  1250. if(!this->LocalGenerators[i]->GetMakefile()->IsOn(
  1251. "CMAKE_SKIP_INSTALL_RULES"))
  1252. {
  1253. this->LocalGenerators[i]->GenerateInstallRules();
  1254. }
  1255. this->LocalGenerators[i]->GenerateTestFiles();
  1256. this->CMakeInstance->UpdateProgress("Generating",
  1257. (static_cast<float>(i)+1.0f)/
  1258. static_cast<float>(this->LocalGenerators.size()));
  1259. }
  1260. this->SetCurrentMakefile(0);
  1261. if(!this->GenerateCPackPropertiesFile())
  1262. {
  1263. this->GetCMakeInstance()->IssueMessage(
  1264. cmake::FATAL_ERROR, "Could not write CPack properties file.");
  1265. }
  1266. for (std::map<std::string, cmExportBuildFileGenerator*>::iterator
  1267. it = this->BuildExportSets.begin(); it != this->BuildExportSets.end();
  1268. ++it)
  1269. {
  1270. if (!it->second->GenerateImportFile()
  1271. && !cmSystemTools::GetErrorOccuredFlag())
  1272. {
  1273. this->GetCMakeInstance()
  1274. ->IssueMessage(cmake::FATAL_ERROR, "Could not write export file.");
  1275. return;
  1276. }
  1277. }
  1278. // Update rule hashes.
  1279. this->CheckRuleHashes();
  1280. this->WriteSummary();
  1281. if (this->ExtraGenerator != 0)
  1282. {
  1283. this->ExtraGenerator->Generate();
  1284. }
  1285. if(!this->CMP0042WarnTargets.empty())
  1286. {
  1287. std::ostringstream w;
  1288. w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0042) << "\n";
  1289. w << "MACOSX_RPATH is not specified for"
  1290. " the following targets:\n";
  1291. for(std::set<std::string>::iterator
  1292. iter = this->CMP0042WarnTargets.begin();
  1293. iter != this->CMP0042WarnTargets.end();
  1294. ++iter)
  1295. {
  1296. w << " " << *iter << "\n";
  1297. }
  1298. this->GetCMakeInstance()->IssueMessage(cmake::AUTHOR_WARNING, w.str());
  1299. }
  1300. this->CMakeInstance->UpdateProgress("Generating done", -1);
  1301. }
  1302. //----------------------------------------------------------------------------
  1303. bool cmGlobalGenerator::ComputeTargetDepends()
  1304. {
  1305. cmComputeTargetDepends ctd(this);
  1306. if(!ctd.Compute())
  1307. {
  1308. return false;
  1309. }
  1310. std::vector<cmGeneratorTarget const*> const& targets = ctd.GetTargets();
  1311. for(std::vector<cmGeneratorTarget const*>::const_iterator ti
  1312. = targets.begin(); ti != targets.end(); ++ti)
  1313. {
  1314. ctd.GetTargetDirectDepends(*ti, this->TargetDependencies[*ti]);
  1315. }
  1316. return true;
  1317. }
  1318. //----------------------------------------------------------------------------
  1319. std::vector<const cmGeneratorTarget*>
  1320. cmGlobalGenerator::CreateQtAutoGeneratorsTargets()
  1321. {
  1322. std::vector<const cmGeneratorTarget*> autogenTargets;
  1323. #ifdef CMAKE_BUILD_WITH_CMAKE
  1324. for(unsigned int i=0; i < this->LocalGenerators.size(); ++i)
  1325. {
  1326. cmTargets& targets =
  1327. this->LocalGenerators[i]->GetMakefile()->GetTargets();
  1328. std::vector<cmGeneratorTarget*> filteredTargets;
  1329. filteredTargets.reserve(targets.size());
  1330. for(cmTargets::iterator ti = targets.begin();
  1331. ti != targets.end(); ++ti)
  1332. {
  1333. if (ti->second.GetType() == cmState::GLOBAL_TARGET)
  1334. {
  1335. continue;
  1336. }
  1337. if(ti->second.GetType() != cmState::EXECUTABLE &&
  1338. ti->second.GetType() != cmState::STATIC_LIBRARY &&
  1339. ti->second.GetType() != cmState::SHARED_LIBRARY &&
  1340. ti->second.GetType() != cmState::MODULE_LIBRARY &&
  1341. ti->second.GetType() != cmState::OBJECT_LIBRARY)
  1342. {
  1343. continue;
  1344. }
  1345. if((!ti->second.GetPropertyAsBool("AUTOMOC")
  1346. && !ti->second.GetPropertyAsBool("AUTOUIC")
  1347. && !ti->second.GetPropertyAsBool("AUTORCC"))
  1348. || ti->second.IsImported())
  1349. {
  1350. continue;
  1351. }
  1352. // don't do anything if there is no Qt4 or Qt5Core (which contains moc):
  1353. cmMakefile* mf = ti->second.GetMakefile();
  1354. std::string qtMajorVersion = mf->GetSafeDefinition("QT_VERSION_MAJOR");
  1355. if (qtMajorVersion == "")
  1356. {
  1357. qtMajorVersion = mf->GetSafeDefinition("Qt5Core_VERSION_MAJOR");
  1358. }
  1359. if (qtMajorVersion != "4" && qtMajorVersion != "5")
  1360. {
  1361. continue;
  1362. }
  1363. cmGeneratorTarget* gt = this->GetGeneratorTarget(&ti->second);
  1364. cmQtAutoGeneratorInitializer::InitializeAutogenSources(gt);
  1365. filteredTargets.push_back(gt);
  1366. }
  1367. for(std::vector<cmGeneratorTarget*>::iterator ti = filteredTargets.begin();
  1368. ti != filteredTargets.end(); ++ti)
  1369. {
  1370. cmQtAutoGeneratorInitializer::InitializeAutogenTarget(
  1371. this->LocalGenerators[i], *ti);
  1372. autogenTargets.push_back(*ti);
  1373. }
  1374. }
  1375. #endif
  1376. return autogenTargets;
  1377. }
  1378. //----------------------------------------------------------------------------
  1379. void cmGlobalGenerator::FinalizeTargetCompileInfo()
  1380. {
  1381. // Construct per-target generator information.
  1382. for(unsigned int i=0; i < this->Makefiles.size(); ++i)
  1383. {
  1384. cmMakefile *mf = this->Makefiles[i];
  1385. const cmStringRange noconfig_compile_definitions =
  1386. mf->GetCompileDefinitionsEntries();
  1387. const cmBacktraceRange noconfig_compile_definitions_bts =
  1388. mf->GetCompileDefinitionsBacktraces();
  1389. cmTargets& targets = mf->GetTargets();
  1390. for(cmTargets::iterator ti = targets.begin();
  1391. ti != targets.end(); ++ti)
  1392. {
  1393. cmTarget* t = &ti->second;
  1394. if (t->GetType() == cmState::GLOBAL_TARGET)
  1395. {
  1396. continue;
  1397. }
  1398. t->AppendBuildInterfaceIncludes();
  1399. if (t->GetType() == cmState::INTERFACE_LIBRARY)
  1400. {
  1401. continue;
  1402. }
  1403. cmBacktraceRange::const_iterator btIt
  1404. = noconfig_compile_definitions_bts.begin();
  1405. for (cmStringRange::const_iterator it
  1406. = noconfig_compile_definitions.begin();
  1407. it != noconfig_compile_definitions.end(); ++it, ++btIt)
  1408. {
  1409. t->InsertCompileDefinition(*it, *btIt);
  1410. }
  1411. cmPolicies::PolicyStatus polSt
  1412. = mf->GetPolicyStatus(cmPolicies::CMP0043);
  1413. if (polSt == cmPolicies::WARN || polSt == cmPolicies::OLD)
  1414. {
  1415. std::vector<std::string> configs;
  1416. mf->GetConfigurations(configs);
  1417. for(std::vector<std::string>::const_iterator ci = configs.begin();
  1418. ci != configs.end(); ++ci)
  1419. {
  1420. std::string defPropName = "COMPILE_DEFINITIONS_";
  1421. defPropName += cmSystemTools::UpperCase(*ci);
  1422. t->AppendProperty(defPropName,
  1423. mf->GetProperty(defPropName));
  1424. }
  1425. }
  1426. }
  1427. }
  1428. }
  1429. //----------------------------------------------------------------------------
  1430. void cmGlobalGenerator::CreateGeneratorTargets(TargetTypes targetTypes,
  1431. cmLocalGenerator *lg)
  1432. {
  1433. cmMakefile* mf = lg->GetMakefile();
  1434. if (targetTypes == AllTargets)
  1435. {
  1436. cmTargets& targets = mf->GetTargets();
  1437. for(cmTargets::iterator ti = targets.begin();
  1438. ti != targets.end(); ++ti)
  1439. {
  1440. cmTarget* t = &ti->second;
  1441. cmGeneratorTarget* gt = new cmGeneratorTarget(t, lg);
  1442. this->GeneratorTargets[t] = gt;
  1443. lg->AddGeneratorTarget(gt);
  1444. }
  1445. }
  1446. for(std::vector<cmTarget*>::const_iterator
  1447. j = mf->GetOwnedImportedTargets().begin();
  1448. j != mf->GetOwnedImportedTargets().end(); ++j)
  1449. {
  1450. cmGeneratorTarget* gt = new cmGeneratorTarget(*j, lg);
  1451. this->GeneratorTargets[*j] = gt;
  1452. }
  1453. }
  1454. //----------------------------------------------------------------------------
  1455. void cmGlobalGenerator::CreateGeneratorTargets(TargetTypes targetTypes)
  1456. {
  1457. // Construct per-target generator information.
  1458. for(unsigned int i=0; i < this->LocalGenerators.size(); ++i)
  1459. {
  1460. this->CreateGeneratorTargets(targetTypes, this->LocalGenerators[i]);
  1461. }
  1462. }
  1463. //----------------------------------------------------------------------------
  1464. void cmGlobalGenerator::ClearGeneratorMembers()
  1465. {
  1466. cmDeleteAll(this->GeneratorTargets);
  1467. this->GeneratorTargets.clear();
  1468. cmDeleteAll(this->BuildExportSets);
  1469. this->BuildExportSets.clear();
  1470. cmDeleteAll(this->Makefiles);
  1471. this->Makefiles.clear();
  1472. cmDeleteAll(this->LocalGenerators);
  1473. this->LocalGenerators.clear();
  1474. this->ExportSets.clear();
  1475. this->TargetDependencies.clear();
  1476. this->TotalTargets.clear();
  1477. this->ImportedTargets.clear();
  1478. this->ProjectMap.clear();
  1479. this->RuleHashes.clear();
  1480. this->DirectoryContentMap.clear();
  1481. this->BinaryDirectories.clear();
  1482. }
  1483. //----------------------------------------------------------------------------
  1484. cmGeneratorTarget*
  1485. cmGlobalGenerator::GetGeneratorTarget(cmTarget const* t) const
  1486. {
  1487. cmGeneratorTargetsType::const_iterator ti = this->GeneratorTargets.find(t);
  1488. if(ti == this->GeneratorTargets.end())
  1489. {
  1490. this->CMakeInstance->IssueMessage(
  1491. cmake::INTERNAL_ERROR, "Missing cmGeneratorTarget instance!");
  1492. return 0;
  1493. }
  1494. return ti->second;
  1495. }
  1496. //----------------------------------------------------------------------------
  1497. void cmGlobalGenerator::ComputeTargetObjectDirectory(cmGeneratorTarget*) const
  1498. {
  1499. }
  1500. void cmGlobalGenerator::CheckTargetProperties()
  1501. {
  1502. std::map<std::string, std::string> notFoundMap;
  1503. // std::set<std::string> notFoundMap;
  1504. // after it is all done do a ConfigureFinalPass
  1505. cmState* state = this->GetCMakeInstance()->GetState();
  1506. for (unsigned int i = 0; i < this->Makefiles.size(); ++i)
  1507. {
  1508. this->Makefiles[i]->ConfigureFinalPass();
  1509. cmTargets &targets =
  1510. this->Makefiles[i]->GetTargets();
  1511. for (cmTargets::iterator l = targets.begin();
  1512. l != targets.end(); l++)
  1513. {
  1514. if (l->second.GetType() == cmState::INTERFACE_LIBRARY)
  1515. {
  1516. continue;
  1517. }
  1518. const cmTarget::LinkLibraryVectorType& libs =
  1519. l->second.GetOriginalLinkLibraries();
  1520. for(cmTarget::LinkLibraryVectorType::const_iterator lib = libs.begin();
  1521. lib != libs.end(); ++lib)
  1522. {
  1523. if(lib->first.size() > 9 &&
  1524. cmSystemTools::IsNOTFOUND(lib->first.c_str()))
  1525. {
  1526. std::string varName = lib->first.substr(0, lib->first.size()-9);
  1527. if(state->GetCacheEntryPropertyAsBool(varName, "ADVANCED"))
  1528. {
  1529. varName += " (ADVANCED)";
  1530. }
  1531. std::string text = notFoundMap[varName];
  1532. text += "\n linked by target \"";
  1533. text += l->second.GetName();
  1534. text += "\" in directory ";
  1535. text+=this->Makefiles[i]->GetCurrentSourceDirectory();
  1536. notFoundMap[varName] = text;
  1537. }
  1538. }
  1539. std::vector<std::string> incs;
  1540. const char *incDirProp = l->second.GetProperty("INCLUDE_DIRECTORIES");
  1541. if (!incDirProp)
  1542. {
  1543. continue;
  1544. }
  1545. std::string incDirs = cmGeneratorExpression::Preprocess(incDirProp,
  1546. cmGeneratorExpression::StripAllGeneratorExpressions);
  1547. cmSystemTools::ExpandListArgument(incDirs, incs);
  1548. for( std::vector<std::string>::const_iterator incDir = incs.begin();
  1549. incDir != incs.end(); ++incDir)
  1550. {
  1551. if(incDir->size() > 9 &&
  1552. cmSystemTools::IsNOTFOUND(incDir->c_str()))
  1553. {
  1554. std::string varName = incDir->substr(0, incDir->size()-9);
  1555. if(state->GetCacheEntryPropertyAsBool(varName, "ADVANCED"))
  1556. {
  1557. varName += " (ADVANCED)";
  1558. }
  1559. std::string text = notFoundMap[varName];
  1560. text += "\n used as include directory in directory ";
  1561. text += this->Makefiles[i]->GetCurrentSourceDirectory();
  1562. notFoundMap[varName] = text;
  1563. }
  1564. }
  1565. }
  1566. this->CMakeInstance->UpdateProgress
  1567. ("Configuring", 0.9f+0.1f*(static_cast<float>(i)+1.0f)/
  1568. static_cast<float>(this->Makefiles.size()));
  1569. }
  1570. if(!notFoundMap.empty())
  1571. {
  1572. std::string notFoundVars;
  1573. for(std::map<std::string, std::string>::const_iterator
  1574. ii = notFoundMap.begin();
  1575. ii != notFoundMap.end();
  1576. ++ii)
  1577. {
  1578. notFoundVars += ii->first;
  1579. notFoundVars += ii->second;
  1580. notFoundVars += "\n";
  1581. }
  1582. cmSystemTools::Error("The following variables are used in this project, "
  1583. "but they are set to NOTFOUND.\n"
  1584. "Please set them or make sure they are set and "
  1585. "tested correctly in the CMake files:\n",
  1586. notFoundVars.c_str());
  1587. }
  1588. }
  1589. int cmGlobalGenerator::TryCompile(const std::string& srcdir,
  1590. const std::string& bindir,
  1591. const std::string& projectName,
  1592. const std::string& target, bool fast,
  1593. std::string& output, cmMakefile *mf)
  1594. {
  1595. // if this is not set, then this is a first time configure
  1596. // and there is a good chance that the try compile stuff will
  1597. // take the bulk of the time, so try and guess some progress
  1598. // by getting closer and closer to 100 without actually getting there.
  1599. if (!this->CMakeInstance->GetState()->GetInitializedCacheValue
  1600. ("CMAKE_NUMBER_OF_MAKEFILES"))
  1601. {
  1602. // If CMAKE_NUMBER_OF_MAKEFILES is not set
  1603. // we are in the first time progress and we have no
  1604. // idea how long it will be. So, just move 1/10th of the way
  1605. // there each time, and don't go over 95%
  1606. this->FirstTimeProgress += ((1.0f - this->FirstTimeProgress) /30.0f);
  1607. if(this->FirstTimeProgress > 0.95f)
  1608. {
  1609. this->FirstTimeProgress = 0.95f;
  1610. }
  1611. this->CMakeInstance->UpdateProgress("Configuring",
  1612. this->FirstTimeProgress);
  1613. }
  1614. std::string newTarget;
  1615. if (!target.empty())
  1616. {
  1617. newTarget += target;
  1618. #if 0
  1619. #if defined(_WIN32) || defined(__CYGWIN__)
  1620. std::string tmp = target;
  1621. // if the target does not already end in . something
  1622. // then assume .exe
  1623. if(tmp.size() < 4 || tmp[tmp.size()-4] != '.')
  1624. {
  1625. newTarget += ".exe";
  1626. }
  1627. #endif // WIN32
  1628. #endif
  1629. }
  1630. std::string config =
  1631. mf->GetSafeDefinition("CMAKE_TRY_COMPILE_CONFIGURATION");
  1632. return this->Build(srcdir,bindir,projectName,
  1633. newTarget,
  1634. output,"",config,false,fast,false,
  1635. this->TryCompileTimeout);
  1636. }
  1637. void cmGlobalGenerator::GenerateBuildCommand(
  1638. std::vector<std::string>& makeCommand, const std::string&,
  1639. const std::string&, const std::string&, const std::string&,
  1640. const std::string&, bool, bool,
  1641. std::vector<std::string> const&)
  1642. {
  1643. makeCommand.push_back(
  1644. "cmGlobalGenerator::GenerateBuildCommand not implemented");
  1645. }
  1646. int cmGlobalGenerator::Build(
  1647. const std::string&, const std::string& bindir,
  1648. const std::string& projectName, const std::string& target,
  1649. std::string& output,
  1650. const std::string& makeCommandCSTR,
  1651. const std::string& config,
  1652. bool clean, bool fast, bool verbose,
  1653. double timeout,
  1654. cmSystemTools::OutputOption outputflag,
  1655. std::vector<std::string> const& nativeOptions)
  1656. {
  1657. /**
  1658. * Run an executable command and put the stdout in output.
  1659. */
  1660. std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
  1661. cmSystemTools::ChangeDirectory(bindir);
  1662. output += "Change Dir: ";
  1663. output += bindir;
  1664. output += "\n";
  1665. int retVal;
  1666. bool hideconsole = cmSystemTools::GetRunCommandHideConsole();
  1667. cmSystemTools::SetRunCommandHideConsole(true);
  1668. std::string outputBuffer;
  1669. std::string* outputPtr = &outputBuffer;
  1670. std::vector<std::string> makeCommand;
  1671. this->GenerateBuildCommand(makeCommand, makeCommandCSTR, projectName,
  1672. bindir, target, config, fast, verbose,
  1673. nativeOptions);
  1674. // Workaround to convince VCExpress.exe to produce output.
  1675. if (outputflag == cmSystemTools::OUTPUT_PASSTHROUGH &&
  1676. !makeCommand.empty() && cmSystemTools::LowerCase(
  1677. cmSystemTools::GetFilenameName(makeCommand[0])) == "vcexpress.exe")
  1678. {
  1679. outputflag = cmSystemTools::OUTPUT_NORMAL;
  1680. }
  1681. // should we do a clean first?
  1682. if (clean)
  1683. {
  1684. std::vector<std::string> cleanCommand;
  1685. this->GenerateBuildCommand(cleanCommand, makeCommandCSTR, projectName,
  1686. bindir, "clean", config, fast, verbose);
  1687. output += "\nRun Clean Command:";
  1688. output += cmSystemTools::PrintSingleCommand(cleanCommand);
  1689. output += "\n";
  1690. if (!cmSystemTools::RunSingleCommand(cleanCommand, outputPtr, outputPtr,
  1691. &retVal, 0, outputflag, timeout))
  1692. {
  1693. cmSystemTools::SetRunCommandHideConsole(hideconsole);
  1694. cmSystemTools::Error("Generator: execution of make clean failed.");
  1695. output += *outputPtr;
  1696. output += "\nGenerator: execution of make clean failed.\n";
  1697. // return to the original directory
  1698. cmSystemTools::ChangeDirectory(cwd);
  1699. return 1;
  1700. }
  1701. output += *outputPtr;
  1702. }
  1703. // now build
  1704. std::string makeCommandStr = cmSystemTools::PrintSingleCommand(makeCommand);
  1705. output += "\nRun Build Command:";
  1706. output += makeCommandStr;
  1707. output += "\n";
  1708. if (!cmSystemTools::RunSingleCommand(makeCommand, outputPtr, outputPtr,
  1709. &retVal, 0, outputflag, timeout))
  1710. {
  1711. cmSystemTools::SetRunCommandHideConsole(hideconsole);
  1712. cmSystemTools::Error
  1713. ("Generator: execution of make failed. Make command was: ",
  1714. makeCommandStr.c_str());
  1715. output += *outputPtr;
  1716. output += "\nGenerator: execution of make failed. Make command was: "
  1717. + makeCommandStr + "\n";
  1718. // return to the original directory
  1719. cmSystemTools::ChangeDirectory(cwd);
  1720. return 1;
  1721. }
  1722. output += *outputPtr;
  1723. cmSystemTools::SetRunCommandHideConsole(hideconsole);
  1724. // The SGI MipsPro 7.3 compiler does not return an error code when
  1725. // the source has a #error in it! This is a work-around for such
  1726. // compilers.
  1727. if((retVal == 0) && (output.find("#error") != std::string::npos))
  1728. {
  1729. retVal = 1;
  1730. }
  1731. cmSystemTools::ChangeDirectory(cwd);
  1732. return retVal;
  1733. }
  1734. //----------------------------------------------------------------------------
  1735. std::string cmGlobalGenerator::GenerateCMakeBuildCommand(
  1736. const std::string& target, const std::string& config,
  1737. const std::string& native,
  1738. bool ignoreErrors)
  1739. {
  1740. std::string makeCommand = cmSystemTools::GetCMakeCommand();
  1741. makeCommand = cmSystemTools::ConvertToOutputPath(makeCommand.c_str());
  1742. makeCommand += " --build .";
  1743. if(!config.empty())
  1744. {
  1745. makeCommand += " --config \"";
  1746. makeCommand += config;
  1747. makeCommand += "\"";
  1748. }
  1749. if(!target.empty())
  1750. {
  1751. makeCommand += " --target \"";
  1752. makeCommand += target;
  1753. makeCommand += "\"";
  1754. }
  1755. const char* sep = " -- ";
  1756. if(ignoreErrors)
  1757. {
  1758. const char* iflag = this->GetBuildIgnoreErrorsFlag();
  1759. if(iflag && *iflag)
  1760. {
  1761. makeCommand += sep;
  1762. makeCommand += iflag;
  1763. sep = " ";
  1764. }
  1765. }
  1766. if(!native.empty())
  1767. {
  1768. makeCommand += sep;
  1769. makeCommand += native;
  1770. }
  1771. return makeCommand;
  1772. }
  1773. //----------------------------------------------------------------------------
  1774. void cmGlobalGenerator::AddMakefile(cmMakefile *mf)
  1775. {
  1776. this->Makefiles.push_back(mf);
  1777. // update progress
  1778. // estimate how many lg there will be
  1779. const char *numGenC =
  1780. this->CMakeInstance->GetState()->GetInitializedCacheValue
  1781. ("CMAKE_NUMBER_OF_MAKEFILES");
  1782. if (!numGenC)
  1783. {
  1784. // If CMAKE_NUMBER_OF_MAKEFILES is not set
  1785. // we are in the first time progress and we have no
  1786. // idea how long it will be. So, just move half way
  1787. // there each time, and don't go over 95%
  1788. this->FirstTimeProgress += ((1.0f - this->FirstTimeProgress) /30.0f);
  1789. if(this->FirstTimeProgress > 0.95f)
  1790. {
  1791. this->FirstTimeProgress = 0.95f;
  1792. }
  1793. this->CMakeInstance->UpdateProgress("Configuring",
  1794. this->FirstTimeProgress);
  1795. return;
  1796. }
  1797. int numGen = atoi(numGenC);
  1798. float prog = 0.9f*static_cast<float>(this->Makefiles.size())/
  1799. static_cast<float>(numGen);
  1800. if (prog > 0.9f)
  1801. {
  1802. prog = 0.9f;
  1803. }
  1804. this->CMakeInstance->UpdateProgress("Configuring", prog);
  1805. }
  1806. void cmGlobalGenerator::AddInstallComponent(const char* component)
  1807. {
  1808. if(component && *component)
  1809. {
  1810. this->InstallComponents.insert(component);
  1811. }
  1812. }
  1813. void cmGlobalGenerator::EnableInstallTarget()
  1814. {
  1815. this->InstallTargetEnabled = true;
  1816. }
  1817. cmLocalGenerator*
  1818. cmGlobalGenerator::CreateLocalGenerator(cmMakefile* mf)
  1819. {
  1820. return new cmLocalGenerator(this, mf);
  1821. }
  1822. void cmGlobalGenerator::EnableLanguagesFromGenerator(cmGlobalGenerator *gen,
  1823. cmMakefile* mf)
  1824. {
  1825. this->SetConfiguredFilesPath(gen);
  1826. this->TryCompileOuterMakefile = mf;
  1827. const char* make =
  1828. gen->GetCMakeInstance()->GetCacheDefinition("CMAKE_MAKE_PROGRAM");
  1829. this->GetCMakeInstance()->AddCacheEntry("CMAKE_MAKE_PROGRAM", make,
  1830. "make program",
  1831. cmState::FILEPATH);
  1832. // copy the enabled languages
  1833. this->GetCMakeInstance()->GetState()->SetEnabledLanguages(
  1834. gen->GetCMakeInstance()->GetState()->GetEnabledLanguages()
  1835. );
  1836. this->LanguagesReady = gen->LanguagesReady;
  1837. this->ExtensionToLanguage = gen->ExtensionToLanguage;
  1838. this->IgnoreExtensions = gen->IgnoreExtensions;
  1839. this->LanguageToOutputExtension = gen->LanguageToOutputExtension;
  1840. this->LanguageToLinkerPreference = gen->LanguageToLinkerPreference;
  1841. this->OutputExtensions = gen->OutputExtensions;
  1842. }
  1843. //----------------------------------------------------------------------------
  1844. void cmGlobalGenerator::SetConfiguredFilesPath(cmGlobalGenerator* gen)
  1845. {
  1846. if(!gen->ConfiguredFilesPath.empty())
  1847. {
  1848. this->ConfiguredFilesPath = gen->ConfiguredFilesPath;
  1849. }
  1850. else
  1851. {
  1852. this->ConfiguredFilesPath = gen->CMakeInstance->GetHomeOutputDirectory();
  1853. this->ConfiguredFilesPath += cmake::GetCMakeFilesDirectory();
  1854. }
  1855. }
  1856. bool cmGlobalGenerator::IsExcluded(cmState::Snapshot const& rootSnp,
  1857. cmState::Snapshot const& snp_) const
  1858. {
  1859. cmState::Snapshot snp = snp_;
  1860. while (snp.IsValid())
  1861. {
  1862. if(snp == rootSnp)
  1863. {
  1864. // No directory excludes itself.
  1865. return false;
  1866. }
  1867. if(snp.GetDirectory().GetPropertyAsBool("EXCLUDE_FROM_ALL"))
  1868. {
  1869. // This directory is excluded from its parent.
  1870. return true;
  1871. }
  1872. snp = snp.GetBuildsystemDirectoryParent();
  1873. }
  1874. return false;
  1875. }
  1876. bool cmGlobalGenerator::IsExcluded(cmLocalGenerator* root,
  1877. cmLocalGenerator* gen) const
  1878. {
  1879. assert(gen);
  1880. cmState::Snapshot rootSnp = root->GetStateSnapshot();
  1881. cmState::Snapshot snp = gen->GetStateSnapshot();
  1882. return this->IsExcluded(rootSnp, snp);
  1883. }
  1884. bool cmGlobalGenerator::IsExcluded(cmLocalGenerator* root,
  1885. cmGeneratorTarget* target) const
  1886. {
  1887. if(target->GetType() == cmState::INTERFACE_LIBRARY
  1888. || target->GetPropertyAsBool("EXCLUDE_FROM_ALL"))
  1889. {
  1890. // This target is excluded from its directory.
  1891. return true;
  1892. }
  1893. // This target is included in its directory. Check whether the
  1894. // directory is excluded.
  1895. return this->IsExcluded(root, target->GetLocalGenerator());
  1896. }
  1897. void
  1898. cmGlobalGenerator::GetEnabledLanguages(std::vector<std::string>& lang) const
  1899. {
  1900. lang = this->CMakeInstance->GetState()->GetEnabledLanguages();
  1901. }
  1902. int cmGlobalGenerator::GetLinkerPreference(const std::string& lang) const
  1903. {
  1904. std::map<std::string, int>::const_iterator it =
  1905. this->LanguageToLinkerPreference.find(lang);
  1906. if (it != this->LanguageToLinkerPreference.end())
  1907. {
  1908. return it->second;
  1909. }
  1910. return 0;
  1911. }
  1912. void cmGlobalGenerator::FillProjectMap()
  1913. {
  1914. this->ProjectMap.clear(); // make sure we start with a clean map
  1915. unsigned int i;
  1916. for(i = 0; i < this->LocalGenerators.size(); ++i)
  1917. {
  1918. // for each local generator add all projects
  1919. cmState::Snapshot snp = this->LocalGenerators[i]->GetStateSnapshot();
  1920. std::string name;
  1921. do
  1922. {
  1923. std::string snpProjName = snp.GetProjectName();
  1924. if (name != snpProjName)
  1925. {
  1926. name = snpProjName;
  1927. this->ProjectMap[name].push_back(this->LocalGenerators[i]);
  1928. }
  1929. snp = snp.GetBuildsystemDirectoryParent();
  1930. }
  1931. while (snp.IsValid());
  1932. }
  1933. }
  1934. cmMakefile*
  1935. cmGlobalGenerator::FindMakefile(const std::string& start_dir) const
  1936. {
  1937. for(std::vector<cmMakefile*>::const_iterator it =
  1938. this->Makefiles.begin(); it != this->Makefiles.end(); ++it)
  1939. {
  1940. std::string sd = (*it)->GetCurrentSourceDirectory();
  1941. if (sd == start_dir)
  1942. {
  1943. return *it;
  1944. }
  1945. }
  1946. return 0;
  1947. }
  1948. ///! Find a local generator by its startdirectory
  1949. cmLocalGenerator*
  1950. cmGlobalGenerator::FindLocalGenerator(const std::string& start_dir) const
  1951. {
  1952. for(std::vector<cmLocalGenerator*>::const_iterator it =
  1953. this->LocalGenerators.begin(); it != this->LocalGenerators.end(); ++it)
  1954. {
  1955. std::string sd = (*it)->GetCurrentSourceDirectory();
  1956. if (sd == start_dir)
  1957. {
  1958. return *it;
  1959. }
  1960. }
  1961. return 0;
  1962. }
  1963. //----------------------------------------------------------------------------
  1964. void cmGlobalGenerator::AddAlias(const std::string& name, cmTarget *tgt)
  1965. {
  1966. this->AliasTargets[name] = tgt;
  1967. }
  1968. //----------------------------------------------------------------------------
  1969. bool cmGlobalGenerator::IsAlias(const std::string& name) const
  1970. {
  1971. return this->AliasTargets.find(name) != this->AliasTargets.end();
  1972. }
  1973. //----------------------------------------------------------------------------
  1974. cmTarget*
  1975. cmGlobalGenerator::FindTarget(const std::string& name,
  1976. bool excludeAliases) const
  1977. {
  1978. if (!excludeAliases)
  1979. {
  1980. TargetMap::const_iterator ai = this->AliasTargets.find(name);
  1981. if (ai != this->AliasTargets.end())
  1982. {
  1983. return ai->second;
  1984. }
  1985. }
  1986. TargetMap::const_iterator i = this->TotalTargets.find ( name );
  1987. if ( i != this->TotalTargets.end() )
  1988. {
  1989. return i->second;
  1990. }
  1991. i = this->ImportedTargets.find(name);
  1992. if ( i != this->ImportedTargets.end() )
  1993. {
  1994. return i->second;
  1995. }
  1996. return 0;
  1997. }
  1998. //----------------------------------------------------------------------------
  1999. bool
  2000. cmGlobalGenerator::NameResolvesToFramework(const std::string& libname) const
  2001. {
  2002. if(cmSystemTools::IsPathToFramework(libname.c_str()))
  2003. {
  2004. return true;
  2005. }
  2006. if(cmTarget* tgt = this->FindTarget(libname))
  2007. {
  2008. cmGeneratorTarget* gt = this->GetGeneratorTarget(tgt);
  2009. if(gt->IsFrameworkOnApple())
  2010. {
  2011. return true;
  2012. }
  2013. }
  2014. return false;
  2015. }
  2016. //----------------------------------------------------------------------------
  2017. inline std::string removeQuotes(const std::string& s)
  2018. {
  2019. if(s[0] == '\"' && s[s.size()-1] == '\"')
  2020. {
  2021. return s.substr(1, s.size()-2);
  2022. }
  2023. return s;
  2024. }
  2025. void cmGlobalGenerator::CreateDefaultGlobalTargets(cmTargets* targets)
  2026. {
  2027. cmMakefile* mf = this->Makefiles[0];
  2028. const char* cmakeCfgIntDir = this->GetCMakeCFGIntDir();
  2029. // CPack
  2030. std::string workingDir = mf->GetCurrentBinaryDirectory();
  2031. cmCustomCommandLines cpackCommandLines;
  2032. std::vector<std::string> depends;
  2033. cmCustomCommandLine singleLine;
  2034. singleLine.push_back(cmSystemTools::GetCPackCommand());
  2035. if ( cmakeCfgIntDir && *cmakeCfgIntDir && cmakeCfgIntDir[0] != '.' )
  2036. {
  2037. singleLine.push_back("-C");
  2038. singleLine.push_back(cmakeCfgIntDir);
  2039. }
  2040. singleLine.push_back("--config");
  2041. std::string configFile = mf->GetCurrentBinaryDirectory();;
  2042. configFile += "/CPackConfig.cmake";
  2043. std::string relConfigFile = "./CPackConfig.cmake";
  2044. singleLine.push_back(relConfigFile);
  2045. cpackCommandLines.push_back(singleLine);
  2046. if ( this->GetPreinstallTargetName() )
  2047. {
  2048. depends.push_back(this->GetPreinstallTargetName());
  2049. }
  2050. else
  2051. {
  2052. const char* noPackageAll =
  2053. mf->GetDefinition("CMAKE_SKIP_PACKAGE_ALL_DEPENDENCY");
  2054. if(!noPackageAll || cmSystemTools::IsOff(noPackageAll))
  2055. {
  2056. depends.push_back(this->GetAllTargetName());
  2057. }
  2058. }
  2059. if(cmSystemTools::FileExists(configFile.c_str()))
  2060. {
  2061. (*targets)[this->GetPackageTargetName()]
  2062. = this->CreateGlobalTarget(this->GetPackageTargetName(),
  2063. "Run CPack packaging tool...",
  2064. &cpackCommandLines, depends,
  2065. workingDir.c_str(), /*uses_terminal*/true);
  2066. }
  2067. // CPack source
  2068. const char* packageSourceTargetName = this->GetPackageSourceTargetName();
  2069. if ( packageSourceTargetName )
  2070. {
  2071. cpackCommandLines.erase(cpackCommandLines.begin(),
  2072. cpackCommandLines.end());
  2073. singleLine.erase(singleLine.begin(), singleLine.end());
  2074. depends.erase(depends.begin(), depends.end());
  2075. singleLine.push_back(cmSystemTools::GetCPackCommand());
  2076. singleLine.push_back("--config");
  2077. configFile = mf->GetCurrentBinaryDirectory();;
  2078. configFile += "/CPackSourceConfig.cmake";
  2079. relConfigFile = "./CPackSourceConfig.cmake";
  2080. singleLine.push_back(relConfigFile);
  2081. if(cmSystemTools::FileExists(configFile.c_str()))
  2082. {
  2083. singleLine.push_back(configFile);
  2084. cpackCommandLines.push_back(singleLine);
  2085. (*targets)[packageSourceTargetName]
  2086. = this->CreateGlobalTarget(packageSourceTargetName,
  2087. "Run CPack packaging tool for source...",
  2088. &cpackCommandLines, depends,
  2089. workingDir.c_str(), /*uses_terminal*/true);
  2090. }
  2091. }
  2092. // Test
  2093. if(mf->IsOn("CMAKE_TESTING_ENABLED"))
  2094. {
  2095. cpackCommandLines.erase(cpackCommandLines.begin(),
  2096. cpackCommandLines.end());
  2097. singleLine.erase(singleLine.begin(), singleLine.end());
  2098. depends.erase(depends.begin(), depends.end());
  2099. singleLine.push_back(cmSystemTools::GetCTestCommand());
  2100. singleLine.push_back("--force-new-ctest-process");
  2101. if(cmakeCfgIntDir && *cmakeCfgIntDir && cmakeCfgIntDir[0] != '.')
  2102. {
  2103. singleLine.push_back("-C");
  2104. singleLine.push_back(cmakeCfgIntDir);
  2105. }
  2106. else // TODO: This is a hack. Should be something to do with the generator
  2107. {
  2108. singleLine.push_back("$(ARGS)");
  2109. }
  2110. cpackCommandLines.push_back(singleLine);
  2111. (*targets)[this->GetTestTargetName()]
  2112. = this->CreateGlobalTarget(this->GetTestTargetName(),
  2113. "Running tests...", &cpackCommandLines, depends, 0,
  2114. /*uses_terminal*/true);
  2115. }
  2116. //Edit Cache
  2117. const char* editCacheTargetName = this->GetEditCacheTargetName();
  2118. if ( editCacheTargetName )
  2119. {
  2120. cpackCommandLines.erase(cpackCommandLines.begin(),
  2121. cpackCommandLines.end());
  2122. singleLine.erase(singleLine.begin(), singleLine.end());
  2123. depends.erase(depends.begin(), depends.end());
  2124. // Use generator preference for the edit_cache rule if it is defined.
  2125. std::string edit_cmd = this->GetEditCacheCommand();
  2126. if (!edit_cmd.empty())
  2127. {
  2128. singleLine.push_back(edit_cmd);
  2129. singleLine.push_back("-H$(CMAKE_SOURCE_DIR)");
  2130. singleLine.push_back("-B$(CMAKE_BINARY_DIR)");
  2131. cpackCommandLines.push_back(singleLine);
  2132. (*targets)[editCacheTargetName] =
  2133. this->CreateGlobalTarget(
  2134. editCacheTargetName, "Running CMake cache editor...",
  2135. &cpackCommandLines, depends, 0, /*uses_terminal*/true);
  2136. }
  2137. else
  2138. {
  2139. singleLine.push_back(cmSystemTools::GetCMakeCommand());
  2140. singleLine.push_back("-E");
  2141. singleLine.push_back("echo");
  2142. singleLine.push_back("No interactive CMake dialog available.");
  2143. cpackCommandLines.push_back(singleLine);
  2144. (*targets)[editCacheTargetName] =
  2145. this->CreateGlobalTarget(
  2146. editCacheTargetName,
  2147. "No interactive CMake dialog available...",
  2148. &cpackCommandLines, depends, 0, /*uses_terminal*/false);
  2149. }
  2150. }
  2151. //Rebuild Cache
  2152. const char* rebuildCacheTargetName = this->GetRebuildCacheTargetName();
  2153. if ( rebuildCacheTargetName )
  2154. {
  2155. cpackCommandLines.erase(cpackCommandLines.begin(),
  2156. cpackCommandLines.end());
  2157. singleLine.erase(singleLine.begin(), singleLine.end());
  2158. depends.erase(depends.begin(), depends.end());
  2159. singleLine.push_back(cmSystemTools::GetCMakeCommand());
  2160. singleLine.push_back("-H$(CMAKE_SOURCE_DIR)");
  2161. singleLine.push_back("-B$(CMAKE_BINARY_DIR)");
  2162. cpackCommandLines.push_back(singleLine);
  2163. (*targets)[rebuildCacheTargetName] =
  2164. this->CreateGlobalTarget(
  2165. rebuildCacheTargetName, "Running CMake to regenerate build system...",
  2166. &cpackCommandLines, depends, 0, /*uses_terminal*/true);
  2167. }
  2168. //Install
  2169. bool skipInstallRules = mf->IsOn("CMAKE_SKIP_INSTALL_RULES");
  2170. if(this->InstallTargetEnabled && skipInstallRules)
  2171. {
  2172. mf->IssueMessage(cmake::WARNING,
  2173. "CMAKE_SKIP_INSTALL_RULES was enabled even though "
  2174. "installation rules have been specified");
  2175. }
  2176. else if(this->InstallTargetEnabled && !skipInstallRules)
  2177. {
  2178. if(!cmakeCfgIntDir || !*cmakeCfgIntDir || cmakeCfgIntDir[0] == '.')
  2179. {
  2180. std::set<std::string>* componentsSet = &this->InstallComponents;
  2181. cpackCommandLines.erase(cpackCommandLines.begin(),
  2182. cpackCommandLines.end());
  2183. depends.erase(depends.begin(), depends.end());
  2184. std::ostringstream ostr;
  2185. if (!componentsSet->empty())
  2186. {
  2187. ostr << "Available install components are: ";
  2188. ostr << cmWrap('"', *componentsSet, '"', " ");
  2189. }
  2190. else
  2191. {
  2192. ostr << "Only default component available";
  2193. }
  2194. singleLine.push_back(ostr.str());
  2195. (*targets)["list_install_components"]
  2196. = this->CreateGlobalTarget("list_install_components",
  2197. ostr.str().c_str(),
  2198. &cpackCommandLines, depends, 0, /*uses_terminal*/false);
  2199. }
  2200. std::string cmd = cmSystemTools::GetCMakeCommand();
  2201. cpackCommandLines.erase(cpackCommandLines.begin(),
  2202. cpackCommandLines.end());
  2203. singleLine.erase(singleLine.begin(), singleLine.end());
  2204. depends.erase(depends.begin(), depends.end());
  2205. if ( this->GetPreinstallTargetName() )
  2206. {
  2207. depends.push_back(this->GetPreinstallTargetName());
  2208. }
  2209. else
  2210. {
  2211. const char* noall =
  2212. mf->GetDefinition("CMAKE_SKIP_INSTALL_ALL_DEPENDENCY");
  2213. if(!noall || cmSystemTools::IsOff(noall))
  2214. {
  2215. depends.push_back(this->GetAllTargetName());
  2216. }
  2217. }
  2218. if(mf->GetDefinition("CMake_BINARY_DIR") &&
  2219. !mf->IsOn("CMAKE_CROSSCOMPILING"))
  2220. {
  2221. // We are building CMake itself. We cannot use the original
  2222. // executable to install over itself. The generator will
  2223. // automatically convert this name to the build-time location.
  2224. cmd = "cmake";
  2225. }
  2226. singleLine.push_back(cmd);
  2227. if ( cmakeCfgIntDir && *cmakeCfgIntDir && cmakeCfgIntDir[0] != '.' )
  2228. {
  2229. std::string cfgArg = "-DBUILD_TYPE=";
  2230. bool iosPlatform = mf->PlatformIsAppleIos();
  2231. if(iosPlatform)
  2232. {
  2233. cfgArg += "$(CONFIGURATION)";
  2234. singleLine.push_back(cfgArg);
  2235. cfgArg = "-DEFFECTIVE_PLATFORM_NAME=$(EFFECTIVE_PLATFORM_NAME)";
  2236. }
  2237. else
  2238. {
  2239. cfgArg += mf->GetDefinition("CMAKE_CFG_INTDIR");
  2240. }
  2241. singleLine.push_back(cfgArg);
  2242. }
  2243. singleLine.push_back("-P");
  2244. singleLine.push_back("cmake_install.cmake");
  2245. cpackCommandLines.push_back(singleLine);
  2246. (*targets)[this->GetInstallTargetName()] =
  2247. this->CreateGlobalTarget(
  2248. this->GetInstallTargetName(), "Install the project...",
  2249. &cpackCommandLines, depends, 0, /*uses_terminal*/true);
  2250. // install_local
  2251. if(const char* install_local = this->GetInstallLocalTargetName())
  2252. {
  2253. cmCustomCommandLine localCmdLine = singleLine;
  2254. localCmdLine.insert(localCmdLine.begin()+1,
  2255. "-DCMAKE_INSTALL_LOCAL_ONLY=1");
  2256. cpackCommandLines.erase(cpackCommandLines.begin(),
  2257. cpackCommandLines.end());
  2258. cpackCommandLines.push_back(localCmdLine);
  2259. (*targets)[install_local] =
  2260. this->CreateGlobalTarget(
  2261. install_local, "Installing only the local directory...",
  2262. &cpackCommandLines, depends, 0, /*uses_terminal*/true);
  2263. }
  2264. // install_strip
  2265. const char* install_strip = this->GetInstallStripTargetName();
  2266. if((install_strip !=0) && (mf->IsSet("CMAKE_STRIP")))
  2267. {
  2268. cmCustomCommandLine stripCmdLine = singleLine;
  2269. stripCmdLine.insert(stripCmdLine.begin()+1,"-DCMAKE_INSTALL_DO_STRIP=1");
  2270. cpackCommandLines.erase(cpackCommandLines.begin(),
  2271. cpackCommandLines.end());
  2272. cpackCommandLines.push_back(stripCmdLine);
  2273. (*targets)[install_strip] =
  2274. this->CreateGlobalTarget(
  2275. install_strip, "Installing the project stripped...",
  2276. &cpackCommandLines, depends, 0, /*uses_terminal*/true);
  2277. }
  2278. }
  2279. }
  2280. //----------------------------------------------------------------------------
  2281. const char* cmGlobalGenerator::GetPredefinedTargetsFolder()
  2282. {
  2283. const char* prop = this->GetCMakeInstance()->GetState()
  2284. ->GetGlobalProperty("PREDEFINED_TARGETS_FOLDER");
  2285. if (prop)
  2286. {
  2287. return prop;
  2288. }
  2289. return "CMakePredefinedTargets";
  2290. }
  2291. //----------------------------------------------------------------------------
  2292. bool cmGlobalGenerator::UseFolderProperty()
  2293. {
  2294. const char* prop = this->GetCMakeInstance()->GetState()
  2295. ->GetGlobalProperty("USE_FOLDERS");
  2296. // If this property is defined, let the setter turn this on or off...
  2297. //
  2298. if (prop)
  2299. {
  2300. return cmSystemTools::IsOn(prop);
  2301. }
  2302. // By default, this feature is OFF, since it is not supported in the
  2303. // Visual Studio Express editions until VS11:
  2304. //
  2305. return false;
  2306. }
  2307. //----------------------------------------------------------------------------
  2308. cmTarget cmGlobalGenerator::CreateGlobalTarget(
  2309. const std::string& name, const char* message,
  2310. const cmCustomCommandLines* commandLines,
  2311. std::vector<std::string> depends,
  2312. const char* workingDirectory,
  2313. bool uses_terminal)
  2314. {
  2315. // Package
  2316. cmTarget target;
  2317. target.SetType(cmState::GLOBAL_TARGET, name);
  2318. target.SetProperty("EXCLUDE_FROM_ALL","TRUE");
  2319. std::vector<std::string> no_outputs;
  2320. std::vector<std::string> no_byproducts;
  2321. std::vector<std::string> no_depends;
  2322. // Store the custom command in the target.
  2323. cmCustomCommand cc(0, no_outputs, no_byproducts, no_depends,
  2324. *commandLines, 0, workingDirectory);
  2325. cc.SetUsesTerminal(uses_terminal);
  2326. target.AddPostBuildCommand(cc);
  2327. target.SetProperty("EchoString", message);
  2328. std::vector<std::string>::iterator dit;
  2329. for ( dit = depends.begin(); dit != depends.end(); ++ dit )
  2330. {
  2331. target.AddUtility(*dit);
  2332. }
  2333. // Organize in the "predefined targets" folder:
  2334. //
  2335. if (this->UseFolderProperty())
  2336. {
  2337. target.SetProperty("FOLDER", this->GetPredefinedTargetsFolder());
  2338. }
  2339. return target;
  2340. }
  2341. //----------------------------------------------------------------------------
  2342. std::string
  2343. cmGlobalGenerator::GenerateRuleFile(std::string const& output) const
  2344. {
  2345. std::string ruleFile = output;
  2346. ruleFile += ".rule";
  2347. const char* dir = this->GetCMakeCFGIntDir();
  2348. if(dir && dir[0] == '$')
  2349. {
  2350. cmSystemTools::ReplaceString(ruleFile, dir,
  2351. cmake::GetCMakeFilesDirectory());
  2352. }
  2353. return ruleFile;
  2354. }
  2355. //----------------------------------------------------------------------------
  2356. std::string cmGlobalGenerator::GetSharedLibFlagsForLanguage(
  2357. std::string const& l) const
  2358. {
  2359. std::map<std::string, std::string>::const_iterator it =
  2360. this->LanguageToOriginalSharedLibFlags.find(l);
  2361. if(it != this->LanguageToOriginalSharedLibFlags.end())
  2362. {
  2363. return it->second;
  2364. }
  2365. return "";
  2366. }
  2367. //----------------------------------------------------------------------------
  2368. void cmGlobalGenerator::AppendDirectoryForConfig(const std::string&,
  2369. const std::string&,
  2370. const std::string&,
  2371. std::string&)
  2372. {
  2373. // Subclasses that support multiple configurations should implement
  2374. // this method to append the subdirectory for the given build
  2375. // configuration.
  2376. }
  2377. //----------------------------------------------------------------------------
  2378. cmGlobalGenerator::TargetDependSet const&
  2379. cmGlobalGenerator::GetTargetDirectDepends(cmGeneratorTarget const* target)
  2380. {
  2381. return this->TargetDependencies[target];
  2382. }
  2383. void cmGlobalGenerator::AddTarget(cmTarget* t)
  2384. {
  2385. if(t->IsImported())
  2386. {
  2387. this->ImportedTargets[t->GetName()] = t;
  2388. }
  2389. else
  2390. {
  2391. this->TotalTargets[t->GetName()] = t;
  2392. }
  2393. }
  2394. bool cmGlobalGenerator::IsReservedTarget(std::string const& name)
  2395. {
  2396. // The following is a list of targets reserved
  2397. // by one or more of the cmake generators.
  2398. // Adding additional targets to this list will require a policy!
  2399. const char* reservedTargets[] =
  2400. {
  2401. "all", "ALL_BUILD",
  2402. "help",
  2403. "install", "INSTALL",
  2404. "preinstall",
  2405. "clean",
  2406. "edit_cache",
  2407. "rebuild_cache",
  2408. "test", "RUN_TESTS",
  2409. "package", "PACKAGE",
  2410. "package_source",
  2411. "ZERO_CHECK"
  2412. };
  2413. return std::find(cmArrayBegin(reservedTargets),
  2414. cmArrayEnd(reservedTargets), name)
  2415. != cmArrayEnd(reservedTargets);
  2416. }
  2417. void cmGlobalGenerator::SetExternalMakefileProjectGenerator(
  2418. cmExternalMakefileProjectGenerator *extraGenerator)
  2419. {
  2420. this->ExtraGenerator = extraGenerator;
  2421. if (this->ExtraGenerator!=0)
  2422. {
  2423. this->ExtraGenerator->SetGlobalGenerator(this);
  2424. }
  2425. }
  2426. std::string cmGlobalGenerator::GetExtraGeneratorName() const
  2427. {
  2428. return this->ExtraGenerator? this->ExtraGenerator->GetName() : std::string();
  2429. }
  2430. void cmGlobalGenerator::FileReplacedDuringGenerate(const std::string& filename)
  2431. {
  2432. this->FilesReplacedDuringGenerate.push_back(filename);
  2433. }
  2434. void
  2435. cmGlobalGenerator
  2436. ::GetFilesReplacedDuringGenerate(std::vector<std::string>& filenames)
  2437. {
  2438. filenames.clear();
  2439. std::copy(
  2440. this->FilesReplacedDuringGenerate.begin(),
  2441. this->FilesReplacedDuringGenerate.end(),
  2442. std::back_inserter(filenames));
  2443. }
  2444. //----------------------------------------------------------------------------
  2445. void cmGlobalGenerator::GetTargetSets(TargetDependSet& projectTargets,
  2446. TargetDependSet& originalTargets,
  2447. cmLocalGenerator* root,
  2448. GeneratorVector const& generators)
  2449. {
  2450. // loop over all local generators
  2451. for(std::vector<cmLocalGenerator*>::const_iterator i = generators.begin();
  2452. i != generators.end(); ++i)
  2453. {
  2454. // check to make sure generator is not excluded
  2455. if(this->IsExcluded(root, *i))
  2456. {
  2457. continue;
  2458. }
  2459. cmMakefile* mf = (*i)->GetMakefile();
  2460. // Get the targets in the makefile
  2461. cmTargets &tgts = mf->GetTargets();
  2462. // loop over all the targets
  2463. for (cmTargets::iterator l = tgts.begin(); l != tgts.end(); ++l)
  2464. {
  2465. cmTarget* target = &l->second;
  2466. cmGeneratorTarget* gt = this->GetGeneratorTarget(target);
  2467. if(this->IsRootOnlyTarget(gt) &&
  2468. target->GetMakefile() != root->GetMakefile())
  2469. {
  2470. continue;
  2471. }
  2472. // put the target in the set of original targets
  2473. originalTargets.insert(gt);
  2474. // Get the set of targets that depend on target
  2475. this->AddTargetDepends(gt, projectTargets);
  2476. }
  2477. }
  2478. }
  2479. //----------------------------------------------------------------------------
  2480. bool cmGlobalGenerator::IsRootOnlyTarget(cmGeneratorTarget* target) const
  2481. {
  2482. return (target->GetType() == cmState::GLOBAL_TARGET ||
  2483. target->GetName() == this->GetAllTargetName());
  2484. }
  2485. //----------------------------------------------------------------------------
  2486. void cmGlobalGenerator::AddTargetDepends(cmGeneratorTarget const* target,
  2487. TargetDependSet& projectTargets)
  2488. {
  2489. // add the target itself
  2490. if(projectTargets.insert(target).second)
  2491. {
  2492. // This is the first time we have encountered the target.
  2493. // Recursively follow its dependencies.
  2494. TargetDependSet const& ts = this->GetTargetDirectDepends(target);
  2495. for(TargetDependSet::const_iterator i = ts.begin(); i != ts.end(); ++i)
  2496. {
  2497. this->AddTargetDepends(*i, projectTargets);
  2498. }
  2499. }
  2500. }
  2501. //----------------------------------------------------------------------------
  2502. void cmGlobalGenerator::AddToManifest(std::string const& f)
  2503. {
  2504. // Add to the content listing for the file's directory.
  2505. std::string dir = cmSystemTools::GetFilenamePath(f);
  2506. std::string file = cmSystemTools::GetFilenameName(f);
  2507. DirectoryContent& dc = this->DirectoryContentMap[dir];
  2508. dc.Generated.insert(file);
  2509. dc.All.insert(file);
  2510. }
  2511. //----------------------------------------------------------------------------
  2512. std::set<std::string> const&
  2513. cmGlobalGenerator::GetDirectoryContent(std::string const& dir, bool needDisk)
  2514. {
  2515. DirectoryContent& dc = this->DirectoryContentMap[dir];
  2516. if(needDisk)
  2517. {
  2518. long mt = cmSystemTools::ModifiedTime(dir);
  2519. if (mt != dc.LastDiskTime)
  2520. {
  2521. // Reset to non-loaded directory content.
  2522. dc.All = dc.Generated;
  2523. // Load the directory content from disk.
  2524. cmsys::Directory d;
  2525. if(d.Load(dir))
  2526. {
  2527. unsigned long n = d.GetNumberOfFiles();
  2528. for(unsigned long i = 0; i < n; ++i)
  2529. {
  2530. const char* f = d.GetFile(i);
  2531. if(strcmp(f, ".") != 0 && strcmp(f, "..") != 0)
  2532. {
  2533. dc.All.insert(f);
  2534. }
  2535. }
  2536. }
  2537. dc.LastDiskTime = mt;
  2538. }
  2539. }
  2540. return dc.All;
  2541. }
  2542. //----------------------------------------------------------------------------
  2543. void
  2544. cmGlobalGenerator::AddRuleHash(const std::vector<std::string>& outputs,
  2545. std::string const& content)
  2546. {
  2547. #if defined(CMAKE_BUILD_WITH_CMAKE)
  2548. // Ignore if there are no outputs.
  2549. if(outputs.empty())
  2550. {
  2551. return;
  2552. }
  2553. // Compute a hash of the rule.
  2554. RuleHash hash;
  2555. {
  2556. unsigned char const* data =
  2557. reinterpret_cast<unsigned char const*>(content.c_str());
  2558. int length = static_cast<int>(content.length());
  2559. cmsysMD5* sum = cmsysMD5_New();
  2560. cmsysMD5_Initialize(sum);
  2561. cmsysMD5_Append(sum, data, length);
  2562. cmsysMD5_FinalizeHex(sum, hash.Data);
  2563. cmsysMD5_Delete(sum);
  2564. }
  2565. // Shorten the output name (in expected use case).
  2566. cmOutputConverter converter(this->GetMakefiles()[0]->GetStateSnapshot());
  2567. std::string fname = converter.Convert(
  2568. outputs[0], cmLocalGenerator::HOME_OUTPUT);
  2569. // Associate the hash with this output.
  2570. this->RuleHashes[fname] = hash;
  2571. #else
  2572. (void)outputs;
  2573. (void)content;
  2574. #endif
  2575. }
  2576. //----------------------------------------------------------------------------
  2577. void cmGlobalGenerator::CheckRuleHashes()
  2578. {
  2579. #if defined(CMAKE_BUILD_WITH_CMAKE)
  2580. std::string home = this->GetCMakeInstance()->GetHomeOutputDirectory();
  2581. std::string pfile = home;
  2582. pfile += this->GetCMakeInstance()->GetCMakeFilesDirectory();
  2583. pfile += "/CMakeRuleHashes.txt";
  2584. this->CheckRuleHashes(pfile, home);
  2585. this->WriteRuleHashes(pfile);
  2586. #endif
  2587. }
  2588. //----------------------------------------------------------------------------
  2589. void cmGlobalGenerator::CheckRuleHashes(std::string const& pfile,
  2590. std::string const& home)
  2591. {
  2592. #if defined(_WIN32) || defined(__CYGWIN__)
  2593. cmsys::ifstream fin(pfile.c_str(), std::ios::in | std::ios::binary);
  2594. #else
  2595. cmsys::ifstream fin(pfile.c_str(), std::ios::in);
  2596. #endif
  2597. if(!fin)
  2598. {
  2599. return;
  2600. }
  2601. std::string line;
  2602. std::string fname;
  2603. while(cmSystemTools::GetLineFromStream(fin, line))
  2604. {
  2605. // Line format is a 32-byte hex string followed by a space
  2606. // followed by a file name (with no escaping).
  2607. // Skip blank and comment lines.
  2608. if(line.size() < 34 || line[0] == '#')
  2609. {
  2610. continue;
  2611. }
  2612. // Get the filename.
  2613. fname = line.substr(33, line.npos);
  2614. // Look for a hash for this file's rule.
  2615. std::map<std::string, RuleHash>::const_iterator rhi =
  2616. this->RuleHashes.find(fname);
  2617. if(rhi != this->RuleHashes.end())
  2618. {
  2619. // Compare the rule hash in the file to that we were given.
  2620. if(strncmp(line.c_str(), rhi->second.Data, 32) != 0)
  2621. {
  2622. // The rule has changed. Delete the output so it will be
  2623. // built again.
  2624. fname = cmSystemTools::CollapseFullPath(fname, home.c_str());
  2625. cmSystemTools::RemoveFile(fname);
  2626. }
  2627. }
  2628. else
  2629. {
  2630. // We have no hash for a rule previously listed. This may be a
  2631. // case where a user has turned off a build option and might
  2632. // want to turn it back on later, so do not delete the file.
  2633. // Instead, we keep the rule hash as long as the file exists so
  2634. // that if the feature is turned back on and the rule has
  2635. // changed the file is still rebuilt.
  2636. std::string fpath =
  2637. cmSystemTools::CollapseFullPath(fname, home.c_str());
  2638. if(cmSystemTools::FileExists(fpath.c_str()))
  2639. {
  2640. RuleHash hash;
  2641. strncpy(hash.Data, line.c_str(), 32);
  2642. this->RuleHashes[fname] = hash;
  2643. }
  2644. }
  2645. }
  2646. }
  2647. //----------------------------------------------------------------------------
  2648. void cmGlobalGenerator::WriteRuleHashes(std::string const& pfile)
  2649. {
  2650. // Now generate a new persistence file with the current hashes.
  2651. if(this->RuleHashes.empty())
  2652. {
  2653. cmSystemTools::RemoveFile(pfile);
  2654. }
  2655. else
  2656. {
  2657. cmGeneratedFileStream fout(pfile.c_str());
  2658. fout << "# Hashes of file build rules.\n";
  2659. for(std::map<std::string, RuleHash>::const_iterator
  2660. rhi = this->RuleHashes.begin(); rhi != this->RuleHashes.end(); ++rhi)
  2661. {
  2662. fout.write(rhi->second.Data, 32);
  2663. fout << " " << rhi->first << "\n";
  2664. }
  2665. }
  2666. }
  2667. //----------------------------------------------------------------------------
  2668. void cmGlobalGenerator::WriteSummary()
  2669. {
  2670. // Record all target directories in a central location.
  2671. std::string fname = this->CMakeInstance->GetHomeOutputDirectory();
  2672. fname += cmake::GetCMakeFilesDirectory();
  2673. fname += "/TargetDirectories.txt";
  2674. cmGeneratedFileStream fout(fname.c_str());
  2675. // Generate summary information files for each target.
  2676. for(TargetMap::const_iterator ti =
  2677. this->TotalTargets.begin(); ti != this->TotalTargets.end(); ++ti)
  2678. {
  2679. if ((ti->second)->GetType() == cmState::INTERFACE_LIBRARY)
  2680. {
  2681. continue;
  2682. }
  2683. cmGeneratorTarget* gt = this->GetGeneratorTarget(ti->second);
  2684. this->WriteSummary(gt);
  2685. fout << gt->GetSupportDirectory() << "\n";
  2686. }
  2687. }
  2688. //----------------------------------------------------------------------------
  2689. void cmGlobalGenerator::WriteSummary(cmGeneratorTarget* target)
  2690. {
  2691. // Place the labels file in a per-target support directory.
  2692. std::string dir = target->GetSupportDirectory();
  2693. std::string file = dir;
  2694. file += "/Labels.txt";
  2695. std::string json_file = dir + "/Labels.json";
  2696. #ifdef CMAKE_BUILD_WITH_CMAKE
  2697. // Check whether labels are enabled for this target.
  2698. if(const char* value = target->GetProperty("LABELS"))
  2699. {
  2700. Json::Value lj_root(Json::objectValue);
  2701. Json::Value& lj_target =
  2702. lj_root["target"] = Json::objectValue;
  2703. lj_target["name"] = target->GetName();
  2704. Json::Value& lj_target_labels =
  2705. lj_target["labels"] = Json::arrayValue;
  2706. Json::Value& lj_sources =
  2707. lj_root["sources"] = Json::arrayValue;
  2708. cmSystemTools::MakeDirectory(dir.c_str());
  2709. cmGeneratedFileStream fout(file.c_str());
  2710. // List the target-wide labels. All sources in the target get
  2711. // these labels.
  2712. std::vector<std::string> labels;
  2713. cmSystemTools::ExpandListArgument(value, labels);
  2714. if(!labels.empty())
  2715. {
  2716. fout << "# Target labels\n";
  2717. for(std::vector<std::string>::const_iterator li = labels.begin();
  2718. li != labels.end(); ++li)
  2719. {
  2720. fout << " " << *li << "\n";
  2721. lj_target_labels.append(*li);
  2722. }
  2723. }
  2724. // List the source files with any per-source labels.
  2725. fout << "# Source files and their labels\n";
  2726. std::vector<cmSourceFile*> sources;
  2727. std::vector<std::string> configs;
  2728. target->Target->GetMakefile()->GetConfigurations(configs);
  2729. if (configs.empty())
  2730. {
  2731. configs.push_back("");
  2732. }
  2733. for(std::vector<std::string>::const_iterator ci = configs.begin();
  2734. ci != configs.end(); ++ci)
  2735. {
  2736. target->GetSourceFiles(sources, *ci);
  2737. }
  2738. std::vector<cmSourceFile*>::const_iterator sourcesEnd
  2739. = cmRemoveDuplicates(sources);
  2740. for(std::vector<cmSourceFile*>::const_iterator si = sources.begin();
  2741. si != sourcesEnd; ++si)
  2742. {
  2743. Json::Value& lj_source = lj_sources.append(Json::objectValue);
  2744. cmSourceFile* sf = *si;
  2745. std::string const& sfp = sf->GetFullPath();
  2746. fout << sfp << "\n";
  2747. lj_source["file"] = sfp;
  2748. if(const char* svalue = sf->GetProperty("LABELS"))
  2749. {
  2750. labels.clear();
  2751. Json::Value& lj_source_labels =
  2752. lj_source["labels"] = Json::arrayValue;
  2753. cmSystemTools::ExpandListArgument(svalue, labels);
  2754. for(std::vector<std::string>::const_iterator li = labels.begin();
  2755. li != labels.end(); ++li)
  2756. {
  2757. fout << " " << *li << "\n";
  2758. lj_source_labels.append(*li);
  2759. }
  2760. }
  2761. }
  2762. cmGeneratedFileStream json_fout(json_file.c_str());
  2763. json_fout << lj_root;
  2764. }
  2765. else
  2766. #endif
  2767. {
  2768. cmSystemTools::RemoveFile(file);
  2769. cmSystemTools::RemoveFile(json_file);
  2770. }
  2771. }
  2772. //----------------------------------------------------------------------------
  2773. // static
  2774. std::string cmGlobalGenerator::EscapeJSON(const std::string& s) {
  2775. std::string result;
  2776. for (std::string::size_type i = 0; i < s.size(); ++i) {
  2777. if (s[i] == '"' || s[i] == '\\') {
  2778. result += '\\';
  2779. }
  2780. result += s[i];
  2781. }
  2782. return result;
  2783. }
  2784. //----------------------------------------------------------------------------
  2785. void cmGlobalGenerator::SetFilenameTargetDepends(cmSourceFile* sf,
  2786. std::set<cmGeneratorTarget const*> tgts)
  2787. {
  2788. this->FilenameTargetDepends[sf] = tgts;
  2789. }
  2790. //----------------------------------------------------------------------------
  2791. std::set<cmGeneratorTarget const*> const&
  2792. cmGlobalGenerator::GetFilenameTargetDepends(cmSourceFile* sf) const {
  2793. return this->FilenameTargetDepends[sf];
  2794. }
  2795. //----------------------------------------------------------------------------
  2796. void cmGlobalGenerator::CreateEvaluationSourceFiles(
  2797. std::string const& config) const
  2798. {
  2799. unsigned int i;
  2800. for (i = 0; i < this->LocalGenerators.size(); ++i)
  2801. {
  2802. this->LocalGenerators[i]->CreateEvaluationFileOutputs(config);
  2803. }
  2804. }
  2805. //----------------------------------------------------------------------------
  2806. void cmGlobalGenerator::ProcessEvaluationFiles()
  2807. {
  2808. std::vector<std::string> generatedFiles;
  2809. unsigned int i;
  2810. for (i = 0; i < this->LocalGenerators.size(); ++i)
  2811. {
  2812. this->LocalGenerators[i]->ProcessEvaluationFiles(generatedFiles);
  2813. }
  2814. }
  2815. //----------------------------------------------------------------------------
  2816. std::string cmGlobalGenerator::ExpandCFGIntDir(const std::string& str,
  2817. const std::string& /*config*/) const
  2818. {
  2819. return str;
  2820. }
  2821. //----------------------------------------------------------------------------
  2822. bool cmGlobalGenerator::GenerateCPackPropertiesFile()
  2823. {
  2824. cmake::InstalledFilesMap const& installedFiles =
  2825. this->CMakeInstance->GetInstalledFiles();
  2826. cmLocalGenerator* lg = this->LocalGenerators[0];
  2827. cmMakefile* mf = lg->GetMakefile();
  2828. std::vector<std::string> configs;
  2829. std::string config = mf->GetConfigurations(configs, false);
  2830. std::string path = this->CMakeInstance->GetHomeOutputDirectory();
  2831. path += "/CPackProperties.cmake";
  2832. if(!cmSystemTools::FileExists(path.c_str()) && installedFiles.empty())
  2833. {
  2834. return true;
  2835. }
  2836. cmGeneratedFileStream file(path.c_str());
  2837. file << "# CPack properties\n";
  2838. for(cmake::InstalledFilesMap::const_iterator i = installedFiles.begin();
  2839. i != installedFiles.end(); ++i)
  2840. {
  2841. cmInstalledFile const& installedFile = i->second;
  2842. cmCPackPropertiesGenerator cpackPropertiesGenerator(
  2843. lg, installedFile, configs);
  2844. cpackPropertiesGenerator.Generate(file, config, configs);
  2845. }
  2846. return true;
  2847. }