cmVisualStudio10TargetGenerator.cxx 165 KB

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