cmVisualStudio10TargetGenerator.cxx 166 KB

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