cmVisualStudio10TargetGenerator.cxx 167 KB

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