cmVisualStudio10TargetGenerator.cxx 166 KB

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