cmGlobalGenerator.cxx 97 KB

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