cmVisualStudio10TargetGenerator.cxx 109 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmVisualStudio10TargetGenerator.h"
  11. #include "cmGlobalVisualStudio10Generator.h"
  12. #include "cmGeneratorTarget.h"
  13. #include "cmTarget.h"
  14. #include "cmComputeLinkInformation.h"
  15. #include "cmGeneratedFileStream.h"
  16. #include "cmMakefile.h"
  17. #include "cmSourceFile.h"
  18. #include "cmVisualStudioGeneratorOptions.h"
  19. #include "cmLocalVisualStudio7Generator.h"
  20. #include "cmCustomCommandGenerator.h"
  21. #include "cmVS10CLFlagTable.h"
  22. #include "cmVS10RCFlagTable.h"
  23. #include "cmVS10LinkFlagTable.h"
  24. #include "cmVS10LibFlagTable.h"
  25. #include "cmVS10MASMFlagTable.h"
  26. #include "cmVS11CLFlagTable.h"
  27. #include "cmVS11RCFlagTable.h"
  28. #include "cmVS11LinkFlagTable.h"
  29. #include "cmVS11LibFlagTable.h"
  30. #include "cmVS11MASMFlagTable.h"
  31. #include "cmVS12CLFlagTable.h"
  32. #include "cmVS12RCFlagTable.h"
  33. #include "cmVS12LinkFlagTable.h"
  34. #include "cmVS12LibFlagTable.h"
  35. #include "cmVS12MASMFlagTable.h"
  36. #include "cmVS14CLFlagTable.h"
  37. #include "cmVS14RCFlagTable.h"
  38. #include "cmVS14LinkFlagTable.h"
  39. #include "cmVS14LibFlagTable.h"
  40. #include "cmVS14MASMFlagTable.h"
  41. #include <cmsys/auto_ptr.hxx>
  42. cmIDEFlagTable const* cmVisualStudio10TargetGenerator::GetClFlagTable() const
  43. {
  44. if(this->MSTools)
  45. {
  46. cmLocalVisualStudioGenerator::VSVersion
  47. v = this->LocalGenerator->GetVersion();
  48. if(v >= cmLocalVisualStudioGenerator::VS14)
  49. { return cmVS14CLFlagTable; }
  50. else if(v >= cmLocalVisualStudioGenerator::VS12)
  51. { return cmVS12CLFlagTable; }
  52. else if(v == cmLocalVisualStudioGenerator::VS11)
  53. { return cmVS11CLFlagTable; }
  54. else
  55. { return cmVS10CLFlagTable; }
  56. }
  57. return 0;
  58. }
  59. cmIDEFlagTable const* cmVisualStudio10TargetGenerator::GetRcFlagTable() const
  60. {
  61. if(this->MSTools)
  62. {
  63. cmLocalVisualStudioGenerator::VSVersion
  64. v = this->LocalGenerator->GetVersion();
  65. if(v >= cmLocalVisualStudioGenerator::VS14)
  66. { return cmVS14RCFlagTable; }
  67. else if(v >= cmLocalVisualStudioGenerator::VS12)
  68. { return cmVS12RCFlagTable; }
  69. else if(v == cmLocalVisualStudioGenerator::VS11)
  70. { return cmVS11RCFlagTable; }
  71. else
  72. { return cmVS10RCFlagTable; }
  73. }
  74. return 0;
  75. }
  76. cmIDEFlagTable const* cmVisualStudio10TargetGenerator::GetLibFlagTable() const
  77. {
  78. if(this->MSTools)
  79. {
  80. cmLocalVisualStudioGenerator::VSVersion
  81. v = this->LocalGenerator->GetVersion();
  82. if(v >= cmLocalVisualStudioGenerator::VS14)
  83. { return cmVS14LibFlagTable; }
  84. else if(v >= cmLocalVisualStudioGenerator::VS12)
  85. { return cmVS12LibFlagTable; }
  86. else if(v == cmLocalVisualStudioGenerator::VS11)
  87. { return cmVS11LibFlagTable; }
  88. else
  89. { return cmVS10LibFlagTable; }
  90. }
  91. return 0;
  92. }
  93. cmIDEFlagTable const* cmVisualStudio10TargetGenerator::GetLinkFlagTable() const
  94. {
  95. if(this->MSTools)
  96. {
  97. cmLocalVisualStudioGenerator::VSVersion
  98. v = this->LocalGenerator->GetVersion();
  99. if(v >= cmLocalVisualStudioGenerator::VS14)
  100. { return cmVS14LinkFlagTable; }
  101. else if(v >= cmLocalVisualStudioGenerator::VS12)
  102. { return cmVS12LinkFlagTable; }
  103. else if(v == cmLocalVisualStudioGenerator::VS11)
  104. { return cmVS11LinkFlagTable; }
  105. else
  106. { return cmVS10LinkFlagTable; }
  107. }
  108. return 0;
  109. }
  110. cmIDEFlagTable const* cmVisualStudio10TargetGenerator::GetMasmFlagTable() const
  111. {
  112. if(this->MSTools)
  113. {
  114. cmLocalVisualStudioGenerator::VSVersion
  115. v = this->LocalGenerator->GetVersion();
  116. if(v >= cmLocalVisualStudioGenerator::VS14)
  117. { return cmVS14MASMFlagTable; }
  118. else if(v >= cmLocalVisualStudioGenerator::VS12)
  119. { return cmVS12MASMFlagTable; }
  120. else if(v == cmLocalVisualStudioGenerator::VS11)
  121. { return cmVS11MASMFlagTable; }
  122. else
  123. { return cmVS10MASMFlagTable; }
  124. }
  125. return 0;
  126. }
  127. static std::string cmVS10EscapeXML(std::string arg)
  128. {
  129. cmSystemTools::ReplaceString(arg, "&", "&amp;");
  130. cmSystemTools::ReplaceString(arg, "<", "&lt;");
  131. cmSystemTools::ReplaceString(arg, ">", "&gt;");
  132. return arg;
  133. }
  134. static std::string cmVS10EscapeComment(std::string comment)
  135. {
  136. // MSBuild takes the CDATA of a <Message></Message> element and just
  137. // does "echo $CDATA" with no escapes. We must encode the string.
  138. // http://technet.microsoft.com/en-us/library/cc772462%28WS.10%29.aspx
  139. std::string echoable;
  140. for(std::string::iterator c = comment.begin(); c != comment.end(); ++c)
  141. {
  142. switch (*c)
  143. {
  144. case '\r': break;
  145. case '\n': echoable += '\t'; break;
  146. case '"': /* no break */
  147. case '|': /* no break */
  148. case '&': /* no break */
  149. case '<': /* no break */
  150. case '>': /* no break */
  151. case '^': echoable += '^'; /* no break */
  152. default: echoable += *c; break;
  153. }
  154. }
  155. return echoable;
  156. }
  157. cmVisualStudio10TargetGenerator::
  158. cmVisualStudio10TargetGenerator(cmTarget* target,
  159. cmGlobalVisualStudio10Generator* gg)
  160. {
  161. this->GlobalGenerator = gg;
  162. this->Target = target;
  163. this->GeneratorTarget = gg->GetGeneratorTarget(target);
  164. this->Makefile = target->GetMakefile();
  165. this->LocalGenerator =
  166. (cmLocalVisualStudio7Generator*)
  167. this->Makefile->GetLocalGenerator();
  168. this->Name = this->Target->GetName();
  169. this->GlobalGenerator->CreateGUID(this->Name.c_str());
  170. this->GUID = this->GlobalGenerator->GetGUID(this->Name.c_str());
  171. this->Platform = gg->GetPlatformName();
  172. this->NsightTegra = gg->IsNsightTegra();
  173. for(int i =
  174. sscanf(gg->GetNsightTegraVersion().c_str(), "%u.%u.%u.%u",
  175. &this->NsightTegraVersion[0], &this->NsightTegraVersion[1],
  176. &this->NsightTegraVersion[2], &this->NsightTegraVersion[3]);
  177. i < 4; ++i)
  178. {
  179. this->NsightTegraVersion[i] = 0;
  180. }
  181. this->MSTools = !this->NsightTegra;
  182. this->TargetCompileAsWinRT = false;
  183. this->BuildFileStream = 0;
  184. this->IsMissingFiles = false;
  185. this->DefaultArtifactDir =
  186. this->Makefile->GetStartOutputDirectory() + std::string("/") +
  187. this->LocalGenerator->GetTargetDirectory(*this->Target);
  188. }
  189. cmVisualStudio10TargetGenerator::~cmVisualStudio10TargetGenerator()
  190. {
  191. for(OptionsMap::iterator i = this->ClOptions.begin();
  192. i != this->ClOptions.end(); ++i)
  193. {
  194. delete i->second;
  195. }
  196. for(OptionsMap::iterator i = this->LinkOptions.begin();
  197. i != this->LinkOptions.end(); ++i)
  198. {
  199. delete i->second;
  200. }
  201. if(!this->BuildFileStream)
  202. {
  203. return;
  204. }
  205. if (this->BuildFileStream->Close())
  206. {
  207. this->GlobalGenerator
  208. ->FileReplacedDuringGenerate(this->PathToVcxproj);
  209. }
  210. delete this->BuildFileStream;
  211. }
  212. void cmVisualStudio10TargetGenerator::WritePlatformConfigTag(
  213. const char* tag,
  214. const std::string& config,
  215. int indentLevel,
  216. const char* attribute,
  217. const char* end,
  218. std::ostream* stream)
  219. {
  220. if(!stream)
  221. {
  222. stream = this->BuildFileStream;
  223. }
  224. stream->fill(' ');
  225. stream->width(indentLevel*2 );
  226. (*stream ) << "";
  227. (*stream ) << "<" << tag
  228. << " Condition=\"'$(Configuration)|$(Platform)'=='";
  229. (*stream ) << config << "|" << this->Platform << "'\"";
  230. if(attribute)
  231. {
  232. (*stream ) << attribute;
  233. }
  234. // close the tag
  235. (*stream ) << ">";
  236. if(end)
  237. {
  238. (*stream ) << end;
  239. }
  240. }
  241. void cmVisualStudio10TargetGenerator::WriteString(const char* line,
  242. int indentLevel)
  243. {
  244. this->BuildFileStream->fill(' ');
  245. this->BuildFileStream->width(indentLevel*2 );
  246. // write an empty string to get the fill level indent to print
  247. (*this->BuildFileStream ) << "";
  248. (*this->BuildFileStream ) << line;
  249. }
  250. #define VS10_USER_PROPS "$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props"
  251. void cmVisualStudio10TargetGenerator::Generate()
  252. {
  253. // do not generate external ms projects
  254. if(this->Target->GetType() == cmTarget::INTERFACE_LIBRARY
  255. || this->Target->GetProperty("EXTERNAL_MSPROJECT"))
  256. {
  257. return;
  258. }
  259. // Tell the global generator the name of the project file
  260. this->Target->SetProperty("GENERATOR_FILE_NAME",this->Name.c_str());
  261. this->Target->SetProperty("GENERATOR_FILE_NAME_EXT",
  262. ".vcxproj");
  263. if(this->Target->GetType() <= cmTarget::OBJECT_LIBRARY)
  264. {
  265. if(!this->ComputeClOptions())
  266. {
  267. return;
  268. }
  269. if(!this->ComputeRcOptions())
  270. {
  271. return;
  272. }
  273. if(!this->ComputeMasmOptions())
  274. {
  275. return;
  276. }
  277. if(!this->ComputeLinkOptions())
  278. {
  279. return;
  280. }
  281. }
  282. cmMakefile* mf = this->Target->GetMakefile();
  283. std::string path = mf->GetStartOutputDirectory();
  284. path += "/";
  285. path += this->Name;
  286. path += ".vcxproj";
  287. this->BuildFileStream =
  288. new cmGeneratedFileStream(path.c_str());
  289. this->PathToVcxproj = path;
  290. this->BuildFileStream->SetCopyIfDifferent(true);
  291. // Write the encoding header into the file
  292. char magic[] = {char(0xEF), char(0xBB), char(0xBF)};
  293. this->BuildFileStream->write(magic, 3);
  294. //get the tools version to use
  295. const std::string toolsVer(this->GlobalGenerator->GetToolsVersion());
  296. std::string project_defaults=
  297. "<?xml version=\"1.0\" encoding=\"" +
  298. this->GlobalGenerator->Encoding() + "\"?>\n";
  299. project_defaults.append("<Project DefaultTargets=\"Build\" ToolsVersion=\"");
  300. project_defaults.append(toolsVer +"\" ");
  301. project_defaults.append(
  302. "xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n");
  303. this->WriteString(project_defaults.c_str(),0);
  304. if(this->NsightTegra)
  305. {
  306. this->WriteString("<PropertyGroup Label=\"NsightTegraProject\">\n", 1);
  307. if(this->NsightTegraVersion[0] >= 2)
  308. {
  309. // Nsight Tegra 2.0 uses project revision 9.
  310. this->WriteString("<NsightTegraProjectRevisionNumber>"
  311. "9"
  312. "</NsightTegraProjectRevisionNumber>\n", 2);
  313. // Tell newer versions to upgrade silently when loading.
  314. this->WriteString("<NsightTegraUpgradeOnceWithoutPrompt>"
  315. "true"
  316. "</NsightTegraUpgradeOnceWithoutPrompt>\n", 2);
  317. }
  318. else
  319. {
  320. // Require Nsight Tegra 1.6 for JCompile support.
  321. this->WriteString("<NsightTegraProjectRevisionNumber>"
  322. "7"
  323. "</NsightTegraProjectRevisionNumber>\n", 2);
  324. }
  325. this->WriteString("</PropertyGroup>\n", 1);
  326. }
  327. this->WriteProjectConfigurations();
  328. this->WriteString("<PropertyGroup Label=\"Globals\">\n", 1);
  329. this->WriteString("<ProjectGUID>", 2);
  330. (*this->BuildFileStream) << "{" << this->GUID << "}</ProjectGUID>\n";
  331. if(this->MSTools && this->Target->GetType() <= cmTarget::GLOBAL_TARGET)
  332. {
  333. this->WriteApplicationTypeSettings();
  334. this->VerifyNecessaryFiles();
  335. }
  336. const char* vsProjectTypes =
  337. this->Target->GetProperty("VS_GLOBAL_PROJECT_TYPES");
  338. if(vsProjectTypes)
  339. {
  340. this->WriteString("<ProjectTypes>", 2);
  341. (*this->BuildFileStream) << cmVS10EscapeXML(vsProjectTypes) <<
  342. "</ProjectTypes>\n";
  343. }
  344. const char* vsProjectName = this->Target->GetProperty("VS_SCC_PROJECTNAME");
  345. const char* vsLocalPath = this->Target->GetProperty("VS_SCC_LOCALPATH");
  346. const char* vsProvider = this->Target->GetProperty("VS_SCC_PROVIDER");
  347. if( vsProjectName && vsLocalPath && vsProvider )
  348. {
  349. this->WriteString("<SccProjectName>", 2);
  350. (*this->BuildFileStream) << cmVS10EscapeXML(vsProjectName) <<
  351. "</SccProjectName>\n";
  352. this->WriteString("<SccLocalPath>", 2);
  353. (*this->BuildFileStream) << cmVS10EscapeXML(vsLocalPath) <<
  354. "</SccLocalPath>\n";
  355. this->WriteString("<SccProvider>", 2);
  356. (*this->BuildFileStream) << cmVS10EscapeXML(vsProvider) <<
  357. "</SccProvider>\n";
  358. const char* vsAuxPath = this->Target->GetProperty("VS_SCC_AUXPATH");
  359. if( vsAuxPath )
  360. {
  361. this->WriteString("<SccAuxPath>", 2);
  362. (*this->BuildFileStream) << cmVS10EscapeXML(vsAuxPath) <<
  363. "</SccAuxPath>\n";
  364. }
  365. }
  366. if(this->Target->GetPropertyAsBool("VS_WINRT_COMPONENT"))
  367. {
  368. this->WriteString("<WinMDAssembly>true</WinMDAssembly>\n", 2);
  369. }
  370. const char* vsGlobalKeyword =
  371. this->Target->GetProperty("VS_GLOBAL_KEYWORD");
  372. if(!vsGlobalKeyword)
  373. {
  374. this->WriteString("<Keyword>Win32Proj</Keyword>\n", 2);
  375. }
  376. else
  377. {
  378. this->WriteString("<Keyword>", 2);
  379. (*this->BuildFileStream) << cmVS10EscapeXML(vsGlobalKeyword) <<
  380. "</Keyword>\n";
  381. }
  382. const char* vsGlobalRootNamespace =
  383. this->Target->GetProperty("VS_GLOBAL_ROOTNAMESPACE");
  384. if(vsGlobalRootNamespace)
  385. {
  386. this->WriteString("<RootNamespace>", 2);
  387. (*this->BuildFileStream) << cmVS10EscapeXML(vsGlobalRootNamespace) <<
  388. "</RootNamespace>\n";
  389. }
  390. this->WriteString("<Platform>", 2);
  391. (*this->BuildFileStream) << cmVS10EscapeXML(this->Platform)
  392. << "</Platform>\n";
  393. const char* projLabel = this->Target->GetProperty("PROJECT_LABEL");
  394. if(!projLabel)
  395. {
  396. projLabel = this->Name.c_str();
  397. }
  398. this->WriteString("<ProjectName>", 2);
  399. (*this->BuildFileStream) << cmVS10EscapeXML(projLabel) << "</ProjectName>\n";
  400. if(const char* targetFrameworkVersion = this->Target->GetProperty(
  401. "VS_DOTNET_TARGET_FRAMEWORK_VERSION"))
  402. {
  403. this->WriteString("<TargetFrameworkVersion>", 2);
  404. (*this->BuildFileStream) << cmVS10EscapeXML(targetFrameworkVersion)
  405. << "</TargetFrameworkVersion>\n";
  406. }
  407. this->WriteString("</PropertyGroup>\n", 1);
  408. this->WriteString("<Import Project="
  409. "\"$(VCTargetsPath)\\Microsoft.Cpp.Default.props\" />\n",
  410. 1);
  411. this->WriteProjectConfigurationValues();
  412. this->WriteString(
  413. "<Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.props\" />\n", 1);
  414. this->WriteString("<ImportGroup Label=\"ExtensionSettings\">\n", 1);
  415. if (this->GlobalGenerator->IsMasmEnabled())
  416. {
  417. this->WriteString("<Import Project=\"$(VCTargetsPath)\\"
  418. "BuildCustomizations\\masm.props\" />\n", 2);
  419. }
  420. this->WriteString("</ImportGroup>\n", 1);
  421. this->WriteString("<ImportGroup Label=\"PropertySheets\">\n", 1);
  422. this->WriteString("<Import Project=\"" VS10_USER_PROPS "\""
  423. " Condition=\"exists('" VS10_USER_PROPS "')\""
  424. " Label=\"LocalAppDataPlatform\" />\n", 2);
  425. this->WriteString("</ImportGroup>\n", 1);
  426. this->WriteString("<PropertyGroup Label=\"UserMacros\" />\n", 1);
  427. this->WriteWinRTPackageCertificateKeyFile();
  428. this->WritePathAndIncrementalLinkOptions();
  429. this->WriteItemDefinitionGroups();
  430. this->WriteCustomCommands();
  431. this->WriteAllSources();
  432. this->WriteDotNetReferences();
  433. this->WriteEmbeddedResourceGroup();
  434. this->WriteXamlFilesGroup();
  435. this->WriteWinRTReferences();
  436. this->WriteProjectReferences();
  437. this->WriteString(
  438. "<Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.targets\""
  439. " />\n", 1);
  440. this->WriteTargetSpecificReferences();
  441. this->WriteString("<ImportGroup Label=\"ExtensionTargets\">\n", 1);
  442. if (this->GlobalGenerator->IsMasmEnabled())
  443. {
  444. this->WriteString("<Import Project=\"$(VCTargetsPath)\\"
  445. "BuildCustomizations\\masm.targets\" />\n", 2);
  446. }
  447. this->WriteString("</ImportGroup>\n", 1);
  448. this->WriteString("</Project>", 0);
  449. // The groups are stored in a separate file for VS 10
  450. this->WriteGroups();
  451. }
  452. void cmVisualStudio10TargetGenerator::WriteDotNetReferences()
  453. {
  454. std::vector<std::string> references;
  455. if(const char* vsDotNetReferences =
  456. this->Target->GetProperty("VS_DOTNET_REFERENCES"))
  457. {
  458. cmSystemTools::ExpandListArgument(vsDotNetReferences, references);
  459. }
  460. if(!references.empty())
  461. {
  462. this->WriteString("<ItemGroup>\n", 1);
  463. for(std::vector<std::string>::iterator ri = references.begin();
  464. ri != references.end(); ++ri)
  465. {
  466. this->WriteString("<Reference Include=\"", 2);
  467. (*this->BuildFileStream) << cmVS10EscapeXML(*ri) << "\">\n";
  468. this->WriteString("<CopyLocalSatelliteAssemblies>true"
  469. "</CopyLocalSatelliteAssemblies>\n", 3);
  470. this->WriteString("<ReferenceOutputAssembly>true"
  471. "</ReferenceOutputAssembly>\n", 3);
  472. this->WriteString("</Reference>\n", 2);
  473. }
  474. this->WriteString("</ItemGroup>\n", 1);
  475. }
  476. }
  477. void cmVisualStudio10TargetGenerator::WriteEmbeddedResourceGroup()
  478. {
  479. std::vector<cmSourceFile const*> resxObjs;
  480. this->GeneratorTarget->GetResxSources(resxObjs, "");
  481. if(!resxObjs.empty())
  482. {
  483. this->WriteString("<ItemGroup>\n", 1);
  484. for(std::vector<cmSourceFile const*>::const_iterator oi = resxObjs.begin();
  485. oi != resxObjs.end(); ++oi)
  486. {
  487. std::string obj = (*oi)->GetFullPath();
  488. this->WriteString("<EmbeddedResource Include=\"", 2);
  489. this->ConvertToWindowsSlash(obj);
  490. (*this->BuildFileStream ) << obj << "\">\n";
  491. this->WriteString("<DependentUpon>", 3);
  492. std::string hFileName = obj.substr(0, obj.find_last_of(".")) + ".h";
  493. (*this->BuildFileStream) << hFileName << "</DependentUpon>\n";
  494. std::vector<std::string> const * configs =
  495. this->GlobalGenerator->GetConfigurations();
  496. for(std::vector<std::string>::const_iterator i = configs->begin();
  497. i != configs->end(); ++i)
  498. {
  499. this->WritePlatformConfigTag("LogicalName", i->c_str(), 3);
  500. if(this->Target->GetProperty("VS_GLOBAL_ROOTNAMESPACE"))
  501. {
  502. (*this->BuildFileStream ) << "$(RootNamespace).";
  503. }
  504. (*this->BuildFileStream ) << "%(Filename)";
  505. (*this->BuildFileStream ) << ".resources";
  506. (*this->BuildFileStream ) << "</LogicalName>\n";
  507. }
  508. this->WriteString("</EmbeddedResource>\n", 2);
  509. }
  510. this->WriteString("</ItemGroup>\n", 1);
  511. }
  512. }
  513. void cmVisualStudio10TargetGenerator::WriteXamlFilesGroup()
  514. {
  515. std::vector<cmSourceFile const*> xamlObjs;
  516. this->GeneratorTarget->GetXamlSources(xamlObjs, "");
  517. if (!xamlObjs.empty())
  518. {
  519. this->WriteString("<ItemGroup>\n", 1);
  520. for (std::vector<cmSourceFile const*>::const_iterator
  521. oi = xamlObjs.begin(); oi != xamlObjs.end(); ++oi)
  522. {
  523. std::string obj = (*oi)->GetFullPath();
  524. std::string xamlType;
  525. const char * xamlTypeProperty = (*oi)->GetProperty("VS_XAML_TYPE");
  526. if (xamlTypeProperty)
  527. {
  528. xamlType = xamlTypeProperty;
  529. }
  530. else
  531. {
  532. xamlType = "Page";
  533. }
  534. this->WriteSource(xamlType, *oi, ">\n");
  535. this->WriteString("<SubType>Designer</SubType>\n", 3);
  536. this->WriteString("</", 2);
  537. (*this->BuildFileStream) << xamlType << ">\n";
  538. }
  539. this->WriteString("</ItemGroup>\n", 1);
  540. }
  541. }
  542. void cmVisualStudio10TargetGenerator::WriteTargetSpecificReferences()
  543. {
  544. if(this->MSTools)
  545. {
  546. if(this->GlobalGenerator->TargetsWindowsPhone() &&
  547. this->GlobalGenerator->GetSystemVersion() == "8.0")
  548. {
  549. this->WriteString(
  550. "<Import Project=\""
  551. "$(MSBuildExtensionsPath)\\Microsoft\\WindowsPhone\\v"
  552. "$(TargetPlatformVersion)\\Microsoft.Cpp.WindowsPhone."
  553. "$(TargetPlatformVersion).targets\" />\n", 1);
  554. }
  555. }
  556. }
  557. void cmVisualStudio10TargetGenerator::WriteWinRTReferences()
  558. {
  559. std::vector<std::string> references;
  560. if(const char* vsWinRTReferences =
  561. this->Target->GetProperty("VS_WINRT_REFERENCES"))
  562. {
  563. cmSystemTools::ExpandListArgument(vsWinRTReferences, references);
  564. }
  565. if(this->GlobalGenerator->TargetsWindowsPhone() &&
  566. this->GlobalGenerator->GetSystemVersion() == "8.0" &&
  567. references.empty())
  568. {
  569. references.push_back("platform.winmd");
  570. }
  571. if(!references.empty())
  572. {
  573. this->WriteString("<ItemGroup>\n", 1);
  574. for(std::vector<std::string>::iterator ri = references.begin();
  575. ri != references.end(); ++ri)
  576. {
  577. this->WriteString("<Reference Include=\"", 2);
  578. (*this->BuildFileStream) << cmVS10EscapeXML(*ri) << "\">\n";
  579. this->WriteString("<IsWinMDFile>true</IsWinMDFile>\n", 3);
  580. this->WriteString("</Reference>\n", 2);
  581. }
  582. this->WriteString("</ItemGroup>\n", 1);
  583. }
  584. }
  585. // ConfigurationType Application, Utility StaticLibrary DynamicLibrary
  586. void cmVisualStudio10TargetGenerator::WriteProjectConfigurations()
  587. {
  588. this->WriteString("<ItemGroup Label=\"ProjectConfigurations\">\n", 1);
  589. std::vector<std::string> *configs =
  590. static_cast<cmGlobalVisualStudio7Generator *>
  591. (this->GlobalGenerator)->GetConfigurations();
  592. for(std::vector<std::string>::iterator i = configs->begin();
  593. i != configs->end(); ++i)
  594. {
  595. this->WriteString("<ProjectConfiguration Include=\"", 2);
  596. (*this->BuildFileStream ) << *i << "|" << this->Platform << "\">\n";
  597. this->WriteString("<Configuration>", 3);
  598. (*this->BuildFileStream ) << *i << "</Configuration>\n";
  599. this->WriteString("<Platform>", 3);
  600. (*this->BuildFileStream) << cmVS10EscapeXML(this->Platform)
  601. << "</Platform>\n";
  602. this->WriteString("</ProjectConfiguration>\n", 2);
  603. }
  604. this->WriteString("</ItemGroup>\n", 1);
  605. }
  606. void cmVisualStudio10TargetGenerator::WriteProjectConfigurationValues()
  607. {
  608. std::vector<std::string> *configs =
  609. static_cast<cmGlobalVisualStudio7Generator *>
  610. (this->GlobalGenerator)->GetConfigurations();
  611. for(std::vector<std::string>::iterator i = configs->begin();
  612. i != configs->end(); ++i)
  613. {
  614. this->WritePlatformConfigTag("PropertyGroup",
  615. i->c_str(),
  616. 1, " Label=\"Configuration\"", "\n");
  617. std::string configType = "<ConfigurationType>";
  618. switch(this->Target->GetType())
  619. {
  620. case cmTarget::SHARED_LIBRARY:
  621. case cmTarget::MODULE_LIBRARY:
  622. configType += "DynamicLibrary";
  623. break;
  624. case cmTarget::OBJECT_LIBRARY:
  625. case cmTarget::STATIC_LIBRARY:
  626. configType += "StaticLibrary";
  627. break;
  628. case cmTarget::EXECUTABLE:
  629. if(this->NsightTegra &&
  630. !this->Target->GetPropertyAsBool("ANDROID_GUI"))
  631. {
  632. // Android executables are .so too.
  633. configType += "DynamicLibrary";
  634. }
  635. else
  636. {
  637. configType += "Application";
  638. }
  639. break;
  640. case cmTarget::UTILITY:
  641. case cmTarget::GLOBAL_TARGET:
  642. if(this->NsightTegra)
  643. {
  644. // Tegra-Android platform does not understand "Utility".
  645. configType += "StaticLibrary";
  646. }
  647. else
  648. {
  649. configType += "Utility";
  650. }
  651. break;
  652. case cmTarget::UNKNOWN_LIBRARY:
  653. case cmTarget::INTERFACE_LIBRARY:
  654. break;
  655. }
  656. configType += "</ConfigurationType>\n";
  657. this->WriteString(configType.c_str(), 2);
  658. if(this->MSTools)
  659. {
  660. this->WriteMSToolConfigurationValues(*i);
  661. }
  662. else if(this->NsightTegra)
  663. {
  664. this->WriteNsightTegraConfigurationValues(*i);
  665. }
  666. this->WriteString("</PropertyGroup>\n", 1);
  667. }
  668. }
  669. //----------------------------------------------------------------------------
  670. void cmVisualStudio10TargetGenerator
  671. ::WriteMSToolConfigurationValues(std::string const& config)
  672. {
  673. cmGlobalVisualStudio10Generator* gg =
  674. static_cast<cmGlobalVisualStudio10Generator*>(this->GlobalGenerator);
  675. const char* mfcFlag =
  676. this->Target->GetMakefile()->GetDefinition("CMAKE_MFC_FLAG");
  677. std::string mfcFlagValue = mfcFlag ? mfcFlag : "0";
  678. std::string useOfMfcValue = "false";
  679. if(mfcFlagValue == "1")
  680. {
  681. useOfMfcValue = "Static";
  682. }
  683. else if(mfcFlagValue == "2")
  684. {
  685. useOfMfcValue = "Dynamic";
  686. }
  687. std::string mfcLine = "<UseOfMfc>";
  688. mfcLine += useOfMfcValue + "</UseOfMfc>\n";
  689. this->WriteString(mfcLine.c_str(), 2);
  690. if((this->Target->GetType() <= cmTarget::OBJECT_LIBRARY &&
  691. this->ClOptions[config]->UsingUnicode()) ||
  692. this->Target->GetPropertyAsBool("VS_WINRT_COMPONENT") ||
  693. this->GlobalGenerator->TargetsWindowsPhone() ||
  694. this->GlobalGenerator->TargetsWindowsStore() ||
  695. this->Target->GetPropertyAsBool("VS_WINRT_EXTENSIONS"))
  696. {
  697. this->WriteString("<CharacterSet>Unicode</CharacterSet>\n", 2);
  698. }
  699. else if (this->Target->GetType() <= cmTarget::MODULE_LIBRARY &&
  700. this->ClOptions[config]->UsingSBCS())
  701. {
  702. this->WriteString("<CharacterSet>NotSet</CharacterSet>\n", 2);
  703. }
  704. else
  705. {
  706. this->WriteString("<CharacterSet>MultiByte</CharacterSet>\n", 2);
  707. }
  708. if(const char* toolset = gg->GetPlatformToolset())
  709. {
  710. std::string pts = "<PlatformToolset>";
  711. pts += toolset;
  712. pts += "</PlatformToolset>\n";
  713. this->WriteString(pts.c_str(), 2);
  714. }
  715. if(this->Target->GetPropertyAsBool("VS_WINRT_COMPONENT") ||
  716. this->Target->GetPropertyAsBool("VS_WINRT_EXTENSIONS"))
  717. {
  718. this->WriteString("<WindowsAppContainer>true"
  719. "</WindowsAppContainer>\n", 2);
  720. }
  721. }
  722. //----------------------------------------------------------------------------
  723. void cmVisualStudio10TargetGenerator
  724. ::WriteNsightTegraConfigurationValues(std::string const&)
  725. {
  726. cmGlobalVisualStudio10Generator* gg =
  727. static_cast<cmGlobalVisualStudio10Generator*>(this->GlobalGenerator);
  728. const char* toolset = gg->GetPlatformToolset();
  729. std::string ntv = "<NdkToolchainVersion>";
  730. ntv += toolset? toolset : "Default";
  731. ntv += "</NdkToolchainVersion>\n";
  732. this->WriteString(ntv.c_str(), 2);
  733. if(const char* minApi = this->Target->GetProperty("ANDROID_API_MIN"))
  734. {
  735. this->WriteString("<AndroidMinAPI>", 2);
  736. (*this->BuildFileStream ) <<
  737. "android-" << cmVS10EscapeXML(minApi) << "</AndroidMinAPI>\n";
  738. }
  739. if(const char* api = this->Target->GetProperty("ANDROID_API"))
  740. {
  741. this->WriteString("<AndroidTargetAPI>", 2);
  742. (*this->BuildFileStream ) <<
  743. "android-" << cmVS10EscapeXML(api) << "</AndroidTargetAPI>\n";
  744. }
  745. }
  746. void cmVisualStudio10TargetGenerator::WriteCustomCommands()
  747. {
  748. this->SourcesVisited.clear();
  749. std::vector<cmSourceFile const*> customCommands;
  750. this->GeneratorTarget->GetCustomCommands(customCommands, "");
  751. for(std::vector<cmSourceFile const*>::const_iterator
  752. si = customCommands.begin();
  753. si != customCommands.end(); ++si)
  754. {
  755. this->WriteCustomCommand(*si);
  756. }
  757. }
  758. //----------------------------------------------------------------------------
  759. void cmVisualStudio10TargetGenerator
  760. ::WriteCustomCommand(cmSourceFile const* sf)
  761. {
  762. if(this->SourcesVisited.insert(sf).second)
  763. {
  764. if(std::vector<cmSourceFile*> const* depends =
  765. this->GeneratorTarget->GetSourceDepends(sf))
  766. {
  767. for(std::vector<cmSourceFile*>::const_iterator di = depends->begin();
  768. di != depends->end(); ++di)
  769. {
  770. this->WriteCustomCommand(*di);
  771. }
  772. }
  773. if(cmCustomCommand const* command = sf->GetCustomCommand())
  774. {
  775. this->WriteString("<ItemGroup>\n", 1);
  776. this->WriteCustomRule(sf, *command);
  777. this->WriteString("</ItemGroup>\n", 1);
  778. }
  779. }
  780. }
  781. void
  782. cmVisualStudio10TargetGenerator::WriteCustomRule(cmSourceFile const* source,
  783. cmCustomCommand const &
  784. command)
  785. {
  786. std::string sourcePath = source->GetFullPath();
  787. // VS 10 will always rebuild a custom command attached to a .rule
  788. // file that doesn't exist so create the file explicitly.
  789. if (source->GetPropertyAsBool("__CMAKE_RULE"))
  790. {
  791. if(!cmSystemTools::FileExists(sourcePath.c_str()))
  792. {
  793. // Make sure the path exists for the file
  794. std::string path = cmSystemTools::GetFilenamePath(sourcePath);
  795. cmSystemTools::MakeDirectory(path.c_str());
  796. cmsys::ofstream fout(sourcePath.c_str());
  797. if(fout)
  798. {
  799. fout << "# generated from CMake\n";
  800. fout.flush();
  801. fout.close();
  802. }
  803. else
  804. {
  805. std::string error = "Could not create file: [";
  806. error += sourcePath;
  807. error += "] ";
  808. cmSystemTools::Error
  809. (error.c_str(), cmSystemTools::GetLastSystemError().c_str());
  810. }
  811. }
  812. }
  813. cmLocalVisualStudio7Generator* lg = this->LocalGenerator;
  814. std::vector<std::string> *configs =
  815. static_cast<cmGlobalVisualStudio7Generator *>
  816. (this->GlobalGenerator)->GetConfigurations();
  817. this->WriteSource("CustomBuild", source, ">\n");
  818. for(std::vector<std::string>::iterator i = configs->begin();
  819. i != configs->end(); ++i)
  820. {
  821. cmCustomCommandGenerator ccg(command, *i, this->Makefile);
  822. std::string comment = lg->ConstructComment(ccg);
  823. comment = cmVS10EscapeComment(comment);
  824. std::string script =
  825. cmVS10EscapeXML(lg->ConstructScript(ccg));
  826. this->WritePlatformConfigTag("Message",i->c_str(), 3);
  827. (*this->BuildFileStream ) << cmVS10EscapeXML(comment) << "</Message>\n";
  828. this->WritePlatformConfigTag("Command", i->c_str(), 3);
  829. (*this->BuildFileStream ) << script << "</Command>\n";
  830. this->WritePlatformConfigTag("AdditionalInputs", i->c_str(), 3);
  831. (*this->BuildFileStream ) << cmVS10EscapeXML(source->GetFullPath());
  832. for(std::vector<std::string>::const_iterator d =
  833. ccg.GetDepends().begin();
  834. d != ccg.GetDepends().end();
  835. ++d)
  836. {
  837. std::string dep;
  838. if(this->LocalGenerator->GetRealDependency(d->c_str(), i->c_str(), dep))
  839. {
  840. this->ConvertToWindowsSlash(dep);
  841. (*this->BuildFileStream ) << ";" << cmVS10EscapeXML(dep);
  842. }
  843. }
  844. (*this->BuildFileStream ) << ";%(AdditionalInputs)</AdditionalInputs>\n";
  845. this->WritePlatformConfigTag("Outputs", i->c_str(), 3);
  846. const char* sep = "";
  847. for(std::vector<std::string>::const_iterator o =
  848. ccg.GetOutputs().begin();
  849. o != ccg.GetOutputs().end();
  850. ++o)
  851. {
  852. std::string out = *o;
  853. this->ConvertToWindowsSlash(out);
  854. (*this->BuildFileStream ) << sep << cmVS10EscapeXML(out);
  855. sep = ";";
  856. }
  857. (*this->BuildFileStream ) << "</Outputs>\n";
  858. if(this->LocalGenerator->GetVersion() > cmLocalVisualStudioGenerator::VS10)
  859. {
  860. // VS >= 11 let us turn off linking of custom command outputs.
  861. this->WritePlatformConfigTag("LinkObjects", i->c_str(), 3);
  862. (*this->BuildFileStream ) << "false</LinkObjects>\n";
  863. }
  864. }
  865. this->WriteString("</CustomBuild>\n", 2);
  866. }
  867. std::string
  868. cmVisualStudio10TargetGenerator::ConvertPath(std::string const& path,
  869. bool forceRelative)
  870. {
  871. return forceRelative
  872. ? cmSystemTools::RelativePath(
  873. this->Makefile->GetCurrentOutputDirectory(), path.c_str())
  874. : this->LocalGenerator->Convert(path.c_str(),
  875. cmLocalGenerator::START_OUTPUT,
  876. cmLocalGenerator::UNCHANGED,
  877. /* optional = */ true);
  878. }
  879. void cmVisualStudio10TargetGenerator::ConvertToWindowsSlash(std::string& s)
  880. {
  881. // first convert all of the slashes
  882. std::string::size_type pos = 0;
  883. while((pos = s.find('/', pos)) != std::string::npos)
  884. {
  885. s[pos] = '\\';
  886. pos++;
  887. }
  888. }
  889. void cmVisualStudio10TargetGenerator::WriteGroups()
  890. {
  891. // collect up group information
  892. std::vector<cmSourceGroup> sourceGroups =
  893. this->Makefile->GetSourceGroups();
  894. std::vector<cmSourceFile*> classes;
  895. if (!this->Target->GetConfigCommonSourceFiles(classes))
  896. {
  897. return;
  898. }
  899. std::set<cmSourceGroup*> groupsUsed;
  900. for(std::vector<cmSourceFile*>::const_iterator s = classes.begin();
  901. s != classes.end(); s++)
  902. {
  903. cmSourceFile* sf = *s;
  904. std::string const& source = sf->GetFullPath();
  905. cmSourceGroup* sourceGroup =
  906. this->Makefile->FindSourceGroup(source.c_str(), sourceGroups);
  907. groupsUsed.insert(sourceGroup);
  908. }
  909. this->AddMissingSourceGroups(groupsUsed, sourceGroups);
  910. // Write out group file
  911. std::string path = this->Makefile->GetStartOutputDirectory();
  912. path += "/";
  913. path += this->Name;
  914. path += ".vcxproj.filters";
  915. cmGeneratedFileStream fout(path.c_str());
  916. fout.SetCopyIfDifferent(true);
  917. char magic[] = {char(0xEF), char(0xBB), char(0xBF)};
  918. fout.write(magic, 3);
  919. cmGeneratedFileStream* save = this->BuildFileStream;
  920. this->BuildFileStream = & fout;
  921. //get the tools version to use
  922. const std::string toolsVer(this->GlobalGenerator->GetToolsVersion());
  923. std::string project_defaults=
  924. "<?xml version=\"1.0\" encoding=\"" +
  925. this->GlobalGenerator->Encoding() + "\"?>\n";
  926. project_defaults.append("<Project ToolsVersion=\"");
  927. project_defaults.append(toolsVer +"\" ");
  928. project_defaults.append(
  929. "xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n");
  930. this->WriteString(project_defaults.c_str(),0);
  931. for(ToolSourceMap::const_iterator ti = this->Tools.begin();
  932. ti != this->Tools.end(); ++ti)
  933. {
  934. this->WriteGroupSources(ti->first.c_str(), ti->second, sourceGroups);
  935. }
  936. // Added files are images and the manifest.
  937. if (!this->AddedFiles.empty())
  938. {
  939. this->WriteString("<ItemGroup>\n", 1);
  940. for(std::vector<std::string>::const_iterator
  941. oi = this->AddedFiles.begin(); oi != this->AddedFiles.end(); ++oi)
  942. {
  943. std::string fileName = cmSystemTools::LowerCase(
  944. cmSystemTools::GetFilenameName(*oi));
  945. if (fileName == "wmappmanifest.xml")
  946. {
  947. this->WriteString("<XML Include=\"", 2);
  948. (*this->BuildFileStream) << *oi << "\">\n";
  949. this->WriteString("<Filter>Resource Files</Filter>\n", 3);
  950. this->WriteString("</XML>\n", 2);
  951. }
  952. else if(cmSystemTools::GetFilenameExtension(fileName) ==
  953. ".appxmanifest")
  954. {
  955. this->WriteString("<AppxManifest Include=\"", 2);
  956. (*this->BuildFileStream) << *oi << "\">\n";
  957. this->WriteString("<Filter>Resource Files</Filter>\n", 3);
  958. this->WriteString("</AppxManifest>\n", 2);
  959. }
  960. else if(cmSystemTools::GetFilenameExtension(fileName) ==
  961. ".pfx")
  962. {
  963. this->WriteString("<None Include=\"", 2);
  964. (*this->BuildFileStream) << *oi << "\">\n";
  965. this->WriteString("<Filter>Resource Files</Filter>\n", 3);
  966. this->WriteString("</None>\n", 2);
  967. }
  968. else
  969. {
  970. this->WriteString("<Image Include=\"", 2);
  971. (*this->BuildFileStream) << *oi << "\">\n";
  972. this->WriteString("<Filter>Resource Files</Filter>\n", 3);
  973. this->WriteString("</Image>\n", 2);
  974. }
  975. }
  976. this->WriteString("</ItemGroup>\n", 1);
  977. }
  978. std::vector<cmSourceFile const*> resxObjs;
  979. this->GeneratorTarget->GetResxSources(resxObjs, "");
  980. if(!resxObjs.empty())
  981. {
  982. this->WriteString("<ItemGroup>\n", 1);
  983. for(std::vector<cmSourceFile const*>::const_iterator oi = resxObjs.begin();
  984. oi != resxObjs.end(); ++oi)
  985. {
  986. std::string obj = (*oi)->GetFullPath();
  987. this->WriteString("<EmbeddedResource Include=\"", 2);
  988. this->ConvertToWindowsSlash(obj);
  989. (*this->BuildFileStream ) << cmVS10EscapeXML(obj) << "\">\n";
  990. this->WriteString("<Filter>Resource Files</Filter>\n", 3);
  991. this->WriteString("</EmbeddedResource>\n", 2);
  992. }
  993. this->WriteString("</ItemGroup>\n", 1);
  994. }
  995. // Add object library contents as external objects.
  996. std::vector<std::string> objs;
  997. this->GeneratorTarget->UseObjectLibraries(objs, "");
  998. if(!objs.empty())
  999. {
  1000. this->WriteString("<ItemGroup>\n", 1);
  1001. for(std::vector<std::string>::const_iterator
  1002. oi = objs.begin(); oi != objs.end(); ++oi)
  1003. {
  1004. std::string obj = *oi;
  1005. this->WriteString("<Object Include=\"", 2);
  1006. this->ConvertToWindowsSlash(obj);
  1007. (*this->BuildFileStream ) << cmVS10EscapeXML(obj) << "\">\n";
  1008. this->WriteString("<Filter>Object Libraries</Filter>\n", 3);
  1009. this->WriteString("</Object>\n", 2);
  1010. }
  1011. this->WriteString("</ItemGroup>\n", 1);
  1012. }
  1013. this->WriteString("<ItemGroup>\n", 1);
  1014. for(std::set<cmSourceGroup*>::iterator g = groupsUsed.begin();
  1015. g != groupsUsed.end(); ++g)
  1016. {
  1017. cmSourceGroup* sg = *g;
  1018. const char* name = sg->GetFullName();
  1019. if(strlen(name) != 0)
  1020. {
  1021. this->WriteString("<Filter Include=\"", 2);
  1022. (*this->BuildFileStream) << name << "\">\n";
  1023. std::string guidName = "SG_Filter_";
  1024. guidName += name;
  1025. this->GlobalGenerator->CreateGUID(guidName.c_str());
  1026. this->WriteString("<UniqueIdentifier>", 3);
  1027. std::string guid
  1028. = this->GlobalGenerator->GetGUID(guidName.c_str());
  1029. (*this->BuildFileStream)
  1030. << "{"
  1031. << guid << "}"
  1032. << "</UniqueIdentifier>\n";
  1033. this->WriteString("</Filter>\n", 2);
  1034. }
  1035. }
  1036. if(!objs.empty())
  1037. {
  1038. this->WriteString("<Filter Include=\"Object Libraries\">\n", 2);
  1039. std::string guidName = "SG_Filter_Object Libraries";
  1040. this->GlobalGenerator->CreateGUID(guidName.c_str());
  1041. this->WriteString("<UniqueIdentifier>", 3);
  1042. std::string guid =
  1043. this->GlobalGenerator->GetGUID(guidName.c_str());
  1044. (*this->BuildFileStream) << "{" << guid << "}"
  1045. << "</UniqueIdentifier>\n";
  1046. this->WriteString("</Filter>\n", 2);
  1047. }
  1048. if(!resxObjs.empty() || !this->AddedFiles.empty())
  1049. {
  1050. this->WriteString("<Filter Include=\"Resource Files\">\n", 2);
  1051. std::string guidName = "SG_Filter_Resource Files";
  1052. this->GlobalGenerator->CreateGUID(guidName.c_str());
  1053. this->WriteString("<UniqueIdentifier>", 3);
  1054. std::string guid =
  1055. this->GlobalGenerator->GetGUID(guidName.c_str());
  1056. (*this->BuildFileStream) << "{" << guid << "}"
  1057. << "</UniqueIdentifier>\n";
  1058. this->WriteString("<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;", 3);
  1059. (*this->BuildFileStream) << "gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;";
  1060. (*this->BuildFileStream) << "mfcribbon-ms</Extensions>\n";
  1061. this->WriteString("</Filter>\n", 2);
  1062. }
  1063. this->WriteString("</ItemGroup>\n", 1);
  1064. this->WriteString("</Project>\n", 0);
  1065. // restore stream pointer
  1066. this->BuildFileStream = save;
  1067. if (fout.Close())
  1068. {
  1069. this->GlobalGenerator->FileReplacedDuringGenerate(path);
  1070. }
  1071. }
  1072. // Add to groupsUsed empty source groups that have non-empty children.
  1073. void
  1074. cmVisualStudio10TargetGenerator::AddMissingSourceGroups(
  1075. std::set<cmSourceGroup*>& groupsUsed,
  1076. const std::vector<cmSourceGroup>& allGroups
  1077. )
  1078. {
  1079. for(std::vector<cmSourceGroup>::const_iterator current = allGroups.begin();
  1080. current != allGroups.end(); ++current)
  1081. {
  1082. std::vector<cmSourceGroup> const& children = current->GetGroupChildren();
  1083. if(children.empty())
  1084. {
  1085. continue; // the group is really empty
  1086. }
  1087. this->AddMissingSourceGroups(groupsUsed, children);
  1088. cmSourceGroup* current_ptr = const_cast<cmSourceGroup*>(&(*current));
  1089. if(groupsUsed.find(current_ptr) != groupsUsed.end())
  1090. {
  1091. continue; // group has already been added to set
  1092. }
  1093. // check if it least one of the group's descendants is not empty
  1094. // (at least one child must already have been added)
  1095. std::vector<cmSourceGroup>::const_iterator child_it = children.begin();
  1096. while(child_it != children.end())
  1097. {
  1098. cmSourceGroup* child_ptr = const_cast<cmSourceGroup*>(&(*child_it));
  1099. if(groupsUsed.find(child_ptr) != groupsUsed.end())
  1100. {
  1101. break; // found a child that was already added => add current group too
  1102. }
  1103. child_it++;
  1104. }
  1105. if(child_it == children.end())
  1106. {
  1107. continue; // no descendants have source files => ignore this group
  1108. }
  1109. groupsUsed.insert(current_ptr);
  1110. }
  1111. }
  1112. void
  1113. cmVisualStudio10TargetGenerator::
  1114. WriteGroupSources(const char* name,
  1115. ToolSources const& sources,
  1116. std::vector<cmSourceGroup>& sourceGroups)
  1117. {
  1118. this->WriteString("<ItemGroup>\n", 1);
  1119. for(ToolSources::const_iterator s = sources.begin();
  1120. s != sources.end(); ++s)
  1121. {
  1122. cmSourceFile const* sf = s->SourceFile;
  1123. std::string const& source = sf->GetFullPath();
  1124. cmSourceGroup* sourceGroup =
  1125. this->Makefile->FindSourceGroup(source.c_str(), sourceGroups);
  1126. const char* filter = sourceGroup->GetFullName();
  1127. this->WriteString("<", 2);
  1128. std::string path = this->ConvertPath(source, s->RelativePath);
  1129. this->ConvertToWindowsSlash(path);
  1130. (*this->BuildFileStream) << name << " Include=\""
  1131. << cmVS10EscapeXML(path);
  1132. if(strlen(filter))
  1133. {
  1134. (*this->BuildFileStream) << "\">\n";
  1135. this->WriteString("<Filter>", 3);
  1136. (*this->BuildFileStream) << filter << "</Filter>\n";
  1137. this->WriteString("</", 2);
  1138. (*this->BuildFileStream) << name << ">\n";
  1139. }
  1140. else
  1141. {
  1142. (*this->BuildFileStream) << "\" />\n";
  1143. }
  1144. }
  1145. this->WriteString("</ItemGroup>\n", 1);
  1146. }
  1147. void cmVisualStudio10TargetGenerator::WriteHeaderSource(cmSourceFile const* sf)
  1148. {
  1149. std::string const& fileName = sf->GetFullPath();
  1150. if (this->IsResxHeader(fileName))
  1151. {
  1152. this->WriteSource("ClInclude", sf, ">\n");
  1153. this->WriteString("<FileType>CppForm</FileType>\n", 3);
  1154. this->WriteString("</ClInclude>\n", 2);
  1155. }
  1156. else if (this->IsXamlHeader(fileName))
  1157. {
  1158. this->WriteSource("ClInclude", sf, ">\n");
  1159. this->WriteString("<DependentUpon>", 3);
  1160. std::string xamlFileName = fileName.substr(0, fileName.find_last_of("."));
  1161. (*this->BuildFileStream) << xamlFileName << "</DependentUpon>\n";
  1162. this->WriteString("</ClInclude>\n", 2);
  1163. }
  1164. else
  1165. {
  1166. this->WriteSource("ClInclude", sf);
  1167. }
  1168. }
  1169. void cmVisualStudio10TargetGenerator::WriteExtraSource(cmSourceFile const* sf)
  1170. {
  1171. bool toolHasSettings = false;
  1172. std::string tool = "None";
  1173. std::string shaderType;
  1174. std::string shaderEntryPoint;
  1175. std::string shaderModel;
  1176. std::string shaderAdditionalFlags;
  1177. std::string ext = cmSystemTools::LowerCase(sf->GetExtension());
  1178. if(ext == "hlsl")
  1179. {
  1180. tool = "FXCompile";
  1181. // Figure out the type of shader compiler to use.
  1182. if(const char* st = sf->GetProperty("VS_SHADER_TYPE"))
  1183. {
  1184. shaderType = st;
  1185. toolHasSettings = true;
  1186. }
  1187. // Figure out which entry point to use if any
  1188. if (const char* se = sf->GetProperty("VS_SHADER_ENTRYPOINT"))
  1189. {
  1190. shaderEntryPoint = se;
  1191. toolHasSettings = true;
  1192. }
  1193. // Figure out which shader model to use if any
  1194. if (const char* sm = sf->GetProperty("VS_SHADER_MODEL"))
  1195. {
  1196. shaderModel = sm;
  1197. toolHasSettings = true;
  1198. }
  1199. // Figure out if there's any additional flags to use
  1200. if (const char* saf = sf->GetProperty("VS_SHADER_FLAGS"))
  1201. {
  1202. shaderAdditionalFlags = saf;
  1203. toolHasSettings = true;
  1204. }
  1205. }
  1206. else if(ext == "jpg" ||
  1207. ext == "png")
  1208. {
  1209. tool = "Image";
  1210. }
  1211. else if(ext == "xml")
  1212. {
  1213. tool = "XML";
  1214. }
  1215. if(this->NsightTegra)
  1216. {
  1217. // Nsight Tegra needs specific file types to check up-to-dateness.
  1218. std::string name =
  1219. cmSystemTools::LowerCase(sf->GetLocation().GetName());
  1220. if(name == "androidmanifest.xml" ||
  1221. name == "build.xml" ||
  1222. name == "proguard.cfg" ||
  1223. name == "proguard-project.txt" ||
  1224. ext == "properties")
  1225. {
  1226. tool = "AndroidBuild";
  1227. }
  1228. else if(ext == "java")
  1229. {
  1230. tool = "JCompile";
  1231. }
  1232. else if(ext == "asm" || ext == "s")
  1233. {
  1234. tool = "ClCompile";
  1235. }
  1236. }
  1237. std::string deployContent;
  1238. std::string deployLocation;
  1239. if(this->GlobalGenerator->TargetsWindowsPhone() ||
  1240. this->GlobalGenerator->TargetsWindowsStore())
  1241. {
  1242. const char* content = sf->GetProperty("VS_DEPLOYMENT_CONTENT");
  1243. if(content && *content)
  1244. {
  1245. toolHasSettings = true;
  1246. deployContent = content;
  1247. const char* location = sf->GetProperty("VS_DEPLOYMENT_LOCATION");
  1248. if(location && *location)
  1249. {
  1250. deployLocation = location;
  1251. }
  1252. }
  1253. }
  1254. if(toolHasSettings)
  1255. {
  1256. this->WriteSource(tool, sf, ">\n");
  1257. if(!deployContent.empty())
  1258. {
  1259. std::vector<std::string> const* configs =
  1260. this->GlobalGenerator->GetConfigurations();
  1261. cmGeneratorExpression ge;
  1262. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
  1263. ge.Parse(deployContent);
  1264. // Deployment location cannot be set on a configuration basis
  1265. if(!deployLocation.empty())
  1266. {
  1267. this->WriteString("<Link>", 3);
  1268. (*this->BuildFileStream) << deployLocation
  1269. << "\\%(FileName)%(Extension)";
  1270. this->WriteString("</Link>\n", 0);
  1271. }
  1272. for(size_t i = 0; i != configs->size(); ++i)
  1273. {
  1274. if(0 == strcmp(cge->Evaluate(this->Makefile, (*configs)[i]), "1"))
  1275. {
  1276. this->WriteString("<DeploymentContent Condition=\""
  1277. "'$(Configuration)|$(Platform)'=='", 3);
  1278. (*this->BuildFileStream) << (*configs)[i] << "|"
  1279. << this->Platform << "'\">true";
  1280. this->WriteString("</DeploymentContent>\n", 0);
  1281. }
  1282. else
  1283. {
  1284. this->WriteString("<ExcludedFromBuild Condition=\""
  1285. "'$(Configuration)|$(Platform)'=='", 3);
  1286. (*this->BuildFileStream) << (*configs)[i] << "|"
  1287. << this->Platform << "'\">true";
  1288. this->WriteString("</ExcludedFromBuild>\n", 0);
  1289. }
  1290. }
  1291. }
  1292. if(!shaderType.empty())
  1293. {
  1294. this->WriteString("<ShaderType>", 3);
  1295. (*this->BuildFileStream) << cmVS10EscapeXML(shaderType)
  1296. << "</ShaderType>\n";
  1297. }
  1298. if(!shaderEntryPoint.empty())
  1299. {
  1300. this->WriteString("<EntryPointName>", 3);
  1301. (*this->BuildFileStream) << cmVS10EscapeXML(shaderEntryPoint)
  1302. << "</EntryPointName>\n";
  1303. }
  1304. if(!shaderModel.empty())
  1305. {
  1306. this->WriteString("<ShaderModel>", 3);
  1307. (*this->BuildFileStream) << cmVS10EscapeXML(shaderModel)
  1308. << "</ShaderModel>\n";
  1309. }
  1310. if(!shaderAdditionalFlags.empty())
  1311. {
  1312. this->WriteString("<AdditionalOptions>", 3);
  1313. (*this->BuildFileStream) << cmVS10EscapeXML(shaderAdditionalFlags)
  1314. << "</AdditionalOptions>\n";
  1315. }
  1316. this->WriteString("</", 2);
  1317. (*this->BuildFileStream) << tool << ">\n";
  1318. }
  1319. else
  1320. {
  1321. this->WriteSource(tool, sf);
  1322. }
  1323. }
  1324. void cmVisualStudio10TargetGenerator::WriteSource(
  1325. std::string const& tool, cmSourceFile const* sf, const char* end)
  1326. {
  1327. // Visual Studio tools append relative paths to the current dir, as in:
  1328. //
  1329. // c:\path\to\current\dir\..\..\..\relative\path\to\source.c
  1330. //
  1331. // and fail if this exceeds the maximum allowed path length. Our path
  1332. // conversion uses full paths when possible to allow deeper trees.
  1333. bool forceRelative = false;
  1334. std::string sourceFile = this->ConvertPath(sf->GetFullPath(), false);
  1335. if(this->LocalGenerator->GetVersion() == cmLocalVisualStudioGenerator::VS10
  1336. && cmSystemTools::FileIsFullPath(sourceFile.c_str()))
  1337. {
  1338. // Normal path conversion resulted in a full path. VS 10 (but not 11)
  1339. // refuses to show the property page in the IDE for a source file with a
  1340. // full path (not starting in a '.' or '/' AFAICT). CMake <= 2.8.4 used a
  1341. // relative path but to allow deeper build trees CMake 2.8.[5678] used a
  1342. // full path except for custom commands. Custom commands do not work
  1343. // without a relative path, but they do not seem to be involved in tools
  1344. // with the above behavior. For other sources we now use a relative path
  1345. // when the combined path will not be too long so property pages appear.
  1346. std::string sourceRel = this->ConvertPath(sf->GetFullPath(), true);
  1347. size_t const maxLen = 250;
  1348. if(sf->GetCustomCommand() ||
  1349. ((strlen(this->Makefile->GetCurrentOutputDirectory()) + 1 +
  1350. sourceRel.length()) <= maxLen))
  1351. {
  1352. forceRelative = true;
  1353. sourceFile = sourceRel;
  1354. }
  1355. else
  1356. {
  1357. this->GlobalGenerator->PathTooLong(this->Target, sf, sourceRel);
  1358. }
  1359. }
  1360. this->ConvertToWindowsSlash(sourceFile);
  1361. this->WriteString("<", 2);
  1362. (*this->BuildFileStream ) << tool << " Include=\""
  1363. << cmVS10EscapeXML(sourceFile) << "\""
  1364. << (end? end : " />\n");
  1365. ToolSource toolSource = {sf, forceRelative};
  1366. this->Tools[tool].push_back(toolSource);
  1367. }
  1368. void cmVisualStudio10TargetGenerator::WriteSources(
  1369. std::string const& tool, std::vector<cmSourceFile const*> const& sources)
  1370. {
  1371. for(std::vector<cmSourceFile const*>::const_iterator
  1372. si = sources.begin(); si != sources.end(); ++si)
  1373. {
  1374. this->WriteSource(tool, *si);
  1375. }
  1376. }
  1377. void cmVisualStudio10TargetGenerator::WriteAllSources()
  1378. {
  1379. if(this->Target->GetType() > cmTarget::UTILITY)
  1380. {
  1381. return;
  1382. }
  1383. this->WriteString("<ItemGroup>\n", 1);
  1384. std::vector<cmSourceFile const*> headerSources;
  1385. this->GeneratorTarget->GetHeaderSources(headerSources, "");
  1386. for(std::vector<cmSourceFile const*>::const_iterator
  1387. si = headerSources.begin(); si != headerSources.end(); ++si)
  1388. {
  1389. this->WriteHeaderSource(*si);
  1390. }
  1391. std::vector<cmSourceFile const*> idlSources;
  1392. this->GeneratorTarget->GetIDLSources(idlSources, "");
  1393. this->WriteSources("Midl", idlSources);
  1394. std::vector<cmSourceFile const*> objectSources;
  1395. this->GeneratorTarget->GetObjectSources(objectSources, "");
  1396. for(std::vector<cmSourceFile const*>::const_iterator
  1397. si = objectSources.begin();
  1398. si != objectSources.end(); ++si)
  1399. {
  1400. const std::string& lang = (*si)->GetLanguage();
  1401. std::string tool;
  1402. if (lang == "C"|| lang == "CXX")
  1403. {
  1404. tool = "ClCompile";
  1405. }
  1406. else if (lang == "ASM_MASM" &&
  1407. this->GlobalGenerator->IsMasmEnabled())
  1408. {
  1409. tool = "MASM";
  1410. }
  1411. else if (lang == "RC")
  1412. {
  1413. tool = "ResourceCompile";
  1414. }
  1415. if (!tool.empty())
  1416. {
  1417. this->WriteSource(tool, *si, " ");
  1418. if (this->OutputSourceSpecificFlags(*si))
  1419. {
  1420. this->WriteString("</", 2);
  1421. (*this->BuildFileStream ) << tool << ">\n";
  1422. }
  1423. else
  1424. {
  1425. (*this->BuildFileStream ) << " />\n";
  1426. }
  1427. }
  1428. else
  1429. {
  1430. this->WriteSource("None", *si);
  1431. }
  1432. }
  1433. std::vector<cmSourceFile const*> manifestSources;
  1434. this->GeneratorTarget->GetAppManifest(manifestSources, "");
  1435. this->WriteSources("AppxManifest", manifestSources);
  1436. std::vector<cmSourceFile const*> certificateSources;
  1437. this->GeneratorTarget->GetCertificates(certificateSources, "");
  1438. this->WriteSources("None", certificateSources);
  1439. std::vector<cmSourceFile const*> externalObjects;
  1440. this->GeneratorTarget->GetExternalObjects(externalObjects, "");
  1441. for(std::vector<cmSourceFile const*>::iterator
  1442. si = externalObjects.begin();
  1443. si != externalObjects.end(); )
  1444. {
  1445. if (!(*si)->GetObjectLibrary().empty())
  1446. {
  1447. si = externalObjects.erase(si);
  1448. }
  1449. else
  1450. {
  1451. ++si;
  1452. }
  1453. }
  1454. if(this->LocalGenerator->GetVersion() > cmLocalVisualStudioGenerator::VS10)
  1455. {
  1456. // For VS >= 11 we use LinkObjects to avoid linking custom command
  1457. // outputs. Use Object for all external objects, generated or not.
  1458. this->WriteSources("Object", externalObjects);
  1459. }
  1460. else
  1461. {
  1462. // If an object file is generated in this target, then vs10 will use
  1463. // it in the build, and we have to list it as None instead of Object.
  1464. for(std::vector<cmSourceFile const*>::const_iterator
  1465. si = externalObjects.begin();
  1466. si != externalObjects.end(); ++si)
  1467. {
  1468. std::vector<cmSourceFile*> const* d =
  1469. this->GeneratorTarget->GetSourceDepends(*si);
  1470. this->WriteSource((d && !d->empty())? "None":"Object", *si);
  1471. }
  1472. }
  1473. std::vector<cmSourceFile const*> extraSources;
  1474. this->GeneratorTarget->GetExtraSources(extraSources, "");
  1475. for(std::vector<cmSourceFile const*>::const_iterator
  1476. si = extraSources.begin(); si != extraSources.end(); ++si)
  1477. {
  1478. this->WriteExtraSource(*si);
  1479. }
  1480. // Add object library contents as external objects.
  1481. std::vector<std::string> objs;
  1482. this->GeneratorTarget->UseObjectLibraries(objs, "");
  1483. for(std::vector<std::string>::const_iterator
  1484. oi = objs.begin(); oi != objs.end(); ++oi)
  1485. {
  1486. std::string obj = *oi;
  1487. this->WriteString("<Object Include=\"", 2);
  1488. this->ConvertToWindowsSlash(obj);
  1489. (*this->BuildFileStream ) << cmVS10EscapeXML(obj) << "\" />\n";
  1490. }
  1491. if (this->IsMissingFiles)
  1492. {
  1493. this->WriteMissingFiles();
  1494. }
  1495. this->WriteString("</ItemGroup>\n", 1);
  1496. }
  1497. bool cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags(
  1498. cmSourceFile const* source)
  1499. {
  1500. cmSourceFile const& sf = *source;
  1501. std::string objectName;
  1502. if(this->GeneratorTarget->HasExplicitObjectName(&sf))
  1503. {
  1504. objectName = this->GeneratorTarget->GetObjectName(&sf);
  1505. }
  1506. std::string flags;
  1507. std::string defines;
  1508. if(const char* cflags = sf.GetProperty("COMPILE_FLAGS"))
  1509. {
  1510. flags += cflags;
  1511. }
  1512. if(const char* cdefs = sf.GetProperty("COMPILE_DEFINITIONS"))
  1513. {
  1514. defines += cdefs;
  1515. }
  1516. std::string lang =
  1517. this->GlobalGenerator->GetLanguageFromExtension
  1518. (sf.GetExtension().c_str());
  1519. std::string sourceLang = this->LocalGenerator->GetSourceFileLanguage(sf);
  1520. const std::string& linkLanguage = this->Target->GetLinkerLanguage();
  1521. bool needForceLang = false;
  1522. // source file does not match its extension language
  1523. if(lang != sourceLang)
  1524. {
  1525. needForceLang = true;
  1526. lang = sourceLang;
  1527. }
  1528. // if the source file does not match the linker language
  1529. // then force c or c++
  1530. const char* compileAs = 0;
  1531. if(needForceLang || (linkLanguage != lang))
  1532. {
  1533. if(lang == "CXX")
  1534. {
  1535. // force a C++ file type
  1536. compileAs = "CompileAsCpp";
  1537. }
  1538. else if(lang == "C")
  1539. {
  1540. // force to c
  1541. compileAs = "CompileAsC";
  1542. }
  1543. }
  1544. bool noWinRT = this->TargetCompileAsWinRT && lang == "C";
  1545. bool hasFlags = false;
  1546. // for the first time we need a new line if there is something
  1547. // produced here.
  1548. const char* firstString = ">\n";
  1549. if(objectName.size())
  1550. {
  1551. (*this->BuildFileStream ) << firstString;
  1552. firstString = "";
  1553. hasFlags = true;
  1554. this->WriteString("<ObjectFileName>", 3);
  1555. (*this->BuildFileStream )
  1556. << "$(IntDir)/" << objectName << "</ObjectFileName>\n";
  1557. }
  1558. std::vector<std::string> *configs =
  1559. static_cast<cmGlobalVisualStudio7Generator *>
  1560. (this->GlobalGenerator)->GetConfigurations();
  1561. for( std::vector<std::string>::iterator config = configs->begin();
  1562. config != configs->end(); ++config)
  1563. {
  1564. std::string configUpper = cmSystemTools::UpperCase(*config);
  1565. std::string configDefines = defines;
  1566. std::string defPropName = "COMPILE_DEFINITIONS_";
  1567. defPropName += configUpper;
  1568. if(const char* ccdefs = sf.GetProperty(defPropName.c_str()))
  1569. {
  1570. if(configDefines.size())
  1571. {
  1572. configDefines += ";";
  1573. }
  1574. configDefines += ccdefs;
  1575. }
  1576. // if we have flags or defines for this config then
  1577. // use them
  1578. if(!flags.empty() || !configDefines.empty() || compileAs || noWinRT)
  1579. {
  1580. (*this->BuildFileStream ) << firstString;
  1581. firstString = ""; // only do firstString once
  1582. hasFlags = true;
  1583. cmVisualStudioGeneratorOptions
  1584. clOptions(this->LocalGenerator,
  1585. cmVisualStudioGeneratorOptions::Compiler,
  1586. this->GetClFlagTable(), 0, this);
  1587. if(compileAs)
  1588. {
  1589. clOptions.AddFlag("CompileAs", compileAs);
  1590. }
  1591. if(noWinRT)
  1592. {
  1593. clOptions.AddFlag("CompileAsWinRT", "false");
  1594. }
  1595. clOptions.Parse(flags.c_str());
  1596. if(clOptions.HasFlag("AdditionalIncludeDirectories"))
  1597. {
  1598. clOptions.AppendFlag("AdditionalIncludeDirectories",
  1599. "%(AdditionalIncludeDirectories)");
  1600. }
  1601. if(clOptions.HasFlag("DisableSpecificWarnings"))
  1602. {
  1603. clOptions.AppendFlag("DisableSpecificWarnings",
  1604. "%(DisableSpecificWarnings)");
  1605. }
  1606. clOptions.AddDefines(configDefines.c_str());
  1607. clOptions.SetConfiguration((*config).c_str());
  1608. clOptions.OutputAdditionalOptions(*this->BuildFileStream, " ", "");
  1609. clOptions.OutputFlagMap(*this->BuildFileStream, " ");
  1610. clOptions.OutputPreprocessorDefinitions(*this->BuildFileStream,
  1611. " ", "\n", lang);
  1612. }
  1613. }
  1614. if (this->IsXamlSource(source->GetFullPath()))
  1615. {
  1616. (*this->BuildFileStream) << firstString;
  1617. firstString = ""; // only do firstString once
  1618. hasFlags = true;
  1619. this->WriteString("<DependentUpon>", 3);
  1620. const std::string& fileName = source->GetFullPath();
  1621. std::string xamlFileName = fileName.substr(0, fileName.find_last_of("."));
  1622. (*this->BuildFileStream) << xamlFileName << "</DependentUpon>\n";
  1623. }
  1624. return hasFlags;
  1625. }
  1626. void cmVisualStudio10TargetGenerator::WritePathAndIncrementalLinkOptions()
  1627. {
  1628. cmTarget::TargetType ttype = this->Target->GetType();
  1629. if(ttype > cmTarget::GLOBAL_TARGET)
  1630. {
  1631. return;
  1632. }
  1633. this->WriteString("<PropertyGroup>\n", 2);
  1634. this->WriteString("<_ProjectFileVersion>10.0.20506.1"
  1635. "</_ProjectFileVersion>\n", 3);
  1636. std::vector<std::string> *configs =
  1637. static_cast<cmGlobalVisualStudio7Generator *>
  1638. (this->GlobalGenerator)->GetConfigurations();
  1639. for(std::vector<std::string>::iterator config = configs->begin();
  1640. config != configs->end(); ++config)
  1641. {
  1642. if(ttype >= cmTarget::UTILITY)
  1643. {
  1644. this->WritePlatformConfigTag("IntDir", config->c_str(), 3);
  1645. *this->BuildFileStream
  1646. << "$(Platform)\\$(Configuration)\\$(ProjectName)\\"
  1647. << "</IntDir>\n";
  1648. }
  1649. else
  1650. {
  1651. std::string intermediateDir = this->LocalGenerator->
  1652. GetTargetDirectory(*this->Target);
  1653. intermediateDir += "/";
  1654. intermediateDir += *config;
  1655. intermediateDir += "/";
  1656. std::string outDir;
  1657. std::string targetNameFull;
  1658. if(ttype == cmTarget::OBJECT_LIBRARY)
  1659. {
  1660. outDir = intermediateDir;
  1661. targetNameFull = this->Target->GetName();
  1662. targetNameFull += ".lib";
  1663. }
  1664. else
  1665. {
  1666. outDir = this->Target->GetDirectory(config->c_str()) + "/";
  1667. targetNameFull = this->Target->GetFullName(config->c_str());
  1668. }
  1669. this->ConvertToWindowsSlash(intermediateDir);
  1670. this->ConvertToWindowsSlash(outDir);
  1671. this->WritePlatformConfigTag("OutDir", config->c_str(), 3);
  1672. *this->BuildFileStream << cmVS10EscapeXML(outDir)
  1673. << "</OutDir>\n";
  1674. this->WritePlatformConfigTag("IntDir", config->c_str(), 3);
  1675. *this->BuildFileStream << cmVS10EscapeXML(intermediateDir)
  1676. << "</IntDir>\n";
  1677. std::string name =
  1678. cmSystemTools::GetFilenameWithoutLastExtension(targetNameFull);
  1679. this->WritePlatformConfigTag("TargetName", config->c_str(), 3);
  1680. *this->BuildFileStream << cmVS10EscapeXML(name) << "</TargetName>\n";
  1681. std::string ext =
  1682. cmSystemTools::GetFilenameLastExtension(targetNameFull);
  1683. if(ext.empty())
  1684. {
  1685. // An empty TargetExt causes a default extension to be used.
  1686. // A single "." appears to be treated as an empty extension.
  1687. ext = ".";
  1688. }
  1689. this->WritePlatformConfigTag("TargetExt", config->c_str(), 3);
  1690. *this->BuildFileStream << cmVS10EscapeXML(ext) << "</TargetExt>\n";
  1691. this->OutputLinkIncremental(*config);
  1692. }
  1693. }
  1694. this->WriteString("</PropertyGroup>\n", 2);
  1695. }
  1696. void
  1697. cmVisualStudio10TargetGenerator::
  1698. OutputLinkIncremental(std::string const& configName)
  1699. {
  1700. if(!this->MSTools)
  1701. {
  1702. return;
  1703. }
  1704. // static libraries and things greater than modules do not need
  1705. // to set this option
  1706. if(this->Target->GetType() == cmTarget::STATIC_LIBRARY
  1707. || this->Target->GetType() > cmTarget::MODULE_LIBRARY)
  1708. {
  1709. return;
  1710. }
  1711. Options& linkOptions = *(this->LinkOptions[configName]);
  1712. const char* incremental = linkOptions.GetFlag("LinkIncremental");
  1713. this->WritePlatformConfigTag("LinkIncremental", configName.c_str(), 3);
  1714. *this->BuildFileStream << (incremental?incremental:"true")
  1715. << "</LinkIncremental>\n";
  1716. linkOptions.RemoveFlag("LinkIncremental");
  1717. const char* manifest = linkOptions.GetFlag("GenerateManifest");
  1718. this->WritePlatformConfigTag("GenerateManifest", configName.c_str(), 3);
  1719. *this->BuildFileStream << (manifest?manifest:"true")
  1720. << "</GenerateManifest>\n";
  1721. linkOptions.RemoveFlag("GenerateManifest");
  1722. // Some link options belong here. Use them now and remove them so that
  1723. // WriteLinkOptions does not use them.
  1724. const char* flags[] = {
  1725. "LinkDelaySign",
  1726. "LinkKeyFile",
  1727. 0};
  1728. for(const char** f = flags; *f; ++f)
  1729. {
  1730. const char* flag = *f;
  1731. if(const char* value = linkOptions.GetFlag(flag))
  1732. {
  1733. this->WritePlatformConfigTag(flag, configName.c_str(), 3);
  1734. *this->BuildFileStream << value << "</" << flag << ">\n";
  1735. linkOptions.RemoveFlag(flag);
  1736. }
  1737. }
  1738. }
  1739. //----------------------------------------------------------------------------
  1740. bool cmVisualStudio10TargetGenerator::ComputeClOptions()
  1741. {
  1742. std::vector<std::string> const* configs =
  1743. this->GlobalGenerator->GetConfigurations();
  1744. for(std::vector<std::string>::const_iterator i = configs->begin();
  1745. i != configs->end(); ++i)
  1746. {
  1747. if(!this->ComputeClOptions(*i))
  1748. {
  1749. return false;
  1750. }
  1751. }
  1752. return true;
  1753. }
  1754. //----------------------------------------------------------------------------
  1755. bool cmVisualStudio10TargetGenerator::ComputeClOptions(
  1756. std::string const& configName)
  1757. {
  1758. // much of this was copied from here:
  1759. // copied from cmLocalVisualStudio7Generator.cxx 805
  1760. // TODO: Integrate code below with cmLocalVisualStudio7Generator.
  1761. cmsys::auto_ptr<Options> pOptions(
  1762. new Options(this->LocalGenerator, Options::Compiler,
  1763. this->GetClFlagTable()));
  1764. Options& clOptions = *pOptions;
  1765. std::string flags;
  1766. const std::string& linkLanguage =
  1767. this->Target->GetLinkerLanguage(configName.c_str());
  1768. if(linkLanguage.empty())
  1769. {
  1770. cmSystemTools::Error
  1771. ("CMake can not determine linker language for target: ",
  1772. this->Name.c_str());
  1773. return false;
  1774. }
  1775. if(linkLanguage == "C" || linkLanguage == "CXX"
  1776. || linkLanguage == "Fortran")
  1777. {
  1778. std::string baseFlagVar = "CMAKE_";
  1779. baseFlagVar += linkLanguage;
  1780. baseFlagVar += "_FLAGS";
  1781. flags = this->
  1782. Target->GetMakefile()->GetRequiredDefinition(baseFlagVar.c_str());
  1783. std::string flagVar = baseFlagVar + std::string("_") +
  1784. cmSystemTools::UpperCase(configName);
  1785. flags += " ";
  1786. flags += this->
  1787. Target->GetMakefile()->GetRequiredDefinition(flagVar.c_str());
  1788. }
  1789. // set the correct language
  1790. if(linkLanguage == "C")
  1791. {
  1792. clOptions.AddFlag("CompileAs", "CompileAsC");
  1793. }
  1794. if(linkLanguage == "CXX")
  1795. {
  1796. clOptions.AddFlag("CompileAs", "CompileAsCpp");
  1797. }
  1798. this->LocalGenerator->AddCompileOptions(flags, this->Target,
  1799. linkLanguage, configName.c_str());
  1800. // Get preprocessor definitions for this directory.
  1801. std::string defineFlags = this->Target->GetMakefile()->GetDefineFlags();
  1802. if(this->MSTools)
  1803. {
  1804. clOptions.FixExceptionHandlingDefault();
  1805. clOptions.AddFlag("PrecompiledHeader", "NotUsing");
  1806. std::string asmLocation = configName + "/";
  1807. clOptions.AddFlag("AssemblerListingLocation", asmLocation.c_str());
  1808. }
  1809. clOptions.Parse(flags.c_str());
  1810. clOptions.Parse(defineFlags.c_str());
  1811. std::vector<std::string> targetDefines;
  1812. this->Target->GetCompileDefinitions(targetDefines,
  1813. configName.c_str(), "CXX");
  1814. clOptions.AddDefines(targetDefines);
  1815. if(this->MSTools)
  1816. {
  1817. clOptions.SetVerboseMakefile(
  1818. this->Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE"));
  1819. }
  1820. // Add a definition for the configuration name.
  1821. std::string configDefine = "CMAKE_INTDIR=\"";
  1822. configDefine += configName;
  1823. configDefine += "\"";
  1824. clOptions.AddDefine(configDefine);
  1825. if(const char* exportMacro = this->Target->GetExportMacro())
  1826. {
  1827. clOptions.AddDefine(exportMacro);
  1828. }
  1829. if (this->MSTools)
  1830. {
  1831. // If we have the VS_WINRT_COMPONENT set then force Compile as WinRT.
  1832. if (this->Target->GetPropertyAsBool("VS_WINRT_COMPONENT"))
  1833. {
  1834. clOptions.AddFlag("CompileAsWinRT", "true");
  1835. // For WinRT components, add the _WINRT_DLL define to produce a lib
  1836. if (this->Target->GetType() == cmTarget::SHARED_LIBRARY ||
  1837. this->Target->GetType() == cmTarget::MODULE_LIBRARY )
  1838. {
  1839. clOptions.AddDefine("_WINRT_DLL");
  1840. }
  1841. }
  1842. else if (this->GlobalGenerator->TargetsWindowsStore() ||
  1843. this->GlobalGenerator->TargetsWindowsPhone())
  1844. {
  1845. if (!clOptions.IsWinRt())
  1846. {
  1847. clOptions.AddFlag("CompileAsWinRT", "false");
  1848. }
  1849. }
  1850. if(const char* winRT = clOptions.GetFlag("CompileAsWinRT"))
  1851. {
  1852. if(cmSystemTools::IsOn(winRT))
  1853. {
  1854. this->TargetCompileAsWinRT = true;
  1855. }
  1856. }
  1857. }
  1858. this->ClOptions[configName] = pOptions.release();
  1859. return true;
  1860. }
  1861. //----------------------------------------------------------------------------
  1862. void cmVisualStudio10TargetGenerator::WriteClOptions(
  1863. std::string const& configName,
  1864. std::vector<std::string> const& includes)
  1865. {
  1866. Options& clOptions = *(this->ClOptions[configName]);
  1867. this->WriteString("<ClCompile>\n", 2);
  1868. clOptions.OutputAdditionalOptions(*this->BuildFileStream, " ", "");
  1869. clOptions.AppendFlag("AdditionalIncludeDirectories", includes);
  1870. clOptions.AppendFlag("AdditionalIncludeDirectories",
  1871. "%(AdditionalIncludeDirectories)");
  1872. clOptions.OutputFlagMap(*this->BuildFileStream, " ");
  1873. clOptions.OutputPreprocessorDefinitions(*this->BuildFileStream, " ",
  1874. "\n", "CXX");
  1875. if(this->MSTools)
  1876. {
  1877. this->WriteString("<ObjectFileName>$(IntDir)</ObjectFileName>\n", 3);
  1878. // If not in debug mode, write the DebugInformationFormat field
  1879. // without value so PDBs don't get generated uselessly.
  1880. if(!clOptions.IsDebug())
  1881. {
  1882. this->WriteString("<DebugInformationFormat>"
  1883. "</DebugInformationFormat>\n", 3);
  1884. }
  1885. // Specify the compiler program database file if configured.
  1886. std::string pdb = this->Target->GetCompilePDBPath(configName.c_str());
  1887. if(!pdb.empty())
  1888. {
  1889. this->ConvertToWindowsSlash(pdb);
  1890. this->WriteString("<ProgramDataBaseFileName>", 3);
  1891. *this->BuildFileStream << cmVS10EscapeXML(pdb)
  1892. << "</ProgramDataBaseFileName>\n";
  1893. }
  1894. }
  1895. this->WriteString("</ClCompile>\n", 2);
  1896. }
  1897. //----------------------------------------------------------------------------
  1898. bool cmVisualStudio10TargetGenerator::ComputeRcOptions()
  1899. {
  1900. std::vector<std::string> const* configs =
  1901. this->GlobalGenerator->GetConfigurations();
  1902. for(std::vector<std::string>::const_iterator i = configs->begin();
  1903. i != configs->end(); ++i)
  1904. {
  1905. if(!this->ComputeRcOptions(*i))
  1906. {
  1907. return false;
  1908. }
  1909. }
  1910. return true;
  1911. }
  1912. //----------------------------------------------------------------------------
  1913. bool cmVisualStudio10TargetGenerator::ComputeRcOptions(
  1914. std::string const& configName)
  1915. {
  1916. cmsys::auto_ptr<Options> pOptions(
  1917. new Options(this->LocalGenerator, Options::ResourceCompiler,
  1918. this->GetRcFlagTable()));
  1919. Options& rcOptions = *pOptions;
  1920. std::string CONFIG = cmSystemTools::UpperCase(configName);
  1921. std::string rcConfigFlagsVar = std::string("CMAKE_RC_FLAGS_") + CONFIG;
  1922. std::string flags =
  1923. std::string(this->Makefile->GetSafeDefinition("CMAKE_RC_FLAGS")) +
  1924. std::string(" ") +
  1925. std::string(this->Makefile->GetSafeDefinition(rcConfigFlagsVar));
  1926. rcOptions.Parse(flags.c_str());
  1927. this->RcOptions[configName] = pOptions.release();
  1928. return true;
  1929. }
  1930. void cmVisualStudio10TargetGenerator::
  1931. WriteRCOptions(std::string const& configName,
  1932. std::vector<std::string> const & includes)
  1933. {
  1934. if(!this->MSTools)
  1935. {
  1936. return;
  1937. }
  1938. this->WriteString("<ResourceCompile>\n", 2);
  1939. // Preprocessor definitions and includes are shared with clOptions.
  1940. Options& clOptions = *(this->ClOptions[configName]);
  1941. clOptions.OutputPreprocessorDefinitions(*this->BuildFileStream, " ",
  1942. "\n", "RC");
  1943. Options& rcOptions = *(this->RcOptions[configName]);
  1944. rcOptions.AppendFlag("AdditionalIncludeDirectories", includes);
  1945. rcOptions.AppendFlag("AdditionalIncludeDirectories",
  1946. "%(AdditionalIncludeDirectories)");
  1947. rcOptions.OutputFlagMap(*this->BuildFileStream, " ");
  1948. rcOptions.OutputAdditionalOptions(*this->BuildFileStream, " ", "");
  1949. this->WriteString("</ResourceCompile>\n", 2);
  1950. }
  1951. //----------------------------------------------------------------------------
  1952. bool cmVisualStudio10TargetGenerator::ComputeMasmOptions()
  1953. {
  1954. if(!this->GlobalGenerator->IsMasmEnabled())
  1955. {
  1956. return true;
  1957. }
  1958. std::vector<std::string> const* configs =
  1959. this->GlobalGenerator->GetConfigurations();
  1960. for(std::vector<std::string>::const_iterator i = configs->begin();
  1961. i != configs->end(); ++i)
  1962. {
  1963. if(!this->ComputeMasmOptions(*i))
  1964. {
  1965. return false;
  1966. }
  1967. }
  1968. return true;
  1969. }
  1970. //----------------------------------------------------------------------------
  1971. bool cmVisualStudio10TargetGenerator::ComputeMasmOptions(
  1972. std::string const& configName)
  1973. {
  1974. cmsys::auto_ptr<Options> pOptions(
  1975. new Options(this->LocalGenerator, Options::MasmCompiler,
  1976. this->GetMasmFlagTable()));
  1977. Options& masmOptions = *pOptions;
  1978. std::string CONFIG = cmSystemTools::UpperCase(configName);
  1979. std::string configFlagsVar = std::string("CMAKE_ASM_MASM_FLAGS_") + CONFIG;
  1980. std::string flags =
  1981. std::string(this->Makefile->GetSafeDefinition("CMAKE_ASM_MASM_FLAGS")) +
  1982. std::string(" ") +
  1983. std::string(this->Makefile->GetSafeDefinition(configFlagsVar));
  1984. masmOptions.Parse(flags.c_str());
  1985. this->MasmOptions[configName] = pOptions.release();
  1986. return true;
  1987. }
  1988. void cmVisualStudio10TargetGenerator::
  1989. WriteMasmOptions(std::string const& configName,
  1990. std::vector<std::string> const& includes)
  1991. {
  1992. if(!this->MSTools || !this->GlobalGenerator->IsMasmEnabled())
  1993. {
  1994. return;
  1995. }
  1996. this->WriteString("<MASM>\n", 2);
  1997. // Preprocessor definitions and includes are shared with clOptions.
  1998. Options& clOptions = *(this->ClOptions[configName]);
  1999. clOptions.OutputPreprocessorDefinitions(*this->BuildFileStream, " ",
  2000. "\n", "ASM_MASM");
  2001. Options& masmOptions = *(this->MasmOptions[configName]);
  2002. masmOptions.AppendFlag("IncludePaths", includes);
  2003. masmOptions.AppendFlag("IncludePaths", "%(IncludePaths)");
  2004. masmOptions.OutputFlagMap(*this->BuildFileStream, " ");
  2005. masmOptions.OutputAdditionalOptions(*this->BuildFileStream, " ", "");
  2006. this->WriteString("</MASM>\n", 2);
  2007. }
  2008. void
  2009. cmVisualStudio10TargetGenerator::WriteLibOptions(std::string const& config)
  2010. {
  2011. if(this->Target->GetType() != cmTarget::STATIC_LIBRARY &&
  2012. this->Target->GetType() != cmTarget::OBJECT_LIBRARY)
  2013. {
  2014. return;
  2015. }
  2016. std::string libflags;
  2017. this->LocalGenerator->GetStaticLibraryFlags(libflags,
  2018. cmSystemTools::UpperCase(config), this->Target);
  2019. if(!libflags.empty())
  2020. {
  2021. this->WriteString("<Lib>\n", 2);
  2022. cmVisualStudioGeneratorOptions
  2023. libOptions(this->LocalGenerator,
  2024. cmVisualStudioGeneratorOptions::Linker,
  2025. this->GetLibFlagTable(), 0, this);
  2026. libOptions.Parse(libflags.c_str());
  2027. libOptions.OutputAdditionalOptions(*this->BuildFileStream, " ", "");
  2028. libOptions.OutputFlagMap(*this->BuildFileStream, " ");
  2029. this->WriteString("</Lib>\n", 2);
  2030. }
  2031. // We cannot generate metadata for static libraries. WindowsPhone
  2032. // and WindowsStore tools look at GenerateWindowsMetadata in the
  2033. // Link tool options even for static libraries.
  2034. if(this->GlobalGenerator->TargetsWindowsPhone() ||
  2035. this->GlobalGenerator->TargetsWindowsStore())
  2036. {
  2037. this->WriteString("<Link>\n", 2);
  2038. this->WriteString("<GenerateWindowsMetadata>false"
  2039. "</GenerateWindowsMetadata>\n", 3);
  2040. this->WriteString("</Link>\n", 2);
  2041. }
  2042. }
  2043. //----------------------------------------------------------------------------
  2044. void cmVisualStudio10TargetGenerator::WriteAntBuildOptions(
  2045. std::string const&)
  2046. {
  2047. // Look through the sources for AndroidManifest.xml and use
  2048. // its location as the root source directory.
  2049. std::string rootDir = this->Makefile->GetCurrentDirectory();
  2050. {
  2051. std::vector<cmSourceFile const*> extraSources;
  2052. this->GeneratorTarget->GetExtraSources(extraSources, "");
  2053. for(std::vector<cmSourceFile const*>::const_iterator si =
  2054. extraSources.begin(); si != extraSources.end(); ++si)
  2055. {
  2056. if("androidmanifest.xml" == cmSystemTools::LowerCase(
  2057. (*si)->GetLocation().GetName()))
  2058. {
  2059. rootDir = (*si)->GetLocation().GetDirectory();
  2060. break;
  2061. }
  2062. }
  2063. }
  2064. // Tell MSBuild to launch Ant.
  2065. {
  2066. std::string antBuildPath = rootDir;
  2067. this->WriteString("<AntBuild>\n", 2);
  2068. this->WriteString("<AntBuildPath>", 3);
  2069. this->ConvertToWindowsSlash(antBuildPath);
  2070. (*this->BuildFileStream) <<
  2071. cmVS10EscapeXML(antBuildPath) << "</AntBuildPath>\n";
  2072. }
  2073. {
  2074. std::string manifest_xml = rootDir + "/AndroidManifest.xml";
  2075. this->ConvertToWindowsSlash(manifest_xml);
  2076. this->WriteString("<AndroidManifestLocation>", 3);
  2077. (*this->BuildFileStream) <<
  2078. cmVS10EscapeXML(manifest_xml) << "</AndroidManifestLocation>\n";
  2079. }
  2080. this->WriteString("</AntBuild>\n", 2);
  2081. }
  2082. //----------------------------------------------------------------------------
  2083. bool cmVisualStudio10TargetGenerator::ComputeLinkOptions()
  2084. {
  2085. if(this->Target->GetType() == cmTarget::EXECUTABLE ||
  2086. this->Target->GetType() == cmTarget::SHARED_LIBRARY ||
  2087. this->Target->GetType() == cmTarget::MODULE_LIBRARY)
  2088. {
  2089. std::vector<std::string> const* configs =
  2090. this->GlobalGenerator->GetConfigurations();
  2091. for(std::vector<std::string>::const_iterator i = configs->begin();
  2092. i != configs->end(); ++i)
  2093. {
  2094. if(!this->ComputeLinkOptions(*i))
  2095. {
  2096. return false;
  2097. }
  2098. }
  2099. }
  2100. return true;
  2101. }
  2102. //----------------------------------------------------------------------------
  2103. bool
  2104. cmVisualStudio10TargetGenerator::ComputeLinkOptions(std::string const& config)
  2105. {
  2106. cmsys::auto_ptr<Options> pOptions(
  2107. new Options(this->LocalGenerator, Options::Linker,
  2108. this->GetLinkFlagTable(), 0, this));
  2109. Options& linkOptions = *pOptions;
  2110. const std::string& linkLanguage =
  2111. this->Target->GetLinkerLanguage(config.c_str());
  2112. if(linkLanguage.empty())
  2113. {
  2114. cmSystemTools::Error
  2115. ("CMake can not determine linker language for target: ",
  2116. this->Name.c_str());
  2117. return false;
  2118. }
  2119. std::string CONFIG = cmSystemTools::UpperCase(config);
  2120. const char* linkType = "SHARED";
  2121. if(this->Target->GetType() == cmTarget::MODULE_LIBRARY)
  2122. {
  2123. linkType = "MODULE";
  2124. }
  2125. if(this->Target->GetType() == cmTarget::EXECUTABLE)
  2126. {
  2127. linkType = "EXE";
  2128. }
  2129. std::string flags;
  2130. std::string linkFlagVarBase = "CMAKE_";
  2131. linkFlagVarBase += linkType;
  2132. linkFlagVarBase += "_LINKER_FLAGS";
  2133. flags += " ";
  2134. flags += this->
  2135. Target->GetMakefile()->GetRequiredDefinition(linkFlagVarBase.c_str());
  2136. std::string linkFlagVar = linkFlagVarBase + "_" + CONFIG;
  2137. flags += " ";
  2138. flags += this->
  2139. Target->GetMakefile()->GetRequiredDefinition(linkFlagVar.c_str());
  2140. const char* targetLinkFlags = this->Target->GetProperty("LINK_FLAGS");
  2141. if(targetLinkFlags)
  2142. {
  2143. flags += " ";
  2144. flags += targetLinkFlags;
  2145. }
  2146. std::string flagsProp = "LINK_FLAGS_";
  2147. flagsProp += CONFIG;
  2148. if(const char* flagsConfig = this->Target->GetProperty(flagsProp.c_str()))
  2149. {
  2150. flags += " ";
  2151. flags += flagsConfig;
  2152. }
  2153. std::string standardLibsVar = "CMAKE_";
  2154. standardLibsVar += linkLanguage;
  2155. standardLibsVar += "_STANDARD_LIBRARIES";
  2156. std::string
  2157. libs = this->Makefile->GetSafeDefinition(standardLibsVar.c_str());
  2158. // Remove trailing spaces from libs
  2159. std::string::size_type pos = libs.size()-1;
  2160. if(libs.size() != 0)
  2161. {
  2162. while(libs[pos] == ' ')
  2163. {
  2164. pos--;
  2165. }
  2166. }
  2167. if(pos != libs.size()-1)
  2168. {
  2169. libs = libs.substr(0, pos+1);
  2170. }
  2171. // Replace spaces in libs with ;
  2172. cmSystemTools::ReplaceString(libs, " ", ";");
  2173. std::vector<std::string> libVec;
  2174. cmSystemTools::ExpandListArgument(libs, libVec);
  2175. cmComputeLinkInformation* pcli =
  2176. this->Target->GetLinkInformation(config.c_str());
  2177. if(!pcli)
  2178. {
  2179. cmSystemTools::Error
  2180. ("CMake can not compute cmComputeLinkInformation for target: ",
  2181. this->Name.c_str());
  2182. return false;
  2183. }
  2184. // add the libraries for the target to libs string
  2185. cmComputeLinkInformation& cli = *pcli;
  2186. this->AddLibraries(cli, libVec);
  2187. linkOptions.AddFlag("AdditionalDependencies", libVec);
  2188. std::vector<std::string> const& ldirs = cli.GetDirectories();
  2189. std::vector<std::string> linkDirs;
  2190. for(std::vector<std::string>::const_iterator d = ldirs.begin();
  2191. d != ldirs.end(); ++d)
  2192. {
  2193. // first just full path
  2194. linkDirs.push_back(*d);
  2195. // next path with configuration type Debug, Release, etc
  2196. linkDirs.push_back(*d + "/$(Configuration)");
  2197. }
  2198. linkDirs.push_back("%(AdditionalLibraryDirectories)");
  2199. linkOptions.AddFlag("AdditionalLibraryDirectories", linkDirs);
  2200. std::string targetName;
  2201. std::string targetNameSO;
  2202. std::string targetNameFull;
  2203. std::string targetNameImport;
  2204. std::string targetNamePDB;
  2205. if(this->Target->GetType() == cmTarget::EXECUTABLE)
  2206. {
  2207. this->Target->GetExecutableNames(targetName, targetNameFull,
  2208. targetNameImport, targetNamePDB,
  2209. config.c_str());
  2210. }
  2211. else
  2212. {
  2213. this->Target->GetLibraryNames(targetName, targetNameSO, targetNameFull,
  2214. targetNameImport, targetNamePDB,
  2215. config.c_str());
  2216. }
  2217. if(this->MSTools)
  2218. {
  2219. linkOptions.AddFlag("Version", "");
  2220. if ( this->Target->GetPropertyAsBool("WIN32_EXECUTABLE") )
  2221. {
  2222. if (this->GlobalGenerator->TargetsWindowsCE())
  2223. {
  2224. linkOptions.AddFlag("SubSystem", "WindowsCE");
  2225. if (this->Target->GetType() == cmTarget::EXECUTABLE)
  2226. {
  2227. if (this->ClOptions[config]->UsingUnicode())
  2228. {
  2229. linkOptions.AddFlag("EntryPointSymbol", "wWinMainCRTStartup");
  2230. }
  2231. else
  2232. {
  2233. linkOptions.AddFlag("EntryPointSymbol", "WinMainCRTStartup");
  2234. }
  2235. }
  2236. }
  2237. else
  2238. {
  2239. linkOptions.AddFlag("SubSystem", "Windows");
  2240. }
  2241. }
  2242. else
  2243. {
  2244. if (this->GlobalGenerator->TargetsWindowsCE())
  2245. {
  2246. linkOptions.AddFlag("SubSystem", "WindowsCE");
  2247. if (this->Target->GetType() == cmTarget::EXECUTABLE)
  2248. {
  2249. if (this->ClOptions[config]->UsingUnicode())
  2250. {
  2251. linkOptions.AddFlag("EntryPointSymbol", "mainWCRTStartup");
  2252. }
  2253. else
  2254. {
  2255. linkOptions.AddFlag("EntryPointSymbol", "mainACRTStartup");
  2256. }
  2257. }
  2258. }
  2259. else
  2260. {
  2261. linkOptions.AddFlag("SubSystem", "Console");
  2262. };
  2263. }
  2264. if(const char* stackVal =
  2265. this->Makefile->GetDefinition("CMAKE_"+linkLanguage+"_STACK_SIZE"))
  2266. {
  2267. linkOptions.AddFlag("StackReserveSize", stackVal);
  2268. }
  2269. if(linkOptions.IsDebug() || flags.find("/debug") != flags.npos)
  2270. {
  2271. linkOptions.AddFlag("GenerateDebugInformation", "true");
  2272. }
  2273. else
  2274. {
  2275. linkOptions.AddFlag("GenerateDebugInformation", "false");
  2276. }
  2277. std::string pdb = this->Target->GetPDBDirectory(config.c_str());
  2278. pdb += "/";
  2279. pdb += targetNamePDB;
  2280. std::string imLib = this->Target->GetDirectory(config.c_str(), true);
  2281. imLib += "/";
  2282. imLib += targetNameImport;
  2283. linkOptions.AddFlag("ImportLibrary", imLib.c_str());
  2284. linkOptions.AddFlag("ProgramDataBaseFile", pdb.c_str());
  2285. // A Windows Runtime component uses internal .NET metadata,
  2286. // so does not have an import library.
  2287. if(this->Target->GetPropertyAsBool("VS_WINRT_COMPONENT"))
  2288. {
  2289. linkOptions.AddFlag("GenerateWindowsMetadata", "true");
  2290. }
  2291. else if (this->GlobalGenerator->TargetsWindowsPhone() ||
  2292. this->GlobalGenerator->TargetsWindowsStore())
  2293. {
  2294. // WindowsPhone and WindowsStore components are in an app container
  2295. // and produce WindowsMetadata. If we are not producing a WINRT
  2296. // component, then do not generate the metadata here.
  2297. linkOptions.AddFlag("GenerateWindowsMetadata", "false");
  2298. }
  2299. if (this->GlobalGenerator->TargetsWindowsPhone() &&
  2300. this->GlobalGenerator->GetSystemVersion() == "8.0")
  2301. {
  2302. // WindowsPhone 8.0 does not have ole32.
  2303. linkOptions.AppendFlag("IgnoreSpecificDefaultLibraries", "ole32.lib");
  2304. }
  2305. }
  2306. else if(this->NsightTegra)
  2307. {
  2308. linkOptions.AddFlag("SoName", targetNameSO.c_str());
  2309. }
  2310. linkOptions.Parse(flags.c_str());
  2311. if(this->MSTools)
  2312. {
  2313. std::string def = this->GeneratorTarget->GetModuleDefinitionFile("");
  2314. if(!def.empty())
  2315. {
  2316. linkOptions.AddFlag("ModuleDefinitionFile", def.c_str());
  2317. }
  2318. linkOptions.AppendFlag("IgnoreSpecificDefaultLibraries",
  2319. "%(IgnoreSpecificDefaultLibraries)");
  2320. }
  2321. this->LinkOptions[config] = pOptions.release();
  2322. return true;
  2323. }
  2324. //----------------------------------------------------------------------------
  2325. void
  2326. cmVisualStudio10TargetGenerator::WriteLinkOptions(std::string const& config)
  2327. {
  2328. if(this->Target->GetType() == cmTarget::STATIC_LIBRARY
  2329. || this->Target->GetType() > cmTarget::MODULE_LIBRARY)
  2330. {
  2331. return;
  2332. }
  2333. Options& linkOptions = *(this->LinkOptions[config]);
  2334. this->WriteString("<Link>\n", 2);
  2335. linkOptions.OutputAdditionalOptions(*this->BuildFileStream, " ", "");
  2336. linkOptions.OutputFlagMap(*this->BuildFileStream, " ");
  2337. this->WriteString("</Link>\n", 2);
  2338. if(!this->GlobalGenerator->NeedLinkLibraryDependencies(*this->Target))
  2339. {
  2340. this->WriteString("<ProjectReference>\n", 2);
  2341. this->WriteString(
  2342. " <LinkLibraryDependencies>false</LinkLibraryDependencies>\n", 2);
  2343. this->WriteString("</ProjectReference>\n", 2);
  2344. }
  2345. }
  2346. void cmVisualStudio10TargetGenerator::AddLibraries(
  2347. cmComputeLinkInformation& cli,
  2348. std::vector<std::string>& libVec)
  2349. {
  2350. typedef cmComputeLinkInformation::ItemVector ItemVector;
  2351. ItemVector libs = cli.GetItems();
  2352. for(ItemVector::const_iterator l = libs.begin(); l != libs.end(); ++l)
  2353. {
  2354. if(l->IsPath)
  2355. {
  2356. std::string path = this->LocalGenerator->
  2357. Convert(l->Value.c_str(),
  2358. cmLocalGenerator::START_OUTPUT,
  2359. cmLocalGenerator::UNCHANGED);
  2360. this->ConvertToWindowsSlash(path);
  2361. libVec.push_back(path);
  2362. }
  2363. else if (!l->Target
  2364. || l->Target->GetType() != cmTarget::INTERFACE_LIBRARY)
  2365. {
  2366. libVec.push_back(l->Value);
  2367. }
  2368. }
  2369. }
  2370. void cmVisualStudio10TargetGenerator::
  2371. WriteMidlOptions(std::string const& /*config*/,
  2372. std::vector<std::string> const & includes)
  2373. {
  2374. if(!this->MSTools)
  2375. {
  2376. return;
  2377. }
  2378. // This processes *any* of the .idl files specified in the project's file
  2379. // list (and passed as the item metadata %(Filename) expressing the rule
  2380. // input filename) into output files at the per-config *build* dir
  2381. // ($(IntDir)) each.
  2382. //
  2383. // IOW, this MIDL section is intended to provide a fully generic syntax
  2384. // content suitable for most cases (read: if you get errors, then it's quite
  2385. // probable that the error is on your side of the .idl setup).
  2386. //
  2387. // Also, note that the marked-as-generated _i.c file in the Visual Studio
  2388. // generator case needs to be referred to as $(IntDir)\foo_i.c at the
  2389. // project's file list, otherwise the compiler-side processing won't pick it
  2390. // up (for non-directory form, it ends up looking in project binary dir
  2391. // only). Perhaps there's something to be done to make this more automatic
  2392. // on the CMake side?
  2393. this->WriteString("<Midl>\n", 2);
  2394. this->WriteString("<AdditionalIncludeDirectories>", 3);
  2395. for(std::vector<std::string>::const_iterator i = includes.begin();
  2396. i != includes.end(); ++i)
  2397. {
  2398. *this->BuildFileStream << cmVS10EscapeXML(*i) << ";";
  2399. }
  2400. this->WriteString("%(AdditionalIncludeDirectories)"
  2401. "</AdditionalIncludeDirectories>\n", 0);
  2402. this->WriteString("<OutputDirectory>$(ProjectDir)/$(IntDir)"
  2403. "</OutputDirectory>\n", 3);
  2404. this->WriteString("<HeaderFileName>%(Filename).h</HeaderFileName>\n", 3);
  2405. this->WriteString(
  2406. "<TypeLibraryName>%(Filename).tlb</TypeLibraryName>\n", 3);
  2407. this->WriteString(
  2408. "<InterfaceIdentifierFileName>"
  2409. "%(Filename)_i.c</InterfaceIdentifierFileName>\n", 3);
  2410. this->WriteString("<ProxyFileName>%(Filename)_p.c</ProxyFileName>\n",3);
  2411. this->WriteString("</Midl>\n", 2);
  2412. }
  2413. void cmVisualStudio10TargetGenerator::WriteItemDefinitionGroups()
  2414. {
  2415. std::vector<std::string> *configs =
  2416. static_cast<cmGlobalVisualStudio7Generator *>
  2417. (this->GlobalGenerator)->GetConfigurations();
  2418. for(std::vector<std::string>::iterator i = configs->begin();
  2419. i != configs->end(); ++i)
  2420. {
  2421. std::vector<std::string> includes;
  2422. this->LocalGenerator->GetIncludeDirectories(includes,
  2423. this->GeneratorTarget,
  2424. "C", i->c_str());
  2425. for(std::vector<std::string>::iterator ii = includes.begin();
  2426. ii != includes.end(); ++ii)
  2427. {
  2428. this->ConvertToWindowsSlash(*ii);
  2429. }
  2430. this->WritePlatformConfigTag("ItemDefinitionGroup", i->c_str(), 1);
  2431. *this->BuildFileStream << "\n";
  2432. // output cl compile flags <ClCompile></ClCompile>
  2433. if(this->Target->GetType() <= cmTarget::OBJECT_LIBRARY)
  2434. {
  2435. this->WriteClOptions(*i, includes);
  2436. // output rc compile flags <ResourceCompile></ResourceCompile>
  2437. this->WriteRCOptions(*i, includes);
  2438. this->WriteMasmOptions(*i, includes);
  2439. }
  2440. // output midl flags <Midl></Midl>
  2441. this->WriteMidlOptions(*i, includes);
  2442. // write events
  2443. this->WriteEvents(*i);
  2444. // output link flags <Link></Link>
  2445. this->WriteLinkOptions(*i);
  2446. // output lib flags <Lib></Lib>
  2447. this->WriteLibOptions(*i);
  2448. if(this->NsightTegra &&
  2449. this->Target->GetType() == cmTarget::EXECUTABLE &&
  2450. this->Target->GetPropertyAsBool("ANDROID_GUI"))
  2451. {
  2452. this->WriteAntBuildOptions(*i);
  2453. }
  2454. this->WriteString("</ItemDefinitionGroup>\n", 1);
  2455. }
  2456. }
  2457. void
  2458. cmVisualStudio10TargetGenerator::WriteEvents(std::string const& configName)
  2459. {
  2460. this->WriteEvent("PreLinkEvent",
  2461. this->Target->GetPreLinkCommands(), configName);
  2462. this->WriteEvent("PreBuildEvent",
  2463. this->Target->GetPreBuildCommands(), configName);
  2464. this->WriteEvent("PostBuildEvent",
  2465. this->Target->GetPostBuildCommands(), configName);
  2466. }
  2467. void cmVisualStudio10TargetGenerator::WriteEvent(
  2468. const char* name,
  2469. std::vector<cmCustomCommand> const& commands,
  2470. std::string const& configName)
  2471. {
  2472. if(commands.size() == 0)
  2473. {
  2474. return;
  2475. }
  2476. this->WriteString("<", 2);
  2477. (*this->BuildFileStream ) << name << ">\n";
  2478. cmLocalVisualStudio7Generator* lg = this->LocalGenerator;
  2479. std::string script;
  2480. const char* pre = "";
  2481. std::string comment;
  2482. for(std::vector<cmCustomCommand>::const_iterator i = commands.begin();
  2483. i != commands.end(); ++i)
  2484. {
  2485. cmCustomCommandGenerator ccg(*i, configName, this->Makefile);
  2486. comment += pre;
  2487. comment += lg->ConstructComment(ccg);
  2488. script += pre;
  2489. pre = "\n";
  2490. script += cmVS10EscapeXML(lg->ConstructScript(ccg));
  2491. }
  2492. comment = cmVS10EscapeComment(comment);
  2493. this->WriteString("<Message>",3);
  2494. (*this->BuildFileStream ) << cmVS10EscapeXML(comment) << "</Message>\n";
  2495. this->WriteString("<Command>", 3);
  2496. (*this->BuildFileStream ) << script;
  2497. (*this->BuildFileStream ) << "</Command>" << "\n";
  2498. this->WriteString("</", 2);
  2499. (*this->BuildFileStream ) << name << ">\n";
  2500. }
  2501. void cmVisualStudio10TargetGenerator::WriteProjectReferences()
  2502. {
  2503. cmGlobalGenerator::TargetDependSet const& unordered
  2504. = this->GlobalGenerator->GetTargetDirectDepends(*this->Target);
  2505. typedef cmGlobalVisualStudioGenerator::OrderedTargetDependSet
  2506. OrderedTargetDependSet;
  2507. OrderedTargetDependSet depends(unordered);
  2508. this->WriteString("<ItemGroup>\n", 1);
  2509. for( OrderedTargetDependSet::const_iterator i = depends.begin();
  2510. i != depends.end(); ++i)
  2511. {
  2512. cmTarget const* dt = *i;
  2513. if(dt->GetType() == cmTarget::INTERFACE_LIBRARY)
  2514. {
  2515. continue;
  2516. }
  2517. // skip fortran targets as they can not be processed by MSBuild
  2518. // the only reference will be in the .sln file
  2519. if(static_cast<cmGlobalVisualStudioGenerator*>(this->GlobalGenerator)
  2520. ->TargetIsFortranOnly(*dt))
  2521. {
  2522. continue;
  2523. }
  2524. this->WriteString("<ProjectReference Include=\"", 2);
  2525. cmMakefile* mf = dt->GetMakefile();
  2526. std::string name = dt->GetName();
  2527. std::string path;
  2528. const char* p = dt->GetProperty("EXTERNAL_MSPROJECT");
  2529. if(p)
  2530. {
  2531. path = p;
  2532. }
  2533. else
  2534. {
  2535. path = mf->GetStartOutputDirectory();
  2536. path += "/";
  2537. path += dt->GetName();
  2538. path += ".vcxproj";
  2539. }
  2540. (*this->BuildFileStream) << cmVS10EscapeXML(path) << "\">\n";
  2541. this->WriteString("<Project>", 3);
  2542. (*this->BuildFileStream)
  2543. << this->GlobalGenerator->GetGUID(name.c_str())
  2544. << "</Project>\n";
  2545. this->WriteString("</ProjectReference>\n", 2);
  2546. }
  2547. this->WriteString("</ItemGroup>\n", 1);
  2548. }
  2549. void cmVisualStudio10TargetGenerator::WriteWinRTPackageCertificateKeyFile()
  2550. {
  2551. if((this->GlobalGenerator->TargetsWindowsStore() ||
  2552. this->GlobalGenerator->TargetsWindowsPhone())
  2553. && (cmTarget::EXECUTABLE == this->Target->GetType()))
  2554. {
  2555. std::string pfxFile;
  2556. std::vector<cmSourceFile const*> certificates;
  2557. this->GeneratorTarget->GetCertificates(certificates, "");
  2558. for(std::vector<cmSourceFile const*>::const_iterator si =
  2559. certificates.begin(); si != certificates.end(); ++si)
  2560. {
  2561. pfxFile = this->ConvertPath((*si)->GetFullPath(), false);
  2562. this->ConvertToWindowsSlash(pfxFile);
  2563. break;
  2564. }
  2565. if(this->IsMissingFiles &&
  2566. !(this->GlobalGenerator->TargetsWindowsPhone() &&
  2567. this->GlobalGenerator->GetSystemVersion() == "8.0"))
  2568. {
  2569. // Move the manifest to a project directory to avoid clashes
  2570. std::string artifactDir =
  2571. this->LocalGenerator->GetTargetDirectory(*this->Target);
  2572. this->ConvertToWindowsSlash(artifactDir);
  2573. this->WriteString("<PropertyGroup>\n", 1);
  2574. this->WriteString("<AppxPackageArtifactsDir>", 2);
  2575. (*this->BuildFileStream) << cmVS10EscapeXML(artifactDir) <<
  2576. "\\</AppxPackageArtifactsDir>\n";
  2577. this->WriteString("<ProjectPriFullPath>"
  2578. "$(TargetDir)resources.pri</ProjectPriFullPath>", 2);
  2579. // If we are missing files and we don't have a certificate and
  2580. // aren't targeting WP8.0, add a default certificate
  2581. if(pfxFile.empty())
  2582. {
  2583. std::string templateFolder = cmSystemTools::GetCMakeRoot() +
  2584. "/Templates/Windows";
  2585. pfxFile = this->DefaultArtifactDir + "/Windows_TemporaryKey.pfx";
  2586. cmSystemTools::CopyAFile(templateFolder + "/Windows_TemporaryKey.pfx",
  2587. pfxFile, false);
  2588. this->ConvertToWindowsSlash(pfxFile);
  2589. this->AddedFiles.push_back(pfxFile);
  2590. }
  2591. this->WriteString("<", 2);
  2592. (*this->BuildFileStream) << "PackageCertificateKeyFile>"
  2593. << pfxFile << "</PackageCertificateKeyFile>\n";
  2594. this->WriteString("</PropertyGroup>\n", 1);
  2595. }
  2596. else if(!pfxFile.empty())
  2597. {
  2598. this->WriteString("<PropertyGroup>\n", 1);
  2599. this->WriteString("<", 2);
  2600. (*this->BuildFileStream) << "PackageCertificateKeyFile>"
  2601. << pfxFile << "</PackageCertificateKeyFile>\n";
  2602. this->WriteString("</PropertyGroup>\n", 1);
  2603. }
  2604. }
  2605. }
  2606. bool cmVisualStudio10TargetGenerator::
  2607. IsResxHeader(const std::string& headerFile)
  2608. {
  2609. std::set<std::string> expectedResxHeaders;
  2610. this->GeneratorTarget->GetExpectedResxHeaders(expectedResxHeaders, "");
  2611. std::set<std::string>::const_iterator it =
  2612. expectedResxHeaders.find(headerFile);
  2613. return it != expectedResxHeaders.end();
  2614. }
  2615. bool cmVisualStudio10TargetGenerator::
  2616. IsXamlHeader(const std::string& headerFile)
  2617. {
  2618. std::set<std::string> expectedXamlHeaders;
  2619. this->GeneratorTarget->GetExpectedXamlHeaders(expectedXamlHeaders, "");
  2620. std::set<std::string>::const_iterator it =
  2621. expectedXamlHeaders.find(headerFile);
  2622. return it != expectedXamlHeaders.end();
  2623. }
  2624. bool cmVisualStudio10TargetGenerator::
  2625. IsXamlSource(const std::string& sourceFile)
  2626. {
  2627. std::set<std::string> expectedXamlSources;
  2628. this->GeneratorTarget->GetExpectedXamlSources(expectedXamlSources, "");
  2629. std::set<std::string>::const_iterator it =
  2630. expectedXamlSources.find(sourceFile);
  2631. return it != expectedXamlSources.end();
  2632. }
  2633. void cmVisualStudio10TargetGenerator::WriteApplicationTypeSettings()
  2634. {
  2635. bool isAppContainer = false;
  2636. bool const isWindowsPhone = this->GlobalGenerator->TargetsWindowsPhone();
  2637. bool const isWindowsStore = this->GlobalGenerator->TargetsWindowsStore();
  2638. std::string const& v = this->GlobalGenerator->GetSystemVersion();
  2639. if(isWindowsPhone || isWindowsStore)
  2640. {
  2641. this->WriteString("<ApplicationType>", 2);
  2642. (*this->BuildFileStream) << (isWindowsPhone ?
  2643. "Windows Phone" : "Windows Store")
  2644. << "</ApplicationType>\n";
  2645. this->WriteString("<ApplicationTypeRevision>", 2);
  2646. (*this->BuildFileStream) << cmVS10EscapeXML(v)
  2647. << "</ApplicationTypeRevision>\n";
  2648. this->WriteString("<DefaultLanguage>en-US"
  2649. "</DefaultLanguage>\n", 2);
  2650. if(v == "8.1")
  2651. {
  2652. // Visual Studio 12.0 is necessary for building 8.1 apps
  2653. this->WriteString("<MinimumVisualStudioVersion>12.0"
  2654. "</MinimumVisualStudioVersion>\n", 2);
  2655. if (this->Target->GetType() < cmTarget::UTILITY)
  2656. {
  2657. isAppContainer = true;
  2658. }
  2659. }
  2660. else if (v == "8.0")
  2661. {
  2662. // Visual Studio 11.0 is necessary for building 8.0 apps
  2663. this->WriteString("<MinimumVisualStudioVersion>11.0"
  2664. "</MinimumVisualStudioVersion>\n", 2);
  2665. if (isWindowsStore && this->Target->GetType() < cmTarget::UTILITY)
  2666. {
  2667. isAppContainer = true;
  2668. }
  2669. else if (isWindowsPhone &&
  2670. this->Target->GetType() == cmTarget::EXECUTABLE)
  2671. {
  2672. this->WriteString("<XapOutputs>true</XapOutputs>\n", 2);
  2673. this->WriteString("<XapFilename>", 2);
  2674. (*this->BuildFileStream) << cmVS10EscapeXML(this->Name.c_str()) <<
  2675. "_$(Configuration)_$(Platform).xap</XapFilename>\n";
  2676. }
  2677. }
  2678. }
  2679. if(isAppContainer)
  2680. {
  2681. this->WriteString("<AppContainerApplication>true"
  2682. "</AppContainerApplication>\n", 2);
  2683. }
  2684. else if (this->Platform == "ARM")
  2685. {
  2686. this->WriteString("<WindowsSDKDesktopARMSupport>true"
  2687. "</WindowsSDKDesktopARMSupport>\n", 2);
  2688. }
  2689. }
  2690. void cmVisualStudio10TargetGenerator::VerifyNecessaryFiles()
  2691. {
  2692. // For Windows and Windows Phone executables, we will assume that if a
  2693. // manifest is not present that we need to add all the necessary files
  2694. if (this->Target->GetType() == cmTarget::EXECUTABLE)
  2695. {
  2696. std::vector<cmSourceFile const*> manifestSources;
  2697. this->GeneratorTarget->GetAppManifest(manifestSources, "");
  2698. {
  2699. std::string const& v = this->GlobalGenerator->GetSystemVersion();
  2700. if(this->GlobalGenerator->TargetsWindowsPhone())
  2701. {
  2702. if (v == "8.0")
  2703. {
  2704. // Look through the sources for WMAppManifest.xml
  2705. std::vector<cmSourceFile const*> extraSources;
  2706. this->GeneratorTarget->GetExtraSources(extraSources, "");
  2707. bool foundManifest = false;
  2708. for(std::vector<cmSourceFile const*>::const_iterator si =
  2709. extraSources.begin(); si != extraSources.end(); ++si)
  2710. {
  2711. // Need to do a lowercase comparison on the filename
  2712. if("wmappmanifest.xml" == cmSystemTools::LowerCase(
  2713. (*si)->GetLocation().GetName()))
  2714. {
  2715. foundManifest = true;
  2716. break;
  2717. }
  2718. }
  2719. if (!foundManifest)
  2720. {
  2721. this->IsMissingFiles = true;
  2722. }
  2723. }
  2724. else if (v == "8.1")
  2725. {
  2726. if(manifestSources.empty())
  2727. {
  2728. this->IsMissingFiles = true;
  2729. }
  2730. }
  2731. }
  2732. else if (this->GlobalGenerator->TargetsWindowsStore())
  2733. {
  2734. if (manifestSources.empty())
  2735. {
  2736. if (v == "8.0")
  2737. {
  2738. this->IsMissingFiles = true;
  2739. }
  2740. else if (v == "8.1")
  2741. {
  2742. this->IsMissingFiles = true;
  2743. }
  2744. }
  2745. }
  2746. }
  2747. }
  2748. }
  2749. void cmVisualStudio10TargetGenerator::WriteMissingFiles()
  2750. {
  2751. std::string const& v = this->GlobalGenerator->GetSystemVersion();
  2752. if(this->GlobalGenerator->TargetsWindowsPhone())
  2753. {
  2754. if (v == "8.0")
  2755. {
  2756. this->WriteMissingFilesWP80();
  2757. }
  2758. else if (v == "8.1")
  2759. {
  2760. this->WriteMissingFilesWP81();
  2761. }
  2762. }
  2763. else if (this->GlobalGenerator->TargetsWindowsStore())
  2764. {
  2765. if (v == "8.0")
  2766. {
  2767. this->WriteMissingFilesWS80();
  2768. }
  2769. else if (v == "8.1")
  2770. {
  2771. this->WriteMissingFilesWS81();
  2772. }
  2773. }
  2774. }
  2775. void cmVisualStudio10TargetGenerator::WriteMissingFilesWP80()
  2776. {
  2777. std::string templateFolder = cmSystemTools::GetCMakeRoot() +
  2778. "/Templates/Windows";
  2779. // For WP80, the manifest needs to be in the same folder as the project
  2780. // this can cause an overwrite problem if projects aren't organized in
  2781. // folders
  2782. std::string manifestFile = this->Makefile->GetStartOutputDirectory() +
  2783. std::string("/WMAppManifest.xml");
  2784. std::string artifactDir =
  2785. this->LocalGenerator->GetTargetDirectory(*this->Target);
  2786. this->ConvertToWindowsSlash(artifactDir);
  2787. std::string artifactDirXML = cmVS10EscapeXML(artifactDir);
  2788. std::string targetNameXML = cmVS10EscapeXML(this->Target->GetName());
  2789. cmGeneratedFileStream fout(manifestFile.c_str());
  2790. fout.SetCopyIfDifferent(true);
  2791. fout <<
  2792. "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
  2793. "<Deployment"
  2794. " xmlns=\"http://schemas.microsoft.com/windowsphone/2012/deployment\""
  2795. " AppPlatformVersion=\"8.0\">\n"
  2796. "\t<DefaultLanguage xmlns=\"\" code=\"en-US\"/>\n"
  2797. "\t<App xmlns=\"\" ProductID=\"{" << this->GUID << "}\""
  2798. " Title=\"CMake Test Program\" RuntimeType=\"Modern Native\""
  2799. " Version=\"1.0.0.0\" Genre=\"apps.normal\" Author=\"CMake\""
  2800. " Description=\"Default CMake App\" Publisher=\"CMake\""
  2801. " PublisherID=\"{" << this->GUID << "}\">\n"
  2802. "\t\t<IconPath IsRelative=\"true\" IsResource=\"false\">"
  2803. << artifactDirXML << "\\ApplicationIcon.png</IconPath>\n"
  2804. "\t\t<Capabilities/>\n"
  2805. "\t\t<Tasks>\n"
  2806. "\t\t\t<DefaultTask Name=\"_default\""
  2807. " ImagePath=\"" << targetNameXML << ".exe\" ImageParams=\"\" />\n"
  2808. "\t\t</Tasks>\n"
  2809. "\t\t<Tokens>\n"
  2810. "\t\t\t<PrimaryToken TokenID=\"" << targetNameXML << "Token\""
  2811. " TaskName=\"_default\">\n"
  2812. "\t\t\t\t<TemplateFlip>\n"
  2813. "\t\t\t\t\t<SmallImageURI IsRelative=\"true\" IsResource=\"false\">"
  2814. << artifactDirXML << "\\SmallLogo.png</SmallImageURI>\n"
  2815. "\t\t\t\t\t<Count>0</Count>\n"
  2816. "\t\t\t\t\t<BackgroundImageURI IsRelative=\"true\" IsResource=\"false\">"
  2817. << artifactDirXML << "\\Logo.png</BackgroundImageURI>\n"
  2818. "\t\t\t\t</TemplateFlip>\n"
  2819. "\t\t\t</PrimaryToken>\n"
  2820. "\t\t</Tokens>\n"
  2821. "\t\t<ScreenResolutions>\n"
  2822. "\t\t\t<ScreenResolution Name=\"ID_RESOLUTION_WVGA\" />\n"
  2823. "\t\t</ScreenResolutions>\n"
  2824. "\t</App>\n"
  2825. "</Deployment>\n";
  2826. std::string sourceFile = this->ConvertPath(manifestFile, false);
  2827. this->ConvertToWindowsSlash(sourceFile);
  2828. this->WriteString("<Xml Include=\"", 2);
  2829. (*this->BuildFileStream) << cmVS10EscapeXML(sourceFile) << "\">\n";
  2830. this->WriteString("<SubType>Designer</SubType>\n", 3);
  2831. this->WriteString("</Xml>\n", 2);
  2832. this->AddedFiles.push_back(sourceFile);
  2833. std::string smallLogo = this->DefaultArtifactDir + "/SmallLogo.png";
  2834. cmSystemTools::CopyAFile(templateFolder + "/SmallLogo.png",
  2835. smallLogo, false);
  2836. this->ConvertToWindowsSlash(smallLogo);
  2837. this->WriteString("<Image Include=\"", 2);
  2838. (*this->BuildFileStream) << cmVS10EscapeXML(smallLogo) << "\" />\n";
  2839. this->AddedFiles.push_back(smallLogo);
  2840. std::string logo = this->DefaultArtifactDir + "/Logo.png";
  2841. cmSystemTools::CopyAFile(templateFolder + "/Logo.png",
  2842. logo, false);
  2843. this->ConvertToWindowsSlash(logo);
  2844. this->WriteString("<Image Include=\"", 2);
  2845. (*this->BuildFileStream) << cmVS10EscapeXML(logo) << "\" />\n";
  2846. this->AddedFiles.push_back(logo);
  2847. std::string applicationIcon =
  2848. this->DefaultArtifactDir + "/ApplicationIcon.png";
  2849. cmSystemTools::CopyAFile(templateFolder + "/ApplicationIcon.png",
  2850. applicationIcon, false);
  2851. this->ConvertToWindowsSlash(applicationIcon);
  2852. this->WriteString("<Image Include=\"", 2);
  2853. (*this->BuildFileStream) << cmVS10EscapeXML(applicationIcon) << "\" />\n";
  2854. this->AddedFiles.push_back(applicationIcon);
  2855. }
  2856. void cmVisualStudio10TargetGenerator::WriteMissingFilesWP81()
  2857. {
  2858. std::string manifestFile =
  2859. this->DefaultArtifactDir + "/package.appxManifest";
  2860. std::string artifactDir =
  2861. this->LocalGenerator->GetTargetDirectory(*this->Target);
  2862. this->ConvertToWindowsSlash(artifactDir);
  2863. std::string artifactDirXML = cmVS10EscapeXML(artifactDir);
  2864. std::string targetNameXML = cmVS10EscapeXML(this->Target->GetName());
  2865. cmGeneratedFileStream fout(manifestFile.c_str());
  2866. fout.SetCopyIfDifferent(true);
  2867. fout <<
  2868. "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
  2869. "<Package xmlns=\"http://schemas.microsoft.com/appx/2010/manifest\""
  2870. " xmlns:m2=\"http://schemas.microsoft.com/appx/2013/manifest\""
  2871. " xmlns:mp=\"http://schemas.microsoft.com/appx/2014/phone/manifest\">\n"
  2872. "\t<Identity Name=\"" << this->GUID << "\" Publisher=\"CN=CMake\""
  2873. " Version=\"1.0.0.0\" />\n"
  2874. "\t<mp:PhoneIdentity PhoneProductId=\"" << this->GUID << "\""
  2875. " PhonePublisherId=\"00000000-0000-0000-0000-000000000000\"/>\n"
  2876. "\t<Properties>\n"
  2877. "\t\t<DisplayName>" << targetNameXML << "</DisplayName>\n"
  2878. "\t\t<PublisherDisplayName>CMake</PublisherDisplayName>\n"
  2879. "\t\t<Logo>" << artifactDirXML << "\\StoreLogo.png</Logo>\n"
  2880. "\t</Properties>\n"
  2881. "\t<Prerequisites>\n"
  2882. "\t\t<OSMinVersion>6.3.1</OSMinVersion>\n"
  2883. "\t\t<OSMaxVersionTested>6.3.1</OSMaxVersionTested>\n"
  2884. "\t</Prerequisites>\n"
  2885. "\t<Resources>\n"
  2886. "\t\t<Resource Language=\"x-generate\" />\n"
  2887. "\t</Resources>\n"
  2888. "\t<Applications>\n"
  2889. "\t\t<Application Id=\"App\""
  2890. " Executable=\"" << targetNameXML << ".exe\""
  2891. " EntryPoint=\"" << targetNameXML << ".App\">\n"
  2892. "\t\t\t<m2:VisualElements\n"
  2893. "\t\t\t\tDisplayName=\"" << targetNameXML << "\"\n"
  2894. "\t\t\t\tDescription=\"" << targetNameXML << "\"\n"
  2895. "\t\t\t\tBackgroundColor=\"#336699\"\n"
  2896. "\t\t\t\tForegroundText=\"light\"\n"
  2897. "\t\t\t\tSquare150x150Logo=\"" << artifactDirXML << "\\Logo.png\"\n"
  2898. "\t\t\t\tSquare30x30Logo=\"" << artifactDirXML << "\\SmallLogo.png\">\n"
  2899. "\t\t\t\t<m2:DefaultTile ShortName=\"" << targetNameXML << "\">\n"
  2900. "\t\t\t\t\t<m2:ShowNameOnTiles>\n"
  2901. "\t\t\t\t\t\t<m2:ShowOn Tile=\"square150x150Logo\" />\n"
  2902. "\t\t\t\t\t</m2:ShowNameOnTiles>\n"
  2903. "\t\t\t\t</m2:DefaultTile>\n"
  2904. "\t\t\t\t<m2:SplashScreen"
  2905. " Image=\"" << artifactDirXML << "\\SplashScreen.png\" />\n"
  2906. "\t\t\t</m2:VisualElements>\n"
  2907. "\t\t</Application>\n"
  2908. "\t</Applications>\n"
  2909. "</Package>\n";
  2910. this->WriteCommonMissingFiles(manifestFile);
  2911. }
  2912. void cmVisualStudio10TargetGenerator::WriteMissingFilesWS80()
  2913. {
  2914. std::string manifestFile =
  2915. this->DefaultArtifactDir + "/package.appxManifest";
  2916. std::string artifactDir =
  2917. this->LocalGenerator->GetTargetDirectory(*this->Target);
  2918. this->ConvertToWindowsSlash(artifactDir);
  2919. std::string artifactDirXML = cmVS10EscapeXML(artifactDir);
  2920. std::string targetNameXML = cmVS10EscapeXML(this->Target->GetName());
  2921. cmGeneratedFileStream fout(manifestFile.c_str());
  2922. fout.SetCopyIfDifferent(true);
  2923. fout <<
  2924. "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
  2925. "<Package xmlns=\"http://schemas.microsoft.com/appx/2010/manifest\">\n"
  2926. "\t<Identity Name=\"" << this->GUID << "\" Publisher=\"CN=CMake\""
  2927. " Version=\"1.0.0.0\" />\n"
  2928. "\t<Properties>\n"
  2929. "\t\t<DisplayName>" << targetNameXML << "</DisplayName>\n"
  2930. "\t\t<PublisherDisplayName>CMake</PublisherDisplayName>\n"
  2931. "\t\t<Logo>" << artifactDirXML << "\\StoreLogo.png</Logo>\n"
  2932. "\t</Properties>\n"
  2933. "\t<Prerequisites>\n"
  2934. "\t\t<OSMinVersion>6.2.1</OSMinVersion>\n"
  2935. "\t\t<OSMaxVersionTested>6.2.1</OSMaxVersionTested>\n"
  2936. "\t</Prerequisites>\n"
  2937. "\t<Resources>\n"
  2938. "\t\t<Resource Language=\"x-generate\" />\n"
  2939. "\t</Resources>\n"
  2940. "\t<Applications>\n"
  2941. "\t\t<Application Id=\"App\""
  2942. " Executable=\"" << targetNameXML << ".exe\""
  2943. " EntryPoint=\"" << targetNameXML << ".App\">\n"
  2944. "\t\t\t<VisualElements"
  2945. " DisplayName=\"" << targetNameXML << "\""
  2946. " Description=\"" << targetNameXML << "\""
  2947. " BackgroundColor=\"#336699\" ForegroundText=\"light\""
  2948. " Logo=\"" << artifactDirXML << "\\Logo.png\""
  2949. " SmallLogo=\"" << artifactDirXML << "\\SmallLogo.png\">\n"
  2950. "\t\t\t\t<DefaultTile ShowName=\"allLogos\""
  2951. " ShortName=\"" << targetNameXML << "\" />\n"
  2952. "\t\t\t\t<SplashScreen"
  2953. " Image=\"" << artifactDirXML << "\\SplashScreen.png\" />\n"
  2954. "\t\t\t</VisualElements>\n"
  2955. "\t\t</Application>\n"
  2956. "\t</Applications>\n"
  2957. "</Package>\n";
  2958. this->WriteCommonMissingFiles(manifestFile);
  2959. }
  2960. void cmVisualStudio10TargetGenerator::WriteMissingFilesWS81()
  2961. {
  2962. std::string manifestFile =
  2963. this->DefaultArtifactDir + "/package.appxManifest";
  2964. std::string artifactDir =
  2965. this->LocalGenerator->GetTargetDirectory(*this->Target);
  2966. this->ConvertToWindowsSlash(artifactDir);
  2967. std::string artifactDirXML = cmVS10EscapeXML(artifactDir);
  2968. std::string targetNameXML = cmVS10EscapeXML(this->Target->GetName());
  2969. cmGeneratedFileStream fout(manifestFile.c_str());
  2970. fout.SetCopyIfDifferent(true);
  2971. fout <<
  2972. "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
  2973. "<Package xmlns=\"http://schemas.microsoft.com/appx/2010/manifest\""
  2974. " xmlns:m2=\"http://schemas.microsoft.com/appx/2013/manifest\">\n"
  2975. "\t<Identity Name=\"" << this->GUID << "\" Publisher=\"CN=CMake\""
  2976. " Version=\"1.0.0.0\" />\n"
  2977. "\t<Properties>\n"
  2978. "\t\t<DisplayName>" << targetNameXML << "</DisplayName>\n"
  2979. "\t\t<PublisherDisplayName>CMake</PublisherDisplayName>\n"
  2980. "\t\t<Logo>" << artifactDirXML << "\\StoreLogo.png</Logo>\n"
  2981. "\t</Properties>\n"
  2982. "\t<Prerequisites>\n"
  2983. "\t\t<OSMinVersion>6.3</OSMinVersion>\n"
  2984. "\t\t<OSMaxVersionTested>6.3</OSMaxVersionTested>\n"
  2985. "\t</Prerequisites>\n"
  2986. "\t<Resources>\n"
  2987. "\t\t<Resource Language=\"x-generate\" />\n"
  2988. "\t</Resources>\n"
  2989. "\t<Applications>\n"
  2990. "\t\t<Application Id=\"App\""
  2991. " Executable=\"" << targetNameXML << ".exe\""
  2992. " EntryPoint=\"" << targetNameXML << ".App\">\n"
  2993. "\t\t\t<m2:VisualElements\n"
  2994. "\t\t\t\tDisplayName=\"" << targetNameXML << "\"\n"
  2995. "\t\t\t\tDescription=\"" << targetNameXML << "\"\n"
  2996. "\t\t\t\tBackgroundColor=\"#336699\"\n"
  2997. "\t\t\t\tForegroundText=\"light\"\n"
  2998. "\t\t\t\tSquare150x150Logo=\"" << artifactDirXML << "\\Logo.png\"\n"
  2999. "\t\t\t\tSquare30x30Logo=\"" << artifactDirXML << "\\SmallLogo.png\">\n"
  3000. "\t\t\t\t<m2:DefaultTile ShortName=\"" << targetNameXML << "\">\n"
  3001. "\t\t\t\t\t<m2:ShowNameOnTiles>\n"
  3002. "\t\t\t\t\t\t<m2:ShowOn Tile=\"square150x150Logo\" />\n"
  3003. "\t\t\t\t\t</m2:ShowNameOnTiles>\n"
  3004. "\t\t\t\t</m2:DefaultTile>\n"
  3005. "\t\t\t\t<m2:SplashScreen"
  3006. " Image=\"" << artifactDirXML << "\\SplashScreen.png\" />\n"
  3007. "\t\t\t</m2:VisualElements>\n"
  3008. "\t\t</Application>\n"
  3009. "\t</Applications>\n"
  3010. "</Package>\n";
  3011. this->WriteCommonMissingFiles(manifestFile);
  3012. }
  3013. void
  3014. cmVisualStudio10TargetGenerator
  3015. ::WriteCommonMissingFiles(const std::string& manifestFile)
  3016. {
  3017. std::string templateFolder = cmSystemTools::GetCMakeRoot() +
  3018. "/Templates/Windows";
  3019. std::string sourceFile = this->ConvertPath(manifestFile, false);
  3020. this->ConvertToWindowsSlash(sourceFile);
  3021. this->WriteString("<AppxManifest Include=\"", 2);
  3022. (*this->BuildFileStream) << cmVS10EscapeXML(sourceFile) << "\">\n";
  3023. this->WriteString("<SubType>Designer</SubType>\n", 3);
  3024. this->WriteString("</AppxManifest>\n", 2);
  3025. this->AddedFiles.push_back(sourceFile);
  3026. std::string smallLogo = this->DefaultArtifactDir + "/SmallLogo.png";
  3027. cmSystemTools::CopyAFile(templateFolder + "/SmallLogo.png",
  3028. smallLogo, false);
  3029. this->ConvertToWindowsSlash(smallLogo);
  3030. this->WriteString("<Image Include=\"", 2);
  3031. (*this->BuildFileStream) << cmVS10EscapeXML(smallLogo) << "\" />\n";
  3032. this->AddedFiles.push_back(smallLogo);
  3033. std::string logo = this->DefaultArtifactDir + "/Logo.png";
  3034. cmSystemTools::CopyAFile(templateFolder + "/Logo.png",
  3035. logo, false);
  3036. this->ConvertToWindowsSlash(logo);
  3037. this->WriteString("<Image Include=\"", 2);
  3038. (*this->BuildFileStream) << cmVS10EscapeXML(logo) << "\" />\n";
  3039. this->AddedFiles.push_back(logo);
  3040. std::string storeLogo = this->DefaultArtifactDir + "/StoreLogo.png";
  3041. cmSystemTools::CopyAFile(templateFolder + "/StoreLogo.png",
  3042. storeLogo, false);
  3043. this->ConvertToWindowsSlash(storeLogo);
  3044. this->WriteString("<Image Include=\"", 2);
  3045. (*this->BuildFileStream) << cmVS10EscapeXML(storeLogo) << "\" />\n";
  3046. this->AddedFiles.push_back(storeLogo);
  3047. std::string splashScreen = this->DefaultArtifactDir + "/SplashScreen.png";
  3048. cmSystemTools::CopyAFile(templateFolder + "/SplashScreen.png",
  3049. splashScreen, false);
  3050. this->ConvertToWindowsSlash(splashScreen);
  3051. this->WriteString("<Image Include=\"", 2);
  3052. (*this->BuildFileStream) << cmVS10EscapeXML(splashScreen) << "\" />\n";
  3053. this->AddedFiles.push_back(splashScreen);
  3054. // This file has already been added to the build so don't copy it
  3055. std::string keyFile = this->DefaultArtifactDir + "/Windows_TemporaryKey.pfx";
  3056. this->ConvertToWindowsSlash(keyFile);
  3057. this->WriteString("<None Include=\"", 2);
  3058. (*this->BuildFileStream) << cmVS10EscapeXML(keyFile) << "\" />\n";
  3059. }