cmVisualStudio10TargetGenerator.cxx 165 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459
  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 "cm_auto_ptr.hxx"
  17. static std::string cmVS10EscapeXML(std::string arg)
  18. {
  19. cmSystemTools::ReplaceString(arg, "&", "&");
  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 == "" || 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 != "") {
  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 = "";
  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. CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = ge.Parse(deployContent);
  1616. // Deployment location cannot be set on a configuration basis
  1617. if (!deployLocation.empty()) {
  1618. this->WriteString("<Link>", 3);
  1619. (*this->BuildFileStream) << deployLocation
  1620. << "\\%(FileName)%(Extension)";
  1621. this->WriteString("</Link>\n", 0);
  1622. }
  1623. for (size_t i = 0; i != this->Configurations.size(); ++i) {
  1624. if (0 == strcmp(cge->Evaluate(this->LocalGenerator,
  1625. this->Configurations[i]),
  1626. "1")) {
  1627. this->WriteString("<DeploymentContent Condition=\""
  1628. "'$(Configuration)|$(Platform)'=='",
  1629. 3);
  1630. (*this->BuildFileStream) << this->Configurations[i] << "|"
  1631. << this->Platform << "'\">true";
  1632. this->WriteString("</DeploymentContent>\n", 0);
  1633. } else {
  1634. this->WriteString("<ExcludedFromBuild Condition=\""
  1635. "'$(Configuration)|$(Platform)'=='",
  1636. 3);
  1637. (*this->BuildFileStream) << this->Configurations[i] << "|"
  1638. << this->Platform << "'\">true";
  1639. this->WriteString("</ExcludedFromBuild>\n", 0);
  1640. }
  1641. }
  1642. }
  1643. if (!shaderType.empty()) {
  1644. this->WriteString("<ShaderType>", 3);
  1645. (*this->BuildFileStream) << cmVS10EscapeXML(shaderType)
  1646. << "</ShaderType>\n";
  1647. }
  1648. if (!shaderEntryPoint.empty()) {
  1649. this->WriteString("<EntryPointName>", 3);
  1650. (*this->BuildFileStream) << cmVS10EscapeXML(shaderEntryPoint)
  1651. << "</EntryPointName>\n";
  1652. }
  1653. if (!shaderModel.empty()) {
  1654. this->WriteString("<ShaderModel>", 3);
  1655. (*this->BuildFileStream) << cmVS10EscapeXML(shaderModel)
  1656. << "</ShaderModel>\n";
  1657. }
  1658. if (!shaderAdditionalFlags.empty()) {
  1659. this->WriteString("<AdditionalOptions>", 3);
  1660. (*this->BuildFileStream) << cmVS10EscapeXML(shaderAdditionalFlags)
  1661. << "</AdditionalOptions>\n";
  1662. }
  1663. if (!settingsGenerator.empty()) {
  1664. this->WriteString("<Generator>", 3);
  1665. (*this->BuildFileStream) << cmVS10EscapeXML(settingsGenerator)
  1666. << "</Generator>\n";
  1667. }
  1668. if (!settingsLastGenOutput.empty()) {
  1669. this->WriteString("<LastGenOutput>", 3);
  1670. (*this->BuildFileStream) << cmVS10EscapeXML(settingsLastGenOutput)
  1671. << "</LastGenOutput>\n";
  1672. }
  1673. if (!sourceLink.empty()) {
  1674. this->WriteString("<Link>", 3);
  1675. (*this->BuildFileStream) << cmVS10EscapeXML(sourceLink) << "</Link>\n";
  1676. }
  1677. if (!subType.empty()) {
  1678. this->WriteString("<SubType>", 3);
  1679. (*this->BuildFileStream) << cmVS10EscapeXML(subType) << "</SubType>\n";
  1680. }
  1681. if (!copyToOutDir.empty()) {
  1682. this->WriteString("<CopyToOutputDirectory>", 3);
  1683. (*this->BuildFileStream) << cmVS10EscapeXML(copyToOutDir)
  1684. << "</CopyToOutputDirectory>\n";
  1685. }
  1686. if (!includeInVsix.empty()) {
  1687. this->WriteString("<IncludeInVSIX>", 3);
  1688. (*this->BuildFileStream) << cmVS10EscapeXML(includeInVsix)
  1689. << "</IncludeInVSIX>\n";
  1690. }
  1691. // write source file specific tags
  1692. this->WriteCSharpSourceProperties(sourceFileTags);
  1693. this->WriteString("</", 2);
  1694. (*this->BuildFileStream) << tool << ">\n";
  1695. } else {
  1696. this->WriteSource(tool, sf);
  1697. }
  1698. }
  1699. void cmVisualStudio10TargetGenerator::WriteSource(std::string const& tool,
  1700. cmSourceFile const* sf,
  1701. const char* end)
  1702. {
  1703. // Visual Studio tools append relative paths to the current dir, as in:
  1704. //
  1705. // c:\path\to\current\dir\..\..\..\relative\path\to\source.c
  1706. //
  1707. // and fail if this exceeds the maximum allowed path length. Our path
  1708. // conversion uses full paths when possible to allow deeper trees.
  1709. // However, CUDA 8.0 msbuild rules fail on absolute paths so for CUDA
  1710. // we must use relative paths.
  1711. bool forceRelative = sf->GetLanguage() == "CUDA";
  1712. std::string sourceFile = this->ConvertPath(sf->GetFullPath(), forceRelative);
  1713. if (this->LocalGenerator->GetVersion() ==
  1714. cmGlobalVisualStudioGenerator::VS10 &&
  1715. cmSystemTools::FileIsFullPath(sourceFile.c_str())) {
  1716. // Normal path conversion resulted in a full path. VS 10 (but not 11)
  1717. // refuses to show the property page in the IDE for a source file with a
  1718. // full path (not starting in a '.' or '/' AFAICT). CMake <= 2.8.4 used a
  1719. // relative path but to allow deeper build trees CMake 2.8.[5678] used a
  1720. // full path except for custom commands. Custom commands do not work
  1721. // without a relative path, but they do not seem to be involved in tools
  1722. // with the above behavior. For other sources we now use a relative path
  1723. // when the combined path will not be too long so property pages appear.
  1724. std::string sourceRel = this->ConvertPath(sf->GetFullPath(), true);
  1725. size_t const maxLen = 250;
  1726. if (sf->GetCustomCommand() ||
  1727. ((strlen(this->LocalGenerator->GetCurrentBinaryDirectory()) + 1 +
  1728. sourceRel.length()) <= maxLen)) {
  1729. forceRelative = true;
  1730. sourceFile = sourceRel;
  1731. } else {
  1732. this->GlobalGenerator->PathTooLong(this->GeneratorTarget, sf, sourceRel);
  1733. }
  1734. }
  1735. this->ConvertToWindowsSlash(sourceFile);
  1736. this->WriteString("<", 2);
  1737. (*this->BuildFileStream) << tool << " Include=\""
  1738. << cmVS10EscapeXML(sourceFile) << "\""
  1739. << (end ? end : " />\n");
  1740. ToolSource toolSource = { sf, forceRelative };
  1741. this->Tools[tool].push_back(toolSource);
  1742. }
  1743. void cmVisualStudio10TargetGenerator::WriteAllSources()
  1744. {
  1745. if (this->GeneratorTarget->GetType() > cmStateEnums::UTILITY) {
  1746. return;
  1747. }
  1748. this->WriteString("<ItemGroup>\n", 1);
  1749. std::vector<size_t> all_configs;
  1750. for (size_t ci = 0; ci < this->Configurations.size(); ++ci) {
  1751. all_configs.push_back(ci);
  1752. }
  1753. std::vector<cmGeneratorTarget::AllConfigSource> const& sources =
  1754. this->GeneratorTarget->GetAllConfigSources();
  1755. for (std::vector<cmGeneratorTarget::AllConfigSource>::const_iterator si =
  1756. sources.begin();
  1757. si != sources.end(); ++si) {
  1758. std::string tool;
  1759. switch (si->Kind) {
  1760. case cmGeneratorTarget::SourceKindAppManifest:
  1761. tool = "AppxManifest";
  1762. break;
  1763. case cmGeneratorTarget::SourceKindCertificate:
  1764. tool = "None";
  1765. break;
  1766. case cmGeneratorTarget::SourceKindCustomCommand:
  1767. // Handled elsewhere.
  1768. break;
  1769. case cmGeneratorTarget::SourceKindExternalObject:
  1770. tool = "Object";
  1771. if (this->LocalGenerator->GetVersion() <
  1772. cmGlobalVisualStudioGenerator::VS11) {
  1773. // For VS == 10 we cannot use LinkObjects to avoid linking custom
  1774. // command outputs. If an object file is generated in this target,
  1775. // then vs10 will use it in the build, and we have to list it as
  1776. // None instead of Object.
  1777. std::vector<cmSourceFile*> const* d =
  1778. this->GeneratorTarget->GetSourceDepends(si->Source);
  1779. if (d && !d->empty()) {
  1780. tool = "None";
  1781. }
  1782. }
  1783. break;
  1784. case cmGeneratorTarget::SourceKindExtra:
  1785. this->WriteExtraSource(si->Source);
  1786. break;
  1787. case cmGeneratorTarget::SourceKindHeader:
  1788. this->WriteHeaderSource(si->Source);
  1789. break;
  1790. case cmGeneratorTarget::SourceKindIDL:
  1791. tool = "Midl";
  1792. break;
  1793. case cmGeneratorTarget::SourceKindManifest:
  1794. // Handled elsewhere.
  1795. break;
  1796. case cmGeneratorTarget::SourceKindModuleDefinition:
  1797. tool = "None";
  1798. break;
  1799. case cmGeneratorTarget::SourceKindObjectSource: {
  1800. const std::string& lang = si->Source->GetLanguage();
  1801. if (lang == "C" || lang == "CXX") {
  1802. tool = "ClCompile";
  1803. } else if (lang == "ASM_MASM" &&
  1804. this->GlobalGenerator->IsMasmEnabled()) {
  1805. tool = "MASM";
  1806. } else if (lang == "ASM_NASM" &&
  1807. this->GlobalGenerator->IsNasmEnabled()) {
  1808. tool = "NASM";
  1809. } else if (lang == "RC") {
  1810. tool = "ResourceCompile";
  1811. } else if (lang == "CSharp") {
  1812. tool = "Compile";
  1813. } else if (lang == "CUDA" && this->GlobalGenerator->IsCudaEnabled()) {
  1814. tool = "CudaCompile";
  1815. } else {
  1816. tool = "None";
  1817. }
  1818. } break;
  1819. case cmGeneratorTarget::SourceKindResx:
  1820. // Handled elsewhere.
  1821. break;
  1822. case cmGeneratorTarget::SourceKindXaml:
  1823. // Handled elsewhere.
  1824. break;
  1825. }
  1826. if (!tool.empty()) {
  1827. // Compute set of configurations to exclude, if any.
  1828. std::vector<size_t> const& include_configs = si->Configs;
  1829. std::vector<size_t> exclude_configs;
  1830. std::set_difference(all_configs.begin(), all_configs.end(),
  1831. include_configs.begin(), include_configs.end(),
  1832. std::back_inserter(exclude_configs));
  1833. if (si->Kind == cmGeneratorTarget::SourceKindObjectSource) {
  1834. // FIXME: refactor generation to avoid tracking XML syntax state.
  1835. this->WriteSource(tool, si->Source, " ");
  1836. bool have_nested = this->OutputSourceSpecificFlags(si->Source);
  1837. if (!exclude_configs.empty()) {
  1838. if (!have_nested) {
  1839. (*this->BuildFileStream) << ">\n";
  1840. }
  1841. this->WriteExcludeFromBuild(exclude_configs);
  1842. have_nested = true;
  1843. }
  1844. if (have_nested) {
  1845. this->WriteString("</", 2);
  1846. (*this->BuildFileStream) << tool << ">\n";
  1847. } else {
  1848. (*this->BuildFileStream) << " />\n";
  1849. }
  1850. } else if (!exclude_configs.empty()) {
  1851. this->WriteSource(tool, si->Source, ">\n");
  1852. this->WriteExcludeFromBuild(exclude_configs);
  1853. this->WriteString("</", 2);
  1854. (*this->BuildFileStream) << tool << ">\n";
  1855. } else {
  1856. this->WriteSource(tool, si->Source);
  1857. }
  1858. }
  1859. }
  1860. if (this->IsMissingFiles) {
  1861. this->WriteMissingFiles();
  1862. }
  1863. this->WriteString("</ItemGroup>\n", 1);
  1864. }
  1865. bool cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags(
  1866. cmSourceFile const* source)
  1867. {
  1868. cmSourceFile const& sf = *source;
  1869. std::string objectName;
  1870. if (this->GeneratorTarget->HasExplicitObjectName(&sf)) {
  1871. objectName = this->GeneratorTarget->GetObjectName(&sf);
  1872. }
  1873. std::string flags;
  1874. bool configDependentFlags = false;
  1875. std::string defines;
  1876. if (const char* cflags = sf.GetProperty("COMPILE_FLAGS")) {
  1877. if (cmGeneratorExpression::Find(cflags) != std::string::npos) {
  1878. configDependentFlags = true;
  1879. }
  1880. flags += cflags;
  1881. }
  1882. if (const char* cdefs = sf.GetProperty("COMPILE_DEFINITIONS")) {
  1883. defines += cdefs;
  1884. }
  1885. std::string lang =
  1886. this->GlobalGenerator->GetLanguageFromExtension(sf.GetExtension().c_str());
  1887. std::string sourceLang = this->LocalGenerator->GetSourceFileLanguage(sf);
  1888. const std::string& linkLanguage =
  1889. this->GeneratorTarget->GetLinkerLanguage("");
  1890. bool needForceLang = false;
  1891. // source file does not match its extension language
  1892. if (lang != sourceLang) {
  1893. needForceLang = true;
  1894. lang = sourceLang;
  1895. }
  1896. // if the source file does not match the linker language
  1897. // then force c or c++
  1898. const char* compileAs = 0;
  1899. if (needForceLang || (linkLanguage != lang)) {
  1900. if (lang == "CXX") {
  1901. // force a C++ file type
  1902. compileAs = "CompileAsCpp";
  1903. } else if (lang == "C") {
  1904. // force to c
  1905. compileAs = "CompileAsC";
  1906. }
  1907. }
  1908. bool noWinRT = this->TargetCompileAsWinRT && lang == "C";
  1909. bool hasFlags = false;
  1910. // for the first time we need a new line if there is something
  1911. // produced here.
  1912. const char* firstString = ">\n";
  1913. if (!objectName.empty()) {
  1914. (*this->BuildFileStream) << firstString;
  1915. firstString = "";
  1916. hasFlags = true;
  1917. this->WriteString("<ObjectFileName>", 3);
  1918. (*this->BuildFileStream) << "$(IntDir)/" << objectName
  1919. << "</ObjectFileName>\n";
  1920. }
  1921. for (std::vector<std::string>::const_iterator config =
  1922. this->Configurations.begin();
  1923. config != this->Configurations.end(); ++config) {
  1924. std::string configUpper = cmSystemTools::UpperCase(*config);
  1925. std::string configDefines = defines;
  1926. std::string defPropName = "COMPILE_DEFINITIONS_";
  1927. defPropName += configUpper;
  1928. if (const char* ccdefs = sf.GetProperty(defPropName)) {
  1929. if (!configDefines.empty()) {
  1930. configDefines += ";";
  1931. }
  1932. configDefines += ccdefs;
  1933. }
  1934. // if we have flags or defines for this config then
  1935. // use them
  1936. if (!flags.empty() || configDependentFlags || !configDefines.empty() ||
  1937. compileAs || noWinRT) {
  1938. (*this->BuildFileStream) << firstString;
  1939. firstString = ""; // only do firstString once
  1940. hasFlags = true;
  1941. cmGlobalVisualStudio10Generator* gg =
  1942. static_cast<cmGlobalVisualStudio10Generator*>(this->GlobalGenerator);
  1943. cmIDEFlagTable const* flagtable = CM_NULLPTR;
  1944. const std::string& srclang = source->GetLanguage();
  1945. if (srclang == "C" || srclang == "CXX") {
  1946. flagtable = gg->GetClFlagTable();
  1947. } else if (srclang == "ASM_MASM" &&
  1948. this->GlobalGenerator->IsMasmEnabled()) {
  1949. flagtable = gg->GetMasmFlagTable();
  1950. } else if (lang == "ASM_NASM" &&
  1951. this->GlobalGenerator->IsNasmEnabled()) {
  1952. flagtable = gg->GetNasmFlagTable();
  1953. } else if (srclang == "RC") {
  1954. flagtable = gg->GetRcFlagTable();
  1955. } else if (srclang == "CSharp") {
  1956. flagtable = gg->GetCSharpFlagTable();
  1957. }
  1958. cmVisualStudioGeneratorOptions clOptions(
  1959. this->LocalGenerator, cmVisualStudioGeneratorOptions::Compiler,
  1960. flagtable, 0, this);
  1961. if (compileAs) {
  1962. clOptions.AddFlag("CompileAs", compileAs);
  1963. }
  1964. if (noWinRT) {
  1965. clOptions.AddFlag("CompileAsWinRT", "false");
  1966. }
  1967. if (configDependentFlags) {
  1968. cmGeneratorExpression ge;
  1969. CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = ge.Parse(flags);
  1970. std::string evaluatedFlags =
  1971. cge->Evaluate(this->LocalGenerator, *config);
  1972. clOptions.Parse(evaluatedFlags.c_str());
  1973. } else {
  1974. clOptions.Parse(flags.c_str());
  1975. }
  1976. if (clOptions.HasFlag("AdditionalIncludeDirectories")) {
  1977. clOptions.AppendFlag("AdditionalIncludeDirectories",
  1978. "%(AdditionalIncludeDirectories)");
  1979. }
  1980. if (clOptions.HasFlag("DisableSpecificWarnings")) {
  1981. clOptions.AppendFlag("DisableSpecificWarnings",
  1982. "%(DisableSpecificWarnings)");
  1983. }
  1984. clOptions.AddDefines(configDefines.c_str());
  1985. clOptions.SetConfiguration((*config).c_str());
  1986. clOptions.PrependInheritedString("AdditionalOptions");
  1987. clOptions.OutputFlagMap(*this->BuildFileStream, " ");
  1988. clOptions.OutputPreprocessorDefinitions(*this->BuildFileStream, " ",
  1989. "\n", lang);
  1990. }
  1991. }
  1992. if (this->IsXamlSource(source->GetFullPath())) {
  1993. (*this->BuildFileStream) << firstString;
  1994. firstString = ""; // only do firstString once
  1995. hasFlags = true;
  1996. this->WriteString("<DependentUpon>", 3);
  1997. const std::string& fileName = source->GetFullPath();
  1998. std::string xamlFileName = fileName.substr(0, fileName.find_last_of("."));
  1999. (*this->BuildFileStream) << xamlFileName << "</DependentUpon>\n";
  2000. }
  2001. if (this->ProjectType == csproj) {
  2002. std::string f = source->GetFullPath();
  2003. typedef std::map<std::string, std::string> CsPropMap;
  2004. CsPropMap sourceFileTags;
  2005. // set <Link> tag if necessary
  2006. std::string link;
  2007. this->GetCSharpSourceLink(source, link);
  2008. if (!link.empty()) {
  2009. sourceFileTags["Link"] = link;
  2010. }
  2011. this->GetCSharpSourceProperties(&sf, sourceFileTags);
  2012. // write source file specific tags
  2013. if (!sourceFileTags.empty()) {
  2014. hasFlags = true;
  2015. (*this->BuildFileStream) << firstString;
  2016. firstString = "";
  2017. this->WriteCSharpSourceProperties(sourceFileTags);
  2018. }
  2019. }
  2020. return hasFlags;
  2021. }
  2022. void cmVisualStudio10TargetGenerator::WriteExcludeFromBuild(
  2023. std::vector<size_t> const& exclude_configs)
  2024. {
  2025. for (std::vector<size_t>::const_iterator ci = exclude_configs.begin();
  2026. ci != exclude_configs.end(); ++ci) {
  2027. this->WriteString("", 3);
  2028. (*this->BuildFileStream)
  2029. << "<ExcludedFromBuild Condition=\"'$(Configuration)|$(Platform)'=='"
  2030. << cmVS10EscapeXML(this->Configurations[*ci]) << "|"
  2031. << cmVS10EscapeXML(this->Platform) << "'\">true</ExcludedFromBuild>\n";
  2032. }
  2033. }
  2034. void cmVisualStudio10TargetGenerator::WritePathAndIncrementalLinkOptions()
  2035. {
  2036. cmStateEnums::TargetType ttype = this->GeneratorTarget->GetType();
  2037. if (ttype > cmStateEnums::GLOBAL_TARGET) {
  2038. return;
  2039. }
  2040. if (this->ProjectType == csproj) {
  2041. return;
  2042. }
  2043. this->WriteString("<PropertyGroup>\n", 1);
  2044. this->WriteString("<_ProjectFileVersion>10.0.20506.1"
  2045. "</_ProjectFileVersion>\n",
  2046. 2);
  2047. for (std::vector<std::string>::const_iterator config =
  2048. this->Configurations.begin();
  2049. config != this->Configurations.end(); ++config) {
  2050. if (ttype >= cmStateEnums::UTILITY) {
  2051. this->WritePlatformConfigTag("IntDir", *config, 2);
  2052. *this->BuildFileStream
  2053. << "$(Platform)\\$(Configuration)\\$(ProjectName)\\"
  2054. << "</IntDir>\n";
  2055. } else {
  2056. std::string intermediateDir =
  2057. this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
  2058. intermediateDir += "/";
  2059. intermediateDir += *config;
  2060. intermediateDir += "/";
  2061. std::string outDir;
  2062. std::string targetNameFull;
  2063. if (ttype == cmStateEnums::OBJECT_LIBRARY) {
  2064. outDir = intermediateDir;
  2065. targetNameFull = this->GeneratorTarget->GetName();
  2066. targetNameFull += ".lib";
  2067. } else {
  2068. outDir = this->GeneratorTarget->GetDirectory(*config) + "/";
  2069. targetNameFull = this->GeneratorTarget->GetFullName(*config);
  2070. }
  2071. this->ConvertToWindowsSlash(intermediateDir);
  2072. this->ConvertToWindowsSlash(outDir);
  2073. this->WritePlatformConfigTag("OutDir", *config, 2);
  2074. *this->BuildFileStream << cmVS10EscapeXML(outDir) << "</OutDir>\n";
  2075. this->WritePlatformConfigTag("IntDir", *config, 2);
  2076. *this->BuildFileStream << cmVS10EscapeXML(intermediateDir)
  2077. << "</IntDir>\n";
  2078. if (const char* workingDir = this->GeneratorTarget->GetProperty(
  2079. "VS_DEBUGGER_WORKING_DIRECTORY")) {
  2080. this->WritePlatformConfigTag("LocalDebuggerWorkingDirectory", *config,
  2081. 2);
  2082. *this->BuildFileStream << cmVS10EscapeXML(workingDir)
  2083. << "</LocalDebuggerWorkingDirectory>\n";
  2084. }
  2085. std::string name =
  2086. cmSystemTools::GetFilenameWithoutLastExtension(targetNameFull);
  2087. this->WritePlatformConfigTag("TargetName", *config, 2);
  2088. *this->BuildFileStream << cmVS10EscapeXML(name) << "</TargetName>\n";
  2089. std::string ext =
  2090. cmSystemTools::GetFilenameLastExtension(targetNameFull);
  2091. if (ext.empty()) {
  2092. // An empty TargetExt causes a default extension to be used.
  2093. // A single "." appears to be treated as an empty extension.
  2094. ext = ".";
  2095. }
  2096. this->WritePlatformConfigTag("TargetExt", *config, 2);
  2097. *this->BuildFileStream << cmVS10EscapeXML(ext) << "</TargetExt>\n";
  2098. this->OutputLinkIncremental(*config);
  2099. }
  2100. }
  2101. this->WriteString("</PropertyGroup>\n", 1);
  2102. }
  2103. void cmVisualStudio10TargetGenerator::OutputLinkIncremental(
  2104. std::string const& configName)
  2105. {
  2106. if (!this->MSTools) {
  2107. return;
  2108. }
  2109. if (this->ProjectType == csproj) {
  2110. return;
  2111. }
  2112. // static libraries and things greater than modules do not need
  2113. // to set this option
  2114. if (this->GeneratorTarget->GetType() == cmStateEnums::STATIC_LIBRARY ||
  2115. this->GeneratorTarget->GetType() > cmStateEnums::MODULE_LIBRARY) {
  2116. return;
  2117. }
  2118. Options& linkOptions = *(this->LinkOptions[configName]);
  2119. const char* incremental = linkOptions.GetFlag("LinkIncremental");
  2120. this->WritePlatformConfigTag("LinkIncremental", configName, 2);
  2121. *this->BuildFileStream << (incremental ? incremental : "true")
  2122. << "</LinkIncremental>\n";
  2123. linkOptions.RemoveFlag("LinkIncremental");
  2124. const char* manifest = linkOptions.GetFlag("GenerateManifest");
  2125. this->WritePlatformConfigTag("GenerateManifest", configName, 2);
  2126. *this->BuildFileStream << (manifest ? manifest : "true")
  2127. << "</GenerateManifest>\n";
  2128. linkOptions.RemoveFlag("GenerateManifest");
  2129. // Some link options belong here. Use them now and remove them so that
  2130. // WriteLinkOptions does not use them.
  2131. const char* flags[] = { "LinkDelaySign", "LinkKeyFile", 0 };
  2132. for (const char** f = flags; *f; ++f) {
  2133. const char* flag = *f;
  2134. if (const char* value = linkOptions.GetFlag(flag)) {
  2135. this->WritePlatformConfigTag(flag, configName, 2);
  2136. *this->BuildFileStream << value << "</" << flag << ">\n";
  2137. linkOptions.RemoveFlag(flag);
  2138. }
  2139. }
  2140. }
  2141. bool cmVisualStudio10TargetGenerator::ComputeClOptions()
  2142. {
  2143. for (std::vector<std::string>::const_iterator i =
  2144. this->Configurations.begin();
  2145. i != this->Configurations.end(); ++i) {
  2146. if (!this->ComputeClOptions(*i)) {
  2147. return false;
  2148. }
  2149. }
  2150. return true;
  2151. }
  2152. bool cmVisualStudio10TargetGenerator::ComputeClOptions(
  2153. std::string const& configName)
  2154. {
  2155. // much of this was copied from here:
  2156. // copied from cmLocalVisualStudio7Generator.cxx 805
  2157. // TODO: Integrate code below with cmLocalVisualStudio7Generator.
  2158. cmGlobalVisualStudio10Generator* gg =
  2159. static_cast<cmGlobalVisualStudio10Generator*>(this->GlobalGenerator);
  2160. CM_AUTO_PTR<Options> pOptions;
  2161. switch (this->ProjectType) {
  2162. case vcxproj:
  2163. pOptions = CM_AUTO_PTR<Options>(new Options(
  2164. this->LocalGenerator, Options::Compiler, gg->GetClFlagTable()));
  2165. break;
  2166. case csproj:
  2167. pOptions = CM_AUTO_PTR<Options>(new Options(this->LocalGenerator,
  2168. Options::CSharpCompiler,
  2169. gg->GetCSharpFlagTable()));
  2170. break;
  2171. }
  2172. Options& clOptions = *pOptions;
  2173. std::string flags;
  2174. const std::string& linkLanguage =
  2175. this->GeneratorTarget->GetLinkerLanguage(configName);
  2176. if (linkLanguage.empty()) {
  2177. cmSystemTools::Error(
  2178. "CMake can not determine linker language for target: ",
  2179. this->Name.c_str());
  2180. return false;
  2181. }
  2182. // Choose a language whose flags to use for ClCompile.
  2183. static const char* clLangs[] = { "CXX", "C", "Fortran", "CSharp" };
  2184. std::string langForClCompile;
  2185. if (std::find(cmArrayBegin(clLangs), cmArrayEnd(clLangs), linkLanguage) !=
  2186. cmArrayEnd(clLangs)) {
  2187. langForClCompile = linkLanguage;
  2188. } else {
  2189. std::set<std::string> languages;
  2190. this->GeneratorTarget->GetLanguages(languages, configName);
  2191. for (const char* const* l = cmArrayBegin(clLangs);
  2192. l != cmArrayEnd(clLangs); ++l) {
  2193. if (languages.find(*l) != languages.end()) {
  2194. langForClCompile = *l;
  2195. break;
  2196. }
  2197. }
  2198. }
  2199. if (!langForClCompile.empty()) {
  2200. std::string baseFlagVar = "CMAKE_";
  2201. baseFlagVar += langForClCompile;
  2202. baseFlagVar += "_FLAGS";
  2203. flags =
  2204. this->GeneratorTarget->Target->GetMakefile()->GetRequiredDefinition(
  2205. baseFlagVar);
  2206. std::string flagVar =
  2207. baseFlagVar + std::string("_") + cmSystemTools::UpperCase(configName);
  2208. flags += " ";
  2209. flags +=
  2210. this->GeneratorTarget->Target->GetMakefile()->GetRequiredDefinition(
  2211. flagVar);
  2212. this->LocalGenerator->AddCompileOptions(flags, this->GeneratorTarget,
  2213. langForClCompile, configName);
  2214. }
  2215. // set the correct language
  2216. if (linkLanguage == "C") {
  2217. clOptions.AddFlag("CompileAs", "CompileAsC");
  2218. }
  2219. if (linkLanguage == "CXX") {
  2220. clOptions.AddFlag("CompileAs", "CompileAsCpp");
  2221. }
  2222. // Check IPO related warning/error.
  2223. this->GeneratorTarget->IsIPOEnabled(linkLanguage, configName);
  2224. // Get preprocessor definitions for this directory.
  2225. std::string defineFlags =
  2226. this->GeneratorTarget->Target->GetMakefile()->GetDefineFlags();
  2227. if (this->MSTools) {
  2228. if (this->ProjectType == vcxproj) {
  2229. clOptions.FixExceptionHandlingDefault();
  2230. clOptions.AddFlag("PrecompiledHeader", "NotUsing");
  2231. std::string asmLocation = configName + "/";
  2232. clOptions.AddFlag("AssemblerListingLocation", asmLocation.c_str());
  2233. }
  2234. }
  2235. clOptions.Parse(flags.c_str());
  2236. clOptions.Parse(defineFlags.c_str());
  2237. std::vector<std::string> targetDefines;
  2238. switch (this->ProjectType) {
  2239. case vcxproj:
  2240. this->GeneratorTarget->GetCompileDefinitions(targetDefines, configName,
  2241. "CXX");
  2242. break;
  2243. case csproj:
  2244. this->GeneratorTarget->GetCompileDefinitions(targetDefines, configName,
  2245. "CSharp");
  2246. break;
  2247. }
  2248. clOptions.AddDefines(targetDefines);
  2249. if (this->MSTools) {
  2250. clOptions.SetVerboseMakefile(
  2251. this->Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE"));
  2252. }
  2253. // Add a definition for the configuration name.
  2254. std::string configDefine = "CMAKE_INTDIR=\"";
  2255. configDefine += configName;
  2256. configDefine += "\"";
  2257. clOptions.AddDefine(configDefine);
  2258. if (const char* exportMacro = this->GeneratorTarget->GetExportMacro()) {
  2259. clOptions.AddDefine(exportMacro);
  2260. }
  2261. if (this->MSTools) {
  2262. // If we have the VS_WINRT_COMPONENT set then force Compile as WinRT.
  2263. if (this->GeneratorTarget->GetPropertyAsBool("VS_WINRT_COMPONENT")) {
  2264. clOptions.AddFlag("CompileAsWinRT", "true");
  2265. // For WinRT components, add the _WINRT_DLL define to produce a lib
  2266. if (this->GeneratorTarget->GetType() == cmStateEnums::SHARED_LIBRARY ||
  2267. this->GeneratorTarget->GetType() == cmStateEnums::MODULE_LIBRARY) {
  2268. clOptions.AddDefine("_WINRT_DLL");
  2269. }
  2270. } else if (this->GlobalGenerator->TargetsWindowsStore() ||
  2271. this->GlobalGenerator->TargetsWindowsPhone()) {
  2272. if (!clOptions.IsWinRt()) {
  2273. clOptions.AddFlag("CompileAsWinRT", "false");
  2274. }
  2275. }
  2276. if (const char* winRT = clOptions.GetFlag("CompileAsWinRT")) {
  2277. if (cmSystemTools::IsOn(winRT)) {
  2278. this->TargetCompileAsWinRT = true;
  2279. }
  2280. }
  2281. }
  2282. if (this->ProjectType != csproj && clOptions.IsManaged()) {
  2283. this->Managed = true;
  2284. std::string managedType = clOptions.GetFlag("CompileAsManaged");
  2285. if (managedType == "Safe") {
  2286. // force empty calling convention if safe clr is used
  2287. clOptions.AddFlag("CallingConvention", "");
  2288. }
  2289. }
  2290. if (this->ProjectType == csproj) {
  2291. // /nowin32manifest overrides /win32manifest: parameter
  2292. if (clOptions.HasFlag("NoWin32Manifest")) {
  2293. clOptions.RemoveFlag("ApplicationManifest");
  2294. }
  2295. }
  2296. this->ClOptions[configName] = pOptions.release();
  2297. return true;
  2298. }
  2299. void cmVisualStudio10TargetGenerator::WriteClOptions(
  2300. std::string const& configName, std::vector<std::string> const& includes)
  2301. {
  2302. Options& clOptions = *(this->ClOptions[configName]);
  2303. if (this->ProjectType == csproj) {
  2304. return;
  2305. }
  2306. this->WriteString("<ClCompile>\n", 2);
  2307. clOptions.PrependInheritedString("AdditionalOptions");
  2308. clOptions.AppendFlag("AdditionalIncludeDirectories", includes);
  2309. clOptions.AppendFlag("AdditionalIncludeDirectories",
  2310. "%(AdditionalIncludeDirectories)");
  2311. clOptions.OutputFlagMap(*this->BuildFileStream, " ");
  2312. clOptions.OutputPreprocessorDefinitions(*this->BuildFileStream, " ",
  2313. "\n", "CXX");
  2314. if (this->NsightTegra) {
  2315. if (const char* processMax =
  2316. this->GeneratorTarget->GetProperty("ANDROID_PROCESS_MAX")) {
  2317. this->WriteString("<ProcessMax>", 3);
  2318. *this->BuildFileStream << cmVS10EscapeXML(processMax)
  2319. << "</ProcessMax>\n";
  2320. }
  2321. }
  2322. if (this->MSTools) {
  2323. cmsys::RegularExpression clangToolset(
  2324. "(v[0-9]+_clang_.*|LLVM-vs[0-9]+.*)");
  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. CM_AUTO_PTR<Options> pOptions(new 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. CM_AUTO_PTR<Options> pOptions(new 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. CM_AUTO_PTR<Options> pOptions(new 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. CM_AUTO_PTR<Options> pOptions(new 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. CM_AUTO_PTR<Options> pOptions(new 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. CM_AUTO_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. CM_AUTO_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. CM_AUTO_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. CM_AUTO_PTR<Options> pOptions(new Options(
  2855. this->LocalGenerator, Options::Linker, gg->GetLinkFlagTable(), 0, this));
  2856. Options& linkOptions = *pOptions;
  2857. cmGeneratorTarget::LinkClosure const* linkClosure =
  2858. this->GeneratorTarget->GetLinkClosure(config);
  2859. const std::string& linkLanguage = linkClosure->LinkerLanguage;
  2860. if (linkLanguage.empty()) {
  2861. cmSystemTools::Error(
  2862. "CMake can not determine linker language for target: ",
  2863. this->Name.c_str());
  2864. return false;
  2865. }
  2866. std::string CONFIG = cmSystemTools::UpperCase(config);
  2867. const char* linkType = "SHARED";
  2868. if (this->GeneratorTarget->GetType() == cmStateEnums::MODULE_LIBRARY) {
  2869. linkType = "MODULE";
  2870. }
  2871. if (this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE) {
  2872. linkType = "EXE";
  2873. }
  2874. std::string flags;
  2875. std::string linkFlagVarBase = "CMAKE_";
  2876. linkFlagVarBase += linkType;
  2877. linkFlagVarBase += "_LINKER_FLAGS";
  2878. flags += " ";
  2879. flags += this->GeneratorTarget->Target->GetMakefile()->GetRequiredDefinition(
  2880. linkFlagVarBase);
  2881. std::string linkFlagVar = linkFlagVarBase + "_" + CONFIG;
  2882. flags += " ";
  2883. flags += this->GeneratorTarget->Target->GetMakefile()->GetRequiredDefinition(
  2884. linkFlagVar);
  2885. const char* targetLinkFlags =
  2886. this->GeneratorTarget->GetProperty("LINK_FLAGS");
  2887. if (targetLinkFlags) {
  2888. flags += " ";
  2889. flags += targetLinkFlags;
  2890. }
  2891. std::string flagsProp = "LINK_FLAGS_";
  2892. flagsProp += CONFIG;
  2893. if (const char* flagsConfig =
  2894. this->GeneratorTarget->GetProperty(flagsProp)) {
  2895. flags += " ";
  2896. flags += flagsConfig;
  2897. }
  2898. cmComputeLinkInformation* pcli =
  2899. this->GeneratorTarget->GetLinkInformation(config);
  2900. if (!pcli) {
  2901. cmSystemTools::Error(
  2902. "CMake can not compute cmComputeLinkInformation for target: ",
  2903. this->Name.c_str());
  2904. return false;
  2905. }
  2906. cmComputeLinkInformation& cli = *pcli;
  2907. std::vector<std::string> libVec;
  2908. std::vector<std::string> vsTargetVec;
  2909. this->AddLibraries(cli, libVec, vsTargetVec);
  2910. if (std::find(linkClosure->Languages.begin(), linkClosure->Languages.end(),
  2911. "CUDA") != linkClosure->Languages.end()) {
  2912. switch (this->CudaOptions[config]->GetCudaRuntime()) {
  2913. case cmVisualStudioGeneratorOptions::CudaRuntimeStatic:
  2914. libVec.push_back("cudart_static.lib");
  2915. break;
  2916. case cmVisualStudioGeneratorOptions::CudaRuntimeShared:
  2917. libVec.push_back("cudart.lib");
  2918. break;
  2919. case cmVisualStudioGeneratorOptions::CudaRuntimeNone:
  2920. break;
  2921. }
  2922. }
  2923. std::string standardLibsVar = "CMAKE_";
  2924. standardLibsVar += linkLanguage;
  2925. standardLibsVar += "_STANDARD_LIBRARIES";
  2926. std::string const libs = this->Makefile->GetSafeDefinition(standardLibsVar);
  2927. cmSystemTools::ParseWindowsCommandLine(libs.c_str(), libVec);
  2928. linkOptions.AddFlag("AdditionalDependencies", libVec);
  2929. // Populate TargetsFileAndConfigsVec
  2930. for (std::vector<std::string>::iterator ti = vsTargetVec.begin();
  2931. ti != vsTargetVec.end(); ++ti) {
  2932. this->AddTargetsFileAndConfigPair(*ti, config);
  2933. }
  2934. std::vector<std::string> const& ldirs = cli.GetDirectories();
  2935. std::vector<std::string> linkDirs;
  2936. for (std::vector<std::string>::const_iterator d = ldirs.begin();
  2937. d != ldirs.end(); ++d) {
  2938. // first just full path
  2939. linkDirs.push_back(*d);
  2940. // next path with configuration type Debug, Release, etc
  2941. linkDirs.push_back(*d + "/$(Configuration)");
  2942. }
  2943. linkDirs.push_back("%(AdditionalLibraryDirectories)");
  2944. linkOptions.AddFlag("AdditionalLibraryDirectories", linkDirs);
  2945. std::string targetName;
  2946. std::string targetNameSO;
  2947. std::string targetNameFull;
  2948. std::string targetNameImport;
  2949. std::string targetNamePDB;
  2950. if (this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE) {
  2951. this->GeneratorTarget->GetExecutableNames(
  2952. targetName, targetNameFull, targetNameImport, targetNamePDB, config);
  2953. } else {
  2954. this->GeneratorTarget->GetLibraryNames(targetName, targetNameSO,
  2955. targetNameFull, targetNameImport,
  2956. targetNamePDB, config);
  2957. }
  2958. if (this->MSTools) {
  2959. linkOptions.AddFlag("Version", "");
  2960. if (this->GeneratorTarget->GetPropertyAsBool("WIN32_EXECUTABLE")) {
  2961. if (this->GlobalGenerator->TargetsWindowsCE()) {
  2962. linkOptions.AddFlag("SubSystem", "WindowsCE");
  2963. if (this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE) {
  2964. if (this->ClOptions[config]->UsingUnicode()) {
  2965. linkOptions.AddFlag("EntryPointSymbol", "wWinMainCRTStartup");
  2966. } else {
  2967. linkOptions.AddFlag("EntryPointSymbol", "WinMainCRTStartup");
  2968. }
  2969. }
  2970. } else {
  2971. linkOptions.AddFlag("SubSystem", "Windows");
  2972. }
  2973. } else {
  2974. if (this->GlobalGenerator->TargetsWindowsCE()) {
  2975. linkOptions.AddFlag("SubSystem", "WindowsCE");
  2976. if (this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE) {
  2977. if (this->ClOptions[config]->UsingUnicode()) {
  2978. linkOptions.AddFlag("EntryPointSymbol", "mainWCRTStartup");
  2979. } else {
  2980. linkOptions.AddFlag("EntryPointSymbol", "mainACRTStartup");
  2981. }
  2982. }
  2983. } else {
  2984. linkOptions.AddFlag("SubSystem", "Console");
  2985. };
  2986. }
  2987. if (const char* stackVal = this->Makefile->GetDefinition(
  2988. "CMAKE_" + linkLanguage + "_STACK_SIZE")) {
  2989. linkOptions.AddFlag("StackReserveSize", stackVal);
  2990. }
  2991. linkOptions.AddFlag("GenerateDebugInformation", "false");
  2992. std::string pdb = this->GeneratorTarget->GetPDBDirectory(config);
  2993. pdb += "/";
  2994. pdb += targetNamePDB;
  2995. std::string imLib = this->GeneratorTarget->GetDirectory(
  2996. config, cmStateEnums::ImportLibraryArtifact);
  2997. imLib += "/";
  2998. imLib += targetNameImport;
  2999. linkOptions.AddFlag("ImportLibrary", imLib.c_str());
  3000. linkOptions.AddFlag("ProgramDataBaseFile", pdb.c_str());
  3001. // A Windows Runtime component uses internal .NET metadata,
  3002. // so does not have an import library.
  3003. if (this->GeneratorTarget->GetPropertyAsBool("VS_WINRT_COMPONENT") &&
  3004. this->GeneratorTarget->GetType() != cmStateEnums::EXECUTABLE) {
  3005. linkOptions.AddFlag("GenerateWindowsMetadata", "true");
  3006. } else if (this->GlobalGenerator->TargetsWindowsPhone() ||
  3007. this->GlobalGenerator->TargetsWindowsStore()) {
  3008. // WindowsPhone and WindowsStore components are in an app container
  3009. // and produce WindowsMetadata. If we are not producing a WINRT
  3010. // component, then do not generate the metadata here.
  3011. linkOptions.AddFlag("GenerateWindowsMetadata", "false");
  3012. }
  3013. if (this->GlobalGenerator->TargetsWindowsPhone() &&
  3014. this->GlobalGenerator->GetSystemVersion() == "8.0") {
  3015. // WindowsPhone 8.0 does not have ole32.
  3016. linkOptions.AppendFlag("IgnoreSpecificDefaultLibraries", "ole32.lib");
  3017. }
  3018. } else if (this->NsightTegra) {
  3019. linkOptions.AddFlag("SoName", targetNameSO.c_str());
  3020. }
  3021. linkOptions.Parse(flags.c_str());
  3022. if (this->MSTools) {
  3023. cmGeneratorTarget::ModuleDefinitionInfo const* mdi =
  3024. this->GeneratorTarget->GetModuleDefinitionInfo(config);
  3025. if (mdi && !mdi->DefFile.empty()) {
  3026. linkOptions.AddFlag("ModuleDefinitionFile", mdi->DefFile.c_str());
  3027. }
  3028. linkOptions.AppendFlag("IgnoreSpecificDefaultLibraries",
  3029. "%(IgnoreSpecificDefaultLibraries)");
  3030. }
  3031. // VS 2015 without all updates has a v140 toolset whose
  3032. // GenerateDebugInformation expects No/Debug instead of false/true.
  3033. if (gg->GetPlatformToolsetNeedsDebugEnum()) {
  3034. if (const char* debug = linkOptions.GetFlag("GenerateDebugInformation")) {
  3035. if (strcmp(debug, "false") == 0) {
  3036. linkOptions.AddFlag("GenerateDebugInformation", "No");
  3037. } else if (strcmp(debug, "true") == 0) {
  3038. linkOptions.AddFlag("GenerateDebugInformation", "Debug");
  3039. }
  3040. }
  3041. }
  3042. this->LinkOptions[config] = pOptions.release();
  3043. return true;
  3044. }
  3045. bool cmVisualStudio10TargetGenerator::ComputeLibOptions()
  3046. {
  3047. if (this->GeneratorTarget->GetType() == cmStateEnums::STATIC_LIBRARY) {
  3048. for (std::vector<std::string>::const_iterator i =
  3049. this->Configurations.begin();
  3050. i != this->Configurations.end(); ++i) {
  3051. if (!this->ComputeLibOptions(*i)) {
  3052. return false;
  3053. }
  3054. }
  3055. }
  3056. return true;
  3057. }
  3058. bool cmVisualStudio10TargetGenerator::ComputeLibOptions(
  3059. std::string const& config)
  3060. {
  3061. cmComputeLinkInformation* pcli =
  3062. this->GeneratorTarget->GetLinkInformation(config);
  3063. if (!pcli) {
  3064. cmSystemTools::Error(
  3065. "CMake can not compute cmComputeLinkInformation for target: ",
  3066. this->Name.c_str());
  3067. return false;
  3068. }
  3069. cmComputeLinkInformation& cli = *pcli;
  3070. typedef cmComputeLinkInformation::ItemVector ItemVector;
  3071. const ItemVector& libs = cli.GetItems();
  3072. std::string currentBinDir =
  3073. this->LocalGenerator->GetCurrentBinaryDirectory();
  3074. for (ItemVector::const_iterator l = libs.begin(); l != libs.end(); ++l) {
  3075. if (l->IsPath && cmVS10IsTargetsFile(l->Value)) {
  3076. std::string path =
  3077. this->LocalGenerator->ConvertToRelativePath(currentBinDir, l->Value);
  3078. this->ConvertToWindowsSlash(path);
  3079. this->AddTargetsFileAndConfigPair(path, config);
  3080. }
  3081. }
  3082. return true;
  3083. }
  3084. void cmVisualStudio10TargetGenerator::WriteLinkOptions(
  3085. std::string const& config)
  3086. {
  3087. if (this->GeneratorTarget->GetType() == cmStateEnums::STATIC_LIBRARY ||
  3088. this->GeneratorTarget->GetType() > cmStateEnums::MODULE_LIBRARY) {
  3089. return;
  3090. }
  3091. if (this->ProjectType == csproj) {
  3092. return;
  3093. }
  3094. Options& linkOptions = *(this->LinkOptions[config]);
  3095. this->WriteString("<Link>\n", 2);
  3096. linkOptions.PrependInheritedString("AdditionalOptions");
  3097. linkOptions.OutputFlagMap(*this->BuildFileStream, " ");
  3098. this->WriteString("</Link>\n", 2);
  3099. if (!this->GlobalGenerator->NeedLinkLibraryDependencies(
  3100. this->GeneratorTarget)) {
  3101. this->WriteString("<ProjectReference>\n", 2);
  3102. this->WriteString(
  3103. "<LinkLibraryDependencies>false</LinkLibraryDependencies>\n", 3);
  3104. this->WriteString("</ProjectReference>\n", 2);
  3105. }
  3106. }
  3107. void cmVisualStudio10TargetGenerator::AddLibraries(
  3108. cmComputeLinkInformation& cli, std::vector<std::string>& libVec,
  3109. std::vector<std::string>& vsTargetVec)
  3110. {
  3111. typedef cmComputeLinkInformation::ItemVector ItemVector;
  3112. ItemVector const& libs = cli.GetItems();
  3113. std::string currentBinDir =
  3114. this->LocalGenerator->GetCurrentBinaryDirectory();
  3115. for (ItemVector::const_iterator l = libs.begin(); l != libs.end(); ++l) {
  3116. if (l->IsPath) {
  3117. std::string path =
  3118. this->LocalGenerator->ConvertToRelativePath(currentBinDir, l->Value);
  3119. this->ConvertToWindowsSlash(path);
  3120. if (cmVS10IsTargetsFile(l->Value)) {
  3121. vsTargetVec.push_back(path);
  3122. } else {
  3123. libVec.push_back(path);
  3124. }
  3125. } else if (!l->Target ||
  3126. l->Target->GetType() != cmStateEnums::INTERFACE_LIBRARY) {
  3127. libVec.push_back(l->Value);
  3128. }
  3129. }
  3130. }
  3131. void cmVisualStudio10TargetGenerator::AddTargetsFileAndConfigPair(
  3132. std::string const& targetsFile, std::string const& config)
  3133. {
  3134. for (std::vector<TargetsFileAndConfigs>::iterator i =
  3135. this->TargetsFileAndConfigsVec.begin();
  3136. i != this->TargetsFileAndConfigsVec.end(); ++i) {
  3137. if (cmSystemTools::ComparePath(targetsFile, i->File)) {
  3138. if (std::find(i->Configs.begin(), i->Configs.end(), config) ==
  3139. i->Configs.end()) {
  3140. i->Configs.push_back(config);
  3141. }
  3142. return;
  3143. }
  3144. }
  3145. TargetsFileAndConfigs entry;
  3146. entry.File = targetsFile;
  3147. entry.Configs.push_back(config);
  3148. this->TargetsFileAndConfigsVec.push_back(entry);
  3149. }
  3150. void cmVisualStudio10TargetGenerator::WriteMidlOptions(
  3151. std::string const& /*config*/, std::vector<std::string> const& includes)
  3152. {
  3153. if (!this->MSTools) {
  3154. return;
  3155. }
  3156. if (this->ProjectType == csproj) {
  3157. return;
  3158. }
  3159. // This processes *any* of the .idl files specified in the project's file
  3160. // list (and passed as the item metadata %(Filename) expressing the rule
  3161. // input filename) into output files at the per-config *build* dir
  3162. // ($(IntDir)) each.
  3163. //
  3164. // IOW, this MIDL section is intended to provide a fully generic syntax
  3165. // content suitable for most cases (read: if you get errors, then it's quite
  3166. // probable that the error is on your side of the .idl setup).
  3167. //
  3168. // Also, note that the marked-as-generated _i.c file in the Visual Studio
  3169. // generator case needs to be referred to as $(IntDir)\foo_i.c at the
  3170. // project's file list, otherwise the compiler-side processing won't pick it
  3171. // up (for non-directory form, it ends up looking in project binary dir
  3172. // only). Perhaps there's something to be done to make this more automatic
  3173. // on the CMake side?
  3174. this->WriteString("<Midl>\n", 2);
  3175. this->WriteString("<AdditionalIncludeDirectories>", 3);
  3176. for (std::vector<std::string>::const_iterator i = includes.begin();
  3177. i != includes.end(); ++i) {
  3178. *this->BuildFileStream << cmVS10EscapeXML(*i) << ";";
  3179. }
  3180. this->WriteString("%(AdditionalIncludeDirectories)"
  3181. "</AdditionalIncludeDirectories>\n",
  3182. 0);
  3183. this->WriteString("<OutputDirectory>$(ProjectDir)/$(IntDir)"
  3184. "</OutputDirectory>\n",
  3185. 3);
  3186. this->WriteString("<HeaderFileName>%(Filename).h</HeaderFileName>\n", 3);
  3187. this->WriteString("<TypeLibraryName>%(Filename).tlb</TypeLibraryName>\n", 3);
  3188. this->WriteString("<InterfaceIdentifierFileName>"
  3189. "%(Filename)_i.c</InterfaceIdentifierFileName>\n",
  3190. 3);
  3191. this->WriteString("<ProxyFileName>%(Filename)_p.c</ProxyFileName>\n", 3);
  3192. this->WriteString("</Midl>\n", 2);
  3193. }
  3194. void cmVisualStudio10TargetGenerator::WriteItemDefinitionGroups()
  3195. {
  3196. if (this->ProjectType == csproj) {
  3197. return;
  3198. }
  3199. for (std::vector<std::string>::const_iterator i =
  3200. this->Configurations.begin();
  3201. i != this->Configurations.end(); ++i) {
  3202. std::vector<std::string> includes;
  3203. this->LocalGenerator->GetIncludeDirectories(
  3204. includes, this->GeneratorTarget, "C", *i);
  3205. for (std::vector<std::string>::iterator ii = includes.begin();
  3206. ii != includes.end(); ++ii) {
  3207. this->ConvertToWindowsSlash(*ii);
  3208. }
  3209. this->WritePlatformConfigTag("ItemDefinitionGroup", *i, 1);
  3210. *this->BuildFileStream << "\n";
  3211. // output cl compile flags <ClCompile></ClCompile>
  3212. if (this->GeneratorTarget->GetType() <= cmStateEnums::OBJECT_LIBRARY) {
  3213. this->WriteClOptions(*i, includes);
  3214. // output rc compile flags <ResourceCompile></ResourceCompile>
  3215. this->WriteRCOptions(*i, includes);
  3216. this->WriteCudaOptions(*i, includes);
  3217. this->WriteMasmOptions(*i, includes);
  3218. this->WriteNasmOptions(*i, includes);
  3219. }
  3220. // output midl flags <Midl></Midl>
  3221. this->WriteMidlOptions(*i, includes);
  3222. // write events
  3223. if (this->ProjectType != csproj) {
  3224. this->WriteEvents(*i);
  3225. }
  3226. // output link flags <Link></Link>
  3227. this->WriteLinkOptions(*i);
  3228. this->WriteCudaLinkOptions(*i);
  3229. // output lib flags <Lib></Lib>
  3230. this->WriteLibOptions(*i);
  3231. // output manifest flags <Manifest></Manifest>
  3232. this->WriteManifestOptions(*i);
  3233. if (this->NsightTegra &&
  3234. this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE &&
  3235. this->GeneratorTarget->GetPropertyAsBool("ANDROID_GUI")) {
  3236. this->WriteAntBuildOptions(*i);
  3237. }
  3238. this->WriteString("</ItemDefinitionGroup>\n", 1);
  3239. }
  3240. }
  3241. void cmVisualStudio10TargetGenerator::WriteEvents(
  3242. std::string const& configName)
  3243. {
  3244. bool addedPrelink = false;
  3245. cmGeneratorTarget::ModuleDefinitionInfo const* mdi =
  3246. this->GeneratorTarget->GetModuleDefinitionInfo(configName);
  3247. if (mdi && mdi->DefFileGenerated) {
  3248. addedPrelink = true;
  3249. std::vector<cmCustomCommand> commands =
  3250. this->GeneratorTarget->GetPreLinkCommands();
  3251. this->GlobalGenerator->AddSymbolExportCommand(this->GeneratorTarget,
  3252. commands, configName);
  3253. this->WriteEvent("PreLinkEvent", commands, configName);
  3254. }
  3255. if (!addedPrelink) {
  3256. this->WriteEvent("PreLinkEvent",
  3257. this->GeneratorTarget->GetPreLinkCommands(), configName);
  3258. }
  3259. this->WriteEvent("PreBuildEvent",
  3260. this->GeneratorTarget->GetPreBuildCommands(), configName);
  3261. this->WriteEvent("PostBuildEvent",
  3262. this->GeneratorTarget->GetPostBuildCommands(), configName);
  3263. }
  3264. void cmVisualStudio10TargetGenerator::WriteEvent(
  3265. const char* name, std::vector<cmCustomCommand> const& commands,
  3266. std::string const& configName)
  3267. {
  3268. if (commands.empty()) {
  3269. return;
  3270. }
  3271. this->WriteString("<", 2);
  3272. (*this->BuildFileStream) << name << ">\n";
  3273. cmLocalVisualStudio7Generator* lg = this->LocalGenerator;
  3274. std::string script;
  3275. const char* pre = "";
  3276. std::string comment;
  3277. for (std::vector<cmCustomCommand>::const_iterator i = commands.begin();
  3278. i != commands.end(); ++i) {
  3279. cmCustomCommandGenerator ccg(*i, configName, this->LocalGenerator);
  3280. comment += pre;
  3281. comment += lg->ConstructComment(ccg);
  3282. script += pre;
  3283. pre = "\n";
  3284. script += cmVS10EscapeXML(lg->ConstructScript(ccg));
  3285. }
  3286. comment = cmVS10EscapeComment(comment);
  3287. if (this->ProjectType != csproj) {
  3288. this->WriteString("<Message>", 3);
  3289. (*this->BuildFileStream) << cmVS10EscapeXML(comment) << "</Message>\n";
  3290. this->WriteString("<Command>", 3);
  3291. } else {
  3292. std::string strippedComment = comment;
  3293. strippedComment.erase(
  3294. std::remove(strippedComment.begin(), strippedComment.end(), '\t'),
  3295. strippedComment.end());
  3296. if (!comment.empty() && !strippedComment.empty()) {
  3297. (*this->BuildFileStream) << "echo " << cmVS10EscapeXML(comment) << "\n";
  3298. }
  3299. }
  3300. (*this->BuildFileStream) << script;
  3301. if (this->ProjectType != csproj) {
  3302. (*this->BuildFileStream) << "</Command>";
  3303. }
  3304. (*this->BuildFileStream) << "\n";
  3305. this->WriteString("</", 2);
  3306. (*this->BuildFileStream) << name << ">\n";
  3307. }
  3308. void cmVisualStudio10TargetGenerator::WriteProjectReferences()
  3309. {
  3310. cmGlobalGenerator::TargetDependSet const& unordered =
  3311. this->GlobalGenerator->GetTargetDirectDepends(this->GeneratorTarget);
  3312. typedef cmGlobalVisualStudioGenerator::OrderedTargetDependSet
  3313. OrderedTargetDependSet;
  3314. OrderedTargetDependSet depends(unordered, CMAKE_CHECK_BUILD_SYSTEM_TARGET);
  3315. this->WriteString("<ItemGroup>\n", 1);
  3316. for (OrderedTargetDependSet::const_iterator i = depends.begin();
  3317. i != depends.end(); ++i) {
  3318. cmGeneratorTarget const* dt = *i;
  3319. if (dt->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
  3320. continue;
  3321. }
  3322. // skip fortran targets as they can not be processed by MSBuild
  3323. // the only reference will be in the .sln file
  3324. if (static_cast<cmGlobalVisualStudioGenerator*>(this->GlobalGenerator)
  3325. ->TargetIsFortranOnly(dt)) {
  3326. continue;
  3327. }
  3328. this->WriteString("<ProjectReference Include=\"", 2);
  3329. cmLocalGenerator* lg = dt->GetLocalGenerator();
  3330. std::string name = dt->GetName();
  3331. std::string path;
  3332. const char* p = dt->GetProperty("EXTERNAL_MSPROJECT");
  3333. if (p) {
  3334. path = p;
  3335. } else {
  3336. path = lg->GetCurrentBinaryDirectory();
  3337. path += "/";
  3338. path += dt->GetName();
  3339. path += computeProjectFileExtension(dt);
  3340. }
  3341. this->ConvertToWindowsSlash(path);
  3342. (*this->BuildFileStream) << cmVS10EscapeXML(path) << "\">\n";
  3343. this->WriteString("<Project>", 3);
  3344. (*this->BuildFileStream) << "{" << this->GlobalGenerator->GetGUID(name)
  3345. << "}";
  3346. (*this->BuildFileStream) << "</Project>\n";
  3347. this->WriteString("<Name>", 3);
  3348. (*this->BuildFileStream) << name << "</Name>\n";
  3349. this->WriteDotNetReferenceCustomTags(name);
  3350. this->WriteString("</ProjectReference>\n", 2);
  3351. }
  3352. this->WriteString("</ItemGroup>\n", 1);
  3353. }
  3354. void cmVisualStudio10TargetGenerator::WritePlatformExtensions()
  3355. {
  3356. // This only applies to Windows 10 apps
  3357. if (this->GlobalGenerator->TargetsWindowsStore() &&
  3358. cmHasLiteralPrefix(this->GlobalGenerator->GetSystemVersion(), "10.0")) {
  3359. const char* desktopExtensionsVersion =
  3360. this->GeneratorTarget->GetProperty("VS_DESKTOP_EXTENSIONS_VERSION");
  3361. if (desktopExtensionsVersion) {
  3362. this->WriteSinglePlatformExtension("WindowsDesktop",
  3363. desktopExtensionsVersion);
  3364. }
  3365. const char* mobileExtensionsVersion =
  3366. this->GeneratorTarget->GetProperty("VS_MOBILE_EXTENSIONS_VERSION");
  3367. if (mobileExtensionsVersion) {
  3368. this->WriteSinglePlatformExtension("WindowsMobile",
  3369. mobileExtensionsVersion);
  3370. }
  3371. }
  3372. }
  3373. void cmVisualStudio10TargetGenerator::WriteSinglePlatformExtension(
  3374. std::string const& extension, std::string const& version)
  3375. {
  3376. this->WriteString("<Import Project=", 2);
  3377. (*this->BuildFileStream)
  3378. << "\"$([Microsoft.Build.Utilities.ToolLocationHelper]"
  3379. << "::GetPlatformExtensionSDKLocation(`" << extension
  3380. << ", Version=" << version
  3381. << "`, $(TargetPlatformIdentifier), $(TargetPlatformVersion), null, "
  3382. << "$(ExtensionSDKDirectoryRoot), null))"
  3383. << "\\DesignTime\\CommonConfiguration\\Neutral\\" << extension
  3384. << ".props\" "
  3385. << "Condition=\"exists('$("
  3386. << "[Microsoft.Build.Utilities.ToolLocationHelper]"
  3387. << "::GetPlatformExtensionSDKLocation(`" << extension
  3388. << ", Version=" << version
  3389. << "`, $(TargetPlatformIdentifier), $(TargetPlatformVersion), null, "
  3390. << "$(ExtensionSDKDirectoryRoot), null))"
  3391. << "\\DesignTime\\CommonConfiguration\\Neutral\\" << extension
  3392. << ".props')\" />\n";
  3393. }
  3394. void cmVisualStudio10TargetGenerator::WriteSDKReferences()
  3395. {
  3396. std::vector<std::string> sdkReferences;
  3397. bool hasWrittenItemGroup = false;
  3398. if (const char* vsSDKReferences =
  3399. this->GeneratorTarget->GetProperty("VS_SDK_REFERENCES")) {
  3400. cmSystemTools::ExpandListArgument(vsSDKReferences, sdkReferences);
  3401. this->WriteString("<ItemGroup>\n", 1);
  3402. hasWrittenItemGroup = true;
  3403. for (std::vector<std::string>::iterator ri = sdkReferences.begin();
  3404. ri != sdkReferences.end(); ++ri) {
  3405. this->WriteString("<SDKReference Include=\"", 2);
  3406. (*this->BuildFileStream) << cmVS10EscapeXML(*ri) << "\"/>\n";
  3407. }
  3408. }
  3409. // This only applies to Windows 10 apps
  3410. if (this->GlobalGenerator->TargetsWindowsStore() &&
  3411. cmHasLiteralPrefix(this->GlobalGenerator->GetSystemVersion(), "10.0")) {
  3412. const char* desktopExtensionsVersion =
  3413. this->GeneratorTarget->GetProperty("VS_DESKTOP_EXTENSIONS_VERSION");
  3414. const char* mobileExtensionsVersion =
  3415. this->GeneratorTarget->GetProperty("VS_MOBILE_EXTENSIONS_VERSION");
  3416. const char* iotExtensionsVersion =
  3417. this->GeneratorTarget->GetProperty("VS_IOT_EXTENSIONS_VERSION");
  3418. if (desktopExtensionsVersion || mobileExtensionsVersion ||
  3419. iotExtensionsVersion) {
  3420. if (!hasWrittenItemGroup) {
  3421. this->WriteString("<ItemGroup>\n", 1);
  3422. hasWrittenItemGroup = true;
  3423. }
  3424. if (desktopExtensionsVersion) {
  3425. this->WriteSingleSDKReference("WindowsDesktop",
  3426. desktopExtensionsVersion);
  3427. }
  3428. if (mobileExtensionsVersion) {
  3429. this->WriteSingleSDKReference("WindowsMobile",
  3430. mobileExtensionsVersion);
  3431. }
  3432. if (iotExtensionsVersion) {
  3433. this->WriteSingleSDKReference("WindowsIoT", iotExtensionsVersion);
  3434. }
  3435. }
  3436. }
  3437. if (hasWrittenItemGroup) {
  3438. this->WriteString("</ItemGroup>\n", 1);
  3439. }
  3440. }
  3441. void cmVisualStudio10TargetGenerator::WriteSingleSDKReference(
  3442. std::string const& extension, std::string const& version)
  3443. {
  3444. this->WriteString("<SDKReference Include=\"", 2);
  3445. (*this->BuildFileStream) << extension << ", Version=" << version
  3446. << "\" />\n";
  3447. }
  3448. void cmVisualStudio10TargetGenerator::WriteWinRTPackageCertificateKeyFile()
  3449. {
  3450. if ((this->GlobalGenerator->TargetsWindowsStore() ||
  3451. this->GlobalGenerator->TargetsWindowsPhone()) &&
  3452. (cmStateEnums::EXECUTABLE == this->GeneratorTarget->GetType())) {
  3453. std::string pfxFile;
  3454. std::vector<cmSourceFile const*> certificates;
  3455. this->GeneratorTarget->GetCertificates(certificates, "");
  3456. for (std::vector<cmSourceFile const*>::const_iterator si =
  3457. certificates.begin();
  3458. si != certificates.end(); ++si) {
  3459. pfxFile = this->ConvertPath((*si)->GetFullPath(), false);
  3460. this->ConvertToWindowsSlash(pfxFile);
  3461. break;
  3462. }
  3463. if (this->IsMissingFiles &&
  3464. !(this->GlobalGenerator->TargetsWindowsPhone() &&
  3465. this->GlobalGenerator->GetSystemVersion() == "8.0")) {
  3466. // Move the manifest to a project directory to avoid clashes
  3467. std::string artifactDir =
  3468. this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
  3469. this->ConvertToWindowsSlash(artifactDir);
  3470. this->WriteString("<PropertyGroup>\n", 1);
  3471. this->WriteString("<AppxPackageArtifactsDir>", 2);
  3472. (*this->BuildFileStream) << cmVS10EscapeXML(artifactDir)
  3473. << "\\</AppxPackageArtifactsDir>\n";
  3474. this->WriteString("<ProjectPriFullPath>", 2);
  3475. std::string resourcePriFile =
  3476. this->DefaultArtifactDir + "/resources.pri";
  3477. this->ConvertToWindowsSlash(resourcePriFile);
  3478. (*this->BuildFileStream) << resourcePriFile << "</ProjectPriFullPath>\n";
  3479. // If we are missing files and we don't have a certificate and
  3480. // aren't targeting WP8.0, add a default certificate
  3481. if (pfxFile.empty()) {
  3482. std::string templateFolder =
  3483. cmSystemTools::GetCMakeRoot() + "/Templates/Windows";
  3484. pfxFile = this->DefaultArtifactDir + "/Windows_TemporaryKey.pfx";
  3485. cmSystemTools::CopyAFile(templateFolder + "/Windows_TemporaryKey.pfx",
  3486. pfxFile, false);
  3487. this->ConvertToWindowsSlash(pfxFile);
  3488. this->AddedFiles.push_back(pfxFile);
  3489. }
  3490. this->WriteString("<", 2);
  3491. (*this->BuildFileStream) << "PackageCertificateKeyFile>" << pfxFile
  3492. << "</PackageCertificateKeyFile>\n";
  3493. std::string thumb = cmSystemTools::ComputeCertificateThumbprint(pfxFile);
  3494. if (!thumb.empty()) {
  3495. this->WriteString("<PackageCertificateThumbprint>", 2);
  3496. (*this->BuildFileStream) << thumb
  3497. << "</PackageCertificateThumbprint>\n";
  3498. }
  3499. this->WriteString("</PropertyGroup>\n", 1);
  3500. } else if (!pfxFile.empty()) {
  3501. this->WriteString("<PropertyGroup>\n", 1);
  3502. this->WriteString("<", 2);
  3503. (*this->BuildFileStream) << "PackageCertificateKeyFile>" << pfxFile
  3504. << "</PackageCertificateKeyFile>\n";
  3505. std::string thumb = cmSystemTools::ComputeCertificateThumbprint(pfxFile);
  3506. if (!thumb.empty()) {
  3507. this->WriteString("<PackageCertificateThumbprint>", 2);
  3508. (*this->BuildFileStream) << thumb
  3509. << "</PackageCertificateThumbprint>\n";
  3510. }
  3511. this->WriteString("</PropertyGroup>\n", 1);
  3512. }
  3513. }
  3514. }
  3515. bool cmVisualStudio10TargetGenerator::IsResxHeader(
  3516. const std::string& headerFile)
  3517. {
  3518. std::set<std::string> expectedResxHeaders;
  3519. this->GeneratorTarget->GetExpectedResxHeaders(expectedResxHeaders, "");
  3520. std::set<std::string>::const_iterator it =
  3521. expectedResxHeaders.find(headerFile);
  3522. return it != expectedResxHeaders.end();
  3523. }
  3524. bool cmVisualStudio10TargetGenerator::IsXamlHeader(
  3525. const std::string& headerFile)
  3526. {
  3527. std::set<std::string> expectedXamlHeaders;
  3528. this->GeneratorTarget->GetExpectedXamlHeaders(expectedXamlHeaders, "");
  3529. std::set<std::string>::const_iterator it =
  3530. expectedXamlHeaders.find(headerFile);
  3531. return it != expectedXamlHeaders.end();
  3532. }
  3533. bool cmVisualStudio10TargetGenerator::IsXamlSource(
  3534. const std::string& sourceFile)
  3535. {
  3536. std::set<std::string> expectedXamlSources;
  3537. this->GeneratorTarget->GetExpectedXamlSources(expectedXamlSources, "");
  3538. std::set<std::string>::const_iterator it =
  3539. expectedXamlSources.find(sourceFile);
  3540. return it != expectedXamlSources.end();
  3541. }
  3542. void cmVisualStudio10TargetGenerator::WriteApplicationTypeSettings()
  3543. {
  3544. cmGlobalVisualStudio10Generator* gg =
  3545. static_cast<cmGlobalVisualStudio10Generator*>(this->GlobalGenerator);
  3546. bool isAppContainer = false;
  3547. bool const isWindowsPhone = this->GlobalGenerator->TargetsWindowsPhone();
  3548. bool const isWindowsStore = this->GlobalGenerator->TargetsWindowsStore();
  3549. std::string const& v = this->GlobalGenerator->GetSystemVersion();
  3550. if (isWindowsPhone || isWindowsStore) {
  3551. this->WriteString("<ApplicationType>", 2);
  3552. (*this->BuildFileStream)
  3553. << (isWindowsPhone ? "Windows Phone" : "Windows Store")
  3554. << "</ApplicationType>\n";
  3555. this->WriteString("<DefaultLanguage>en-US"
  3556. "</DefaultLanguage>\n",
  3557. 2);
  3558. if (cmHasLiteralPrefix(v, "10.0")) {
  3559. this->WriteString("<ApplicationTypeRevision>", 2);
  3560. (*this->BuildFileStream) << cmVS10EscapeXML("10.0")
  3561. << "</ApplicationTypeRevision>\n";
  3562. // Visual Studio 14.0 is necessary for building 10.0 apps
  3563. this->WriteString("<MinimumVisualStudioVersion>14.0"
  3564. "</MinimumVisualStudioVersion>\n",
  3565. 2);
  3566. if (this->GeneratorTarget->GetType() < cmStateEnums::UTILITY) {
  3567. isAppContainer = true;
  3568. }
  3569. } else if (v == "8.1") {
  3570. this->WriteString("<ApplicationTypeRevision>", 2);
  3571. (*this->BuildFileStream) << cmVS10EscapeXML(v)
  3572. << "</ApplicationTypeRevision>\n";
  3573. // Visual Studio 12.0 is necessary for building 8.1 apps
  3574. this->WriteString("<MinimumVisualStudioVersion>12.0"
  3575. "</MinimumVisualStudioVersion>\n",
  3576. 2);
  3577. if (this->GeneratorTarget->GetType() < cmStateEnums::UTILITY) {
  3578. isAppContainer = true;
  3579. }
  3580. } else if (v == "8.0") {
  3581. this->WriteString("<ApplicationTypeRevision>", 2);
  3582. (*this->BuildFileStream) << cmVS10EscapeXML(v)
  3583. << "</ApplicationTypeRevision>\n";
  3584. // Visual Studio 11.0 is necessary for building 8.0 apps
  3585. this->WriteString("<MinimumVisualStudioVersion>11.0"
  3586. "</MinimumVisualStudioVersion>\n",
  3587. 2);
  3588. if (isWindowsStore &&
  3589. this->GeneratorTarget->GetType() < cmStateEnums::UTILITY) {
  3590. isAppContainer = true;
  3591. } else if (isWindowsPhone &&
  3592. this->GeneratorTarget->GetType() ==
  3593. cmStateEnums::EXECUTABLE) {
  3594. this->WriteString("<XapOutputs>true</XapOutputs>\n", 2);
  3595. this->WriteString("<XapFilename>", 2);
  3596. (*this->BuildFileStream)
  3597. << cmVS10EscapeXML(this->Name)
  3598. << "_$(Configuration)_$(Platform).xap</XapFilename>\n";
  3599. }
  3600. }
  3601. }
  3602. if (isAppContainer) {
  3603. this->WriteString("<AppContainerApplication>true"
  3604. "</AppContainerApplication>\n",
  3605. 2);
  3606. } else if (this->Platform == "ARM") {
  3607. this->WriteString("<WindowsSDKDesktopARMSupport>true"
  3608. "</WindowsSDKDesktopARMSupport>\n",
  3609. 2);
  3610. }
  3611. std::string const& targetPlatformVersion =
  3612. gg->GetWindowsTargetPlatformVersion();
  3613. if (!targetPlatformVersion.empty()) {
  3614. this->WriteString("<WindowsTargetPlatformVersion>", 2);
  3615. (*this->BuildFileStream) << cmVS10EscapeXML(targetPlatformVersion)
  3616. << "</WindowsTargetPlatformVersion>\n";
  3617. }
  3618. const char* targetPlatformMinVersion = this->GeneratorTarget->GetProperty(
  3619. "VS_WINDOWS_TARGET_PLATFORM_MIN_VERSION");
  3620. if (targetPlatformMinVersion) {
  3621. this->WriteString("<WindowsTargetPlatformMinVersion>", 2);
  3622. (*this->BuildFileStream) << cmVS10EscapeXML(targetPlatformMinVersion)
  3623. << "</WindowsTargetPlatformMinVersion>\n";
  3624. } else if (isWindowsStore && cmHasLiteralPrefix(v, "10.0")) {
  3625. // If the min version is not set, then use the TargetPlatformVersion
  3626. if (!targetPlatformVersion.empty()) {
  3627. this->WriteString("<WindowsTargetPlatformMinVersion>", 2);
  3628. (*this->BuildFileStream) << cmVS10EscapeXML(targetPlatformVersion)
  3629. << "</WindowsTargetPlatformMinVersion>\n";
  3630. }
  3631. }
  3632. // Added IoT Startup Task support
  3633. if (this->GeneratorTarget->GetPropertyAsBool("VS_IOT_STARTUP_TASK")) {
  3634. this->WriteString("<ContainsStartupTask>true</ContainsStartupTask>\n", 2);
  3635. }
  3636. }
  3637. void cmVisualStudio10TargetGenerator::VerifyNecessaryFiles()
  3638. {
  3639. // For Windows and Windows Phone executables, we will assume that if a
  3640. // manifest is not present that we need to add all the necessary files
  3641. if (this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE) {
  3642. std::vector<cmSourceFile const*> manifestSources;
  3643. this->GeneratorTarget->GetAppManifest(manifestSources, "");
  3644. {
  3645. std::string const& v = this->GlobalGenerator->GetSystemVersion();
  3646. if (this->GlobalGenerator->TargetsWindowsPhone()) {
  3647. if (v == "8.0") {
  3648. // Look through the sources for WMAppManifest.xml
  3649. std::vector<cmSourceFile const*> extraSources;
  3650. this->GeneratorTarget->GetExtraSources(extraSources, "");
  3651. bool foundManifest = false;
  3652. for (std::vector<cmSourceFile const*>::const_iterator si =
  3653. extraSources.begin();
  3654. si != extraSources.end(); ++si) {
  3655. // Need to do a lowercase comparison on the filename
  3656. if ("wmappmanifest.xml" ==
  3657. cmSystemTools::LowerCase((*si)->GetLocation().GetName())) {
  3658. foundManifest = true;
  3659. break;
  3660. }
  3661. }
  3662. if (!foundManifest) {
  3663. this->IsMissingFiles = true;
  3664. }
  3665. } else if (v == "8.1") {
  3666. if (manifestSources.empty()) {
  3667. this->IsMissingFiles = true;
  3668. }
  3669. }
  3670. } else if (this->GlobalGenerator->TargetsWindowsStore()) {
  3671. if (manifestSources.empty()) {
  3672. if (v == "8.0") {
  3673. this->IsMissingFiles = true;
  3674. } else if (v == "8.1" || cmHasLiteralPrefix(v, "10.0")) {
  3675. this->IsMissingFiles = true;
  3676. }
  3677. }
  3678. }
  3679. }
  3680. }
  3681. }
  3682. void cmVisualStudio10TargetGenerator::WriteMissingFiles()
  3683. {
  3684. std::string const& v = this->GlobalGenerator->GetSystemVersion();
  3685. if (this->GlobalGenerator->TargetsWindowsPhone()) {
  3686. if (v == "8.0") {
  3687. this->WriteMissingFilesWP80();
  3688. } else if (v == "8.1") {
  3689. this->WriteMissingFilesWP81();
  3690. }
  3691. } else if (this->GlobalGenerator->TargetsWindowsStore()) {
  3692. if (v == "8.0") {
  3693. this->WriteMissingFilesWS80();
  3694. } else if (v == "8.1") {
  3695. this->WriteMissingFilesWS81();
  3696. } else if (cmHasLiteralPrefix(v, "10.0")) {
  3697. this->WriteMissingFilesWS10_0();
  3698. }
  3699. }
  3700. }
  3701. void cmVisualStudio10TargetGenerator::WriteMissingFilesWP80()
  3702. {
  3703. std::string templateFolder =
  3704. cmSystemTools::GetCMakeRoot() + "/Templates/Windows";
  3705. // For WP80, the manifest needs to be in the same folder as the project
  3706. // this can cause an overwrite problem if projects aren't organized in
  3707. // folders
  3708. std::string manifestFile =
  3709. this->LocalGenerator->GetCurrentBinaryDirectory() +
  3710. std::string("/WMAppManifest.xml");
  3711. std::string artifactDir =
  3712. this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
  3713. this->ConvertToWindowsSlash(artifactDir);
  3714. std::string artifactDirXML = cmVS10EscapeXML(artifactDir);
  3715. std::string targetNameXML =
  3716. cmVS10EscapeXML(this->GeneratorTarget->GetName());
  3717. cmGeneratedFileStream fout(manifestFile.c_str());
  3718. fout.SetCopyIfDifferent(true);
  3719. /* clang-format off */
  3720. fout <<
  3721. "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
  3722. "<Deployment"
  3723. " xmlns=\"http://schemas.microsoft.com/windowsphone/2012/deployment\""
  3724. " AppPlatformVersion=\"8.0\">\n"
  3725. "\t<DefaultLanguage xmlns=\"\" code=\"en-US\"/>\n"
  3726. "\t<App xmlns=\"\" ProductID=\"{" << this->GUID << "}\""
  3727. " Title=\"CMake Test Program\" RuntimeType=\"Modern Native\""
  3728. " Version=\"1.0.0.0\" Genre=\"apps.normal\" Author=\"CMake\""
  3729. " Description=\"Default CMake App\" Publisher=\"CMake\""
  3730. " PublisherID=\"{" << this->GUID << "}\">\n"
  3731. "\t\t<IconPath IsRelative=\"true\" IsResource=\"false\">"
  3732. << artifactDirXML << "\\ApplicationIcon.png</IconPath>\n"
  3733. "\t\t<Capabilities/>\n"
  3734. "\t\t<Tasks>\n"
  3735. "\t\t\t<DefaultTask Name=\"_default\""
  3736. " ImagePath=\"" << targetNameXML << ".exe\" ImageParams=\"\" />\n"
  3737. "\t\t</Tasks>\n"
  3738. "\t\t<Tokens>\n"
  3739. "\t\t\t<PrimaryToken TokenID=\"" << targetNameXML << "Token\""
  3740. " TaskName=\"_default\">\n"
  3741. "\t\t\t\t<TemplateFlip>\n"
  3742. "\t\t\t\t\t<SmallImageURI IsRelative=\"true\" IsResource=\"false\">"
  3743. << artifactDirXML << "\\SmallLogo.png</SmallImageURI>\n"
  3744. "\t\t\t\t\t<Count>0</Count>\n"
  3745. "\t\t\t\t\t<BackgroundImageURI IsRelative=\"true\" IsResource=\"false\">"
  3746. << artifactDirXML << "\\Logo.png</BackgroundImageURI>\n"
  3747. "\t\t\t\t</TemplateFlip>\n"
  3748. "\t\t\t</PrimaryToken>\n"
  3749. "\t\t</Tokens>\n"
  3750. "\t\t<ScreenResolutions>\n"
  3751. "\t\t\t<ScreenResolution Name=\"ID_RESOLUTION_WVGA\" />\n"
  3752. "\t\t</ScreenResolutions>\n"
  3753. "\t</App>\n"
  3754. "</Deployment>\n";
  3755. /* clang-format on */
  3756. std::string sourceFile = this->ConvertPath(manifestFile, false);
  3757. this->ConvertToWindowsSlash(sourceFile);
  3758. this->WriteString("<Xml Include=\"", 2);
  3759. (*this->BuildFileStream) << cmVS10EscapeXML(sourceFile) << "\">\n";
  3760. this->WriteString("<SubType>Designer</SubType>\n", 3);
  3761. this->WriteString("</Xml>\n", 2);
  3762. this->AddedFiles.push_back(sourceFile);
  3763. std::string smallLogo = this->DefaultArtifactDir + "/SmallLogo.png";
  3764. cmSystemTools::CopyAFile(templateFolder + "/SmallLogo.png", smallLogo,
  3765. false);
  3766. this->ConvertToWindowsSlash(smallLogo);
  3767. this->WriteString("<Image Include=\"", 2);
  3768. (*this->BuildFileStream) << cmVS10EscapeXML(smallLogo) << "\" />\n";
  3769. this->AddedFiles.push_back(smallLogo);
  3770. std::string logo = this->DefaultArtifactDir + "/Logo.png";
  3771. cmSystemTools::CopyAFile(templateFolder + "/Logo.png", logo, false);
  3772. this->ConvertToWindowsSlash(logo);
  3773. this->WriteString("<Image Include=\"", 2);
  3774. (*this->BuildFileStream) << cmVS10EscapeXML(logo) << "\" />\n";
  3775. this->AddedFiles.push_back(logo);
  3776. std::string applicationIcon =
  3777. this->DefaultArtifactDir + "/ApplicationIcon.png";
  3778. cmSystemTools::CopyAFile(templateFolder + "/ApplicationIcon.png",
  3779. applicationIcon, false);
  3780. this->ConvertToWindowsSlash(applicationIcon);
  3781. this->WriteString("<Image Include=\"", 2);
  3782. (*this->BuildFileStream) << cmVS10EscapeXML(applicationIcon) << "\" />\n";
  3783. this->AddedFiles.push_back(applicationIcon);
  3784. }
  3785. void cmVisualStudio10TargetGenerator::WriteMissingFilesWP81()
  3786. {
  3787. std::string manifestFile =
  3788. this->DefaultArtifactDir + "/package.appxManifest";
  3789. std::string artifactDir =
  3790. this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
  3791. this->ConvertToWindowsSlash(artifactDir);
  3792. std::string artifactDirXML = cmVS10EscapeXML(artifactDir);
  3793. std::string targetNameXML =
  3794. cmVS10EscapeXML(this->GeneratorTarget->GetName());
  3795. cmGeneratedFileStream fout(manifestFile.c_str());
  3796. fout.SetCopyIfDifferent(true);
  3797. /* clang-format off */
  3798. fout <<
  3799. "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
  3800. "<Package xmlns=\"http://schemas.microsoft.com/appx/2010/manifest\""
  3801. " xmlns:m2=\"http://schemas.microsoft.com/appx/2013/manifest\""
  3802. " xmlns:mp=\"http://schemas.microsoft.com/appx/2014/phone/manifest\">\n"
  3803. "\t<Identity Name=\"" << this->GUID << "\" Publisher=\"CN=CMake\""
  3804. " Version=\"1.0.0.0\" />\n"
  3805. "\t<mp:PhoneIdentity PhoneProductId=\"" << this->GUID << "\""
  3806. " PhonePublisherId=\"00000000-0000-0000-0000-000000000000\"/>\n"
  3807. "\t<Properties>\n"
  3808. "\t\t<DisplayName>" << targetNameXML << "</DisplayName>\n"
  3809. "\t\t<PublisherDisplayName>CMake</PublisherDisplayName>\n"
  3810. "\t\t<Logo>" << artifactDirXML << "\\StoreLogo.png</Logo>\n"
  3811. "\t</Properties>\n"
  3812. "\t<Prerequisites>\n"
  3813. "\t\t<OSMinVersion>6.3.1</OSMinVersion>\n"
  3814. "\t\t<OSMaxVersionTested>6.3.1</OSMaxVersionTested>\n"
  3815. "\t</Prerequisites>\n"
  3816. "\t<Resources>\n"
  3817. "\t\t<Resource Language=\"x-generate\" />\n"
  3818. "\t</Resources>\n"
  3819. "\t<Applications>\n"
  3820. "\t\t<Application Id=\"App\""
  3821. " Executable=\"" << targetNameXML << ".exe\""
  3822. " EntryPoint=\"" << targetNameXML << ".App\">\n"
  3823. "\t\t\t<m2:VisualElements\n"
  3824. "\t\t\t\tDisplayName=\"" << targetNameXML << "\"\n"
  3825. "\t\t\t\tDescription=\"" << targetNameXML << "\"\n"
  3826. "\t\t\t\tBackgroundColor=\"#336699\"\n"
  3827. "\t\t\t\tForegroundText=\"light\"\n"
  3828. "\t\t\t\tSquare150x150Logo=\"" << artifactDirXML << "\\Logo.png\"\n"
  3829. "\t\t\t\tSquare30x30Logo=\"" << artifactDirXML << "\\SmallLogo.png\">\n"
  3830. "\t\t\t\t<m2:DefaultTile ShortName=\"" << targetNameXML << "\">\n"
  3831. "\t\t\t\t\t<m2:ShowNameOnTiles>\n"
  3832. "\t\t\t\t\t\t<m2:ShowOn Tile=\"square150x150Logo\" />\n"
  3833. "\t\t\t\t\t</m2:ShowNameOnTiles>\n"
  3834. "\t\t\t\t</m2:DefaultTile>\n"
  3835. "\t\t\t\t<m2:SplashScreen"
  3836. " Image=\"" << artifactDirXML << "\\SplashScreen.png\" />\n"
  3837. "\t\t\t</m2:VisualElements>\n"
  3838. "\t\t</Application>\n"
  3839. "\t</Applications>\n"
  3840. "</Package>\n";
  3841. /* clang-format on */
  3842. this->WriteCommonMissingFiles(manifestFile);
  3843. }
  3844. void cmVisualStudio10TargetGenerator::WriteMissingFilesWS80()
  3845. {
  3846. std::string manifestFile =
  3847. this->DefaultArtifactDir + "/package.appxManifest";
  3848. std::string artifactDir =
  3849. this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
  3850. this->ConvertToWindowsSlash(artifactDir);
  3851. std::string artifactDirXML = cmVS10EscapeXML(artifactDir);
  3852. std::string targetNameXML =
  3853. cmVS10EscapeXML(this->GeneratorTarget->GetName());
  3854. cmGeneratedFileStream fout(manifestFile.c_str());
  3855. fout.SetCopyIfDifferent(true);
  3856. /* clang-format off */
  3857. fout <<
  3858. "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
  3859. "<Package xmlns=\"http://schemas.microsoft.com/appx/2010/manifest\">\n"
  3860. "\t<Identity Name=\"" << this->GUID << "\" Publisher=\"CN=CMake\""
  3861. " Version=\"1.0.0.0\" />\n"
  3862. "\t<Properties>\n"
  3863. "\t\t<DisplayName>" << targetNameXML << "</DisplayName>\n"
  3864. "\t\t<PublisherDisplayName>CMake</PublisherDisplayName>\n"
  3865. "\t\t<Logo>" << artifactDirXML << "\\StoreLogo.png</Logo>\n"
  3866. "\t</Properties>\n"
  3867. "\t<Prerequisites>\n"
  3868. "\t\t<OSMinVersion>6.2.1</OSMinVersion>\n"
  3869. "\t\t<OSMaxVersionTested>6.2.1</OSMaxVersionTested>\n"
  3870. "\t</Prerequisites>\n"
  3871. "\t<Resources>\n"
  3872. "\t\t<Resource Language=\"x-generate\" />\n"
  3873. "\t</Resources>\n"
  3874. "\t<Applications>\n"
  3875. "\t\t<Application Id=\"App\""
  3876. " Executable=\"" << targetNameXML << ".exe\""
  3877. " EntryPoint=\"" << targetNameXML << ".App\">\n"
  3878. "\t\t\t<VisualElements"
  3879. " DisplayName=\"" << targetNameXML << "\""
  3880. " Description=\"" << targetNameXML << "\""
  3881. " BackgroundColor=\"#336699\" ForegroundText=\"light\""
  3882. " Logo=\"" << artifactDirXML << "\\Logo.png\""
  3883. " SmallLogo=\"" << artifactDirXML << "\\SmallLogo.png\">\n"
  3884. "\t\t\t\t<DefaultTile ShowName=\"allLogos\""
  3885. " ShortName=\"" << targetNameXML << "\" />\n"
  3886. "\t\t\t\t<SplashScreen"
  3887. " Image=\"" << artifactDirXML << "\\SplashScreen.png\" />\n"
  3888. "\t\t\t</VisualElements>\n"
  3889. "\t\t</Application>\n"
  3890. "\t</Applications>\n"
  3891. "</Package>\n";
  3892. /* clang-format on */
  3893. this->WriteCommonMissingFiles(manifestFile);
  3894. }
  3895. void cmVisualStudio10TargetGenerator::WriteMissingFilesWS81()
  3896. {
  3897. std::string manifestFile =
  3898. this->DefaultArtifactDir + "/package.appxManifest";
  3899. std::string artifactDir =
  3900. this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
  3901. this->ConvertToWindowsSlash(artifactDir);
  3902. std::string artifactDirXML = cmVS10EscapeXML(artifactDir);
  3903. std::string targetNameXML =
  3904. cmVS10EscapeXML(this->GeneratorTarget->GetName());
  3905. cmGeneratedFileStream fout(manifestFile.c_str());
  3906. fout.SetCopyIfDifferent(true);
  3907. /* clang-format off */
  3908. fout <<
  3909. "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
  3910. "<Package xmlns=\"http://schemas.microsoft.com/appx/2010/manifest\""
  3911. " xmlns:m2=\"http://schemas.microsoft.com/appx/2013/manifest\">\n"
  3912. "\t<Identity Name=\"" << this->GUID << "\" Publisher=\"CN=CMake\""
  3913. " Version=\"1.0.0.0\" />\n"
  3914. "\t<Properties>\n"
  3915. "\t\t<DisplayName>" << targetNameXML << "</DisplayName>\n"
  3916. "\t\t<PublisherDisplayName>CMake</PublisherDisplayName>\n"
  3917. "\t\t<Logo>" << artifactDirXML << "\\StoreLogo.png</Logo>\n"
  3918. "\t</Properties>\n"
  3919. "\t<Prerequisites>\n"
  3920. "\t\t<OSMinVersion>6.3</OSMinVersion>\n"
  3921. "\t\t<OSMaxVersionTested>6.3</OSMaxVersionTested>\n"
  3922. "\t</Prerequisites>\n"
  3923. "\t<Resources>\n"
  3924. "\t\t<Resource Language=\"x-generate\" />\n"
  3925. "\t</Resources>\n"
  3926. "\t<Applications>\n"
  3927. "\t\t<Application Id=\"App\""
  3928. " Executable=\"" << targetNameXML << ".exe\""
  3929. " EntryPoint=\"" << targetNameXML << ".App\">\n"
  3930. "\t\t\t<m2:VisualElements\n"
  3931. "\t\t\t\tDisplayName=\"" << targetNameXML << "\"\n"
  3932. "\t\t\t\tDescription=\"" << targetNameXML << "\"\n"
  3933. "\t\t\t\tBackgroundColor=\"#336699\"\n"
  3934. "\t\t\t\tForegroundText=\"light\"\n"
  3935. "\t\t\t\tSquare150x150Logo=\"" << artifactDirXML << "\\Logo.png\"\n"
  3936. "\t\t\t\tSquare30x30Logo=\"" << artifactDirXML << "\\SmallLogo.png\">\n"
  3937. "\t\t\t\t<m2:DefaultTile ShortName=\"" << targetNameXML << "\">\n"
  3938. "\t\t\t\t\t<m2:ShowNameOnTiles>\n"
  3939. "\t\t\t\t\t\t<m2:ShowOn Tile=\"square150x150Logo\" />\n"
  3940. "\t\t\t\t\t</m2:ShowNameOnTiles>\n"
  3941. "\t\t\t\t</m2:DefaultTile>\n"
  3942. "\t\t\t\t<m2:SplashScreen"
  3943. " Image=\"" << artifactDirXML << "\\SplashScreen.png\" />\n"
  3944. "\t\t\t</m2:VisualElements>\n"
  3945. "\t\t</Application>\n"
  3946. "\t</Applications>\n"
  3947. "</Package>\n";
  3948. /* clang-format on */
  3949. this->WriteCommonMissingFiles(manifestFile);
  3950. }
  3951. void cmVisualStudio10TargetGenerator::WriteMissingFilesWS10_0()
  3952. {
  3953. std::string manifestFile =
  3954. this->DefaultArtifactDir + "/package.appxManifest";
  3955. std::string artifactDir =
  3956. this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
  3957. this->ConvertToWindowsSlash(artifactDir);
  3958. std::string artifactDirXML = cmVS10EscapeXML(artifactDir);
  3959. std::string targetNameXML =
  3960. cmVS10EscapeXML(this->GeneratorTarget->GetName());
  3961. cmGeneratedFileStream fout(manifestFile.c_str());
  3962. fout.SetCopyIfDifferent(true);
  3963. /* clang-format off */
  3964. fout <<
  3965. "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
  3966. "<Package\n\t"
  3967. "xmlns=\"http://schemas.microsoft.com/appx/manifest/foundation/windows10\""
  3968. "\txmlns:mp=\"http://schemas.microsoft.com/appx/2014/phone/manifest\"\n"
  3969. "\txmlns:uap=\"http://schemas.microsoft.com/appx/manifest/uap/windows10\""
  3970. "\n\tIgnorableNamespaces=\"uap mp\">\n\n"
  3971. "\t<Identity Name=\"" << this->GUID << "\" Publisher=\"CN=CMake\""
  3972. " Version=\"1.0.0.0\" />\n"
  3973. "\t<mp:PhoneIdentity PhoneProductId=\"" << this->GUID <<
  3974. "\" PhonePublisherId=\"00000000-0000-0000-0000-000000000000\"/>\n"
  3975. "\t<Properties>\n"
  3976. "\t\t<DisplayName>" << targetNameXML << "</DisplayName>\n"
  3977. "\t\t<PublisherDisplayName>CMake</PublisherDisplayName>\n"
  3978. "\t\t<Logo>" << artifactDirXML << "\\StoreLogo.png</Logo>\n"
  3979. "\t</Properties>\n"
  3980. "\t<Dependencies>\n"
  3981. "\t\t<TargetDeviceFamily Name=\"Windows.Universal\" "
  3982. "MinVersion=\"10.0.0.0\" MaxVersionTested=\"10.0.0.0\" />\n"
  3983. "\t</Dependencies>\n"
  3984. "\t<Resources>\n"
  3985. "\t\t<Resource Language=\"x-generate\" />\n"
  3986. "\t</Resources>\n"
  3987. "\t<Applications>\n"
  3988. "\t\t<Application Id=\"App\""
  3989. " Executable=\"" << targetNameXML << ".exe\""
  3990. " EntryPoint=\"" << targetNameXML << ".App\">\n"
  3991. "\t\t\t<uap:VisualElements\n"
  3992. "\t\t\t\tDisplayName=\"" << targetNameXML << "\"\n"
  3993. "\t\t\t\tDescription=\"" << targetNameXML << "\"\n"
  3994. "\t\t\t\tBackgroundColor=\"#336699\"\n"
  3995. "\t\t\t\tSquare150x150Logo=\"" << artifactDirXML << "\\Logo.png\"\n"
  3996. "\t\t\t\tSquare44x44Logo=\"" << artifactDirXML <<
  3997. "\\SmallLogo44x44.png\">\n"
  3998. "\t\t\t\t<uap:SplashScreen"
  3999. " Image=\"" << artifactDirXML << "\\SplashScreen.png\" />\n"
  4000. "\t\t\t</uap:VisualElements>\n"
  4001. "\t\t</Application>\n"
  4002. "\t</Applications>\n"
  4003. "</Package>\n";
  4004. /* clang-format on */
  4005. this->WriteCommonMissingFiles(manifestFile);
  4006. }
  4007. void cmVisualStudio10TargetGenerator::WriteCommonMissingFiles(
  4008. const std::string& manifestFile)
  4009. {
  4010. std::string templateFolder =
  4011. cmSystemTools::GetCMakeRoot() + "/Templates/Windows";
  4012. std::string sourceFile = this->ConvertPath(manifestFile, false);
  4013. this->ConvertToWindowsSlash(sourceFile);
  4014. this->WriteString("<AppxManifest Include=\"", 2);
  4015. (*this->BuildFileStream) << cmVS10EscapeXML(sourceFile) << "\">\n";
  4016. this->WriteString("<SubType>Designer</SubType>\n", 3);
  4017. this->WriteString("</AppxManifest>\n", 2);
  4018. this->AddedFiles.push_back(sourceFile);
  4019. std::string smallLogo = this->DefaultArtifactDir + "/SmallLogo.png";
  4020. cmSystemTools::CopyAFile(templateFolder + "/SmallLogo.png", smallLogo,
  4021. false);
  4022. this->ConvertToWindowsSlash(smallLogo);
  4023. this->WriteString("<Image Include=\"", 2);
  4024. (*this->BuildFileStream) << cmVS10EscapeXML(smallLogo) << "\" />\n";
  4025. this->AddedFiles.push_back(smallLogo);
  4026. std::string smallLogo44 = this->DefaultArtifactDir + "/SmallLogo44x44.png";
  4027. cmSystemTools::CopyAFile(templateFolder + "/SmallLogo44x44.png", smallLogo44,
  4028. false);
  4029. this->ConvertToWindowsSlash(smallLogo44);
  4030. this->WriteString("<Image Include=\"", 2);
  4031. (*this->BuildFileStream) << cmVS10EscapeXML(smallLogo44) << "\" />\n";
  4032. this->AddedFiles.push_back(smallLogo44);
  4033. std::string logo = this->DefaultArtifactDir + "/Logo.png";
  4034. cmSystemTools::CopyAFile(templateFolder + "/Logo.png", logo, false);
  4035. this->ConvertToWindowsSlash(logo);
  4036. this->WriteString("<Image Include=\"", 2);
  4037. (*this->BuildFileStream) << cmVS10EscapeXML(logo) << "\" />\n";
  4038. this->AddedFiles.push_back(logo);
  4039. std::string storeLogo = this->DefaultArtifactDir + "/StoreLogo.png";
  4040. cmSystemTools::CopyAFile(templateFolder + "/StoreLogo.png", storeLogo,
  4041. false);
  4042. this->ConvertToWindowsSlash(storeLogo);
  4043. this->WriteString("<Image Include=\"", 2);
  4044. (*this->BuildFileStream) << cmVS10EscapeXML(storeLogo) << "\" />\n";
  4045. this->AddedFiles.push_back(storeLogo);
  4046. std::string splashScreen = this->DefaultArtifactDir + "/SplashScreen.png";
  4047. cmSystemTools::CopyAFile(templateFolder + "/SplashScreen.png", splashScreen,
  4048. false);
  4049. this->ConvertToWindowsSlash(splashScreen);
  4050. this->WriteString("<Image Include=\"", 2);
  4051. (*this->BuildFileStream) << cmVS10EscapeXML(splashScreen) << "\" />\n";
  4052. this->AddedFiles.push_back(splashScreen);
  4053. // This file has already been added to the build so don't copy it
  4054. std::string keyFile = this->DefaultArtifactDir + "/Windows_TemporaryKey.pfx";
  4055. this->ConvertToWindowsSlash(keyFile);
  4056. this->WriteString("<None Include=\"", 2);
  4057. (*this->BuildFileStream) << cmVS10EscapeXML(keyFile) << "\" />\n";
  4058. }
  4059. bool cmVisualStudio10TargetGenerator::ForceOld(const std::string& source) const
  4060. {
  4061. HANDLE h =
  4062. CreateFileW(cmSystemTools::ConvertToWindowsExtendedPath(source).c_str(),
  4063. FILE_WRITE_ATTRIBUTES, FILE_SHARE_WRITE, 0, OPEN_EXISTING,
  4064. FILE_FLAG_BACKUP_SEMANTICS, 0);
  4065. if (!h) {
  4066. return false;
  4067. }
  4068. FILETIME const ftime_20010101 = { 3365781504u, 29389701u };
  4069. if (!SetFileTime(h, &ftime_20010101, &ftime_20010101, &ftime_20010101)) {
  4070. CloseHandle(h);
  4071. return false;
  4072. }
  4073. CloseHandle(h);
  4074. return true;
  4075. }
  4076. void cmVisualStudio10TargetGenerator::GetCSharpSourceProperties(
  4077. cmSourceFile const* sf, std::map<std::string, std::string>& tags)
  4078. {
  4079. if (this->ProjectType == csproj) {
  4080. const cmPropertyMap& props = sf->GetProperties();
  4081. for (cmPropertyMap::const_iterator p = props.begin(); p != props.end();
  4082. ++p) {
  4083. static const std::string propNamePrefix = "VS_CSHARP_";
  4084. if (p->first.find(propNamePrefix) == 0) {
  4085. std::string tagName = p->first.substr(propNamePrefix.length());
  4086. if (!tagName.empty()) {
  4087. const std::string val = props.GetPropertyValue(p->first);
  4088. if (!val.empty()) {
  4089. tags[tagName] = val;
  4090. } else {
  4091. tags.erase(tagName);
  4092. }
  4093. }
  4094. }
  4095. }
  4096. }
  4097. }
  4098. void cmVisualStudio10TargetGenerator::WriteCSharpSourceProperties(
  4099. const std::map<std::string, std::string>& tags)
  4100. {
  4101. if (!tags.empty()) {
  4102. for (std::map<std::string, std::string>::const_iterator i = tags.begin();
  4103. i != tags.end(); ++i) {
  4104. this->WriteString("<", 3);
  4105. (*this->BuildFileStream) << i->first << ">" << cmVS10EscapeXML(i->second)
  4106. << "</" << i->first << ">\n";
  4107. }
  4108. }
  4109. }
  4110. void cmVisualStudio10TargetGenerator::GetCSharpSourceLink(
  4111. cmSourceFile const* sf, std::string& link)
  4112. {
  4113. std::string f = sf->GetFullPath();
  4114. if (!this->InSourceBuild) {
  4115. const std::string stripFromPath =
  4116. this->Makefile->GetCurrentSourceDirectory();
  4117. if (f.find(stripFromPath) != std::string::npos) {
  4118. link = f.substr(stripFromPath.length() + 1);
  4119. if (const char* l = sf->GetProperty("VS_CSHARP_Link")) {
  4120. link = l;
  4121. }
  4122. this->ConvertToWindowsSlash(link);
  4123. }
  4124. }
  4125. }
  4126. std::string cmVisualStudio10TargetGenerator::GetCMakeFilePath(
  4127. const char* relativeFilePath) const
  4128. {
  4129. // Always search in the standard modules location.
  4130. std::string path = cmSystemTools::GetCMakeRoot() + "/";
  4131. path += relativeFilePath;
  4132. this->ConvertToWindowsSlash(path);
  4133. return path;
  4134. }