cmVisualStudio10TargetGenerator.cxx 162 KB

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