cmVisualStudio10TargetGenerator.cxx 159 KB

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