cmVisualStudio10TargetGenerator.cxx 165 KB

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