cmVisualStudio10TargetGenerator.cxx 158 KB

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