cmVisualStudio10TargetGenerator.cxx 155 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168
  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. this->WriteString("<ItemGroup>\n", 1);
  1253. for (std::set<cmSourceGroup*>::iterator g = groupsUsed.begin();
  1254. g != groupsUsed.end(); ++g) {
  1255. cmSourceGroup* sg = *g;
  1256. const char* name = sg->GetFullName();
  1257. if (strlen(name) != 0) {
  1258. this->WriteString("<Filter Include=\"", 2);
  1259. (*this->BuildFileStream) << name << "\">\n";
  1260. std::string guidName = "SG_Filter_";
  1261. guidName += name;
  1262. this->WriteString("<UniqueIdentifier>", 3);
  1263. std::string guid = this->GlobalGenerator->GetGUID(guidName.c_str());
  1264. (*this->BuildFileStream) << "{" << guid << "}"
  1265. << "</UniqueIdentifier>\n";
  1266. this->WriteString("</Filter>\n", 2);
  1267. }
  1268. }
  1269. if (!resxObjs.empty() || !this->AddedFiles.empty()) {
  1270. this->WriteString("<Filter Include=\"Resource Files\">\n", 2);
  1271. std::string guidName = "SG_Filter_Resource Files";
  1272. this->WriteString("<UniqueIdentifier>", 3);
  1273. std::string guid = this->GlobalGenerator->GetGUID(guidName.c_str());
  1274. (*this->BuildFileStream) << "{" << guid << "}"
  1275. << "</UniqueIdentifier>\n";
  1276. this->WriteString("<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;", 3);
  1277. (*this->BuildFileStream) << "gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;";
  1278. (*this->BuildFileStream) << "mfcribbon-ms</Extensions>\n";
  1279. this->WriteString("</Filter>\n", 2);
  1280. }
  1281. this->WriteString("</ItemGroup>\n", 1);
  1282. this->WriteString("</Project>\n", 0);
  1283. // restore stream pointer
  1284. this->BuildFileStream = save;
  1285. if (fout.Close()) {
  1286. this->GlobalGenerator->FileReplacedDuringGenerate(path);
  1287. }
  1288. }
  1289. // Add to groupsUsed empty source groups that have non-empty children.
  1290. void cmVisualStudio10TargetGenerator::AddMissingSourceGroups(
  1291. std::set<cmSourceGroup*>& groupsUsed,
  1292. const std::vector<cmSourceGroup>& allGroups)
  1293. {
  1294. for (std::vector<cmSourceGroup>::const_iterator current = allGroups.begin();
  1295. current != allGroups.end(); ++current) {
  1296. std::vector<cmSourceGroup> const& children = current->GetGroupChildren();
  1297. if (children.empty()) {
  1298. continue; // the group is really empty
  1299. }
  1300. this->AddMissingSourceGroups(groupsUsed, children);
  1301. cmSourceGroup* current_ptr = const_cast<cmSourceGroup*>(&(*current));
  1302. if (groupsUsed.find(current_ptr) != groupsUsed.end()) {
  1303. continue; // group has already been added to set
  1304. }
  1305. // check if it least one of the group's descendants is not empty
  1306. // (at least one child must already have been added)
  1307. std::vector<cmSourceGroup>::const_iterator child_it = children.begin();
  1308. while (child_it != children.end()) {
  1309. cmSourceGroup* child_ptr = const_cast<cmSourceGroup*>(&(*child_it));
  1310. if (groupsUsed.find(child_ptr) != groupsUsed.end()) {
  1311. break; // found a child that was already added => add current group too
  1312. }
  1313. child_it++;
  1314. }
  1315. if (child_it == children.end()) {
  1316. continue; // no descendants have source files => ignore this group
  1317. }
  1318. groupsUsed.insert(current_ptr);
  1319. }
  1320. }
  1321. void cmVisualStudio10TargetGenerator::WriteGroupSources(
  1322. const char* name, ToolSources const& sources,
  1323. std::vector<cmSourceGroup>& sourceGroups)
  1324. {
  1325. this->WriteString("<ItemGroup>\n", 1);
  1326. for (ToolSources::const_iterator s = sources.begin(); s != sources.end();
  1327. ++s) {
  1328. cmSourceFile const* sf = s->SourceFile;
  1329. std::string const& source = sf->GetFullPath();
  1330. cmSourceGroup* sourceGroup =
  1331. this->Makefile->FindSourceGroup(source.c_str(), sourceGroups);
  1332. const char* filter = sourceGroup->GetFullName();
  1333. this->WriteString("<", 2);
  1334. std::string path = this->ConvertPath(source, s->RelativePath);
  1335. this->ConvertToWindowsSlash(path);
  1336. (*this->BuildFileStream) << name << " Include=\"" << cmVS10EscapeXML(path);
  1337. if (strlen(filter)) {
  1338. (*this->BuildFileStream) << "\">\n";
  1339. this->WriteString("<Filter>", 3);
  1340. (*this->BuildFileStream) << filter << "</Filter>\n";
  1341. this->WriteString("</", 2);
  1342. (*this->BuildFileStream) << name << ">\n";
  1343. } else {
  1344. (*this->BuildFileStream) << "\" />\n";
  1345. }
  1346. }
  1347. this->WriteString("</ItemGroup>\n", 1);
  1348. }
  1349. void cmVisualStudio10TargetGenerator::WriteHeaderSource(cmSourceFile const* sf)
  1350. {
  1351. std::string const& fileName = sf->GetFullPath();
  1352. if (this->IsResxHeader(fileName)) {
  1353. this->WriteSource("ClInclude", sf, ">\n");
  1354. this->WriteString("<FileType>CppForm</FileType>\n", 3);
  1355. this->WriteString("</ClInclude>\n", 2);
  1356. } else if (this->IsXamlHeader(fileName)) {
  1357. this->WriteSource("ClInclude", sf, ">\n");
  1358. this->WriteString("<DependentUpon>", 3);
  1359. std::string xamlFileName = fileName.substr(0, fileName.find_last_of("."));
  1360. (*this->BuildFileStream) << xamlFileName << "</DependentUpon>\n";
  1361. this->WriteString("</ClInclude>\n", 2);
  1362. } else {
  1363. this->WriteSource("ClInclude", sf);
  1364. }
  1365. }
  1366. void cmVisualStudio10TargetGenerator::WriteExtraSource(cmSourceFile const* sf)
  1367. {
  1368. bool toolHasSettings = false;
  1369. std::string tool = "None";
  1370. std::string shaderType;
  1371. std::string shaderEntryPoint;
  1372. std::string shaderModel;
  1373. std::string shaderAdditionalFlags;
  1374. std::string settingsGenerator;
  1375. std::string settingsLastGenOutput;
  1376. std::string sourceLink;
  1377. std::string subType;
  1378. std::string copyToOutDir;
  1379. std::string includeInVsix;
  1380. std::string ext = cmSystemTools::LowerCase(sf->GetExtension());
  1381. if (csproj == this->ProjectType) {
  1382. // EVERY extra source file must have a <Link>, otherwise it might not
  1383. // be visible in Visual Studio at all. The path relative to current
  1384. // source- or binary-dir is used within the link, if the file is
  1385. // in none of these paths, it is added with the plain filename without
  1386. // any path. This means the file will show up at root-level of the csproj
  1387. // (where CMakeLists.txt etc. are).
  1388. if (!this->InSourceBuild) {
  1389. toolHasSettings = true;
  1390. std::string fullFileName = sf->GetFullPath();
  1391. std::string srcDir = this->Makefile->GetCurrentSourceDirectory();
  1392. std::string binDir = this->Makefile->GetCurrentBinaryDirectory();
  1393. if (fullFileName.find(binDir) != std::string::npos) {
  1394. sourceLink = "";
  1395. } else if (fullFileName.find(srcDir) != std::string::npos) {
  1396. sourceLink = fullFileName.substr(srcDir.length() + 1);
  1397. } else {
  1398. // fallback: add plain filename without any path
  1399. sourceLink = cmsys::SystemTools::GetFilenameName(fullFileName);
  1400. }
  1401. if (!sourceLink.empty()) {
  1402. this->ConvertToWindowsSlash(sourceLink);
  1403. }
  1404. }
  1405. }
  1406. if (ext == "hlsl") {
  1407. tool = "FXCompile";
  1408. // Figure out the type of shader compiler to use.
  1409. if (const char* st = sf->GetProperty("VS_SHADER_TYPE")) {
  1410. shaderType = st;
  1411. toolHasSettings = true;
  1412. }
  1413. // Figure out which entry point to use if any
  1414. if (const char* se = sf->GetProperty("VS_SHADER_ENTRYPOINT")) {
  1415. shaderEntryPoint = se;
  1416. toolHasSettings = true;
  1417. }
  1418. // Figure out which shader model to use if any
  1419. if (const char* sm = sf->GetProperty("VS_SHADER_MODEL")) {
  1420. shaderModel = sm;
  1421. toolHasSettings = true;
  1422. }
  1423. // Figure out if there's any additional flags to use
  1424. if (const char* saf = sf->GetProperty("VS_SHADER_FLAGS")) {
  1425. shaderAdditionalFlags = saf;
  1426. toolHasSettings = true;
  1427. }
  1428. } else if (ext == "jpg" || ext == "png") {
  1429. tool = "Image";
  1430. } else if (ext == "resw") {
  1431. tool = "PRIResource";
  1432. } else if (ext == "xml") {
  1433. tool = "XML";
  1434. } else if (ext == "natvis") {
  1435. tool = "Natvis";
  1436. } else if (ext == "settings") {
  1437. // remove path to current source dir (if files are in current source dir)
  1438. if (!sourceLink.empty()) {
  1439. settingsLastGenOutput = sourceLink;
  1440. } else {
  1441. settingsLastGenOutput = sf->GetFullPath();
  1442. }
  1443. std::size_t pos = settingsLastGenOutput.find(".settings");
  1444. settingsLastGenOutput.replace(pos, 9, ".Designer.cs");
  1445. settingsGenerator = "SettingsSingleFileGenerator";
  1446. toolHasSettings = true;
  1447. } else if (ext == "vsixmanifest") {
  1448. subType = "Designer";
  1449. }
  1450. if (const char* c = sf->GetProperty("VS_COPY_TO_OUT_DIR")) {
  1451. copyToOutDir = c;
  1452. toolHasSettings = true;
  1453. }
  1454. if (sf->GetPropertyAsBool("VS_INCLUDE_IN_VSIX")) {
  1455. includeInVsix = "True";
  1456. tool = "Content";
  1457. toolHasSettings = true;
  1458. }
  1459. if (this->NsightTegra) {
  1460. // Nsight Tegra needs specific file types to check up-to-dateness.
  1461. std::string name = cmSystemTools::LowerCase(sf->GetLocation().GetName());
  1462. if (name == "androidmanifest.xml" || name == "build.xml" ||
  1463. name == "proguard.cfg" || name == "proguard-project.txt" ||
  1464. ext == "properties") {
  1465. tool = "AndroidBuild";
  1466. } else if (ext == "java") {
  1467. tool = "JCompile";
  1468. } else if (ext == "asm" || ext == "s") {
  1469. tool = "ClCompile";
  1470. }
  1471. }
  1472. const char* toolOverride = sf->GetProperty("VS_TOOL_OVERRIDE");
  1473. if (toolOverride && *toolOverride) {
  1474. tool = toolOverride;
  1475. }
  1476. std::string deployContent;
  1477. std::string deployLocation;
  1478. if (this->GlobalGenerator->TargetsWindowsPhone() ||
  1479. this->GlobalGenerator->TargetsWindowsStore()) {
  1480. const char* content = sf->GetProperty("VS_DEPLOYMENT_CONTENT");
  1481. if (content && *content) {
  1482. toolHasSettings = true;
  1483. deployContent = content;
  1484. const char* location = sf->GetProperty("VS_DEPLOYMENT_LOCATION");
  1485. if (location && *location) {
  1486. deployLocation = location;
  1487. }
  1488. }
  1489. }
  1490. if (toolHasSettings) {
  1491. this->WriteSource(tool, sf, ">\n");
  1492. if (!deployContent.empty()) {
  1493. cmGeneratorExpression ge;
  1494. CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = ge.Parse(deployContent);
  1495. // Deployment location cannot be set on a configuration basis
  1496. if (!deployLocation.empty()) {
  1497. this->WriteString("<Link>", 3);
  1498. (*this->BuildFileStream) << deployLocation
  1499. << "\\%(FileName)%(Extension)";
  1500. this->WriteString("</Link>\n", 0);
  1501. }
  1502. for (size_t i = 0; i != this->Configurations.size(); ++i) {
  1503. if (0 == strcmp(cge->Evaluate(this->LocalGenerator,
  1504. this->Configurations[i]),
  1505. "1")) {
  1506. this->WriteString("<DeploymentContent Condition=\""
  1507. "'$(Configuration)|$(Platform)'=='",
  1508. 3);
  1509. (*this->BuildFileStream) << this->Configurations[i] << "|"
  1510. << this->Platform << "'\">true";
  1511. this->WriteString("</DeploymentContent>\n", 0);
  1512. } else {
  1513. this->WriteString("<ExcludedFromBuild Condition=\""
  1514. "'$(Configuration)|$(Platform)'=='",
  1515. 3);
  1516. (*this->BuildFileStream) << this->Configurations[i] << "|"
  1517. << this->Platform << "'\">true";
  1518. this->WriteString("</ExcludedFromBuild>\n", 0);
  1519. }
  1520. }
  1521. }
  1522. if (!shaderType.empty()) {
  1523. this->WriteString("<ShaderType>", 3);
  1524. (*this->BuildFileStream) << cmVS10EscapeXML(shaderType)
  1525. << "</ShaderType>\n";
  1526. }
  1527. if (!shaderEntryPoint.empty()) {
  1528. this->WriteString("<EntryPointName>", 3);
  1529. (*this->BuildFileStream) << cmVS10EscapeXML(shaderEntryPoint)
  1530. << "</EntryPointName>\n";
  1531. }
  1532. if (!shaderModel.empty()) {
  1533. this->WriteString("<ShaderModel>", 3);
  1534. (*this->BuildFileStream) << cmVS10EscapeXML(shaderModel)
  1535. << "</ShaderModel>\n";
  1536. }
  1537. if (!shaderAdditionalFlags.empty()) {
  1538. this->WriteString("<AdditionalOptions>", 3);
  1539. (*this->BuildFileStream) << cmVS10EscapeXML(shaderAdditionalFlags)
  1540. << "</AdditionalOptions>\n";
  1541. }
  1542. if (!settingsGenerator.empty()) {
  1543. this->WriteString("<Generator>", 3);
  1544. (*this->BuildFileStream) << cmVS10EscapeXML(settingsGenerator)
  1545. << "</Generator>\n";
  1546. }
  1547. if (!settingsLastGenOutput.empty()) {
  1548. this->WriteString("<LastGenOutput>", 3);
  1549. (*this->BuildFileStream) << cmVS10EscapeXML(settingsLastGenOutput)
  1550. << "</LastGenOutput>\n";
  1551. }
  1552. if (!sourceLink.empty()) {
  1553. this->WriteString("<Link>", 3);
  1554. (*this->BuildFileStream) << cmVS10EscapeXML(sourceLink) << "</Link>\n";
  1555. }
  1556. if (!subType.empty()) {
  1557. this->WriteString("<SubType>", 3);
  1558. (*this->BuildFileStream) << cmVS10EscapeXML(subType) << "</SubType>\n";
  1559. }
  1560. if (!copyToOutDir.empty()) {
  1561. this->WriteString("<CopyToOutputDirectory>", 3);
  1562. (*this->BuildFileStream) << cmVS10EscapeXML(copyToOutDir)
  1563. << "</CopyToOutputDirectory>\n";
  1564. }
  1565. if (!includeInVsix.empty()) {
  1566. this->WriteString("<IncludeInVSIX>", 3);
  1567. (*this->BuildFileStream) << cmVS10EscapeXML(includeInVsix)
  1568. << "</IncludeInVSIX>\n";
  1569. }
  1570. this->WriteString("</", 2);
  1571. (*this->BuildFileStream) << tool << ">\n";
  1572. } else {
  1573. this->WriteSource(tool, sf);
  1574. }
  1575. }
  1576. void cmVisualStudio10TargetGenerator::WriteSource(std::string const& tool,
  1577. cmSourceFile const* sf,
  1578. const char* end)
  1579. {
  1580. // Visual Studio tools append relative paths to the current dir, as in:
  1581. //
  1582. // c:\path\to\current\dir\..\..\..\relative\path\to\source.c
  1583. //
  1584. // and fail if this exceeds the maximum allowed path length. Our path
  1585. // conversion uses full paths when possible to allow deeper trees.
  1586. // However, CUDA 8.0 msbuild rules fail on absolute paths so for CUDA
  1587. // we must use relative paths.
  1588. bool forceRelative = sf->GetLanguage() == "CUDA";
  1589. std::string sourceFile = this->ConvertPath(sf->GetFullPath(), forceRelative);
  1590. if (this->LocalGenerator->GetVersion() ==
  1591. cmGlobalVisualStudioGenerator::VS10 &&
  1592. cmSystemTools::FileIsFullPath(sourceFile.c_str())) {
  1593. // Normal path conversion resulted in a full path. VS 10 (but not 11)
  1594. // refuses to show the property page in the IDE for a source file with a
  1595. // full path (not starting in a '.' or '/' AFAICT). CMake <= 2.8.4 used a
  1596. // relative path but to allow deeper build trees CMake 2.8.[5678] used a
  1597. // full path except for custom commands. Custom commands do not work
  1598. // without a relative path, but they do not seem to be involved in tools
  1599. // with the above behavior. For other sources we now use a relative path
  1600. // when the combined path will not be too long so property pages appear.
  1601. std::string sourceRel = this->ConvertPath(sf->GetFullPath(), true);
  1602. size_t const maxLen = 250;
  1603. if (sf->GetCustomCommand() ||
  1604. ((strlen(this->LocalGenerator->GetCurrentBinaryDirectory()) + 1 +
  1605. sourceRel.length()) <= maxLen)) {
  1606. forceRelative = true;
  1607. sourceFile = sourceRel;
  1608. } else {
  1609. this->GlobalGenerator->PathTooLong(this->GeneratorTarget, sf, sourceRel);
  1610. }
  1611. }
  1612. this->ConvertToWindowsSlash(sourceFile);
  1613. this->WriteString("<", 2);
  1614. (*this->BuildFileStream) << tool << " Include=\""
  1615. << cmVS10EscapeXML(sourceFile) << "\""
  1616. << (end ? end : " />\n");
  1617. ToolSource toolSource = { sf, forceRelative };
  1618. this->Tools[tool].push_back(toolSource);
  1619. }
  1620. void cmVisualStudio10TargetGenerator::WriteSources(
  1621. std::string const& tool, std::vector<cmSourceFile const*> const& sources)
  1622. {
  1623. for (std::vector<cmSourceFile const*>::const_iterator si = sources.begin();
  1624. si != sources.end(); ++si) {
  1625. this->WriteSource(tool, *si);
  1626. }
  1627. }
  1628. void cmVisualStudio10TargetGenerator::WriteAllSources()
  1629. {
  1630. if (this->GeneratorTarget->GetType() > cmStateEnums::UTILITY) {
  1631. return;
  1632. }
  1633. this->WriteString("<ItemGroup>\n", 1);
  1634. std::vector<cmSourceFile const*> headerSources;
  1635. this->GeneratorTarget->GetHeaderSources(headerSources, "");
  1636. for (std::vector<cmSourceFile const*>::const_iterator si =
  1637. headerSources.begin();
  1638. si != headerSources.end(); ++si) {
  1639. this->WriteHeaderSource(*si);
  1640. }
  1641. std::vector<cmSourceFile const*> idlSources;
  1642. this->GeneratorTarget->GetIDLSources(idlSources, "");
  1643. this->WriteSources("Midl", idlSources);
  1644. std::vector<cmSourceFile const*> objectSources;
  1645. this->GeneratorTarget->GetObjectSources(objectSources, "");
  1646. for (std::vector<cmSourceFile const*>::const_iterator si =
  1647. objectSources.begin();
  1648. si != objectSources.end(); ++si) {
  1649. const std::string& lang = (*si)->GetLanguage();
  1650. std::string tool;
  1651. if (lang == "C" || lang == "CXX") {
  1652. tool = "ClCompile";
  1653. } else if (lang == "ASM_MASM" && this->GlobalGenerator->IsMasmEnabled()) {
  1654. tool = "MASM";
  1655. } else if (lang == "ASM_NASM" && this->GlobalGenerator->IsNasmEnabled()) {
  1656. tool = "NASM";
  1657. } else if (lang == "RC") {
  1658. tool = "ResourceCompile";
  1659. } else if (lang == "CSharp") {
  1660. tool = "Compile";
  1661. } else if (lang == "CUDA" && this->GlobalGenerator->IsCudaEnabled()) {
  1662. tool = "CudaCompile";
  1663. }
  1664. if (!tool.empty()) {
  1665. this->WriteSource(tool, *si, " ");
  1666. if (this->OutputSourceSpecificFlags(*si)) {
  1667. this->WriteString("</", 2);
  1668. (*this->BuildFileStream) << tool << ">\n";
  1669. } else {
  1670. (*this->BuildFileStream) << " />\n";
  1671. }
  1672. } else {
  1673. this->WriteSource("None", *si);
  1674. }
  1675. }
  1676. std::vector<cmSourceFile const*> manifestSources;
  1677. this->GeneratorTarget->GetAppManifest(manifestSources, "");
  1678. this->WriteSources("AppxManifest", manifestSources);
  1679. std::vector<cmSourceFile const*> certificateSources;
  1680. this->GeneratorTarget->GetCertificates(certificateSources, "");
  1681. this->WriteSources("None", certificateSources);
  1682. std::vector<cmSourceFile const*> externalObjects;
  1683. this->GeneratorTarget->GetExternalObjects(externalObjects, "");
  1684. if (this->LocalGenerator->GetVersion() >
  1685. cmGlobalVisualStudioGenerator::VS10) {
  1686. // For VS >= 11 we use LinkObjects to avoid linking custom command
  1687. // outputs. Use Object for all external objects, generated or not.
  1688. this->WriteSources("Object", externalObjects);
  1689. } else {
  1690. // If an object file is generated in this target, then vs10 will use
  1691. // it in the build, and we have to list it as None instead of Object.
  1692. for (std::vector<cmSourceFile const*>::const_iterator si =
  1693. externalObjects.begin();
  1694. si != externalObjects.end(); ++si) {
  1695. std::vector<cmSourceFile*> const* d =
  1696. this->GeneratorTarget->GetSourceDepends(*si);
  1697. this->WriteSource((d && !d->empty()) ? "None" : "Object", *si);
  1698. }
  1699. }
  1700. std::vector<cmSourceFile const*> extraSources;
  1701. this->GeneratorTarget->GetExtraSources(extraSources, "");
  1702. for (std::vector<cmSourceFile const*>::const_iterator si =
  1703. extraSources.begin();
  1704. si != extraSources.end(); ++si) {
  1705. this->WriteExtraSource(*si);
  1706. }
  1707. std::vector<cmSourceFile const*> defSources;
  1708. this->GeneratorTarget->GetModuleDefinitionSources(defSources, "");
  1709. this->WriteSources("None", defSources);
  1710. if (this->IsMissingFiles) {
  1711. this->WriteMissingFiles();
  1712. }
  1713. this->WriteString("</ItemGroup>\n", 1);
  1714. }
  1715. bool cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags(
  1716. cmSourceFile const* source)
  1717. {
  1718. cmSourceFile const& sf = *source;
  1719. std::string objectName;
  1720. if (this->GeneratorTarget->HasExplicitObjectName(&sf)) {
  1721. objectName = this->GeneratorTarget->GetObjectName(&sf);
  1722. }
  1723. std::string flags;
  1724. bool configDependentFlags = false;
  1725. std::string defines;
  1726. if (const char* cflags = sf.GetProperty("COMPILE_FLAGS")) {
  1727. if (cmGeneratorExpression::Find(cflags) != std::string::npos) {
  1728. configDependentFlags = true;
  1729. }
  1730. flags += cflags;
  1731. }
  1732. if (const char* cdefs = sf.GetProperty("COMPILE_DEFINITIONS")) {
  1733. defines += cdefs;
  1734. }
  1735. std::string lang =
  1736. this->GlobalGenerator->GetLanguageFromExtension(sf.GetExtension().c_str());
  1737. std::string sourceLang = this->LocalGenerator->GetSourceFileLanguage(sf);
  1738. const std::string& linkLanguage = this->GeneratorTarget->GetLinkerLanguage();
  1739. bool needForceLang = false;
  1740. // source file does not match its extension language
  1741. if (lang != sourceLang) {
  1742. needForceLang = true;
  1743. lang = sourceLang;
  1744. }
  1745. // if the source file does not match the linker language
  1746. // then force c or c++
  1747. const char* compileAs = 0;
  1748. if (needForceLang || (linkLanguage != lang)) {
  1749. if (lang == "CXX") {
  1750. // force a C++ file type
  1751. compileAs = "CompileAsCpp";
  1752. } else if (lang == "C") {
  1753. // force to c
  1754. compileAs = "CompileAsC";
  1755. }
  1756. }
  1757. bool noWinRT = this->TargetCompileAsWinRT && lang == "C";
  1758. bool hasFlags = false;
  1759. // for the first time we need a new line if there is something
  1760. // produced here.
  1761. const char* firstString = ">\n";
  1762. if (!objectName.empty()) {
  1763. (*this->BuildFileStream) << firstString;
  1764. firstString = "";
  1765. hasFlags = true;
  1766. this->WriteString("<ObjectFileName>", 3);
  1767. (*this->BuildFileStream) << "$(IntDir)/" << objectName
  1768. << "</ObjectFileName>\n";
  1769. }
  1770. for (std::vector<std::string>::const_iterator config =
  1771. this->Configurations.begin();
  1772. config != this->Configurations.end(); ++config) {
  1773. std::string configUpper = cmSystemTools::UpperCase(*config);
  1774. std::string configDefines = defines;
  1775. std::string defPropName = "COMPILE_DEFINITIONS_";
  1776. defPropName += configUpper;
  1777. if (const char* ccdefs = sf.GetProperty(defPropName.c_str())) {
  1778. if (!configDefines.empty()) {
  1779. configDefines += ";";
  1780. }
  1781. configDefines += ccdefs;
  1782. }
  1783. // if we have flags or defines for this config then
  1784. // use them
  1785. if (!flags.empty() || configDependentFlags || !configDefines.empty() ||
  1786. compileAs || noWinRT) {
  1787. (*this->BuildFileStream) << firstString;
  1788. firstString = ""; // only do firstString once
  1789. hasFlags = true;
  1790. cmGlobalVisualStudio10Generator* gg =
  1791. static_cast<cmGlobalVisualStudio10Generator*>(this->GlobalGenerator);
  1792. cmVisualStudioGeneratorOptions clOptions(
  1793. this->LocalGenerator, cmVisualStudioGeneratorOptions::Compiler,
  1794. gg->GetClFlagTable(), 0, this);
  1795. if (compileAs) {
  1796. clOptions.AddFlag("CompileAs", compileAs);
  1797. }
  1798. if (noWinRT) {
  1799. clOptions.AddFlag("CompileAsWinRT", "false");
  1800. }
  1801. if (configDependentFlags) {
  1802. cmGeneratorExpression ge;
  1803. CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = ge.Parse(flags);
  1804. std::string evaluatedFlags =
  1805. cge->Evaluate(this->LocalGenerator, *config);
  1806. clOptions.Parse(evaluatedFlags.c_str());
  1807. } else {
  1808. clOptions.Parse(flags.c_str());
  1809. }
  1810. if (clOptions.HasFlag("AdditionalIncludeDirectories")) {
  1811. clOptions.AppendFlag("AdditionalIncludeDirectories",
  1812. "%(AdditionalIncludeDirectories)");
  1813. }
  1814. if (clOptions.HasFlag("DisableSpecificWarnings")) {
  1815. clOptions.AppendFlag("DisableSpecificWarnings",
  1816. "%(DisableSpecificWarnings)");
  1817. }
  1818. clOptions.AddDefines(configDefines.c_str());
  1819. clOptions.SetConfiguration((*config).c_str());
  1820. clOptions.PrependInheritedString("AdditionalOptions");
  1821. clOptions.OutputFlagMap(*this->BuildFileStream, " ");
  1822. clOptions.OutputPreprocessorDefinitions(*this->BuildFileStream, " ",
  1823. "\n", lang);
  1824. }
  1825. }
  1826. if (this->IsXamlSource(source->GetFullPath())) {
  1827. (*this->BuildFileStream) << firstString;
  1828. firstString = ""; // only do firstString once
  1829. hasFlags = true;
  1830. this->WriteString("<DependentUpon>", 3);
  1831. const std::string& fileName = source->GetFullPath();
  1832. std::string xamlFileName = fileName.substr(0, fileName.find_last_of("."));
  1833. (*this->BuildFileStream) << xamlFileName << "</DependentUpon>\n";
  1834. }
  1835. if (csproj == this->ProjectType) {
  1836. std::string f = source->GetFullPath();
  1837. typedef std::map<std::string, std::string> CsPropMap;
  1838. CsPropMap sourceFileTags;
  1839. // set <Link> tag if necessary
  1840. if (!this->InSourceBuild) {
  1841. const std::string stripFromPath =
  1842. this->Makefile->GetCurrentSourceDirectory();
  1843. if (f.find(stripFromPath) != std::string::npos) {
  1844. std::string link = f.substr(stripFromPath.length() + 1);
  1845. this->ConvertToWindowsSlash(link);
  1846. sourceFileTags["Link"] = link;
  1847. }
  1848. }
  1849. const cmPropertyMap& props = sf.GetProperties();
  1850. for (cmPropertyMap::const_iterator p = props.begin(); p != props.end();
  1851. ++p) {
  1852. static const std::string propNamePrefix = "VS_CSHARP_";
  1853. if (p->first.find(propNamePrefix.c_str()) == 0) {
  1854. std::string tagName = p->first.substr(propNamePrefix.length());
  1855. if (!tagName.empty()) {
  1856. const std::string val = props.GetPropertyValue(p->first);
  1857. if (!val.empty()) {
  1858. sourceFileTags[tagName] = val;
  1859. } else {
  1860. sourceFileTags.erase(tagName);
  1861. }
  1862. }
  1863. }
  1864. }
  1865. // write source file specific tags
  1866. if (!sourceFileTags.empty()) {
  1867. hasFlags = true;
  1868. (*this->BuildFileStream) << firstString;
  1869. firstString = "";
  1870. for (CsPropMap::const_iterator i = sourceFileTags.begin();
  1871. i != sourceFileTags.end(); ++i) {
  1872. this->WriteString("<", 3);
  1873. (*this->BuildFileStream)
  1874. << i->first << ">" << cmVS10EscapeXML(i->second) << "</" << i->first
  1875. << ">\n";
  1876. }
  1877. }
  1878. }
  1879. return hasFlags;
  1880. }
  1881. void cmVisualStudio10TargetGenerator::WritePathAndIncrementalLinkOptions()
  1882. {
  1883. cmStateEnums::TargetType ttype = this->GeneratorTarget->GetType();
  1884. if (ttype > cmStateEnums::GLOBAL_TARGET) {
  1885. return;
  1886. }
  1887. if (csproj == this->ProjectType) {
  1888. return;
  1889. }
  1890. this->WriteString("<PropertyGroup>\n", 2);
  1891. this->WriteString("<_ProjectFileVersion>10.0.20506.1"
  1892. "</_ProjectFileVersion>\n",
  1893. 3);
  1894. for (std::vector<std::string>::const_iterator config =
  1895. this->Configurations.begin();
  1896. config != this->Configurations.end(); ++config) {
  1897. if (ttype >= cmStateEnums::UTILITY) {
  1898. this->WritePlatformConfigTag("IntDir", config->c_str(), 3);
  1899. *this->BuildFileStream
  1900. << "$(Platform)\\$(Configuration)\\$(ProjectName)\\"
  1901. << "</IntDir>\n";
  1902. } else {
  1903. std::string intermediateDir =
  1904. this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
  1905. intermediateDir += "/";
  1906. intermediateDir += *config;
  1907. intermediateDir += "/";
  1908. std::string outDir;
  1909. std::string targetNameFull;
  1910. if (ttype == cmStateEnums::OBJECT_LIBRARY) {
  1911. outDir = intermediateDir;
  1912. targetNameFull = this->GeneratorTarget->GetName();
  1913. targetNameFull += ".lib";
  1914. } else {
  1915. outDir = this->GeneratorTarget->GetDirectory(config->c_str()) + "/";
  1916. targetNameFull = this->GeneratorTarget->GetFullName(config->c_str());
  1917. }
  1918. this->ConvertToWindowsSlash(intermediateDir);
  1919. this->ConvertToWindowsSlash(outDir);
  1920. this->WritePlatformConfigTag("OutDir", config->c_str(), 3);
  1921. *this->BuildFileStream << cmVS10EscapeXML(outDir) << "</OutDir>\n";
  1922. this->WritePlatformConfigTag("IntDir", config->c_str(), 3);
  1923. *this->BuildFileStream << cmVS10EscapeXML(intermediateDir)
  1924. << "</IntDir>\n";
  1925. if (const char* workingDir = this->GeneratorTarget->GetProperty(
  1926. "VS_DEBUGGER_WORKING_DIRECTORY")) {
  1927. this->WritePlatformConfigTag("LocalDebuggerWorkingDirectory",
  1928. config->c_str(), 3);
  1929. *this->BuildFileStream << cmVS10EscapeXML(workingDir)
  1930. << "</LocalDebuggerWorkingDirectory>\n";
  1931. }
  1932. std::string name =
  1933. cmSystemTools::GetFilenameWithoutLastExtension(targetNameFull);
  1934. this->WritePlatformConfigTag("TargetName", config->c_str(), 3);
  1935. *this->BuildFileStream << cmVS10EscapeXML(name) << "</TargetName>\n";
  1936. std::string ext =
  1937. cmSystemTools::GetFilenameLastExtension(targetNameFull);
  1938. if (ext.empty()) {
  1939. // An empty TargetExt causes a default extension to be used.
  1940. // A single "." appears to be treated as an empty extension.
  1941. ext = ".";
  1942. }
  1943. this->WritePlatformConfigTag("TargetExt", config->c_str(), 3);
  1944. *this->BuildFileStream << cmVS10EscapeXML(ext) << "</TargetExt>\n";
  1945. this->OutputLinkIncremental(*config);
  1946. }
  1947. }
  1948. this->WriteString("</PropertyGroup>\n", 2);
  1949. }
  1950. void cmVisualStudio10TargetGenerator::OutputLinkIncremental(
  1951. std::string const& configName)
  1952. {
  1953. if (!this->MSTools) {
  1954. return;
  1955. }
  1956. if (csproj == this->ProjectType) {
  1957. return;
  1958. }
  1959. // static libraries and things greater than modules do not need
  1960. // to set this option
  1961. if (this->GeneratorTarget->GetType() == cmStateEnums::STATIC_LIBRARY ||
  1962. this->GeneratorTarget->GetType() > cmStateEnums::MODULE_LIBRARY) {
  1963. return;
  1964. }
  1965. Options& linkOptions = *(this->LinkOptions[configName]);
  1966. const char* incremental = linkOptions.GetFlag("LinkIncremental");
  1967. this->WritePlatformConfigTag("LinkIncremental", configName.c_str(), 3);
  1968. *this->BuildFileStream << (incremental ? incremental : "true")
  1969. << "</LinkIncremental>\n";
  1970. linkOptions.RemoveFlag("LinkIncremental");
  1971. const char* manifest = linkOptions.GetFlag("GenerateManifest");
  1972. this->WritePlatformConfigTag("GenerateManifest", configName.c_str(), 3);
  1973. *this->BuildFileStream << (manifest ? manifest : "true")
  1974. << "</GenerateManifest>\n";
  1975. linkOptions.RemoveFlag("GenerateManifest");
  1976. // Some link options belong here. Use them now and remove them so that
  1977. // WriteLinkOptions does not use them.
  1978. const char* flags[] = { "LinkDelaySign", "LinkKeyFile", 0 };
  1979. for (const char** f = flags; *f; ++f) {
  1980. const char* flag = *f;
  1981. if (const char* value = linkOptions.GetFlag(flag)) {
  1982. this->WritePlatformConfigTag(flag, configName.c_str(), 3);
  1983. *this->BuildFileStream << value << "</" << flag << ">\n";
  1984. linkOptions.RemoveFlag(flag);
  1985. }
  1986. }
  1987. }
  1988. bool cmVisualStudio10TargetGenerator::ComputeClOptions()
  1989. {
  1990. for (std::vector<std::string>::const_iterator i =
  1991. this->Configurations.begin();
  1992. i != this->Configurations.end(); ++i) {
  1993. if (!this->ComputeClOptions(*i)) {
  1994. return false;
  1995. }
  1996. }
  1997. return true;
  1998. }
  1999. bool cmVisualStudio10TargetGenerator::ComputeClOptions(
  2000. std::string const& configName)
  2001. {
  2002. // much of this was copied from here:
  2003. // copied from cmLocalVisualStudio7Generator.cxx 805
  2004. // TODO: Integrate code below with cmLocalVisualStudio7Generator.
  2005. cmGlobalVisualStudio10Generator* gg =
  2006. static_cast<cmGlobalVisualStudio10Generator*>(this->GlobalGenerator);
  2007. CM_AUTO_PTR<Options> pOptions;
  2008. switch (this->ProjectType) {
  2009. case vcxproj:
  2010. pOptions = CM_AUTO_PTR<Options>(new Options(
  2011. this->LocalGenerator, Options::Compiler, gg->GetClFlagTable()));
  2012. break;
  2013. case csproj:
  2014. pOptions = CM_AUTO_PTR<Options>(new Options(this->LocalGenerator,
  2015. Options::CSharpCompiler,
  2016. gg->GetCSharpFlagTable()));
  2017. break;
  2018. }
  2019. Options& clOptions = *pOptions;
  2020. std::string flags;
  2021. const std::string& linkLanguage =
  2022. this->GeneratorTarget->GetLinkerLanguage(configName.c_str());
  2023. if (linkLanguage.empty()) {
  2024. cmSystemTools::Error(
  2025. "CMake can not determine linker language for target: ",
  2026. this->Name.c_str());
  2027. return false;
  2028. }
  2029. if (linkLanguage == "C" || linkLanguage == "CXX" ||
  2030. linkLanguage == "Fortran" || linkLanguage == "CSharp") {
  2031. std::string baseFlagVar = "CMAKE_";
  2032. baseFlagVar += linkLanguage;
  2033. baseFlagVar += "_FLAGS";
  2034. flags =
  2035. this->GeneratorTarget->Target->GetMakefile()->GetRequiredDefinition(
  2036. baseFlagVar.c_str());
  2037. std::string flagVar =
  2038. baseFlagVar + std::string("_") + cmSystemTools::UpperCase(configName);
  2039. flags += " ";
  2040. flags +=
  2041. this->GeneratorTarget->Target->GetMakefile()->GetRequiredDefinition(
  2042. flagVar.c_str());
  2043. }
  2044. // set the correct language
  2045. if (linkLanguage == "C") {
  2046. clOptions.AddFlag("CompileAs", "CompileAsC");
  2047. }
  2048. if (linkLanguage == "CXX") {
  2049. clOptions.AddFlag("CompileAs", "CompileAsCpp");
  2050. }
  2051. if (linkLanguage != "CUDA") {
  2052. this->LocalGenerator->AddCompileOptions(flags, this->GeneratorTarget,
  2053. linkLanguage, configName.c_str());
  2054. }
  2055. // Check IPO related warning/error.
  2056. this->GeneratorTarget->IsIPOEnabled(configName);
  2057. // Get preprocessor definitions for this directory.
  2058. std::string defineFlags =
  2059. this->GeneratorTarget->Target->GetMakefile()->GetDefineFlags();
  2060. if (this->MSTools) {
  2061. if (vcxproj == this->ProjectType) {
  2062. clOptions.FixExceptionHandlingDefault();
  2063. clOptions.AddFlag("PrecompiledHeader", "NotUsing");
  2064. std::string asmLocation = configName + "/";
  2065. clOptions.AddFlag("AssemblerListingLocation", asmLocation.c_str());
  2066. }
  2067. }
  2068. clOptions.Parse(flags.c_str());
  2069. clOptions.Parse(defineFlags.c_str());
  2070. std::vector<std::string> targetDefines;
  2071. switch (this->ProjectType) {
  2072. case vcxproj:
  2073. this->GeneratorTarget->GetCompileDefinitions(targetDefines,
  2074. configName.c_str(), "CXX");
  2075. break;
  2076. case csproj:
  2077. this->GeneratorTarget->GetCompileDefinitions(
  2078. targetDefines, configName.c_str(), "CSharp");
  2079. break;
  2080. }
  2081. clOptions.AddDefines(targetDefines);
  2082. if (this->MSTools) {
  2083. clOptions.SetVerboseMakefile(
  2084. this->Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE"));
  2085. }
  2086. // Add a definition for the configuration name.
  2087. std::string configDefine = "CMAKE_INTDIR=\"";
  2088. configDefine += configName;
  2089. configDefine += "\"";
  2090. clOptions.AddDefine(configDefine);
  2091. if (const char* exportMacro = this->GeneratorTarget->GetExportMacro()) {
  2092. clOptions.AddDefine(exportMacro);
  2093. }
  2094. if (this->MSTools) {
  2095. // If we have the VS_WINRT_COMPONENT set then force Compile as WinRT.
  2096. if (this->GeneratorTarget->GetPropertyAsBool("VS_WINRT_COMPONENT")) {
  2097. clOptions.AddFlag("CompileAsWinRT", "true");
  2098. // For WinRT components, add the _WINRT_DLL define to produce a lib
  2099. if (this->GeneratorTarget->GetType() == cmStateEnums::SHARED_LIBRARY ||
  2100. this->GeneratorTarget->GetType() == cmStateEnums::MODULE_LIBRARY) {
  2101. clOptions.AddDefine("_WINRT_DLL");
  2102. }
  2103. } else if (this->GlobalGenerator->TargetsWindowsStore() ||
  2104. this->GlobalGenerator->TargetsWindowsPhone()) {
  2105. if (!clOptions.IsWinRt()) {
  2106. clOptions.AddFlag("CompileAsWinRT", "false");
  2107. }
  2108. }
  2109. if (const char* winRT = clOptions.GetFlag("CompileAsWinRT")) {
  2110. if (cmSystemTools::IsOn(winRT)) {
  2111. this->TargetCompileAsWinRT = true;
  2112. }
  2113. }
  2114. }
  2115. if (csproj != this->ProjectType && clOptions.IsManaged()) {
  2116. this->Managed = true;
  2117. std::string managedType = clOptions.GetFlag("CompileAsManaged");
  2118. if (managedType == "Safe") {
  2119. // force empty calling convention if safe clr is used
  2120. clOptions.AddFlag("CallingConvention", "");
  2121. }
  2122. }
  2123. this->ClOptions[configName] = pOptions.release();
  2124. return true;
  2125. }
  2126. void cmVisualStudio10TargetGenerator::WriteClOptions(
  2127. std::string const& configName, std::vector<std::string> const& includes)
  2128. {
  2129. Options& clOptions = *(this->ClOptions[configName]);
  2130. if (this->ProjectType == csproj) {
  2131. return;
  2132. }
  2133. this->WriteString("<ClCompile>\n", 2);
  2134. clOptions.PrependInheritedString("AdditionalOptions");
  2135. clOptions.AppendFlag("AdditionalIncludeDirectories", includes);
  2136. clOptions.AppendFlag("AdditionalIncludeDirectories",
  2137. "%(AdditionalIncludeDirectories)");
  2138. clOptions.OutputFlagMap(*this->BuildFileStream, " ");
  2139. clOptions.OutputPreprocessorDefinitions(*this->BuildFileStream, " ",
  2140. "\n", "CXX");
  2141. if (this->NsightTegra) {
  2142. if (const char* processMax =
  2143. this->GeneratorTarget->GetProperty("ANDROID_PROCESS_MAX")) {
  2144. this->WriteString("<ProcessMax>", 3);
  2145. *this->BuildFileStream << cmVS10EscapeXML(processMax)
  2146. << "</ProcessMax>\n";
  2147. }
  2148. }
  2149. if (this->MSTools) {
  2150. cmsys::RegularExpression clangToolset(
  2151. "(v[0-9]+_clang_.*|LLVM-vs[0-9]+.*)");
  2152. const char* toolset = this->GlobalGenerator->GetPlatformToolset();
  2153. if (toolset && clangToolset.find(toolset)) {
  2154. this->WriteString("<ObjectFileName>"
  2155. "$(IntDir)%(filename).obj"
  2156. "</ObjectFileName>\n",
  2157. 3);
  2158. } else {
  2159. this->WriteString("<ObjectFileName>$(IntDir)</ObjectFileName>\n", 3);
  2160. }
  2161. // If not in debug mode, write the DebugInformationFormat field
  2162. // without value so PDBs don't get generated uselessly.
  2163. if (!clOptions.IsDebug()) {
  2164. this->WriteString("<DebugInformationFormat>"
  2165. "</DebugInformationFormat>\n",
  2166. 3);
  2167. }
  2168. // Specify the compiler program database file if configured.
  2169. std::string pdb =
  2170. this->GeneratorTarget->GetCompilePDBPath(configName.c_str());
  2171. if (!pdb.empty()) {
  2172. this->ConvertToWindowsSlash(pdb);
  2173. this->WriteString("<ProgramDataBaseFileName>", 3);
  2174. *this->BuildFileStream << cmVS10EscapeXML(pdb)
  2175. << "</ProgramDataBaseFileName>\n";
  2176. }
  2177. }
  2178. this->WriteString("</ClCompile>\n", 2);
  2179. }
  2180. bool cmVisualStudio10TargetGenerator::ComputeRcOptions()
  2181. {
  2182. for (std::vector<std::string>::const_iterator i =
  2183. this->Configurations.begin();
  2184. i != this->Configurations.end(); ++i) {
  2185. if (!this->ComputeRcOptions(*i)) {
  2186. return false;
  2187. }
  2188. }
  2189. return true;
  2190. }
  2191. bool cmVisualStudio10TargetGenerator::ComputeRcOptions(
  2192. std::string const& configName)
  2193. {
  2194. cmGlobalVisualStudio10Generator* gg =
  2195. static_cast<cmGlobalVisualStudio10Generator*>(this->GlobalGenerator);
  2196. CM_AUTO_PTR<Options> pOptions(new Options(
  2197. this->LocalGenerator, Options::ResourceCompiler, gg->GetRcFlagTable()));
  2198. Options& rcOptions = *pOptions;
  2199. std::string CONFIG = cmSystemTools::UpperCase(configName);
  2200. std::string rcConfigFlagsVar = std::string("CMAKE_RC_FLAGS_") + CONFIG;
  2201. std::string flags =
  2202. std::string(this->Makefile->GetSafeDefinition("CMAKE_RC_FLAGS")) +
  2203. std::string(" ") +
  2204. std::string(this->Makefile->GetSafeDefinition(rcConfigFlagsVar));
  2205. rcOptions.Parse(flags.c_str());
  2206. // For historical reasons, add the C preprocessor defines to RC.
  2207. Options& clOptions = *(this->ClOptions[configName]);
  2208. rcOptions.AddDefines(clOptions.GetDefines());
  2209. this->RcOptions[configName] = pOptions.release();
  2210. return true;
  2211. }
  2212. void cmVisualStudio10TargetGenerator::WriteRCOptions(
  2213. std::string const& configName, std::vector<std::string> const& includes)
  2214. {
  2215. if (!this->MSTools) {
  2216. return;
  2217. }
  2218. this->WriteString("<ResourceCompile>\n", 2);
  2219. Options& rcOptions = *(this->RcOptions[configName]);
  2220. rcOptions.OutputPreprocessorDefinitions(*this->BuildFileStream, " ",
  2221. "\n", "RC");
  2222. rcOptions.AppendFlag("AdditionalIncludeDirectories", includes);
  2223. rcOptions.AppendFlag("AdditionalIncludeDirectories",
  2224. "%(AdditionalIncludeDirectories)");
  2225. rcOptions.PrependInheritedString("AdditionalOptions");
  2226. rcOptions.OutputFlagMap(*this->BuildFileStream, " ");
  2227. this->WriteString("</ResourceCompile>\n", 2);
  2228. }
  2229. bool cmVisualStudio10TargetGenerator::ComputeCudaOptions()
  2230. {
  2231. if (!this->GlobalGenerator->IsCudaEnabled()) {
  2232. return true;
  2233. }
  2234. for (std::vector<std::string>::const_iterator i =
  2235. this->Configurations.begin();
  2236. i != this->Configurations.end(); ++i) {
  2237. if (!this->ComputeCudaOptions(*i)) {
  2238. return false;
  2239. }
  2240. }
  2241. return true;
  2242. }
  2243. bool cmVisualStudio10TargetGenerator::ComputeCudaOptions(
  2244. std::string const& configName)
  2245. {
  2246. cmGlobalVisualStudio10Generator* gg =
  2247. static_cast<cmGlobalVisualStudio10Generator*>(this->GlobalGenerator);
  2248. CM_AUTO_PTR<Options> pOptions(new Options(
  2249. this->LocalGenerator, Options::CudaCompiler, gg->GetCudaFlagTable()));
  2250. Options& cudaOptions = *pOptions;
  2251. // Get compile flags for CUDA in this directory.
  2252. std::string CONFIG = cmSystemTools::UpperCase(configName);
  2253. std::string configFlagsVar = std::string("CMAKE_CUDA_FLAGS_") + CONFIG;
  2254. std::string flags =
  2255. std::string(this->Makefile->GetSafeDefinition("CMAKE_CUDA_FLAGS")) +
  2256. std::string(" ") +
  2257. std::string(this->Makefile->GetSafeDefinition(configFlagsVar));
  2258. // Get preprocessor definitions for this directory.
  2259. std::string defineFlags =
  2260. this->GeneratorTarget->Target->GetMakefile()->GetDefineFlags();
  2261. cudaOptions.Parse(flags.c_str());
  2262. cudaOptions.Parse(defineFlags.c_str());
  2263. cudaOptions.ParseFinish();
  2264. if (this->GeneratorTarget->GetPropertyAsBool("CUDA_SEPARABLE_COMPILATION")) {
  2265. cudaOptions.AddFlag("GenerateRelocatableDeviceCode", "true");
  2266. }
  2267. // Convert the host compiler options to the toolset's abstractions
  2268. // using a secondary flag table.
  2269. cudaOptions.ClearTables();
  2270. cudaOptions.AddTable(gg->GetCudaHostFlagTable());
  2271. cudaOptions.Reparse("AdditionalCompilerOptions");
  2272. // `CUDA 8.0.targets` places these before nvcc! Just drop whatever
  2273. // did not parse and hope it works.
  2274. cudaOptions.RemoveFlag("AdditionalCompilerOptions");
  2275. cudaOptions.FixCudaCodeGeneration();
  2276. std::vector<std::string> targetDefines;
  2277. this->GeneratorTarget->GetCompileDefinitions(targetDefines,
  2278. configName.c_str(), "CUDA");
  2279. cudaOptions.AddDefines(targetDefines);
  2280. // Add a definition for the configuration name.
  2281. std::string configDefine = "CMAKE_INTDIR=\"";
  2282. configDefine += configName;
  2283. configDefine += "\"";
  2284. cudaOptions.AddDefine(configDefine);
  2285. if (const char* exportMacro = this->GeneratorTarget->GetExportMacro()) {
  2286. cudaOptions.AddDefine(exportMacro);
  2287. }
  2288. this->CudaOptions[configName] = pOptions.release();
  2289. return true;
  2290. }
  2291. void cmVisualStudio10TargetGenerator::WriteCudaOptions(
  2292. std::string const& configName, std::vector<std::string> const& includes)
  2293. {
  2294. if (!this->MSTools || !this->GlobalGenerator->IsCudaEnabled()) {
  2295. return;
  2296. }
  2297. this->WriteString("<CudaCompile>\n", 2);
  2298. Options& cudaOptions = *(this->CudaOptions[configName]);
  2299. cudaOptions.AppendFlag("Include", includes);
  2300. cudaOptions.AppendFlag("Include", "%(Include)");
  2301. cudaOptions.OutputPreprocessorDefinitions(*this->BuildFileStream, " ",
  2302. "\n", "CUDA");
  2303. cudaOptions.PrependInheritedString("AdditionalOptions");
  2304. cudaOptions.OutputFlagMap(*this->BuildFileStream, " ");
  2305. this->WriteString("</CudaCompile>\n", 2);
  2306. }
  2307. bool cmVisualStudio10TargetGenerator::ComputeMasmOptions()
  2308. {
  2309. if (!this->GlobalGenerator->IsMasmEnabled()) {
  2310. return true;
  2311. }
  2312. for (std::vector<std::string>::const_iterator i =
  2313. this->Configurations.begin();
  2314. i != this->Configurations.end(); ++i) {
  2315. if (!this->ComputeMasmOptions(*i)) {
  2316. return false;
  2317. }
  2318. }
  2319. return true;
  2320. }
  2321. bool cmVisualStudio10TargetGenerator::ComputeMasmOptions(
  2322. std::string const& configName)
  2323. {
  2324. cmGlobalVisualStudio10Generator* gg =
  2325. static_cast<cmGlobalVisualStudio10Generator*>(this->GlobalGenerator);
  2326. CM_AUTO_PTR<Options> pOptions(new Options(
  2327. this->LocalGenerator, Options::MasmCompiler, gg->GetMasmFlagTable()));
  2328. Options& masmOptions = *pOptions;
  2329. std::string CONFIG = cmSystemTools::UpperCase(configName);
  2330. std::string configFlagsVar = std::string("CMAKE_ASM_MASM_FLAGS_") + CONFIG;
  2331. std::string flags =
  2332. std::string(this->Makefile->GetSafeDefinition("CMAKE_ASM_MASM_FLAGS")) +
  2333. std::string(" ") +
  2334. std::string(this->Makefile->GetSafeDefinition(configFlagsVar));
  2335. masmOptions.Parse(flags.c_str());
  2336. this->MasmOptions[configName] = pOptions.release();
  2337. return true;
  2338. }
  2339. void cmVisualStudio10TargetGenerator::WriteMasmOptions(
  2340. std::string const& configName, std::vector<std::string> const& includes)
  2341. {
  2342. if (!this->MSTools || !this->GlobalGenerator->IsMasmEnabled()) {
  2343. return;
  2344. }
  2345. this->WriteString("<MASM>\n", 2);
  2346. // Preprocessor definitions and includes are shared with clOptions.
  2347. Options& clOptions = *(this->ClOptions[configName]);
  2348. clOptions.OutputPreprocessorDefinitions(*this->BuildFileStream, " ",
  2349. "\n", "ASM_MASM");
  2350. Options& masmOptions = *(this->MasmOptions[configName]);
  2351. masmOptions.AppendFlag("IncludePaths", includes);
  2352. masmOptions.AppendFlag("IncludePaths", "%(IncludePaths)");
  2353. masmOptions.PrependInheritedString("AdditionalOptions");
  2354. masmOptions.OutputFlagMap(*this->BuildFileStream, " ");
  2355. this->WriteString("</MASM>\n", 2);
  2356. }
  2357. bool cmVisualStudio10TargetGenerator::ComputeNasmOptions()
  2358. {
  2359. if (!this->GlobalGenerator->IsNasmEnabled()) {
  2360. return true;
  2361. }
  2362. for (std::vector<std::string>::const_iterator i =
  2363. this->Configurations.begin();
  2364. i != this->Configurations.end(); ++i) {
  2365. if (!this->ComputeNasmOptions(*i)) {
  2366. return false;
  2367. }
  2368. }
  2369. return true;
  2370. }
  2371. bool cmVisualStudio10TargetGenerator::ComputeNasmOptions(
  2372. std::string const& configName)
  2373. {
  2374. cmGlobalVisualStudio10Generator* gg =
  2375. static_cast<cmGlobalVisualStudio10Generator*>(this->GlobalGenerator);
  2376. CM_AUTO_PTR<Options> pOptions(new Options(
  2377. this->LocalGenerator, Options::NasmCompiler, gg->GetNasmFlagTable()));
  2378. Options& nasmOptions = *pOptions;
  2379. std::string CONFIG = cmSystemTools::UpperCase(configName);
  2380. std::string configFlagsVar = std::string("CMAKE_ASM_NASM_FLAGS_") + CONFIG;
  2381. std::string flags =
  2382. std::string(this->Makefile->GetSafeDefinition("CMAKE_ASM_NASM_FLAGS")) +
  2383. std::string(" -f") + std::string(this->Makefile->GetSafeDefinition(
  2384. "CMAKE_ASM_NASM_OBJECT_FORMAT")) +
  2385. std::string(" ") +
  2386. std::string(this->Makefile->GetSafeDefinition(configFlagsVar));
  2387. nasmOptions.Parse(flags.c_str());
  2388. this->NasmOptions[configName] = pOptions.release();
  2389. return true;
  2390. }
  2391. void cmVisualStudio10TargetGenerator::WriteNasmOptions(
  2392. std::string const& configName, std::vector<std::string> includes)
  2393. {
  2394. if (!this->GlobalGenerator->IsNasmEnabled()) {
  2395. return;
  2396. }
  2397. this->WriteString("<NASM>\n", 2);
  2398. Options& nasmOptions = *(this->NasmOptions[configName]);
  2399. for (size_t i = 0; i < includes.size(); i++) {
  2400. includes[i] += "\\";
  2401. }
  2402. nasmOptions.AppendFlag("IncludePaths", includes);
  2403. nasmOptions.AppendFlag("IncludePaths", "%(IncludePaths)");
  2404. nasmOptions.OutputFlagMap(*this->BuildFileStream, " ");
  2405. nasmOptions.PrependInheritedString("AdditionalOptions");
  2406. nasmOptions.OutputPreprocessorDefinitions(*this->BuildFileStream, " ",
  2407. "\n", "ASM_NASM");
  2408. // Preprocessor definitions and includes are shared with clOptions.
  2409. Options& clOptions = *(this->ClOptions[configName]);
  2410. clOptions.OutputPreprocessorDefinitions(*this->BuildFileStream, " ",
  2411. "\n", "ASM_NASM");
  2412. this->WriteString("</NASM>\n", 2);
  2413. }
  2414. void cmVisualStudio10TargetGenerator::WriteLibOptions(
  2415. std::string const& config)
  2416. {
  2417. if (this->GeneratorTarget->GetType() != cmStateEnums::STATIC_LIBRARY &&
  2418. this->GeneratorTarget->GetType() != cmStateEnums::OBJECT_LIBRARY) {
  2419. return;
  2420. }
  2421. std::string libflags;
  2422. this->LocalGenerator->GetStaticLibraryFlags(
  2423. libflags, cmSystemTools::UpperCase(config), this->GeneratorTarget);
  2424. if (!libflags.empty()) {
  2425. this->WriteString("<Lib>\n", 2);
  2426. cmGlobalVisualStudio10Generator* gg =
  2427. static_cast<cmGlobalVisualStudio10Generator*>(this->GlobalGenerator);
  2428. cmVisualStudioGeneratorOptions libOptions(
  2429. this->LocalGenerator, cmVisualStudioGeneratorOptions::Linker,
  2430. gg->GetLibFlagTable(), 0, this);
  2431. libOptions.Parse(libflags.c_str());
  2432. libOptions.PrependInheritedString("AdditionalOptions");
  2433. libOptions.OutputFlagMap(*this->BuildFileStream, " ");
  2434. this->WriteString("</Lib>\n", 2);
  2435. }
  2436. // We cannot generate metadata for static libraries. WindowsPhone
  2437. // and WindowsStore tools look at GenerateWindowsMetadata in the
  2438. // Link tool options even for static libraries.
  2439. if (this->GlobalGenerator->TargetsWindowsPhone() ||
  2440. this->GlobalGenerator->TargetsWindowsStore()) {
  2441. this->WriteString("<Link>\n", 2);
  2442. this->WriteString("<GenerateWindowsMetadata>false"
  2443. "</GenerateWindowsMetadata>\n",
  2444. 3);
  2445. this->WriteString("</Link>\n", 2);
  2446. }
  2447. }
  2448. void cmVisualStudio10TargetGenerator::WriteManifestOptions(
  2449. std::string const& config)
  2450. {
  2451. if (this->GeneratorTarget->GetType() != cmStateEnums::EXECUTABLE &&
  2452. this->GeneratorTarget->GetType() != cmStateEnums::SHARED_LIBRARY &&
  2453. this->GeneratorTarget->GetType() != cmStateEnums::MODULE_LIBRARY) {
  2454. return;
  2455. }
  2456. std::vector<cmSourceFile const*> manifest_srcs;
  2457. this->GeneratorTarget->GetManifests(manifest_srcs, config);
  2458. if (!manifest_srcs.empty()) {
  2459. this->WriteString("<Manifest>\n", 2);
  2460. this->WriteString("<AdditionalManifestFiles>", 3);
  2461. for (std::vector<cmSourceFile const*>::const_iterator mi =
  2462. manifest_srcs.begin();
  2463. mi != manifest_srcs.end(); ++mi) {
  2464. std::string m = this->ConvertPath((*mi)->GetFullPath(), false);
  2465. this->ConvertToWindowsSlash(m);
  2466. (*this->BuildFileStream) << m << ";";
  2467. }
  2468. (*this->BuildFileStream) << "</AdditionalManifestFiles>\n";
  2469. this->WriteString("</Manifest>\n", 2);
  2470. }
  2471. }
  2472. void cmVisualStudio10TargetGenerator::WriteAntBuildOptions(
  2473. std::string const& configName)
  2474. {
  2475. // Look through the sources for AndroidManifest.xml and use
  2476. // its location as the root source directory.
  2477. std::string rootDir = this->LocalGenerator->GetCurrentSourceDirectory();
  2478. {
  2479. std::vector<cmSourceFile const*> extraSources;
  2480. this->GeneratorTarget->GetExtraSources(extraSources, "");
  2481. for (std::vector<cmSourceFile const*>::const_iterator si =
  2482. extraSources.begin();
  2483. si != extraSources.end(); ++si) {
  2484. if ("androidmanifest.xml" ==
  2485. cmSystemTools::LowerCase((*si)->GetLocation().GetName())) {
  2486. rootDir = (*si)->GetLocation().GetDirectory();
  2487. break;
  2488. }
  2489. }
  2490. }
  2491. // Tell MSBuild to launch Ant.
  2492. {
  2493. std::string antBuildPath = rootDir;
  2494. this->WriteString("<AntBuild>\n", 2);
  2495. this->WriteString("<AntBuildPath>", 3);
  2496. this->ConvertToWindowsSlash(antBuildPath);
  2497. (*this->BuildFileStream) << cmVS10EscapeXML(antBuildPath)
  2498. << "</AntBuildPath>\n";
  2499. }
  2500. if (this->GeneratorTarget->GetPropertyAsBool("ANDROID_SKIP_ANT_STEP")) {
  2501. this->WriteString("<SkipAntStep>true</SkipAntStep>\n", 3);
  2502. }
  2503. if (this->GeneratorTarget->GetPropertyAsBool("ANDROID_PROGUARD")) {
  2504. this->WriteString("<EnableProGuard>true</EnableProGuard>\n", 3);
  2505. }
  2506. if (const char* proGuardConfigLocation =
  2507. this->GeneratorTarget->GetProperty("ANDROID_PROGUARD_CONFIG_PATH")) {
  2508. this->WriteString("<ProGuardConfigLocation>", 3);
  2509. (*this->BuildFileStream) << cmVS10EscapeXML(proGuardConfigLocation)
  2510. << "</ProGuardConfigLocation>\n";
  2511. }
  2512. if (const char* securePropertiesLocation =
  2513. this->GeneratorTarget->GetProperty("ANDROID_SECURE_PROPS_PATH")) {
  2514. this->WriteString("<SecurePropertiesLocation>", 3);
  2515. (*this->BuildFileStream) << cmVS10EscapeXML(securePropertiesLocation)
  2516. << "</SecurePropertiesLocation>\n";
  2517. }
  2518. if (const char* nativeLibDirectoriesExpression =
  2519. this->GeneratorTarget->GetProperty("ANDROID_NATIVE_LIB_DIRECTORIES")) {
  2520. cmGeneratorExpression ge;
  2521. CM_AUTO_PTR<cmCompiledGeneratorExpression> cge =
  2522. ge.Parse(nativeLibDirectoriesExpression);
  2523. std::string nativeLibDirs =
  2524. cge->Evaluate(this->LocalGenerator, configName);
  2525. this->WriteString("<NativeLibDirectories>", 3);
  2526. (*this->BuildFileStream) << cmVS10EscapeXML(nativeLibDirs)
  2527. << "</NativeLibDirectories>\n";
  2528. }
  2529. if (const char* nativeLibDependenciesExpression =
  2530. this->GeneratorTarget->GetProperty(
  2531. "ANDROID_NATIVE_LIB_DEPENDENCIES")) {
  2532. cmGeneratorExpression ge;
  2533. CM_AUTO_PTR<cmCompiledGeneratorExpression> cge =
  2534. ge.Parse(nativeLibDependenciesExpression);
  2535. std::string nativeLibDeps =
  2536. cge->Evaluate(this->LocalGenerator, configName);
  2537. this->WriteString("<NativeLibDependencies>", 3);
  2538. (*this->BuildFileStream) << cmVS10EscapeXML(nativeLibDeps)
  2539. << "</NativeLibDependencies>\n";
  2540. }
  2541. if (const char* javaSourceDir =
  2542. this->GeneratorTarget->GetProperty("ANDROID_JAVA_SOURCE_DIR")) {
  2543. this->WriteString("<JavaSourceDir>", 3);
  2544. (*this->BuildFileStream) << cmVS10EscapeXML(javaSourceDir)
  2545. << "</JavaSourceDir>\n";
  2546. }
  2547. if (const char* jarDirectoriesExpression =
  2548. this->GeneratorTarget->GetProperty("ANDROID_JAR_DIRECTORIES")) {
  2549. cmGeneratorExpression ge;
  2550. CM_AUTO_PTR<cmCompiledGeneratorExpression> cge =
  2551. ge.Parse(jarDirectoriesExpression);
  2552. std::string jarDirectories =
  2553. cge->Evaluate(this->LocalGenerator, configName);
  2554. this->WriteString("<JarDirectories>", 3);
  2555. (*this->BuildFileStream) << cmVS10EscapeXML(jarDirectories)
  2556. << "</JarDirectories>\n";
  2557. }
  2558. if (const char* jarDeps =
  2559. this->GeneratorTarget->GetProperty("ANDROID_JAR_DEPENDENCIES")) {
  2560. this->WriteString("<JarDependencies>", 3);
  2561. (*this->BuildFileStream) << cmVS10EscapeXML(jarDeps)
  2562. << "</JarDependencies>\n";
  2563. }
  2564. if (const char* assetsDirectories =
  2565. this->GeneratorTarget->GetProperty("ANDROID_ASSETS_DIRECTORIES")) {
  2566. this->WriteString("<AssetsDirectories>", 3);
  2567. (*this->BuildFileStream) << cmVS10EscapeXML(assetsDirectories)
  2568. << "</AssetsDirectories>\n";
  2569. }
  2570. {
  2571. std::string manifest_xml = rootDir + "/AndroidManifest.xml";
  2572. this->ConvertToWindowsSlash(manifest_xml);
  2573. this->WriteString("<AndroidManifestLocation>", 3);
  2574. (*this->BuildFileStream) << cmVS10EscapeXML(manifest_xml)
  2575. << "</AndroidManifestLocation>\n";
  2576. }
  2577. if (const char* antAdditionalOptions =
  2578. this->GeneratorTarget->GetProperty("ANDROID_ANT_ADDITIONAL_OPTIONS")) {
  2579. this->WriteString("<AdditionalOptions>", 3);
  2580. (*this->BuildFileStream) << cmVS10EscapeXML(antAdditionalOptions)
  2581. << " %(AdditionalOptions)</AdditionalOptions>\n";
  2582. }
  2583. this->WriteString("</AntBuild>\n", 2);
  2584. }
  2585. bool cmVisualStudio10TargetGenerator::ComputeLinkOptions()
  2586. {
  2587. if (this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE ||
  2588. this->GeneratorTarget->GetType() == cmStateEnums::SHARED_LIBRARY ||
  2589. this->GeneratorTarget->GetType() == cmStateEnums::MODULE_LIBRARY) {
  2590. for (std::vector<std::string>::const_iterator i =
  2591. this->Configurations.begin();
  2592. i != this->Configurations.end(); ++i) {
  2593. if (!this->ComputeLinkOptions(*i)) {
  2594. return false;
  2595. }
  2596. }
  2597. }
  2598. return true;
  2599. }
  2600. bool cmVisualStudio10TargetGenerator::ComputeLinkOptions(
  2601. std::string const& config)
  2602. {
  2603. cmGlobalVisualStudio10Generator* gg =
  2604. static_cast<cmGlobalVisualStudio10Generator*>(this->GlobalGenerator);
  2605. CM_AUTO_PTR<Options> pOptions(new Options(
  2606. this->LocalGenerator, Options::Linker, gg->GetLinkFlagTable(), 0, this));
  2607. Options& linkOptions = *pOptions;
  2608. cmGeneratorTarget::LinkClosure const* linkClosure =
  2609. this->GeneratorTarget->GetLinkClosure(config);
  2610. const std::string& linkLanguage = linkClosure->LinkerLanguage;
  2611. if (linkLanguage.empty()) {
  2612. cmSystemTools::Error(
  2613. "CMake can not determine linker language for target: ",
  2614. this->Name.c_str());
  2615. return false;
  2616. }
  2617. std::string CONFIG = cmSystemTools::UpperCase(config);
  2618. const char* linkType = "SHARED";
  2619. if (this->GeneratorTarget->GetType() == cmStateEnums::MODULE_LIBRARY) {
  2620. linkType = "MODULE";
  2621. }
  2622. if (this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE) {
  2623. linkType = "EXE";
  2624. }
  2625. std::string flags;
  2626. std::string linkFlagVarBase = "CMAKE_";
  2627. linkFlagVarBase += linkType;
  2628. linkFlagVarBase += "_LINKER_FLAGS";
  2629. flags += " ";
  2630. flags += this->GeneratorTarget->Target->GetMakefile()->GetRequiredDefinition(
  2631. linkFlagVarBase.c_str());
  2632. std::string linkFlagVar = linkFlagVarBase + "_" + CONFIG;
  2633. flags += " ";
  2634. flags += this->GeneratorTarget->Target->GetMakefile()->GetRequiredDefinition(
  2635. linkFlagVar.c_str());
  2636. const char* targetLinkFlags =
  2637. this->GeneratorTarget->GetProperty("LINK_FLAGS");
  2638. if (targetLinkFlags) {
  2639. flags += " ";
  2640. flags += targetLinkFlags;
  2641. }
  2642. std::string flagsProp = "LINK_FLAGS_";
  2643. flagsProp += CONFIG;
  2644. if (const char* flagsConfig =
  2645. this->GeneratorTarget->GetProperty(flagsProp.c_str())) {
  2646. flags += " ";
  2647. flags += flagsConfig;
  2648. }
  2649. cmComputeLinkInformation* pcli =
  2650. this->GeneratorTarget->GetLinkInformation(config.c_str());
  2651. if (!pcli) {
  2652. cmSystemTools::Error(
  2653. "CMake can not compute cmComputeLinkInformation for target: ",
  2654. this->Name.c_str());
  2655. return false;
  2656. }
  2657. cmComputeLinkInformation& cli = *pcli;
  2658. std::vector<std::string> libVec;
  2659. std::vector<std::string> vsTargetVec;
  2660. this->AddLibraries(cli, libVec, vsTargetVec);
  2661. if (std::find(linkClosure->Languages.begin(), linkClosure->Languages.end(),
  2662. "CUDA") != linkClosure->Languages.end()) {
  2663. switch (this->CudaOptions[config]->GetCudaRuntime()) {
  2664. case cmVisualStudioGeneratorOptions::CudaRuntimeStatic:
  2665. libVec.push_back("cudart_static.lib");
  2666. break;
  2667. case cmVisualStudioGeneratorOptions::CudaRuntimeShared:
  2668. libVec.push_back("cudart.lib");
  2669. break;
  2670. case cmVisualStudioGeneratorOptions::CudaRuntimeNone:
  2671. break;
  2672. }
  2673. }
  2674. std::string standardLibsVar = "CMAKE_";
  2675. standardLibsVar += linkLanguage;
  2676. standardLibsVar += "_STANDARD_LIBRARIES";
  2677. std::string const libs =
  2678. this->Makefile->GetSafeDefinition(standardLibsVar.c_str());
  2679. cmSystemTools::ParseWindowsCommandLine(libs.c_str(), libVec);
  2680. linkOptions.AddFlag("AdditionalDependencies", libVec);
  2681. // Populate TargetsFileAndConfigsVec
  2682. for (std::vector<std::string>::iterator ti = vsTargetVec.begin();
  2683. ti != vsTargetVec.end(); ++ti) {
  2684. this->AddTargetsFileAndConfigPair(*ti, config);
  2685. }
  2686. std::vector<std::string> const& ldirs = cli.GetDirectories();
  2687. std::vector<std::string> linkDirs;
  2688. for (std::vector<std::string>::const_iterator d = ldirs.begin();
  2689. d != ldirs.end(); ++d) {
  2690. // first just full path
  2691. linkDirs.push_back(*d);
  2692. // next path with configuration type Debug, Release, etc
  2693. linkDirs.push_back(*d + "/$(Configuration)");
  2694. }
  2695. linkDirs.push_back("%(AdditionalLibraryDirectories)");
  2696. linkOptions.AddFlag("AdditionalLibraryDirectories", linkDirs);
  2697. std::string targetName;
  2698. std::string targetNameSO;
  2699. std::string targetNameFull;
  2700. std::string targetNameImport;
  2701. std::string targetNamePDB;
  2702. if (this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE) {
  2703. this->GeneratorTarget->GetExecutableNames(targetName, targetNameFull,
  2704. targetNameImport, targetNamePDB,
  2705. config.c_str());
  2706. } else {
  2707. this->GeneratorTarget->GetLibraryNames(targetName, targetNameSO,
  2708. targetNameFull, targetNameImport,
  2709. targetNamePDB, config.c_str());
  2710. }
  2711. if (this->MSTools) {
  2712. linkOptions.AddFlag("Version", "");
  2713. if (this->GeneratorTarget->GetPropertyAsBool("WIN32_EXECUTABLE")) {
  2714. if (this->GlobalGenerator->TargetsWindowsCE()) {
  2715. linkOptions.AddFlag("SubSystem", "WindowsCE");
  2716. if (this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE) {
  2717. if (this->ClOptions[config]->UsingUnicode()) {
  2718. linkOptions.AddFlag("EntryPointSymbol", "wWinMainCRTStartup");
  2719. } else {
  2720. linkOptions.AddFlag("EntryPointSymbol", "WinMainCRTStartup");
  2721. }
  2722. }
  2723. } else {
  2724. linkOptions.AddFlag("SubSystem", "Windows");
  2725. }
  2726. } else {
  2727. if (this->GlobalGenerator->TargetsWindowsCE()) {
  2728. linkOptions.AddFlag("SubSystem", "WindowsCE");
  2729. if (this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE) {
  2730. if (this->ClOptions[config]->UsingUnicode()) {
  2731. linkOptions.AddFlag("EntryPointSymbol", "mainWCRTStartup");
  2732. } else {
  2733. linkOptions.AddFlag("EntryPointSymbol", "mainACRTStartup");
  2734. }
  2735. }
  2736. } else {
  2737. linkOptions.AddFlag("SubSystem", "Console");
  2738. };
  2739. }
  2740. if (const char* stackVal = this->Makefile->GetDefinition(
  2741. "CMAKE_" + linkLanguage + "_STACK_SIZE")) {
  2742. linkOptions.AddFlag("StackReserveSize", stackVal);
  2743. }
  2744. if (this->LocalGenerator->GetVersion() >=
  2745. cmGlobalVisualStudioGenerator::VS14) {
  2746. linkOptions.AddFlag("GenerateDebugInformation", "No");
  2747. } else {
  2748. linkOptions.AddFlag("GenerateDebugInformation", "false");
  2749. }
  2750. std::string pdb = this->GeneratorTarget->GetPDBDirectory(config.c_str());
  2751. pdb += "/";
  2752. pdb += targetNamePDB;
  2753. std::string imLib =
  2754. this->GeneratorTarget->GetDirectory(config.c_str(), true);
  2755. imLib += "/";
  2756. imLib += targetNameImport;
  2757. linkOptions.AddFlag("ImportLibrary", imLib.c_str());
  2758. linkOptions.AddFlag("ProgramDataBaseFile", pdb.c_str());
  2759. // A Windows Runtime component uses internal .NET metadata,
  2760. // so does not have an import library.
  2761. if (this->GeneratorTarget->GetPropertyAsBool("VS_WINRT_COMPONENT") &&
  2762. this->GeneratorTarget->GetType() != cmStateEnums::EXECUTABLE) {
  2763. linkOptions.AddFlag("GenerateWindowsMetadata", "true");
  2764. } else if (this->GlobalGenerator->TargetsWindowsPhone() ||
  2765. this->GlobalGenerator->TargetsWindowsStore()) {
  2766. // WindowsPhone and WindowsStore components are in an app container
  2767. // and produce WindowsMetadata. If we are not producing a WINRT
  2768. // component, then do not generate the metadata here.
  2769. linkOptions.AddFlag("GenerateWindowsMetadata", "false");
  2770. }
  2771. if (this->GlobalGenerator->TargetsWindowsPhone() &&
  2772. this->GlobalGenerator->GetSystemVersion() == "8.0") {
  2773. // WindowsPhone 8.0 does not have ole32.
  2774. linkOptions.AppendFlag("IgnoreSpecificDefaultLibraries", "ole32.lib");
  2775. }
  2776. } else if (this->NsightTegra) {
  2777. linkOptions.AddFlag("SoName", targetNameSO.c_str());
  2778. }
  2779. linkOptions.Parse(flags.c_str());
  2780. if (this->MSTools) {
  2781. cmGeneratorTarget::ModuleDefinitionInfo const* mdi =
  2782. this->GeneratorTarget->GetModuleDefinitionInfo(config);
  2783. if (mdi && !mdi->DefFile.empty()) {
  2784. linkOptions.AddFlag("ModuleDefinitionFile", mdi->DefFile.c_str());
  2785. }
  2786. linkOptions.AppendFlag("IgnoreSpecificDefaultLibraries",
  2787. "%(IgnoreSpecificDefaultLibraries)");
  2788. }
  2789. // Hack to fix flag version selection in a common use case.
  2790. // FIXME: Select flag table based on toolset instead of VS version.
  2791. if (this->LocalGenerator->GetVersion() >=
  2792. cmGlobalVisualStudioGenerator::VS14) {
  2793. cmGlobalVisualStudio10Generator* gg =
  2794. static_cast<cmGlobalVisualStudio10Generator*>(this->GlobalGenerator);
  2795. const char* toolset = gg->GetPlatformToolset();
  2796. if (toolset &&
  2797. (toolset == kWINDOWS_7_1_SDK || /* clang-format please break here */
  2798. cmHasLiteralPrefix(toolset, "v80") ||
  2799. cmHasLiteralPrefix(toolset, "v90") ||
  2800. cmHasLiteralPrefix(toolset, "v100") ||
  2801. cmHasLiteralPrefix(toolset, "v110") ||
  2802. cmHasLiteralPrefix(toolset, "v120"))) {
  2803. if (const char* debug =
  2804. linkOptions.GetFlag("GenerateDebugInformation")) {
  2805. // Convert value from enumeration back to boolean for older toolsets.
  2806. if (strcmp(debug, "No") == 0) {
  2807. linkOptions.AddFlag("GenerateDebugInformation", "false");
  2808. } else if (strcmp(debug, "Debug") == 0) {
  2809. linkOptions.AddFlag("GenerateDebugInformation", "true");
  2810. }
  2811. }
  2812. }
  2813. }
  2814. this->LinkOptions[config] = pOptions.release();
  2815. return true;
  2816. }
  2817. bool cmVisualStudio10TargetGenerator::ComputeLibOptions()
  2818. {
  2819. if (this->GeneratorTarget->GetType() == cmStateEnums::STATIC_LIBRARY) {
  2820. for (std::vector<std::string>::const_iterator i =
  2821. this->Configurations.begin();
  2822. i != this->Configurations.end(); ++i) {
  2823. if (!this->ComputeLibOptions(*i)) {
  2824. return false;
  2825. }
  2826. }
  2827. }
  2828. return true;
  2829. }
  2830. bool cmVisualStudio10TargetGenerator::ComputeLibOptions(
  2831. std::string const& config)
  2832. {
  2833. cmComputeLinkInformation* pcli =
  2834. this->GeneratorTarget->GetLinkInformation(config.c_str());
  2835. if (!pcli) {
  2836. cmSystemTools::Error(
  2837. "CMake can not compute cmComputeLinkInformation for target: ",
  2838. this->Name.c_str());
  2839. return false;
  2840. }
  2841. cmComputeLinkInformation& cli = *pcli;
  2842. typedef cmComputeLinkInformation::ItemVector ItemVector;
  2843. const ItemVector& libs = cli.GetItems();
  2844. std::string currentBinDir =
  2845. this->LocalGenerator->GetCurrentBinaryDirectory();
  2846. for (ItemVector::const_iterator l = libs.begin(); l != libs.end(); ++l) {
  2847. if (l->IsPath && cmVS10IsTargetsFile(l->Value)) {
  2848. std::string path = this->LocalGenerator->ConvertToRelativePath(
  2849. currentBinDir, l->Value.c_str());
  2850. this->ConvertToWindowsSlash(path);
  2851. this->AddTargetsFileAndConfigPair(path, config);
  2852. }
  2853. }
  2854. return true;
  2855. }
  2856. void cmVisualStudio10TargetGenerator::WriteLinkOptions(
  2857. std::string const& config)
  2858. {
  2859. if (this->GeneratorTarget->GetType() == cmStateEnums::STATIC_LIBRARY ||
  2860. this->GeneratorTarget->GetType() > cmStateEnums::MODULE_LIBRARY) {
  2861. return;
  2862. }
  2863. if (csproj == this->ProjectType) {
  2864. return;
  2865. }
  2866. Options& linkOptions = *(this->LinkOptions[config]);
  2867. this->WriteString("<Link>\n", 2);
  2868. linkOptions.PrependInheritedString("AdditionalOptions");
  2869. linkOptions.OutputFlagMap(*this->BuildFileStream, " ");
  2870. this->WriteString("</Link>\n", 2);
  2871. if (!this->GlobalGenerator->NeedLinkLibraryDependencies(
  2872. this->GeneratorTarget)) {
  2873. this->WriteString("<ProjectReference>\n", 2);
  2874. this->WriteString(
  2875. "<LinkLibraryDependencies>false</LinkLibraryDependencies>\n", 3);
  2876. this->WriteString("</ProjectReference>\n", 2);
  2877. }
  2878. }
  2879. void cmVisualStudio10TargetGenerator::AddLibraries(
  2880. cmComputeLinkInformation& cli, std::vector<std::string>& libVec,
  2881. std::vector<std::string>& vsTargetVec)
  2882. {
  2883. typedef cmComputeLinkInformation::ItemVector ItemVector;
  2884. ItemVector const& libs = cli.GetItems();
  2885. std::string currentBinDir =
  2886. this->LocalGenerator->GetCurrentBinaryDirectory();
  2887. for (ItemVector::const_iterator l = libs.begin(); l != libs.end(); ++l) {
  2888. if (l->IsPath) {
  2889. std::string path = this->LocalGenerator->ConvertToRelativePath(
  2890. currentBinDir, l->Value.c_str());
  2891. this->ConvertToWindowsSlash(path);
  2892. if (cmVS10IsTargetsFile(l->Value)) {
  2893. vsTargetVec.push_back(path);
  2894. } else {
  2895. libVec.push_back(path);
  2896. }
  2897. } else if (!l->Target ||
  2898. l->Target->GetType() != cmStateEnums::INTERFACE_LIBRARY) {
  2899. libVec.push_back(l->Value);
  2900. }
  2901. }
  2902. }
  2903. void cmVisualStudio10TargetGenerator::AddTargetsFileAndConfigPair(
  2904. std::string const& targetsFile, std::string const& config)
  2905. {
  2906. for (std::vector<TargetsFileAndConfigs>::iterator i =
  2907. this->TargetsFileAndConfigsVec.begin();
  2908. i != this->TargetsFileAndConfigsVec.end(); ++i) {
  2909. if (cmSystemTools::ComparePath(targetsFile, i->File)) {
  2910. if (std::find(i->Configs.begin(), i->Configs.end(), config) ==
  2911. i->Configs.end()) {
  2912. i->Configs.push_back(config);
  2913. }
  2914. return;
  2915. }
  2916. }
  2917. TargetsFileAndConfigs entry;
  2918. entry.File = targetsFile;
  2919. entry.Configs.push_back(config);
  2920. this->TargetsFileAndConfigsVec.push_back(entry);
  2921. }
  2922. void cmVisualStudio10TargetGenerator::WriteMidlOptions(
  2923. std::string const& /*config*/, std::vector<std::string> const& includes)
  2924. {
  2925. if (!this->MSTools) {
  2926. return;
  2927. }
  2928. if (csproj == this->ProjectType) {
  2929. return;
  2930. }
  2931. // This processes *any* of the .idl files specified in the project's file
  2932. // list (and passed as the item metadata %(Filename) expressing the rule
  2933. // input filename) into output files at the per-config *build* dir
  2934. // ($(IntDir)) each.
  2935. //
  2936. // IOW, this MIDL section is intended to provide a fully generic syntax
  2937. // content suitable for most cases (read: if you get errors, then it's quite
  2938. // probable that the error is on your side of the .idl setup).
  2939. //
  2940. // Also, note that the marked-as-generated _i.c file in the Visual Studio
  2941. // generator case needs to be referred to as $(IntDir)\foo_i.c at the
  2942. // project's file list, otherwise the compiler-side processing won't pick it
  2943. // up (for non-directory form, it ends up looking in project binary dir
  2944. // only). Perhaps there's something to be done to make this more automatic
  2945. // on the CMake side?
  2946. this->WriteString("<Midl>\n", 2);
  2947. this->WriteString("<AdditionalIncludeDirectories>", 3);
  2948. for (std::vector<std::string>::const_iterator i = includes.begin();
  2949. i != includes.end(); ++i) {
  2950. *this->BuildFileStream << cmVS10EscapeXML(*i) << ";";
  2951. }
  2952. this->WriteString("%(AdditionalIncludeDirectories)"
  2953. "</AdditionalIncludeDirectories>\n",
  2954. 0);
  2955. this->WriteString("<OutputDirectory>$(ProjectDir)/$(IntDir)"
  2956. "</OutputDirectory>\n",
  2957. 3);
  2958. this->WriteString("<HeaderFileName>%(Filename).h</HeaderFileName>\n", 3);
  2959. this->WriteString("<TypeLibraryName>%(Filename).tlb</TypeLibraryName>\n", 3);
  2960. this->WriteString("<InterfaceIdentifierFileName>"
  2961. "%(Filename)_i.c</InterfaceIdentifierFileName>\n",
  2962. 3);
  2963. this->WriteString("<ProxyFileName>%(Filename)_p.c</ProxyFileName>\n", 3);
  2964. this->WriteString("</Midl>\n", 2);
  2965. }
  2966. void cmVisualStudio10TargetGenerator::WriteItemDefinitionGroups()
  2967. {
  2968. for (std::vector<std::string>::const_iterator i =
  2969. this->Configurations.begin();
  2970. i != this->Configurations.end(); ++i) {
  2971. std::vector<std::string> includes;
  2972. this->LocalGenerator->GetIncludeDirectories(
  2973. includes, this->GeneratorTarget, "C", i->c_str());
  2974. for (std::vector<std::string>::iterator ii = includes.begin();
  2975. ii != includes.end(); ++ii) {
  2976. this->ConvertToWindowsSlash(*ii);
  2977. }
  2978. this->WritePlatformConfigTag("ItemDefinitionGroup", i->c_str(), 1);
  2979. *this->BuildFileStream << "\n";
  2980. // output cl compile flags <ClCompile></ClCompile>
  2981. if (this->GeneratorTarget->GetType() <= cmStateEnums::OBJECT_LIBRARY) {
  2982. this->WriteClOptions(*i, includes);
  2983. // output rc compile flags <ResourceCompile></ResourceCompile>
  2984. this->WriteRCOptions(*i, includes);
  2985. this->WriteCudaOptions(*i, includes);
  2986. this->WriteMasmOptions(*i, includes);
  2987. this->WriteNasmOptions(*i, includes);
  2988. }
  2989. // output midl flags <Midl></Midl>
  2990. this->WriteMidlOptions(*i, includes);
  2991. // write events
  2992. if (csproj != this->ProjectType) {
  2993. this->WriteEvents(*i);
  2994. }
  2995. // output link flags <Link></Link>
  2996. this->WriteLinkOptions(*i);
  2997. // output lib flags <Lib></Lib>
  2998. this->WriteLibOptions(*i);
  2999. // output manifest flags <Manifest></Manifest>
  3000. this->WriteManifestOptions(*i);
  3001. if (this->NsightTegra &&
  3002. this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE &&
  3003. this->GeneratorTarget->GetPropertyAsBool("ANDROID_GUI")) {
  3004. this->WriteAntBuildOptions(*i);
  3005. }
  3006. this->WriteString("</ItemDefinitionGroup>\n", 1);
  3007. }
  3008. }
  3009. void cmVisualStudio10TargetGenerator::WriteEvents(
  3010. std::string const& configName)
  3011. {
  3012. bool addedPrelink = false;
  3013. cmGeneratorTarget::ModuleDefinitionInfo const* mdi =
  3014. this->GeneratorTarget->GetModuleDefinitionInfo(configName);
  3015. if (mdi && mdi->DefFileGenerated) {
  3016. addedPrelink = true;
  3017. std::vector<cmCustomCommand> commands =
  3018. this->GeneratorTarget->GetPreLinkCommands();
  3019. this->GlobalGenerator->AddSymbolExportCommand(this->GeneratorTarget,
  3020. commands, configName);
  3021. this->WriteEvent("PreLinkEvent", commands, configName);
  3022. }
  3023. if (!addedPrelink) {
  3024. this->WriteEvent("PreLinkEvent",
  3025. this->GeneratorTarget->GetPreLinkCommands(), configName);
  3026. }
  3027. this->WriteEvent("PreBuildEvent",
  3028. this->GeneratorTarget->GetPreBuildCommands(), configName);
  3029. this->WriteEvent("PostBuildEvent",
  3030. this->GeneratorTarget->GetPostBuildCommands(), configName);
  3031. }
  3032. void cmVisualStudio10TargetGenerator::WriteEvent(
  3033. const char* name, std::vector<cmCustomCommand> const& commands,
  3034. std::string const& configName)
  3035. {
  3036. if (commands.empty()) {
  3037. return;
  3038. }
  3039. this->WriteString("<", 2);
  3040. (*this->BuildFileStream) << name << ">\n";
  3041. cmLocalVisualStudio7Generator* lg = this->LocalGenerator;
  3042. std::string script;
  3043. const char* pre = "";
  3044. std::string comment;
  3045. for (std::vector<cmCustomCommand>::const_iterator i = commands.begin();
  3046. i != commands.end(); ++i) {
  3047. cmCustomCommandGenerator ccg(*i, configName, this->LocalGenerator);
  3048. comment += pre;
  3049. comment += lg->ConstructComment(ccg);
  3050. script += pre;
  3051. pre = "\n";
  3052. script += cmVS10EscapeXML(lg->ConstructScript(ccg));
  3053. }
  3054. comment = cmVS10EscapeComment(comment);
  3055. if (csproj != this->ProjectType) {
  3056. this->WriteString("<Message>", 3);
  3057. (*this->BuildFileStream) << cmVS10EscapeXML(comment) << "</Message>\n";
  3058. this->WriteString("<Command>", 3);
  3059. } else {
  3060. if (!comment.empty()) {
  3061. (*this->BuildFileStream) << "echo " << cmVS10EscapeXML(comment) << "\n";
  3062. }
  3063. }
  3064. (*this->BuildFileStream) << script;
  3065. if (csproj != this->ProjectType) {
  3066. (*this->BuildFileStream) << "</Command>";
  3067. }
  3068. (*this->BuildFileStream) << "\n";
  3069. this->WriteString("</", 2);
  3070. (*this->BuildFileStream) << name << ">\n";
  3071. }
  3072. void cmVisualStudio10TargetGenerator::WriteProjectReferences()
  3073. {
  3074. cmGlobalGenerator::TargetDependSet const& unordered =
  3075. this->GlobalGenerator->GetTargetDirectDepends(this->GeneratorTarget);
  3076. typedef cmGlobalVisualStudioGenerator::OrderedTargetDependSet
  3077. OrderedTargetDependSet;
  3078. OrderedTargetDependSet depends(unordered, CMAKE_CHECK_BUILD_SYSTEM_TARGET);
  3079. this->WriteString("<ItemGroup>\n", 1);
  3080. for (OrderedTargetDependSet::const_iterator i = depends.begin();
  3081. i != depends.end(); ++i) {
  3082. cmGeneratorTarget const* dt = *i;
  3083. if (dt->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
  3084. continue;
  3085. }
  3086. // skip fortran targets as they can not be processed by MSBuild
  3087. // the only reference will be in the .sln file
  3088. if (static_cast<cmGlobalVisualStudioGenerator*>(this->GlobalGenerator)
  3089. ->TargetIsFortranOnly(dt)) {
  3090. continue;
  3091. }
  3092. if (csproj == this->ProjectType &&
  3093. !this->GlobalGenerator->TargetIsCSharpOnly(dt)) {
  3094. continue;
  3095. }
  3096. this->WriteString("<ProjectReference Include=\"", 2);
  3097. cmLocalGenerator* lg = dt->GetLocalGenerator();
  3098. std::string name = dt->GetName();
  3099. std::string path;
  3100. const char* p = dt->GetProperty("EXTERNAL_MSPROJECT");
  3101. if (p) {
  3102. path = p;
  3103. } else {
  3104. path = lg->GetCurrentBinaryDirectory();
  3105. path += "/";
  3106. path += dt->GetName();
  3107. path += computeProjectFileExtension(dt);
  3108. }
  3109. this->ConvertToWindowsSlash(path);
  3110. (*this->BuildFileStream) << cmVS10EscapeXML(path) << "\">\n";
  3111. this->WriteString("<Project>", 3);
  3112. if (csproj == this->ProjectType) {
  3113. (*this->BuildFileStream) << "{";
  3114. }
  3115. (*this->BuildFileStream) << this->GlobalGenerator->GetGUID(name.c_str());
  3116. if (csproj == this->ProjectType) {
  3117. (*this->BuildFileStream) << "}";
  3118. }
  3119. (*this->BuildFileStream) << "</Project>\n";
  3120. this->WriteString("<Name>", 3);
  3121. (*this->BuildFileStream) << name << "</Name>\n";
  3122. this->WriteString("</ProjectReference>\n", 2);
  3123. }
  3124. this->WriteString("</ItemGroup>\n", 1);
  3125. }
  3126. void cmVisualStudio10TargetGenerator::WritePlatformExtensions()
  3127. {
  3128. // This only applies to Windows 10 apps
  3129. if (this->GlobalGenerator->TargetsWindowsStore() &&
  3130. cmHasLiteralPrefix(this->GlobalGenerator->GetSystemVersion(), "10.0")) {
  3131. const char* desktopExtensionsVersion =
  3132. this->GeneratorTarget->GetProperty("VS_DESKTOP_EXTENSIONS_VERSION");
  3133. if (desktopExtensionsVersion) {
  3134. this->WriteSinglePlatformExtension("WindowsDesktop",
  3135. desktopExtensionsVersion);
  3136. }
  3137. const char* mobileExtensionsVersion =
  3138. this->GeneratorTarget->GetProperty("VS_MOBILE_EXTENSIONS_VERSION");
  3139. if (mobileExtensionsVersion) {
  3140. this->WriteSinglePlatformExtension("WindowsMobile",
  3141. mobileExtensionsVersion);
  3142. }
  3143. }
  3144. }
  3145. void cmVisualStudio10TargetGenerator::WriteSinglePlatformExtension(
  3146. std::string const& extension, std::string const& version)
  3147. {
  3148. this->WriteString("<Import Project=", 2);
  3149. (*this->BuildFileStream)
  3150. << "\"$([Microsoft.Build.Utilities.ToolLocationHelper]"
  3151. << "::GetPlatformExtensionSDKLocation(`" << extension
  3152. << ", Version=" << version
  3153. << "`, $(TargetPlatformIdentifier), $(TargetPlatformVersion), null, "
  3154. << "$(ExtensionSDKDirectoryRoot), null))"
  3155. << "\\DesignTime\\CommonConfiguration\\Neutral\\" << extension
  3156. << ".props\" "
  3157. << "Condition=\"exists('$("
  3158. << "[Microsoft.Build.Utilities.ToolLocationHelper]"
  3159. << "::GetPlatformExtensionSDKLocation(`" << extension
  3160. << ", Version=" << version
  3161. << "`, $(TargetPlatformIdentifier), $(TargetPlatformVersion), null, "
  3162. << "$(ExtensionSDKDirectoryRoot), null))"
  3163. << "\\DesignTime\\CommonConfiguration\\Neutral\\" << extension
  3164. << ".props')\" />\n";
  3165. }
  3166. void cmVisualStudio10TargetGenerator::WriteSDKReferences()
  3167. {
  3168. std::vector<std::string> sdkReferences;
  3169. bool hasWrittenItemGroup = false;
  3170. if (const char* vsSDKReferences =
  3171. this->GeneratorTarget->GetProperty("VS_SDK_REFERENCES")) {
  3172. cmSystemTools::ExpandListArgument(vsSDKReferences, sdkReferences);
  3173. this->WriteString("<ItemGroup>\n", 1);
  3174. hasWrittenItemGroup = true;
  3175. for (std::vector<std::string>::iterator ri = sdkReferences.begin();
  3176. ri != sdkReferences.end(); ++ri) {
  3177. this->WriteString("<SDKReference Include=\"", 2);
  3178. (*this->BuildFileStream) << cmVS10EscapeXML(*ri) << "\"/>\n";
  3179. }
  3180. }
  3181. // This only applies to Windows 10 apps
  3182. if (this->GlobalGenerator->TargetsWindowsStore() &&
  3183. cmHasLiteralPrefix(this->GlobalGenerator->GetSystemVersion(), "10.0")) {
  3184. const char* desktopExtensionsVersion =
  3185. this->GeneratorTarget->GetProperty("VS_DESKTOP_EXTENSIONS_VERSION");
  3186. const char* mobileExtensionsVersion =
  3187. this->GeneratorTarget->GetProperty("VS_MOBILE_EXTENSIONS_VERSION");
  3188. const char* iotExtensionsVersion =
  3189. this->GeneratorTarget->GetProperty("VS_IOT_EXTENSIONS_VERSION");
  3190. if (desktopExtensionsVersion || mobileExtensionsVersion ||
  3191. iotExtensionsVersion) {
  3192. if (!hasWrittenItemGroup) {
  3193. this->WriteString("<ItemGroup>\n", 1);
  3194. hasWrittenItemGroup = true;
  3195. }
  3196. if (desktopExtensionsVersion) {
  3197. this->WriteSingleSDKReference("WindowsDesktop",
  3198. desktopExtensionsVersion);
  3199. }
  3200. if (mobileExtensionsVersion) {
  3201. this->WriteSingleSDKReference("WindowsMobile",
  3202. mobileExtensionsVersion);
  3203. }
  3204. if (iotExtensionsVersion) {
  3205. this->WriteSingleSDKReference("WindowsIoT", iotExtensionsVersion);
  3206. }
  3207. }
  3208. if (hasWrittenItemGroup) {
  3209. this->WriteString("</ItemGroup>\n", 1);
  3210. }
  3211. }
  3212. }
  3213. void cmVisualStudio10TargetGenerator::WriteSingleSDKReference(
  3214. std::string const& extension, std::string const& version)
  3215. {
  3216. this->WriteString("<SDKReference Include=\"", 2);
  3217. (*this->BuildFileStream) << extension << ", Version=" << version
  3218. << "\" />\n";
  3219. }
  3220. void cmVisualStudio10TargetGenerator::WriteWinRTPackageCertificateKeyFile()
  3221. {
  3222. if ((this->GlobalGenerator->TargetsWindowsStore() ||
  3223. this->GlobalGenerator->TargetsWindowsPhone()) &&
  3224. (cmStateEnums::EXECUTABLE == this->GeneratorTarget->GetType())) {
  3225. std::string pfxFile;
  3226. std::vector<cmSourceFile const*> certificates;
  3227. this->GeneratorTarget->GetCertificates(certificates, "");
  3228. for (std::vector<cmSourceFile const*>::const_iterator si =
  3229. certificates.begin();
  3230. si != certificates.end(); ++si) {
  3231. pfxFile = this->ConvertPath((*si)->GetFullPath(), false);
  3232. this->ConvertToWindowsSlash(pfxFile);
  3233. break;
  3234. }
  3235. if (this->IsMissingFiles &&
  3236. !(this->GlobalGenerator->TargetsWindowsPhone() &&
  3237. this->GlobalGenerator->GetSystemVersion() == "8.0")) {
  3238. // Move the manifest to a project directory to avoid clashes
  3239. std::string artifactDir =
  3240. this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
  3241. this->ConvertToWindowsSlash(artifactDir);
  3242. this->WriteString("<PropertyGroup>\n", 1);
  3243. this->WriteString("<AppxPackageArtifactsDir>", 2);
  3244. (*this->BuildFileStream) << cmVS10EscapeXML(artifactDir)
  3245. << "\\</AppxPackageArtifactsDir>\n";
  3246. this->WriteString("<ProjectPriFullPath>", 2);
  3247. std::string resourcePriFile =
  3248. this->DefaultArtifactDir + "/resources.pri";
  3249. this->ConvertToWindowsSlash(resourcePriFile);
  3250. (*this->BuildFileStream) << resourcePriFile << "</ProjectPriFullPath>\n";
  3251. // If we are missing files and we don't have a certificate and
  3252. // aren't targeting WP8.0, add a default certificate
  3253. if (pfxFile.empty()) {
  3254. std::string templateFolder =
  3255. cmSystemTools::GetCMakeRoot() + "/Templates/Windows";
  3256. pfxFile = this->DefaultArtifactDir + "/Windows_TemporaryKey.pfx";
  3257. cmSystemTools::CopyAFile(templateFolder + "/Windows_TemporaryKey.pfx",
  3258. pfxFile, false);
  3259. this->ConvertToWindowsSlash(pfxFile);
  3260. this->AddedFiles.push_back(pfxFile);
  3261. }
  3262. this->WriteString("<", 2);
  3263. (*this->BuildFileStream) << "PackageCertificateKeyFile>" << pfxFile
  3264. << "</PackageCertificateKeyFile>\n";
  3265. std::string thumb = cmSystemTools::ComputeCertificateThumbprint(pfxFile);
  3266. if (!thumb.empty()) {
  3267. this->WriteString("<PackageCertificateThumbprint>", 2);
  3268. (*this->BuildFileStream) << thumb
  3269. << "</PackageCertificateThumbprint>\n";
  3270. }
  3271. this->WriteString("</PropertyGroup>\n", 1);
  3272. } else if (!pfxFile.empty()) {
  3273. this->WriteString("<PropertyGroup>\n", 1);
  3274. this->WriteString("<", 2);
  3275. (*this->BuildFileStream) << "PackageCertificateKeyFile>" << pfxFile
  3276. << "</PackageCertificateKeyFile>\n";
  3277. std::string thumb = cmSystemTools::ComputeCertificateThumbprint(pfxFile);
  3278. if (!thumb.empty()) {
  3279. this->WriteString("<PackageCertificateThumbprint>", 2);
  3280. (*this->BuildFileStream) << thumb
  3281. << "</PackageCertificateThumbprint>\n";
  3282. }
  3283. this->WriteString("</PropertyGroup>\n", 1);
  3284. }
  3285. }
  3286. }
  3287. bool cmVisualStudio10TargetGenerator::IsResxHeader(
  3288. const std::string& headerFile)
  3289. {
  3290. std::set<std::string> expectedResxHeaders;
  3291. this->GeneratorTarget->GetExpectedResxHeaders(expectedResxHeaders, "");
  3292. std::set<std::string>::const_iterator it =
  3293. expectedResxHeaders.find(headerFile);
  3294. return it != expectedResxHeaders.end();
  3295. }
  3296. bool cmVisualStudio10TargetGenerator::IsXamlHeader(
  3297. const std::string& headerFile)
  3298. {
  3299. std::set<std::string> expectedXamlHeaders;
  3300. this->GeneratorTarget->GetExpectedXamlHeaders(expectedXamlHeaders, "");
  3301. std::set<std::string>::const_iterator it =
  3302. expectedXamlHeaders.find(headerFile);
  3303. return it != expectedXamlHeaders.end();
  3304. }
  3305. bool cmVisualStudio10TargetGenerator::IsXamlSource(
  3306. const std::string& sourceFile)
  3307. {
  3308. std::set<std::string> expectedXamlSources;
  3309. this->GeneratorTarget->GetExpectedXamlSources(expectedXamlSources, "");
  3310. std::set<std::string>::const_iterator it =
  3311. expectedXamlSources.find(sourceFile);
  3312. return it != expectedXamlSources.end();
  3313. }
  3314. void cmVisualStudio10TargetGenerator::WriteApplicationTypeSettings()
  3315. {
  3316. cmGlobalVisualStudio10Generator* gg =
  3317. static_cast<cmGlobalVisualStudio10Generator*>(this->GlobalGenerator);
  3318. bool isAppContainer = false;
  3319. bool const isWindowsPhone = this->GlobalGenerator->TargetsWindowsPhone();
  3320. bool const isWindowsStore = this->GlobalGenerator->TargetsWindowsStore();
  3321. std::string const& v = this->GlobalGenerator->GetSystemVersion();
  3322. if (isWindowsPhone || isWindowsStore) {
  3323. this->WriteString("<ApplicationType>", 2);
  3324. (*this->BuildFileStream)
  3325. << (isWindowsPhone ? "Windows Phone" : "Windows Store")
  3326. << "</ApplicationType>\n";
  3327. this->WriteString("<DefaultLanguage>en-US"
  3328. "</DefaultLanguage>\n",
  3329. 2);
  3330. if (cmHasLiteralPrefix(v, "10.0")) {
  3331. this->WriteString("<ApplicationTypeRevision>", 2);
  3332. (*this->BuildFileStream) << cmVS10EscapeXML("10.0")
  3333. << "</ApplicationTypeRevision>\n";
  3334. // Visual Studio 14.0 is necessary for building 10.0 apps
  3335. this->WriteString("<MinimumVisualStudioVersion>14.0"
  3336. "</MinimumVisualStudioVersion>\n",
  3337. 2);
  3338. if (this->GeneratorTarget->GetType() < cmStateEnums::UTILITY) {
  3339. isAppContainer = true;
  3340. }
  3341. } else if (v == "8.1") {
  3342. this->WriteString("<ApplicationTypeRevision>", 2);
  3343. (*this->BuildFileStream) << cmVS10EscapeXML(v)
  3344. << "</ApplicationTypeRevision>\n";
  3345. // Visual Studio 12.0 is necessary for building 8.1 apps
  3346. this->WriteString("<MinimumVisualStudioVersion>12.0"
  3347. "</MinimumVisualStudioVersion>\n",
  3348. 2);
  3349. if (this->GeneratorTarget->GetType() < cmStateEnums::UTILITY) {
  3350. isAppContainer = true;
  3351. }
  3352. } else if (v == "8.0") {
  3353. this->WriteString("<ApplicationTypeRevision>", 2);
  3354. (*this->BuildFileStream) << cmVS10EscapeXML(v)
  3355. << "</ApplicationTypeRevision>\n";
  3356. // Visual Studio 11.0 is necessary for building 8.0 apps
  3357. this->WriteString("<MinimumVisualStudioVersion>11.0"
  3358. "</MinimumVisualStudioVersion>\n",
  3359. 2);
  3360. if (isWindowsStore &&
  3361. this->GeneratorTarget->GetType() < cmStateEnums::UTILITY) {
  3362. isAppContainer = true;
  3363. } else if (isWindowsPhone &&
  3364. this->GeneratorTarget->GetType() ==
  3365. cmStateEnums::EXECUTABLE) {
  3366. this->WriteString("<XapOutputs>true</XapOutputs>\n", 2);
  3367. this->WriteString("<XapFilename>", 2);
  3368. (*this->BuildFileStream)
  3369. << cmVS10EscapeXML(this->Name.c_str())
  3370. << "_$(Configuration)_$(Platform).xap</XapFilename>\n";
  3371. }
  3372. }
  3373. }
  3374. if (isAppContainer) {
  3375. this->WriteString("<AppContainerApplication>true"
  3376. "</AppContainerApplication>\n",
  3377. 2);
  3378. } else if (this->Platform == "ARM") {
  3379. this->WriteString("<WindowsSDKDesktopARMSupport>true"
  3380. "</WindowsSDKDesktopARMSupport>\n",
  3381. 2);
  3382. }
  3383. std::string const& targetPlatformVersion =
  3384. gg->GetWindowsTargetPlatformVersion();
  3385. if (!targetPlatformVersion.empty()) {
  3386. this->WriteString("<WindowsTargetPlatformVersion>", 2);
  3387. (*this->BuildFileStream) << cmVS10EscapeXML(targetPlatformVersion)
  3388. << "</WindowsTargetPlatformVersion>\n";
  3389. }
  3390. const char* targetPlatformMinVersion = this->GeneratorTarget->GetProperty(
  3391. "VS_WINDOWS_TARGET_PLATFORM_MIN_VERSION");
  3392. if (targetPlatformMinVersion) {
  3393. this->WriteString("<WindowsTargetPlatformMinVersion>", 2);
  3394. (*this->BuildFileStream) << cmVS10EscapeXML(targetPlatformMinVersion)
  3395. << "</WindowsTargetPlatformMinVersion>\n";
  3396. } else if (isWindowsStore && cmHasLiteralPrefix(v, "10.0")) {
  3397. // If the min version is not set, then use the TargetPlatformVersion
  3398. if (!targetPlatformVersion.empty()) {
  3399. this->WriteString("<WindowsTargetPlatformMinVersion>", 2);
  3400. (*this->BuildFileStream) << cmVS10EscapeXML(targetPlatformVersion)
  3401. << "</WindowsTargetPlatformMinVersion>\n";
  3402. }
  3403. }
  3404. // Added IoT Startup Task support
  3405. if (this->GeneratorTarget->GetPropertyAsBool("VS_IOT_STARTUP_TASK")) {
  3406. this->WriteString("<ContainsStartupTask>true</ContainsStartupTask>\n", 2);
  3407. }
  3408. }
  3409. void cmVisualStudio10TargetGenerator::VerifyNecessaryFiles()
  3410. {
  3411. // For Windows and Windows Phone executables, we will assume that if a
  3412. // manifest is not present that we need to add all the necessary files
  3413. if (this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE) {
  3414. std::vector<cmSourceFile const*> manifestSources;
  3415. this->GeneratorTarget->GetAppManifest(manifestSources, "");
  3416. {
  3417. std::string const& v = this->GlobalGenerator->GetSystemVersion();
  3418. if (this->GlobalGenerator->TargetsWindowsPhone()) {
  3419. if (v == "8.0") {
  3420. // Look through the sources for WMAppManifest.xml
  3421. std::vector<cmSourceFile const*> extraSources;
  3422. this->GeneratorTarget->GetExtraSources(extraSources, "");
  3423. bool foundManifest = false;
  3424. for (std::vector<cmSourceFile const*>::const_iterator si =
  3425. extraSources.begin();
  3426. si != extraSources.end(); ++si) {
  3427. // Need to do a lowercase comparison on the filename
  3428. if ("wmappmanifest.xml" ==
  3429. cmSystemTools::LowerCase((*si)->GetLocation().GetName())) {
  3430. foundManifest = true;
  3431. break;
  3432. }
  3433. }
  3434. if (!foundManifest) {
  3435. this->IsMissingFiles = true;
  3436. }
  3437. } else if (v == "8.1") {
  3438. if (manifestSources.empty()) {
  3439. this->IsMissingFiles = true;
  3440. }
  3441. }
  3442. } else if (this->GlobalGenerator->TargetsWindowsStore()) {
  3443. if (manifestSources.empty()) {
  3444. if (v == "8.0") {
  3445. this->IsMissingFiles = true;
  3446. } else if (v == "8.1" || cmHasLiteralPrefix(v, "10.0")) {
  3447. this->IsMissingFiles = true;
  3448. }
  3449. }
  3450. }
  3451. }
  3452. }
  3453. }
  3454. void cmVisualStudio10TargetGenerator::WriteMissingFiles()
  3455. {
  3456. std::string const& v = this->GlobalGenerator->GetSystemVersion();
  3457. if (this->GlobalGenerator->TargetsWindowsPhone()) {
  3458. if (v == "8.0") {
  3459. this->WriteMissingFilesWP80();
  3460. } else if (v == "8.1") {
  3461. this->WriteMissingFilesWP81();
  3462. }
  3463. } else if (this->GlobalGenerator->TargetsWindowsStore()) {
  3464. if (v == "8.0") {
  3465. this->WriteMissingFilesWS80();
  3466. } else if (v == "8.1") {
  3467. this->WriteMissingFilesWS81();
  3468. } else if (cmHasLiteralPrefix(v, "10.0")) {
  3469. this->WriteMissingFilesWS10_0();
  3470. }
  3471. }
  3472. }
  3473. void cmVisualStudio10TargetGenerator::WriteMissingFilesWP80()
  3474. {
  3475. std::string templateFolder =
  3476. cmSystemTools::GetCMakeRoot() + "/Templates/Windows";
  3477. // For WP80, the manifest needs to be in the same folder as the project
  3478. // this can cause an overwrite problem if projects aren't organized in
  3479. // folders
  3480. std::string manifestFile =
  3481. this->LocalGenerator->GetCurrentBinaryDirectory() +
  3482. std::string("/WMAppManifest.xml");
  3483. std::string artifactDir =
  3484. this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
  3485. this->ConvertToWindowsSlash(artifactDir);
  3486. std::string artifactDirXML = cmVS10EscapeXML(artifactDir);
  3487. std::string targetNameXML =
  3488. cmVS10EscapeXML(this->GeneratorTarget->GetName());
  3489. cmGeneratedFileStream fout(manifestFile.c_str());
  3490. fout.SetCopyIfDifferent(true);
  3491. /* clang-format off */
  3492. fout <<
  3493. "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
  3494. "<Deployment"
  3495. " xmlns=\"http://schemas.microsoft.com/windowsphone/2012/deployment\""
  3496. " AppPlatformVersion=\"8.0\">\n"
  3497. "\t<DefaultLanguage xmlns=\"\" code=\"en-US\"/>\n"
  3498. "\t<App xmlns=\"\" ProductID=\"{" << this->GUID << "}\""
  3499. " Title=\"CMake Test Program\" RuntimeType=\"Modern Native\""
  3500. " Version=\"1.0.0.0\" Genre=\"apps.normal\" Author=\"CMake\""
  3501. " Description=\"Default CMake App\" Publisher=\"CMake\""
  3502. " PublisherID=\"{" << this->GUID << "}\">\n"
  3503. "\t\t<IconPath IsRelative=\"true\" IsResource=\"false\">"
  3504. << artifactDirXML << "\\ApplicationIcon.png</IconPath>\n"
  3505. "\t\t<Capabilities/>\n"
  3506. "\t\t<Tasks>\n"
  3507. "\t\t\t<DefaultTask Name=\"_default\""
  3508. " ImagePath=\"" << targetNameXML << ".exe\" ImageParams=\"\" />\n"
  3509. "\t\t</Tasks>\n"
  3510. "\t\t<Tokens>\n"
  3511. "\t\t\t<PrimaryToken TokenID=\"" << targetNameXML << "Token\""
  3512. " TaskName=\"_default\">\n"
  3513. "\t\t\t\t<TemplateFlip>\n"
  3514. "\t\t\t\t\t<SmallImageURI IsRelative=\"true\" IsResource=\"false\">"
  3515. << artifactDirXML << "\\SmallLogo.png</SmallImageURI>\n"
  3516. "\t\t\t\t\t<Count>0</Count>\n"
  3517. "\t\t\t\t\t<BackgroundImageURI IsRelative=\"true\" IsResource=\"false\">"
  3518. << artifactDirXML << "\\Logo.png</BackgroundImageURI>\n"
  3519. "\t\t\t\t</TemplateFlip>\n"
  3520. "\t\t\t</PrimaryToken>\n"
  3521. "\t\t</Tokens>\n"
  3522. "\t\t<ScreenResolutions>\n"
  3523. "\t\t\t<ScreenResolution Name=\"ID_RESOLUTION_WVGA\" />\n"
  3524. "\t\t</ScreenResolutions>\n"
  3525. "\t</App>\n"
  3526. "</Deployment>\n";
  3527. /* clang-format on */
  3528. std::string sourceFile = this->ConvertPath(manifestFile, false);
  3529. this->ConvertToWindowsSlash(sourceFile);
  3530. this->WriteString("<Xml Include=\"", 2);
  3531. (*this->BuildFileStream) << cmVS10EscapeXML(sourceFile) << "\">\n";
  3532. this->WriteString("<SubType>Designer</SubType>\n", 3);
  3533. this->WriteString("</Xml>\n", 2);
  3534. this->AddedFiles.push_back(sourceFile);
  3535. std::string smallLogo = this->DefaultArtifactDir + "/SmallLogo.png";
  3536. cmSystemTools::CopyAFile(templateFolder + "/SmallLogo.png", smallLogo,
  3537. false);
  3538. this->ConvertToWindowsSlash(smallLogo);
  3539. this->WriteString("<Image Include=\"", 2);
  3540. (*this->BuildFileStream) << cmVS10EscapeXML(smallLogo) << "\" />\n";
  3541. this->AddedFiles.push_back(smallLogo);
  3542. std::string logo = this->DefaultArtifactDir + "/Logo.png";
  3543. cmSystemTools::CopyAFile(templateFolder + "/Logo.png", logo, false);
  3544. this->ConvertToWindowsSlash(logo);
  3545. this->WriteString("<Image Include=\"", 2);
  3546. (*this->BuildFileStream) << cmVS10EscapeXML(logo) << "\" />\n";
  3547. this->AddedFiles.push_back(logo);
  3548. std::string applicationIcon =
  3549. this->DefaultArtifactDir + "/ApplicationIcon.png";
  3550. cmSystemTools::CopyAFile(templateFolder + "/ApplicationIcon.png",
  3551. applicationIcon, false);
  3552. this->ConvertToWindowsSlash(applicationIcon);
  3553. this->WriteString("<Image Include=\"", 2);
  3554. (*this->BuildFileStream) << cmVS10EscapeXML(applicationIcon) << "\" />\n";
  3555. this->AddedFiles.push_back(applicationIcon);
  3556. }
  3557. void cmVisualStudio10TargetGenerator::WriteMissingFilesWP81()
  3558. {
  3559. std::string manifestFile =
  3560. this->DefaultArtifactDir + "/package.appxManifest";
  3561. std::string artifactDir =
  3562. this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
  3563. this->ConvertToWindowsSlash(artifactDir);
  3564. std::string artifactDirXML = cmVS10EscapeXML(artifactDir);
  3565. std::string targetNameXML =
  3566. cmVS10EscapeXML(this->GeneratorTarget->GetName());
  3567. cmGeneratedFileStream fout(manifestFile.c_str());
  3568. fout.SetCopyIfDifferent(true);
  3569. /* clang-format off */
  3570. fout <<
  3571. "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
  3572. "<Package xmlns=\"http://schemas.microsoft.com/appx/2010/manifest\""
  3573. " xmlns:m2=\"http://schemas.microsoft.com/appx/2013/manifest\""
  3574. " xmlns:mp=\"http://schemas.microsoft.com/appx/2014/phone/manifest\">\n"
  3575. "\t<Identity Name=\"" << this->GUID << "\" Publisher=\"CN=CMake\""
  3576. " Version=\"1.0.0.0\" />\n"
  3577. "\t<mp:PhoneIdentity PhoneProductId=\"" << this->GUID << "\""
  3578. " PhonePublisherId=\"00000000-0000-0000-0000-000000000000\"/>\n"
  3579. "\t<Properties>\n"
  3580. "\t\t<DisplayName>" << targetNameXML << "</DisplayName>\n"
  3581. "\t\t<PublisherDisplayName>CMake</PublisherDisplayName>\n"
  3582. "\t\t<Logo>" << artifactDirXML << "\\StoreLogo.png</Logo>\n"
  3583. "\t</Properties>\n"
  3584. "\t<Prerequisites>\n"
  3585. "\t\t<OSMinVersion>6.3.1</OSMinVersion>\n"
  3586. "\t\t<OSMaxVersionTested>6.3.1</OSMaxVersionTested>\n"
  3587. "\t</Prerequisites>\n"
  3588. "\t<Resources>\n"
  3589. "\t\t<Resource Language=\"x-generate\" />\n"
  3590. "\t</Resources>\n"
  3591. "\t<Applications>\n"
  3592. "\t\t<Application Id=\"App\""
  3593. " Executable=\"" << targetNameXML << ".exe\""
  3594. " EntryPoint=\"" << targetNameXML << ".App\">\n"
  3595. "\t\t\t<m2:VisualElements\n"
  3596. "\t\t\t\tDisplayName=\"" << targetNameXML << "\"\n"
  3597. "\t\t\t\tDescription=\"" << targetNameXML << "\"\n"
  3598. "\t\t\t\tBackgroundColor=\"#336699\"\n"
  3599. "\t\t\t\tForegroundText=\"light\"\n"
  3600. "\t\t\t\tSquare150x150Logo=\"" << artifactDirXML << "\\Logo.png\"\n"
  3601. "\t\t\t\tSquare30x30Logo=\"" << artifactDirXML << "\\SmallLogo.png\">\n"
  3602. "\t\t\t\t<m2:DefaultTile ShortName=\"" << targetNameXML << "\">\n"
  3603. "\t\t\t\t\t<m2:ShowNameOnTiles>\n"
  3604. "\t\t\t\t\t\t<m2:ShowOn Tile=\"square150x150Logo\" />\n"
  3605. "\t\t\t\t\t</m2:ShowNameOnTiles>\n"
  3606. "\t\t\t\t</m2:DefaultTile>\n"
  3607. "\t\t\t\t<m2:SplashScreen"
  3608. " Image=\"" << artifactDirXML << "\\SplashScreen.png\" />\n"
  3609. "\t\t\t</m2:VisualElements>\n"
  3610. "\t\t</Application>\n"
  3611. "\t</Applications>\n"
  3612. "</Package>\n";
  3613. /* clang-format on */
  3614. this->WriteCommonMissingFiles(manifestFile);
  3615. }
  3616. void cmVisualStudio10TargetGenerator::WriteMissingFilesWS80()
  3617. {
  3618. std::string manifestFile =
  3619. this->DefaultArtifactDir + "/package.appxManifest";
  3620. std::string artifactDir =
  3621. this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
  3622. this->ConvertToWindowsSlash(artifactDir);
  3623. std::string artifactDirXML = cmVS10EscapeXML(artifactDir);
  3624. std::string targetNameXML =
  3625. cmVS10EscapeXML(this->GeneratorTarget->GetName());
  3626. cmGeneratedFileStream fout(manifestFile.c_str());
  3627. fout.SetCopyIfDifferent(true);
  3628. /* clang-format off */
  3629. fout <<
  3630. "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
  3631. "<Package xmlns=\"http://schemas.microsoft.com/appx/2010/manifest\">\n"
  3632. "\t<Identity Name=\"" << this->GUID << "\" Publisher=\"CN=CMake\""
  3633. " Version=\"1.0.0.0\" />\n"
  3634. "\t<Properties>\n"
  3635. "\t\t<DisplayName>" << targetNameXML << "</DisplayName>\n"
  3636. "\t\t<PublisherDisplayName>CMake</PublisherDisplayName>\n"
  3637. "\t\t<Logo>" << artifactDirXML << "\\StoreLogo.png</Logo>\n"
  3638. "\t</Properties>\n"
  3639. "\t<Prerequisites>\n"
  3640. "\t\t<OSMinVersion>6.2.1</OSMinVersion>\n"
  3641. "\t\t<OSMaxVersionTested>6.2.1</OSMaxVersionTested>\n"
  3642. "\t</Prerequisites>\n"
  3643. "\t<Resources>\n"
  3644. "\t\t<Resource Language=\"x-generate\" />\n"
  3645. "\t</Resources>\n"
  3646. "\t<Applications>\n"
  3647. "\t\t<Application Id=\"App\""
  3648. " Executable=\"" << targetNameXML << ".exe\""
  3649. " EntryPoint=\"" << targetNameXML << ".App\">\n"
  3650. "\t\t\t<VisualElements"
  3651. " DisplayName=\"" << targetNameXML << "\""
  3652. " Description=\"" << targetNameXML << "\""
  3653. " BackgroundColor=\"#336699\" ForegroundText=\"light\""
  3654. " Logo=\"" << artifactDirXML << "\\Logo.png\""
  3655. " SmallLogo=\"" << artifactDirXML << "\\SmallLogo.png\">\n"
  3656. "\t\t\t\t<DefaultTile ShowName=\"allLogos\""
  3657. " ShortName=\"" << targetNameXML << "\" />\n"
  3658. "\t\t\t\t<SplashScreen"
  3659. " Image=\"" << artifactDirXML << "\\SplashScreen.png\" />\n"
  3660. "\t\t\t</VisualElements>\n"
  3661. "\t\t</Application>\n"
  3662. "\t</Applications>\n"
  3663. "</Package>\n";
  3664. /* clang-format on */
  3665. this->WriteCommonMissingFiles(manifestFile);
  3666. }
  3667. void cmVisualStudio10TargetGenerator::WriteMissingFilesWS81()
  3668. {
  3669. std::string manifestFile =
  3670. this->DefaultArtifactDir + "/package.appxManifest";
  3671. std::string artifactDir =
  3672. this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
  3673. this->ConvertToWindowsSlash(artifactDir);
  3674. std::string artifactDirXML = cmVS10EscapeXML(artifactDir);
  3675. std::string targetNameXML =
  3676. cmVS10EscapeXML(this->GeneratorTarget->GetName());
  3677. cmGeneratedFileStream fout(manifestFile.c_str());
  3678. fout.SetCopyIfDifferent(true);
  3679. /* clang-format off */
  3680. fout <<
  3681. "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
  3682. "<Package xmlns=\"http://schemas.microsoft.com/appx/2010/manifest\""
  3683. " xmlns:m2=\"http://schemas.microsoft.com/appx/2013/manifest\">\n"
  3684. "\t<Identity Name=\"" << this->GUID << "\" Publisher=\"CN=CMake\""
  3685. " Version=\"1.0.0.0\" />\n"
  3686. "\t<Properties>\n"
  3687. "\t\t<DisplayName>" << targetNameXML << "</DisplayName>\n"
  3688. "\t\t<PublisherDisplayName>CMake</PublisherDisplayName>\n"
  3689. "\t\t<Logo>" << artifactDirXML << "\\StoreLogo.png</Logo>\n"
  3690. "\t</Properties>\n"
  3691. "\t<Prerequisites>\n"
  3692. "\t\t<OSMinVersion>6.3</OSMinVersion>\n"
  3693. "\t\t<OSMaxVersionTested>6.3</OSMaxVersionTested>\n"
  3694. "\t</Prerequisites>\n"
  3695. "\t<Resources>\n"
  3696. "\t\t<Resource Language=\"x-generate\" />\n"
  3697. "\t</Resources>\n"
  3698. "\t<Applications>\n"
  3699. "\t\t<Application Id=\"App\""
  3700. " Executable=\"" << targetNameXML << ".exe\""
  3701. " EntryPoint=\"" << targetNameXML << ".App\">\n"
  3702. "\t\t\t<m2:VisualElements\n"
  3703. "\t\t\t\tDisplayName=\"" << targetNameXML << "\"\n"
  3704. "\t\t\t\tDescription=\"" << targetNameXML << "\"\n"
  3705. "\t\t\t\tBackgroundColor=\"#336699\"\n"
  3706. "\t\t\t\tForegroundText=\"light\"\n"
  3707. "\t\t\t\tSquare150x150Logo=\"" << artifactDirXML << "\\Logo.png\"\n"
  3708. "\t\t\t\tSquare30x30Logo=\"" << artifactDirXML << "\\SmallLogo.png\">\n"
  3709. "\t\t\t\t<m2:DefaultTile ShortName=\"" << targetNameXML << "\">\n"
  3710. "\t\t\t\t\t<m2:ShowNameOnTiles>\n"
  3711. "\t\t\t\t\t\t<m2:ShowOn Tile=\"square150x150Logo\" />\n"
  3712. "\t\t\t\t\t</m2:ShowNameOnTiles>\n"
  3713. "\t\t\t\t</m2:DefaultTile>\n"
  3714. "\t\t\t\t<m2:SplashScreen"
  3715. " Image=\"" << artifactDirXML << "\\SplashScreen.png\" />\n"
  3716. "\t\t\t</m2:VisualElements>\n"
  3717. "\t\t</Application>\n"
  3718. "\t</Applications>\n"
  3719. "</Package>\n";
  3720. /* clang-format on */
  3721. this->WriteCommonMissingFiles(manifestFile);
  3722. }
  3723. void cmVisualStudio10TargetGenerator::WriteMissingFilesWS10_0()
  3724. {
  3725. std::string manifestFile =
  3726. this->DefaultArtifactDir + "/package.appxManifest";
  3727. std::string artifactDir =
  3728. this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
  3729. this->ConvertToWindowsSlash(artifactDir);
  3730. std::string artifactDirXML = cmVS10EscapeXML(artifactDir);
  3731. std::string targetNameXML =
  3732. cmVS10EscapeXML(this->GeneratorTarget->GetName());
  3733. cmGeneratedFileStream fout(manifestFile.c_str());
  3734. fout.SetCopyIfDifferent(true);
  3735. /* clang-format off */
  3736. fout <<
  3737. "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
  3738. "<Package\n\t"
  3739. "xmlns=\"http://schemas.microsoft.com/appx/manifest/foundation/windows10\""
  3740. "\txmlns:mp=\"http://schemas.microsoft.com/appx/2014/phone/manifest\"\n"
  3741. "\txmlns:uap=\"http://schemas.microsoft.com/appx/manifest/uap/windows10\""
  3742. "\n\tIgnorableNamespaces=\"uap mp\">\n\n"
  3743. "\t<Identity Name=\"" << this->GUID << "\" Publisher=\"CN=CMake\""
  3744. " Version=\"1.0.0.0\" />\n"
  3745. "\t<mp:PhoneIdentity PhoneProductId=\"" << this->GUID <<
  3746. "\" PhonePublisherId=\"00000000-0000-0000-0000-000000000000\"/>\n"
  3747. "\t<Properties>\n"
  3748. "\t\t<DisplayName>" << targetNameXML << "</DisplayName>\n"
  3749. "\t\t<PublisherDisplayName>CMake</PublisherDisplayName>\n"
  3750. "\t\t<Logo>" << artifactDirXML << "\\StoreLogo.png</Logo>\n"
  3751. "\t</Properties>\n"
  3752. "\t<Dependencies>\n"
  3753. "\t\t<TargetDeviceFamily Name=\"Windows.Universal\" "
  3754. "MinVersion=\"10.0.0.0\" MaxVersionTested=\"10.0.0.0\" />\n"
  3755. "\t</Dependencies>\n"
  3756. "\t<Resources>\n"
  3757. "\t\t<Resource Language=\"x-generate\" />\n"
  3758. "\t</Resources>\n"
  3759. "\t<Applications>\n"
  3760. "\t\t<Application Id=\"App\""
  3761. " Executable=\"" << targetNameXML << ".exe\""
  3762. " EntryPoint=\"" << targetNameXML << ".App\">\n"
  3763. "\t\t\t<uap:VisualElements\n"
  3764. "\t\t\t\tDisplayName=\"" << targetNameXML << "\"\n"
  3765. "\t\t\t\tDescription=\"" << targetNameXML << "\"\n"
  3766. "\t\t\t\tBackgroundColor=\"#336699\"\n"
  3767. "\t\t\t\tSquare150x150Logo=\"" << artifactDirXML << "\\Logo.png\"\n"
  3768. "\t\t\t\tSquare44x44Logo=\"" << artifactDirXML <<
  3769. "\\SmallLogo44x44.png\">\n"
  3770. "\t\t\t\t<uap:SplashScreen"
  3771. " Image=\"" << artifactDirXML << "\\SplashScreen.png\" />\n"
  3772. "\t\t\t</uap:VisualElements>\n"
  3773. "\t\t</Application>\n"
  3774. "\t</Applications>\n"
  3775. "</Package>\n";
  3776. /* clang-format on */
  3777. this->WriteCommonMissingFiles(manifestFile);
  3778. }
  3779. void cmVisualStudio10TargetGenerator::WriteCommonMissingFiles(
  3780. const std::string& manifestFile)
  3781. {
  3782. std::string templateFolder =
  3783. cmSystemTools::GetCMakeRoot() + "/Templates/Windows";
  3784. std::string sourceFile = this->ConvertPath(manifestFile, false);
  3785. this->ConvertToWindowsSlash(sourceFile);
  3786. this->WriteString("<AppxManifest Include=\"", 2);
  3787. (*this->BuildFileStream) << cmVS10EscapeXML(sourceFile) << "\">\n";
  3788. this->WriteString("<SubType>Designer</SubType>\n", 3);
  3789. this->WriteString("</AppxManifest>\n", 2);
  3790. this->AddedFiles.push_back(sourceFile);
  3791. std::string smallLogo = this->DefaultArtifactDir + "/SmallLogo.png";
  3792. cmSystemTools::CopyAFile(templateFolder + "/SmallLogo.png", smallLogo,
  3793. false);
  3794. this->ConvertToWindowsSlash(smallLogo);
  3795. this->WriteString("<Image Include=\"", 2);
  3796. (*this->BuildFileStream) << cmVS10EscapeXML(smallLogo) << "\" />\n";
  3797. this->AddedFiles.push_back(smallLogo);
  3798. std::string smallLogo44 = this->DefaultArtifactDir + "/SmallLogo44x44.png";
  3799. cmSystemTools::CopyAFile(templateFolder + "/SmallLogo44x44.png", smallLogo44,
  3800. false);
  3801. this->ConvertToWindowsSlash(smallLogo44);
  3802. this->WriteString("<Image Include=\"", 2);
  3803. (*this->BuildFileStream) << cmVS10EscapeXML(smallLogo44) << "\" />\n";
  3804. this->AddedFiles.push_back(smallLogo44);
  3805. std::string logo = this->DefaultArtifactDir + "/Logo.png";
  3806. cmSystemTools::CopyAFile(templateFolder + "/Logo.png", logo, false);
  3807. this->ConvertToWindowsSlash(logo);
  3808. this->WriteString("<Image Include=\"", 2);
  3809. (*this->BuildFileStream) << cmVS10EscapeXML(logo) << "\" />\n";
  3810. this->AddedFiles.push_back(logo);
  3811. std::string storeLogo = this->DefaultArtifactDir + "/StoreLogo.png";
  3812. cmSystemTools::CopyAFile(templateFolder + "/StoreLogo.png", storeLogo,
  3813. false);
  3814. this->ConvertToWindowsSlash(storeLogo);
  3815. this->WriteString("<Image Include=\"", 2);
  3816. (*this->BuildFileStream) << cmVS10EscapeXML(storeLogo) << "\" />\n";
  3817. this->AddedFiles.push_back(storeLogo);
  3818. std::string splashScreen = this->DefaultArtifactDir + "/SplashScreen.png";
  3819. cmSystemTools::CopyAFile(templateFolder + "/SplashScreen.png", splashScreen,
  3820. false);
  3821. this->ConvertToWindowsSlash(splashScreen);
  3822. this->WriteString("<Image Include=\"", 2);
  3823. (*this->BuildFileStream) << cmVS10EscapeXML(splashScreen) << "\" />\n";
  3824. this->AddedFiles.push_back(splashScreen);
  3825. // This file has already been added to the build so don't copy it
  3826. std::string keyFile = this->DefaultArtifactDir + "/Windows_TemporaryKey.pfx";
  3827. this->ConvertToWindowsSlash(keyFile);
  3828. this->WriteString("<None Include=\"", 2);
  3829. (*this->BuildFileStream) << cmVS10EscapeXML(keyFile) << "\" />\n";
  3830. }
  3831. bool cmVisualStudio10TargetGenerator::ForceOld(const std::string& source) const
  3832. {
  3833. HANDLE h =
  3834. CreateFileW(cmSystemTools::ConvertToWindowsExtendedPath(source).c_str(),
  3835. FILE_WRITE_ATTRIBUTES, FILE_SHARE_WRITE, 0, OPEN_EXISTING,
  3836. FILE_FLAG_BACKUP_SEMANTICS, 0);
  3837. if (!h) {
  3838. return false;
  3839. }
  3840. FILETIME const ftime_20010101 = { 3365781504u, 29389701u };
  3841. if (!SetFileTime(h, &ftime_20010101, &ftime_20010101, &ftime_20010101)) {
  3842. CloseHandle(h);
  3843. return false;
  3844. }
  3845. CloseHandle(h);
  3846. return true;
  3847. }
  3848. std::string cmVisualStudio10TargetGenerator::GetCMakeFilePath(
  3849. const char* relativeFilePath) const
  3850. {
  3851. // Always search in the standard modules location.
  3852. std::string path = cmSystemTools::GetCMakeRoot() + "/";
  3853. path += relativeFilePath;
  3854. this->ConvertToWindowsSlash(path);
  3855. return path;
  3856. }