cmVisualStudio10TargetGenerator.cxx 161 KB

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