cmVisualStudio10TargetGenerator.cxx 166 KB

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