cmGlobalGenerator.cxx 78 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461
  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. #endif
  13. #include "cmGlobalGenerator.h"
  14. #include "cmLocalGenerator.h"
  15. #include "cmExternalMakefileProjectGenerator.h"
  16. #include "cmake.h"
  17. #include "cmMakefile.h"
  18. #include "cmQtAutomoc.h"
  19. #include "cmSourceFile.h"
  20. #include "cmVersion.h"
  21. #include "cmExportInstallFileGenerator.h"
  22. #include "cmComputeTargetDepends.h"
  23. #include "cmGeneratedFileStream.h"
  24. #include "cmGeneratorTarget.h"
  25. #include <cmsys/Directory.hxx>
  26. #if defined(CMAKE_BUILD_WITH_CMAKE)
  27. # include <cmsys/MD5.h>
  28. #endif
  29. #include <stdlib.h> // required for atof
  30. #include <assert.h>
  31. cmGlobalGenerator::cmGlobalGenerator()
  32. {
  33. // By default the .SYMBOLIC dependency is not needed on symbolic rules.
  34. this->NeedSymbolicMark = false;
  35. // by default use the native paths
  36. this->ForceUnixPaths = false;
  37. // By default do not try to support color.
  38. this->ToolSupportsColor = false;
  39. // By default do not use link scripts.
  40. this->UseLinkScript = false;
  41. // Whether an install target is needed.
  42. this->InstallTargetEnabled = false;
  43. // how long to let try compiles run
  44. this->TryCompileTimeout = 0;
  45. this->ExtraGenerator = 0;
  46. this->CurrentLocalGenerator = 0;
  47. this->TryCompileOuterMakefile = 0;
  48. }
  49. cmGlobalGenerator::~cmGlobalGenerator()
  50. {
  51. // Delete any existing cmLocalGenerators
  52. for (unsigned int i = 0; i < this->LocalGenerators.size(); ++i)
  53. {
  54. delete this->LocalGenerators[i];
  55. }
  56. this->LocalGenerators.clear();
  57. if (this->ExtraGenerator)
  58. {
  59. delete this->ExtraGenerator;
  60. }
  61. this->ClearGeneratorTargets();
  62. this->ClearExportSets();
  63. }
  64. void cmGlobalGenerator::ResolveLanguageCompiler(const std::string &lang,
  65. cmMakefile *mf,
  66. bool optional) {
  67. std::string langComp = "CMAKE_";
  68. langComp += lang;
  69. langComp += "_COMPILER";
  70. if(!mf->GetDefinition(langComp.c_str()))
  71. {
  72. if(!optional)
  73. {
  74. cmSystemTools::Error(langComp.c_str(),
  75. " not set, after EnableLanguage");
  76. }
  77. return;
  78. }
  79. const char* name = mf->GetRequiredDefinition(langComp.c_str());
  80. std::string path;
  81. if(!cmSystemTools::FileIsFullPath(name))
  82. {
  83. path = cmSystemTools::FindProgram(name);
  84. }
  85. else
  86. {
  87. path = name;
  88. }
  89. if((path.size() == 0 || !cmSystemTools::FileExists(path.c_str()))
  90. && (optional==false))
  91. {
  92. std::string message = "your ";
  93. message += lang;
  94. message += " compiler: \"";
  95. message += name;
  96. message += "\" was not found. Please set ";
  97. message += langComp;
  98. message += " to a valid compiler path or name.";
  99. cmSystemTools::Error(message.c_str());
  100. path = name;
  101. }
  102. std::string doc = lang;
  103. doc += " compiler.";
  104. const char* cname = this->GetCMakeInstance()->
  105. GetCacheManager()->GetCacheValue(langComp.c_str());
  106. std::string changeVars;
  107. if(cname && (path != cname) && (optional==false))
  108. {
  109. std::string cnameString = cname;
  110. std::string pathString = path;
  111. // get rid of potentially multiple slashes:
  112. cmSystemTools::ConvertToUnixSlashes(cnameString);
  113. cmSystemTools::ConvertToUnixSlashes(pathString);
  114. if (cnameString != pathString)
  115. {
  116. const char* cvars =
  117. this->GetCMakeInstance()->GetProperty(
  118. "__CMAKE_DELETE_CACHE_CHANGE_VARS_");
  119. if(cvars)
  120. {
  121. changeVars += cvars;
  122. changeVars += ";";
  123. }
  124. changeVars += langComp;
  125. changeVars += ";";
  126. changeVars += cname;
  127. this->GetCMakeInstance()->SetProperty(
  128. "__CMAKE_DELETE_CACHE_CHANGE_VARS_",
  129. changeVars.c_str());
  130. }
  131. }
  132. mf->AddCacheDefinition(langComp.c_str(), path.c_str(),
  133. doc.c_str(), cmCacheManager::FILEPATH);
  134. }
  135. // Find the make program for the generator, required for try compiles
  136. void cmGlobalGenerator::FindMakeProgram(cmMakefile* mf)
  137. {
  138. if(this->FindMakeProgramFile.size() == 0)
  139. {
  140. cmSystemTools::Error(
  141. "Generator implementation error, "
  142. "all generators must specify this->FindMakeProgramFile");
  143. }
  144. if(!mf->GetDefinition("CMAKE_MAKE_PROGRAM")
  145. || cmSystemTools::IsOff(mf->GetDefinition("CMAKE_MAKE_PROGRAM")))
  146. {
  147. std::string setMakeProgram =
  148. mf->GetModulesFile(this->FindMakeProgramFile.c_str());
  149. if(setMakeProgram.size())
  150. {
  151. mf->ReadListFile(0, setMakeProgram.c_str());
  152. }
  153. }
  154. if(!mf->GetDefinition("CMAKE_MAKE_PROGRAM")
  155. || cmSystemTools::IsOff(mf->GetDefinition("CMAKE_MAKE_PROGRAM")))
  156. {
  157. cmOStringStream err;
  158. err << "CMake was unable to find a build program corresponding to \""
  159. << this->GetName() << "\". CMAKE_MAKE_PROGRAM is not set. You "
  160. << "probably need to select a different build tool.";
  161. cmSystemTools::Error(err.str().c_str());
  162. cmSystemTools::SetFatalErrorOccured();
  163. return;
  164. }
  165. std::string makeProgram = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
  166. // if there are spaces in the make program use short path
  167. // but do not short path the actual program name, as
  168. // this can cause trouble with VSExpress
  169. if(makeProgram.find(' ') != makeProgram.npos)
  170. {
  171. std::string dir;
  172. std::string file;
  173. cmSystemTools::SplitProgramPath(makeProgram.c_str(),
  174. dir, file);
  175. std::string saveFile = file;
  176. cmSystemTools::GetShortPath(makeProgram.c_str(), makeProgram);
  177. cmSystemTools::SplitProgramPath(makeProgram.c_str(),
  178. dir, file);
  179. makeProgram = dir;
  180. makeProgram += "/";
  181. makeProgram += saveFile;
  182. mf->AddCacheDefinition("CMAKE_MAKE_PROGRAM", makeProgram.c_str(),
  183. "make program",
  184. cmCacheManager::FILEPATH);
  185. }
  186. if(makeProgram.find("xcodebuild") != makeProgram.npos)
  187. {
  188. // due to the text file busy /bin/sh problem with xcodebuild
  189. // use the cmakexbuild wrapper instead. This program
  190. // will run xcodebuild and if it sees the error text file busy
  191. // it will stop forwarding output, and let the build finish.
  192. // Then it will retry the build. It will continue this
  193. // untill no text file busy errors occur.
  194. std::string cmakexbuild =
  195. this->CMakeInstance->GetCacheManager()->GetCacheValue("CMAKE_COMMAND");
  196. cmakexbuild = cmakexbuild.substr(0, cmakexbuild.length()-5);
  197. cmakexbuild += "cmakexbuild";
  198. mf->AddCacheDefinition("CMAKE_MAKE_PROGRAM",
  199. cmakexbuild.c_str(),
  200. "make program",
  201. cmCacheManager::FILEPATH);
  202. }
  203. }
  204. // enable the given language
  205. //
  206. // The following files are loaded in this order:
  207. //
  208. // First figure out what OS we are running on:
  209. //
  210. // CMakeSystem.cmake - configured file created by CMakeDetermineSystem.cmake
  211. // CMakeDetermineSystem.cmake - figure out os info and create
  212. // CMakeSystem.cmake IF CMAKE_SYSTEM
  213. // not set
  214. // CMakeSystem.cmake - configured file created by
  215. // CMakeDetermineSystem.cmake IF CMAKE_SYSTEM_LOADED
  216. // Next try and enable all languages found in the languages vector
  217. //
  218. // FOREACH LANG in languages
  219. // CMake(LANG)Compiler.cmake - configured file create by
  220. // CMakeDetermine(LANG)Compiler.cmake
  221. // CMakeDetermine(LANG)Compiler.cmake - Finds compiler for LANG and
  222. // creates CMake(LANG)Compiler.cmake
  223. // CMake(LANG)Compiler.cmake - configured file created by
  224. // CMakeDetermine(LANG)Compiler.cmake
  225. //
  226. // CMakeSystemSpecificInformation.cmake
  227. // - includes Platform/${CMAKE_SYSTEM_NAME}.cmake
  228. // may use compiler stuff
  229. // FOREACH LANG in languages
  230. // CMake(LANG)Information.cmake
  231. // - loads Platform/${CMAKE_SYSTEM_NAME}-${COMPILER}.cmake
  232. // CMakeTest(LANG)Compiler.cmake
  233. // - Make sure the compiler works with a try compile if
  234. // CMakeDetermine(LANG) was loaded
  235. //
  236. // Now load a few files that can override values set in any of the above
  237. // (PROJECTNAME)Compatibility.cmake
  238. // - load any backwards compatibility stuff for current project
  239. // ${CMAKE_USER_MAKE_RULES_OVERRIDE}
  240. // - allow users a chance to override system variables
  241. //
  242. //
  243. void
  244. cmGlobalGenerator::EnableLanguage(std::vector<std::string>const& languages,
  245. cmMakefile *mf, bool)
  246. {
  247. if(languages.size() == 0)
  248. {
  249. cmSystemTools::Error("EnableLanguage must have a lang specified!");
  250. cmSystemTools::SetFatalErrorOccured();
  251. return;
  252. }
  253. if(this->TryCompileOuterMakefile)
  254. {
  255. // In a try-compile we can only enable languages provided by caller.
  256. for(std::vector<std::string>::const_iterator li = languages.begin();
  257. li != languages.end(); ++li)
  258. {
  259. if(*li == "NONE")
  260. {
  261. this->SetLanguageEnabled("NONE", mf);
  262. }
  263. else
  264. {
  265. const char* lang = li->c_str();
  266. if(this->LanguagesReady.find(lang) == this->LanguagesReady.end())
  267. {
  268. cmOStringStream e;
  269. e << "The test project needs language "
  270. << lang << " which is not enabled.";
  271. this->TryCompileOuterMakefile
  272. ->IssueMessage(cmake::FATAL_ERROR, e.str());
  273. cmSystemTools::SetFatalErrorOccured();
  274. return;
  275. }
  276. }
  277. }
  278. }
  279. mf->AddDefinition("RUN_CONFIGURE", true);
  280. std::string rootBin = mf->GetHomeOutputDirectory();
  281. rootBin += cmake::GetCMakeFilesDirectory();
  282. // If the configuration files path has been set,
  283. // then we are in a try compile and need to copy the enable language
  284. // files from the parent cmake bin dir, into the try compile bin dir
  285. if(this->ConfiguredFilesPath.size())
  286. {
  287. rootBin = this->ConfiguredFilesPath;
  288. }
  289. // set the dir for parent files so they can be used by modules
  290. mf->AddDefinition("CMAKE_PLATFORM_ROOT_BIN",rootBin.c_str());
  291. // find and make sure CMAKE_MAKE_PROGRAM is defined
  292. this->FindMakeProgram(mf);
  293. // try and load the CMakeSystem.cmake if it is there
  294. std::string fpath = rootBin;
  295. if(!mf->GetDefinition("CMAKE_SYSTEM_LOADED"))
  296. {
  297. fpath += "/CMakeSystem.cmake";
  298. if(cmSystemTools::FileExists(fpath.c_str()))
  299. {
  300. mf->ReadListFile(0,fpath.c_str());
  301. }
  302. }
  303. // Load the CMakeDetermineSystem.cmake file and find out
  304. // what platform we are running on
  305. if (!mf->GetDefinition("CMAKE_SYSTEM"))
  306. {
  307. #if defined(_WIN32) && !defined(__CYGWIN__)
  308. /* Windows version number data. */
  309. OSVERSIONINFO osvi;
  310. ZeroMemory(&osvi, sizeof(osvi));
  311. osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  312. GetVersionEx (&osvi);
  313. cmOStringStream windowsVersionString;
  314. windowsVersionString << osvi.dwMajorVersion << "." << osvi.dwMinorVersion;
  315. windowsVersionString.str();
  316. mf->AddDefinition("CMAKE_HOST_SYSTEM_VERSION",
  317. windowsVersionString.str().c_str());
  318. #endif
  319. // Read the DetermineSystem file
  320. std::string systemFile = mf->GetModulesFile("CMakeDetermineSystem.cmake");
  321. mf->ReadListFile(0, systemFile.c_str());
  322. // load the CMakeSystem.cmake from the binary directory
  323. // this file is configured by the CMakeDetermineSystem.cmake file
  324. fpath = rootBin;
  325. fpath += "/CMakeSystem.cmake";
  326. mf->ReadListFile(0,fpath.c_str());
  327. }
  328. std::map<cmStdString, bool> needTestLanguage;
  329. std::map<cmStdString, bool> needSetLanguageEnabledMaps;
  330. // foreach language
  331. // load the CMakeDetermine(LANG)Compiler.cmake file to find
  332. // the compiler
  333. for(std::vector<std::string>::const_iterator l = languages.begin();
  334. l != languages.end(); ++l)
  335. {
  336. const char* lang = l->c_str();
  337. needSetLanguageEnabledMaps[lang] = false;
  338. if(*l == "NONE")
  339. {
  340. this->SetLanguageEnabled("NONE", mf);
  341. continue;
  342. }
  343. std::string loadedLang = "CMAKE_";
  344. loadedLang += lang;
  345. loadedLang += "_COMPILER_LOADED";
  346. // If the existing build tree was already configured with this
  347. // version of CMake then try to load the configured file first
  348. // to avoid duplicate compiler tests.
  349. unsigned int cacheMajor = mf->GetCacheMajorVersion();
  350. unsigned int cacheMinor = mf->GetCacheMinorVersion();
  351. unsigned int selfMajor = cmVersion::GetMajorVersion();
  352. unsigned int selfMinor = cmVersion::GetMinorVersion();
  353. if((this->CMakeInstance->GetIsInTryCompile() ||
  354. (selfMajor == cacheMajor && selfMinor == cacheMinor))
  355. && !mf->GetDefinition(loadedLang.c_str()))
  356. {
  357. fpath = rootBin;
  358. fpath += "/CMake";
  359. fpath += lang;
  360. fpath += "Compiler.cmake";
  361. if(cmSystemTools::FileExists(fpath.c_str()))
  362. {
  363. if(!mf->ReadListFile(0,fpath.c_str()))
  364. {
  365. cmSystemTools::Error("Could not find cmake module file:",
  366. fpath.c_str());
  367. }
  368. // if this file was found then the language was already determined
  369. // to be working
  370. needTestLanguage[lang] = false;
  371. this->SetLanguageEnabledFlag(lang, mf);
  372. needSetLanguageEnabledMaps[lang] = true;
  373. // this can only be called after loading CMake(LANG)Compiler.cmake
  374. }
  375. }
  376. if(!this->GetLanguageEnabled(lang) )
  377. {
  378. if (this->CMakeInstance->GetIsInTryCompile())
  379. {
  380. cmSystemTools::Error("This should not have happen. "
  381. "If you see this message, you are probably "
  382. "using a broken CMakeLists.txt file or a "
  383. "problematic release of CMake");
  384. }
  385. // if the CMake(LANG)Compiler.cmake file was not found then
  386. // load CMakeDetermine(LANG)Compiler.cmake
  387. std::string determineCompiler = "CMakeDetermine";
  388. determineCompiler += lang;
  389. determineCompiler += "Compiler.cmake";
  390. std::string determineFile =
  391. mf->GetModulesFile(determineCompiler.c_str());
  392. if(!mf->ReadListFile(0,determineFile.c_str()))
  393. {
  394. cmSystemTools::Error("Could not find cmake module file:",
  395. determineFile.c_str());
  396. }
  397. needTestLanguage[lang] = true;
  398. // Some generators like visual studio should not use the env variables
  399. // So the global generator can specify that in this variable
  400. if(!mf->GetDefinition("CMAKE_GENERATOR_NO_COMPILER_ENV"))
  401. {
  402. // put ${CMake_(LANG)_COMPILER_ENV_VAR}=${CMAKE_(LANG)_COMPILER
  403. // into the environment, in case user scripts want to run
  404. // configure, or sub cmakes
  405. std::string compilerName = "CMAKE_";
  406. compilerName += lang;
  407. compilerName += "_COMPILER";
  408. std::string compilerEnv = "CMAKE_";
  409. compilerEnv += lang;
  410. compilerEnv += "_COMPILER_ENV_VAR";
  411. std::string envVar = mf->GetRequiredDefinition(compilerEnv.c_str());
  412. std::string envVarValue =
  413. mf->GetRequiredDefinition(compilerName.c_str());
  414. std::string env = envVar;
  415. env += "=";
  416. env += envVarValue;
  417. cmSystemTools::PutEnv(env.c_str());
  418. }
  419. // if determineLanguage was called then load the file it
  420. // configures CMake(LANG)Compiler.cmake
  421. fpath = rootBin;
  422. fpath += "/CMake";
  423. fpath += lang;
  424. fpath += "Compiler.cmake";
  425. if(!mf->ReadListFile(0,fpath.c_str()))
  426. {
  427. cmSystemTools::Error("Could not find cmake module file:",
  428. fpath.c_str());
  429. }
  430. this->SetLanguageEnabledFlag(lang, mf);
  431. needSetLanguageEnabledMaps[lang] = true;
  432. // this can only be called after loading CMake(LANG)Compiler.cmake
  433. // the language must be enabled for try compile to work, but we do
  434. // not know if it is a working compiler yet so set the test language
  435. // flag
  436. needTestLanguage[lang] = true;
  437. } // end if(!this->GetLanguageEnabled(lang) )
  438. } // end loop over languages
  439. // **** Load the system specific information if not yet loaded
  440. if (!mf->GetDefinition("CMAKE_SYSTEM_SPECIFIC_INFORMATION_LOADED"))
  441. {
  442. fpath = mf->GetModulesFile("CMakeSystemSpecificInformation.cmake");
  443. if(!mf->ReadListFile(0,fpath.c_str()))
  444. {
  445. cmSystemTools::Error("Could not find cmake module file:",
  446. fpath.c_str());
  447. }
  448. }
  449. // loop over languages again loading CMake(LANG)Information.cmake
  450. //
  451. for(std::vector<std::string>::const_iterator l = languages.begin();
  452. l != languages.end(); ++l)
  453. {
  454. const char* lang = l->c_str();
  455. if(*l == "NONE")
  456. {
  457. this->SetLanguageEnabled("NONE", mf);
  458. continue;
  459. }
  460. std::string langLoadedVar = "CMAKE_";
  461. langLoadedVar += lang;
  462. langLoadedVar += "_INFORMATION_LOADED";
  463. if (!mf->GetDefinition(langLoadedVar.c_str()))
  464. {
  465. fpath = "CMake";
  466. fpath += lang;
  467. fpath += "Information.cmake";
  468. std::string informationFile = mf->GetModulesFile(fpath.c_str());
  469. if (informationFile.empty())
  470. {
  471. cmSystemTools::Error("Could not find cmake module file:",
  472. fpath.c_str());
  473. }
  474. else if(!mf->ReadListFile(0, informationFile.c_str()))
  475. {
  476. cmSystemTools::Error("Could not process cmake module file:",
  477. informationFile.c_str());
  478. }
  479. }
  480. if (needSetLanguageEnabledMaps[lang])
  481. {
  482. this->SetLanguageEnabledMaps(lang, mf);
  483. }
  484. this->LanguagesReady.insert(lang);
  485. std::string compilerName = "CMAKE_";
  486. compilerName += lang;
  487. compilerName += "_COMPILER";
  488. std::string compilerLangFile = rootBin;
  489. compilerLangFile += "/CMake";
  490. compilerLangFile += lang;
  491. compilerLangFile += "Compiler.cmake";
  492. // Test the compiler for the language just setup
  493. // (but only if a compiler has been actually found)
  494. // At this point we should have enough info for a try compile
  495. // which is used in the backward stuff
  496. // If the language is untested then test it now with a try compile.
  497. if (!mf->IsSet(compilerName.c_str()))
  498. {
  499. // if the compiler did not work, then remove the
  500. // CMake(LANG)Compiler.cmake file so that it will get tested the
  501. // next time cmake is run
  502. cmSystemTools::RemoveFile(compilerLangFile.c_str());
  503. }
  504. else if(needTestLanguage[lang])
  505. {
  506. if (!this->CMakeInstance->GetIsInTryCompile())
  507. {
  508. std::string testLang = "CMakeTest";
  509. testLang += lang;
  510. testLang += "Compiler.cmake";
  511. std::string ifpath = mf->GetModulesFile(testLang.c_str());
  512. if(!mf->ReadListFile(0,ifpath.c_str()))
  513. {
  514. cmSystemTools::Error("Could not find cmake module file:",
  515. ifpath.c_str());
  516. }
  517. std::string compilerWorks = "CMAKE_";
  518. compilerWorks += lang;
  519. compilerWorks += "_COMPILER_WORKS";
  520. // if the compiler did not work, then remove the
  521. // CMake(LANG)Compiler.cmake file so that it will get tested the
  522. // next time cmake is run
  523. if(!mf->IsOn(compilerWorks.c_str()))
  524. {
  525. cmSystemTools::RemoveFile(compilerLangFile.c_str());
  526. }
  527. else
  528. {
  529. // load backwards compatibility stuff for C and CXX
  530. // for old versions of CMake ListFiles C and CXX had some
  531. // backwards compatibility files they have to load
  532. // These files have a bunch of try compiles in them so
  533. // should only be done
  534. if (mf->NeedBackwardsCompatibility(1,4))
  535. {
  536. if(strcmp(lang, "C") == 0)
  537. {
  538. ifpath =
  539. mf->GetModulesFile("CMakeBackwardCompatibilityC.cmake");
  540. mf->ReadListFile(0,ifpath.c_str());
  541. }
  542. if(strcmp(lang, "CXX") == 0)
  543. {
  544. ifpath =
  545. mf->GetModulesFile("CMakeBackwardCompatibilityCXX.cmake");
  546. mf->ReadListFile(0,ifpath.c_str());
  547. }
  548. }
  549. }
  550. } // end if in try compile
  551. } // end need test language
  552. } // end for each language
  553. // Now load files that can override any settings on the platform or for
  554. // the project First load the project compatibility file if it is in
  555. // cmake
  556. std::string projectCompatibility = mf->GetDefinition("CMAKE_ROOT");
  557. projectCompatibility += "/Modules/";
  558. projectCompatibility += mf->GetSafeDefinition("PROJECT_NAME");
  559. projectCompatibility += "Compatibility.cmake";
  560. if(cmSystemTools::FileExists(projectCompatibility.c_str()))
  561. {
  562. mf->ReadListFile(0,projectCompatibility.c_str());
  563. }
  564. }
  565. //----------------------------------------------------------------------------
  566. const char*
  567. cmGlobalGenerator::GetLanguageOutputExtension(cmSourceFile const& source)
  568. {
  569. if(const char* lang = source.GetLanguage())
  570. {
  571. if(this->LanguageToOutputExtension.count(lang) > 0)
  572. {
  573. return this->LanguageToOutputExtension[lang].c_str();
  574. }
  575. }
  576. else
  577. {
  578. // if no language is found then check to see if it is already an
  579. // ouput extension for some language. In that case it should be ignored
  580. // and in this map, so it will not be compiled but will just be used.
  581. std::string const& ext = source.GetExtension();
  582. if(!ext.empty())
  583. {
  584. if(this->OutputExtensions.count(ext))
  585. {
  586. return ext.c_str();
  587. }
  588. }
  589. }
  590. return "";
  591. }
  592. const char* cmGlobalGenerator::GetLanguageFromExtension(const char* ext)
  593. {
  594. // if there is an extension and it starts with . then move past the
  595. // . because the extensions are not stored with a . in the map
  596. if(ext && *ext == '.')
  597. {
  598. ++ext;
  599. }
  600. if(this->ExtensionToLanguage.count(ext) > 0)
  601. {
  602. return this->ExtensionToLanguage[ext].c_str();
  603. }
  604. return 0;
  605. }
  606. /* SetLanguageEnabled() is now split in two parts:
  607. at first the enabled-flag is set. This can then be used in EnabledLanguage()
  608. for checking whether the language is already enabled. After setting this
  609. flag still the values from the cmake variables have to be copied into the
  610. internal maps, this is done in SetLanguageEnabledMaps() which is called
  611. after the system- and compiler specific files have been loaded.
  612. This split was done originally so that compiler-specific configuration
  613. files could change the object file extension
  614. (CMAKE_<LANG>_OUTPUT_EXTENSION) before the CMake variables were copied
  615. to the C++ maps.
  616. */
  617. void cmGlobalGenerator::SetLanguageEnabled(const char* l, cmMakefile* mf)
  618. {
  619. this->SetLanguageEnabledFlag(l, mf);
  620. this->SetLanguageEnabledMaps(l, mf);
  621. }
  622. void cmGlobalGenerator::SetLanguageEnabledFlag(const char* l, cmMakefile* mf)
  623. {
  624. this->LanguageEnabled[l] = true;
  625. // Fill the language-to-extension map with the current variable
  626. // settings to make sure it is available for the try_compile()
  627. // command source file signature. In SetLanguageEnabledMaps this
  628. // will be done again to account for any compiler- or
  629. // platform-specific entries.
  630. this->FillExtensionToLanguageMap(l, mf);
  631. }
  632. void cmGlobalGenerator::SetLanguageEnabledMaps(const char* l, cmMakefile* mf)
  633. {
  634. // use LanguageToLinkerPreference to detect whether this functions has
  635. // run before
  636. if (this->LanguageToLinkerPreference.find(l) !=
  637. this->LanguageToLinkerPreference.end())
  638. {
  639. return;
  640. }
  641. std::string linkerPrefVar = std::string("CMAKE_") +
  642. std::string(l) + std::string("_LINKER_PREFERENCE");
  643. const char* linkerPref = mf->GetDefinition(linkerPrefVar.c_str());
  644. int preference = 0;
  645. if(linkerPref)
  646. {
  647. if (sscanf(linkerPref, "%d", &preference)!=1)
  648. {
  649. // backward compatibility: before 2.6 LINKER_PREFERENCE
  650. // was either "None" or "Prefered", and only the first character was
  651. // tested. So if there is a custom language out there and it is
  652. // "Prefered", set its preference high
  653. if (linkerPref[0]=='P')
  654. {
  655. preference = 100;
  656. }
  657. else
  658. {
  659. preference = 0;
  660. }
  661. }
  662. }
  663. if (preference < 0)
  664. {
  665. std::string msg = linkerPrefVar;
  666. msg += " is negative, adjusting it to 0";
  667. cmSystemTools::Message(msg.c_str(), "Warning");
  668. preference = 0;
  669. }
  670. this->LanguageToLinkerPreference[l] = preference;
  671. std::string outputExtensionVar = std::string("CMAKE_") +
  672. std::string(l) + std::string("_OUTPUT_EXTENSION");
  673. const char* outputExtension = mf->GetDefinition(outputExtensionVar.c_str());
  674. if(outputExtension)
  675. {
  676. this->LanguageToOutputExtension[l] = outputExtension;
  677. this->OutputExtensions[outputExtension] = outputExtension;
  678. if(outputExtension[0] == '.')
  679. {
  680. this->OutputExtensions[outputExtension+1] = outputExtension+1;
  681. }
  682. }
  683. // The map was originally filled by SetLanguageEnabledFlag, but
  684. // since then the compiler- and platform-specific files have been
  685. // loaded which might have added more entries.
  686. this->FillExtensionToLanguageMap(l, mf);
  687. std::string ignoreExtensionsVar = std::string("CMAKE_") +
  688. std::string(l) + std::string("_IGNORE_EXTENSIONS");
  689. std::string ignoreExts = mf->GetSafeDefinition(ignoreExtensionsVar.c_str());
  690. std::vector<std::string> extensionList;
  691. cmSystemTools::ExpandListArgument(ignoreExts, extensionList);
  692. for(std::vector<std::string>::iterator i = extensionList.begin();
  693. i != extensionList.end(); ++i)
  694. {
  695. this->IgnoreExtensions[*i] = true;
  696. }
  697. }
  698. void cmGlobalGenerator::FillExtensionToLanguageMap(const char* l,
  699. cmMakefile* mf)
  700. {
  701. std::string extensionsVar = std::string("CMAKE_") +
  702. std::string(l) + std::string("_SOURCE_FILE_EXTENSIONS");
  703. std::string exts = mf->GetSafeDefinition(extensionsVar.c_str());
  704. std::vector<std::string> extensionList;
  705. cmSystemTools::ExpandListArgument(exts, extensionList);
  706. for(std::vector<std::string>::iterator i = extensionList.begin();
  707. i != extensionList.end(); ++i)
  708. {
  709. this->ExtensionToLanguage[*i] = l;
  710. }
  711. }
  712. bool cmGlobalGenerator::IgnoreFile(const char* l)
  713. {
  714. if(this->GetLanguageFromExtension(l))
  715. {
  716. return false;
  717. }
  718. return (this->IgnoreExtensions.count(l) > 0);
  719. }
  720. bool cmGlobalGenerator::GetLanguageEnabled(const char* l) const
  721. {
  722. return (this->LanguageEnabled.find(l)!= this->LanguageEnabled.end());
  723. }
  724. void cmGlobalGenerator::ClearEnabledLanguages()
  725. {
  726. this->LanguageEnabled.clear();
  727. }
  728. bool cmGlobalGenerator::IsDependedOn(const char* project,
  729. cmTarget* targetIn)
  730. {
  731. // Get all local gens for this project
  732. std::vector<cmLocalGenerator*>* gens = &this->ProjectMap[project];
  733. // loop over local gens and get the targets for each one
  734. for(unsigned int i = 0; i < gens->size(); ++i)
  735. {
  736. cmTargets& targets = (*gens)[i]->GetMakefile()->GetTargets();
  737. for (cmTargets::iterator l = targets.begin();
  738. l != targets.end(); l++)
  739. {
  740. cmTarget& target = l->second;
  741. TargetDependSet const& tgtdeps = this->GetTargetDirectDepends(target);
  742. if(tgtdeps.count(targetIn))
  743. {
  744. return true;
  745. }
  746. }
  747. }
  748. return false;
  749. }
  750. void cmGlobalGenerator::Configure()
  751. {
  752. this->FirstTimeProgress = 0.0f;
  753. this->ClearGeneratorTargets();
  754. this->ClearExportSets();
  755. // Delete any existing cmLocalGenerators
  756. unsigned int i;
  757. for (i = 0; i < this->LocalGenerators.size(); ++i)
  758. {
  759. delete this->LocalGenerators[i];
  760. }
  761. this->LocalGenerators.clear();
  762. this->TargetDependencies.clear();
  763. this->TotalTargets.clear();
  764. this->LocalGeneratorToTargetMap.clear();
  765. this->ProjectMap.clear();
  766. this->RuleHashes.clear();
  767. this->DirectoryContentMap.clear();
  768. this->BinaryDirectories.clear();
  769. // start with this directory
  770. cmLocalGenerator *lg = this->CreateLocalGenerator();
  771. this->LocalGenerators.push_back(lg);
  772. // set the Start directories
  773. cmMakefile* mf = lg->GetMakefile();
  774. lg->GetMakefile()->SetStartDirectory
  775. (this->CMakeInstance->GetStartDirectory());
  776. lg->GetMakefile()->SetStartOutputDirectory
  777. (this->CMakeInstance->GetStartOutputDirectory());
  778. lg->GetMakefile()->MakeStartDirectoriesCurrent();
  779. this->BinaryDirectories.insert(mf->GetStartOutputDirectory());
  780. // now do it
  781. lg->Configure();
  782. // update the cache entry for the number of local generators, this is used
  783. // for progress
  784. char num[100];
  785. sprintf(num,"%d",static_cast<int>(this->LocalGenerators.size()));
  786. this->GetCMakeInstance()->AddCacheEntry
  787. ("CMAKE_NUMBER_OF_LOCAL_GENERATORS", num,
  788. "number of local generators", cmCacheManager::INTERNAL);
  789. // check for link libraries and include directories containing "NOTFOUND"
  790. // and for infinite loops
  791. this->CheckLocalGenerators();
  792. // at this point this->LocalGenerators has been filled,
  793. // so create the map from project name to vector of local generators
  794. this->FillProjectMap();
  795. if ( this->CMakeInstance->GetWorkingMode() == cmake::NORMAL_MODE)
  796. {
  797. const char* msg = "Configuring done";
  798. if(cmSystemTools::GetErrorOccuredFlag())
  799. {
  800. msg = "Configuring incomplete, errors occurred!";
  801. }
  802. this->CMakeInstance->UpdateProgress(msg, -1);
  803. }
  804. }
  805. bool cmGlobalGenerator::CheckALLOW_DUPLICATE_CUSTOM_TARGETS()
  806. {
  807. // If the property is not enabled then okay.
  808. if(!this->CMakeInstance
  809. ->GetPropertyAsBool("ALLOW_DUPLICATE_CUSTOM_TARGETS"))
  810. {
  811. return true;
  812. }
  813. // This generator does not support duplicate custom targets.
  814. cmOStringStream e;
  815. e << "This project has enabled the ALLOW_DUPLICATE_CUSTOM_TARGETS "
  816. << "global property. "
  817. << "The \"" << this->GetName() << "\" generator does not support "
  818. << "duplicate custom targets. "
  819. << "Consider using a Makefiles generator or fix the project to not "
  820. << "use duplicat target names.";
  821. cmSystemTools::Error(e.str().c_str());
  822. return false;
  823. }
  824. void cmGlobalGenerator::Generate()
  825. {
  826. // Some generators track files replaced during the Generate.
  827. // Start with an empty vector:
  828. this->FilesReplacedDuringGenerate.clear();
  829. // Check whether this generator is allowed to run.
  830. if(!this->CheckALLOW_DUPLICATE_CUSTOM_TARGETS())
  831. {
  832. return;
  833. }
  834. // Check that all targets are valid.
  835. if(!this->CheckTargets())
  836. {
  837. return;
  838. }
  839. // Iterate through all targets and set up automoc for those which have
  840. // the AUTOMOC property set
  841. this->CreateAutomocTargets();
  842. // For each existing cmLocalGenerator
  843. unsigned int i;
  844. // Put a copy of each global target in every directory.
  845. cmTargets globalTargets;
  846. this->CreateDefaultGlobalTargets(&globalTargets);
  847. for (i = 0; i < this->LocalGenerators.size(); ++i)
  848. {
  849. cmMakefile* mf = this->LocalGenerators[i]->GetMakefile();
  850. cmTargets* targets = &(mf->GetTargets());
  851. cmTargets::iterator tit;
  852. for ( tit = globalTargets.begin(); tit != globalTargets.end(); ++ tit )
  853. {
  854. (*targets)[tit->first] = tit->second;
  855. (*targets)[tit->first].SetMakefile(mf);
  856. }
  857. }
  858. // Add generator specific helper commands
  859. for (i = 0; i < this->LocalGenerators.size(); ++i)
  860. {
  861. this->LocalGenerators[i]->AddHelperCommands();
  862. }
  863. // Trace the dependencies, after that no custom commands should be added
  864. // because their dependencies might not be handled correctly
  865. for (i = 0; i < this->LocalGenerators.size(); ++i)
  866. {
  867. this->LocalGenerators[i]->TraceDependencies();
  868. }
  869. // Compute the manifest of main targets generated.
  870. for (i = 0; i < this->LocalGenerators.size(); ++i)
  871. {
  872. this->LocalGenerators[i]->GenerateTargetManifest();
  873. }
  874. // Create per-target generator information.
  875. this->CreateGeneratorTargets();
  876. // Compute the inter-target dependencies.
  877. if(!this->ComputeTargetDepends())
  878. {
  879. return;
  880. }
  881. // Create a map from local generator to the complete set of targets
  882. // it builds by default.
  883. this->FillLocalGeneratorToTargetMap();
  884. // Generate project files
  885. for (i = 0; i < this->LocalGenerators.size(); ++i)
  886. {
  887. this->SetCurrentLocalGenerator(this->LocalGenerators[i]);
  888. this->LocalGenerators[i]->Generate();
  889. this->LocalGenerators[i]->GenerateInstallRules();
  890. this->LocalGenerators[i]->GenerateTestFiles();
  891. this->CMakeInstance->UpdateProgress("Generating",
  892. (static_cast<float>(i)+1.0f)/
  893. static_cast<float>(this->LocalGenerators.size()));
  894. }
  895. this->SetCurrentLocalGenerator(0);
  896. // Update rule hashes.
  897. this->CheckRuleHashes();
  898. this->WriteSummary();
  899. if (this->ExtraGenerator != 0)
  900. {
  901. this->ExtraGenerator->Generate();
  902. }
  903. this->CMakeInstance->UpdateProgress("Generating done", -1);
  904. }
  905. //----------------------------------------------------------------------------
  906. bool cmGlobalGenerator::ComputeTargetDepends()
  907. {
  908. cmComputeTargetDepends ctd(this);
  909. if(!ctd.Compute())
  910. {
  911. return false;
  912. }
  913. std::vector<cmTarget*> const& targets = ctd.GetTargets();
  914. for(std::vector<cmTarget*>::const_iterator ti = targets.begin();
  915. ti != targets.end(); ++ti)
  916. {
  917. ctd.GetTargetDirectDepends(*ti, this->TargetDependencies[*ti]);
  918. }
  919. return true;
  920. }
  921. //----------------------------------------------------------------------------
  922. bool cmGlobalGenerator::CheckTargets()
  923. {
  924. // Make sure all targets can find their source files.
  925. for(unsigned int i=0; i < this->LocalGenerators.size(); ++i)
  926. {
  927. cmTargets& targets =
  928. this->LocalGenerators[i]->GetMakefile()->GetTargets();
  929. for(cmTargets::iterator ti = targets.begin();
  930. ti != targets.end(); ++ti)
  931. {
  932. cmTarget& target = ti->second;
  933. if(target.GetType() == cmTarget::EXECUTABLE ||
  934. target.GetType() == cmTarget::STATIC_LIBRARY ||
  935. target.GetType() == cmTarget::SHARED_LIBRARY ||
  936. target.GetType() == cmTarget::MODULE_LIBRARY ||
  937. target.GetType() == cmTarget::UTILITY)
  938. {
  939. if(!target.FindSourceFiles())
  940. {
  941. return false;
  942. }
  943. }
  944. }
  945. }
  946. return true;
  947. }
  948. //----------------------------------------------------------------------------
  949. void cmGlobalGenerator::CreateAutomocTargets()
  950. {
  951. #ifdef CMAKE_BUILD_WITH_CMAKE
  952. for(unsigned int i=0; i < this->LocalGenerators.size(); ++i)
  953. {
  954. cmTargets& targets =
  955. this->LocalGenerators[i]->GetMakefile()->GetTargets();
  956. for(cmTargets::iterator ti = targets.begin();
  957. ti != targets.end(); ++ti)
  958. {
  959. cmTarget& target = ti->second;
  960. if(target.GetType() == cmTarget::EXECUTABLE ||
  961. target.GetType() == cmTarget::STATIC_LIBRARY ||
  962. target.GetType() == cmTarget::SHARED_LIBRARY ||
  963. target.GetType() == cmTarget::MODULE_LIBRARY)
  964. {
  965. if(target.GetPropertyAsBool("AUTOMOC") && !target.IsImported())
  966. {
  967. cmQtAutomoc automoc;
  968. automoc.SetupAutomocTarget(&target);
  969. }
  970. }
  971. }
  972. }
  973. #endif
  974. }
  975. //----------------------------------------------------------------------------
  976. void cmGlobalGenerator::CreateGeneratorTargets()
  977. {
  978. // Construct per-target generator information.
  979. for(unsigned int i=0; i < this->LocalGenerators.size(); ++i)
  980. {
  981. cmTargets& targets =
  982. this->LocalGenerators[i]->GetMakefile()->GetTargets();
  983. for(cmTargets::iterator ti = targets.begin();
  984. ti != targets.end(); ++ti)
  985. {
  986. cmTarget* t = &ti->second;
  987. cmGeneratorTarget* gt = new cmGeneratorTarget(t);
  988. this->GeneratorTargets[t] = gt;
  989. this->ComputeTargetObjects(gt);
  990. }
  991. }
  992. }
  993. //----------------------------------------------------------------------------
  994. void cmGlobalGenerator::ClearGeneratorTargets()
  995. {
  996. for(GeneratorTargetsType::iterator i = this->GeneratorTargets.begin();
  997. i != this->GeneratorTargets.end(); ++i)
  998. {
  999. delete i->second;
  1000. }
  1001. this->GeneratorTargets.clear();
  1002. }
  1003. //----------------------------------------------------------------------------
  1004. cmGeneratorTarget* cmGlobalGenerator::GetGeneratorTarget(cmTarget* t) const
  1005. {
  1006. GeneratorTargetsType::const_iterator ti = this->GeneratorTargets.find(t);
  1007. if(ti == this->GeneratorTargets.end())
  1008. {
  1009. this->CMakeInstance->IssueMessage(
  1010. cmake::INTERNAL_ERROR, "Missing cmGeneratorTarget instance!",
  1011. cmListFileBacktrace());
  1012. return 0;
  1013. }
  1014. return ti->second;
  1015. }
  1016. //----------------------------------------------------------------------------
  1017. void cmGlobalGenerator::ComputeTargetObjects(cmGeneratorTarget*) const
  1018. {
  1019. // Implemented in generator subclasses that need this.
  1020. }
  1021. void cmGlobalGenerator::CheckLocalGenerators()
  1022. {
  1023. std::map<cmStdString, cmStdString> notFoundMap;
  1024. // std::set<cmStdString> notFoundMap;
  1025. // after it is all done do a ConfigureFinalPass
  1026. cmCacheManager* manager = 0;
  1027. for (unsigned int i = 0; i < this->LocalGenerators.size(); ++i)
  1028. {
  1029. manager = this->LocalGenerators[i]->GetMakefile()->GetCacheManager();
  1030. this->LocalGenerators[i]->ConfigureFinalPass();
  1031. cmTargets & targets =
  1032. this->LocalGenerators[i]->GetMakefile()->GetTargets();
  1033. for (cmTargets::iterator l = targets.begin();
  1034. l != targets.end(); l++)
  1035. {
  1036. const cmTarget::LinkLibraryVectorType& libs =
  1037. l->second.GetOriginalLinkLibraries();
  1038. for(cmTarget::LinkLibraryVectorType::const_iterator lib = libs.begin();
  1039. lib != libs.end(); ++lib)
  1040. {
  1041. if(lib->first.size() > 9 &&
  1042. cmSystemTools::IsNOTFOUND(lib->first.c_str()))
  1043. {
  1044. std::string varName = lib->first.substr(0, lib->first.size()-9);
  1045. cmCacheManager::CacheIterator it =
  1046. manager->GetCacheIterator(varName.c_str());
  1047. if(it.GetPropertyAsBool("ADVANCED"))
  1048. {
  1049. varName += " (ADVANCED)";
  1050. }
  1051. std::string text = notFoundMap[varName];
  1052. text += "\n linked by target \"";
  1053. text += l->second.GetName();
  1054. text += "\" in directory ";
  1055. text+=this->LocalGenerators[i]->GetMakefile()->GetCurrentDirectory();
  1056. notFoundMap[varName] = text;
  1057. }
  1058. }
  1059. std::vector<std::string> incs;
  1060. this->LocalGenerators[i]->GetIncludeDirectories(incs, &l->second);
  1061. for( std::vector<std::string>::const_iterator incDir = incs.begin();
  1062. incDir != incs.end(); ++incDir)
  1063. {
  1064. if(incDir->size() > 9 &&
  1065. cmSystemTools::IsNOTFOUND(incDir->c_str()))
  1066. {
  1067. std::string varName = incDir->substr(0, incDir->size()-9);
  1068. cmCacheManager::CacheIterator it =
  1069. manager->GetCacheIterator(varName.c_str());
  1070. if(it.GetPropertyAsBool("ADVANCED"))
  1071. {
  1072. varName += " (ADVANCED)";
  1073. }
  1074. std::string text = notFoundMap[varName];
  1075. text += "\n used as include directory in directory ";
  1076. text += this->LocalGenerators[i]
  1077. ->GetMakefile()->GetCurrentDirectory();
  1078. notFoundMap[varName] = text;
  1079. }
  1080. }
  1081. }
  1082. this->CMakeInstance->UpdateProgress
  1083. ("Configuring", 0.9f+0.1f*(static_cast<float>(i)+1.0f)/
  1084. static_cast<float>(this->LocalGenerators.size()));
  1085. }
  1086. if(notFoundMap.size())
  1087. {
  1088. std::string notFoundVars;
  1089. for(std::map<cmStdString, cmStdString>::const_iterator
  1090. ii = notFoundMap.begin();
  1091. ii != notFoundMap.end();
  1092. ++ii)
  1093. {
  1094. notFoundVars += ii->first;
  1095. notFoundVars += ii->second;
  1096. notFoundVars += "\n";
  1097. }
  1098. cmSystemTools::Error("The following variables are used in this project, "
  1099. "but they are set to NOTFOUND.\n"
  1100. "Please set them or make sure they are set and "
  1101. "tested correctly in the CMake files:\n",
  1102. notFoundVars.c_str());
  1103. }
  1104. }
  1105. int cmGlobalGenerator::TryCompile(const char *srcdir, const char *bindir,
  1106. const char *projectName,
  1107. const char *target, bool fast,
  1108. std::string *output, cmMakefile *mf)
  1109. {
  1110. // if this is not set, then this is a first time configure
  1111. // and there is a good chance that the try compile stuff will
  1112. // take the bulk of the time, so try and guess some progress
  1113. // by getting closer and closer to 100 without actually getting there.
  1114. if (!this->CMakeInstance->GetCacheManager()->GetCacheValue
  1115. ("CMAKE_NUMBER_OF_LOCAL_GENERATORS"))
  1116. {
  1117. // If CMAKE_NUMBER_OF_LOCAL_GENERATORS is not set
  1118. // we are in the first time progress and we have no
  1119. // idea how long it will be. So, just move 1/10th of the way
  1120. // there each time, and don't go over 95%
  1121. this->FirstTimeProgress += ((1.0f - this->FirstTimeProgress) /30.0f);
  1122. if(this->FirstTimeProgress > 0.95f)
  1123. {
  1124. this->FirstTimeProgress = 0.95f;
  1125. }
  1126. this->CMakeInstance->UpdateProgress("Configuring",
  1127. this->FirstTimeProgress);
  1128. }
  1129. std::string makeCommand = this->CMakeInstance->
  1130. GetCacheManager()->GetCacheValue("CMAKE_MAKE_PROGRAM");
  1131. if(makeCommand.size() == 0)
  1132. {
  1133. cmSystemTools::Error(
  1134. "Generator cannot find the appropriate make command.");
  1135. return 1;
  1136. }
  1137. std::string newTarget;
  1138. if (target && strlen(target))
  1139. {
  1140. newTarget += target;
  1141. #if 0
  1142. #if defined(_WIN32) || defined(__CYGWIN__)
  1143. std::string tmp = target;
  1144. // if the target does not already end in . something
  1145. // then assume .exe
  1146. if(tmp.size() < 4 || tmp[tmp.size()-4] != '.')
  1147. {
  1148. newTarget += ".exe";
  1149. }
  1150. #endif // WIN32
  1151. #endif
  1152. }
  1153. const char* config = mf->GetDefinition("CMAKE_TRY_COMPILE_CONFIGURATION");
  1154. return this->Build(srcdir,bindir,projectName,
  1155. newTarget.c_str(),
  1156. output,makeCommand.c_str(),config,false,fast,
  1157. this->TryCompileTimeout);
  1158. }
  1159. std::string cmGlobalGenerator
  1160. ::GenerateBuildCommand(const char* makeProgram, const char *projectName,
  1161. const char* additionalOptions, const char *targetName,
  1162. const char* config, bool ignoreErrors, bool)
  1163. {
  1164. // Project name and config are not used yet.
  1165. (void)projectName;
  1166. (void)config;
  1167. std::string makeCommand =
  1168. cmSystemTools::ConvertToUnixOutputPath(makeProgram);
  1169. // Since we have full control over the invocation of nmake, let us
  1170. // make it quiet.
  1171. if ( strcmp(this->GetName(), "NMake Makefiles") == 0 )
  1172. {
  1173. makeCommand += " /NOLOGO ";
  1174. }
  1175. if ( ignoreErrors )
  1176. {
  1177. makeCommand += " -i";
  1178. }
  1179. if ( additionalOptions )
  1180. {
  1181. makeCommand += " ";
  1182. makeCommand += additionalOptions;
  1183. }
  1184. if ( targetName )
  1185. {
  1186. makeCommand += " ";
  1187. makeCommand += targetName;
  1188. }
  1189. return makeCommand;
  1190. }
  1191. int cmGlobalGenerator::Build(
  1192. const char *, const char *bindir,
  1193. const char *projectName, const char *target,
  1194. std::string *output,
  1195. const char *makeCommandCSTR,
  1196. const char *config,
  1197. bool clean, bool fast,
  1198. double timeout,
  1199. cmSystemTools::OutputOption outputflag,
  1200. const char* extraOptions,
  1201. std::vector<std::string> const& nativeOptions)
  1202. {
  1203. /**
  1204. * Run an executable command and put the stdout in output.
  1205. */
  1206. std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
  1207. cmSystemTools::ChangeDirectory(bindir);
  1208. if(output)
  1209. {
  1210. *output += "Change Dir: ";
  1211. *output += bindir;
  1212. *output += "\n";
  1213. }
  1214. int retVal;
  1215. bool hideconsole = cmSystemTools::GetRunCommandHideConsole();
  1216. cmSystemTools::SetRunCommandHideConsole(true);
  1217. std::string outputBuffer;
  1218. std::string* outputPtr = 0;
  1219. if(output)
  1220. {
  1221. outputPtr = &outputBuffer;
  1222. }
  1223. // should we do a clean first?
  1224. if (clean)
  1225. {
  1226. std::string cleanCommand =
  1227. this->GenerateBuildCommand(makeCommandCSTR, projectName,
  1228. 0, "clean", config, false, fast);
  1229. if(output)
  1230. {
  1231. *output += "\nRun Clean Command:";
  1232. *output += cleanCommand;
  1233. *output += "\n";
  1234. }
  1235. if (!cmSystemTools::RunSingleCommand(cleanCommand.c_str(), outputPtr,
  1236. &retVal, 0, outputflag, timeout))
  1237. {
  1238. cmSystemTools::SetRunCommandHideConsole(hideconsole);
  1239. cmSystemTools::Error("Generator: execution of make clean failed.");
  1240. if (output)
  1241. {
  1242. *output += *outputPtr;
  1243. *output += "\nGenerator: execution of make clean failed.\n";
  1244. }
  1245. // return to the original directory
  1246. cmSystemTools::ChangeDirectory(cwd.c_str());
  1247. return 1;
  1248. }
  1249. if (output)
  1250. {
  1251. *output += *outputPtr;
  1252. }
  1253. }
  1254. // now build
  1255. std::string makeCommand =
  1256. this->GenerateBuildCommand(makeCommandCSTR, projectName,
  1257. extraOptions, target,
  1258. config, false, fast);
  1259. if(output)
  1260. {
  1261. *output += "\nRun Build Command:";
  1262. *output += makeCommand;
  1263. *output += "\n";
  1264. }
  1265. std::vector<cmStdString> command =
  1266. cmSystemTools::ParseArguments(makeCommand.c_str());
  1267. for(std::vector<std::string>::const_iterator ni = nativeOptions.begin();
  1268. ni != nativeOptions.end(); ++ni)
  1269. {
  1270. command.push_back(*ni);
  1271. }
  1272. if (!cmSystemTools::RunSingleCommand(command, outputPtr,
  1273. &retVal, 0, outputflag, timeout))
  1274. {
  1275. cmSystemTools::SetRunCommandHideConsole(hideconsole);
  1276. cmSystemTools::Error
  1277. ("Generator: execution of make failed. Make command was: ",
  1278. makeCommand.c_str());
  1279. if (output)
  1280. {
  1281. *output += *outputPtr;
  1282. *output += "\nGenerator: execution of make failed. Make command was: "
  1283. + makeCommand + "\n";
  1284. }
  1285. // return to the original directory
  1286. cmSystemTools::ChangeDirectory(cwd.c_str());
  1287. return 1;
  1288. }
  1289. if (output)
  1290. {
  1291. *output += *outputPtr;
  1292. }
  1293. cmSystemTools::SetRunCommandHideConsole(hideconsole);
  1294. // The SGI MipsPro 7.3 compiler does not return an error code when
  1295. // the source has a #error in it! This is a work-around for such
  1296. // compilers.
  1297. if((retVal == 0) && (output->find("#error") != std::string::npos))
  1298. {
  1299. retVal = 1;
  1300. }
  1301. cmSystemTools::ChangeDirectory(cwd.c_str());
  1302. return retVal;
  1303. }
  1304. void cmGlobalGenerator::AddLocalGenerator(cmLocalGenerator *lg)
  1305. {
  1306. this->LocalGenerators.push_back(lg);
  1307. // update progress
  1308. // estimate how many lg there will be
  1309. const char *numGenC =
  1310. this->CMakeInstance->GetCacheManager()->GetCacheValue
  1311. ("CMAKE_NUMBER_OF_LOCAL_GENERATORS");
  1312. if (!numGenC)
  1313. {
  1314. // If CMAKE_NUMBER_OF_LOCAL_GENERATORS is not set
  1315. // we are in the first time progress and we have no
  1316. // idea how long it will be. So, just move half way
  1317. // there each time, and don't go over 95%
  1318. this->FirstTimeProgress += ((1.0f - this->FirstTimeProgress) /30.0f);
  1319. if(this->FirstTimeProgress > 0.95f)
  1320. {
  1321. this->FirstTimeProgress = 0.95f;
  1322. }
  1323. this->CMakeInstance->UpdateProgress("Configuring",
  1324. this->FirstTimeProgress);
  1325. return;
  1326. }
  1327. int numGen = atoi(numGenC);
  1328. float prog = 0.9f*static_cast<float>(this->LocalGenerators.size())/
  1329. static_cast<float>(numGen);
  1330. if (prog > 0.9f)
  1331. {
  1332. prog = 0.9f;
  1333. }
  1334. this->CMakeInstance->UpdateProgress("Configuring", prog);
  1335. }
  1336. void cmGlobalGenerator::AddInstallComponent(const char* component)
  1337. {
  1338. if(component && *component)
  1339. {
  1340. this->InstallComponents.insert(component);
  1341. }
  1342. }
  1343. void cmGlobalGenerator::AddTargetToExports(const char* exportSetName,
  1344. cmTarget* target,
  1345. cmInstallTargetGenerator* archive,
  1346. cmInstallTargetGenerator* runTime,
  1347. cmInstallTargetGenerator* library,
  1348. cmInstallTargetGenerator* framework,
  1349. cmInstallTargetGenerator* bundle,
  1350. cmInstallFilesGenerator* headers)
  1351. {
  1352. if ((exportSetName) && (*exportSetName) && (target))
  1353. {
  1354. cmTargetExport* te = new cmTargetExport(target, archive, runTime, library,
  1355. framework, bundle, headers);
  1356. this->ExportSets[exportSetName].push_back(te);
  1357. }
  1358. }
  1359. //----------------------------------------------------------------------------
  1360. void cmGlobalGenerator::ClearExportSets()
  1361. {
  1362. for(std::map<cmStdString, std::vector<cmTargetExport*> >::iterator
  1363. setIt = this->ExportSets.begin();
  1364. setIt != this->ExportSets.end(); ++setIt)
  1365. {
  1366. for(unsigned int i = 0; i < setIt->second.size(); ++i)
  1367. {
  1368. delete setIt->second[i];
  1369. }
  1370. }
  1371. this->ExportSets.clear();
  1372. }
  1373. const std::vector<cmTargetExport*>* cmGlobalGenerator::GetExportSet(
  1374. const char* name) const
  1375. {
  1376. std::map<cmStdString, std::vector<cmTargetExport*> >::const_iterator
  1377. exportSetIt = this->ExportSets.find(name);
  1378. if (exportSetIt != this->ExportSets.end())
  1379. {
  1380. return &exportSetIt->second;
  1381. }
  1382. return 0;
  1383. }
  1384. void cmGlobalGenerator::EnableInstallTarget()
  1385. {
  1386. this->InstallTargetEnabled = true;
  1387. }
  1388. cmLocalGenerator *cmGlobalGenerator::CreateLocalGenerator()
  1389. {
  1390. cmLocalGenerator *lg = new cmLocalGenerator;
  1391. lg->SetGlobalGenerator(this);
  1392. return lg;
  1393. }
  1394. void cmGlobalGenerator::EnableLanguagesFromGenerator(cmGlobalGenerator *gen,
  1395. cmMakefile* mf)
  1396. {
  1397. this->SetConfiguredFilesPath(gen);
  1398. this->TryCompileOuterMakefile = mf;
  1399. const char* make =
  1400. gen->GetCMakeInstance()->GetCacheDefinition("CMAKE_MAKE_PROGRAM");
  1401. this->GetCMakeInstance()->AddCacheEntry("CMAKE_MAKE_PROGRAM", make,
  1402. "make program",
  1403. cmCacheManager::FILEPATH);
  1404. // copy the enabled languages
  1405. this->LanguageEnabled = gen->LanguageEnabled;
  1406. this->LanguagesReady = gen->LanguagesReady;
  1407. this->ExtensionToLanguage = gen->ExtensionToLanguage;
  1408. this->IgnoreExtensions = gen->IgnoreExtensions;
  1409. this->LanguageToOutputExtension = gen->LanguageToOutputExtension;
  1410. this->LanguageToLinkerPreference = gen->LanguageToLinkerPreference;
  1411. this->OutputExtensions = gen->OutputExtensions;
  1412. }
  1413. //----------------------------------------------------------------------------
  1414. void cmGlobalGenerator::SetConfiguredFilesPath(cmGlobalGenerator* gen)
  1415. {
  1416. if(!gen->ConfiguredFilesPath.empty())
  1417. {
  1418. this->ConfiguredFilesPath = gen->ConfiguredFilesPath;
  1419. }
  1420. else
  1421. {
  1422. this->ConfiguredFilesPath = gen->CMakeInstance->GetHomeOutputDirectory();
  1423. this->ConfiguredFilesPath += cmake::GetCMakeFilesDirectory();
  1424. }
  1425. }
  1426. //----------------------------------------------------------------------------
  1427. void cmGlobalGenerator::GetDocumentation(cmDocumentationEntry& entry) const
  1428. {
  1429. entry.Name = this->GetName();
  1430. entry.Brief = "";
  1431. entry.Full = "";
  1432. }
  1433. bool cmGlobalGenerator::IsExcluded(cmLocalGenerator* root,
  1434. cmLocalGenerator* gen)
  1435. {
  1436. if(!gen || gen == root)
  1437. {
  1438. // No directory excludes itself.
  1439. return false;
  1440. }
  1441. if(gen->GetMakefile()->GetPropertyAsBool("EXCLUDE_FROM_ALL"))
  1442. {
  1443. // This directory is excluded from its parent.
  1444. return true;
  1445. }
  1446. // This directory is included in its parent. Check whether the
  1447. // parent is excluded.
  1448. return this->IsExcluded(root, gen->GetParent());
  1449. }
  1450. bool cmGlobalGenerator::IsExcluded(cmLocalGenerator* root,
  1451. cmTarget& target)
  1452. {
  1453. if(target.GetPropertyAsBool("EXCLUDE_FROM_ALL"))
  1454. {
  1455. // This target is excluded from its directory.
  1456. return true;
  1457. }
  1458. else
  1459. {
  1460. // This target is included in its directory. Check whether the
  1461. // directory is excluded.
  1462. return this->IsExcluded(root, target.GetMakefile()->GetLocalGenerator());
  1463. }
  1464. }
  1465. void cmGlobalGenerator::GetEnabledLanguages(std::vector<std::string>& lang)
  1466. {
  1467. for(std::map<cmStdString, bool>::iterator i =
  1468. this->LanguageEnabled.begin(); i != this->LanguageEnabled.end(); ++i)
  1469. {
  1470. lang.push_back(i->first);
  1471. }
  1472. }
  1473. int cmGlobalGenerator::GetLinkerPreference(const char* lang)
  1474. {
  1475. std::map<cmStdString, int>::const_iterator it =
  1476. this->LanguageToLinkerPreference.find(lang);
  1477. if (it != this->LanguageToLinkerPreference.end())
  1478. {
  1479. return it->second;
  1480. }
  1481. return 0;
  1482. }
  1483. void cmGlobalGenerator::FillProjectMap()
  1484. {
  1485. this->ProjectMap.clear(); // make sure we start with a clean map
  1486. unsigned int i;
  1487. for(i = 0; i < this->LocalGenerators.size(); ++i)
  1488. {
  1489. // for each local generator add all projects
  1490. cmLocalGenerator *lg = this->LocalGenerators[i];
  1491. std::string name;
  1492. do
  1493. {
  1494. if (name != lg->GetMakefile()->GetProjectName())
  1495. {
  1496. name = lg->GetMakefile()->GetProjectName();
  1497. this->ProjectMap[name].push_back(this->LocalGenerators[i]);
  1498. }
  1499. lg = lg->GetParent();
  1500. }
  1501. while (lg);
  1502. }
  1503. }
  1504. // Build a map that contains a the set of targets used by each local
  1505. // generator directory level.
  1506. void cmGlobalGenerator::FillLocalGeneratorToTargetMap()
  1507. {
  1508. this->LocalGeneratorToTargetMap.clear();
  1509. // Loop over all targets in all local generators.
  1510. for(std::vector<cmLocalGenerator*>::const_iterator
  1511. lgi = this->LocalGenerators.begin();
  1512. lgi != this->LocalGenerators.end(); ++lgi)
  1513. {
  1514. cmLocalGenerator* lg = *lgi;
  1515. cmMakefile* mf = lg->GetMakefile();
  1516. cmTargets& targets = mf->GetTargets();
  1517. for(cmTargets::iterator t = targets.begin(); t != targets.end(); ++t)
  1518. {
  1519. cmTarget& target = t->second;
  1520. // Consider the directory containing the target and all its
  1521. // parents until something excludes the target.
  1522. for(cmLocalGenerator* clg = lg; clg && !this->IsExcluded(clg, target);
  1523. clg = clg->GetParent())
  1524. {
  1525. // This local generator includes the target.
  1526. std::set<cmTarget*>& targetSet =
  1527. this->LocalGeneratorToTargetMap[clg];
  1528. targetSet.insert(&target);
  1529. // Add dependencies of the included target. An excluded
  1530. // target may still be included if it is a dependency of a
  1531. // non-excluded target.
  1532. TargetDependSet const& tgtdeps = this->GetTargetDirectDepends(target);
  1533. for(TargetDependSet::const_iterator ti = tgtdeps.begin();
  1534. ti != tgtdeps.end(); ++ti)
  1535. {
  1536. targetSet.insert(*ti);
  1537. }
  1538. }
  1539. }
  1540. }
  1541. }
  1542. ///! Find a local generator by its startdirectory
  1543. cmLocalGenerator* cmGlobalGenerator::FindLocalGenerator(const char* start_dir)
  1544. {
  1545. std::vector<cmLocalGenerator*>* gens = &this->LocalGenerators;
  1546. for(unsigned int i = 0; i < gens->size(); ++i)
  1547. {
  1548. std::string sd = (*gens)[i]->GetMakefile()->GetStartDirectory();
  1549. if (sd == start_dir)
  1550. {
  1551. return (*gens)[i];
  1552. }
  1553. }
  1554. return 0;
  1555. }
  1556. //----------------------------------------------------------------------------
  1557. cmTarget*
  1558. cmGlobalGenerator::FindTarget(const char* project, const char* name)
  1559. {
  1560. // if project specific
  1561. if(project)
  1562. {
  1563. std::vector<cmLocalGenerator*>* gens = &this->ProjectMap[project];
  1564. for(unsigned int i = 0; i < gens->size(); ++i)
  1565. {
  1566. cmTarget* ret = (*gens)[i]->GetMakefile()->FindTarget(name);
  1567. if(ret)
  1568. {
  1569. return ret;
  1570. }
  1571. }
  1572. }
  1573. // if all projects/directories
  1574. else
  1575. {
  1576. std::map<cmStdString,cmTarget *>::iterator i =
  1577. this->TotalTargets.find ( name );
  1578. if ( i != this->TotalTargets.end() )
  1579. {
  1580. return i->second;
  1581. }
  1582. i = this->ImportedTargets.find(name);
  1583. if ( i != this->ImportedTargets.end() )
  1584. {
  1585. return i->second;
  1586. }
  1587. }
  1588. return 0;
  1589. }
  1590. //----------------------------------------------------------------------------
  1591. bool cmGlobalGenerator::NameResolvesToFramework(const std::string& libname)
  1592. {
  1593. if(cmSystemTools::IsPathToFramework(libname.c_str()))
  1594. {
  1595. return true;
  1596. }
  1597. if(cmTarget* tgt = this->FindTarget(0, libname.c_str()))
  1598. {
  1599. if(tgt->IsFrameworkOnApple())
  1600. {
  1601. return true;
  1602. }
  1603. }
  1604. return false;
  1605. }
  1606. //----------------------------------------------------------------------------
  1607. inline std::string removeQuotes(const std::string& s)
  1608. {
  1609. if(s[0] == '\"' && s[s.size()-1] == '\"')
  1610. {
  1611. return s.substr(1, s.size()-2);
  1612. }
  1613. return s;
  1614. }
  1615. void cmGlobalGenerator::SetCMakeInstance(cmake* cm)
  1616. {
  1617. // Store a pointer to the cmake object instance.
  1618. this->CMakeInstance = cm;
  1619. }
  1620. void cmGlobalGenerator::CreateDefaultGlobalTargets(cmTargets* targets)
  1621. {
  1622. cmMakefile* mf = this->LocalGenerators[0]->GetMakefile();
  1623. const char* cmakeCfgIntDir = this->GetCMakeCFGIntDir();
  1624. const char* cmakeCommand = mf->GetRequiredDefinition("CMAKE_COMMAND");
  1625. // CPack
  1626. std::string workingDir = mf->GetStartOutputDirectory();
  1627. cmCustomCommandLines cpackCommandLines;
  1628. std::vector<std::string> depends;
  1629. cmCustomCommandLine singleLine;
  1630. singleLine.push_back(this->GetCMakeInstance()->GetCPackCommand());
  1631. if ( cmakeCfgIntDir && *cmakeCfgIntDir && cmakeCfgIntDir[0] != '.' )
  1632. {
  1633. singleLine.push_back("-C");
  1634. singleLine.push_back(cmakeCfgIntDir);
  1635. }
  1636. singleLine.push_back("--config");
  1637. std::string configFile = mf->GetStartOutputDirectory();;
  1638. configFile += "/CPackConfig.cmake";
  1639. std::string relConfigFile = "./CPackConfig.cmake";
  1640. singleLine.push_back(relConfigFile);
  1641. cpackCommandLines.push_back(singleLine);
  1642. if ( this->GetPreinstallTargetName() )
  1643. {
  1644. depends.push_back(this->GetPreinstallTargetName());
  1645. }
  1646. else
  1647. {
  1648. const char* noPackageAll =
  1649. mf->GetDefinition("CMAKE_SKIP_PACKAGE_ALL_DEPENDENCY");
  1650. if(!noPackageAll || cmSystemTools::IsOff(noPackageAll))
  1651. {
  1652. depends.push_back(this->GetAllTargetName());
  1653. }
  1654. }
  1655. if(cmSystemTools::FileExists(configFile.c_str()))
  1656. {
  1657. (*targets)[this->GetPackageTargetName()]
  1658. = this->CreateGlobalTarget(this->GetPackageTargetName(),
  1659. "Run CPack packaging tool...",
  1660. &cpackCommandLines, depends,
  1661. workingDir.c_str());
  1662. }
  1663. // CPack source
  1664. const char* packageSourceTargetName = this->GetPackageSourceTargetName();
  1665. if ( packageSourceTargetName )
  1666. {
  1667. cpackCommandLines.erase(cpackCommandLines.begin(),
  1668. cpackCommandLines.end());
  1669. singleLine.erase(singleLine.begin(), singleLine.end());
  1670. depends.erase(depends.begin(), depends.end());
  1671. singleLine.push_back(this->GetCMakeInstance()->GetCPackCommand());
  1672. singleLine.push_back("--config");
  1673. configFile = mf->GetStartOutputDirectory();;
  1674. configFile += "/CPackSourceConfig.cmake";
  1675. relConfigFile = "./CPackSourceConfig.cmake";
  1676. singleLine.push_back(relConfigFile);
  1677. if(cmSystemTools::FileExists(configFile.c_str()))
  1678. {
  1679. singleLine.push_back(configFile);
  1680. cpackCommandLines.push_back(singleLine);
  1681. (*targets)[packageSourceTargetName]
  1682. = this->CreateGlobalTarget(packageSourceTargetName,
  1683. "Run CPack packaging tool for source...",
  1684. &cpackCommandLines, depends,
  1685. workingDir.c_str()
  1686. );
  1687. }
  1688. }
  1689. // Test
  1690. if(mf->IsOn("CMAKE_TESTING_ENABLED"))
  1691. {
  1692. cpackCommandLines.erase(cpackCommandLines.begin(),
  1693. cpackCommandLines.end());
  1694. singleLine.erase(singleLine.begin(), singleLine.end());
  1695. depends.erase(depends.begin(), depends.end());
  1696. singleLine.push_back(this->GetCMakeInstance()->GetCTestCommand());
  1697. singleLine.push_back("--force-new-ctest-process");
  1698. if(cmakeCfgIntDir && *cmakeCfgIntDir && cmakeCfgIntDir[0] != '.')
  1699. {
  1700. singleLine.push_back("-C");
  1701. singleLine.push_back(cmakeCfgIntDir);
  1702. }
  1703. else // TODO: This is a hack. Should be something to do with the generator
  1704. {
  1705. singleLine.push_back("$(ARGS)");
  1706. }
  1707. cpackCommandLines.push_back(singleLine);
  1708. (*targets)[this->GetTestTargetName()]
  1709. = this->CreateGlobalTarget(this->GetTestTargetName(),
  1710. "Running tests...", &cpackCommandLines, depends, 0);
  1711. }
  1712. //Edit Cache
  1713. const char* editCacheTargetName = this->GetEditCacheTargetName();
  1714. if ( editCacheTargetName )
  1715. {
  1716. cpackCommandLines.erase(cpackCommandLines.begin(),
  1717. cpackCommandLines.end());
  1718. singleLine.erase(singleLine.begin(), singleLine.end());
  1719. depends.erase(depends.begin(), depends.end());
  1720. // Use CMAKE_EDIT_COMMAND for the edit_cache rule if it is defined.
  1721. // Otherwise default to the interactive command-line interface.
  1722. if(mf->GetDefinition("CMAKE_EDIT_COMMAND"))
  1723. {
  1724. singleLine.push_back(mf->GetDefinition("CMAKE_EDIT_COMMAND"));
  1725. singleLine.push_back("-H$(CMAKE_SOURCE_DIR)");
  1726. singleLine.push_back("-B$(CMAKE_BINARY_DIR)");
  1727. cpackCommandLines.push_back(singleLine);
  1728. (*targets)[editCacheTargetName] =
  1729. this->CreateGlobalTarget(
  1730. editCacheTargetName, "Running CMake cache editor...",
  1731. &cpackCommandLines, depends, 0);
  1732. }
  1733. else
  1734. {
  1735. singleLine.push_back(cmakeCommand);
  1736. singleLine.push_back("-i");
  1737. singleLine.push_back(".");
  1738. cpackCommandLines.push_back(singleLine);
  1739. (*targets)[editCacheTargetName] =
  1740. this->CreateGlobalTarget(
  1741. editCacheTargetName,
  1742. "Running interactive CMake command-line interface...",
  1743. &cpackCommandLines, depends, 0);
  1744. }
  1745. }
  1746. //Rebuild Cache
  1747. const char* rebuildCacheTargetName = this->GetRebuildCacheTargetName();
  1748. if ( rebuildCacheTargetName )
  1749. {
  1750. cpackCommandLines.erase(cpackCommandLines.begin(),
  1751. cpackCommandLines.end());
  1752. singleLine.erase(singleLine.begin(), singleLine.end());
  1753. depends.erase(depends.begin(), depends.end());
  1754. singleLine.push_back(cmakeCommand);
  1755. singleLine.push_back("-H$(CMAKE_SOURCE_DIR)");
  1756. singleLine.push_back("-B$(CMAKE_BINARY_DIR)");
  1757. cpackCommandLines.push_back(singleLine);
  1758. (*targets)[rebuildCacheTargetName] =
  1759. this->CreateGlobalTarget(
  1760. rebuildCacheTargetName, "Running CMake to regenerate build system...",
  1761. &cpackCommandLines, depends, 0);
  1762. }
  1763. //Install
  1764. if(this->InstallTargetEnabled)
  1765. {
  1766. if(!cmakeCfgIntDir || !*cmakeCfgIntDir || cmakeCfgIntDir[0] == '.')
  1767. {
  1768. std::set<cmStdString>* componentsSet = &this->InstallComponents;
  1769. cpackCommandLines.erase(cpackCommandLines.begin(),
  1770. cpackCommandLines.end());
  1771. depends.erase(depends.begin(), depends.end());
  1772. cmOStringStream ostr;
  1773. if ( componentsSet->size() > 0 )
  1774. {
  1775. ostr << "Available install components are:";
  1776. std::set<cmStdString>::iterator it;
  1777. for (
  1778. it = componentsSet->begin();
  1779. it != componentsSet->end();
  1780. ++ it )
  1781. {
  1782. ostr << " \"" << it->c_str() << "\"";
  1783. }
  1784. }
  1785. else
  1786. {
  1787. ostr << "Only default component available";
  1788. }
  1789. singleLine.push_back(ostr.str().c_str());
  1790. (*targets)["list_install_components"]
  1791. = this->CreateGlobalTarget("list_install_components",
  1792. ostr.str().c_str(),
  1793. &cpackCommandLines, depends, 0);
  1794. }
  1795. std::string cmd = cmakeCommand;
  1796. cpackCommandLines.erase(cpackCommandLines.begin(),
  1797. cpackCommandLines.end());
  1798. singleLine.erase(singleLine.begin(), singleLine.end());
  1799. depends.erase(depends.begin(), depends.end());
  1800. if ( this->GetPreinstallTargetName() )
  1801. {
  1802. depends.push_back(this->GetPreinstallTargetName());
  1803. }
  1804. else
  1805. {
  1806. const char* noall =
  1807. mf->GetDefinition("CMAKE_SKIP_INSTALL_ALL_DEPENDENCY");
  1808. if(!noall || cmSystemTools::IsOff(noall))
  1809. {
  1810. depends.push_back(this->GetAllTargetName());
  1811. }
  1812. }
  1813. if(mf->GetDefinition("CMake_BINARY_DIR"))
  1814. {
  1815. // We are building CMake itself. We cannot use the original
  1816. // executable to install over itself. The generator will
  1817. // automatically convert this name to the build-time location.
  1818. cmd = "cmake";
  1819. }
  1820. singleLine.push_back(cmd.c_str());
  1821. if ( cmakeCfgIntDir && *cmakeCfgIntDir && cmakeCfgIntDir[0] != '.' )
  1822. {
  1823. std::string cfgArg = "-DBUILD_TYPE=";
  1824. cfgArg += mf->GetDefinition("CMAKE_CFG_INTDIR");
  1825. singleLine.push_back(cfgArg);
  1826. }
  1827. singleLine.push_back("-P");
  1828. singleLine.push_back("cmake_install.cmake");
  1829. cpackCommandLines.push_back(singleLine);
  1830. (*targets)[this->GetInstallTargetName()] =
  1831. this->CreateGlobalTarget(
  1832. this->GetInstallTargetName(), "Install the project...",
  1833. &cpackCommandLines, depends, 0);
  1834. // install_local
  1835. if(const char* install_local = this->GetInstallLocalTargetName())
  1836. {
  1837. cmCustomCommandLine localCmdLine = singleLine;
  1838. localCmdLine.insert(localCmdLine.begin()+1,
  1839. "-DCMAKE_INSTALL_LOCAL_ONLY=1");
  1840. cpackCommandLines.erase(cpackCommandLines.begin(),
  1841. cpackCommandLines.end());
  1842. cpackCommandLines.push_back(localCmdLine);
  1843. (*targets)[install_local] =
  1844. this->CreateGlobalTarget(
  1845. install_local, "Installing only the local directory...",
  1846. &cpackCommandLines, depends, 0);
  1847. }
  1848. // install_strip
  1849. const char* install_strip = this->GetInstallStripTargetName();
  1850. if((install_strip !=0) && (mf->IsSet("CMAKE_STRIP")))
  1851. {
  1852. cmCustomCommandLine stripCmdLine = singleLine;
  1853. stripCmdLine.insert(stripCmdLine.begin()+1,"-DCMAKE_INSTALL_DO_STRIP=1");
  1854. cpackCommandLines.erase(cpackCommandLines.begin(),
  1855. cpackCommandLines.end());
  1856. cpackCommandLines.push_back(stripCmdLine);
  1857. (*targets)[install_strip] =
  1858. this->CreateGlobalTarget(
  1859. install_strip, "Installing the project stripped...",
  1860. &cpackCommandLines, depends, 0);
  1861. }
  1862. }
  1863. }
  1864. //----------------------------------------------------------------------------
  1865. const char* cmGlobalGenerator::GetPredefinedTargetsFolder()
  1866. {
  1867. const char* prop =
  1868. this->GetCMakeInstance()->GetProperty("PREDEFINED_TARGETS_FOLDER");
  1869. if (prop)
  1870. {
  1871. return prop;
  1872. }
  1873. return "CMakePredefinedTargets";
  1874. }
  1875. //----------------------------------------------------------------------------
  1876. bool cmGlobalGenerator::UseFolderProperty()
  1877. {
  1878. const char* prop = this->GetCMakeInstance()->GetProperty("USE_FOLDERS");
  1879. // If this property is defined, let the setter turn this on or off...
  1880. //
  1881. if (prop)
  1882. {
  1883. return cmSystemTools::IsOn(prop);
  1884. }
  1885. // By default, this feature is OFF, since it is not supported in the
  1886. // Visual Studio Express editions:
  1887. //
  1888. return false;
  1889. }
  1890. //----------------------------------------------------------------------------
  1891. cmTarget cmGlobalGenerator::CreateGlobalTarget(
  1892. const char* name, const char* message,
  1893. const cmCustomCommandLines* commandLines,
  1894. std::vector<std::string> depends,
  1895. const char* workingDirectory)
  1896. {
  1897. // Package
  1898. cmTarget target;
  1899. target.GetProperties().SetCMakeInstance(this->CMakeInstance);
  1900. target.SetType(cmTarget::GLOBAL_TARGET, name);
  1901. target.SetProperty("EXCLUDE_FROM_ALL","TRUE");
  1902. std::vector<std::string> no_outputs;
  1903. std::vector<std::string> no_depends;
  1904. // Store the custom command in the target.
  1905. cmCustomCommand cc(0, no_outputs, no_depends, *commandLines, 0,
  1906. workingDirectory);
  1907. target.GetPostBuildCommands().push_back(cc);
  1908. target.SetProperty("EchoString", message);
  1909. std::vector<std::string>::iterator dit;
  1910. for ( dit = depends.begin(); dit != depends.end(); ++ dit )
  1911. {
  1912. target.AddUtility(dit->c_str());
  1913. }
  1914. // Organize in the "predefined targets" folder:
  1915. //
  1916. if (this->UseFolderProperty())
  1917. {
  1918. target.SetProperty("FOLDER", this->GetPredefinedTargetsFolder());
  1919. }
  1920. return target;
  1921. }
  1922. //----------------------------------------------------------------------------
  1923. void cmGlobalGenerator::AppendDirectoryForConfig(const char*, const char*,
  1924. const char*, std::string&)
  1925. {
  1926. // Subclasses that support multiple configurations should implement
  1927. // this method to append the subdirectory for the given build
  1928. // configuration.
  1929. }
  1930. //----------------------------------------------------------------------------
  1931. cmGlobalGenerator::TargetDependSet const&
  1932. cmGlobalGenerator::GetTargetDirectDepends(cmTarget & target)
  1933. {
  1934. return this->TargetDependencies[&target];
  1935. }
  1936. void cmGlobalGenerator::AddTarget(cmTarget* t)
  1937. {
  1938. if(t->IsImported())
  1939. {
  1940. this->ImportedTargets[t->GetName()] = t;
  1941. }
  1942. else
  1943. {
  1944. this->TotalTargets[t->GetName()] = t;
  1945. }
  1946. }
  1947. void cmGlobalGenerator::SetExternalMakefileProjectGenerator(
  1948. cmExternalMakefileProjectGenerator *extraGenerator)
  1949. {
  1950. this->ExtraGenerator = extraGenerator;
  1951. if (this->ExtraGenerator!=0)
  1952. {
  1953. this->ExtraGenerator->SetGlobalGenerator(this);
  1954. }
  1955. }
  1956. const char* cmGlobalGenerator::GetExtraGeneratorName() const
  1957. {
  1958. return this->ExtraGenerator==0 ? 0 : this->ExtraGenerator->GetName();
  1959. }
  1960. void cmGlobalGenerator::FileReplacedDuringGenerate(const std::string& filename)
  1961. {
  1962. this->FilesReplacedDuringGenerate.push_back(filename);
  1963. }
  1964. void
  1965. cmGlobalGenerator
  1966. ::GetFilesReplacedDuringGenerate(std::vector<std::string>& filenames)
  1967. {
  1968. filenames.clear();
  1969. std::copy(
  1970. this->FilesReplacedDuringGenerate.begin(),
  1971. this->FilesReplacedDuringGenerate.end(),
  1972. std::back_inserter(filenames));
  1973. }
  1974. //----------------------------------------------------------------------------
  1975. void cmGlobalGenerator::GetTargetSets(TargetDependSet& projectTargets,
  1976. TargetDependSet& originalTargets,
  1977. cmLocalGenerator* root,
  1978. GeneratorVector const& generators)
  1979. {
  1980. // loop over all local generators
  1981. for(std::vector<cmLocalGenerator*>::const_iterator i = generators.begin();
  1982. i != generators.end(); ++i)
  1983. {
  1984. // check to make sure generator is not excluded
  1985. if(this->IsExcluded(root, *i))
  1986. {
  1987. continue;
  1988. }
  1989. cmMakefile* mf = (*i)->GetMakefile();
  1990. // Get the targets in the makefile
  1991. cmTargets &tgts = mf->GetTargets();
  1992. // loop over all the targets
  1993. for (cmTargets::iterator l = tgts.begin(); l != tgts.end(); ++l)
  1994. {
  1995. cmTarget* target = &l->second;
  1996. if(this->IsRootOnlyTarget(target) &&
  1997. target->GetMakefile() != root->GetMakefile())
  1998. {
  1999. continue;
  2000. }
  2001. // put the target in the set of original targets
  2002. originalTargets.insert(target);
  2003. // Get the set of targets that depend on target
  2004. this->AddTargetDepends(target, projectTargets);
  2005. }
  2006. }
  2007. }
  2008. //----------------------------------------------------------------------------
  2009. bool cmGlobalGenerator::IsRootOnlyTarget(cmTarget* target)
  2010. {
  2011. return (target->GetType() == cmTarget::GLOBAL_TARGET ||
  2012. strcmp(target->GetName(), this->GetAllTargetName()) == 0);
  2013. }
  2014. //----------------------------------------------------------------------------
  2015. void cmGlobalGenerator::AddTargetDepends(cmTarget* target,
  2016. TargetDependSet& projectTargets)
  2017. {
  2018. // add the target itself
  2019. if(projectTargets.insert(target).second)
  2020. {
  2021. // This is the first time we have encountered the target.
  2022. // Recursively follow its dependencies.
  2023. TargetDependSet const& ts = this->GetTargetDirectDepends(*target);
  2024. for(TargetDependSet::const_iterator i = ts.begin(); i != ts.end(); ++i)
  2025. {
  2026. cmTarget* dtarget = *i;
  2027. this->AddTargetDepends(dtarget, projectTargets);
  2028. }
  2029. }
  2030. }
  2031. //----------------------------------------------------------------------------
  2032. void cmGlobalGenerator::AddToManifest(const char* config,
  2033. std::string const& f)
  2034. {
  2035. // Add to the main manifest for this configuration.
  2036. this->TargetManifest[config].insert(f);
  2037. // Add to the content listing for the file's directory.
  2038. std::string dir = cmSystemTools::GetFilenamePath(f);
  2039. std::string file = cmSystemTools::GetFilenameName(f);
  2040. this->DirectoryContentMap[dir].insert(file);
  2041. }
  2042. //----------------------------------------------------------------------------
  2043. std::set<cmStdString> const&
  2044. cmGlobalGenerator::GetDirectoryContent(std::string const& dir, bool needDisk)
  2045. {
  2046. DirectoryContent& dc = this->DirectoryContentMap[dir];
  2047. if(needDisk && !dc.LoadedFromDisk)
  2048. {
  2049. // Load the directory content from disk.
  2050. cmsys::Directory d;
  2051. if(d.Load(dir.c_str()))
  2052. {
  2053. unsigned long n = d.GetNumberOfFiles();
  2054. for(unsigned long i = 0; i < n; ++i)
  2055. {
  2056. const char* f = d.GetFile(i);
  2057. if(strcmp(f, ".") != 0 && strcmp(f, "..") != 0)
  2058. {
  2059. dc.insert(f);
  2060. }
  2061. }
  2062. }
  2063. dc.LoadedFromDisk = true;
  2064. }
  2065. return dc;
  2066. }
  2067. //----------------------------------------------------------------------------
  2068. void
  2069. cmGlobalGenerator::AddRuleHash(const std::vector<std::string>& outputs,
  2070. std::string const& content)
  2071. {
  2072. #if defined(CMAKE_BUILD_WITH_CMAKE)
  2073. // Ignore if there are no outputs.
  2074. if(outputs.empty())
  2075. {
  2076. return;
  2077. }
  2078. // Compute a hash of the rule.
  2079. RuleHash hash;
  2080. {
  2081. unsigned char const* data =
  2082. reinterpret_cast<unsigned char const*>(content.c_str());
  2083. int length = static_cast<int>(content.length());
  2084. cmsysMD5* sum = cmsysMD5_New();
  2085. cmsysMD5_Initialize(sum);
  2086. cmsysMD5_Append(sum, data, length);
  2087. cmsysMD5_FinalizeHex(sum, hash.Data);
  2088. cmsysMD5_Delete(sum);
  2089. }
  2090. // Shorten the output name (in expected use case).
  2091. cmLocalGenerator* lg = this->GetLocalGenerators()[0];
  2092. std::string fname = lg->Convert(outputs[0].c_str(),
  2093. cmLocalGenerator::HOME_OUTPUT);
  2094. // Associate the hash with this output.
  2095. this->RuleHashes[fname] = hash;
  2096. #else
  2097. (void)outputs;
  2098. (void)content;
  2099. #endif
  2100. }
  2101. //----------------------------------------------------------------------------
  2102. void cmGlobalGenerator::CheckRuleHashes()
  2103. {
  2104. #if defined(CMAKE_BUILD_WITH_CMAKE)
  2105. std::string home = this->GetCMakeInstance()->GetHomeOutputDirectory();
  2106. std::string pfile = home;
  2107. pfile += this->GetCMakeInstance()->GetCMakeFilesDirectory();
  2108. pfile += "/CMakeRuleHashes.txt";
  2109. this->CheckRuleHashes(pfile, home);
  2110. this->WriteRuleHashes(pfile);
  2111. #endif
  2112. }
  2113. //----------------------------------------------------------------------------
  2114. void cmGlobalGenerator::CheckRuleHashes(std::string const& pfile,
  2115. std::string const& home)
  2116. {
  2117. #if defined(_WIN32) || defined(__CYGWIN__)
  2118. std::ifstream fin(pfile.c_str(), std::ios::in | std::ios::binary);
  2119. #else
  2120. std::ifstream fin(pfile.c_str(), std::ios::in);
  2121. #endif
  2122. if(!fin)
  2123. {
  2124. return;
  2125. }
  2126. std::string line;
  2127. std::string fname;
  2128. while(cmSystemTools::GetLineFromStream(fin, line))
  2129. {
  2130. // Line format is a 32-byte hex string followed by a space
  2131. // followed by a file name (with no escaping).
  2132. // Skip blank and comment lines.
  2133. if(line.size() < 34 || line[0] == '#')
  2134. {
  2135. continue;
  2136. }
  2137. // Get the filename.
  2138. fname = line.substr(33, line.npos);
  2139. // Look for a hash for this file's rule.
  2140. std::map<cmStdString, RuleHash>::const_iterator rhi =
  2141. this->RuleHashes.find(fname);
  2142. if(rhi != this->RuleHashes.end())
  2143. {
  2144. // Compare the rule hash in the file to that we were given.
  2145. if(strncmp(line.c_str(), rhi->second.Data, 32) != 0)
  2146. {
  2147. // The rule has changed. Delete the output so it will be
  2148. // built again.
  2149. fname = cmSystemTools::CollapseFullPath(fname.c_str(), home.c_str());
  2150. cmSystemTools::RemoveFile(fname.c_str());
  2151. }
  2152. }
  2153. else
  2154. {
  2155. // We have no hash for a rule previously listed. This may be a
  2156. // case where a user has turned off a build option and might
  2157. // want to turn it back on later, so do not delete the file.
  2158. // Instead, we keep the rule hash as long as the file exists so
  2159. // that if the feature is turned back on and the rule has
  2160. // changed the file is still rebuilt.
  2161. std::string fpath =
  2162. cmSystemTools::CollapseFullPath(fname.c_str(), home.c_str());
  2163. if(cmSystemTools::FileExists(fpath.c_str()))
  2164. {
  2165. RuleHash hash;
  2166. strncpy(hash.Data, line.c_str(), 32);
  2167. this->RuleHashes[fname] = hash;
  2168. }
  2169. }
  2170. }
  2171. }
  2172. //----------------------------------------------------------------------------
  2173. void cmGlobalGenerator::WriteRuleHashes(std::string const& pfile)
  2174. {
  2175. // Now generate a new persistence file with the current hashes.
  2176. if(this->RuleHashes.empty())
  2177. {
  2178. cmSystemTools::RemoveFile(pfile.c_str());
  2179. }
  2180. else
  2181. {
  2182. cmGeneratedFileStream fout(pfile.c_str());
  2183. fout << "# Hashes of file build rules.\n";
  2184. for(std::map<cmStdString, RuleHash>::const_iterator
  2185. rhi = this->RuleHashes.begin(); rhi != this->RuleHashes.end(); ++rhi)
  2186. {
  2187. fout.write(rhi->second.Data, 32);
  2188. fout << " " << rhi->first << "\n";
  2189. }
  2190. }
  2191. }
  2192. //----------------------------------------------------------------------------
  2193. void cmGlobalGenerator::WriteSummary()
  2194. {
  2195. cmMakefile* mf = this->LocalGenerators[0]->GetMakefile();
  2196. // Record all target directories in a central location.
  2197. std::string fname = mf->GetHomeOutputDirectory();
  2198. fname += cmake::GetCMakeFilesDirectory();
  2199. fname += "/TargetDirectories.txt";
  2200. cmGeneratedFileStream fout(fname.c_str());
  2201. // Generate summary information files for each target.
  2202. std::string dir;
  2203. for(std::map<cmStdString,cmTarget *>::const_iterator ti =
  2204. this->TotalTargets.begin(); ti != this->TotalTargets.end(); ++ti)
  2205. {
  2206. this->WriteSummary(ti->second);
  2207. fout << ti->second->GetSupportDirectory() << "\n";
  2208. }
  2209. }
  2210. //----------------------------------------------------------------------------
  2211. void cmGlobalGenerator::WriteSummary(cmTarget* target)
  2212. {
  2213. // Place the labels file in a per-target support directory.
  2214. std::string dir = target->GetSupportDirectory();
  2215. std::string file = dir;
  2216. file += "/Labels.txt";
  2217. // Check whether labels are enabled for this target.
  2218. if(const char* value = target->GetProperty("LABELS"))
  2219. {
  2220. cmSystemTools::MakeDirectory(dir.c_str());
  2221. cmGeneratedFileStream fout(file.c_str());
  2222. // List the target-wide labels. All sources in the target get
  2223. // these labels.
  2224. std::vector<std::string> labels;
  2225. cmSystemTools::ExpandListArgument(value, labels);
  2226. if(!labels.empty())
  2227. {
  2228. fout << "# Target labels\n";
  2229. for(std::vector<std::string>::const_iterator li = labels.begin();
  2230. li != labels.end(); ++li)
  2231. {
  2232. fout << " " << *li << "\n";
  2233. }
  2234. }
  2235. // List the source files with any per-source labels.
  2236. fout << "# Source files and their labels\n";
  2237. std::vector<cmSourceFile*> const& sources = target->GetSourceFiles();
  2238. for(std::vector<cmSourceFile*>::const_iterator si = sources.begin();
  2239. si != sources.end(); ++si)
  2240. {
  2241. cmSourceFile* sf = *si;
  2242. fout << sf->GetFullPath() << "\n";
  2243. if(const char* svalue = sf->GetProperty("LABELS"))
  2244. {
  2245. labels.clear();
  2246. cmSystemTools::ExpandListArgument(svalue, labels);
  2247. for(std::vector<std::string>::const_iterator li = labels.begin();
  2248. li != labels.end(); ++li)
  2249. {
  2250. fout << " " << *li << "\n";
  2251. }
  2252. }
  2253. }
  2254. }
  2255. else
  2256. {
  2257. cmSystemTools::RemoveFile(file.c_str());
  2258. }
  2259. }