cmVisualStudio10TargetGenerator.cxx 158 KB

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