cmVisualStudio10TargetGenerator.cxx 156 KB

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