cmGlobalGenerator.cxx 109 KB

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