cmGlobalGenerator.cxx 99 KB

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