cmVisualStudio10TargetGenerator.cxx 166 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738
  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 "cmVisualStudio10TargetGenerator.h"
  4. #include "cmAlgorithms.h"
  5. #include "cmComputeLinkInformation.h"
  6. #include "cmCustomCommand.h"
  7. #include "cmCustomCommandGenerator.h"
  8. #include "cmGeneratedFileStream.h"
  9. #include "cmGeneratorExpression.h"
  10. #include "cmGeneratorTarget.h"
  11. #include "cmGlobalVisualStudio10Generator.h"
  12. #include "cmLinkLineDeviceComputer.h"
  13. #include "cmLocalVisualStudio10Generator.h"
  14. #include "cmMakefile.h"
  15. #include "cmSourceFile.h"
  16. #include "cmSystemTools.h"
  17. #include "cmVisualStudioGeneratorOptions.h"
  18. #include "windows.h"
  19. #include <iterator>
  20. #include <memory> // IWYU pragma: keep
  21. #include <set>
  22. static void ConvertToWindowsSlash(std::string& s);
  23. static std::string cmVS10EscapeXML(std::string arg)
  24. {
  25. cmSystemTools::ReplaceString(arg, "&", "&amp;");
  26. cmSystemTools::ReplaceString(arg, "<", "&lt;");
  27. cmSystemTools::ReplaceString(arg, ">", "&gt;");
  28. return arg;
  29. }
  30. static std::string cmVS10EscapeAttr(std::string arg)
  31. {
  32. cmSystemTools::ReplaceString(arg, "&", "&amp;");
  33. cmSystemTools::ReplaceString(arg, "<", "&lt;");
  34. cmSystemTools::ReplaceString(arg, ">", "&gt;");
  35. cmSystemTools::ReplaceString(arg, "\"", "&quot;");
  36. cmSystemTools::ReplaceString(arg, "\n", "&#10;");
  37. return arg;
  38. }
  39. struct cmVisualStudio10TargetGenerator::Elem
  40. {
  41. std::ostream& S;
  42. const int Indent;
  43. bool HasElements = false;
  44. bool HasContent = false;
  45. std::string Tag;
  46. Elem(std::ostream& s, const char* tag)
  47. : S(s)
  48. , Indent(0)
  49. , Tag(tag)
  50. {
  51. this->StartElement();
  52. }
  53. Elem(const Elem&) = delete;
  54. Elem(Elem& par, const char* tag)
  55. : S(par.S)
  56. , Indent(par.Indent + 1)
  57. , Tag(tag)
  58. {
  59. par.SetHasElements();
  60. this->StartElement();
  61. }
  62. void SetHasElements()
  63. {
  64. if (!HasElements) {
  65. this->S << ">\n";
  66. HasElements = true;
  67. }
  68. }
  69. std::ostream& WriteString(const char* line);
  70. void StartElement() { this->WriteString("<") << this->Tag; }
  71. void Element(const char* tag, const std::string& val)
  72. {
  73. Elem(*this, tag).Content(val);
  74. }
  75. Elem& Attribute(const char* an, const std::string& av)
  76. {
  77. this->S << " " << an << "=\"" << cmVS10EscapeAttr(av) << "\"";
  78. return *this;
  79. }
  80. void Content(const std::string& val)
  81. {
  82. if (!this->HasContent) {
  83. this->S << ">";
  84. this->HasContent = true;
  85. }
  86. this->S << cmVS10EscapeXML(val);
  87. }
  88. ~Elem()
  89. {
  90. // Do not emit element which has not been started
  91. if (Tag.empty()) {
  92. return;
  93. }
  94. if (HasElements) {
  95. this->WriteString("</") << this->Tag << ">";
  96. if (this->Indent > 0) {
  97. this->S << '\n';
  98. } else {
  99. // special case: don't print EOL at EOF
  100. }
  101. } else if (HasContent) {
  102. this->S << "</" << this->Tag << ">\n";
  103. } else {
  104. this->S << " />\n";
  105. }
  106. }
  107. void WritePlatformConfigTag(const char* tag, const std::string& cond,
  108. const std::string& content);
  109. };
  110. class cmVS10GeneratorOptions : public cmVisualStudioGeneratorOptions
  111. {
  112. public:
  113. typedef cmVisualStudio10TargetGenerator::Elem Elem;
  114. cmVS10GeneratorOptions(cmLocalVisualStudioGenerator* lg, Tool tool,
  115. cmVS7FlagTable const* table,
  116. cmVisualStudio10TargetGenerator* g = nullptr)
  117. : cmVisualStudioGeneratorOptions(lg, tool, table)
  118. , TargetGenerator(g)
  119. {
  120. }
  121. void OutputFlag(std::ostream& /*fout*/, int /*indent*/, const char* tag,
  122. const std::string& content) override
  123. {
  124. if (!this->GetConfiguration().empty()) {
  125. // if there are configuration specific flags, then
  126. // use the configuration specific tag for PreprocessorDefinitions
  127. const std::string cond =
  128. this->TargetGenerator->CalcCondition(this->GetConfiguration());
  129. this->Parent->WritePlatformConfigTag(tag, cond, content);
  130. } else {
  131. this->Parent->Element(tag, content);
  132. }
  133. }
  134. private:
  135. cmVisualStudio10TargetGenerator* const TargetGenerator;
  136. Elem* Parent = nullptr;
  137. friend cmVisualStudio10TargetGenerator::OptionsHelper;
  138. };
  139. struct cmVisualStudio10TargetGenerator::OptionsHelper
  140. {
  141. cmVS10GeneratorOptions& O;
  142. OptionsHelper(cmVS10GeneratorOptions& o, Elem& e)
  143. : O(o)
  144. {
  145. O.Parent = &e;
  146. }
  147. ~OptionsHelper() { O.Parent = nullptr; }
  148. void OutputPreprocessorDefinitions(const std::string& lang)
  149. {
  150. O.OutputPreprocessorDefinitions(O.Parent->S, O.Parent->Indent + 1, lang);
  151. }
  152. void OutputAdditionalIncludeDirectories(const std::string& lang)
  153. {
  154. O.OutputAdditionalIncludeDirectories(O.Parent->S, O.Parent->Indent + 1,
  155. lang);
  156. }
  157. void OutputFlagMap() { O.OutputFlagMap(O.Parent->S, O.Parent->Indent + 1); }
  158. void PrependInheritedString(std::string const& key)
  159. {
  160. O.PrependInheritedString(key);
  161. }
  162. };
  163. static std::string cmVS10EscapeComment(std::string comment)
  164. {
  165. // MSBuild takes the CDATA of a <Message></Message> element and just
  166. // does "echo $CDATA" with no escapes. We must encode the string.
  167. // http://technet.microsoft.com/en-us/library/cc772462%28WS.10%29.aspx
  168. std::string echoable;
  169. for (char c : comment) {
  170. switch (c) {
  171. case '\r':
  172. break;
  173. case '\n':
  174. echoable += '\t';
  175. break;
  176. case '"': /* no break */
  177. case '|': /* no break */
  178. case '&': /* no break */
  179. case '<': /* no break */
  180. case '>': /* no break */
  181. case '^':
  182. echoable += '^'; /* no break */
  183. CM_FALLTHROUGH;
  184. default:
  185. echoable += c;
  186. break;
  187. }
  188. }
  189. return echoable;
  190. }
  191. static bool cmVS10IsTargetsFile(std::string const& path)
  192. {
  193. std::string const ext = cmSystemTools::GetFilenameLastExtension(path);
  194. return cmSystemTools::Strucmp(ext.c_str(), ".targets") == 0;
  195. }
  196. static std::string computeProjectFileExtension(cmGeneratorTarget const* t)
  197. {
  198. std::string res;
  199. res = ".vcxproj";
  200. if (t->IsCSharpOnly()) {
  201. res = ".csproj";
  202. }
  203. return res;
  204. }
  205. cmVisualStudio10TargetGenerator::cmVisualStudio10TargetGenerator(
  206. cmGeneratorTarget* target, cmGlobalVisualStudio10Generator* gg)
  207. : GeneratorTarget(target)
  208. , Makefile(target->Target->GetMakefile())
  209. , Platform(gg->GetPlatformName())
  210. , Name(target->GetName())
  211. , GUID(gg->GetGUID(this->Name))
  212. , GlobalGenerator(gg)
  213. , LocalGenerator(
  214. (cmLocalVisualStudio10Generator*)target->GetLocalGenerator())
  215. {
  216. this->Makefile->GetConfigurations(this->Configurations);
  217. this->NsightTegra = gg->IsNsightTegra();
  218. for (int i = 0; i < 4; ++i) {
  219. this->NsightTegraVersion[i] = 0;
  220. }
  221. sscanf(gg->GetNsightTegraVersion().c_str(), "%u.%u.%u.%u",
  222. &this->NsightTegraVersion[0], &this->NsightTegraVersion[1],
  223. &this->NsightTegraVersion[2], &this->NsightTegraVersion[3]);
  224. this->MSTools = !this->NsightTegra;
  225. this->Managed = false;
  226. this->TargetCompileAsWinRT = false;
  227. this->IsMissingFiles = false;
  228. this->DefaultArtifactDir =
  229. this->LocalGenerator->GetCurrentBinaryDirectory() + "/" +
  230. this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
  231. this->InSourceBuild = (this->Makefile->GetCurrentSourceDirectory() ==
  232. this->Makefile->GetCurrentBinaryDirectory());
  233. }
  234. cmVisualStudio10TargetGenerator::~cmVisualStudio10TargetGenerator()
  235. {
  236. }
  237. std::string cmVisualStudio10TargetGenerator::CalcCondition(
  238. const std::string& config) const
  239. {
  240. std::ostringstream oss;
  241. oss << "'$(Configuration)|$(Platform)'=='";
  242. oss << config << "|" << this->Platform;
  243. oss << "'";
  244. // handle special case for 32 bit C# targets
  245. if (this->ProjectType == csproj && this->Platform == "Win32") {
  246. oss << " Or ";
  247. oss << "'$(Configuration)|$(Platform)'=='";
  248. oss << config << "|x86";
  249. oss << "'";
  250. }
  251. return oss.str();
  252. }
  253. void cmVisualStudio10TargetGenerator::Elem::WritePlatformConfigTag(
  254. const char* tag, const std::string& cond, const std::string& content)
  255. {
  256. Elem(*this, tag).Attribute("Condition", cond).Content(content);
  257. }
  258. std::ostream& cmVisualStudio10TargetGenerator::Elem::WriteString(
  259. const char* line)
  260. {
  261. this->S.fill(' ');
  262. this->S.width(this->Indent * 2);
  263. // write an empty string to get the fill level indent to print
  264. this->S << "";
  265. this->S << line;
  266. return this->S;
  267. }
  268. #define VS10_CXX_DEFAULT_PROPS "$(VCTargetsPath)\\Microsoft.Cpp.Default.props"
  269. #define VS10_CXX_PROPS "$(VCTargetsPath)\\Microsoft.Cpp.props"
  270. #define VS10_CXX_USER_PROPS \
  271. "$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props"
  272. #define VS10_CXX_TARGETS "$(VCTargetsPath)\\Microsoft.Cpp.targets"
  273. #define VS10_CSharp_DEFAULT_PROPS \
  274. "$(MSBuildExtensionsPath)\\$(MSBuildToolsVersion)\\Microsoft.Common.props"
  275. // This does not seem to exist by default, it's just provided for consistency
  276. // in case users want to have default custom props for C# targets
  277. #define VS10_CSharp_USER_PROPS \
  278. "$(UserRootDir)\\Microsoft.CSharp.$(Platform).user.props"
  279. #define VS10_CSharp_TARGETS "$(MSBuildToolsPath)\\Microsoft.CSharp.targets"
  280. #define VS10_CSharp_NETCF_TARGETS \
  281. "$(MSBuildExtensionsPath)\\Microsoft\\$(TargetFrameworkIdentifier)\\" \
  282. "$(TargetFrameworkTargetsVersion)\\Microsoft.$(TargetFrameworkIdentifier)" \
  283. ".CSharp.targets"
  284. void cmVisualStudio10TargetGenerator::Generate()
  285. {
  286. // do not generate external ms projects
  287. if (this->GeneratorTarget->GetType() == cmStateEnums::INTERFACE_LIBRARY ||
  288. this->GeneratorTarget->GetProperty("EXTERNAL_MSPROJECT")) {
  289. return;
  290. }
  291. const std::string ProjectFileExtension =
  292. computeProjectFileExtension(this->GeneratorTarget);
  293. if (ProjectFileExtension == ".vcxproj") {
  294. this->ProjectType = vcxproj;
  295. this->Managed = false;
  296. } else if (ProjectFileExtension == ".csproj") {
  297. if (this->GeneratorTarget->GetType() == cmStateEnums::STATIC_LIBRARY) {
  298. std::string message = "The C# target \"" +
  299. this->GeneratorTarget->GetName() +
  300. "\" is of type STATIC_LIBRARY. This is discouraged (and may be "
  301. "disabled in future). Make it a SHARED library instead.";
  302. this->Makefile->IssueMessage(MessageType::DEPRECATION_WARNING, message);
  303. }
  304. this->ProjectType = csproj;
  305. this->Managed = true;
  306. }
  307. // Tell the global generator the name of the project file
  308. this->GeneratorTarget->Target->SetProperty("GENERATOR_FILE_NAME",
  309. this->Name.c_str());
  310. this->GeneratorTarget->Target->SetProperty("GENERATOR_FILE_NAME_EXT",
  311. ProjectFileExtension.c_str());
  312. this->DotNetHintReferences.clear();
  313. this->AdditionalUsingDirectories.clear();
  314. if (this->GeneratorTarget->GetType() <= cmStateEnums::OBJECT_LIBRARY) {
  315. if (!this->ComputeClOptions()) {
  316. return;
  317. }
  318. if (!this->ComputeRcOptions()) {
  319. return;
  320. }
  321. if (!this->ComputeCudaOptions()) {
  322. return;
  323. }
  324. if (!this->ComputeCudaLinkOptions()) {
  325. return;
  326. }
  327. if (!this->ComputeMasmOptions()) {
  328. return;
  329. }
  330. if (!this->ComputeNasmOptions()) {
  331. return;
  332. }
  333. if (!this->ComputeLinkOptions()) {
  334. return;
  335. }
  336. if (!this->ComputeLibOptions()) {
  337. return;
  338. }
  339. }
  340. std::string path = this->LocalGenerator->GetCurrentBinaryDirectory();
  341. path += "/";
  342. path += this->Name;
  343. path += ProjectFileExtension;
  344. cmGeneratedFileStream BuildFileStream(path);
  345. const std::string PathToProjectFile = path;
  346. BuildFileStream.SetCopyIfDifferent(true);
  347. // Write the encoding header into the file
  348. char magic[] = { char(0xEF), char(0xBB), char(0xBF) };
  349. BuildFileStream.write(magic, 3);
  350. BuildFileStream << "<?xml version=\"1.0\" encoding=\""
  351. << this->GlobalGenerator->Encoding() << "\"?>"
  352. << "\n";
  353. {
  354. Elem e0(BuildFileStream, "Project");
  355. e0.Attribute("DefaultTargets", "Build");
  356. const char* toolsVersion = this->GlobalGenerator->GetToolsVersion();
  357. if (this->GlobalGenerator->GetVersion() ==
  358. cmGlobalVisualStudioGenerator::VS12 &&
  359. this->GlobalGenerator->TargetsWindowsCE()) {
  360. toolsVersion = "4.0";
  361. }
  362. e0.Attribute("ToolsVersion", toolsVersion);
  363. e0.Attribute("xmlns",
  364. "http://schemas.microsoft.com/developer/msbuild/2003");
  365. if (this->NsightTegra) {
  366. Elem e1(e0, "PropertyGroup");
  367. e1.Attribute("Label", "NsightTegraProject");
  368. const unsigned int nsightTegraMajorVersion = this->NsightTegraVersion[0];
  369. const unsigned int nsightTegraMinorVersion = this->NsightTegraVersion[1];
  370. if (nsightTegraMajorVersion >= 2) {
  371. if (nsightTegraMajorVersion > 3 ||
  372. (nsightTegraMajorVersion == 3 && nsightTegraMinorVersion >= 1)) {
  373. e1.Element("NsightTegraProjectRevisionNumber", "11");
  374. } else {
  375. // Nsight Tegra 2.0 uses project revision 9.
  376. e1.Element("NsightTegraProjectRevisionNumber", "9");
  377. }
  378. // Tell newer versions to upgrade silently when loading.
  379. e1.Element("NsightTegraUpgradeOnceWithoutPrompt", "true");
  380. } else {
  381. // Require Nsight Tegra 1.6 for JCompile support.
  382. e1.Element("NsightTegraProjectRevisionNumber", "7");
  383. }
  384. }
  385. if (const char* hostArch =
  386. this->GlobalGenerator->GetPlatformToolsetHostArchitecture()) {
  387. Elem e1(e0, "PropertyGroup");
  388. e1.Element("PreferredToolArchitecture", hostArch);
  389. }
  390. if (this->ProjectType != csproj) {
  391. this->WriteProjectConfigurations(e0);
  392. }
  393. {
  394. Elem e1(e0, "PropertyGroup");
  395. e1.Attribute("Label", "Globals");
  396. e1.Element("ProjectGuid", "{" + this->GUID + "}");
  397. if (this->MSTools &&
  398. this->GeneratorTarget->GetType() <= cmStateEnums::GLOBAL_TARGET) {
  399. this->WriteApplicationTypeSettings(e1);
  400. this->VerifyNecessaryFiles();
  401. }
  402. const char* vsProjectTypes =
  403. this->GeneratorTarget->GetProperty("VS_GLOBAL_PROJECT_TYPES");
  404. if (vsProjectTypes) {
  405. const char* tagName = "ProjectTypes";
  406. if (this->ProjectType == csproj) {
  407. tagName = "ProjectTypeGuids";
  408. }
  409. e1.Element(tagName, vsProjectTypes);
  410. }
  411. const char* vsProjectName =
  412. this->GeneratorTarget->GetProperty("VS_SCC_PROJECTNAME");
  413. const char* vsLocalPath =
  414. this->GeneratorTarget->GetProperty("VS_SCC_LOCALPATH");
  415. const char* vsProvider =
  416. this->GeneratorTarget->GetProperty("VS_SCC_PROVIDER");
  417. if (vsProjectName && vsLocalPath && vsProvider) {
  418. e1.Element("SccProjectName", vsProjectName);
  419. e1.Element("SccLocalPath", vsLocalPath);
  420. e1.Element("SccProvider", vsProvider);
  421. const char* vsAuxPath =
  422. this->GeneratorTarget->GetProperty("VS_SCC_AUXPATH");
  423. if (vsAuxPath) {
  424. e1.Element("SccAuxPath", vsAuxPath);
  425. }
  426. }
  427. if (this->GeneratorTarget->GetPropertyAsBool("VS_WINRT_COMPONENT")) {
  428. e1.Element("WinMDAssembly", "true");
  429. }
  430. const char* vsGlobalKeyword =
  431. this->GeneratorTarget->GetProperty("VS_GLOBAL_KEYWORD");
  432. if (!vsGlobalKeyword) {
  433. e1.Element("Keyword", "Win32Proj");
  434. } else {
  435. e1.Element("Keyword", vsGlobalKeyword);
  436. }
  437. const char* vsGlobalRootNamespace =
  438. this->GeneratorTarget->GetProperty("VS_GLOBAL_ROOTNAMESPACE");
  439. if (vsGlobalRootNamespace) {
  440. e1.Element("RootNamespace", vsGlobalRootNamespace);
  441. }
  442. e1.Element("Platform", this->Platform);
  443. const char* projLabel =
  444. this->GeneratorTarget->GetProperty("PROJECT_LABEL");
  445. if (!projLabel) {
  446. projLabel = this->Name.c_str();
  447. }
  448. e1.Element("ProjectName", projLabel);
  449. {
  450. // TODO: add deprecation warning for VS_* property?
  451. const char* targetFrameworkVersion =
  452. this->GeneratorTarget->GetProperty(
  453. "VS_DOTNET_TARGET_FRAMEWORK_VERSION");
  454. if (!targetFrameworkVersion) {
  455. targetFrameworkVersion = this->GeneratorTarget->GetProperty(
  456. "DOTNET_TARGET_FRAMEWORK_VERSION");
  457. }
  458. if (!targetFrameworkVersion && this->ProjectType == csproj &&
  459. this->GlobalGenerator->TargetsWindowsCE() &&
  460. this->GlobalGenerator->GetVersion() ==
  461. cmGlobalVisualStudioGenerator::VS12) {
  462. // VS12 .NETCF default to .NET framework 3.9
  463. targetFrameworkVersion = "v3.9";
  464. }
  465. if (targetFrameworkVersion) {
  466. e1.Element("TargetFrameworkVersion", targetFrameworkVersion);
  467. }
  468. if (this->ProjectType == csproj &&
  469. this->GlobalGenerator->TargetsWindowsCE()) {
  470. const char* targetFrameworkId = this->GeneratorTarget->GetProperty(
  471. "VS_TARGET_FRAMEWORK_IDENTIFIER");
  472. if (!targetFrameworkId) {
  473. targetFrameworkId = "WindowsEmbeddedCompact";
  474. }
  475. e1.Element("TargetFrameworkIdentifier", targetFrameworkId);
  476. const char* targetFrameworkVer = this->GeneratorTarget->GetProperty(
  477. "VS_TARGET_FRAMEWORKS_TARGET_VERSION");
  478. if (!targetFrameworkVer) {
  479. targetFrameworkVer = "v8.0";
  480. }
  481. e1.Element("TargetFrameworkTargetsVersion", targetFrameworkVer);
  482. }
  483. }
  484. // Disable the project upgrade prompt that is displayed the first time a
  485. // project using an older toolset version is opened in a newer version of
  486. // the IDE (respected by VS 2013 and above).
  487. if (this->GlobalGenerator->GetVersion() >=
  488. cmGlobalVisualStudioGenerator::VS12) {
  489. e1.Element("VCProjectUpgraderObjectName", "NoUpgrade");
  490. }
  491. std::vector<std::string> keys = this->GeneratorTarget->GetPropertyKeys();
  492. for (std::string const& keyIt : keys) {
  493. static const char* prefix = "VS_GLOBAL_";
  494. if (keyIt.find(prefix) != 0)
  495. continue;
  496. std::string globalKey = keyIt.substr(strlen(prefix));
  497. // Skip invalid or separately-handled properties.
  498. if (globalKey.empty() || globalKey == "PROJECT_TYPES" ||
  499. globalKey == "ROOTNAMESPACE" || globalKey == "KEYWORD") {
  500. continue;
  501. }
  502. const char* value = this->GeneratorTarget->GetProperty(keyIt);
  503. if (!value)
  504. continue;
  505. e1.Element(globalKey.c_str(), value);
  506. }
  507. if (this->Managed) {
  508. std::string outputType;
  509. switch (this->GeneratorTarget->GetType()) {
  510. case cmStateEnums::OBJECT_LIBRARY:
  511. case cmStateEnums::STATIC_LIBRARY:
  512. case cmStateEnums::SHARED_LIBRARY:
  513. outputType = "Library";
  514. break;
  515. case cmStateEnums::MODULE_LIBRARY:
  516. outputType = "Module";
  517. break;
  518. case cmStateEnums::EXECUTABLE:
  519. if (this->GeneratorTarget->Target->GetPropertyAsBool(
  520. "WIN32_EXECUTABLE")) {
  521. outputType = "WinExe";
  522. } else {
  523. outputType = "Exe";
  524. }
  525. break;
  526. case cmStateEnums::UTILITY:
  527. case cmStateEnums::GLOBAL_TARGET:
  528. outputType = "Utility";
  529. break;
  530. case cmStateEnums::UNKNOWN_LIBRARY:
  531. case cmStateEnums::INTERFACE_LIBRARY:
  532. break;
  533. }
  534. e1.Element("OutputType", outputType);
  535. e1.Element("AppDesignerFolder", "Properties");
  536. }
  537. }
  538. switch (this->ProjectType) {
  539. case vcxproj:
  540. if (this->GlobalGenerator->GetPlatformToolsetVersion()) {
  541. Elem(e0, "Import")
  542. .Attribute("Project",
  543. this->GlobalGenerator->GetAuxiliaryToolset());
  544. }
  545. Elem(e0, "Import").Attribute("Project", VS10_CXX_DEFAULT_PROPS);
  546. break;
  547. case csproj:
  548. Elem(e0, "Import")
  549. .Attribute("Project", VS10_CSharp_DEFAULT_PROPS)
  550. .Attribute("Condition", "Exists('" VS10_CSharp_DEFAULT_PROPS "')");
  551. break;
  552. }
  553. this->WriteProjectConfigurationValues(e0);
  554. if (this->ProjectType == vcxproj) {
  555. Elem(e0, "Import").Attribute("Project", VS10_CXX_PROPS);
  556. }
  557. {
  558. Elem e1(e0, "ImportGroup");
  559. e1.Attribute("Label", "ExtensionSettings");
  560. e1.SetHasElements();
  561. if (this->GlobalGenerator->IsCudaEnabled()) {
  562. Elem(e1, "Import")
  563. .Attribute("Project",
  564. "$(VCTargetsPath)\\BuildCustomizations\\CUDA " +
  565. this->GlobalGenerator->GetPlatformToolsetCudaString() +
  566. ".props");
  567. }
  568. if (this->GlobalGenerator->IsMasmEnabled()) {
  569. Elem(e1, "Import")
  570. .Attribute("Project",
  571. "$(VCTargetsPath)\\BuildCustomizations\\masm.props");
  572. }
  573. if (this->GlobalGenerator->IsNasmEnabled()) {
  574. // Always search in the standard modules location.
  575. std::string propsTemplate =
  576. GetCMakeFilePath("Templates/MSBuild/nasm.props.in");
  577. std::string propsLocal;
  578. propsLocal += this->DefaultArtifactDir;
  579. propsLocal += "\\nasm.props";
  580. ConvertToWindowsSlash(propsLocal);
  581. this->Makefile->ConfigureFile(propsTemplate, propsLocal, false, true,
  582. true);
  583. Elem(e1, "Import").Attribute("Project", propsLocal);
  584. }
  585. }
  586. {
  587. Elem e1(e0, "ImportGroup");
  588. e1.Attribute("Label", "PropertySheets");
  589. std::string props;
  590. switch (this->ProjectType) {
  591. case vcxproj:
  592. props = VS10_CXX_USER_PROPS;
  593. break;
  594. case csproj:
  595. props = VS10_CSharp_USER_PROPS;
  596. break;
  597. }
  598. if (const char* p =
  599. this->GeneratorTarget->GetProperty("VS_USER_PROPS")) {
  600. props = p;
  601. }
  602. if (!props.empty()) {
  603. ConvertToWindowsSlash(props);
  604. Elem(e1, "Import")
  605. .Attribute("Project", props)
  606. .Attribute("Condition", "exists('" + props + "')")
  607. .Attribute("Label", "LocalAppDataPlatform");
  608. }
  609. this->WritePlatformExtensions(e1);
  610. }
  611. Elem(e0, "PropertyGroup").Attribute("Label", "UserMacros");
  612. this->WriteWinRTPackageCertificateKeyFile(e0);
  613. this->WritePathAndIncrementalLinkOptions(e0);
  614. this->WriteCEDebugProjectConfigurationValues(e0);
  615. this->WriteItemDefinitionGroups(e0);
  616. this->WriteCustomCommands(e0);
  617. this->WriteAllSources(e0);
  618. this->WriteDotNetReferences(e0);
  619. this->WritePackageReferences(e0);
  620. this->WriteImports(e0);
  621. this->WriteEmbeddedResourceGroup(e0);
  622. this->WriteXamlFilesGroup(e0);
  623. this->WriteWinRTReferences(e0);
  624. this->WriteProjectReferences(e0);
  625. this->WriteSDKReferences(e0);
  626. switch (this->ProjectType) {
  627. case vcxproj:
  628. Elem(e0, "Import").Attribute("Project", VS10_CXX_TARGETS);
  629. break;
  630. case csproj:
  631. if (this->GlobalGenerator->TargetsWindowsCE()) {
  632. Elem(e0, "Import").Attribute("Project", VS10_CSharp_NETCF_TARGETS);
  633. } else {
  634. Elem(e0, "Import").Attribute("Project", VS10_CSharp_TARGETS);
  635. }
  636. break;
  637. }
  638. this->WriteTargetSpecificReferences(e0);
  639. {
  640. Elem e1(e0, "ImportGroup");
  641. e1.Attribute("Label", "ExtensionTargets");
  642. e1.SetHasElements();
  643. this->WriteTargetsFileReferences(e1);
  644. if (this->GlobalGenerator->IsCudaEnabled()) {
  645. Elem(e1, "Import")
  646. .Attribute("Project",
  647. "$(VCTargetsPath)\\BuildCustomizations\\CUDA " +
  648. this->GlobalGenerator->GetPlatformToolsetCudaString() +
  649. ".targets");
  650. }
  651. if (this->GlobalGenerator->IsMasmEnabled()) {
  652. Elem(e1, "Import")
  653. .Attribute("Project",
  654. "$(VCTargetsPath)\\BuildCustomizations\\masm.targets");
  655. }
  656. if (this->GlobalGenerator->IsNasmEnabled()) {
  657. std::string nasmTargets =
  658. GetCMakeFilePath("Templates/MSBuild/nasm.targets");
  659. Elem(e1, "Import").Attribute("Project", nasmTargets);
  660. }
  661. }
  662. if (this->ProjectType == csproj) {
  663. for (std::string const& c : this->Configurations) {
  664. Elem e1(e0, "PropertyGroup");
  665. e1.Attribute("Condition", "'$(Configuration)' == '" + c + "'");
  666. e1.SetHasElements();
  667. this->WriteEvents(e1, c);
  668. }
  669. // make sure custom commands are executed before build (if necessary)
  670. {
  671. Elem e1(e0, "PropertyGroup");
  672. std::ostringstream oss;
  673. oss << "\n";
  674. for (std::string const& i : this->CSharpCustomCommandNames) {
  675. oss << " " << i << ";\n";
  676. }
  677. oss << " "
  678. << "$(BuildDependsOn)\n";
  679. e1.Element("BuildDependsOn", oss.str());
  680. }
  681. }
  682. }
  683. if (BuildFileStream.Close()) {
  684. this->GlobalGenerator->FileReplacedDuringGenerate(PathToProjectFile);
  685. }
  686. // The groups are stored in a separate file for VS 10
  687. this->WriteGroups();
  688. }
  689. void cmVisualStudio10TargetGenerator::WritePackageReferences(Elem& e0)
  690. {
  691. std::vector<std::string> packageReferences;
  692. if (const char* vsPackageReferences =
  693. this->GeneratorTarget->GetProperty("VS_PACKAGE_REFERENCES")) {
  694. cmSystemTools::ExpandListArgument(vsPackageReferences, packageReferences);
  695. }
  696. if (!packageReferences.empty()) {
  697. Elem e1(e0, "ItemGroup");
  698. for (std::string const& ri : packageReferences) {
  699. size_t versionIndex = ri.find_last_of('_');
  700. if (versionIndex != std::string::npos) {
  701. WritePackageReference(e1, ri.substr(0, versionIndex),
  702. ri.substr(versionIndex + 1));
  703. }
  704. }
  705. }
  706. }
  707. void cmVisualStudio10TargetGenerator::WritePackageReference(
  708. Elem& e1, std::string const& ref, std::string const& version)
  709. {
  710. Elem e2(e1, "PackageReference");
  711. e2.Attribute("Include", ref);
  712. e2.Attribute("Version", version);
  713. }
  714. void cmVisualStudio10TargetGenerator::WriteDotNetReferences(Elem& e0)
  715. {
  716. std::vector<std::string> references;
  717. if (const char* vsDotNetReferences =
  718. this->GeneratorTarget->GetProperty("VS_DOTNET_REFERENCES")) {
  719. cmSystemTools::ExpandListArgument(vsDotNetReferences, references);
  720. }
  721. cmPropertyMap const& props = this->GeneratorTarget->Target->GetProperties();
  722. for (auto const& i : props.GetList()) {
  723. if (i.first.find("VS_DOTNET_REFERENCE_") == 0) {
  724. std::string name = i.first.substr(20);
  725. if (!name.empty()) {
  726. std::string path = i.second;
  727. if (!cmsys::SystemTools::FileIsFullPath(path)) {
  728. path = this->Makefile->GetCurrentSourceDirectory() + "/" + path;
  729. }
  730. ConvertToWindowsSlash(path);
  731. this->DotNetHintReferences[""].push_back(
  732. DotNetHintReference(name, path));
  733. }
  734. }
  735. }
  736. if (!references.empty() || !this->DotNetHintReferences.empty()) {
  737. Elem e1(e0, "ItemGroup");
  738. for (std::string const& ri : references) {
  739. // if the entry from VS_DOTNET_REFERENCES is an existing file, generate
  740. // a new hint-reference and name it from the filename
  741. if (cmsys::SystemTools::FileExists(ri, true)) {
  742. std::string name =
  743. cmsys::SystemTools::GetFilenameWithoutLastExtension(ri);
  744. std::string path = ri;
  745. ConvertToWindowsSlash(path);
  746. this->DotNetHintReferences[""].push_back(
  747. DotNetHintReference(name, path));
  748. } else {
  749. this->WriteDotNetReference(e1, ri, "", "");
  750. }
  751. }
  752. for (const auto& h : this->DotNetHintReferences) {
  753. // DotNetHintReferences is also populated from AddLibraries().
  754. // The configuration specific hint references are added there.
  755. for (const auto& i : h.second) {
  756. this->WriteDotNetReference(e1, i.first, i.second, h.first);
  757. }
  758. }
  759. }
  760. }
  761. void cmVisualStudio10TargetGenerator::WriteDotNetReference(
  762. Elem& e1, std::string const& ref, std::string const& hint,
  763. std::string const& config)
  764. {
  765. Elem e2(e1, "Reference");
  766. // If 'config' is not empty, the reference is only added for the given
  767. // configuration. This is used when referencing imported managed assemblies.
  768. // See also cmVisualStudio10TargetGenerator::AddLibraries().
  769. if (!config.empty()) {
  770. e2.Attribute("Condition", this->CalcCondition(config));
  771. }
  772. e2.Attribute("Include", ref);
  773. e2.Element("CopyLocalSatelliteAssemblies", "true");
  774. e2.Element("ReferenceOutputAssembly", "true");
  775. if (!hint.empty()) {
  776. const char* privateReference = "True";
  777. if (const char* value = this->GeneratorTarget->GetProperty(
  778. "VS_DOTNET_REFERENCES_COPY_LOCAL")) {
  779. if (cmSystemTools::IsOff(value)) {
  780. privateReference = "False";
  781. }
  782. }
  783. e2.Element("Private", privateReference);
  784. e2.Element("HintPath", hint);
  785. }
  786. this->WriteDotNetReferenceCustomTags(e2, ref);
  787. }
  788. void cmVisualStudio10TargetGenerator::WriteImports(Elem& e0)
  789. {
  790. const char* imports =
  791. this->GeneratorTarget->Target->GetProperty("VS_PROJECT_IMPORT");
  792. if (imports) {
  793. std::vector<std::string> argsSplit;
  794. cmSystemTools::ExpandListArgument(std::string(imports), argsSplit, false);
  795. for (auto& path : argsSplit) {
  796. if (!cmsys::SystemTools::FileIsFullPath(path)) {
  797. path = this->Makefile->GetCurrentSourceDirectory() + "/" + path;
  798. }
  799. ConvertToWindowsSlash(path);
  800. Elem e1(e0, "Import");
  801. e1.Attribute("Project", path);
  802. }
  803. }
  804. }
  805. void cmVisualStudio10TargetGenerator::WriteDotNetReferenceCustomTags(
  806. Elem& e2, std::string const& ref)
  807. {
  808. static const std::string refpropPrefix = "VS_DOTNET_REFERENCEPROP_";
  809. static const std::string refpropInfix = "_TAG_";
  810. const std::string refPropFullPrefix = refpropPrefix + ref + refpropInfix;
  811. typedef std::map<std::string, std::string> CustomTags;
  812. CustomTags tags;
  813. cmPropertyMap const& props = this->GeneratorTarget->Target->GetProperties();
  814. for (const auto& i : props.GetList()) {
  815. if (i.first.find(refPropFullPrefix) == 0) {
  816. std::string refTag = i.first.substr(refPropFullPrefix.length());
  817. std::string refVal = i.second;
  818. if (!refTag.empty() && !refVal.empty()) {
  819. tags[refTag] = refVal;
  820. }
  821. }
  822. }
  823. for (auto const& tag : tags) {
  824. e2.Element(tag.first.c_str(), tag.second);
  825. }
  826. }
  827. void cmVisualStudio10TargetGenerator::WriteEmbeddedResourceGroup(Elem& e0)
  828. {
  829. std::vector<cmSourceFile const*> resxObjs;
  830. this->GeneratorTarget->GetResxSources(resxObjs, "");
  831. if (!resxObjs.empty()) {
  832. Elem e1(e0, "ItemGroup");
  833. std::string srcDir = this->Makefile->GetCurrentSourceDirectory();
  834. ConvertToWindowsSlash(srcDir);
  835. for (cmSourceFile const* oi : resxObjs) {
  836. std::string obj = oi->GetFullPath();
  837. ConvertToWindowsSlash(obj);
  838. bool useRelativePath = false;
  839. if (this->ProjectType == csproj && this->InSourceBuild) {
  840. // If we do an in-source build and the resource file is in a
  841. // subdirectory
  842. // of the .csproj file, we have to use relative pathnames, otherwise
  843. // visual studio does not show the file in the IDE. Sorry.
  844. if (obj.find(srcDir) == 0) {
  845. obj = this->ConvertPath(obj, true);
  846. ConvertToWindowsSlash(obj);
  847. useRelativePath = true;
  848. }
  849. }
  850. Elem e2(e1, "EmbeddedResource");
  851. e2.Attribute("Include", obj);
  852. if (this->ProjectType != csproj) {
  853. std::string hFileName = obj.substr(0, obj.find_last_of(".")) + ".h";
  854. e2.Element("DependentUpon", hFileName);
  855. for (std::string const& c : this->Configurations) {
  856. std::string s;
  857. if (this->GeneratorTarget->GetProperty("VS_GLOBAL_ROOTNAMESPACE") ||
  858. // Handle variant of VS_GLOBAL_<variable> for RootNamespace.
  859. this->GeneratorTarget->GetProperty("VS_GLOBAL_RootNamespace")) {
  860. s = "$(RootNamespace).";
  861. }
  862. s += "%(Filename).resources";
  863. e2.WritePlatformConfigTag("LogicalName", this->CalcCondition(c), s);
  864. }
  865. } else {
  866. std::string binDir = this->Makefile->GetCurrentBinaryDirectory();
  867. ConvertToWindowsSlash(binDir);
  868. // If the resource was NOT added using a relative path (which should
  869. // be the default), we have to provide a link here
  870. if (!useRelativePath) {
  871. std::string link;
  872. if (obj.find(srcDir) == 0) {
  873. link = obj.substr(srcDir.length() + 1);
  874. } else if (obj.find(binDir) == 0) {
  875. link = obj.substr(binDir.length() + 1);
  876. } else {
  877. link = cmsys::SystemTools::GetFilenameName(obj);
  878. }
  879. if (!link.empty()) {
  880. e2.Element("Link", link);
  881. }
  882. }
  883. // Determine if this is a generated resource from a .Designer.cs file
  884. std::string designerResource =
  885. cmSystemTools::GetFilenamePath(oi->GetFullPath()) + "/" +
  886. cmSystemTools::GetFilenameWithoutLastExtension(oi->GetFullPath()) +
  887. ".Designer.cs";
  888. if (cmsys::SystemTools::FileExists(designerResource)) {
  889. std::string generator = "PublicResXFileCodeGenerator";
  890. if (const char* g = oi->GetProperty("VS_RESOURCE_GENERATOR")) {
  891. generator = g;
  892. }
  893. if (!generator.empty()) {
  894. e2.Element("Generator", generator);
  895. if (designerResource.find(srcDir) == 0) {
  896. designerResource = designerResource.substr(srcDir.length() + 1);
  897. } else if (designerResource.find(binDir) == 0) {
  898. designerResource = designerResource.substr(binDir.length() + 1);
  899. } else {
  900. designerResource =
  901. cmsys::SystemTools::GetFilenameName(designerResource);
  902. }
  903. ConvertToWindowsSlash(designerResource);
  904. e2.Element("LastGenOutput", designerResource);
  905. }
  906. }
  907. const cmPropertyMap& props = oi->GetProperties();
  908. for (const std::string& p : props.GetKeys()) {
  909. static const std::string propNamePrefix = "VS_CSHARP_";
  910. if (p.find(propNamePrefix) == 0) {
  911. std::string tagName = p.substr(propNamePrefix.length());
  912. if (!tagName.empty()) {
  913. std::string value = props.GetPropertyValue(p);
  914. if (!value.empty()) {
  915. e2.Element(tagName.c_str(), value);
  916. }
  917. }
  918. }
  919. }
  920. }
  921. }
  922. }
  923. }
  924. void cmVisualStudio10TargetGenerator::WriteXamlFilesGroup(Elem& e0)
  925. {
  926. std::vector<cmSourceFile const*> xamlObjs;
  927. this->GeneratorTarget->GetXamlSources(xamlObjs, "");
  928. if (!xamlObjs.empty()) {
  929. Elem e1(e0, "ItemGroup");
  930. for (cmSourceFile const* oi : xamlObjs) {
  931. std::string obj = oi->GetFullPath();
  932. const char* xamlType;
  933. const char* xamlTypeProperty = oi->GetProperty("VS_XAML_TYPE");
  934. if (xamlTypeProperty) {
  935. xamlType = xamlTypeProperty;
  936. } else {
  937. xamlType = "Page";
  938. }
  939. Elem e2(e1, xamlType);
  940. this->WriteSource(e2, oi);
  941. e2.SetHasElements();
  942. if (this->ProjectType == csproj && !this->InSourceBuild) {
  943. // add <Link> tag to written XAML source if necessary
  944. const std::string& srcDir =
  945. this->Makefile->GetCurrentSourceDirectory();
  946. const std::string& binDir =
  947. this->Makefile->GetCurrentBinaryDirectory();
  948. std::string link;
  949. if (obj.find(srcDir) == 0) {
  950. link = obj.substr(srcDir.length() + 1);
  951. } else if (obj.find(binDir) == 0) {
  952. link = obj.substr(binDir.length() + 1);
  953. } else {
  954. link = cmsys::SystemTools::GetFilenameName(obj);
  955. }
  956. if (!link.empty()) {
  957. ConvertToWindowsSlash(link);
  958. e2.Element("Link", link);
  959. }
  960. }
  961. e2.Element("SubType", "Designer");
  962. }
  963. }
  964. }
  965. void cmVisualStudio10TargetGenerator::WriteTargetSpecificReferences(Elem& e0)
  966. {
  967. if (this->MSTools) {
  968. if (this->GlobalGenerator->TargetsWindowsPhone() &&
  969. this->GlobalGenerator->GetSystemVersion() == "8.0") {
  970. Elem(e0, "Import")
  971. .Attribute("Project",
  972. "$(MSBuildExtensionsPath)\\Microsoft\\WindowsPhone\\v"
  973. "$(TargetPlatformVersion)\\Microsoft.Cpp.WindowsPhone."
  974. "$(TargetPlatformVersion).targets");
  975. }
  976. }
  977. }
  978. void cmVisualStudio10TargetGenerator::WriteTargetsFileReferences(Elem& e1)
  979. {
  980. for (TargetsFileAndConfigs const& tac : this->TargetsFileAndConfigsVec) {
  981. std::ostringstream oss;
  982. oss << "Exists('" << tac.File << "')";
  983. if (!tac.Configs.empty()) {
  984. oss << " And (";
  985. for (size_t j = 0; j < tac.Configs.size(); ++j) {
  986. if (j > 0) {
  987. oss << " Or ";
  988. }
  989. oss << "'$(Configuration)'=='" << tac.Configs[j] << "'";
  990. }
  991. oss << ")";
  992. }
  993. Elem(e1, "Import")
  994. .Attribute("Project", tac.File)
  995. .Attribute("Condition", oss.str());
  996. }
  997. }
  998. void cmVisualStudio10TargetGenerator::WriteWinRTReferences(Elem& e0)
  999. {
  1000. std::vector<std::string> references;
  1001. if (const char* vsWinRTReferences =
  1002. this->GeneratorTarget->GetProperty("VS_WINRT_REFERENCES")) {
  1003. cmSystemTools::ExpandListArgument(vsWinRTReferences, references);
  1004. }
  1005. if (this->GlobalGenerator->TargetsWindowsPhone() &&
  1006. this->GlobalGenerator->GetSystemVersion() == "8.0" &&
  1007. references.empty()) {
  1008. references.push_back("platform.winmd");
  1009. }
  1010. if (!references.empty()) {
  1011. Elem e1(e0, "ItemGroup");
  1012. for (std::string const& ri : references) {
  1013. Elem e2(e1, "Reference");
  1014. e2.Attribute("Include", ri);
  1015. e2.Element("IsWinMDFile", "true");
  1016. }
  1017. }
  1018. }
  1019. // ConfigurationType Application, Utility StaticLibrary DynamicLibrary
  1020. void cmVisualStudio10TargetGenerator::WriteProjectConfigurations(Elem& e0)
  1021. {
  1022. Elem e1(e0, "ItemGroup");
  1023. e1.Attribute("Label", "ProjectConfigurations");
  1024. for (std::string const& c : this->Configurations) {
  1025. Elem e2(e1, "ProjectConfiguration");
  1026. e2.Attribute("Include", c + "|" + this->Platform);
  1027. e2.Element("Configuration", c);
  1028. e2.Element("Platform", this->Platform);
  1029. }
  1030. }
  1031. void cmVisualStudio10TargetGenerator::WriteProjectConfigurationValues(Elem& e0)
  1032. {
  1033. for (std::string const& c : this->Configurations) {
  1034. Elem e1(e0, "PropertyGroup");
  1035. e1.Attribute("Condition", this->CalcCondition(c));
  1036. e1.Attribute("Label", "Configuration");
  1037. if (this->ProjectType != csproj) {
  1038. std::string configType;
  1039. if (const char* vsConfigurationType =
  1040. this->GeneratorTarget->GetProperty("VS_CONFIGURATION_TYPE")) {
  1041. configType = vsConfigurationType;
  1042. } else {
  1043. switch (this->GeneratorTarget->GetType()) {
  1044. case cmStateEnums::SHARED_LIBRARY:
  1045. case cmStateEnums::MODULE_LIBRARY:
  1046. configType = "DynamicLibrary";
  1047. break;
  1048. case cmStateEnums::OBJECT_LIBRARY:
  1049. case cmStateEnums::STATIC_LIBRARY:
  1050. configType = "StaticLibrary";
  1051. break;
  1052. case cmStateEnums::EXECUTABLE:
  1053. if (this->NsightTegra &&
  1054. !this->GeneratorTarget->GetPropertyAsBool("ANDROID_GUI")) {
  1055. // Android executables are .so too.
  1056. configType = "DynamicLibrary";
  1057. } else {
  1058. configType = "Application";
  1059. }
  1060. break;
  1061. case cmStateEnums::UTILITY:
  1062. case cmStateEnums::GLOBAL_TARGET:
  1063. if (this->NsightTegra) {
  1064. // Tegra-Android platform does not understand "Utility".
  1065. configType = "StaticLibrary";
  1066. } else {
  1067. configType = "Utility";
  1068. }
  1069. break;
  1070. case cmStateEnums::UNKNOWN_LIBRARY:
  1071. case cmStateEnums::INTERFACE_LIBRARY:
  1072. break;
  1073. }
  1074. }
  1075. e1.Element("ConfigurationType", configType);
  1076. }
  1077. if (this->MSTools) {
  1078. if (!this->Managed) {
  1079. this->WriteMSToolConfigurationValues(e1, c);
  1080. } else {
  1081. this->WriteMSToolConfigurationValuesManaged(e1, c);
  1082. }
  1083. } else if (this->NsightTegra) {
  1084. this->WriteNsightTegraConfigurationValues(e1, c);
  1085. }
  1086. }
  1087. }
  1088. void cmVisualStudio10TargetGenerator::WriteCEDebugProjectConfigurationValues(
  1089. Elem& e0)
  1090. {
  1091. if (!this->GlobalGenerator->TargetsWindowsCE()) {
  1092. return;
  1093. }
  1094. const char* additionalFiles =
  1095. this->GeneratorTarget->GetProperty("DEPLOYMENT_ADDITIONAL_FILES");
  1096. const char* remoteDirectory =
  1097. this->GeneratorTarget->GetProperty("DEPLOYMENT_REMOTE_DIRECTORY");
  1098. if (!(additionalFiles || remoteDirectory)) {
  1099. return;
  1100. }
  1101. for (std::string const& c : this->Configurations) {
  1102. Elem e1(e0, "PropertyGroup");
  1103. e1.Attribute("Condition", this->CalcCondition(c));
  1104. if (remoteDirectory) {
  1105. e1.Element("RemoteDirectory", remoteDirectory);
  1106. }
  1107. if (additionalFiles) {
  1108. e1.Element("CEAdditionalFiles", additionalFiles);
  1109. }
  1110. }
  1111. }
  1112. void cmVisualStudio10TargetGenerator::WriteMSToolConfigurationValues(
  1113. Elem& e1, std::string const& config)
  1114. {
  1115. cmGlobalVisualStudio10Generator* gg = this->GlobalGenerator;
  1116. const char* mfcFlag = this->Makefile->GetDefinition("CMAKE_MFC_FLAG");
  1117. if (mfcFlag) {
  1118. std::string const mfcFlagValue = mfcFlag;
  1119. std::string useOfMfcValue = "false";
  1120. if (this->GeneratorTarget->GetType() <= cmStateEnums::OBJECT_LIBRARY) {
  1121. if (mfcFlagValue == "1") {
  1122. useOfMfcValue = "Static";
  1123. } else if (mfcFlagValue == "2") {
  1124. useOfMfcValue = "Dynamic";
  1125. }
  1126. }
  1127. e1.Element("UseOfMfc", useOfMfcValue);
  1128. }
  1129. if ((this->GeneratorTarget->GetType() <= cmStateEnums::OBJECT_LIBRARY &&
  1130. this->ClOptions[config]->UsingUnicode()) ||
  1131. this->GeneratorTarget->GetPropertyAsBool("VS_WINRT_COMPONENT") ||
  1132. this->GlobalGenerator->TargetsWindowsPhone() ||
  1133. this->GlobalGenerator->TargetsWindowsStore() ||
  1134. this->GeneratorTarget->GetPropertyAsBool("VS_WINRT_EXTENSIONS")) {
  1135. e1.Element("CharacterSet", "Unicode");
  1136. } else if (this->GeneratorTarget->GetType() <=
  1137. cmStateEnums::MODULE_LIBRARY &&
  1138. this->ClOptions[config]->UsingSBCS()) {
  1139. e1.Element("CharacterSet", "NotSet");
  1140. } else {
  1141. e1.Element("CharacterSet", "MultiByte");
  1142. }
  1143. if (const char* toolset = gg->GetPlatformToolset()) {
  1144. e1.Element("PlatformToolset", toolset);
  1145. }
  1146. if (this->GeneratorTarget->GetPropertyAsBool("VS_WINRT_COMPONENT") ||
  1147. this->GeneratorTarget->GetPropertyAsBool("VS_WINRT_EXTENSIONS")) {
  1148. e1.Element("WindowsAppContainer", "true");
  1149. }
  1150. if (this->IPOEnabledConfigurations.count(config) > 0) {
  1151. e1.Element("WholeProgramOptimization", "true");
  1152. }
  1153. if (this->SpectreMitigationConfigurations.count(config) > 0) {
  1154. e1.Element("SpectreMitigation", "Spectre");
  1155. }
  1156. }
  1157. void cmVisualStudio10TargetGenerator::WriteMSToolConfigurationValuesManaged(
  1158. Elem& e1, std::string const& config)
  1159. {
  1160. if (this->GeneratorTarget->GetType() > cmStateEnums::OBJECT_LIBRARY) {
  1161. return;
  1162. }
  1163. cmGlobalVisualStudio10Generator* gg = this->GlobalGenerator;
  1164. Options& o = *(this->ClOptions[config]);
  1165. if (o.IsDebug()) {
  1166. e1.Element("DebugSymbols", "true");
  1167. e1.Element("DefineDebug", "true");
  1168. }
  1169. std::string outDir = this->GeneratorTarget->GetDirectory(config) + "/";
  1170. ConvertToWindowsSlash(outDir);
  1171. e1.Element("OutputPath", outDir);
  1172. if (o.HasFlag("Platform")) {
  1173. e1.Element("PlatformTarget", o.GetFlag("Platform"));
  1174. o.RemoveFlag("Platform");
  1175. }
  1176. if (const char* toolset = gg->GetPlatformToolset()) {
  1177. e1.Element("PlatformToolset", toolset);
  1178. }
  1179. std::string postfixName = cmSystemTools::UpperCase(config);
  1180. postfixName += "_POSTFIX";
  1181. std::string assemblyName = this->GeneratorTarget->GetOutputName(
  1182. config, cmStateEnums::RuntimeBinaryArtifact);
  1183. if (const char* postfix = this->GeneratorTarget->GetProperty(postfixName)) {
  1184. assemblyName += postfix;
  1185. }
  1186. e1.Element("AssemblyName", assemblyName);
  1187. if (cmStateEnums::EXECUTABLE == this->GeneratorTarget->GetType()) {
  1188. e1.Element("StartAction", "Program");
  1189. e1.Element("StartProgram", outDir + assemblyName + ".exe");
  1190. }
  1191. OptionsHelper oh(o, e1);
  1192. oh.OutputFlagMap();
  1193. }
  1194. //----------------------------------------------------------------------------
  1195. void cmVisualStudio10TargetGenerator::WriteNsightTegraConfigurationValues(
  1196. Elem& e1, std::string const&)
  1197. {
  1198. cmGlobalVisualStudio10Generator* gg = this->GlobalGenerator;
  1199. const char* toolset = gg->GetPlatformToolset();
  1200. e1.Element("NdkToolchainVersion", toolset ? toolset : "Default");
  1201. if (const char* minApi =
  1202. this->GeneratorTarget->GetProperty("ANDROID_API_MIN")) {
  1203. e1.Element("AndroidMinAPI", "android-" + std::string(minApi));
  1204. }
  1205. if (const char* api = this->GeneratorTarget->GetProperty("ANDROID_API")) {
  1206. e1.Element("AndroidTargetAPI", "android-" + std::string(api));
  1207. }
  1208. if (const char* cpuArch =
  1209. this->GeneratorTarget->GetProperty("ANDROID_ARCH")) {
  1210. e1.Element("AndroidArch", cpuArch);
  1211. }
  1212. if (const char* stlType =
  1213. this->GeneratorTarget->GetProperty("ANDROID_STL_TYPE")) {
  1214. e1.Element("AndroidStlType", stlType);
  1215. }
  1216. }
  1217. void cmVisualStudio10TargetGenerator::WriteCustomCommands(Elem& e0)
  1218. {
  1219. this->CSharpCustomCommandNames.clear();
  1220. std::vector<cmSourceFile const*> customCommands;
  1221. this->GeneratorTarget->GetCustomCommands(customCommands, "");
  1222. for (cmSourceFile const* si : customCommands) {
  1223. this->WriteCustomCommand(e0, si);
  1224. }
  1225. // Add CMakeLists.txt file with rule to re-run CMake for user convenience.
  1226. if (this->GeneratorTarget->GetType() != cmStateEnums::GLOBAL_TARGET &&
  1227. this->GeneratorTarget->GetName() != CMAKE_CHECK_BUILD_SYSTEM_TARGET) {
  1228. if (cmSourceFile const* sf =
  1229. this->LocalGenerator->CreateVCProjBuildRule()) {
  1230. // Write directly rather than through WriteCustomCommand because
  1231. // we do not want the de-duplication and it has no dependencies.
  1232. if (cmCustomCommand const* command = sf->GetCustomCommand()) {
  1233. this->WriteCustomRule(e0, sf, *command);
  1234. }
  1235. }
  1236. }
  1237. }
  1238. void cmVisualStudio10TargetGenerator::WriteCustomCommand(
  1239. Elem& e0, cmSourceFile const* sf)
  1240. {
  1241. if (this->LocalGenerator->GetSourcesVisited(this->GeneratorTarget)
  1242. .insert(sf)
  1243. .second) {
  1244. if (std::vector<cmSourceFile*> const* depends =
  1245. this->GeneratorTarget->GetSourceDepends(sf)) {
  1246. for (cmSourceFile const* di : *depends) {
  1247. this->WriteCustomCommand(e0, di);
  1248. }
  1249. }
  1250. if (cmCustomCommand const* command = sf->GetCustomCommand()) {
  1251. // C# projects write their <Target> within WriteCustomRule()
  1252. this->WriteCustomRule(e0, sf, *command);
  1253. }
  1254. }
  1255. }
  1256. void cmVisualStudio10TargetGenerator::WriteCustomRule(
  1257. Elem& e0, cmSourceFile const* source, cmCustomCommand const& command)
  1258. {
  1259. std::string sourcePath = source->GetFullPath();
  1260. // VS 10 will always rebuild a custom command attached to a .rule
  1261. // file that doesn't exist so create the file explicitly.
  1262. if (source->GetPropertyAsBool("__CMAKE_RULE")) {
  1263. if (!cmSystemTools::FileExists(sourcePath)) {
  1264. // Make sure the path exists for the file
  1265. std::string path = cmSystemTools::GetFilenamePath(sourcePath);
  1266. cmSystemTools::MakeDirectory(path);
  1267. cmsys::ofstream fout(sourcePath.c_str());
  1268. if (fout) {
  1269. fout << "# generated from CMake\n";
  1270. fout.flush();
  1271. fout.close();
  1272. // Force given file to have a very old timestamp, thus
  1273. // preventing dependent rebuilds.
  1274. this->ForceOld(sourcePath);
  1275. } else {
  1276. std::string error = "Could not create file: [";
  1277. error += sourcePath;
  1278. error += "] ";
  1279. cmSystemTools::Error(error + cmSystemTools::GetLastSystemError());
  1280. }
  1281. }
  1282. }
  1283. cmLocalVisualStudio7Generator* lg = this->LocalGenerator;
  1284. std::unique_ptr<Elem> spe1;
  1285. std::unique_ptr<Elem> spe2;
  1286. if (this->ProjectType != csproj) {
  1287. spe1 = cm::make_unique<Elem>(e0, "ItemGroup");
  1288. spe2 = cm::make_unique<Elem>(*spe1, "CustomBuild");
  1289. this->WriteSource(*spe2, source);
  1290. spe2->SetHasElements();
  1291. } else {
  1292. Elem e1(e0, "ItemGroup");
  1293. Elem e2(e1, "None");
  1294. std::string link;
  1295. this->GetCSharpSourceLink(source, link);
  1296. this->WriteSource(e2, source);
  1297. e2.SetHasElements();
  1298. if (!link.empty()) {
  1299. e2.Element("Link", link);
  1300. }
  1301. }
  1302. for (std::string const& c : this->Configurations) {
  1303. cmCustomCommandGenerator ccg(command, c, lg);
  1304. std::string comment = lg->ConstructComment(ccg);
  1305. comment = cmVS10EscapeComment(comment);
  1306. std::string script = lg->ConstructScript(ccg);
  1307. // input files for custom command
  1308. std::stringstream additional_inputs;
  1309. {
  1310. const char* sep = "";
  1311. if (this->ProjectType == csproj) {
  1312. // csproj files do not attach the command to a specific file
  1313. // so the primary input must be listed explicitly.
  1314. additional_inputs << source->GetFullPath();
  1315. sep = ";";
  1316. }
  1317. // Avoid listing an input more than once.
  1318. std::set<std::string> unique_inputs;
  1319. // The source is either implicit an input or has been added above.
  1320. unique_inputs.insert(source->GetFullPath());
  1321. for (std::string const& d : ccg.GetDepends()) {
  1322. std::string dep;
  1323. if (lg->GetRealDependency(d, c, dep)) {
  1324. if (!unique_inputs.insert(dep).second) {
  1325. // already listed
  1326. continue;
  1327. }
  1328. ConvertToWindowsSlash(dep);
  1329. additional_inputs << sep << dep;
  1330. sep = ";";
  1331. }
  1332. }
  1333. if (this->ProjectType != csproj) {
  1334. additional_inputs << sep << "%(AdditionalInputs)";
  1335. }
  1336. }
  1337. // output files for custom command
  1338. std::stringstream outputs;
  1339. {
  1340. const char* sep = "";
  1341. for (std::string const& o : ccg.GetOutputs()) {
  1342. std::string out = o;
  1343. ConvertToWindowsSlash(out);
  1344. outputs << sep << out;
  1345. sep = ";";
  1346. }
  1347. }
  1348. if (this->ProjectType == csproj) {
  1349. std::string name = "CustomCommand_" + c + "_" +
  1350. cmSystemTools::ComputeStringMD5(sourcePath);
  1351. this->WriteCustomRuleCSharp(e0, c, name, script, additional_inputs.str(),
  1352. outputs.str(), comment);
  1353. } else {
  1354. this->WriteCustomRuleCpp(*spe2, c, script, additional_inputs.str(),
  1355. outputs.str(), comment);
  1356. }
  1357. }
  1358. }
  1359. void cmVisualStudio10TargetGenerator::WriteCustomRuleCpp(
  1360. Elem& e2, std::string const& config, std::string const& script,
  1361. std::string const& additional_inputs, std::string const& outputs,
  1362. std::string const& comment)
  1363. {
  1364. const std::string cond = this->CalcCondition(config);
  1365. e2.WritePlatformConfigTag("Message", cond, comment);
  1366. e2.WritePlatformConfigTag("Command", cond, script);
  1367. e2.WritePlatformConfigTag("AdditionalInputs", cond, additional_inputs);
  1368. e2.WritePlatformConfigTag("Outputs", cond, outputs);
  1369. if (this->LocalGenerator->GetVersion() >
  1370. cmGlobalVisualStudioGenerator::VS10) {
  1371. // VS >= 11 let us turn off linking of custom command outputs.
  1372. e2.WritePlatformConfigTag("LinkObjects", cond, "false");
  1373. }
  1374. }
  1375. void cmVisualStudio10TargetGenerator::WriteCustomRuleCSharp(
  1376. Elem& e0, std::string const& config, std::string const& name,
  1377. std::string const& script, std::string const& inputs,
  1378. std::string const& outputs, std::string const& comment)
  1379. {
  1380. this->CSharpCustomCommandNames.insert(name);
  1381. Elem e1(e0, "Target");
  1382. e1.Attribute("Condition", this->CalcCondition(config));
  1383. e1.S << "\n Name=\"" << name << "\"";
  1384. e1.S << "\n Inputs=\"" << cmVS10EscapeAttr(inputs) << "\"";
  1385. e1.S << "\n Outputs=\"" << cmVS10EscapeAttr(outputs) << "\"";
  1386. if (!comment.empty()) {
  1387. Elem(e1, "Exec").Attribute("Command", "echo " + comment);
  1388. }
  1389. Elem(e1, "Exec").Attribute("Command", script);
  1390. }
  1391. std::string cmVisualStudio10TargetGenerator::ConvertPath(
  1392. std::string const& path, bool forceRelative)
  1393. {
  1394. return forceRelative
  1395. ? cmSystemTools::RelativePath(
  1396. this->LocalGenerator->GetCurrentBinaryDirectory(), path)
  1397. : path;
  1398. }
  1399. static void ConvertToWindowsSlash(std::string& s)
  1400. {
  1401. // first convert all of the slashes
  1402. for (auto& ch : s) {
  1403. if (ch == '/') {
  1404. ch = '\\';
  1405. }
  1406. }
  1407. }
  1408. void cmVisualStudio10TargetGenerator::WriteGroups()
  1409. {
  1410. if (this->ProjectType == csproj) {
  1411. return;
  1412. }
  1413. // collect up group information
  1414. std::vector<cmSourceGroup> sourceGroups = this->Makefile->GetSourceGroups();
  1415. std::vector<cmGeneratorTarget::AllConfigSource> const& sources =
  1416. this->GeneratorTarget->GetAllConfigSources();
  1417. std::set<cmSourceGroup const*> groupsUsed;
  1418. for (cmGeneratorTarget::AllConfigSource const& si : sources) {
  1419. std::string const& source = si.Source->GetFullPath();
  1420. cmSourceGroup* sourceGroup =
  1421. this->Makefile->FindSourceGroup(source, sourceGroups);
  1422. groupsUsed.insert(sourceGroup);
  1423. }
  1424. if (cmSourceFile const* srcCMakeLists =
  1425. this->LocalGenerator->CreateVCProjBuildRule()) {
  1426. std::string const& source = srcCMakeLists->GetFullPath();
  1427. cmSourceGroup* sourceGroup =
  1428. this->Makefile->FindSourceGroup(source, sourceGroups);
  1429. groupsUsed.insert(sourceGroup);
  1430. }
  1431. this->AddMissingSourceGroups(groupsUsed, sourceGroups);
  1432. // Write out group file
  1433. std::string path = this->LocalGenerator->GetCurrentBinaryDirectory();
  1434. path += "/";
  1435. path += this->Name;
  1436. path += computeProjectFileExtension(this->GeneratorTarget);
  1437. path += ".filters";
  1438. cmGeneratedFileStream fout(path);
  1439. fout.SetCopyIfDifferent(true);
  1440. char magic[] = { char(0xEF), char(0xBB), char(0xBF) };
  1441. fout.write(magic, 3);
  1442. fout << "<?xml version=\"1.0\" encoding=\""
  1443. << this->GlobalGenerator->Encoding() << "\"?>"
  1444. << "\n";
  1445. {
  1446. Elem e0(fout, "Project");
  1447. e0.Attribute("ToolsVersion", this->GlobalGenerator->GetToolsVersion());
  1448. e0.Attribute("xmlns",
  1449. "http://schemas.microsoft.com/developer/msbuild/2003");
  1450. for (auto const& ti : this->Tools) {
  1451. this->WriteGroupSources(e0, ti.first, ti.second, sourceGroups);
  1452. }
  1453. // Added files are images and the manifest.
  1454. if (!this->AddedFiles.empty()) {
  1455. Elem e1(e0, "ItemGroup");
  1456. e1.SetHasElements();
  1457. for (std::string const& oi : this->AddedFiles) {
  1458. std::string fileName =
  1459. cmSystemTools::LowerCase(cmSystemTools::GetFilenameName(oi));
  1460. if (fileName == "wmappmanifest.xml") {
  1461. Elem e2(e1, "XML");
  1462. e2.Attribute("Include", oi);
  1463. e2.Element("Filter", "Resource Files");
  1464. } else if (cmSystemTools::GetFilenameExtension(fileName) ==
  1465. ".appxmanifest") {
  1466. Elem e2(e1, "AppxManifest");
  1467. e2.Attribute("Include", oi);
  1468. e2.Element("Filter", "Resource Files");
  1469. } else if (cmSystemTools::GetFilenameExtension(fileName) == ".pfx") {
  1470. Elem e2(e1, "None");
  1471. e2.Attribute("Include", oi);
  1472. e2.Element("Filter", "Resource Files");
  1473. } else {
  1474. Elem e2(e1, "Image");
  1475. e2.Attribute("Include", oi);
  1476. e2.Element("Filter", "Resource Files");
  1477. }
  1478. }
  1479. }
  1480. std::vector<cmSourceFile const*> resxObjs;
  1481. this->GeneratorTarget->GetResxSources(resxObjs, "");
  1482. if (!resxObjs.empty()) {
  1483. Elem e1(e0, "ItemGroup");
  1484. for (cmSourceFile const* oi : resxObjs) {
  1485. std::string obj = oi->GetFullPath();
  1486. ConvertToWindowsSlash(obj);
  1487. Elem e2(e1, "EmbeddedResource");
  1488. e2.Attribute("Include", obj);
  1489. e2.Element("Filter", "Resource Files");
  1490. }
  1491. }
  1492. {
  1493. Elem e1(e0, "ItemGroup");
  1494. e1.SetHasElements();
  1495. std::vector<cmSourceGroup const*> groupsVec(groupsUsed.begin(),
  1496. groupsUsed.end());
  1497. std::sort(groupsVec.begin(), groupsVec.end(),
  1498. [](cmSourceGroup const* l, cmSourceGroup const* r) {
  1499. return l->GetFullName() < r->GetFullName();
  1500. });
  1501. for (cmSourceGroup const* sg : groupsVec) {
  1502. std::string const& name = sg->GetFullName();
  1503. if (!name.empty()) {
  1504. std::string guidName = "SG_Filter_" + name;
  1505. std::string guid = this->GlobalGenerator->GetGUID(guidName);
  1506. Elem e2(e1, "Filter");
  1507. e2.Attribute("Include", name);
  1508. e2.Element("UniqueIdentifier", "{" + guid + "}");
  1509. }
  1510. }
  1511. if (!resxObjs.empty() || !this->AddedFiles.empty()) {
  1512. std::string guidName = "SG_Filter_Resource Files";
  1513. std::string guid = this->GlobalGenerator->GetGUID(guidName);
  1514. Elem e2(e1, "Filter");
  1515. e2.Attribute("Include", "Resource Files");
  1516. e2.Element("UniqueIdentifier", "{" + guid + "}");
  1517. e2.Element("Extensions",
  1518. "rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;"
  1519. "gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms");
  1520. }
  1521. }
  1522. }
  1523. fout << '\n';
  1524. if (fout.Close()) {
  1525. this->GlobalGenerator->FileReplacedDuringGenerate(path);
  1526. }
  1527. }
  1528. // Add to groupsUsed empty source groups that have non-empty children.
  1529. void cmVisualStudio10TargetGenerator::AddMissingSourceGroups(
  1530. std::set<cmSourceGroup const*>& groupsUsed,
  1531. const std::vector<cmSourceGroup>& allGroups)
  1532. {
  1533. for (cmSourceGroup const& current : allGroups) {
  1534. std::vector<cmSourceGroup> const& children = current.GetGroupChildren();
  1535. if (children.empty()) {
  1536. continue; // the group is really empty
  1537. }
  1538. this->AddMissingSourceGroups(groupsUsed, children);
  1539. if (groupsUsed.count(&current) > 0) {
  1540. continue; // group has already been added to set
  1541. }
  1542. // check if it least one of the group's descendants is not empty
  1543. // (at least one child must already have been added)
  1544. auto child_it = children.begin();
  1545. while (child_it != children.end()) {
  1546. if (groupsUsed.count(&(*child_it)) > 0) {
  1547. break; // found a child that was already added => add current group too
  1548. }
  1549. child_it++;
  1550. }
  1551. if (child_it == children.end()) {
  1552. continue; // no descendants have source files => ignore this group
  1553. }
  1554. groupsUsed.insert(&current);
  1555. }
  1556. }
  1557. void cmVisualStudio10TargetGenerator::WriteGroupSources(
  1558. Elem& e0, std::string const& name, ToolSources const& sources,
  1559. std::vector<cmSourceGroup>& sourceGroups)
  1560. {
  1561. Elem e1(e0, "ItemGroup");
  1562. e1.SetHasElements();
  1563. for (ToolSource const& s : sources) {
  1564. cmSourceFile const* sf = s.SourceFile;
  1565. std::string const& source = sf->GetFullPath();
  1566. cmSourceGroup* sourceGroup =
  1567. this->Makefile->FindSourceGroup(source, sourceGroups);
  1568. std::string const& filter = sourceGroup->GetFullName();
  1569. std::string path = this->ConvertPath(source, s.RelativePath);
  1570. ConvertToWindowsSlash(path);
  1571. Elem e2(e1, name.c_str());
  1572. e2.Attribute("Include", path);
  1573. if (!filter.empty()) {
  1574. e2.Element("Filter", filter);
  1575. }
  1576. }
  1577. }
  1578. void cmVisualStudio10TargetGenerator::WriteHeaderSource(Elem& e1,
  1579. cmSourceFile const* sf)
  1580. {
  1581. std::string const& fileName = sf->GetFullPath();
  1582. Elem e2(e1, "ClInclude");
  1583. this->WriteSource(e2, sf);
  1584. if (this->IsResxHeader(fileName)) {
  1585. e2.Element("FileType", "CppForm");
  1586. } else if (this->IsXamlHeader(fileName)) {
  1587. std::string xamlFileName = fileName.substr(0, fileName.find_last_of("."));
  1588. e2.Element("DependentUpon", xamlFileName);
  1589. }
  1590. }
  1591. void cmVisualStudio10TargetGenerator::WriteExtraSource(Elem& e1,
  1592. cmSourceFile const* sf)
  1593. {
  1594. bool toolHasSettings = false;
  1595. const char* tool = "None";
  1596. std::string shaderType;
  1597. std::string shaderEntryPoint;
  1598. std::string shaderModel;
  1599. std::string shaderAdditionalFlags;
  1600. std::string shaderDisableOptimizations;
  1601. std::string shaderEnableDebug;
  1602. std::string shaderObjectFileName;
  1603. std::string outputHeaderFile;
  1604. std::string variableName;
  1605. std::string settingsGenerator;
  1606. std::string settingsLastGenOutput;
  1607. std::string sourceLink;
  1608. std::string subType;
  1609. std::string copyToOutDir;
  1610. std::string includeInVsix;
  1611. std::string ext = cmSystemTools::LowerCase(sf->GetExtension());
  1612. if (this->ProjectType == csproj) {
  1613. // EVERY extra source file must have a <Link>, otherwise it might not
  1614. // be visible in Visual Studio at all. The path relative to current
  1615. // source- or binary-dir is used within the link, if the file is
  1616. // in none of these paths, it is added with the plain filename without
  1617. // any path. This means the file will show up at root-level of the csproj
  1618. // (where CMakeLists.txt etc. are).
  1619. if (!this->InSourceBuild) {
  1620. toolHasSettings = true;
  1621. std::string fullFileName = sf->GetFullPath();
  1622. std::string srcDir = this->Makefile->GetCurrentSourceDirectory();
  1623. std::string binDir = this->Makefile->GetCurrentBinaryDirectory();
  1624. if (fullFileName.find(binDir) != std::string::npos) {
  1625. sourceLink.clear();
  1626. } else if (fullFileName.find(srcDir) != std::string::npos) {
  1627. sourceLink = fullFileName.substr(srcDir.length() + 1);
  1628. } else {
  1629. // fallback: add plain filename without any path
  1630. sourceLink = cmsys::SystemTools::GetFilenameName(fullFileName);
  1631. }
  1632. if (!sourceLink.empty()) {
  1633. ConvertToWindowsSlash(sourceLink);
  1634. }
  1635. }
  1636. }
  1637. if (ext == "hlsl") {
  1638. tool = "FXCompile";
  1639. // Figure out the type of shader compiler to use.
  1640. if (const char* st = sf->GetProperty("VS_SHADER_TYPE")) {
  1641. shaderType = st;
  1642. toolHasSettings = true;
  1643. }
  1644. // Figure out which entry point to use if any
  1645. if (const char* se = sf->GetProperty("VS_SHADER_ENTRYPOINT")) {
  1646. shaderEntryPoint = se;
  1647. toolHasSettings = true;
  1648. }
  1649. // Figure out which shader model to use if any
  1650. if (const char* sm = sf->GetProperty("VS_SHADER_MODEL")) {
  1651. shaderModel = sm;
  1652. toolHasSettings = true;
  1653. }
  1654. // Figure out which output header file to use if any
  1655. if (const char* ohf = sf->GetProperty("VS_SHADER_OUTPUT_HEADER_FILE")) {
  1656. outputHeaderFile = ohf;
  1657. toolHasSettings = true;
  1658. }
  1659. // Figure out which variable name to use if any
  1660. if (const char* vn = sf->GetProperty("VS_SHADER_VARIABLE_NAME")) {
  1661. variableName = vn;
  1662. toolHasSettings = true;
  1663. }
  1664. // Figure out if there's any additional flags to use
  1665. if (const char* saf = sf->GetProperty("VS_SHADER_FLAGS")) {
  1666. shaderAdditionalFlags = saf;
  1667. toolHasSettings = true;
  1668. }
  1669. // Figure out if debug information should be generated
  1670. if (const char* sed = sf->GetProperty("VS_SHADER_ENABLE_DEBUG")) {
  1671. shaderEnableDebug = sed;
  1672. toolHasSettings = true;
  1673. }
  1674. // Figure out if optimizations should be disabled
  1675. if (const char* sdo = sf->GetProperty("VS_SHADER_DISABLE_OPTIMIZATIONS")) {
  1676. shaderDisableOptimizations = sdo;
  1677. toolHasSettings = true;
  1678. }
  1679. if (const char* sofn = sf->GetProperty("VS_SHADER_OBJECT_FILE_NAME")) {
  1680. shaderObjectFileName = sofn;
  1681. toolHasSettings = true;
  1682. }
  1683. } else if (ext == "jpg" || ext == "png") {
  1684. tool = "Image";
  1685. } else if (ext == "resw") {
  1686. tool = "PRIResource";
  1687. } else if (ext == "xml") {
  1688. tool = "XML";
  1689. } else if (ext == "natvis") {
  1690. tool = "Natvis";
  1691. } else if (ext == "settings") {
  1692. settingsLastGenOutput =
  1693. cmsys::SystemTools::GetFilenameName(sf->GetFullPath());
  1694. std::size_t pos = settingsLastGenOutput.find(".settings");
  1695. settingsLastGenOutput.replace(pos, 9, ".Designer.cs");
  1696. settingsGenerator = "SettingsSingleFileGenerator";
  1697. toolHasSettings = true;
  1698. } else if (ext == "vsixmanifest") {
  1699. subType = "Designer";
  1700. }
  1701. if (const char* c = sf->GetProperty("VS_COPY_TO_OUT_DIR")) {
  1702. tool = "Content";
  1703. copyToOutDir = c;
  1704. toolHasSettings = true;
  1705. }
  1706. if (sf->GetPropertyAsBool("VS_INCLUDE_IN_VSIX")) {
  1707. includeInVsix = "True";
  1708. tool = "Content";
  1709. toolHasSettings = true;
  1710. }
  1711. // Collect VS_CSHARP_* property values (if some are set)
  1712. std::map<std::string, std::string> sourceFileTags;
  1713. this->GetCSharpSourceProperties(sf, sourceFileTags);
  1714. if (this->NsightTegra) {
  1715. // Nsight Tegra needs specific file types to check up-to-dateness.
  1716. std::string name = cmSystemTools::LowerCase(sf->GetLocation().GetName());
  1717. if (name == "androidmanifest.xml" || name == "build.xml" ||
  1718. name == "proguard.cfg" || name == "proguard-project.txt" ||
  1719. ext == "properties") {
  1720. tool = "AndroidBuild";
  1721. } else if (ext == "java") {
  1722. tool = "JCompile";
  1723. } else if (ext == "asm" || ext == "s") {
  1724. tool = "ClCompile";
  1725. }
  1726. }
  1727. const char* toolOverride = sf->GetProperty("VS_TOOL_OVERRIDE");
  1728. if (toolOverride && *toolOverride) {
  1729. tool = toolOverride;
  1730. }
  1731. std::string deployContent;
  1732. std::string deployLocation;
  1733. if (this->GlobalGenerator->TargetsWindowsPhone() ||
  1734. this->GlobalGenerator->TargetsWindowsStore()) {
  1735. const char* content = sf->GetProperty("VS_DEPLOYMENT_CONTENT");
  1736. if (content && *content) {
  1737. toolHasSettings = true;
  1738. deployContent = content;
  1739. const char* location = sf->GetProperty("VS_DEPLOYMENT_LOCATION");
  1740. if (location && *location) {
  1741. deployLocation = location;
  1742. }
  1743. }
  1744. }
  1745. Elem e2(e1, tool);
  1746. this->WriteSource(e2, sf);
  1747. if (toolHasSettings) {
  1748. e2.SetHasElements();
  1749. if (!deployContent.empty()) {
  1750. cmGeneratorExpression ge;
  1751. std::unique_ptr<cmCompiledGeneratorExpression> cge =
  1752. ge.Parse(deployContent);
  1753. // Deployment location cannot be set on a configuration basis
  1754. if (!deployLocation.empty()) {
  1755. e2.Element("Link", deployLocation + "\\%(FileName)%(Extension)");
  1756. }
  1757. for (size_t i = 0; i != this->Configurations.size(); ++i) {
  1758. if (cge->Evaluate(this->LocalGenerator, this->Configurations[i]) ==
  1759. "1") {
  1760. e2.WritePlatformConfigTag("DeploymentContent",
  1761. "'$(Configuration)|$(Platform)'=='" +
  1762. this->Configurations[i] + "|" +
  1763. this->Platform + "'",
  1764. "true");
  1765. } else {
  1766. e2.WritePlatformConfigTag("ExcludedFromBuild",
  1767. "'$(Configuration)|$(Platform)'=='" +
  1768. this->Configurations[i] + "|" +
  1769. this->Platform + "'",
  1770. "true");
  1771. }
  1772. }
  1773. }
  1774. if (!shaderType.empty()) {
  1775. e2.Element("ShaderType", shaderType);
  1776. }
  1777. if (!shaderEntryPoint.empty()) {
  1778. e2.Element("EntryPointName", shaderEntryPoint);
  1779. }
  1780. if (!shaderModel.empty()) {
  1781. e2.Element("ShaderModel", shaderModel);
  1782. }
  1783. if (!outputHeaderFile.empty()) {
  1784. for (size_t i = 0; i != this->Configurations.size(); ++i) {
  1785. e2.WritePlatformConfigTag("HeaderFileOutput",
  1786. "'$(Configuration)|$(Platform)'=='" +
  1787. this->Configurations[i] + "|" +
  1788. this->Platform + "'",
  1789. outputHeaderFile);
  1790. }
  1791. }
  1792. if (!variableName.empty()) {
  1793. for (size_t i = 0; i != this->Configurations.size(); ++i) {
  1794. e2.WritePlatformConfigTag("VariableName",
  1795. "'$(Configuration)|$(Platform)'=='" +
  1796. this->Configurations[i] + "|" +
  1797. this->Platform + "'",
  1798. variableName);
  1799. }
  1800. }
  1801. if (!shaderEnableDebug.empty()) {
  1802. cmGeneratorExpression ge;
  1803. std::unique_ptr<cmCompiledGeneratorExpression> cge =
  1804. ge.Parse(shaderEnableDebug);
  1805. for (size_t i = 0; i != this->Configurations.size(); ++i) {
  1806. const std::string& enableDebug =
  1807. cge->Evaluate(this->LocalGenerator, this->Configurations[i]);
  1808. if (!enableDebug.empty()) {
  1809. e2.WritePlatformConfigTag(
  1810. "EnableDebuggingInformation",
  1811. "'$(Configuration)|$(Platform)'=='" + this->Configurations[i] +
  1812. "|" + this->Platform + "'",
  1813. cmSystemTools::IsOn(enableDebug) ? "true" : "false");
  1814. }
  1815. }
  1816. }
  1817. if (!shaderDisableOptimizations.empty()) {
  1818. cmGeneratorExpression ge;
  1819. std::unique_ptr<cmCompiledGeneratorExpression> cge =
  1820. ge.Parse(shaderDisableOptimizations);
  1821. for (size_t i = 0; i != this->Configurations.size(); ++i) {
  1822. const std::string& disableOptimizations =
  1823. cge->Evaluate(this->LocalGenerator, this->Configurations[i]);
  1824. if (!disableOptimizations.empty()) {
  1825. e2.WritePlatformConfigTag(
  1826. "DisableOptimizations",
  1827. "'$(Configuration)|$(Platform)'=='" + this->Configurations[i] +
  1828. "|" + this->Platform + "'",
  1829. (cmSystemTools::IsOn(disableOptimizations) ? "true" : "false"));
  1830. }
  1831. }
  1832. }
  1833. if (!shaderObjectFileName.empty()) {
  1834. e2.Element("ObjectFileOutput", shaderObjectFileName);
  1835. }
  1836. if (!shaderAdditionalFlags.empty()) {
  1837. e2.Element("AdditionalOptions", shaderAdditionalFlags);
  1838. }
  1839. if (!settingsGenerator.empty()) {
  1840. e2.Element("Generator", settingsGenerator);
  1841. }
  1842. if (!settingsLastGenOutput.empty()) {
  1843. e2.Element("LastGenOutput", settingsLastGenOutput);
  1844. }
  1845. if (!sourceLink.empty()) {
  1846. e2.Element("Link", sourceLink);
  1847. }
  1848. if (!subType.empty()) {
  1849. e2.Element("SubType", subType);
  1850. }
  1851. if (!copyToOutDir.empty()) {
  1852. e2.Element("CopyToOutputDirectory", copyToOutDir);
  1853. }
  1854. if (!includeInVsix.empty()) {
  1855. e2.Element("IncludeInVSIX", includeInVsix);
  1856. }
  1857. // write source file specific tags
  1858. this->WriteCSharpSourceProperties(e2, sourceFileTags);
  1859. }
  1860. }
  1861. void cmVisualStudio10TargetGenerator::WriteSource(Elem& e2,
  1862. cmSourceFile const* sf)
  1863. {
  1864. // Visual Studio tools append relative paths to the current dir, as in:
  1865. //
  1866. // c:\path\to\current\dir\..\..\..\relative\path\to\source.c
  1867. //
  1868. // and fail if this exceeds the maximum allowed path length. Our path
  1869. // conversion uses full paths when possible to allow deeper trees.
  1870. // However, CUDA 8.0 msbuild rules fail on absolute paths so for CUDA
  1871. // we must use relative paths.
  1872. bool forceRelative = sf->GetLanguage() == "CUDA";
  1873. std::string sourceFile = this->ConvertPath(sf->GetFullPath(), forceRelative);
  1874. if (this->LocalGenerator->GetVersion() ==
  1875. cmGlobalVisualStudioGenerator::VS10 &&
  1876. cmSystemTools::FileIsFullPath(sourceFile)) {
  1877. // Normal path conversion resulted in a full path. VS 10 (but not 11)
  1878. // refuses to show the property page in the IDE for a source file with a
  1879. // full path (not starting in a '.' or '/' AFAICT). CMake <= 2.8.4 used a
  1880. // relative path but to allow deeper build trees CMake 2.8.[5678] used a
  1881. // full path except for custom commands. Custom commands do not work
  1882. // without a relative path, but they do not seem to be involved in tools
  1883. // with the above behavior. For other sources we now use a relative path
  1884. // when the combined path will not be too long so property pages appear.
  1885. std::string sourceRel = this->ConvertPath(sf->GetFullPath(), true);
  1886. size_t const maxLen = 250;
  1887. if (sf->GetCustomCommand() ||
  1888. ((this->LocalGenerator->GetCurrentBinaryDirectory().length() + 1 +
  1889. sourceRel.length()) <= maxLen)) {
  1890. forceRelative = true;
  1891. sourceFile = sourceRel;
  1892. } else {
  1893. this->GlobalGenerator->PathTooLong(this->GeneratorTarget, sf, sourceRel);
  1894. }
  1895. }
  1896. ConvertToWindowsSlash(sourceFile);
  1897. e2.Attribute("Include", sourceFile);
  1898. ToolSource toolSource = { sf, forceRelative };
  1899. this->Tools[e2.Tag].push_back(toolSource);
  1900. }
  1901. void cmVisualStudio10TargetGenerator::WriteAllSources(Elem& e0)
  1902. {
  1903. if (this->GeneratorTarget->GetType() > cmStateEnums::UTILITY) {
  1904. return;
  1905. }
  1906. Elem e1(e0, "ItemGroup");
  1907. e1.SetHasElements();
  1908. std::vector<size_t> all_configs;
  1909. for (size_t ci = 0; ci < this->Configurations.size(); ++ci) {
  1910. all_configs.push_back(ci);
  1911. }
  1912. std::vector<cmGeneratorTarget::AllConfigSource> const& sources =
  1913. this->GeneratorTarget->GetAllConfigSources();
  1914. cmSourceFile const* srcCMakeLists =
  1915. this->LocalGenerator->CreateVCProjBuildRule();
  1916. for (cmGeneratorTarget::AllConfigSource const& si : sources) {
  1917. if (si.Source == srcCMakeLists) {
  1918. // Skip explicit reference to CMakeLists.txt source.
  1919. continue;
  1920. }
  1921. const char* tool = nullptr;
  1922. switch (si.Kind) {
  1923. case cmGeneratorTarget::SourceKindAppManifest:
  1924. tool = "AppxManifest";
  1925. break;
  1926. case cmGeneratorTarget::SourceKindCertificate:
  1927. tool = "None";
  1928. break;
  1929. case cmGeneratorTarget::SourceKindCustomCommand:
  1930. // Handled elsewhere.
  1931. break;
  1932. case cmGeneratorTarget::SourceKindExternalObject:
  1933. tool = "Object";
  1934. if (this->LocalGenerator->GetVersion() <
  1935. cmGlobalVisualStudioGenerator::VS11) {
  1936. // For VS == 10 we cannot use LinkObjects to avoid linking custom
  1937. // command outputs. If an object file is generated in this target,
  1938. // then vs10 will use it in the build, and we have to list it as
  1939. // None instead of Object.
  1940. std::vector<cmSourceFile*> const* d =
  1941. this->GeneratorTarget->GetSourceDepends(si.Source);
  1942. if (d && !d->empty()) {
  1943. tool = "None";
  1944. }
  1945. }
  1946. break;
  1947. case cmGeneratorTarget::SourceKindExtra:
  1948. this->WriteExtraSource(e1, si.Source);
  1949. break;
  1950. case cmGeneratorTarget::SourceKindHeader:
  1951. this->WriteHeaderSource(e1, si.Source);
  1952. break;
  1953. case cmGeneratorTarget::SourceKindIDL:
  1954. tool = "Midl";
  1955. break;
  1956. case cmGeneratorTarget::SourceKindManifest:
  1957. // Handled elsewhere.
  1958. break;
  1959. case cmGeneratorTarget::SourceKindModuleDefinition:
  1960. tool = "None";
  1961. break;
  1962. case cmGeneratorTarget::SourceKindObjectSource: {
  1963. const std::string& lang = si.Source->GetLanguage();
  1964. if (lang == "C" || lang == "CXX") {
  1965. tool = "ClCompile";
  1966. } else if (lang == "ASM_MASM" &&
  1967. this->GlobalGenerator->IsMasmEnabled()) {
  1968. tool = "MASM";
  1969. } else if (lang == "ASM_NASM" &&
  1970. this->GlobalGenerator->IsNasmEnabled()) {
  1971. tool = "NASM";
  1972. } else if (lang == "RC") {
  1973. tool = "ResourceCompile";
  1974. } else if (lang == "CSharp") {
  1975. tool = "Compile";
  1976. } else if (lang == "CUDA" && this->GlobalGenerator->IsCudaEnabled()) {
  1977. tool = "CudaCompile";
  1978. } else {
  1979. tool = "None";
  1980. }
  1981. } break;
  1982. case cmGeneratorTarget::SourceKindResx:
  1983. // Handled elsewhere.
  1984. break;
  1985. case cmGeneratorTarget::SourceKindXaml:
  1986. // Handled elsewhere.
  1987. break;
  1988. }
  1989. if (tool) {
  1990. // Compute set of configurations to exclude, if any.
  1991. std::vector<size_t> const& include_configs = si.Configs;
  1992. std::vector<size_t> exclude_configs;
  1993. std::set_difference(all_configs.begin(), all_configs.end(),
  1994. include_configs.begin(), include_configs.end(),
  1995. std::back_inserter(exclude_configs));
  1996. Elem e2(e1, tool);
  1997. this->WriteSource(e2, si.Source);
  1998. if (si.Kind == cmGeneratorTarget::SourceKindObjectSource) {
  1999. this->OutputSourceSpecificFlags(e2, si.Source);
  2000. }
  2001. if (!exclude_configs.empty()) {
  2002. this->WriteExcludeFromBuild(e2, exclude_configs);
  2003. }
  2004. }
  2005. }
  2006. if (this->IsMissingFiles) {
  2007. this->WriteMissingFiles(e1);
  2008. }
  2009. }
  2010. void cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags(
  2011. Elem& e2, cmSourceFile const* source)
  2012. {
  2013. cmSourceFile const& sf = *source;
  2014. std::string objectName;
  2015. if (this->GeneratorTarget->HasExplicitObjectName(&sf)) {
  2016. objectName = this->GeneratorTarget->GetObjectName(&sf);
  2017. }
  2018. std::string flags;
  2019. bool configDependentFlags = false;
  2020. std::string options;
  2021. bool configDependentOptions = false;
  2022. std::string defines;
  2023. bool configDependentDefines = false;
  2024. std::string includes;
  2025. bool configDependentIncludes = false;
  2026. if (const char* cflags = sf.GetProperty("COMPILE_FLAGS")) {
  2027. configDependentFlags =
  2028. cmGeneratorExpression::Find(cflags) != std::string::npos;
  2029. flags += cflags;
  2030. }
  2031. if (const char* coptions = sf.GetProperty("COMPILE_OPTIONS")) {
  2032. configDependentOptions =
  2033. cmGeneratorExpression::Find(coptions) != std::string::npos;
  2034. options += coptions;
  2035. }
  2036. if (const char* cdefs = sf.GetProperty("COMPILE_DEFINITIONS")) {
  2037. configDependentDefines =
  2038. cmGeneratorExpression::Find(cdefs) != std::string::npos;
  2039. defines += cdefs;
  2040. }
  2041. if (const char* cincludes = sf.GetProperty("INCLUDE_DIRECTORIES")) {
  2042. configDependentIncludes =
  2043. cmGeneratorExpression::Find(cincludes) != std::string::npos;
  2044. includes += cincludes;
  2045. }
  2046. std::string lang =
  2047. this->GlobalGenerator->GetLanguageFromExtension(sf.GetExtension().c_str());
  2048. std::string sourceLang = this->LocalGenerator->GetSourceFileLanguage(sf);
  2049. const std::string& linkLanguage =
  2050. this->GeneratorTarget->GetLinkerLanguage("");
  2051. bool needForceLang = false;
  2052. // source file does not match its extension language
  2053. if (lang != sourceLang) {
  2054. needForceLang = true;
  2055. lang = sourceLang;
  2056. }
  2057. // if the source file does not match the linker language
  2058. // then force c or c++
  2059. const char* compileAs = 0;
  2060. if (needForceLang || (linkLanguage != lang)) {
  2061. if (lang == "CXX") {
  2062. // force a C++ file type
  2063. compileAs = "CompileAsCpp";
  2064. } else if (lang == "C") {
  2065. // force to c
  2066. compileAs = "CompileAsC";
  2067. }
  2068. }
  2069. bool noWinRT = this->TargetCompileAsWinRT && lang == "C";
  2070. // for the first time we need a new line if there is something
  2071. // produced here.
  2072. if (!objectName.empty()) {
  2073. if (lang == "CUDA") {
  2074. e2.Element("CompileOut", "$(IntDir)/" + objectName);
  2075. } else {
  2076. e2.Element("ObjectFileName", "$(IntDir)/" + objectName);
  2077. }
  2078. }
  2079. for (std::string const& config : this->Configurations) {
  2080. std::string configUpper = cmSystemTools::UpperCase(config);
  2081. std::string configDefines = defines;
  2082. std::string defPropName = "COMPILE_DEFINITIONS_";
  2083. defPropName += configUpper;
  2084. if (const char* ccdefs = sf.GetProperty(defPropName)) {
  2085. if (!configDefines.empty()) {
  2086. configDefines += ";";
  2087. }
  2088. configDependentDefines |=
  2089. cmGeneratorExpression::Find(ccdefs) != std::string::npos;
  2090. configDefines += ccdefs;
  2091. }
  2092. // if we have flags or defines for this config then
  2093. // use them
  2094. if (!flags.empty() || !options.empty() || !configDefines.empty() ||
  2095. !includes.empty() || compileAs || noWinRT) {
  2096. cmGlobalVisualStudio10Generator* gg = this->GlobalGenerator;
  2097. cmIDEFlagTable const* flagtable = nullptr;
  2098. const std::string& srclang = source->GetLanguage();
  2099. if (srclang == "C" || srclang == "CXX") {
  2100. flagtable = gg->GetClFlagTable();
  2101. } else if (srclang == "ASM_MASM" &&
  2102. this->GlobalGenerator->IsMasmEnabled()) {
  2103. flagtable = gg->GetMasmFlagTable();
  2104. } else if (lang == "ASM_NASM" &&
  2105. this->GlobalGenerator->IsNasmEnabled()) {
  2106. flagtable = gg->GetNasmFlagTable();
  2107. } else if (srclang == "RC") {
  2108. flagtable = gg->GetRcFlagTable();
  2109. } else if (srclang == "CSharp") {
  2110. flagtable = gg->GetCSharpFlagTable();
  2111. }
  2112. cmGeneratorExpressionInterpreter genexInterpreter(
  2113. this->LocalGenerator, config, this->GeneratorTarget, lang);
  2114. cmVS10GeneratorOptions clOptions(
  2115. this->LocalGenerator, cmVisualStudioGeneratorOptions::Compiler,
  2116. flagtable, this);
  2117. if (compileAs) {
  2118. clOptions.AddFlag("CompileAs", compileAs);
  2119. }
  2120. if (noWinRT) {
  2121. clOptions.AddFlag("CompileAsWinRT", "false");
  2122. }
  2123. if (configDependentFlags) {
  2124. clOptions.Parse(genexInterpreter.Evaluate(flags, "COMPILE_FLAGS"));
  2125. } else {
  2126. clOptions.Parse(flags);
  2127. }
  2128. if (!options.empty()) {
  2129. std::string expandedOptions;
  2130. if (configDependentOptions) {
  2131. this->LocalGenerator->AppendCompileOptions(
  2132. expandedOptions,
  2133. genexInterpreter.Evaluate(options, "COMPILE_OPTIONS"));
  2134. } else {
  2135. this->LocalGenerator->AppendCompileOptions(expandedOptions, options);
  2136. }
  2137. clOptions.Parse(expandedOptions);
  2138. }
  2139. if (clOptions.HasFlag("DisableSpecificWarnings")) {
  2140. clOptions.AppendFlag("DisableSpecificWarnings",
  2141. "%(DisableSpecificWarnings)");
  2142. }
  2143. if (configDependentDefines) {
  2144. clOptions.AddDefines(
  2145. genexInterpreter.Evaluate(configDefines, "COMPILE_DEFINITIONS"));
  2146. } else {
  2147. clOptions.AddDefines(configDefines);
  2148. }
  2149. std::vector<std::string> includeList;
  2150. if (configDependentIncludes) {
  2151. this->LocalGenerator->AppendIncludeDirectories(
  2152. includeList,
  2153. genexInterpreter.Evaluate(includes, "INCLUDE_DIRECTORIES"), *source);
  2154. } else {
  2155. this->LocalGenerator->AppendIncludeDirectories(includeList, includes,
  2156. *source);
  2157. }
  2158. clOptions.AddIncludes(includeList);
  2159. clOptions.SetConfiguration(config);
  2160. OptionsHelper oh(clOptions, e2);
  2161. oh.PrependInheritedString("AdditionalOptions");
  2162. oh.OutputAdditionalIncludeDirectories(lang);
  2163. oh.OutputFlagMap();
  2164. oh.OutputPreprocessorDefinitions(lang);
  2165. }
  2166. }
  2167. if (this->IsXamlSource(source->GetFullPath())) {
  2168. const std::string& fileName = source->GetFullPath();
  2169. std::string xamlFileName = fileName.substr(0, fileName.find_last_of("."));
  2170. e2.Element("DependentUpon", xamlFileName);
  2171. }
  2172. if (this->ProjectType == csproj) {
  2173. std::string f = source->GetFullPath();
  2174. typedef std::map<std::string, std::string> CsPropMap;
  2175. CsPropMap sourceFileTags;
  2176. // set <Link> tag if necessary
  2177. std::string link;
  2178. this->GetCSharpSourceLink(source, link);
  2179. if (!link.empty()) {
  2180. sourceFileTags["Link"] = link;
  2181. }
  2182. this->GetCSharpSourceProperties(&sf, sourceFileTags);
  2183. // write source file specific tags
  2184. if (!sourceFileTags.empty()) {
  2185. this->WriteCSharpSourceProperties(e2, sourceFileTags);
  2186. }
  2187. }
  2188. }
  2189. void cmVisualStudio10TargetGenerator::WriteExcludeFromBuild(
  2190. Elem& e2, std::vector<size_t> const& exclude_configs)
  2191. {
  2192. for (size_t ci : exclude_configs) {
  2193. e2.WritePlatformConfigTag("ExcludedFromBuild",
  2194. "'$(Configuration)|$(Platform)'=='" +
  2195. this->Configurations[ci] + "|" +
  2196. this->Platform + "'",
  2197. "true");
  2198. }
  2199. }
  2200. void cmVisualStudio10TargetGenerator::WritePathAndIncrementalLinkOptions(
  2201. Elem& e0)
  2202. {
  2203. cmStateEnums::TargetType ttype = this->GeneratorTarget->GetType();
  2204. if (ttype > cmStateEnums::GLOBAL_TARGET) {
  2205. return;
  2206. }
  2207. if (this->ProjectType == csproj) {
  2208. return;
  2209. }
  2210. Elem e1(e0, "PropertyGroup");
  2211. e1.Element("_ProjectFileVersion", "10.0.20506.1");
  2212. for (std::string const& config : this->Configurations) {
  2213. const std::string cond = this->CalcCondition(config);
  2214. if (ttype <= cmStateEnums::UTILITY) {
  2215. if (const char* workingDir = this->GeneratorTarget->GetProperty(
  2216. "VS_DEBUGGER_WORKING_DIRECTORY")) {
  2217. cmGeneratorExpression ge;
  2218. std::unique_ptr<cmCompiledGeneratorExpression> cge =
  2219. ge.Parse(workingDir);
  2220. std::string genWorkingDir =
  2221. cge->Evaluate(this->LocalGenerator, config);
  2222. e1.WritePlatformConfigTag("LocalDebuggerWorkingDirectory", cond,
  2223. genWorkingDir);
  2224. }
  2225. if (const char* environment =
  2226. this->GeneratorTarget->GetProperty("VS_DEBUGGER_ENVIRONMENT")) {
  2227. cmGeneratorExpression ge;
  2228. std::unique_ptr<cmCompiledGeneratorExpression> cge =
  2229. ge.Parse(environment);
  2230. std::string genEnvironment =
  2231. cge->Evaluate(this->LocalGenerator, config);
  2232. e1.WritePlatformConfigTag("LocalDebuggerEnvironment", cond,
  2233. genEnvironment);
  2234. }
  2235. if (const char* debuggerCommand =
  2236. this->GeneratorTarget->GetProperty("VS_DEBUGGER_COMMAND")) {
  2237. cmGeneratorExpression ge;
  2238. std::unique_ptr<cmCompiledGeneratorExpression> cge =
  2239. ge.Parse(debuggerCommand);
  2240. std::string genDebuggerCommand =
  2241. cge->Evaluate(this->LocalGenerator, config);
  2242. e1.WritePlatformConfigTag("LocalDebuggerCommand", cond,
  2243. genDebuggerCommand);
  2244. }
  2245. if (const char* commandArguments = this->GeneratorTarget->GetProperty(
  2246. "VS_DEBUGGER_COMMAND_ARGUMENTS")) {
  2247. cmGeneratorExpression ge;
  2248. std::unique_ptr<cmCompiledGeneratorExpression> cge =
  2249. ge.Parse(commandArguments);
  2250. std::string genCommandArguments =
  2251. cge->Evaluate(this->LocalGenerator, config);
  2252. e1.WritePlatformConfigTag("LocalDebuggerCommandArguments", cond,
  2253. genCommandArguments);
  2254. }
  2255. }
  2256. if (ttype >= cmStateEnums::UTILITY) {
  2257. e1.WritePlatformConfigTag(
  2258. "IntDir", cond, "$(Platform)\\$(Configuration)\\$(ProjectName)\\");
  2259. } else {
  2260. std::string intermediateDir =
  2261. this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
  2262. intermediateDir += "/";
  2263. intermediateDir += config;
  2264. intermediateDir += "/";
  2265. std::string outDir;
  2266. std::string targetNameFull;
  2267. if (ttype == cmStateEnums::OBJECT_LIBRARY) {
  2268. outDir = intermediateDir;
  2269. targetNameFull = this->GeneratorTarget->GetName();
  2270. targetNameFull += ".lib";
  2271. } else {
  2272. outDir = this->GeneratorTarget->GetDirectory(config) + "/";
  2273. targetNameFull = this->GeneratorTarget->GetFullName(config);
  2274. }
  2275. ConvertToWindowsSlash(intermediateDir);
  2276. ConvertToWindowsSlash(outDir);
  2277. e1.WritePlatformConfigTag("OutDir", cond, outDir);
  2278. e1.WritePlatformConfigTag("IntDir", cond, intermediateDir);
  2279. if (const char* sdkExecutableDirectories = this->Makefile->GetDefinition(
  2280. "CMAKE_VS_SDK_EXECUTABLE_DIRECTORIES")) {
  2281. e1.WritePlatformConfigTag("ExecutablePath", cond,
  2282. sdkExecutableDirectories);
  2283. }
  2284. if (const char* sdkIncludeDirectories = this->Makefile->GetDefinition(
  2285. "CMAKE_VS_SDK_INCLUDE_DIRECTORIES")) {
  2286. e1.WritePlatformConfigTag("IncludePath", cond, sdkIncludeDirectories);
  2287. }
  2288. if (const char* sdkReferenceDirectories = this->Makefile->GetDefinition(
  2289. "CMAKE_VS_SDK_REFERENCE_DIRECTORIES")) {
  2290. e1.WritePlatformConfigTag("ReferencePath", cond,
  2291. sdkReferenceDirectories);
  2292. }
  2293. if (const char* sdkLibraryDirectories = this->Makefile->GetDefinition(
  2294. "CMAKE_VS_SDK_LIBRARY_DIRECTORIES")) {
  2295. e1.WritePlatformConfigTag("LibraryPath", cond, sdkLibraryDirectories);
  2296. }
  2297. if (const char* sdkLibraryWDirectories = this->Makefile->GetDefinition(
  2298. "CMAKE_VS_SDK_LIBRARY_WINRT_DIRECTORIES")) {
  2299. e1.WritePlatformConfigTag("LibraryWPath", cond,
  2300. sdkLibraryWDirectories);
  2301. }
  2302. if (const char* sdkSourceDirectories =
  2303. this->Makefile->GetDefinition("CMAKE_VS_SDK_SOURCE_DIRECTORIES")) {
  2304. e1.WritePlatformConfigTag("SourcePath", cond, sdkSourceDirectories);
  2305. }
  2306. if (const char* sdkExcludeDirectories = this->Makefile->GetDefinition(
  2307. "CMAKE_VS_SDK_EXCLUDE_DIRECTORIES")) {
  2308. e1.WritePlatformConfigTag("ExcludePath", cond, sdkExcludeDirectories);
  2309. }
  2310. std::string name =
  2311. cmSystemTools::GetFilenameWithoutLastExtension(targetNameFull);
  2312. e1.WritePlatformConfigTag("TargetName", cond, name);
  2313. std::string ext =
  2314. cmSystemTools::GetFilenameLastExtension(targetNameFull);
  2315. if (ext.empty()) {
  2316. // An empty TargetExt causes a default extension to be used.
  2317. // A single "." appears to be treated as an empty extension.
  2318. ext = ".";
  2319. }
  2320. e1.WritePlatformConfigTag("TargetExt", cond, ext);
  2321. this->OutputLinkIncremental(e1, config);
  2322. }
  2323. }
  2324. }
  2325. void cmVisualStudio10TargetGenerator::OutputLinkIncremental(
  2326. Elem& e1, std::string const& configName)
  2327. {
  2328. if (!this->MSTools) {
  2329. return;
  2330. }
  2331. if (this->ProjectType == csproj) {
  2332. return;
  2333. }
  2334. // static libraries and things greater than modules do not need
  2335. // to set this option
  2336. if (this->GeneratorTarget->GetType() == cmStateEnums::STATIC_LIBRARY ||
  2337. this->GeneratorTarget->GetType() > cmStateEnums::MODULE_LIBRARY) {
  2338. return;
  2339. }
  2340. Options& linkOptions = *(this->LinkOptions[configName]);
  2341. const std::string cond = this->CalcCondition(configName);
  2342. if (this->IPOEnabledConfigurations.count(configName) == 0) {
  2343. const char* incremental = linkOptions.GetFlag("LinkIncremental");
  2344. e1.WritePlatformConfigTag("LinkIncremental", cond,
  2345. (incremental ? incremental : "true"));
  2346. }
  2347. linkOptions.RemoveFlag("LinkIncremental");
  2348. const char* manifest = linkOptions.GetFlag("GenerateManifest");
  2349. e1.WritePlatformConfigTag("GenerateManifest", cond,
  2350. (manifest ? manifest : "true"));
  2351. linkOptions.RemoveFlag("GenerateManifest");
  2352. // Some link options belong here. Use them now and remove them so that
  2353. // WriteLinkOptions does not use them.
  2354. const char* flags[] = { "LinkDelaySign", "LinkKeyFile", 0 };
  2355. for (const char** f = flags; *f; ++f) {
  2356. const char* flag = *f;
  2357. if (const char* value = linkOptions.GetFlag(flag)) {
  2358. e1.WritePlatformConfigTag(flag, cond, value);
  2359. linkOptions.RemoveFlag(flag);
  2360. }
  2361. }
  2362. }
  2363. std::vector<std::string> cmVisualStudio10TargetGenerator::GetIncludes(
  2364. std::string const& config, std::string const& lang) const
  2365. {
  2366. std::vector<std::string> includes;
  2367. this->LocalGenerator->GetIncludeDirectories(includes, this->GeneratorTarget,
  2368. lang, config);
  2369. for (std::string& i : includes) {
  2370. ConvertToWindowsSlash(i);
  2371. }
  2372. return includes;
  2373. }
  2374. bool cmVisualStudio10TargetGenerator::ComputeClOptions()
  2375. {
  2376. for (std::string const& c : this->Configurations) {
  2377. if (!this->ComputeClOptions(c)) {
  2378. return false;
  2379. }
  2380. }
  2381. return true;
  2382. }
  2383. bool cmVisualStudio10TargetGenerator::ComputeClOptions(
  2384. std::string const& configName)
  2385. {
  2386. // much of this was copied from here:
  2387. // copied from cmLocalVisualStudio7Generator.cxx 805
  2388. // TODO: Integrate code below with cmLocalVisualStudio7Generator.
  2389. cmGlobalVisualStudio10Generator* gg = this->GlobalGenerator;
  2390. std::unique_ptr<Options> pOptions;
  2391. switch (this->ProjectType) {
  2392. case vcxproj:
  2393. pOptions = cm::make_unique<Options>(
  2394. this->LocalGenerator, Options::Compiler, gg->GetClFlagTable());
  2395. break;
  2396. case csproj:
  2397. pOptions =
  2398. cm::make_unique<Options>(this->LocalGenerator, Options::CSharpCompiler,
  2399. gg->GetCSharpFlagTable());
  2400. break;
  2401. }
  2402. Options& clOptions = *pOptions;
  2403. std::string flags;
  2404. const std::string& linkLanguage =
  2405. this->GeneratorTarget->GetLinkerLanguage(configName);
  2406. if (linkLanguage.empty()) {
  2407. cmSystemTools::Error(
  2408. "CMake can not determine linker language for target: " + this->Name);
  2409. return false;
  2410. }
  2411. // Choose a language whose flags to use for ClCompile.
  2412. static const char* clLangs[] = { "CXX", "C", "Fortran" };
  2413. std::string langForClCompile;
  2414. if (this->ProjectType == csproj) {
  2415. langForClCompile = "CSharp";
  2416. } else if (std::find(cm::cbegin(clLangs), cm::cend(clLangs), linkLanguage) !=
  2417. cm::cend(clLangs)) {
  2418. langForClCompile = linkLanguage;
  2419. } else {
  2420. std::set<std::string> languages;
  2421. this->GeneratorTarget->GetLanguages(languages, configName);
  2422. for (const char* l : clLangs) {
  2423. if (languages.count(l)) {
  2424. langForClCompile = l;
  2425. break;
  2426. }
  2427. }
  2428. }
  2429. this->LangForClCompile = langForClCompile;
  2430. if (!langForClCompile.empty()) {
  2431. this->LocalGenerator->AddLanguageFlags(flags, this->GeneratorTarget,
  2432. langForClCompile, configName);
  2433. this->LocalGenerator->AddCompileOptions(flags, this->GeneratorTarget,
  2434. langForClCompile, configName);
  2435. }
  2436. // set the correct language
  2437. if (linkLanguage == "C") {
  2438. clOptions.AddFlag("CompileAs", "CompileAsC");
  2439. }
  2440. if (linkLanguage == "CXX") {
  2441. clOptions.AddFlag("CompileAs", "CompileAsCpp");
  2442. }
  2443. // Put the IPO enabled configurations into a set.
  2444. if (this->GeneratorTarget->IsIPOEnabled(linkLanguage, configName)) {
  2445. this->IPOEnabledConfigurations.insert(configName);
  2446. }
  2447. // Get preprocessor definitions for this directory.
  2448. std::string defineFlags = this->Makefile->GetDefineFlags();
  2449. if (this->MSTools) {
  2450. if (this->ProjectType == vcxproj) {
  2451. clOptions.FixExceptionHandlingDefault();
  2452. if (this->GlobalGenerator->GetVersion() >=
  2453. cmGlobalVisualStudioGenerator::VS15) {
  2454. // Toolsets that come with VS 2017 may now enable UseFullPaths
  2455. // by default and there is no negative /FC option that projects
  2456. // can use to switch it back. Older toolsets disable this by
  2457. // default anyway so this will not hurt them. If the project
  2458. // is using an explicit /FC option then parsing flags will
  2459. // replace this setting with "true" below.
  2460. clOptions.AddFlag("UseFullPaths", "false");
  2461. }
  2462. clOptions.AddFlag("PrecompiledHeader", "NotUsing");
  2463. std::string asmLocation = configName + "/";
  2464. clOptions.AddFlag("AssemblerListingLocation", asmLocation);
  2465. }
  2466. }
  2467. // check for managed C++ assembly compiler flag. This overrides any
  2468. // /clr* compiler flags which may be defined in the flags variable(s).
  2469. if (this->ProjectType != csproj) {
  2470. // Warn if /clr was added manually. This should not be done
  2471. // anymore, because cmGeneratorTarget may not be aware that the
  2472. // target uses C++/CLI.
  2473. if (flags.find("/clr") != std::string::npos ||
  2474. defineFlags.find("/clr") != std::string::npos) {
  2475. if (configName == this->Configurations[0]) {
  2476. std::string message = "For the target \"" +
  2477. this->GeneratorTarget->GetName() +
  2478. "\" the /clr compiler flag was added manually. " +
  2479. "Set usage of C++/CLI by setting COMMON_LANGUAGE_RUNTIME "
  2480. "target property.";
  2481. this->Makefile->IssueMessage(MessageType::WARNING, message);
  2482. }
  2483. }
  2484. if (auto* clr =
  2485. this->GeneratorTarget->GetProperty("COMMON_LANGUAGE_RUNTIME")) {
  2486. std::string clrString = clr;
  2487. if (!clrString.empty()) {
  2488. clrString = ":" + clrString;
  2489. }
  2490. flags += " /clr" + clrString;
  2491. }
  2492. }
  2493. clOptions.Parse(flags);
  2494. clOptions.Parse(defineFlags);
  2495. std::vector<std::string> targetDefines;
  2496. switch (this->ProjectType) {
  2497. case vcxproj:
  2498. if (!langForClCompile.empty()) {
  2499. this->GeneratorTarget->GetCompileDefinitions(targetDefines, configName,
  2500. langForClCompile);
  2501. }
  2502. break;
  2503. case csproj:
  2504. this->GeneratorTarget->GetCompileDefinitions(targetDefines, configName,
  2505. "CSharp");
  2506. break;
  2507. }
  2508. clOptions.AddDefines(targetDefines);
  2509. if (this->ProjectType == csproj) {
  2510. clOptions.AppendFlag("DefineConstants", targetDefines);
  2511. }
  2512. // Get includes for this target
  2513. if (!this->LangForClCompile.empty()) {
  2514. clOptions.AddIncludes(
  2515. this->GetIncludes(configName, this->LangForClCompile));
  2516. }
  2517. if (this->MSTools) {
  2518. clOptions.SetVerboseMakefile(
  2519. this->Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE"));
  2520. }
  2521. // Add a definition for the configuration name.
  2522. std::string configDefine = "CMAKE_INTDIR=\"";
  2523. configDefine += configName;
  2524. configDefine += "\"";
  2525. clOptions.AddDefine(configDefine);
  2526. if (const std::string* exportMacro =
  2527. this->GeneratorTarget->GetExportMacro()) {
  2528. clOptions.AddDefine(*exportMacro);
  2529. }
  2530. if (this->MSTools) {
  2531. // If we have the VS_WINRT_COMPONENT or CMAKE_VS_WINRT_BY_DEFAULT
  2532. // set then force Compile as WinRT.
  2533. if (this->GeneratorTarget->GetPropertyAsBool("VS_WINRT_COMPONENT") ||
  2534. this->Makefile->IsOn("CMAKE_VS_WINRT_BY_DEFAULT")) {
  2535. clOptions.AddFlag("CompileAsWinRT", "true");
  2536. // For WinRT components, add the _WINRT_DLL define to produce a lib
  2537. if (this->GeneratorTarget->GetType() == cmStateEnums::SHARED_LIBRARY ||
  2538. this->GeneratorTarget->GetType() == cmStateEnums::MODULE_LIBRARY) {
  2539. clOptions.AddDefine("_WINRT_DLL");
  2540. }
  2541. } else if (this->GlobalGenerator->TargetsWindowsStore() ||
  2542. this->GlobalGenerator->TargetsWindowsPhone()) {
  2543. if (!clOptions.IsWinRt()) {
  2544. clOptions.AddFlag("CompileAsWinRT", "false");
  2545. }
  2546. }
  2547. if (const char* winRT = clOptions.GetFlag("CompileAsWinRT")) {
  2548. if (cmSystemTools::IsOn(winRT)) {
  2549. this->TargetCompileAsWinRT = true;
  2550. }
  2551. }
  2552. }
  2553. if (this->ProjectType != csproj && clOptions.IsManaged()) {
  2554. this->Managed = true;
  2555. std::string managedType = clOptions.GetFlag("CompileAsManaged");
  2556. if (managedType == "Safe" || managedType == "Pure") {
  2557. // force empty calling convention if safe clr is used
  2558. clOptions.AddFlag("CallingConvention", "");
  2559. }
  2560. // The default values of these flags are incompatible to
  2561. // managed assemblies. We have to force valid values if
  2562. // the target is a managed C++ target.
  2563. clOptions.AddFlag("ExceptionHandling", "Async");
  2564. clOptions.AddFlag("BasicRuntimeChecks", "Default");
  2565. }
  2566. if (this->ProjectType == csproj) {
  2567. // /nowin32manifest overrides /win32manifest: parameter
  2568. if (clOptions.HasFlag("NoWin32Manifest")) {
  2569. clOptions.RemoveFlag("ApplicationManifest");
  2570. }
  2571. }
  2572. if (clOptions.HasFlag("SpectreMitigation")) {
  2573. this->SpectreMitigationConfigurations.insert(configName);
  2574. clOptions.RemoveFlag("SpectreMitigation");
  2575. }
  2576. this->ClOptions[configName] = std::move(pOptions);
  2577. return true;
  2578. }
  2579. void cmVisualStudio10TargetGenerator::WriteClOptions(
  2580. Elem& e1, std::string const& configName)
  2581. {
  2582. Options& clOptions = *(this->ClOptions[configName]);
  2583. if (this->ProjectType == csproj) {
  2584. return;
  2585. }
  2586. Elem e2(e1, "ClCompile");
  2587. OptionsHelper oh(clOptions, e2);
  2588. oh.PrependInheritedString("AdditionalOptions");
  2589. oh.OutputAdditionalIncludeDirectories(this->LangForClCompile);
  2590. oh.OutputFlagMap();
  2591. oh.OutputPreprocessorDefinitions(this->LangForClCompile);
  2592. if (this->NsightTegra) {
  2593. if (const char* processMax =
  2594. this->GeneratorTarget->GetProperty("ANDROID_PROCESS_MAX")) {
  2595. e2.Element("ProcessMax", processMax);
  2596. }
  2597. }
  2598. if (this->MSTools) {
  2599. cmsys::RegularExpression clangToolset("v[0-9]+_clang_.*");
  2600. const char* toolset = this->GlobalGenerator->GetPlatformToolset();
  2601. if (toolset && clangToolset.find(toolset)) {
  2602. e2.Element("ObjectFileName", "$(IntDir)%(filename).obj");
  2603. } else {
  2604. e2.Element("ObjectFileName", "$(IntDir)");
  2605. }
  2606. // If not in debug mode, write the DebugInformationFormat field
  2607. // without value so PDBs don't get generated uselessly. Each tag
  2608. // goes on its own line because Visual Studio corrects it this
  2609. // way when saving the project after CMake generates it.
  2610. if (!clOptions.IsDebug()) {
  2611. Elem e3(e2, "DebugInformationFormat");
  2612. e3.SetHasElements();
  2613. }
  2614. // Specify the compiler program database file if configured.
  2615. std::string pdb = this->GeneratorTarget->GetCompilePDBPath(configName);
  2616. if (!pdb.empty()) {
  2617. if (this->GlobalGenerator->IsCudaEnabled()) {
  2618. // CUDA does not quote paths with spaces correctly when forwarding
  2619. // this to the host compiler. Use a relative path to avoid spaces.
  2620. // FIXME: We can likely do this even when CUDA is not involved,
  2621. // but for now we will make a minimal change.
  2622. pdb = this->ConvertPath(pdb, true);
  2623. }
  2624. ConvertToWindowsSlash(pdb);
  2625. e2.Element("ProgramDataBaseFileName", pdb);
  2626. }
  2627. // add AdditionalUsingDirectories
  2628. if (this->AdditionalUsingDirectories.count(configName) > 0) {
  2629. std::string dirs;
  2630. for (auto u : this->AdditionalUsingDirectories[configName]) {
  2631. if (!dirs.empty()) {
  2632. dirs.append(";");
  2633. }
  2634. dirs.append(u);
  2635. }
  2636. e2.Element("AdditionalUsingDirectories", dirs);
  2637. }
  2638. }
  2639. }
  2640. bool cmVisualStudio10TargetGenerator::ComputeRcOptions()
  2641. {
  2642. for (std::string const& c : this->Configurations) {
  2643. if (!this->ComputeRcOptions(c)) {
  2644. return false;
  2645. }
  2646. }
  2647. return true;
  2648. }
  2649. bool cmVisualStudio10TargetGenerator::ComputeRcOptions(
  2650. std::string const& configName)
  2651. {
  2652. cmGlobalVisualStudio10Generator* gg = this->GlobalGenerator;
  2653. auto pOptions = cm::make_unique<Options>(
  2654. this->LocalGenerator, Options::ResourceCompiler, gg->GetRcFlagTable());
  2655. Options& rcOptions = *pOptions;
  2656. std::string CONFIG = cmSystemTools::UpperCase(configName);
  2657. std::string rcConfigFlagsVar = "CMAKE_RC_FLAGS_" + CONFIG;
  2658. std::string flags = this->Makefile->GetSafeDefinition("CMAKE_RC_FLAGS") +
  2659. " " + this->Makefile->GetSafeDefinition(rcConfigFlagsVar);
  2660. rcOptions.Parse(flags);
  2661. // For historical reasons, add the C preprocessor defines to RC.
  2662. Options& clOptions = *(this->ClOptions[configName]);
  2663. rcOptions.AddDefines(clOptions.GetDefines());
  2664. // Get includes for this target
  2665. rcOptions.AddIncludes(this->GetIncludes(configName, "RC"));
  2666. this->RcOptions[configName] = std::move(pOptions);
  2667. return true;
  2668. }
  2669. void cmVisualStudio10TargetGenerator::WriteRCOptions(
  2670. Elem& e1, std::string const& configName)
  2671. {
  2672. if (!this->MSTools) {
  2673. return;
  2674. }
  2675. Elem e2(e1, "ResourceCompile");
  2676. OptionsHelper rcOptions(*(this->RcOptions[configName]), e2);
  2677. rcOptions.OutputPreprocessorDefinitions("RC");
  2678. rcOptions.OutputAdditionalIncludeDirectories("RC");
  2679. rcOptions.PrependInheritedString("AdditionalOptions");
  2680. rcOptions.OutputFlagMap();
  2681. }
  2682. bool cmVisualStudio10TargetGenerator::ComputeCudaOptions()
  2683. {
  2684. if (!this->GlobalGenerator->IsCudaEnabled()) {
  2685. return true;
  2686. }
  2687. for (std::string const& c : this->Configurations) {
  2688. if (!this->ComputeCudaOptions(c)) {
  2689. return false;
  2690. }
  2691. }
  2692. return true;
  2693. }
  2694. bool cmVisualStudio10TargetGenerator::ComputeCudaOptions(
  2695. std::string const& configName)
  2696. {
  2697. cmGlobalVisualStudio10Generator* gg = this->GlobalGenerator;
  2698. auto pOptions = cm::make_unique<Options>(
  2699. this->LocalGenerator, Options::CudaCompiler, gg->GetCudaFlagTable());
  2700. Options& cudaOptions = *pOptions;
  2701. // Get compile flags for CUDA in this directory.
  2702. std::string CONFIG = cmSystemTools::UpperCase(configName);
  2703. std::string configFlagsVar = "CMAKE_CUDA_FLAGS_" + CONFIG;
  2704. std::string flags = this->Makefile->GetSafeDefinition("CMAKE_CUDA_FLAGS") +
  2705. " " + this->Makefile->GetSafeDefinition(configFlagsVar);
  2706. this->LocalGenerator->AddCompileOptions(flags, this->GeneratorTarget, "CUDA",
  2707. configName);
  2708. // Get preprocessor definitions for this directory.
  2709. std::string defineFlags = this->Makefile->GetDefineFlags();
  2710. cudaOptions.Parse(flags);
  2711. cudaOptions.Parse(defineFlags);
  2712. cudaOptions.ParseFinish();
  2713. // If we haven't explicitly enabled GPU debug information
  2714. // explicitly disable it
  2715. if (!cudaOptions.HasFlag("GPUDebugInfo")) {
  2716. cudaOptions.AddFlag("GPUDebugInfo", "false");
  2717. }
  2718. // The extension on object libraries the CUDA gives isn't
  2719. // consistent with how MSVC generates object libraries for C+, so set
  2720. // the default to not have any extension
  2721. cudaOptions.AddFlag("CompileOut", "$(IntDir)%(Filename).obj");
  2722. bool notPtx = true;
  2723. if (this->GeneratorTarget->GetPropertyAsBool("CUDA_SEPARABLE_COMPILATION")) {
  2724. cudaOptions.AddFlag("GenerateRelocatableDeviceCode", "true");
  2725. } else if (this->GeneratorTarget->GetPropertyAsBool(
  2726. "CUDA_PTX_COMPILATION")) {
  2727. cudaOptions.AddFlag("NvccCompilation", "ptx");
  2728. // We drop the %(Extension) component as CMake expects all PTX files
  2729. // to not have the source file extension at all
  2730. cudaOptions.AddFlag("CompileOut", "$(IntDir)%(Filename).ptx");
  2731. notPtx = false;
  2732. }
  2733. if (notPtx &&
  2734. cmSystemTools::VersionCompareGreaterEq(
  2735. "8.0", this->GlobalGenerator->GetPlatformToolsetCudaString())) {
  2736. // Explicitly state that we want this file to be treated as a
  2737. // CUDA file no matter what the file extensions is
  2738. // This is only needed for < CUDA 9
  2739. cudaOptions.AppendFlagString("AdditionalOptions", "-x cu");
  2740. }
  2741. // Specify the compiler program database file if configured.
  2742. std::string pdb = this->GeneratorTarget->GetCompilePDBPath(configName);
  2743. if (!pdb.empty()) {
  2744. // CUDA does not make the directory if it is non-standard.
  2745. std::string const pdbDir = cmSystemTools::GetFilenamePath(pdb);
  2746. cmSystemTools::MakeDirectory(pdbDir);
  2747. if (cmSystemTools::VersionCompareGreaterEq(
  2748. "9.2", this->GlobalGenerator->GetPlatformToolsetCudaString())) {
  2749. // CUDA does not have a field for this and does not honor the
  2750. // ProgramDataBaseFileName field in ClCompile. Work around this
  2751. // limitation by creating the directory and passing the flag ourselves.
  2752. pdb = this->ConvertPath(pdb, true);
  2753. ConvertToWindowsSlash(pdb);
  2754. std::string const clFd = "-Xcompiler=\"-Fd\\\"" + pdb + "\\\"\"";
  2755. cudaOptions.AppendFlagString("AdditionalOptions", clFd);
  2756. }
  2757. }
  2758. // CUDA automatically passes the proper '--machine' flag to nvcc
  2759. // for the current architecture, but does not reflect this default
  2760. // in the user-visible IDE settings. Set it explicitly.
  2761. if (this->Platform == "x64") {
  2762. cudaOptions.AddFlag("TargetMachinePlatform", "64");
  2763. }
  2764. // Convert the host compiler options to the toolset's abstractions
  2765. // using a secondary flag table.
  2766. cudaOptions.ClearTables();
  2767. cudaOptions.AddTable(gg->GetCudaHostFlagTable());
  2768. cudaOptions.Reparse("AdditionalCompilerOptions");
  2769. // `CUDA 8.0.targets` places AdditionalCompilerOptions before nvcc!
  2770. // Pass them through -Xcompiler in AdditionalOptions instead.
  2771. if (const char* acoPtr = cudaOptions.GetFlag("AdditionalCompilerOptions")) {
  2772. std::string aco = acoPtr;
  2773. cudaOptions.RemoveFlag("AdditionalCompilerOptions");
  2774. if (!aco.empty()) {
  2775. aco = this->LocalGenerator->EscapeForShell(aco, false);
  2776. cudaOptions.AppendFlagString("AdditionalOptions", "-Xcompiler=" + aco);
  2777. }
  2778. }
  2779. cudaOptions.FixCudaCodeGeneration();
  2780. std::vector<std::string> targetDefines;
  2781. this->GeneratorTarget->GetCompileDefinitions(targetDefines, configName,
  2782. "CUDA");
  2783. cudaOptions.AddDefines(targetDefines);
  2784. // Add a definition for the configuration name.
  2785. std::string configDefine = "CMAKE_INTDIR=\"";
  2786. configDefine += configName;
  2787. configDefine += "\"";
  2788. cudaOptions.AddDefine(configDefine);
  2789. if (const std::string* exportMacro =
  2790. this->GeneratorTarget->GetExportMacro()) {
  2791. cudaOptions.AddDefine(*exportMacro);
  2792. }
  2793. // Get includes for this target
  2794. cudaOptions.AddIncludes(this->GetIncludes(configName, "CUDA"));
  2795. cudaOptions.AddFlag("UseHostInclude", "false");
  2796. this->CudaOptions[configName] = std::move(pOptions);
  2797. return true;
  2798. }
  2799. void cmVisualStudio10TargetGenerator::WriteCudaOptions(
  2800. Elem& e1, std::string const& configName)
  2801. {
  2802. if (!this->MSTools || !this->GlobalGenerator->IsCudaEnabled()) {
  2803. return;
  2804. }
  2805. Elem e2(e1, "CudaCompile");
  2806. OptionsHelper cudaOptions(*(this->CudaOptions[configName]), e2);
  2807. cudaOptions.OutputAdditionalIncludeDirectories("CUDA");
  2808. cudaOptions.OutputPreprocessorDefinitions("CUDA");
  2809. cudaOptions.PrependInheritedString("AdditionalOptions");
  2810. cudaOptions.OutputFlagMap();
  2811. }
  2812. bool cmVisualStudio10TargetGenerator::ComputeCudaLinkOptions()
  2813. {
  2814. if (!this->GlobalGenerator->IsCudaEnabled()) {
  2815. return true;
  2816. }
  2817. for (std::string const& c : this->Configurations) {
  2818. if (!this->ComputeCudaLinkOptions(c)) {
  2819. return false;
  2820. }
  2821. }
  2822. return true;
  2823. }
  2824. bool cmVisualStudio10TargetGenerator::ComputeCudaLinkOptions(
  2825. std::string const& configName)
  2826. {
  2827. cmGlobalVisualStudio10Generator* gg = this->GlobalGenerator;
  2828. auto pOptions = cm::make_unique<Options>(
  2829. this->LocalGenerator, Options::CudaCompiler, gg->GetCudaFlagTable());
  2830. Options& cudaLinkOptions = *pOptions;
  2831. // Determine if we need to do a device link
  2832. bool doDeviceLinking = requireDeviceLinking(
  2833. *this->GeneratorTarget, *this->LocalGenerator, configName);
  2834. cudaLinkOptions.AddFlag("PerformDeviceLink",
  2835. doDeviceLinking ? "true" : "false");
  2836. // Suppress deprecation warnings for default GPU targets during device link.
  2837. if (cmSystemTools::VersionCompareGreaterEq(
  2838. this->GlobalGenerator->GetPlatformToolsetCudaString(), "8.0")) {
  2839. cudaLinkOptions.AppendFlagString("AdditionalOptions",
  2840. "-Wno-deprecated-gpu-targets");
  2841. }
  2842. this->CudaLinkOptions[configName] = std::move(pOptions);
  2843. return true;
  2844. }
  2845. void cmVisualStudio10TargetGenerator::WriteCudaLinkOptions(
  2846. Elem& e1, std::string const& configName)
  2847. {
  2848. if (this->GeneratorTarget->GetType() > cmStateEnums::MODULE_LIBRARY) {
  2849. return;
  2850. }
  2851. if (!this->MSTools || !this->GlobalGenerator->IsCudaEnabled()) {
  2852. return;
  2853. }
  2854. Elem e2(e1, "CudaLink");
  2855. OptionsHelper cudaLinkOptions(*(this->CudaLinkOptions[configName]), e2);
  2856. cudaLinkOptions.OutputFlagMap();
  2857. }
  2858. bool cmVisualStudio10TargetGenerator::ComputeMasmOptions()
  2859. {
  2860. if (!this->GlobalGenerator->IsMasmEnabled()) {
  2861. return true;
  2862. }
  2863. for (std::string const& c : this->Configurations) {
  2864. if (!this->ComputeMasmOptions(c)) {
  2865. return false;
  2866. }
  2867. }
  2868. return true;
  2869. }
  2870. bool cmVisualStudio10TargetGenerator::ComputeMasmOptions(
  2871. std::string const& configName)
  2872. {
  2873. cmGlobalVisualStudio10Generator* gg = this->GlobalGenerator;
  2874. auto pOptions = cm::make_unique<Options>(
  2875. this->LocalGenerator, Options::MasmCompiler, gg->GetMasmFlagTable());
  2876. Options& masmOptions = *pOptions;
  2877. std::string CONFIG = cmSystemTools::UpperCase(configName);
  2878. std::string configFlagsVar = "CMAKE_ASM_MASM_FLAGS_" + CONFIG;
  2879. std::string flags =
  2880. this->Makefile->GetSafeDefinition("CMAKE_ASM_MASM_FLAGS") + " " +
  2881. this->Makefile->GetSafeDefinition(configFlagsVar);
  2882. masmOptions.Parse(flags);
  2883. // Get includes for this target
  2884. masmOptions.AddIncludes(this->GetIncludes(configName, "ASM_MASM"));
  2885. this->MasmOptions[configName] = std::move(pOptions);
  2886. return true;
  2887. }
  2888. void cmVisualStudio10TargetGenerator::WriteMasmOptions(
  2889. Elem& e1, std::string const& configName)
  2890. {
  2891. if (!this->MSTools || !this->GlobalGenerator->IsMasmEnabled()) {
  2892. return;
  2893. }
  2894. Elem e2(e1, "MASM");
  2895. // Preprocessor definitions and includes are shared with clOptions.
  2896. OptionsHelper clOptions(*(this->ClOptions[configName]), e2);
  2897. clOptions.OutputPreprocessorDefinitions("ASM_MASM");
  2898. OptionsHelper masmOptions(*(this->MasmOptions[configName]), e2);
  2899. masmOptions.OutputAdditionalIncludeDirectories("ASM_MASM");
  2900. masmOptions.PrependInheritedString("AdditionalOptions");
  2901. masmOptions.OutputFlagMap();
  2902. }
  2903. bool cmVisualStudio10TargetGenerator::ComputeNasmOptions()
  2904. {
  2905. if (!this->GlobalGenerator->IsNasmEnabled()) {
  2906. return true;
  2907. }
  2908. for (std::string const& c : this->Configurations) {
  2909. if (!this->ComputeNasmOptions(c)) {
  2910. return false;
  2911. }
  2912. }
  2913. return true;
  2914. }
  2915. bool cmVisualStudio10TargetGenerator::ComputeNasmOptions(
  2916. std::string const& configName)
  2917. {
  2918. cmGlobalVisualStudio10Generator* gg = this->GlobalGenerator;
  2919. auto pOptions = cm::make_unique<Options>(
  2920. this->LocalGenerator, Options::NasmCompiler, gg->GetNasmFlagTable());
  2921. Options& nasmOptions = *pOptions;
  2922. std::string CONFIG = cmSystemTools::UpperCase(configName);
  2923. std::string configFlagsVar = "CMAKE_ASM_NASM_FLAGS_" + CONFIG;
  2924. std::string flags =
  2925. this->Makefile->GetSafeDefinition("CMAKE_ASM_NASM_FLAGS") + " -f" +
  2926. this->Makefile->GetSafeDefinition("CMAKE_ASM_NASM_OBJECT_FORMAT") + " " +
  2927. this->Makefile->GetSafeDefinition(configFlagsVar);
  2928. nasmOptions.Parse(flags);
  2929. // Get includes for this target
  2930. nasmOptions.AddIncludes(this->GetIncludes(configName, "ASM_NASM"));
  2931. this->NasmOptions[configName] = std::move(pOptions);
  2932. return true;
  2933. }
  2934. void cmVisualStudio10TargetGenerator::WriteNasmOptions(
  2935. Elem& e1, std::string const& configName)
  2936. {
  2937. if (!this->GlobalGenerator->IsNasmEnabled()) {
  2938. return;
  2939. }
  2940. Elem e2(e1, "NASM");
  2941. std::vector<std::string> includes =
  2942. this->GetIncludes(configName, "ASM_NASM");
  2943. OptionsHelper nasmOptions(*(this->NasmOptions[configName]), e2);
  2944. nasmOptions.OutputAdditionalIncludeDirectories("ASM_NASM");
  2945. nasmOptions.OutputFlagMap();
  2946. nasmOptions.PrependInheritedString("AdditionalOptions");
  2947. nasmOptions.OutputPreprocessorDefinitions("ASM_NASM");
  2948. // Preprocessor definitions and includes are shared with clOptions.
  2949. OptionsHelper clOptions(*(this->ClOptions[configName]), e2);
  2950. clOptions.OutputPreprocessorDefinitions("ASM_NASM");
  2951. }
  2952. void cmVisualStudio10TargetGenerator::WriteLibOptions(
  2953. Elem& e1, std::string const& config)
  2954. {
  2955. if (this->GeneratorTarget->GetType() != cmStateEnums::STATIC_LIBRARY &&
  2956. this->GeneratorTarget->GetType() != cmStateEnums::OBJECT_LIBRARY) {
  2957. return;
  2958. }
  2959. const std::string& linkLanguage =
  2960. this->GeneratorTarget->GetLinkClosure(config)->LinkerLanguage;
  2961. std::string libflags;
  2962. this->LocalGenerator->GetStaticLibraryFlags(
  2963. libflags, cmSystemTools::UpperCase(config), linkLanguage,
  2964. this->GeneratorTarget);
  2965. if (!libflags.empty()) {
  2966. Elem e2(e1, "Lib");
  2967. cmGlobalVisualStudio10Generator* gg = this->GlobalGenerator;
  2968. cmVS10GeneratorOptions libOptions(this->LocalGenerator,
  2969. cmVisualStudioGeneratorOptions::Linker,
  2970. gg->GetLibFlagTable(), this);
  2971. libOptions.Parse(libflags);
  2972. OptionsHelper oh(libOptions, e2);
  2973. oh.PrependInheritedString("AdditionalOptions");
  2974. oh.OutputFlagMap();
  2975. }
  2976. // We cannot generate metadata for static libraries. WindowsPhone
  2977. // and WindowsStore tools look at GenerateWindowsMetadata in the
  2978. // Link tool options even for static libraries.
  2979. if (this->GlobalGenerator->TargetsWindowsPhone() ||
  2980. this->GlobalGenerator->TargetsWindowsStore()) {
  2981. Elem e2(e1, "Link");
  2982. e2.Element("GenerateWindowsMetadata", "false");
  2983. }
  2984. }
  2985. void cmVisualStudio10TargetGenerator::WriteManifestOptions(
  2986. Elem& e1, std::string const& config)
  2987. {
  2988. if (this->GeneratorTarget->GetType() != cmStateEnums::EXECUTABLE &&
  2989. this->GeneratorTarget->GetType() != cmStateEnums::SHARED_LIBRARY &&
  2990. this->GeneratorTarget->GetType() != cmStateEnums::MODULE_LIBRARY) {
  2991. return;
  2992. }
  2993. std::vector<cmSourceFile const*> manifest_srcs;
  2994. this->GeneratorTarget->GetManifests(manifest_srcs, config);
  2995. if (!manifest_srcs.empty()) {
  2996. std::ostringstream oss;
  2997. for (cmSourceFile const* mi : manifest_srcs) {
  2998. std::string m = this->ConvertPath(mi->GetFullPath(), false);
  2999. ConvertToWindowsSlash(m);
  3000. oss << m << ";";
  3001. }
  3002. Elem e2(e1, "Manifest");
  3003. e2.Element("AdditionalManifestFiles", oss.str());
  3004. }
  3005. }
  3006. void cmVisualStudio10TargetGenerator::WriteAntBuildOptions(
  3007. Elem& e1, std::string const& configName)
  3008. {
  3009. // Look through the sources for AndroidManifest.xml and use
  3010. // its location as the root source directory.
  3011. std::string rootDir = this->LocalGenerator->GetCurrentSourceDirectory();
  3012. {
  3013. std::vector<cmSourceFile const*> extraSources;
  3014. this->GeneratorTarget->GetExtraSources(extraSources, "");
  3015. for (cmSourceFile const* si : extraSources) {
  3016. if ("androidmanifest.xml" ==
  3017. cmSystemTools::LowerCase(si->GetLocation().GetName())) {
  3018. rootDir = si->GetLocation().GetDirectory();
  3019. break;
  3020. }
  3021. }
  3022. }
  3023. // Tell MSBuild to launch Ant.
  3024. Elem e2(e1, "AntBuild");
  3025. {
  3026. std::string antBuildPath = rootDir;
  3027. ConvertToWindowsSlash(antBuildPath);
  3028. e2.Element("AntBuildPath", antBuildPath);
  3029. }
  3030. if (this->GeneratorTarget->GetPropertyAsBool("ANDROID_SKIP_ANT_STEP")) {
  3031. e2.Element("SkipAntStep", "true");
  3032. }
  3033. if (this->GeneratorTarget->GetPropertyAsBool("ANDROID_PROGUARD")) {
  3034. e2.Element("EnableProGuard", "true");
  3035. }
  3036. if (const char* proGuardConfigLocation =
  3037. this->GeneratorTarget->GetProperty("ANDROID_PROGUARD_CONFIG_PATH")) {
  3038. e2.Element("ProGuardConfigLocation", proGuardConfigLocation);
  3039. }
  3040. if (const char* securePropertiesLocation =
  3041. this->GeneratorTarget->GetProperty("ANDROID_SECURE_PROPS_PATH")) {
  3042. e2.Element("SecurePropertiesLocation", securePropertiesLocation);
  3043. }
  3044. if (const char* nativeLibDirectoriesExpression =
  3045. this->GeneratorTarget->GetProperty("ANDROID_NATIVE_LIB_DIRECTORIES")) {
  3046. cmGeneratorExpression ge;
  3047. std::unique_ptr<cmCompiledGeneratorExpression> cge =
  3048. ge.Parse(nativeLibDirectoriesExpression);
  3049. std::string nativeLibDirs =
  3050. cge->Evaluate(this->LocalGenerator, configName);
  3051. e2.Element("NativeLibDirectories", nativeLibDirs);
  3052. }
  3053. if (const char* nativeLibDependenciesExpression =
  3054. this->GeneratorTarget->GetProperty(
  3055. "ANDROID_NATIVE_LIB_DEPENDENCIES")) {
  3056. cmGeneratorExpression ge;
  3057. std::unique_ptr<cmCompiledGeneratorExpression> cge =
  3058. ge.Parse(nativeLibDependenciesExpression);
  3059. std::string nativeLibDeps =
  3060. cge->Evaluate(this->LocalGenerator, configName);
  3061. e2.Element("NativeLibDependencies", nativeLibDeps);
  3062. }
  3063. if (const char* javaSourceDir =
  3064. this->GeneratorTarget->GetProperty("ANDROID_JAVA_SOURCE_DIR")) {
  3065. e2.Element("JavaSourceDir", javaSourceDir);
  3066. }
  3067. if (const char* jarDirectoriesExpression =
  3068. this->GeneratorTarget->GetProperty("ANDROID_JAR_DIRECTORIES")) {
  3069. cmGeneratorExpression ge;
  3070. std::unique_ptr<cmCompiledGeneratorExpression> cge =
  3071. ge.Parse(jarDirectoriesExpression);
  3072. std::string jarDirectories =
  3073. cge->Evaluate(this->LocalGenerator, configName);
  3074. e2.Element("JarDirectories", jarDirectories);
  3075. }
  3076. if (const char* jarDeps =
  3077. this->GeneratorTarget->GetProperty("ANDROID_JAR_DEPENDENCIES")) {
  3078. e2.Element("JarDependencies", jarDeps);
  3079. }
  3080. if (const char* assetsDirectories =
  3081. this->GeneratorTarget->GetProperty("ANDROID_ASSETS_DIRECTORIES")) {
  3082. e2.Element("AssetsDirectories", assetsDirectories);
  3083. }
  3084. {
  3085. std::string manifest_xml = rootDir + "/AndroidManifest.xml";
  3086. ConvertToWindowsSlash(manifest_xml);
  3087. e2.Element("AndroidManifestLocation", manifest_xml);
  3088. }
  3089. if (const char* antAdditionalOptions =
  3090. this->GeneratorTarget->GetProperty("ANDROID_ANT_ADDITIONAL_OPTIONS")) {
  3091. e2.Element("AdditionalOptions",
  3092. std::string(antAdditionalOptions) + " %(AdditionalOptions)");
  3093. }
  3094. }
  3095. bool cmVisualStudio10TargetGenerator::ComputeLinkOptions()
  3096. {
  3097. if (this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE ||
  3098. this->GeneratorTarget->GetType() == cmStateEnums::SHARED_LIBRARY ||
  3099. this->GeneratorTarget->GetType() == cmStateEnums::MODULE_LIBRARY) {
  3100. for (std::string const& c : this->Configurations) {
  3101. if (!this->ComputeLinkOptions(c)) {
  3102. return false;
  3103. }
  3104. }
  3105. }
  3106. return true;
  3107. }
  3108. bool cmVisualStudio10TargetGenerator::ComputeLinkOptions(
  3109. std::string const& config)
  3110. {
  3111. cmGlobalVisualStudio10Generator* gg = this->GlobalGenerator;
  3112. auto pOptions = cm::make_unique<Options>(
  3113. this->LocalGenerator, Options::Linker, gg->GetLinkFlagTable(), this);
  3114. Options& linkOptions = *pOptions;
  3115. cmGeneratorTarget::LinkClosure const* linkClosure =
  3116. this->GeneratorTarget->GetLinkClosure(config);
  3117. const std::string& linkLanguage = linkClosure->LinkerLanguage;
  3118. if (linkLanguage.empty()) {
  3119. cmSystemTools::Error(
  3120. "CMake can not determine linker language for target: " + this->Name);
  3121. return false;
  3122. }
  3123. std::string CONFIG = cmSystemTools::UpperCase(config);
  3124. const char* linkType = "SHARED";
  3125. if (this->GeneratorTarget->GetType() == cmStateEnums::MODULE_LIBRARY) {
  3126. linkType = "MODULE";
  3127. }
  3128. if (this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE) {
  3129. linkType = "EXE";
  3130. }
  3131. std::string flags;
  3132. std::string linkFlagVarBase = "CMAKE_";
  3133. linkFlagVarBase += linkType;
  3134. linkFlagVarBase += "_LINKER_FLAGS";
  3135. flags += " ";
  3136. flags += this->Makefile->GetRequiredDefinition(linkFlagVarBase);
  3137. std::string linkFlagVar = linkFlagVarBase + "_" + CONFIG;
  3138. flags += " ";
  3139. flags += this->Makefile->GetRequiredDefinition(linkFlagVar);
  3140. const char* targetLinkFlags =
  3141. this->GeneratorTarget->GetProperty("LINK_FLAGS");
  3142. if (targetLinkFlags) {
  3143. flags += " ";
  3144. flags += targetLinkFlags;
  3145. }
  3146. std::string flagsProp = "LINK_FLAGS_";
  3147. flagsProp += CONFIG;
  3148. if (const char* flagsConfig =
  3149. this->GeneratorTarget->GetProperty(flagsProp)) {
  3150. flags += " ";
  3151. flags += flagsConfig;
  3152. }
  3153. std::vector<std::string> opts;
  3154. this->GeneratorTarget->GetLinkOptions(opts, config, linkLanguage);
  3155. // LINK_OPTIONS are escaped.
  3156. this->LocalGenerator->AppendCompileOptions(flags, opts);
  3157. cmComputeLinkInformation* pcli =
  3158. this->GeneratorTarget->GetLinkInformation(config);
  3159. if (!pcli) {
  3160. cmSystemTools::Error(
  3161. "CMake can not compute cmComputeLinkInformation for target: " +
  3162. this->Name);
  3163. return false;
  3164. }
  3165. cmComputeLinkInformation& cli = *pcli;
  3166. std::vector<std::string> libVec;
  3167. std::vector<std::string> vsTargetVec;
  3168. this->AddLibraries(cli, libVec, vsTargetVec, config);
  3169. if (std::find(linkClosure->Languages.begin(), linkClosure->Languages.end(),
  3170. "CUDA") != linkClosure->Languages.end() &&
  3171. this->CudaOptions[config] != nullptr) {
  3172. switch (this->CudaOptions[config]->GetCudaRuntime()) {
  3173. case cmVisualStudioGeneratorOptions::CudaRuntimeStatic:
  3174. libVec.push_back("cudadevrt.lib");
  3175. libVec.push_back("cudart_static.lib");
  3176. break;
  3177. case cmVisualStudioGeneratorOptions::CudaRuntimeShared:
  3178. libVec.push_back("cudadevrt.lib");
  3179. libVec.push_back("cudart.lib");
  3180. break;
  3181. case cmVisualStudioGeneratorOptions::CudaRuntimeNone:
  3182. break;
  3183. }
  3184. }
  3185. std::string standardLibsVar = "CMAKE_";
  3186. standardLibsVar += linkLanguage;
  3187. standardLibsVar += "_STANDARD_LIBRARIES";
  3188. std::string const& libs = this->Makefile->GetSafeDefinition(standardLibsVar);
  3189. cmSystemTools::ParseWindowsCommandLine(libs.c_str(), libVec);
  3190. linkOptions.AddFlag("AdditionalDependencies", libVec);
  3191. // Populate TargetsFileAndConfigsVec
  3192. for (std::string const& ti : vsTargetVec) {
  3193. this->AddTargetsFileAndConfigPair(ti, config);
  3194. }
  3195. std::vector<std::string> const& ldirs = cli.GetDirectories();
  3196. std::vector<std::string> linkDirs;
  3197. for (std::string const& d : ldirs) {
  3198. // first just full path
  3199. linkDirs.push_back(d);
  3200. // next path with configuration type Debug, Release, etc
  3201. linkDirs.push_back(d + "/$(Configuration)");
  3202. }
  3203. linkDirs.push_back("%(AdditionalLibraryDirectories)");
  3204. linkOptions.AddFlag("AdditionalLibraryDirectories", linkDirs);
  3205. cmGeneratorTarget::Names targetNames;
  3206. if (this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE) {
  3207. targetNames = this->GeneratorTarget->GetExecutableNames(config);
  3208. } else {
  3209. targetNames = this->GeneratorTarget->GetLibraryNames(config);
  3210. }
  3211. if (this->MSTools) {
  3212. if (this->GeneratorTarget->GetPropertyAsBool("WIN32_EXECUTABLE")) {
  3213. if (this->GlobalGenerator->TargetsWindowsCE()) {
  3214. linkOptions.AddFlag("SubSystem", "WindowsCE");
  3215. if (this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE) {
  3216. if (this->ClOptions[config]->UsingUnicode()) {
  3217. linkOptions.AddFlag("EntryPointSymbol", "wWinMainCRTStartup");
  3218. } else {
  3219. linkOptions.AddFlag("EntryPointSymbol", "WinMainCRTStartup");
  3220. }
  3221. }
  3222. } else {
  3223. linkOptions.AddFlag("SubSystem", "Windows");
  3224. }
  3225. } else {
  3226. if (this->GlobalGenerator->TargetsWindowsCE()) {
  3227. linkOptions.AddFlag("SubSystem", "WindowsCE");
  3228. if (this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE) {
  3229. if (this->ClOptions[config]->UsingUnicode()) {
  3230. linkOptions.AddFlag("EntryPointSymbol", "mainWCRTStartup");
  3231. } else {
  3232. linkOptions.AddFlag("EntryPointSymbol", "mainACRTStartup");
  3233. }
  3234. }
  3235. } else {
  3236. linkOptions.AddFlag("SubSystem", "Console");
  3237. };
  3238. }
  3239. if (const char* stackVal = this->Makefile->GetDefinition(
  3240. "CMAKE_" + linkLanguage + "_STACK_SIZE")) {
  3241. linkOptions.AddFlag("StackReserveSize", stackVal);
  3242. }
  3243. linkOptions.AddFlag("GenerateDebugInformation", "false");
  3244. std::string pdb = this->GeneratorTarget->GetPDBDirectory(config);
  3245. pdb += "/";
  3246. pdb += targetNames.PDB;
  3247. std::string imLib = this->GeneratorTarget->GetDirectory(
  3248. config, cmStateEnums::ImportLibraryArtifact);
  3249. imLib += "/";
  3250. imLib += targetNames.ImportLibrary;
  3251. linkOptions.AddFlag("ImportLibrary", imLib);
  3252. linkOptions.AddFlag("ProgramDataBaseFile", pdb);
  3253. // A Windows Runtime component uses internal .NET metadata,
  3254. // so does not have an import library.
  3255. if (this->GeneratorTarget->GetPropertyAsBool("VS_WINRT_COMPONENT") &&
  3256. this->GeneratorTarget->GetType() != cmStateEnums::EXECUTABLE) {
  3257. linkOptions.AddFlag("GenerateWindowsMetadata", "true");
  3258. } else if (this->GlobalGenerator->TargetsWindowsPhone() ||
  3259. this->GlobalGenerator->TargetsWindowsStore()) {
  3260. // WindowsPhone and WindowsStore components are in an app container
  3261. // and produce WindowsMetadata. If we are not producing a WINRT
  3262. // component, then do not generate the metadata here.
  3263. linkOptions.AddFlag("GenerateWindowsMetadata", "false");
  3264. }
  3265. if (this->GlobalGenerator->TargetsWindowsPhone() &&
  3266. this->GlobalGenerator->GetSystemVersion() == "8.0") {
  3267. // WindowsPhone 8.0 does not have ole32.
  3268. linkOptions.AppendFlag("IgnoreSpecificDefaultLibraries", "ole32.lib");
  3269. }
  3270. } else if (this->NsightTegra) {
  3271. linkOptions.AddFlag("SoName", targetNames.SharedObject);
  3272. }
  3273. linkOptions.Parse(flags);
  3274. linkOptions.FixManifestUACFlags();
  3275. if (this->MSTools) {
  3276. cmGeneratorTarget::ModuleDefinitionInfo const* mdi =
  3277. this->GeneratorTarget->GetModuleDefinitionInfo(config);
  3278. if (mdi && !mdi->DefFile.empty()) {
  3279. linkOptions.AddFlag("ModuleDefinitionFile", mdi->DefFile);
  3280. }
  3281. linkOptions.AppendFlag("IgnoreSpecificDefaultLibraries",
  3282. "%(IgnoreSpecificDefaultLibraries)");
  3283. }
  3284. // VS 2015 without all updates has a v140 toolset whose
  3285. // GenerateDebugInformation expects No/Debug instead of false/true.
  3286. if (gg->GetPlatformToolsetNeedsDebugEnum()) {
  3287. if (const char* debug = linkOptions.GetFlag("GenerateDebugInformation")) {
  3288. if (strcmp(debug, "false") == 0) {
  3289. linkOptions.AddFlag("GenerateDebugInformation", "No");
  3290. } else if (strcmp(debug, "true") == 0) {
  3291. linkOptions.AddFlag("GenerateDebugInformation", "Debug");
  3292. }
  3293. }
  3294. }
  3295. // Managed code cannot be linked with /DEBUG:FASTLINK
  3296. if (this->Managed) {
  3297. if (const char* debug = linkOptions.GetFlag("GenerateDebugInformation")) {
  3298. if (strcmp(debug, "DebugFastLink") == 0) {
  3299. linkOptions.AddFlag("GenerateDebugInformation", "Debug");
  3300. }
  3301. }
  3302. }
  3303. this->LinkOptions[config] = std::move(pOptions);
  3304. return true;
  3305. }
  3306. bool cmVisualStudio10TargetGenerator::ComputeLibOptions()
  3307. {
  3308. if (this->GeneratorTarget->GetType() == cmStateEnums::STATIC_LIBRARY) {
  3309. for (std::string const& c : this->Configurations) {
  3310. if (!this->ComputeLibOptions(c)) {
  3311. return false;
  3312. }
  3313. }
  3314. }
  3315. return true;
  3316. }
  3317. bool cmVisualStudio10TargetGenerator::ComputeLibOptions(
  3318. std::string const& config)
  3319. {
  3320. cmComputeLinkInformation* pcli =
  3321. this->GeneratorTarget->GetLinkInformation(config);
  3322. if (!pcli) {
  3323. cmSystemTools::Error(
  3324. "CMake can not compute cmComputeLinkInformation for target: " +
  3325. this->Name);
  3326. return false;
  3327. }
  3328. cmComputeLinkInformation& cli = *pcli;
  3329. typedef cmComputeLinkInformation::ItemVector ItemVector;
  3330. const ItemVector& libs = cli.GetItems();
  3331. std::string currentBinDir =
  3332. this->LocalGenerator->GetCurrentBinaryDirectory();
  3333. for (cmComputeLinkInformation::Item const& l : libs) {
  3334. if (l.IsPath && cmVS10IsTargetsFile(l.Value)) {
  3335. std::string path = this->LocalGenerator->MaybeConvertToRelativePath(
  3336. currentBinDir, l.Value);
  3337. ConvertToWindowsSlash(path);
  3338. this->AddTargetsFileAndConfigPair(path, config);
  3339. }
  3340. }
  3341. return true;
  3342. }
  3343. void cmVisualStudio10TargetGenerator::WriteLinkOptions(
  3344. Elem& e1, std::string const& config)
  3345. {
  3346. if (this->GeneratorTarget->GetType() == cmStateEnums::STATIC_LIBRARY ||
  3347. this->GeneratorTarget->GetType() > cmStateEnums::MODULE_LIBRARY) {
  3348. return;
  3349. }
  3350. if (this->ProjectType == csproj) {
  3351. return;
  3352. }
  3353. {
  3354. Elem e2(e1, "Link");
  3355. OptionsHelper linkOptions(*(this->LinkOptions[config]), e2);
  3356. linkOptions.PrependInheritedString("AdditionalOptions");
  3357. linkOptions.OutputFlagMap();
  3358. }
  3359. if (!this->GlobalGenerator->NeedLinkLibraryDependencies(
  3360. this->GeneratorTarget)) {
  3361. Elem e2(e1, "ProjectReference");
  3362. e2.Element("LinkLibraryDependencies", "false");
  3363. }
  3364. }
  3365. void cmVisualStudio10TargetGenerator::AddLibraries(
  3366. const cmComputeLinkInformation& cli, std::vector<std::string>& libVec,
  3367. std::vector<std::string>& vsTargetVec, const std::string& config)
  3368. {
  3369. typedef cmComputeLinkInformation::ItemVector ItemVector;
  3370. ItemVector const& libs = cli.GetItems();
  3371. std::string currentBinDir =
  3372. this->LocalGenerator->GetCurrentBinaryDirectory();
  3373. for (cmComputeLinkInformation::Item const& l : libs) {
  3374. if (l.Target) {
  3375. auto managedType = l.Target->GetManagedType(config);
  3376. if (managedType != cmGeneratorTarget::ManagedType::Native &&
  3377. this->GeneratorTarget->GetManagedType(config) !=
  3378. cmGeneratorTarget::ManagedType::Native &&
  3379. l.Target->IsImported()) {
  3380. auto location = l.Target->GetFullPath(config);
  3381. if (!location.empty()) {
  3382. ConvertToWindowsSlash(location);
  3383. switch (this->ProjectType) {
  3384. case csproj:
  3385. // If the target we want to "link" to is an imported managed
  3386. // target and this is a C# project, we add a hint reference. This
  3387. // reference is written to project file in
  3388. // WriteDotNetReferences().
  3389. this->DotNetHintReferences[config].push_back(
  3390. DotNetHintReference(l.Target->GetName(), location));
  3391. break;
  3392. case vcxproj:
  3393. // Add path of assembly to list of using-directories, so the
  3394. // managed assembly can be used by '#using <assembly.dll>' in
  3395. // code.
  3396. this->AdditionalUsingDirectories[config].insert(
  3397. cmSystemTools::GetFilenamePath(location));
  3398. break;
  3399. }
  3400. }
  3401. }
  3402. // Do not allow C# targets to be added to the LIB listing. LIB files are
  3403. // used for linking C++ dependencies. C# libraries do not have lib files.
  3404. // Instead, they compile down to C# reference libraries (DLL files). The
  3405. // `<ProjectReference>` elements added to the vcxproj are enough for the
  3406. // IDE to deduce the DLL file required by other C# projects that need its
  3407. // reference library.
  3408. if (managedType == cmGeneratorTarget::ManagedType::Managed) {
  3409. continue;
  3410. }
  3411. }
  3412. if (l.IsPath) {
  3413. std::string path = this->LocalGenerator->MaybeConvertToRelativePath(
  3414. currentBinDir, l.Value);
  3415. ConvertToWindowsSlash(path);
  3416. if (cmVS10IsTargetsFile(l.Value)) {
  3417. vsTargetVec.push_back(path);
  3418. } else {
  3419. libVec.push_back(path);
  3420. }
  3421. } else if (!l.Target ||
  3422. l.Target->GetType() != cmStateEnums::INTERFACE_LIBRARY) {
  3423. libVec.push_back(l.Value);
  3424. }
  3425. }
  3426. }
  3427. void cmVisualStudio10TargetGenerator::AddTargetsFileAndConfigPair(
  3428. std::string const& targetsFile, std::string const& config)
  3429. {
  3430. for (TargetsFileAndConfigs& i : this->TargetsFileAndConfigsVec) {
  3431. if (cmSystemTools::ComparePath(targetsFile, i.File)) {
  3432. if (std::find(i.Configs.begin(), i.Configs.end(), config) ==
  3433. i.Configs.end()) {
  3434. i.Configs.push_back(config);
  3435. }
  3436. return;
  3437. }
  3438. }
  3439. TargetsFileAndConfigs entry;
  3440. entry.File = targetsFile;
  3441. entry.Configs.push_back(config);
  3442. this->TargetsFileAndConfigsVec.push_back(entry);
  3443. }
  3444. void cmVisualStudio10TargetGenerator::WriteMidlOptions(
  3445. Elem& e1, std::string const& configName)
  3446. {
  3447. if (!this->MSTools) {
  3448. return;
  3449. }
  3450. if (this->ProjectType == csproj) {
  3451. return;
  3452. }
  3453. // This processes *any* of the .idl files specified in the project's file
  3454. // list (and passed as the item metadata %(Filename) expressing the rule
  3455. // input filename) into output files at the per-config *build* dir
  3456. // ($(IntDir)) each.
  3457. //
  3458. // IOW, this MIDL section is intended to provide a fully generic syntax
  3459. // content suitable for most cases (read: if you get errors, then it's quite
  3460. // probable that the error is on your side of the .idl setup).
  3461. //
  3462. // Also, note that the marked-as-generated _i.c file in the Visual Studio
  3463. // generator case needs to be referred to as $(IntDir)\foo_i.c at the
  3464. // project's file list, otherwise the compiler-side processing won't pick it
  3465. // up (for non-directory form, it ends up looking in project binary dir
  3466. // only). Perhaps there's something to be done to make this more automatic
  3467. // on the CMake side?
  3468. std::vector<std::string> const includes =
  3469. this->GetIncludes(configName, "MIDL");
  3470. std::ostringstream oss;
  3471. for (std::string const& i : includes) {
  3472. oss << i << ";";
  3473. }
  3474. oss << "%(AdditionalIncludeDirectories)";
  3475. Elem e2(e1, "Midl");
  3476. e2.Element("AdditionalIncludeDirectories", oss.str());
  3477. e2.Element("OutputDirectory", "$(ProjectDir)/$(IntDir)");
  3478. e2.Element("HeaderFileName", "%(Filename).h");
  3479. e2.Element("TypeLibraryName", "%(Filename).tlb");
  3480. e2.Element("InterfaceIdentifierFileName", "%(Filename)_i.c");
  3481. e2.Element("ProxyFileName", "%(Filename)_p.c");
  3482. }
  3483. void cmVisualStudio10TargetGenerator::WriteItemDefinitionGroups(Elem& e0)
  3484. {
  3485. if (this->ProjectType == csproj) {
  3486. return;
  3487. }
  3488. for (const std::string& c : this->Configurations) {
  3489. Elem e1(e0, "ItemDefinitionGroup");
  3490. e1.Attribute("Condition", this->CalcCondition(c));
  3491. // output cl compile flags <ClCompile></ClCompile>
  3492. if (this->GeneratorTarget->GetType() <= cmStateEnums::OBJECT_LIBRARY) {
  3493. this->WriteClOptions(e1, c);
  3494. // output rc compile flags <ResourceCompile></ResourceCompile>
  3495. this->WriteRCOptions(e1, c);
  3496. this->WriteCudaOptions(e1, c);
  3497. this->WriteMasmOptions(e1, c);
  3498. this->WriteNasmOptions(e1, c);
  3499. }
  3500. // output midl flags <Midl></Midl>
  3501. this->WriteMidlOptions(e1, c);
  3502. // write events
  3503. if (this->ProjectType != csproj) {
  3504. this->WriteEvents(e1, c);
  3505. }
  3506. // output link flags <Link></Link>
  3507. this->WriteLinkOptions(e1, c);
  3508. this->WriteCudaLinkOptions(e1, c);
  3509. // output lib flags <Lib></Lib>
  3510. this->WriteLibOptions(e1, c);
  3511. // output manifest flags <Manifest></Manifest>
  3512. this->WriteManifestOptions(e1, c);
  3513. if (this->NsightTegra &&
  3514. this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE &&
  3515. this->GeneratorTarget->GetPropertyAsBool("ANDROID_GUI")) {
  3516. this->WriteAntBuildOptions(e1, c);
  3517. }
  3518. }
  3519. }
  3520. void cmVisualStudio10TargetGenerator::WriteEvents(
  3521. Elem& e1, std::string const& configName)
  3522. {
  3523. bool addedPrelink = false;
  3524. cmGeneratorTarget::ModuleDefinitionInfo const* mdi =
  3525. this->GeneratorTarget->GetModuleDefinitionInfo(configName);
  3526. if (mdi && mdi->DefFileGenerated) {
  3527. addedPrelink = true;
  3528. std::vector<cmCustomCommand> commands =
  3529. this->GeneratorTarget->GetPreLinkCommands();
  3530. this->GlobalGenerator->AddSymbolExportCommand(this->GeneratorTarget,
  3531. commands, configName);
  3532. this->WriteEvent(e1, "PreLinkEvent", commands, configName);
  3533. }
  3534. if (!addedPrelink) {
  3535. this->WriteEvent(e1, "PreLinkEvent",
  3536. this->GeneratorTarget->GetPreLinkCommands(), configName);
  3537. }
  3538. this->WriteEvent(e1, "PreBuildEvent",
  3539. this->GeneratorTarget->GetPreBuildCommands(), configName);
  3540. this->WriteEvent(e1, "PostBuildEvent",
  3541. this->GeneratorTarget->GetPostBuildCommands(), configName);
  3542. }
  3543. void cmVisualStudio10TargetGenerator::WriteEvent(
  3544. Elem& e1, const char* name, std::vector<cmCustomCommand> const& commands,
  3545. std::string const& configName)
  3546. {
  3547. if (commands.empty()) {
  3548. return;
  3549. }
  3550. cmLocalVisualStudio7Generator* lg = this->LocalGenerator;
  3551. std::string script;
  3552. const char* pre = "";
  3553. std::string comment;
  3554. for (cmCustomCommand const& cc : commands) {
  3555. cmCustomCommandGenerator ccg(cc, configName, lg);
  3556. if (!ccg.HasOnlyEmptyCommandLines()) {
  3557. comment += pre;
  3558. comment += lg->ConstructComment(ccg);
  3559. script += pre;
  3560. pre = "\n";
  3561. script += lg->ConstructScript(ccg);
  3562. }
  3563. }
  3564. comment = cmVS10EscapeComment(comment);
  3565. if (this->ProjectType != csproj) {
  3566. Elem e2(e1, name);
  3567. e2.Element("Message", comment);
  3568. e2.Element("Command", script);
  3569. } else {
  3570. std::string strippedComment = comment;
  3571. strippedComment.erase(
  3572. std::remove(strippedComment.begin(), strippedComment.end(), '\t'),
  3573. strippedComment.end());
  3574. std::ostringstream oss;
  3575. if (!comment.empty() && !strippedComment.empty()) {
  3576. oss << "echo " << comment << "\n";
  3577. }
  3578. oss << script << "\n";
  3579. e1.Element(name, oss.str());
  3580. }
  3581. }
  3582. void cmVisualStudio10TargetGenerator::WriteProjectReferences(Elem& e0)
  3583. {
  3584. cmGlobalGenerator::TargetDependSet const& unordered =
  3585. this->GlobalGenerator->GetTargetDirectDepends(this->GeneratorTarget);
  3586. typedef cmGlobalVisualStudioGenerator::OrderedTargetDependSet
  3587. OrderedTargetDependSet;
  3588. OrderedTargetDependSet depends(unordered, CMAKE_CHECK_BUILD_SYSTEM_TARGET);
  3589. Elem e1(e0, "ItemGroup");
  3590. e1.SetHasElements();
  3591. for (cmGeneratorTarget const* dt : depends) {
  3592. if (dt->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
  3593. continue;
  3594. }
  3595. // skip fortran targets as they can not be processed by MSBuild
  3596. // the only reference will be in the .sln file
  3597. if (this->GlobalGenerator->TargetIsFortranOnly(dt)) {
  3598. continue;
  3599. }
  3600. cmLocalGenerator* lg = dt->GetLocalGenerator();
  3601. std::string name = dt->GetName();
  3602. std::string path;
  3603. const char* p = dt->GetProperty("EXTERNAL_MSPROJECT");
  3604. if (p) {
  3605. path = p;
  3606. } else {
  3607. path = lg->GetCurrentBinaryDirectory();
  3608. path += "/";
  3609. path += dt->GetName();
  3610. path += computeProjectFileExtension(dt);
  3611. }
  3612. ConvertToWindowsSlash(path);
  3613. Elem e2(e1, "ProjectReference");
  3614. e2.Attribute("Include", path);
  3615. e2.Element("Project", "{" + this->GlobalGenerator->GetGUID(name) + "}");
  3616. e2.Element("Name", name);
  3617. this->WriteDotNetReferenceCustomTags(e2, name);
  3618. // If the dependency target is not managed (compiled with /clr or
  3619. // C# target) and not a WinRT component we cannot reference it and
  3620. // have to set 'ReferenceOutputAssembly' to false.
  3621. auto referenceNotManaged =
  3622. dt->GetManagedType("") < cmGeneratorTarget::ManagedType::Mixed;
  3623. // Workaround to check for manually set /clr flags.
  3624. if (referenceNotManaged) {
  3625. if (const auto* flags = dt->GetProperty("COMPILE_OPTIONS")) {
  3626. std::string flagsStr = flags;
  3627. if (flagsStr.find("clr") != std::string::npos) {
  3628. // There is a warning already issued when building the flags.
  3629. referenceNotManaged = false;
  3630. }
  3631. }
  3632. }
  3633. // Workaround for static library C# targets
  3634. if (referenceNotManaged && dt->GetType() == cmStateEnums::STATIC_LIBRARY) {
  3635. referenceNotManaged = !dt->IsCSharpOnly();
  3636. }
  3637. // Referencing WinRT components is okay.
  3638. if (referenceNotManaged) {
  3639. referenceNotManaged = !dt->GetPropertyAsBool("VS_WINRT_COMPONENT");
  3640. }
  3641. if (referenceNotManaged) {
  3642. e2.Element("ReferenceOutputAssembly", "false");
  3643. e2.Element("CopyToOutputDirectory", "Never");
  3644. }
  3645. }
  3646. }
  3647. void cmVisualStudio10TargetGenerator::WritePlatformExtensions(Elem& e1)
  3648. {
  3649. // This only applies to Windows 10 apps
  3650. if (this->GlobalGenerator->TargetsWindowsStore() &&
  3651. cmHasLiteralPrefix(this->GlobalGenerator->GetSystemVersion(), "10.0")) {
  3652. const char* desktopExtensionsVersion =
  3653. this->GeneratorTarget->GetProperty("VS_DESKTOP_EXTENSIONS_VERSION");
  3654. if (desktopExtensionsVersion) {
  3655. this->WriteSinglePlatformExtension(e1, "WindowsDesktop",
  3656. desktopExtensionsVersion);
  3657. }
  3658. const char* mobileExtensionsVersion =
  3659. this->GeneratorTarget->GetProperty("VS_MOBILE_EXTENSIONS_VERSION");
  3660. if (mobileExtensionsVersion) {
  3661. this->WriteSinglePlatformExtension(e1, "WindowsMobile",
  3662. mobileExtensionsVersion);
  3663. }
  3664. }
  3665. }
  3666. void cmVisualStudio10TargetGenerator::WriteSinglePlatformExtension(
  3667. Elem& e1, std::string const& extension, std::string const& version)
  3668. {
  3669. const std::string s = "$([Microsoft.Build.Utilities.ToolLocationHelper]"
  3670. "::GetPlatformExtensionSDKLocation(`" +
  3671. extension + ", Version=" + version +
  3672. "`, $(TargetPlatformIdentifier), $(TargetPlatformVersion), null, "
  3673. "$(ExtensionSDKDirectoryRoot), null))"
  3674. "\\DesignTime\\CommonConfiguration\\Neutral\\" +
  3675. extension + ".props";
  3676. Elem e2(e1, "Import");
  3677. e2.Attribute("Project", s);
  3678. e2.Attribute("Condition", "exists('" + s + "')");
  3679. }
  3680. void cmVisualStudio10TargetGenerator::WriteSDKReferences(Elem& e0)
  3681. {
  3682. std::vector<std::string> sdkReferences;
  3683. std::unique_ptr<Elem> spe1;
  3684. if (const char* vsSDKReferences =
  3685. this->GeneratorTarget->GetProperty("VS_SDK_REFERENCES")) {
  3686. cmSystemTools::ExpandListArgument(vsSDKReferences, sdkReferences);
  3687. spe1 = cm::make_unique<Elem>(e0, "ItemGroup");
  3688. for (std::string const& ri : sdkReferences) {
  3689. Elem(*spe1, "SDKReference").Attribute("Include", ri);
  3690. }
  3691. }
  3692. // This only applies to Windows 10 apps
  3693. if (this->GlobalGenerator->TargetsWindowsStore() &&
  3694. cmHasLiteralPrefix(this->GlobalGenerator->GetSystemVersion(), "10.0")) {
  3695. const char* desktopExtensionsVersion =
  3696. this->GeneratorTarget->GetProperty("VS_DESKTOP_EXTENSIONS_VERSION");
  3697. const char* mobileExtensionsVersion =
  3698. this->GeneratorTarget->GetProperty("VS_MOBILE_EXTENSIONS_VERSION");
  3699. const char* iotExtensionsVersion =
  3700. this->GeneratorTarget->GetProperty("VS_IOT_EXTENSIONS_VERSION");
  3701. if (desktopExtensionsVersion || mobileExtensionsVersion ||
  3702. iotExtensionsVersion) {
  3703. if (!spe1) {
  3704. spe1 = cm::make_unique<Elem>(e0, "ItemGroup");
  3705. }
  3706. if (desktopExtensionsVersion) {
  3707. this->WriteSingleSDKReference(*spe1, "WindowsDesktop",
  3708. desktopExtensionsVersion);
  3709. }
  3710. if (mobileExtensionsVersion) {
  3711. this->WriteSingleSDKReference(*spe1, "WindowsMobile",
  3712. mobileExtensionsVersion);
  3713. }
  3714. if (iotExtensionsVersion) {
  3715. this->WriteSingleSDKReference(*spe1, "WindowsIoT",
  3716. iotExtensionsVersion);
  3717. }
  3718. }
  3719. }
  3720. }
  3721. void cmVisualStudio10TargetGenerator::WriteSingleSDKReference(
  3722. Elem& e1, std::string const& extension, std::string const& version)
  3723. {
  3724. Elem(e1, "SDKReference")
  3725. .Attribute("Include", extension + ", Version=" + version);
  3726. }
  3727. void cmVisualStudio10TargetGenerator::WriteWinRTPackageCertificateKeyFile(
  3728. Elem& e0)
  3729. {
  3730. if ((this->GlobalGenerator->TargetsWindowsStore() ||
  3731. this->GlobalGenerator->TargetsWindowsPhone()) &&
  3732. (cmStateEnums::EXECUTABLE == this->GeneratorTarget->GetType())) {
  3733. std::string pfxFile;
  3734. std::vector<cmSourceFile const*> certificates;
  3735. this->GeneratorTarget->GetCertificates(certificates, "");
  3736. for (cmSourceFile const* si : certificates) {
  3737. pfxFile = this->ConvertPath(si->GetFullPath(), false);
  3738. ConvertToWindowsSlash(pfxFile);
  3739. break;
  3740. }
  3741. if (this->IsMissingFiles &&
  3742. !(this->GlobalGenerator->TargetsWindowsPhone() &&
  3743. this->GlobalGenerator->GetSystemVersion() == "8.0")) {
  3744. // Move the manifest to a project directory to avoid clashes
  3745. std::string artifactDir =
  3746. this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
  3747. ConvertToWindowsSlash(artifactDir);
  3748. Elem e1(e0, "PropertyGroup");
  3749. e1.Element("AppxPackageArtifactsDir", artifactDir + "\\");
  3750. std::string resourcePriFile =
  3751. this->DefaultArtifactDir + "/resources.pri";
  3752. ConvertToWindowsSlash(resourcePriFile);
  3753. e1.Element("ProjectPriFullPath", resourcePriFile);
  3754. // If we are missing files and we don't have a certificate and
  3755. // aren't targeting WP8.0, add a default certificate
  3756. if (pfxFile.empty()) {
  3757. std::string templateFolder =
  3758. cmSystemTools::GetCMakeRoot() + "/Templates/Windows";
  3759. pfxFile = this->DefaultArtifactDir + "/Windows_TemporaryKey.pfx";
  3760. cmSystemTools::CopyAFile(templateFolder + "/Windows_TemporaryKey.pfx",
  3761. pfxFile, false);
  3762. ConvertToWindowsSlash(pfxFile);
  3763. this->AddedFiles.push_back(pfxFile);
  3764. this->AddedDefaultCertificate = true;
  3765. }
  3766. e1.Element("PackageCertificateKeyFile", pfxFile);
  3767. std::string thumb = cmSystemTools::ComputeCertificateThumbprint(pfxFile);
  3768. if (!thumb.empty()) {
  3769. e1.Element("PackageCertificateThumbprint", thumb);
  3770. }
  3771. } else if (!pfxFile.empty()) {
  3772. Elem e1(e0, "PropertyGroup");
  3773. e1.Element("PackageCertificateKeyFile", pfxFile);
  3774. std::string thumb = cmSystemTools::ComputeCertificateThumbprint(pfxFile);
  3775. if (!thumb.empty()) {
  3776. e1.Element("PackageCertificateThumbprint", thumb);
  3777. }
  3778. }
  3779. }
  3780. }
  3781. bool cmVisualStudio10TargetGenerator::IsResxHeader(
  3782. const std::string& headerFile)
  3783. {
  3784. std::set<std::string> expectedResxHeaders;
  3785. this->GeneratorTarget->GetExpectedResxHeaders(expectedResxHeaders, "");
  3786. return expectedResxHeaders.count(headerFile) > 0;
  3787. }
  3788. bool cmVisualStudio10TargetGenerator::IsXamlHeader(
  3789. const std::string& headerFile)
  3790. {
  3791. std::set<std::string> expectedXamlHeaders;
  3792. this->GeneratorTarget->GetExpectedXamlHeaders(expectedXamlHeaders, "");
  3793. return expectedXamlHeaders.count(headerFile) > 0;
  3794. }
  3795. bool cmVisualStudio10TargetGenerator::IsXamlSource(
  3796. const std::string& sourceFile)
  3797. {
  3798. std::set<std::string> expectedXamlSources;
  3799. this->GeneratorTarget->GetExpectedXamlSources(expectedXamlSources, "");
  3800. return expectedXamlSources.count(sourceFile) > 0;
  3801. }
  3802. void cmVisualStudio10TargetGenerator::WriteApplicationTypeSettings(Elem& e1)
  3803. {
  3804. cmGlobalVisualStudio10Generator* gg = this->GlobalGenerator;
  3805. bool isAppContainer = false;
  3806. bool const isWindowsPhone = this->GlobalGenerator->TargetsWindowsPhone();
  3807. bool const isWindowsStore = this->GlobalGenerator->TargetsWindowsStore();
  3808. std::string const& rev = this->GlobalGenerator->GetApplicationTypeRevision();
  3809. if (isWindowsPhone || isWindowsStore) {
  3810. e1.Element("ApplicationType",
  3811. (isWindowsPhone ? "Windows Phone" : "Windows Store"));
  3812. e1.Element("DefaultLanguage", "en-US");
  3813. if (rev == "10.0") {
  3814. e1.Element("ApplicationTypeRevision", rev);
  3815. // Visual Studio 14.0 is necessary for building 10.0 apps
  3816. e1.Element("MinimumVisualStudioVersion", "14.0");
  3817. if (this->GeneratorTarget->GetType() < cmStateEnums::UTILITY) {
  3818. isAppContainer = true;
  3819. }
  3820. } else if (rev == "8.1") {
  3821. e1.Element("ApplicationTypeRevision", rev);
  3822. // Visual Studio 12.0 is necessary for building 8.1 apps
  3823. e1.Element("MinimumVisualStudioVersion", "12.0");
  3824. if (this->GeneratorTarget->GetType() < cmStateEnums::UTILITY) {
  3825. isAppContainer = true;
  3826. }
  3827. } else if (rev == "8.0") {
  3828. e1.Element("ApplicationTypeRevision", rev);
  3829. // Visual Studio 11.0 is necessary for building 8.0 apps
  3830. e1.Element("MinimumVisualStudioVersion", "11.0");
  3831. if (isWindowsStore &&
  3832. this->GeneratorTarget->GetType() < cmStateEnums::UTILITY) {
  3833. isAppContainer = true;
  3834. } else if (isWindowsPhone &&
  3835. this->GeneratorTarget->GetType() ==
  3836. cmStateEnums::EXECUTABLE) {
  3837. e1.Element("XapOutputs", "true");
  3838. e1.Element("XapFilename",
  3839. this->Name + "_$(Configuration)_$(Platform).xap");
  3840. }
  3841. }
  3842. }
  3843. if (isAppContainer) {
  3844. e1.Element("AppContainerApplication", "true");
  3845. } else if (this->Platform == "ARM64") {
  3846. e1.Element("WindowsSDKDesktopARM64Support", "true");
  3847. } else if (this->Platform == "ARM") {
  3848. e1.Element("WindowsSDKDesktopARMSupport", "true");
  3849. }
  3850. std::string const& targetPlatformVersion =
  3851. gg->GetWindowsTargetPlatformVersion();
  3852. if (!targetPlatformVersion.empty()) {
  3853. e1.Element("WindowsTargetPlatformVersion", targetPlatformVersion);
  3854. }
  3855. const char* targetPlatformMinVersion = this->GeneratorTarget->GetProperty(
  3856. "VS_WINDOWS_TARGET_PLATFORM_MIN_VERSION");
  3857. if (targetPlatformMinVersion) {
  3858. e1.Element("WindowsTargetPlatformMinVersion", targetPlatformMinVersion);
  3859. } else if (isWindowsStore && rev == "10.0") {
  3860. // If the min version is not set, then use the TargetPlatformVersion
  3861. if (!targetPlatformVersion.empty()) {
  3862. e1.Element("WindowsTargetPlatformMinVersion", targetPlatformVersion);
  3863. }
  3864. }
  3865. // Added IoT Startup Task support
  3866. if (this->GeneratorTarget->GetPropertyAsBool("VS_IOT_STARTUP_TASK")) {
  3867. e1.Element("ContainsStartupTask", "true");
  3868. }
  3869. }
  3870. void cmVisualStudio10TargetGenerator::VerifyNecessaryFiles()
  3871. {
  3872. // For Windows and Windows Phone executables, we will assume that if a
  3873. // manifest is not present that we need to add all the necessary files
  3874. if (this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE) {
  3875. std::vector<cmSourceFile const*> manifestSources;
  3876. this->GeneratorTarget->GetAppManifest(manifestSources, "");
  3877. {
  3878. std::string const& v = this->GlobalGenerator->GetSystemVersion();
  3879. if (this->GlobalGenerator->TargetsWindowsPhone()) {
  3880. if (v == "8.0") {
  3881. // Look through the sources for WMAppManifest.xml
  3882. std::vector<cmSourceFile const*> extraSources;
  3883. this->GeneratorTarget->GetExtraSources(extraSources, "");
  3884. bool foundManifest = false;
  3885. for (cmSourceFile const* si : extraSources) {
  3886. // Need to do a lowercase comparison on the filename
  3887. if ("wmappmanifest.xml" ==
  3888. cmSystemTools::LowerCase(si->GetLocation().GetName())) {
  3889. foundManifest = true;
  3890. break;
  3891. }
  3892. }
  3893. if (!foundManifest) {
  3894. this->IsMissingFiles = true;
  3895. }
  3896. } else if (v == "8.1") {
  3897. if (manifestSources.empty()) {
  3898. this->IsMissingFiles = true;
  3899. }
  3900. }
  3901. } else if (this->GlobalGenerator->TargetsWindowsStore()) {
  3902. if (manifestSources.empty()) {
  3903. if (v == "8.0") {
  3904. this->IsMissingFiles = true;
  3905. } else if (v == "8.1" || cmHasLiteralPrefix(v, "10.0")) {
  3906. this->IsMissingFiles = true;
  3907. }
  3908. }
  3909. }
  3910. }
  3911. }
  3912. }
  3913. void cmVisualStudio10TargetGenerator::WriteMissingFiles(Elem& e1)
  3914. {
  3915. std::string const& v = this->GlobalGenerator->GetSystemVersion();
  3916. if (this->GlobalGenerator->TargetsWindowsPhone()) {
  3917. if (v == "8.0") {
  3918. this->WriteMissingFilesWP80(e1);
  3919. } else if (v == "8.1") {
  3920. this->WriteMissingFilesWP81(e1);
  3921. }
  3922. } else if (this->GlobalGenerator->TargetsWindowsStore()) {
  3923. if (v == "8.0") {
  3924. this->WriteMissingFilesWS80(e1);
  3925. } else if (v == "8.1") {
  3926. this->WriteMissingFilesWS81(e1);
  3927. } else if (cmHasLiteralPrefix(v, "10.0")) {
  3928. this->WriteMissingFilesWS10_0(e1);
  3929. }
  3930. }
  3931. }
  3932. void cmVisualStudio10TargetGenerator::WriteMissingFilesWP80(Elem& e1)
  3933. {
  3934. std::string templateFolder =
  3935. cmSystemTools::GetCMakeRoot() + "/Templates/Windows";
  3936. // For WP80, the manifest needs to be in the same folder as the project
  3937. // this can cause an overwrite problem if projects aren't organized in
  3938. // folders
  3939. std::string manifestFile =
  3940. this->LocalGenerator->GetCurrentBinaryDirectory() + "/WMAppManifest.xml";
  3941. std::string artifactDir =
  3942. this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
  3943. ConvertToWindowsSlash(artifactDir);
  3944. std::string artifactDirXML = cmVS10EscapeXML(artifactDir);
  3945. std::string targetNameXML =
  3946. cmVS10EscapeXML(this->GeneratorTarget->GetName());
  3947. cmGeneratedFileStream fout(manifestFile);
  3948. fout.SetCopyIfDifferent(true);
  3949. /* clang-format off */
  3950. fout <<
  3951. "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
  3952. "<Deployment"
  3953. " xmlns=\"http://schemas.microsoft.com/windowsphone/2012/deployment\""
  3954. " AppPlatformVersion=\"8.0\">\n"
  3955. "\t<DefaultLanguage xmlns=\"\" code=\"en-US\"/>\n"
  3956. "\t<App xmlns=\"\" ProductID=\"{" << this->GUID << "}\""
  3957. " Title=\"CMake Test Program\" RuntimeType=\"Modern Native\""
  3958. " Version=\"1.0.0.0\" Genre=\"apps.normal\" Author=\"CMake\""
  3959. " Description=\"Default CMake App\" Publisher=\"CMake\""
  3960. " PublisherID=\"{" << this->GUID << "}\">\n"
  3961. "\t\t<IconPath IsRelative=\"true\" IsResource=\"false\">"
  3962. << artifactDirXML << "\\ApplicationIcon.png</IconPath>\n"
  3963. "\t\t<Capabilities/>\n"
  3964. "\t\t<Tasks>\n"
  3965. "\t\t\t<DefaultTask Name=\"_default\""
  3966. " ImagePath=\"" << targetNameXML << ".exe\" ImageParams=\"\" />\n"
  3967. "\t\t</Tasks>\n"
  3968. "\t\t<Tokens>\n"
  3969. "\t\t\t<PrimaryToken TokenID=\"" << targetNameXML << "Token\""
  3970. " TaskName=\"_default\">\n"
  3971. "\t\t\t\t<TemplateFlip>\n"
  3972. "\t\t\t\t\t<SmallImageURI IsRelative=\"true\" IsResource=\"false\">"
  3973. << artifactDirXML << "\\SmallLogo.png</SmallImageURI>\n"
  3974. "\t\t\t\t\t<Count>0</Count>\n"
  3975. "\t\t\t\t\t<BackgroundImageURI IsRelative=\"true\" IsResource=\"false\">"
  3976. << artifactDirXML << "\\Logo.png</BackgroundImageURI>\n"
  3977. "\t\t\t\t</TemplateFlip>\n"
  3978. "\t\t\t</PrimaryToken>\n"
  3979. "\t\t</Tokens>\n"
  3980. "\t\t<ScreenResolutions>\n"
  3981. "\t\t\t<ScreenResolution Name=\"ID_RESOLUTION_WVGA\" />\n"
  3982. "\t\t</ScreenResolutions>\n"
  3983. "\t</App>\n"
  3984. "</Deployment>\n";
  3985. /* clang-format on */
  3986. std::string sourceFile = this->ConvertPath(manifestFile, false);
  3987. ConvertToWindowsSlash(sourceFile);
  3988. {
  3989. Elem e2(e1, "Xml");
  3990. e2.Attribute("Include", sourceFile);
  3991. e2.Element("SubType", "Designer");
  3992. }
  3993. this->AddedFiles.push_back(sourceFile);
  3994. std::string smallLogo = this->DefaultArtifactDir + "/SmallLogo.png";
  3995. cmSystemTools::CopyAFile(templateFolder + "/SmallLogo.png", smallLogo,
  3996. false);
  3997. ConvertToWindowsSlash(smallLogo);
  3998. Elem(e1, "Image").Attribute("Include", smallLogo);
  3999. this->AddedFiles.push_back(smallLogo);
  4000. std::string logo = this->DefaultArtifactDir + "/Logo.png";
  4001. cmSystemTools::CopyAFile(templateFolder + "/Logo.png", logo, false);
  4002. ConvertToWindowsSlash(logo);
  4003. Elem(e1, "Image").Attribute("Include", logo);
  4004. this->AddedFiles.push_back(logo);
  4005. std::string applicationIcon =
  4006. this->DefaultArtifactDir + "/ApplicationIcon.png";
  4007. cmSystemTools::CopyAFile(templateFolder + "/ApplicationIcon.png",
  4008. applicationIcon, false);
  4009. ConvertToWindowsSlash(applicationIcon);
  4010. Elem(e1, "Image").Attribute("Include", applicationIcon);
  4011. this->AddedFiles.push_back(applicationIcon);
  4012. }
  4013. void cmVisualStudio10TargetGenerator::WriteMissingFilesWP81(Elem& e1)
  4014. {
  4015. std::string manifestFile =
  4016. this->DefaultArtifactDir + "/package.appxManifest";
  4017. std::string artifactDir =
  4018. this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
  4019. ConvertToWindowsSlash(artifactDir);
  4020. std::string artifactDirXML = cmVS10EscapeXML(artifactDir);
  4021. std::string targetNameXML =
  4022. cmVS10EscapeXML(this->GeneratorTarget->GetName());
  4023. cmGeneratedFileStream fout(manifestFile);
  4024. fout.SetCopyIfDifferent(true);
  4025. /* clang-format off */
  4026. fout <<
  4027. "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
  4028. "<Package xmlns=\"http://schemas.microsoft.com/appx/2010/manifest\""
  4029. " xmlns:m2=\"http://schemas.microsoft.com/appx/2013/manifest\""
  4030. " xmlns:mp=\"http://schemas.microsoft.com/appx/2014/phone/manifest\">\n"
  4031. "\t<Identity Name=\"" << this->GUID << "\" Publisher=\"CN=CMake\""
  4032. " Version=\"1.0.0.0\" />\n"
  4033. "\t<mp:PhoneIdentity PhoneProductId=\"" << this->GUID << "\""
  4034. " PhonePublisherId=\"00000000-0000-0000-0000-000000000000\"/>\n"
  4035. "\t<Properties>\n"
  4036. "\t\t<DisplayName>" << targetNameXML << "</DisplayName>\n"
  4037. "\t\t<PublisherDisplayName>CMake</PublisherDisplayName>\n"
  4038. "\t\t<Logo>" << artifactDirXML << "\\StoreLogo.png</Logo>\n"
  4039. "\t</Properties>\n"
  4040. "\t<Prerequisites>\n"
  4041. "\t\t<OSMinVersion>6.3.1</OSMinVersion>\n"
  4042. "\t\t<OSMaxVersionTested>6.3.1</OSMaxVersionTested>\n"
  4043. "\t</Prerequisites>\n"
  4044. "\t<Resources>\n"
  4045. "\t\t<Resource Language=\"x-generate\" />\n"
  4046. "\t</Resources>\n"
  4047. "\t<Applications>\n"
  4048. "\t\t<Application Id=\"App\""
  4049. " Executable=\"" << targetNameXML << ".exe\""
  4050. " EntryPoint=\"" << targetNameXML << ".App\">\n"
  4051. "\t\t\t<m2:VisualElements\n"
  4052. "\t\t\t\tDisplayName=\"" << targetNameXML << "\"\n"
  4053. "\t\t\t\tDescription=\"" << targetNameXML << "\"\n"
  4054. "\t\t\t\tBackgroundColor=\"#336699\"\n"
  4055. "\t\t\t\tForegroundText=\"light\"\n"
  4056. "\t\t\t\tSquare150x150Logo=\"" << artifactDirXML << "\\Logo.png\"\n"
  4057. "\t\t\t\tSquare30x30Logo=\"" << artifactDirXML << "\\SmallLogo.png\">\n"
  4058. "\t\t\t\t<m2:DefaultTile ShortName=\"" << targetNameXML << "\">\n"
  4059. "\t\t\t\t\t<m2:ShowNameOnTiles>\n"
  4060. "\t\t\t\t\t\t<m2:ShowOn Tile=\"square150x150Logo\" />\n"
  4061. "\t\t\t\t\t</m2:ShowNameOnTiles>\n"
  4062. "\t\t\t\t</m2:DefaultTile>\n"
  4063. "\t\t\t\t<m2:SplashScreen"
  4064. " Image=\"" << artifactDirXML << "\\SplashScreen.png\" />\n"
  4065. "\t\t\t</m2:VisualElements>\n"
  4066. "\t\t</Application>\n"
  4067. "\t</Applications>\n"
  4068. "</Package>\n";
  4069. /* clang-format on */
  4070. this->WriteCommonMissingFiles(e1, manifestFile);
  4071. }
  4072. void cmVisualStudio10TargetGenerator::WriteMissingFilesWS80(Elem& e1)
  4073. {
  4074. std::string manifestFile =
  4075. this->DefaultArtifactDir + "/package.appxManifest";
  4076. std::string artifactDir =
  4077. this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
  4078. ConvertToWindowsSlash(artifactDir);
  4079. std::string artifactDirXML = cmVS10EscapeXML(artifactDir);
  4080. std::string targetNameXML =
  4081. cmVS10EscapeXML(this->GeneratorTarget->GetName());
  4082. cmGeneratedFileStream fout(manifestFile);
  4083. fout.SetCopyIfDifferent(true);
  4084. /* clang-format off */
  4085. fout <<
  4086. "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
  4087. "<Package xmlns=\"http://schemas.microsoft.com/appx/2010/manifest\">\n"
  4088. "\t<Identity Name=\"" << this->GUID << "\" Publisher=\"CN=CMake\""
  4089. " Version=\"1.0.0.0\" />\n"
  4090. "\t<Properties>\n"
  4091. "\t\t<DisplayName>" << targetNameXML << "</DisplayName>\n"
  4092. "\t\t<PublisherDisplayName>CMake</PublisherDisplayName>\n"
  4093. "\t\t<Logo>" << artifactDirXML << "\\StoreLogo.png</Logo>\n"
  4094. "\t</Properties>\n"
  4095. "\t<Prerequisites>\n"
  4096. "\t\t<OSMinVersion>6.2.1</OSMinVersion>\n"
  4097. "\t\t<OSMaxVersionTested>6.2.1</OSMaxVersionTested>\n"
  4098. "\t</Prerequisites>\n"
  4099. "\t<Resources>\n"
  4100. "\t\t<Resource Language=\"x-generate\" />\n"
  4101. "\t</Resources>\n"
  4102. "\t<Applications>\n"
  4103. "\t\t<Application Id=\"App\""
  4104. " Executable=\"" << targetNameXML << ".exe\""
  4105. " EntryPoint=\"" << targetNameXML << ".App\">\n"
  4106. "\t\t\t<VisualElements"
  4107. " DisplayName=\"" << targetNameXML << "\""
  4108. " Description=\"" << targetNameXML << "\""
  4109. " BackgroundColor=\"#336699\" ForegroundText=\"light\""
  4110. " Logo=\"" << artifactDirXML << "\\Logo.png\""
  4111. " SmallLogo=\"" << artifactDirXML << "\\SmallLogo.png\">\n"
  4112. "\t\t\t\t<DefaultTile ShowName=\"allLogos\""
  4113. " ShortName=\"" << targetNameXML << "\" />\n"
  4114. "\t\t\t\t<SplashScreen"
  4115. " Image=\"" << artifactDirXML << "\\SplashScreen.png\" />\n"
  4116. "\t\t\t</VisualElements>\n"
  4117. "\t\t</Application>\n"
  4118. "\t</Applications>\n"
  4119. "</Package>\n";
  4120. /* clang-format on */
  4121. this->WriteCommonMissingFiles(e1, manifestFile);
  4122. }
  4123. void cmVisualStudio10TargetGenerator::WriteMissingFilesWS81(Elem& e1)
  4124. {
  4125. std::string manifestFile =
  4126. this->DefaultArtifactDir + "/package.appxManifest";
  4127. std::string artifactDir =
  4128. this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
  4129. ConvertToWindowsSlash(artifactDir);
  4130. std::string artifactDirXML = cmVS10EscapeXML(artifactDir);
  4131. std::string targetNameXML =
  4132. cmVS10EscapeXML(this->GeneratorTarget->GetName());
  4133. cmGeneratedFileStream fout(manifestFile);
  4134. fout.SetCopyIfDifferent(true);
  4135. /* clang-format off */
  4136. fout <<
  4137. "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
  4138. "<Package xmlns=\"http://schemas.microsoft.com/appx/2010/manifest\""
  4139. " xmlns:m2=\"http://schemas.microsoft.com/appx/2013/manifest\">\n"
  4140. "\t<Identity Name=\"" << this->GUID << "\" Publisher=\"CN=CMake\""
  4141. " Version=\"1.0.0.0\" />\n"
  4142. "\t<Properties>\n"
  4143. "\t\t<DisplayName>" << targetNameXML << "</DisplayName>\n"
  4144. "\t\t<PublisherDisplayName>CMake</PublisherDisplayName>\n"
  4145. "\t\t<Logo>" << artifactDirXML << "\\StoreLogo.png</Logo>\n"
  4146. "\t</Properties>\n"
  4147. "\t<Prerequisites>\n"
  4148. "\t\t<OSMinVersion>6.3</OSMinVersion>\n"
  4149. "\t\t<OSMaxVersionTested>6.3</OSMaxVersionTested>\n"
  4150. "\t</Prerequisites>\n"
  4151. "\t<Resources>\n"
  4152. "\t\t<Resource Language=\"x-generate\" />\n"
  4153. "\t</Resources>\n"
  4154. "\t<Applications>\n"
  4155. "\t\t<Application Id=\"App\""
  4156. " Executable=\"" << targetNameXML << ".exe\""
  4157. " EntryPoint=\"" << targetNameXML << ".App\">\n"
  4158. "\t\t\t<m2:VisualElements\n"
  4159. "\t\t\t\tDisplayName=\"" << targetNameXML << "\"\n"
  4160. "\t\t\t\tDescription=\"" << targetNameXML << "\"\n"
  4161. "\t\t\t\tBackgroundColor=\"#336699\"\n"
  4162. "\t\t\t\tForegroundText=\"light\"\n"
  4163. "\t\t\t\tSquare150x150Logo=\"" << artifactDirXML << "\\Logo.png\"\n"
  4164. "\t\t\t\tSquare30x30Logo=\"" << artifactDirXML << "\\SmallLogo.png\">\n"
  4165. "\t\t\t\t<m2:DefaultTile ShortName=\"" << targetNameXML << "\">\n"
  4166. "\t\t\t\t\t<m2:ShowNameOnTiles>\n"
  4167. "\t\t\t\t\t\t<m2:ShowOn Tile=\"square150x150Logo\" />\n"
  4168. "\t\t\t\t\t</m2:ShowNameOnTiles>\n"
  4169. "\t\t\t\t</m2:DefaultTile>\n"
  4170. "\t\t\t\t<m2:SplashScreen"
  4171. " Image=\"" << artifactDirXML << "\\SplashScreen.png\" />\n"
  4172. "\t\t\t</m2:VisualElements>\n"
  4173. "\t\t</Application>\n"
  4174. "\t</Applications>\n"
  4175. "</Package>\n";
  4176. /* clang-format on */
  4177. this->WriteCommonMissingFiles(e1, manifestFile);
  4178. }
  4179. void cmVisualStudio10TargetGenerator::WriteMissingFilesWS10_0(Elem& e1)
  4180. {
  4181. std::string manifestFile =
  4182. this->DefaultArtifactDir + "/package.appxManifest";
  4183. std::string artifactDir =
  4184. this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
  4185. ConvertToWindowsSlash(artifactDir);
  4186. std::string artifactDirXML = cmVS10EscapeXML(artifactDir);
  4187. std::string targetNameXML =
  4188. cmVS10EscapeXML(this->GeneratorTarget->GetName());
  4189. cmGeneratedFileStream fout(manifestFile);
  4190. fout.SetCopyIfDifferent(true);
  4191. /* clang-format off */
  4192. fout <<
  4193. "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
  4194. "<Package\n\t"
  4195. "xmlns=\"http://schemas.microsoft.com/appx/manifest/foundation/windows10\""
  4196. "\txmlns:mp=\"http://schemas.microsoft.com/appx/2014/phone/manifest\"\n"
  4197. "\txmlns:uap=\"http://schemas.microsoft.com/appx/manifest/uap/windows10\""
  4198. "\n\tIgnorableNamespaces=\"uap mp\">\n\n"
  4199. "\t<Identity Name=\"" << this->GUID << "\" Publisher=\"CN=CMake\""
  4200. " Version=\"1.0.0.0\" />\n"
  4201. "\t<mp:PhoneIdentity PhoneProductId=\"" << this->GUID <<
  4202. "\" PhonePublisherId=\"00000000-0000-0000-0000-000000000000\"/>\n"
  4203. "\t<Properties>\n"
  4204. "\t\t<DisplayName>" << targetNameXML << "</DisplayName>\n"
  4205. "\t\t<PublisherDisplayName>CMake</PublisherDisplayName>\n"
  4206. "\t\t<Logo>" << artifactDirXML << "\\StoreLogo.png</Logo>\n"
  4207. "\t</Properties>\n"
  4208. "\t<Dependencies>\n"
  4209. "\t\t<TargetDeviceFamily Name=\"Windows.Universal\" "
  4210. "MinVersion=\"10.0.0.0\" MaxVersionTested=\"10.0.0.0\" />\n"
  4211. "\t</Dependencies>\n"
  4212. "\t<Resources>\n"
  4213. "\t\t<Resource Language=\"x-generate\" />\n"
  4214. "\t</Resources>\n"
  4215. "\t<Applications>\n"
  4216. "\t\t<Application Id=\"App\""
  4217. " Executable=\"" << targetNameXML << ".exe\""
  4218. " EntryPoint=\"" << targetNameXML << ".App\">\n"
  4219. "\t\t\t<uap:VisualElements\n"
  4220. "\t\t\t\tDisplayName=\"" << targetNameXML << "\"\n"
  4221. "\t\t\t\tDescription=\"" << targetNameXML << "\"\n"
  4222. "\t\t\t\tBackgroundColor=\"#336699\"\n"
  4223. "\t\t\t\tSquare150x150Logo=\"" << artifactDirXML << "\\Logo.png\"\n"
  4224. "\t\t\t\tSquare44x44Logo=\"" << artifactDirXML <<
  4225. "\\SmallLogo44x44.png\">\n"
  4226. "\t\t\t\t<uap:SplashScreen"
  4227. " Image=\"" << artifactDirXML << "\\SplashScreen.png\" />\n"
  4228. "\t\t\t</uap:VisualElements>\n"
  4229. "\t\t</Application>\n"
  4230. "\t</Applications>\n"
  4231. "</Package>\n";
  4232. /* clang-format on */
  4233. this->WriteCommonMissingFiles(e1, manifestFile);
  4234. }
  4235. void cmVisualStudio10TargetGenerator::WriteCommonMissingFiles(
  4236. Elem& e1, const std::string& manifestFile)
  4237. {
  4238. std::string templateFolder =
  4239. cmSystemTools::GetCMakeRoot() + "/Templates/Windows";
  4240. std::string sourceFile = this->ConvertPath(manifestFile, false);
  4241. ConvertToWindowsSlash(sourceFile);
  4242. {
  4243. Elem e2(e1, "AppxManifest");
  4244. e2.Attribute("Include", sourceFile);
  4245. e2.Element("SubType", "Designer");
  4246. }
  4247. this->AddedFiles.push_back(sourceFile);
  4248. std::string smallLogo = this->DefaultArtifactDir + "/SmallLogo.png";
  4249. cmSystemTools::CopyAFile(templateFolder + "/SmallLogo.png", smallLogo,
  4250. false);
  4251. ConvertToWindowsSlash(smallLogo);
  4252. Elem(e1, "Image").Attribute("Include", smallLogo);
  4253. this->AddedFiles.push_back(smallLogo);
  4254. std::string smallLogo44 = this->DefaultArtifactDir + "/SmallLogo44x44.png";
  4255. cmSystemTools::CopyAFile(templateFolder + "/SmallLogo44x44.png", smallLogo44,
  4256. false);
  4257. ConvertToWindowsSlash(smallLogo44);
  4258. Elem(e1, "Image").Attribute("Include", smallLogo44);
  4259. this->AddedFiles.push_back(smallLogo44);
  4260. std::string logo = this->DefaultArtifactDir + "/Logo.png";
  4261. cmSystemTools::CopyAFile(templateFolder + "/Logo.png", logo, false);
  4262. ConvertToWindowsSlash(logo);
  4263. Elem(e1, "Image").Attribute("Include", logo);
  4264. this->AddedFiles.push_back(logo);
  4265. std::string storeLogo = this->DefaultArtifactDir + "/StoreLogo.png";
  4266. cmSystemTools::CopyAFile(templateFolder + "/StoreLogo.png", storeLogo,
  4267. false);
  4268. ConvertToWindowsSlash(storeLogo);
  4269. Elem(e1, "Image").Attribute("Include", storeLogo);
  4270. this->AddedFiles.push_back(storeLogo);
  4271. std::string splashScreen = this->DefaultArtifactDir + "/SplashScreen.png";
  4272. cmSystemTools::CopyAFile(templateFolder + "/SplashScreen.png", splashScreen,
  4273. false);
  4274. ConvertToWindowsSlash(splashScreen);
  4275. Elem(e1, "Image").Attribute("Include", splashScreen);
  4276. this->AddedFiles.push_back(splashScreen);
  4277. if (this->AddedDefaultCertificate) {
  4278. // This file has already been added to the build so don't copy it
  4279. std::string keyFile =
  4280. this->DefaultArtifactDir + "/Windows_TemporaryKey.pfx";
  4281. ConvertToWindowsSlash(keyFile);
  4282. Elem(e1, "None").Attribute("Include", keyFile);
  4283. }
  4284. }
  4285. bool cmVisualStudio10TargetGenerator::ForceOld(const std::string& source) const
  4286. {
  4287. HANDLE h =
  4288. CreateFileW(cmSystemTools::ConvertToWindowsExtendedPath(source).c_str(),
  4289. FILE_WRITE_ATTRIBUTES, FILE_SHARE_WRITE, 0, OPEN_EXISTING,
  4290. FILE_FLAG_BACKUP_SEMANTICS, 0);
  4291. if (!h) {
  4292. return false;
  4293. }
  4294. FILETIME const ftime_20010101 = { 3365781504u, 29389701u };
  4295. if (!SetFileTime(h, &ftime_20010101, &ftime_20010101, &ftime_20010101)) {
  4296. CloseHandle(h);
  4297. return false;
  4298. }
  4299. CloseHandle(h);
  4300. return true;
  4301. }
  4302. void cmVisualStudio10TargetGenerator::GetCSharpSourceProperties(
  4303. cmSourceFile const* sf, std::map<std::string, std::string>& tags)
  4304. {
  4305. if (this->ProjectType == csproj) {
  4306. const cmPropertyMap& props = sf->GetProperties();
  4307. for (const std::string& p : props.GetKeys()) {
  4308. static const std::string propNamePrefix = "VS_CSHARP_";
  4309. if (p.find(propNamePrefix) == 0) {
  4310. std::string tagName = p.substr(propNamePrefix.length());
  4311. if (!tagName.empty()) {
  4312. const std::string val = props.GetPropertyValue(p);
  4313. if (!val.empty()) {
  4314. tags[tagName] = val;
  4315. } else {
  4316. tags.erase(tagName);
  4317. }
  4318. }
  4319. }
  4320. }
  4321. }
  4322. }
  4323. void cmVisualStudio10TargetGenerator::WriteCSharpSourceProperties(
  4324. Elem& e2, const std::map<std::string, std::string>& tags)
  4325. {
  4326. for (const auto& i : tags) {
  4327. e2.Element(i.first.c_str(), i.second);
  4328. }
  4329. }
  4330. void cmVisualStudio10TargetGenerator::GetCSharpSourceLink(
  4331. cmSourceFile const* sf, std::string& link)
  4332. {
  4333. std::string const& sourceFilePath = sf->GetFullPath();
  4334. std::string const& binaryDir = LocalGenerator->GetCurrentBinaryDirectory();
  4335. if (!cmSystemTools::IsSubDirectory(sourceFilePath, binaryDir)) {
  4336. const std::string& stripFromPath =
  4337. this->Makefile->GetCurrentSourceDirectory();
  4338. if (sourceFilePath.find(stripFromPath) == 0) {
  4339. if (const char* l = sf->GetProperty("VS_CSHARP_Link")) {
  4340. link = l;
  4341. } else {
  4342. link = sourceFilePath.substr(stripFromPath.length() + 1);
  4343. }
  4344. ConvertToWindowsSlash(link);
  4345. }
  4346. }
  4347. }
  4348. std::string cmVisualStudio10TargetGenerator::GetCMakeFilePath(
  4349. const char* relativeFilePath) const
  4350. {
  4351. // Always search in the standard modules location.
  4352. std::string path = cmSystemTools::GetCMakeRoot() + "/";
  4353. path += relativeFilePath;
  4354. ConvertToWindowsSlash(path);
  4355. return path;
  4356. }