cmVisualStudio10TargetGenerator.cxx 126 KB

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