cmGlobalGenerator.cxx 97 KB

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