cmVisualStudio10TargetGenerator.cxx 167 KB

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