cmVisualStudio10TargetGenerator.cxx 159 KB

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