cmVisualStudio10TargetGenerator.cxx 168 KB

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