cmVisualStudio10TargetGenerator.cxx 126 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388
  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 <cm_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. } else if (ext == "natvis") {
  1108. tool = "Natvis";
  1109. }
  1110. if (this->NsightTegra) {
  1111. // Nsight Tegra needs specific file types to check up-to-dateness.
  1112. std::string name = cmSystemTools::LowerCase(sf->GetLocation().GetName());
  1113. if (name == "androidmanifest.xml" || name == "build.xml" ||
  1114. name == "proguard.cfg" || name == "proguard-project.txt" ||
  1115. ext == "properties") {
  1116. tool = "AndroidBuild";
  1117. } else if (ext == "java") {
  1118. tool = "JCompile";
  1119. } else if (ext == "asm" || ext == "s") {
  1120. tool = "ClCompile";
  1121. }
  1122. }
  1123. const char* toolOverride = sf->GetProperty("VS_TOOL_OVERRIDE");
  1124. if (toolOverride && *toolOverride) {
  1125. tool = toolOverride;
  1126. }
  1127. std::string deployContent;
  1128. std::string deployLocation;
  1129. if (this->GlobalGenerator->TargetsWindowsPhone() ||
  1130. this->GlobalGenerator->TargetsWindowsStore()) {
  1131. const char* content = sf->GetProperty("VS_DEPLOYMENT_CONTENT");
  1132. if (content && *content) {
  1133. toolHasSettings = true;
  1134. deployContent = content;
  1135. const char* location = sf->GetProperty("VS_DEPLOYMENT_LOCATION");
  1136. if (location && *location) {
  1137. deployLocation = location;
  1138. }
  1139. }
  1140. }
  1141. if (toolHasSettings) {
  1142. this->WriteSource(tool, sf, ">\n");
  1143. if (!deployContent.empty()) {
  1144. cmGeneratorExpression ge;
  1145. CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = ge.Parse(deployContent);
  1146. // Deployment location cannot be set on a configuration basis
  1147. if (!deployLocation.empty()) {
  1148. this->WriteString("<Link>", 3);
  1149. (*this->BuildFileStream) << deployLocation
  1150. << "\\%(FileName)%(Extension)";
  1151. this->WriteString("</Link>\n", 0);
  1152. }
  1153. for (size_t i = 0; i != this->Configurations.size(); ++i) {
  1154. if (0 == strcmp(cge->Evaluate(this->LocalGenerator,
  1155. this->Configurations[i]),
  1156. "1")) {
  1157. this->WriteString("<DeploymentContent Condition=\""
  1158. "'$(Configuration)|$(Platform)'=='",
  1159. 3);
  1160. (*this->BuildFileStream) << this->Configurations[i] << "|"
  1161. << this->Platform << "'\">true";
  1162. this->WriteString("</DeploymentContent>\n", 0);
  1163. } else {
  1164. this->WriteString("<ExcludedFromBuild Condition=\""
  1165. "'$(Configuration)|$(Platform)'=='",
  1166. 3);
  1167. (*this->BuildFileStream) << this->Configurations[i] << "|"
  1168. << this->Platform << "'\">true";
  1169. this->WriteString("</ExcludedFromBuild>\n", 0);
  1170. }
  1171. }
  1172. }
  1173. if (!shaderType.empty()) {
  1174. this->WriteString("<ShaderType>", 3);
  1175. (*this->BuildFileStream) << cmVS10EscapeXML(shaderType)
  1176. << "</ShaderType>\n";
  1177. }
  1178. if (!shaderEntryPoint.empty()) {
  1179. this->WriteString("<EntryPointName>", 3);
  1180. (*this->BuildFileStream) << cmVS10EscapeXML(shaderEntryPoint)
  1181. << "</EntryPointName>\n";
  1182. }
  1183. if (!shaderModel.empty()) {
  1184. this->WriteString("<ShaderModel>", 3);
  1185. (*this->BuildFileStream) << cmVS10EscapeXML(shaderModel)
  1186. << "</ShaderModel>\n";
  1187. }
  1188. if (!shaderAdditionalFlags.empty()) {
  1189. this->WriteString("<AdditionalOptions>", 3);
  1190. (*this->BuildFileStream) << cmVS10EscapeXML(shaderAdditionalFlags)
  1191. << "</AdditionalOptions>\n";
  1192. }
  1193. this->WriteString("</", 2);
  1194. (*this->BuildFileStream) << tool << ">\n";
  1195. } else {
  1196. this->WriteSource(tool, sf);
  1197. }
  1198. }
  1199. void cmVisualStudio10TargetGenerator::WriteSource(std::string const& tool,
  1200. cmSourceFile const* sf,
  1201. const char* end)
  1202. {
  1203. // Visual Studio tools append relative paths to the current dir, as in:
  1204. //
  1205. // c:\path\to\current\dir\..\..\..\relative\path\to\source.c
  1206. //
  1207. // and fail if this exceeds the maximum allowed path length. Our path
  1208. // conversion uses full paths when possible to allow deeper trees.
  1209. bool forceRelative = false;
  1210. std::string sourceFile = this->ConvertPath(sf->GetFullPath(), false);
  1211. if (this->LocalGenerator->GetVersion() ==
  1212. cmGlobalVisualStudioGenerator::VS10 &&
  1213. cmSystemTools::FileIsFullPath(sourceFile.c_str())) {
  1214. // Normal path conversion resulted in a full path. VS 10 (but not 11)
  1215. // refuses to show the property page in the IDE for a source file with a
  1216. // full path (not starting in a '.' or '/' AFAICT). CMake <= 2.8.4 used a
  1217. // relative path but to allow deeper build trees CMake 2.8.[5678] used a
  1218. // full path except for custom commands. Custom commands do not work
  1219. // without a relative path, but they do not seem to be involved in tools
  1220. // with the above behavior. For other sources we now use a relative path
  1221. // when the combined path will not be too long so property pages appear.
  1222. std::string sourceRel = this->ConvertPath(sf->GetFullPath(), true);
  1223. size_t const maxLen = 250;
  1224. if (sf->GetCustomCommand() ||
  1225. ((strlen(this->LocalGenerator->GetCurrentBinaryDirectory()) + 1 +
  1226. sourceRel.length()) <= maxLen)) {
  1227. forceRelative = true;
  1228. sourceFile = sourceRel;
  1229. } else {
  1230. this->GlobalGenerator->PathTooLong(this->GeneratorTarget, sf, sourceRel);
  1231. }
  1232. }
  1233. this->ConvertToWindowsSlash(sourceFile);
  1234. this->WriteString("<", 2);
  1235. (*this->BuildFileStream) << tool << " Include=\""
  1236. << cmVS10EscapeXML(sourceFile) << "\""
  1237. << (end ? end : " />\n");
  1238. ToolSource toolSource = { sf, forceRelative };
  1239. this->Tools[tool].push_back(toolSource);
  1240. }
  1241. void cmVisualStudio10TargetGenerator::WriteSources(
  1242. std::string const& tool, std::vector<cmSourceFile const*> const& sources)
  1243. {
  1244. for (std::vector<cmSourceFile const*>::const_iterator si = sources.begin();
  1245. si != sources.end(); ++si) {
  1246. this->WriteSource(tool, *si);
  1247. }
  1248. }
  1249. void cmVisualStudio10TargetGenerator::WriteAllSources()
  1250. {
  1251. if (this->GeneratorTarget->GetType() > cmState::UTILITY) {
  1252. return;
  1253. }
  1254. this->WriteString("<ItemGroup>\n", 1);
  1255. std::vector<cmSourceFile const*> headerSources;
  1256. this->GeneratorTarget->GetHeaderSources(headerSources, "");
  1257. for (std::vector<cmSourceFile const*>::const_iterator si =
  1258. headerSources.begin();
  1259. si != headerSources.end(); ++si) {
  1260. this->WriteHeaderSource(*si);
  1261. }
  1262. std::vector<cmSourceFile const*> idlSources;
  1263. this->GeneratorTarget->GetIDLSources(idlSources, "");
  1264. this->WriteSources("Midl", idlSources);
  1265. std::vector<cmSourceFile const*> objectSources;
  1266. this->GeneratorTarget->GetObjectSources(objectSources, "");
  1267. for (std::vector<cmSourceFile const*>::const_iterator si =
  1268. objectSources.begin();
  1269. si != objectSources.end(); ++si) {
  1270. const std::string& lang = (*si)->GetLanguage();
  1271. std::string tool;
  1272. if (lang == "C" || lang == "CXX") {
  1273. tool = "ClCompile";
  1274. } else if (lang == "ASM_MASM" && this->GlobalGenerator->IsMasmEnabled()) {
  1275. tool = "MASM";
  1276. } else if (lang == "RC") {
  1277. tool = "ResourceCompile";
  1278. }
  1279. if (!tool.empty()) {
  1280. this->WriteSource(tool, *si, " ");
  1281. if (this->OutputSourceSpecificFlags(*si)) {
  1282. this->WriteString("</", 2);
  1283. (*this->BuildFileStream) << tool << ">\n";
  1284. } else {
  1285. (*this->BuildFileStream) << " />\n";
  1286. }
  1287. } else {
  1288. this->WriteSource("None", *si);
  1289. }
  1290. }
  1291. std::vector<cmSourceFile const*> manifestSources;
  1292. this->GeneratorTarget->GetAppManifest(manifestSources, "");
  1293. this->WriteSources("AppxManifest", manifestSources);
  1294. std::vector<cmSourceFile const*> certificateSources;
  1295. this->GeneratorTarget->GetCertificates(certificateSources, "");
  1296. this->WriteSources("None", certificateSources);
  1297. std::vector<cmSourceFile const*> externalObjects;
  1298. this->GeneratorTarget->GetExternalObjects(externalObjects, "");
  1299. for (std::vector<cmSourceFile const*>::iterator si = externalObjects.begin();
  1300. si != externalObjects.end();) {
  1301. if (!(*si)->GetObjectLibrary().empty()) {
  1302. si = externalObjects.erase(si);
  1303. } else {
  1304. ++si;
  1305. }
  1306. }
  1307. if (this->LocalGenerator->GetVersion() >
  1308. cmGlobalVisualStudioGenerator::VS10) {
  1309. // For VS >= 11 we use LinkObjects to avoid linking custom command
  1310. // outputs. Use Object for all external objects, generated or not.
  1311. this->WriteSources("Object", externalObjects);
  1312. } else {
  1313. // If an object file is generated in this target, then vs10 will use
  1314. // it in the build, and we have to list it as None instead of Object.
  1315. for (std::vector<cmSourceFile const*>::const_iterator si =
  1316. externalObjects.begin();
  1317. si != externalObjects.end(); ++si) {
  1318. std::vector<cmSourceFile*> const* d =
  1319. this->GeneratorTarget->GetSourceDepends(*si);
  1320. this->WriteSource((d && !d->empty()) ? "None" : "Object", *si);
  1321. }
  1322. }
  1323. std::vector<cmSourceFile const*> extraSources;
  1324. this->GeneratorTarget->GetExtraSources(extraSources, "");
  1325. for (std::vector<cmSourceFile const*>::const_iterator si =
  1326. extraSources.begin();
  1327. si != extraSources.end(); ++si) {
  1328. this->WriteExtraSource(*si);
  1329. }
  1330. // Add object library contents as external objects.
  1331. std::vector<std::string> objs;
  1332. this->GeneratorTarget->UseObjectLibraries(objs, "");
  1333. for (std::vector<std::string>::const_iterator oi = objs.begin();
  1334. oi != objs.end(); ++oi) {
  1335. std::string obj = *oi;
  1336. this->WriteString("<Object Include=\"", 2);
  1337. this->ConvertToWindowsSlash(obj);
  1338. (*this->BuildFileStream) << cmVS10EscapeXML(obj) << "\" />\n";
  1339. }
  1340. if (cmSourceFile const* defsrc =
  1341. this->GeneratorTarget->GetModuleDefinitionFile("")) {
  1342. this->WriteSource("None", defsrc);
  1343. }
  1344. if (this->IsMissingFiles) {
  1345. this->WriteMissingFiles();
  1346. }
  1347. this->WriteString("</ItemGroup>\n", 1);
  1348. }
  1349. bool cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags(
  1350. cmSourceFile const* source)
  1351. {
  1352. cmSourceFile const& sf = *source;
  1353. std::string objectName;
  1354. if (this->GeneratorTarget->HasExplicitObjectName(&sf)) {
  1355. objectName = this->GeneratorTarget->GetObjectName(&sf);
  1356. }
  1357. std::string flags;
  1358. std::string defines;
  1359. if (const char* cflags = sf.GetProperty("COMPILE_FLAGS")) {
  1360. flags += cflags;
  1361. }
  1362. if (const char* cdefs = sf.GetProperty("COMPILE_DEFINITIONS")) {
  1363. defines += cdefs;
  1364. }
  1365. std::string lang =
  1366. this->GlobalGenerator->GetLanguageFromExtension(sf.GetExtension().c_str());
  1367. std::string sourceLang = this->LocalGenerator->GetSourceFileLanguage(sf);
  1368. const std::string& linkLanguage = this->GeneratorTarget->GetLinkerLanguage();
  1369. bool needForceLang = false;
  1370. // source file does not match its extension language
  1371. if (lang != sourceLang) {
  1372. needForceLang = true;
  1373. lang = sourceLang;
  1374. }
  1375. // if the source file does not match the linker language
  1376. // then force c or c++
  1377. const char* compileAs = 0;
  1378. if (needForceLang || (linkLanguage != lang)) {
  1379. if (lang == "CXX") {
  1380. // force a C++ file type
  1381. compileAs = "CompileAsCpp";
  1382. } else if (lang == "C") {
  1383. // force to c
  1384. compileAs = "CompileAsC";
  1385. }
  1386. }
  1387. bool noWinRT = this->TargetCompileAsWinRT && lang == "C";
  1388. bool hasFlags = false;
  1389. // for the first time we need a new line if there is something
  1390. // produced here.
  1391. const char* firstString = ">\n";
  1392. if (!objectName.empty()) {
  1393. (*this->BuildFileStream) << firstString;
  1394. firstString = "";
  1395. hasFlags = true;
  1396. this->WriteString("<ObjectFileName>", 3);
  1397. (*this->BuildFileStream) << "$(IntDir)/" << objectName
  1398. << "</ObjectFileName>\n";
  1399. }
  1400. for (std::vector<std::string>::const_iterator config =
  1401. this->Configurations.begin();
  1402. config != this->Configurations.end(); ++config) {
  1403. std::string configUpper = cmSystemTools::UpperCase(*config);
  1404. std::string configDefines = defines;
  1405. std::string defPropName = "COMPILE_DEFINITIONS_";
  1406. defPropName += configUpper;
  1407. if (const char* ccdefs = sf.GetProperty(defPropName.c_str())) {
  1408. if (!configDefines.empty()) {
  1409. configDefines += ";";
  1410. }
  1411. configDefines += ccdefs;
  1412. }
  1413. // if we have flags or defines for this config then
  1414. // use them
  1415. if (!flags.empty() || !configDefines.empty() || compileAs || noWinRT) {
  1416. (*this->BuildFileStream) << firstString;
  1417. firstString = ""; // only do firstString once
  1418. hasFlags = true;
  1419. cmVisualStudioGeneratorOptions clOptions(
  1420. this->LocalGenerator, cmVisualStudioGeneratorOptions::Compiler,
  1421. this->GetClFlagTable(), 0, this);
  1422. if (compileAs) {
  1423. clOptions.AddFlag("CompileAs", compileAs);
  1424. }
  1425. if (noWinRT) {
  1426. clOptions.AddFlag("CompileAsWinRT", "false");
  1427. }
  1428. clOptions.Parse(flags.c_str());
  1429. if (clOptions.HasFlag("AdditionalIncludeDirectories")) {
  1430. clOptions.AppendFlag("AdditionalIncludeDirectories",
  1431. "%(AdditionalIncludeDirectories)");
  1432. }
  1433. if (clOptions.HasFlag("DisableSpecificWarnings")) {
  1434. clOptions.AppendFlag("DisableSpecificWarnings",
  1435. "%(DisableSpecificWarnings)");
  1436. }
  1437. clOptions.AddDefines(configDefines.c_str());
  1438. clOptions.SetConfiguration((*config).c_str());
  1439. clOptions.OutputAdditionalOptions(*this->BuildFileStream, " ", "");
  1440. clOptions.OutputFlagMap(*this->BuildFileStream, " ");
  1441. clOptions.OutputPreprocessorDefinitions(*this->BuildFileStream, " ",
  1442. "\n", lang);
  1443. }
  1444. }
  1445. if (this->IsXamlSource(source->GetFullPath())) {
  1446. (*this->BuildFileStream) << firstString;
  1447. firstString = ""; // only do firstString once
  1448. hasFlags = true;
  1449. this->WriteString("<DependentUpon>", 3);
  1450. const std::string& fileName = source->GetFullPath();
  1451. std::string xamlFileName = fileName.substr(0, fileName.find_last_of("."));
  1452. (*this->BuildFileStream) << xamlFileName << "</DependentUpon>\n";
  1453. }
  1454. return hasFlags;
  1455. }
  1456. void cmVisualStudio10TargetGenerator::WritePathAndIncrementalLinkOptions()
  1457. {
  1458. cmState::TargetType ttype = this->GeneratorTarget->GetType();
  1459. if (ttype > cmState::GLOBAL_TARGET) {
  1460. return;
  1461. }
  1462. this->WriteString("<PropertyGroup>\n", 2);
  1463. this->WriteString("<_ProjectFileVersion>10.0.20506.1"
  1464. "</_ProjectFileVersion>\n",
  1465. 3);
  1466. for (std::vector<std::string>::const_iterator config =
  1467. this->Configurations.begin();
  1468. config != this->Configurations.end(); ++config) {
  1469. if (ttype >= cmState::UTILITY) {
  1470. this->WritePlatformConfigTag("IntDir", config->c_str(), 3);
  1471. *this->BuildFileStream
  1472. << "$(Platform)\\$(Configuration)\\$(ProjectName)\\"
  1473. << "</IntDir>\n";
  1474. } else {
  1475. std::string intermediateDir =
  1476. this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
  1477. intermediateDir += "/";
  1478. intermediateDir += *config;
  1479. intermediateDir += "/";
  1480. std::string outDir;
  1481. std::string targetNameFull;
  1482. if (ttype == cmState::OBJECT_LIBRARY) {
  1483. outDir = intermediateDir;
  1484. targetNameFull = this->GeneratorTarget->GetName();
  1485. targetNameFull += ".lib";
  1486. } else {
  1487. outDir = this->GeneratorTarget->GetDirectory(config->c_str()) + "/";
  1488. targetNameFull = this->GeneratorTarget->GetFullName(config->c_str());
  1489. }
  1490. this->ConvertToWindowsSlash(intermediateDir);
  1491. this->ConvertToWindowsSlash(outDir);
  1492. this->WritePlatformConfigTag("OutDir", config->c_str(), 3);
  1493. *this->BuildFileStream << cmVS10EscapeXML(outDir) << "</OutDir>\n";
  1494. this->WritePlatformConfigTag("IntDir", config->c_str(), 3);
  1495. *this->BuildFileStream << cmVS10EscapeXML(intermediateDir)
  1496. << "</IntDir>\n";
  1497. std::string name =
  1498. cmSystemTools::GetFilenameWithoutLastExtension(targetNameFull);
  1499. this->WritePlatformConfigTag("TargetName", config->c_str(), 3);
  1500. *this->BuildFileStream << cmVS10EscapeXML(name) << "</TargetName>\n";
  1501. std::string ext =
  1502. cmSystemTools::GetFilenameLastExtension(targetNameFull);
  1503. if (ext.empty()) {
  1504. // An empty TargetExt causes a default extension to be used.
  1505. // A single "." appears to be treated as an empty extension.
  1506. ext = ".";
  1507. }
  1508. this->WritePlatformConfigTag("TargetExt", config->c_str(), 3);
  1509. *this->BuildFileStream << cmVS10EscapeXML(ext) << "</TargetExt>\n";
  1510. this->OutputLinkIncremental(*config);
  1511. }
  1512. }
  1513. this->WriteString("</PropertyGroup>\n", 2);
  1514. }
  1515. void cmVisualStudio10TargetGenerator::OutputLinkIncremental(
  1516. std::string const& configName)
  1517. {
  1518. if (!this->MSTools) {
  1519. return;
  1520. }
  1521. // static libraries and things greater than modules do not need
  1522. // to set this option
  1523. if (this->GeneratorTarget->GetType() == cmState::STATIC_LIBRARY ||
  1524. this->GeneratorTarget->GetType() > cmState::MODULE_LIBRARY) {
  1525. return;
  1526. }
  1527. Options& linkOptions = *(this->LinkOptions[configName]);
  1528. const char* incremental = linkOptions.GetFlag("LinkIncremental");
  1529. this->WritePlatformConfigTag("LinkIncremental", configName.c_str(), 3);
  1530. *this->BuildFileStream << (incremental ? incremental : "true")
  1531. << "</LinkIncremental>\n";
  1532. linkOptions.RemoveFlag("LinkIncremental");
  1533. const char* manifest = linkOptions.GetFlag("GenerateManifest");
  1534. this->WritePlatformConfigTag("GenerateManifest", configName.c_str(), 3);
  1535. *this->BuildFileStream << (manifest ? manifest : "true")
  1536. << "</GenerateManifest>\n";
  1537. linkOptions.RemoveFlag("GenerateManifest");
  1538. // Some link options belong here. Use them now and remove them so that
  1539. // WriteLinkOptions does not use them.
  1540. const char* flags[] = { "LinkDelaySign", "LinkKeyFile", 0 };
  1541. for (const char** f = flags; *f; ++f) {
  1542. const char* flag = *f;
  1543. if (const char* value = linkOptions.GetFlag(flag)) {
  1544. this->WritePlatformConfigTag(flag, configName.c_str(), 3);
  1545. *this->BuildFileStream << value << "</" << flag << ">\n";
  1546. linkOptions.RemoveFlag(flag);
  1547. }
  1548. }
  1549. }
  1550. bool cmVisualStudio10TargetGenerator::ComputeClOptions()
  1551. {
  1552. for (std::vector<std::string>::const_iterator i =
  1553. this->Configurations.begin();
  1554. i != this->Configurations.end(); ++i) {
  1555. if (!this->ComputeClOptions(*i)) {
  1556. return false;
  1557. }
  1558. }
  1559. return true;
  1560. }
  1561. bool cmVisualStudio10TargetGenerator::ComputeClOptions(
  1562. std::string const& configName)
  1563. {
  1564. // much of this was copied from here:
  1565. // copied from cmLocalVisualStudio7Generator.cxx 805
  1566. // TODO: Integrate code below with cmLocalVisualStudio7Generator.
  1567. CM_AUTO_PTR<Options> pOptions(new Options(
  1568. this->LocalGenerator, Options::Compiler, this->GetClFlagTable()));
  1569. Options& clOptions = *pOptions;
  1570. std::string flags;
  1571. const std::string& linkLanguage =
  1572. this->GeneratorTarget->GetLinkerLanguage(configName.c_str());
  1573. if (linkLanguage.empty()) {
  1574. cmSystemTools::Error(
  1575. "CMake can not determine linker language for target: ",
  1576. this->Name.c_str());
  1577. return false;
  1578. }
  1579. if (linkLanguage == "C" || linkLanguage == "CXX" ||
  1580. linkLanguage == "Fortran") {
  1581. std::string baseFlagVar = "CMAKE_";
  1582. baseFlagVar += linkLanguage;
  1583. baseFlagVar += "_FLAGS";
  1584. flags =
  1585. this->GeneratorTarget->Target->GetMakefile()->GetRequiredDefinition(
  1586. baseFlagVar.c_str());
  1587. std::string flagVar =
  1588. baseFlagVar + std::string("_") + cmSystemTools::UpperCase(configName);
  1589. flags += " ";
  1590. flags +=
  1591. this->GeneratorTarget->Target->GetMakefile()->GetRequiredDefinition(
  1592. flagVar.c_str());
  1593. }
  1594. // set the correct language
  1595. if (linkLanguage == "C") {
  1596. clOptions.AddFlag("CompileAs", "CompileAsC");
  1597. }
  1598. if (linkLanguage == "CXX") {
  1599. clOptions.AddFlag("CompileAs", "CompileAsCpp");
  1600. }
  1601. this->LocalGenerator->AddCompileOptions(flags, this->GeneratorTarget,
  1602. linkLanguage, configName.c_str());
  1603. // Get preprocessor definitions for this directory.
  1604. std::string defineFlags =
  1605. this->GeneratorTarget->Target->GetMakefile()->GetDefineFlags();
  1606. if (this->MSTools) {
  1607. clOptions.FixExceptionHandlingDefault();
  1608. clOptions.AddFlag("PrecompiledHeader", "NotUsing");
  1609. std::string asmLocation = configName + "/";
  1610. clOptions.AddFlag("AssemblerListingLocation", asmLocation.c_str());
  1611. }
  1612. clOptions.Parse(flags.c_str());
  1613. clOptions.Parse(defineFlags.c_str());
  1614. std::vector<std::string> targetDefines;
  1615. this->GeneratorTarget->GetCompileDefinitions(targetDefines,
  1616. configName.c_str(), "CXX");
  1617. clOptions.AddDefines(targetDefines);
  1618. if (this->MSTools) {
  1619. clOptions.SetVerboseMakefile(
  1620. this->Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE"));
  1621. }
  1622. // Add a definition for the configuration name.
  1623. std::string configDefine = "CMAKE_INTDIR=\"";
  1624. configDefine += configName;
  1625. configDefine += "\"";
  1626. clOptions.AddDefine(configDefine);
  1627. if (const char* exportMacro = this->GeneratorTarget->GetExportMacro()) {
  1628. clOptions.AddDefine(exportMacro);
  1629. }
  1630. if (this->MSTools) {
  1631. // If we have the VS_WINRT_COMPONENT set then force Compile as WinRT.
  1632. if (this->GeneratorTarget->GetPropertyAsBool("VS_WINRT_COMPONENT")) {
  1633. clOptions.AddFlag("CompileAsWinRT", "true");
  1634. // For WinRT components, add the _WINRT_DLL define to produce a lib
  1635. if (this->GeneratorTarget->GetType() == cmState::SHARED_LIBRARY ||
  1636. this->GeneratorTarget->GetType() == cmState::MODULE_LIBRARY) {
  1637. clOptions.AddDefine("_WINRT_DLL");
  1638. }
  1639. } else if (this->GlobalGenerator->TargetsWindowsStore() ||
  1640. this->GlobalGenerator->TargetsWindowsPhone()) {
  1641. if (!clOptions.IsWinRt()) {
  1642. clOptions.AddFlag("CompileAsWinRT", "false");
  1643. }
  1644. }
  1645. if (const char* winRT = clOptions.GetFlag("CompileAsWinRT")) {
  1646. if (cmSystemTools::IsOn(winRT)) {
  1647. this->TargetCompileAsWinRT = true;
  1648. }
  1649. }
  1650. }
  1651. this->ClOptions[configName] = pOptions.release();
  1652. return true;
  1653. }
  1654. void cmVisualStudio10TargetGenerator::WriteClOptions(
  1655. std::string const& configName, std::vector<std::string> const& includes)
  1656. {
  1657. Options& clOptions = *(this->ClOptions[configName]);
  1658. this->WriteString("<ClCompile>\n", 2);
  1659. clOptions.OutputAdditionalOptions(*this->BuildFileStream, " ", "");
  1660. clOptions.AppendFlag("AdditionalIncludeDirectories", includes);
  1661. clOptions.AppendFlag("AdditionalIncludeDirectories",
  1662. "%(AdditionalIncludeDirectories)");
  1663. clOptions.OutputFlagMap(*this->BuildFileStream, " ");
  1664. clOptions.OutputPreprocessorDefinitions(*this->BuildFileStream, " ",
  1665. "\n", "CXX");
  1666. if (this->NsightTegra) {
  1667. if (const char* processMax =
  1668. this->GeneratorTarget->GetProperty("ANDROID_PROCESS_MAX")) {
  1669. this->WriteString("<ProcessMax>", 3);
  1670. *this->BuildFileStream << cmVS10EscapeXML(processMax)
  1671. << "</ProcessMax>\n";
  1672. }
  1673. }
  1674. if (this->MSTools) {
  1675. cmsys::RegularExpression clangToolset("v[0-9]+_clang_.*");
  1676. const char* toolset = this->GlobalGenerator->GetPlatformToolset();
  1677. if (toolset && clangToolset.find(toolset)) {
  1678. this->WriteString("<ObjectFileName>"
  1679. "$(IntDir)%(filename).obj"
  1680. "</ObjectFileName>\n",
  1681. 3);
  1682. } else {
  1683. this->WriteString("<ObjectFileName>$(IntDir)</ObjectFileName>\n", 3);
  1684. }
  1685. // If not in debug mode, write the DebugInformationFormat field
  1686. // without value so PDBs don't get generated uselessly.
  1687. if (!clOptions.IsDebug()) {
  1688. this->WriteString("<DebugInformationFormat>"
  1689. "</DebugInformationFormat>\n",
  1690. 3);
  1691. }
  1692. // Specify the compiler program database file if configured.
  1693. std::string pdb =
  1694. this->GeneratorTarget->GetCompilePDBPath(configName.c_str());
  1695. if (!pdb.empty()) {
  1696. this->ConvertToWindowsSlash(pdb);
  1697. this->WriteString("<ProgramDataBaseFileName>", 3);
  1698. *this->BuildFileStream << cmVS10EscapeXML(pdb)
  1699. << "</ProgramDataBaseFileName>\n";
  1700. }
  1701. }
  1702. this->WriteString("</ClCompile>\n", 2);
  1703. }
  1704. bool cmVisualStudio10TargetGenerator::ComputeRcOptions()
  1705. {
  1706. for (std::vector<std::string>::const_iterator i =
  1707. this->Configurations.begin();
  1708. i != this->Configurations.end(); ++i) {
  1709. if (!this->ComputeRcOptions(*i)) {
  1710. return false;
  1711. }
  1712. }
  1713. return true;
  1714. }
  1715. bool cmVisualStudio10TargetGenerator::ComputeRcOptions(
  1716. std::string const& configName)
  1717. {
  1718. CM_AUTO_PTR<Options> pOptions(new Options(
  1719. this->LocalGenerator, Options::ResourceCompiler, this->GetRcFlagTable()));
  1720. Options& rcOptions = *pOptions;
  1721. std::string CONFIG = cmSystemTools::UpperCase(configName);
  1722. std::string rcConfigFlagsVar = std::string("CMAKE_RC_FLAGS_") + CONFIG;
  1723. std::string flags =
  1724. std::string(this->Makefile->GetSafeDefinition("CMAKE_RC_FLAGS")) +
  1725. std::string(" ") +
  1726. std::string(this->Makefile->GetSafeDefinition(rcConfigFlagsVar));
  1727. rcOptions.Parse(flags.c_str());
  1728. this->RcOptions[configName] = pOptions.release();
  1729. return true;
  1730. }
  1731. void cmVisualStudio10TargetGenerator::WriteRCOptions(
  1732. std::string const& configName, std::vector<std::string> const& includes)
  1733. {
  1734. if (!this->MSTools) {
  1735. return;
  1736. }
  1737. this->WriteString("<ResourceCompile>\n", 2);
  1738. // Preprocessor definitions and includes are shared with clOptions.
  1739. Options& clOptions = *(this->ClOptions[configName]);
  1740. clOptions.OutputPreprocessorDefinitions(*this->BuildFileStream, " ",
  1741. "\n", "RC");
  1742. Options& rcOptions = *(this->RcOptions[configName]);
  1743. rcOptions.AppendFlag("AdditionalIncludeDirectories", includes);
  1744. rcOptions.AppendFlag("AdditionalIncludeDirectories",
  1745. "%(AdditionalIncludeDirectories)");
  1746. rcOptions.OutputFlagMap(*this->BuildFileStream, " ");
  1747. rcOptions.OutputAdditionalOptions(*this->BuildFileStream, " ", "");
  1748. this->WriteString("</ResourceCompile>\n", 2);
  1749. }
  1750. bool cmVisualStudio10TargetGenerator::ComputeMasmOptions()
  1751. {
  1752. if (!this->GlobalGenerator->IsMasmEnabled()) {
  1753. return true;
  1754. }
  1755. for (std::vector<std::string>::const_iterator i =
  1756. this->Configurations.begin();
  1757. i != this->Configurations.end(); ++i) {
  1758. if (!this->ComputeMasmOptions(*i)) {
  1759. return false;
  1760. }
  1761. }
  1762. return true;
  1763. }
  1764. bool cmVisualStudio10TargetGenerator::ComputeMasmOptions(
  1765. std::string const& configName)
  1766. {
  1767. CM_AUTO_PTR<Options> pOptions(new Options(
  1768. this->LocalGenerator, Options::MasmCompiler, this->GetMasmFlagTable()));
  1769. Options& masmOptions = *pOptions;
  1770. std::string CONFIG = cmSystemTools::UpperCase(configName);
  1771. std::string configFlagsVar = std::string("CMAKE_ASM_MASM_FLAGS_") + CONFIG;
  1772. std::string flags =
  1773. std::string(this->Makefile->GetSafeDefinition("CMAKE_ASM_MASM_FLAGS")) +
  1774. std::string(" ") +
  1775. std::string(this->Makefile->GetSafeDefinition(configFlagsVar));
  1776. masmOptions.Parse(flags.c_str());
  1777. this->MasmOptions[configName] = pOptions.release();
  1778. return true;
  1779. }
  1780. void cmVisualStudio10TargetGenerator::WriteMasmOptions(
  1781. std::string const& configName, std::vector<std::string> const& includes)
  1782. {
  1783. if (!this->MSTools || !this->GlobalGenerator->IsMasmEnabled()) {
  1784. return;
  1785. }
  1786. this->WriteString("<MASM>\n", 2);
  1787. // Preprocessor definitions and includes are shared with clOptions.
  1788. Options& clOptions = *(this->ClOptions[configName]);
  1789. clOptions.OutputPreprocessorDefinitions(*this->BuildFileStream, " ",
  1790. "\n", "ASM_MASM");
  1791. Options& masmOptions = *(this->MasmOptions[configName]);
  1792. masmOptions.AppendFlag("IncludePaths", includes);
  1793. masmOptions.AppendFlag("IncludePaths", "%(IncludePaths)");
  1794. masmOptions.OutputFlagMap(*this->BuildFileStream, " ");
  1795. masmOptions.OutputAdditionalOptions(*this->BuildFileStream, " ", "");
  1796. this->WriteString("</MASM>\n", 2);
  1797. }
  1798. void cmVisualStudio10TargetGenerator::WriteLibOptions(
  1799. std::string const& config)
  1800. {
  1801. if (this->GeneratorTarget->GetType() != cmState::STATIC_LIBRARY &&
  1802. this->GeneratorTarget->GetType() != cmState::OBJECT_LIBRARY) {
  1803. return;
  1804. }
  1805. std::string libflags;
  1806. this->LocalGenerator->GetStaticLibraryFlags(
  1807. libflags, cmSystemTools::UpperCase(config), this->GeneratorTarget);
  1808. if (!libflags.empty()) {
  1809. this->WriteString("<Lib>\n", 2);
  1810. cmVisualStudioGeneratorOptions libOptions(
  1811. this->LocalGenerator, cmVisualStudioGeneratorOptions::Linker,
  1812. this->GetLibFlagTable(), 0, this);
  1813. libOptions.Parse(libflags.c_str());
  1814. libOptions.OutputAdditionalOptions(*this->BuildFileStream, " ", "");
  1815. libOptions.OutputFlagMap(*this->BuildFileStream, " ");
  1816. this->WriteString("</Lib>\n", 2);
  1817. }
  1818. // We cannot generate metadata for static libraries. WindowsPhone
  1819. // and WindowsStore tools look at GenerateWindowsMetadata in the
  1820. // Link tool options even for static libraries.
  1821. if (this->GlobalGenerator->TargetsWindowsPhone() ||
  1822. this->GlobalGenerator->TargetsWindowsStore()) {
  1823. this->WriteString("<Link>\n", 2);
  1824. this->WriteString("<GenerateWindowsMetadata>false"
  1825. "</GenerateWindowsMetadata>\n",
  1826. 3);
  1827. this->WriteString("</Link>\n", 2);
  1828. }
  1829. }
  1830. void cmVisualStudio10TargetGenerator::WriteManifestOptions(
  1831. std::string const& config)
  1832. {
  1833. if (this->GeneratorTarget->GetType() != cmState::EXECUTABLE &&
  1834. this->GeneratorTarget->GetType() != cmState::SHARED_LIBRARY &&
  1835. this->GeneratorTarget->GetType() != cmState::MODULE_LIBRARY) {
  1836. return;
  1837. }
  1838. std::vector<cmSourceFile const*> manifest_srcs;
  1839. this->GeneratorTarget->GetManifests(manifest_srcs, config);
  1840. if (!manifest_srcs.empty()) {
  1841. this->WriteString("<Manifest>\n", 2);
  1842. this->WriteString("<AdditionalManifestFiles>", 3);
  1843. for (std::vector<cmSourceFile const*>::const_iterator mi =
  1844. manifest_srcs.begin();
  1845. mi != manifest_srcs.end(); ++mi) {
  1846. std::string m = this->ConvertPath((*mi)->GetFullPath(), false);
  1847. this->ConvertToWindowsSlash(m);
  1848. (*this->BuildFileStream) << m << ";";
  1849. }
  1850. (*this->BuildFileStream) << "</AdditionalManifestFiles>\n";
  1851. this->WriteString("</Manifest>\n", 2);
  1852. }
  1853. }
  1854. void cmVisualStudio10TargetGenerator::WriteAntBuildOptions(
  1855. std::string const& configName)
  1856. {
  1857. // Look through the sources for AndroidManifest.xml and use
  1858. // its location as the root source directory.
  1859. std::string rootDir = this->LocalGenerator->GetCurrentSourceDirectory();
  1860. {
  1861. std::vector<cmSourceFile const*> extraSources;
  1862. this->GeneratorTarget->GetExtraSources(extraSources, "");
  1863. for (std::vector<cmSourceFile const*>::const_iterator si =
  1864. extraSources.begin();
  1865. si != extraSources.end(); ++si) {
  1866. if ("androidmanifest.xml" ==
  1867. cmSystemTools::LowerCase((*si)->GetLocation().GetName())) {
  1868. rootDir = (*si)->GetLocation().GetDirectory();
  1869. break;
  1870. }
  1871. }
  1872. }
  1873. // Tell MSBuild to launch Ant.
  1874. {
  1875. std::string antBuildPath = rootDir;
  1876. this->WriteString("<AntBuild>\n", 2);
  1877. this->WriteString("<AntBuildPath>", 3);
  1878. this->ConvertToWindowsSlash(antBuildPath);
  1879. (*this->BuildFileStream) << cmVS10EscapeXML(antBuildPath)
  1880. << "</AntBuildPath>\n";
  1881. }
  1882. if (this->GeneratorTarget->GetPropertyAsBool("ANDROID_SKIP_ANT_STEP")) {
  1883. this->WriteString("<SkipAntStep>true</SkipAntStep>\n", 3);
  1884. }
  1885. if (this->GeneratorTarget->GetPropertyAsBool("ANDROID_PROGUARD")) {
  1886. this->WriteString("<EnableProGuard>true</EnableProGuard>\n", 3);
  1887. }
  1888. if (const char* proGuardConfigLocation =
  1889. this->GeneratorTarget->GetProperty("ANDROID_PROGUARD_CONFIG_PATH")) {
  1890. this->WriteString("<ProGuardConfigLocation>", 3);
  1891. (*this->BuildFileStream) << cmVS10EscapeXML(proGuardConfigLocation)
  1892. << "</ProGuardConfigLocation>\n";
  1893. }
  1894. if (const char* securePropertiesLocation =
  1895. this->GeneratorTarget->GetProperty("ANDROID_SECURE_PROPS_PATH")) {
  1896. this->WriteString("<SecurePropertiesLocation>", 3);
  1897. (*this->BuildFileStream) << cmVS10EscapeXML(securePropertiesLocation)
  1898. << "</SecurePropertiesLocation>\n";
  1899. }
  1900. if (const char* nativeLibDirectoriesExpression =
  1901. this->GeneratorTarget->GetProperty("ANDROID_NATIVE_LIB_DIRECTORIES")) {
  1902. cmGeneratorExpression ge;
  1903. CM_AUTO_PTR<cmCompiledGeneratorExpression> cge =
  1904. ge.Parse(nativeLibDirectoriesExpression);
  1905. std::string nativeLibDirs =
  1906. cge->Evaluate(this->LocalGenerator, configName);
  1907. this->WriteString("<NativeLibDirectories>", 3);
  1908. (*this->BuildFileStream) << cmVS10EscapeXML(nativeLibDirs)
  1909. << "</NativeLibDirectories>\n";
  1910. }
  1911. if (const char* nativeLibDependenciesExpression =
  1912. this->GeneratorTarget->GetProperty(
  1913. "ANDROID_NATIVE_LIB_DEPENDENCIES")) {
  1914. cmGeneratorExpression ge;
  1915. CM_AUTO_PTR<cmCompiledGeneratorExpression> cge =
  1916. ge.Parse(nativeLibDependenciesExpression);
  1917. std::string nativeLibDeps =
  1918. cge->Evaluate(this->LocalGenerator, configName);
  1919. this->WriteString("<NativeLibDependencies>", 3);
  1920. (*this->BuildFileStream) << cmVS10EscapeXML(nativeLibDeps)
  1921. << "</NativeLibDependencies>\n";
  1922. }
  1923. if (const char* javaSourceDir =
  1924. this->GeneratorTarget->GetProperty("ANDROID_JAVA_SOURCE_DIR")) {
  1925. this->WriteString("<JavaSourceDir>", 3);
  1926. (*this->BuildFileStream) << cmVS10EscapeXML(javaSourceDir)
  1927. << "</JavaSourceDir>\n";
  1928. }
  1929. if (const char* jarDirectoriesExpression =
  1930. this->GeneratorTarget->GetProperty("ANDROID_JAR_DIRECTORIES")) {
  1931. cmGeneratorExpression ge;
  1932. CM_AUTO_PTR<cmCompiledGeneratorExpression> cge =
  1933. ge.Parse(jarDirectoriesExpression);
  1934. std::string jarDirectories =
  1935. cge->Evaluate(this->LocalGenerator, configName);
  1936. this->WriteString("<JarDirectories>", 3);
  1937. (*this->BuildFileStream) << cmVS10EscapeXML(jarDirectories)
  1938. << "</JarDirectories>\n";
  1939. }
  1940. if (const char* jarDeps =
  1941. this->GeneratorTarget->GetProperty("ANDROID_JAR_DEPENDENCIES")) {
  1942. this->WriteString("<JarDependencies>", 3);
  1943. (*this->BuildFileStream) << cmVS10EscapeXML(jarDeps)
  1944. << "</JarDependencies>\n";
  1945. }
  1946. if (const char* assetsDirectories =
  1947. this->GeneratorTarget->GetProperty("ANDROID_ASSETS_DIRECTORIES")) {
  1948. this->WriteString("<AssetsDirectories>", 3);
  1949. (*this->BuildFileStream) << cmVS10EscapeXML(assetsDirectories)
  1950. << "</AssetsDirectories>\n";
  1951. }
  1952. {
  1953. std::string manifest_xml = rootDir + "/AndroidManifest.xml";
  1954. this->ConvertToWindowsSlash(manifest_xml);
  1955. this->WriteString("<AndroidManifestLocation>", 3);
  1956. (*this->BuildFileStream) << cmVS10EscapeXML(manifest_xml)
  1957. << "</AndroidManifestLocation>\n";
  1958. }
  1959. if (const char* antAdditionalOptions =
  1960. this->GeneratorTarget->GetProperty("ANDROID_ANT_ADDITIONAL_OPTIONS")) {
  1961. this->WriteString("<AdditionalOptions>", 3);
  1962. (*this->BuildFileStream) << cmVS10EscapeXML(antAdditionalOptions)
  1963. << " %(AdditionalOptions)</AdditionalOptions>\n";
  1964. }
  1965. this->WriteString("</AntBuild>\n", 2);
  1966. }
  1967. bool cmVisualStudio10TargetGenerator::ComputeLinkOptions()
  1968. {
  1969. if (this->GeneratorTarget->GetType() == cmState::EXECUTABLE ||
  1970. this->GeneratorTarget->GetType() == cmState::SHARED_LIBRARY ||
  1971. this->GeneratorTarget->GetType() == cmState::MODULE_LIBRARY) {
  1972. for (std::vector<std::string>::const_iterator i =
  1973. this->Configurations.begin();
  1974. i != this->Configurations.end(); ++i) {
  1975. if (!this->ComputeLinkOptions(*i)) {
  1976. return false;
  1977. }
  1978. }
  1979. }
  1980. return true;
  1981. }
  1982. bool cmVisualStudio10TargetGenerator::ComputeLinkOptions(
  1983. std::string const& config)
  1984. {
  1985. CM_AUTO_PTR<Options> pOptions(new Options(
  1986. this->LocalGenerator, Options::Linker, this->GetLinkFlagTable(), 0, this));
  1987. Options& linkOptions = *pOptions;
  1988. const std::string& linkLanguage =
  1989. this->GeneratorTarget->GetLinkerLanguage(config.c_str());
  1990. if (linkLanguage.empty()) {
  1991. cmSystemTools::Error(
  1992. "CMake can not determine linker language for target: ",
  1993. this->Name.c_str());
  1994. return false;
  1995. }
  1996. std::string CONFIG = cmSystemTools::UpperCase(config);
  1997. const char* linkType = "SHARED";
  1998. if (this->GeneratorTarget->GetType() == cmState::MODULE_LIBRARY) {
  1999. linkType = "MODULE";
  2000. }
  2001. if (this->GeneratorTarget->GetType() == cmState::EXECUTABLE) {
  2002. linkType = "EXE";
  2003. }
  2004. std::string flags;
  2005. std::string linkFlagVarBase = "CMAKE_";
  2006. linkFlagVarBase += linkType;
  2007. linkFlagVarBase += "_LINKER_FLAGS";
  2008. flags += " ";
  2009. flags += this->GeneratorTarget->Target->GetMakefile()->GetRequiredDefinition(
  2010. linkFlagVarBase.c_str());
  2011. std::string linkFlagVar = linkFlagVarBase + "_" + CONFIG;
  2012. flags += " ";
  2013. flags += this->GeneratorTarget->Target->GetMakefile()->GetRequiredDefinition(
  2014. linkFlagVar.c_str());
  2015. const char* targetLinkFlags =
  2016. this->GeneratorTarget->GetProperty("LINK_FLAGS");
  2017. if (targetLinkFlags) {
  2018. flags += " ";
  2019. flags += targetLinkFlags;
  2020. }
  2021. std::string flagsProp = "LINK_FLAGS_";
  2022. flagsProp += CONFIG;
  2023. if (const char* flagsConfig =
  2024. this->GeneratorTarget->GetProperty(flagsProp.c_str())) {
  2025. flags += " ";
  2026. flags += flagsConfig;
  2027. }
  2028. std::string standardLibsVar = "CMAKE_";
  2029. standardLibsVar += linkLanguage;
  2030. standardLibsVar += "_STANDARD_LIBRARIES";
  2031. std::string libs =
  2032. this->Makefile->GetSafeDefinition(standardLibsVar.c_str());
  2033. // Remove trailing spaces from libs
  2034. std::string::size_type pos = libs.size() - 1;
  2035. if (!libs.empty()) {
  2036. while (libs[pos] == ' ') {
  2037. pos--;
  2038. }
  2039. }
  2040. if (pos != libs.size() - 1) {
  2041. libs = libs.substr(0, pos + 1);
  2042. }
  2043. // Replace spaces in libs with ;
  2044. std::replace(libs.begin(), libs.end(), ' ', ';');
  2045. std::vector<std::string> libVec;
  2046. cmSystemTools::ExpandListArgument(libs, libVec);
  2047. cmComputeLinkInformation* pcli =
  2048. this->GeneratorTarget->GetLinkInformation(config.c_str());
  2049. if (!pcli) {
  2050. cmSystemTools::Error(
  2051. "CMake can not compute cmComputeLinkInformation for target: ",
  2052. this->Name.c_str());
  2053. return false;
  2054. }
  2055. // add the libraries for the target to libs string
  2056. cmComputeLinkInformation& cli = *pcli;
  2057. this->AddLibraries(cli, libVec);
  2058. linkOptions.AddFlag("AdditionalDependencies", libVec);
  2059. std::vector<std::string> const& ldirs = cli.GetDirectories();
  2060. std::vector<std::string> linkDirs;
  2061. for (std::vector<std::string>::const_iterator d = ldirs.begin();
  2062. d != ldirs.end(); ++d) {
  2063. // first just full path
  2064. linkDirs.push_back(*d);
  2065. // next path with configuration type Debug, Release, etc
  2066. linkDirs.push_back(*d + "/$(Configuration)");
  2067. }
  2068. linkDirs.push_back("%(AdditionalLibraryDirectories)");
  2069. linkOptions.AddFlag("AdditionalLibraryDirectories", linkDirs);
  2070. std::string targetName;
  2071. std::string targetNameSO;
  2072. std::string targetNameFull;
  2073. std::string targetNameImport;
  2074. std::string targetNamePDB;
  2075. if (this->GeneratorTarget->GetType() == cmState::EXECUTABLE) {
  2076. this->GeneratorTarget->GetExecutableNames(targetName, targetNameFull,
  2077. targetNameImport, targetNamePDB,
  2078. config.c_str());
  2079. } else {
  2080. this->GeneratorTarget->GetLibraryNames(targetName, targetNameSO,
  2081. targetNameFull, targetNameImport,
  2082. targetNamePDB, config.c_str());
  2083. }
  2084. if (this->MSTools) {
  2085. linkOptions.AddFlag("Version", "");
  2086. if (this->GeneratorTarget->GetPropertyAsBool("WIN32_EXECUTABLE")) {
  2087. if (this->GlobalGenerator->TargetsWindowsCE()) {
  2088. linkOptions.AddFlag("SubSystem", "WindowsCE");
  2089. if (this->GeneratorTarget->GetType() == cmState::EXECUTABLE) {
  2090. if (this->ClOptions[config]->UsingUnicode()) {
  2091. linkOptions.AddFlag("EntryPointSymbol", "wWinMainCRTStartup");
  2092. } else {
  2093. linkOptions.AddFlag("EntryPointSymbol", "WinMainCRTStartup");
  2094. }
  2095. }
  2096. } else {
  2097. linkOptions.AddFlag("SubSystem", "Windows");
  2098. }
  2099. } else {
  2100. if (this->GlobalGenerator->TargetsWindowsCE()) {
  2101. linkOptions.AddFlag("SubSystem", "WindowsCE");
  2102. if (this->GeneratorTarget->GetType() == cmState::EXECUTABLE) {
  2103. if (this->ClOptions[config]->UsingUnicode()) {
  2104. linkOptions.AddFlag("EntryPointSymbol", "mainWCRTStartup");
  2105. } else {
  2106. linkOptions.AddFlag("EntryPointSymbol", "mainACRTStartup");
  2107. }
  2108. }
  2109. } else {
  2110. linkOptions.AddFlag("SubSystem", "Console");
  2111. };
  2112. }
  2113. if (const char* stackVal = this->Makefile->GetDefinition(
  2114. "CMAKE_" + linkLanguage + "_STACK_SIZE")) {
  2115. linkOptions.AddFlag("StackReserveSize", stackVal);
  2116. }
  2117. if (this->LocalGenerator->GetVersion() >=
  2118. cmGlobalVisualStudioGenerator::VS14) {
  2119. linkOptions.AddFlag("GenerateDebugInformation", "No");
  2120. } else {
  2121. linkOptions.AddFlag("GenerateDebugInformation", "false");
  2122. }
  2123. std::string pdb = this->GeneratorTarget->GetPDBDirectory(config.c_str());
  2124. pdb += "/";
  2125. pdb += targetNamePDB;
  2126. std::string imLib =
  2127. this->GeneratorTarget->GetDirectory(config.c_str(), true);
  2128. imLib += "/";
  2129. imLib += targetNameImport;
  2130. linkOptions.AddFlag("ImportLibrary", imLib.c_str());
  2131. linkOptions.AddFlag("ProgramDataBaseFile", pdb.c_str());
  2132. // A Windows Runtime component uses internal .NET metadata,
  2133. // so does not have an import library.
  2134. if (this->GeneratorTarget->GetPropertyAsBool("VS_WINRT_COMPONENT") &&
  2135. this->GeneratorTarget->GetType() != cmState::EXECUTABLE) {
  2136. linkOptions.AddFlag("GenerateWindowsMetadata", "true");
  2137. } else if (this->GlobalGenerator->TargetsWindowsPhone() ||
  2138. this->GlobalGenerator->TargetsWindowsStore()) {
  2139. // WindowsPhone and WindowsStore components are in an app container
  2140. // and produce WindowsMetadata. If we are not producing a WINRT
  2141. // component, then do not generate the metadata here.
  2142. linkOptions.AddFlag("GenerateWindowsMetadata", "false");
  2143. }
  2144. if (this->GlobalGenerator->TargetsWindowsPhone() &&
  2145. this->GlobalGenerator->GetSystemVersion() == "8.0") {
  2146. // WindowsPhone 8.0 does not have ole32.
  2147. linkOptions.AppendFlag("IgnoreSpecificDefaultLibraries", "ole32.lib");
  2148. }
  2149. } else if (this->NsightTegra) {
  2150. linkOptions.AddFlag("SoName", targetNameSO.c_str());
  2151. }
  2152. linkOptions.Parse(flags.c_str());
  2153. if (this->MSTools) {
  2154. if (cmSourceFile const* defsrc =
  2155. this->GeneratorTarget->GetModuleDefinitionFile("")) {
  2156. linkOptions.AddFlag("ModuleDefinitionFile",
  2157. defsrc->GetFullPath().c_str());
  2158. }
  2159. linkOptions.AppendFlag("IgnoreSpecificDefaultLibraries",
  2160. "%(IgnoreSpecificDefaultLibraries)");
  2161. }
  2162. if ((this->GeneratorTarget->GetType() == cmState::SHARED_LIBRARY ||
  2163. this->GeneratorTarget->IsExecutableWithExports()) &&
  2164. this->Makefile->IsOn("CMAKE_SUPPORT_WINDOWS_EXPORT_ALL_SYMBOLS")) {
  2165. if (this->GeneratorTarget->GetPropertyAsBool(
  2166. "WINDOWS_EXPORT_ALL_SYMBOLS")) {
  2167. linkOptions.AddFlag("ModuleDefinitionFile", "$(IntDir)exportall.def");
  2168. }
  2169. }
  2170. // Hack to fix flag version selection in a common use case.
  2171. // FIXME: Select flag table based on toolset instead of VS version.
  2172. if (this->LocalGenerator->GetVersion() >=
  2173. cmGlobalVisualStudioGenerator::VS14) {
  2174. cmGlobalVisualStudio10Generator* gg =
  2175. static_cast<cmGlobalVisualStudio10Generator*>(this->GlobalGenerator);
  2176. const char* toolset = gg->GetPlatformToolset();
  2177. if (toolset && (cmHasLiteralPrefix(toolset, "v90") ||
  2178. cmHasLiteralPrefix(toolset, "v100") ||
  2179. cmHasLiteralPrefix(toolset, "v110") ||
  2180. cmHasLiteralPrefix(toolset, "v120"))) {
  2181. if (const char* debug =
  2182. linkOptions.GetFlag("GenerateDebugInformation")) {
  2183. // Convert value from enumeration back to boolean for older toolsets.
  2184. if (strcmp(debug, "No") == 0) {
  2185. linkOptions.AddFlag("GenerateDebugInformation", "false");
  2186. } else if (strcmp(debug, "Debug") == 0) {
  2187. linkOptions.AddFlag("GenerateDebugInformation", "true");
  2188. }
  2189. }
  2190. }
  2191. }
  2192. this->LinkOptions[config] = pOptions.release();
  2193. return true;
  2194. }
  2195. void cmVisualStudio10TargetGenerator::WriteLinkOptions(
  2196. std::string const& config)
  2197. {
  2198. if (this->GeneratorTarget->GetType() == cmState::STATIC_LIBRARY ||
  2199. this->GeneratorTarget->GetType() > cmState::MODULE_LIBRARY) {
  2200. return;
  2201. }
  2202. Options& linkOptions = *(this->LinkOptions[config]);
  2203. this->WriteString("<Link>\n", 2);
  2204. linkOptions.OutputAdditionalOptions(*this->BuildFileStream, " ", "");
  2205. linkOptions.OutputFlagMap(*this->BuildFileStream, " ");
  2206. this->WriteString("</Link>\n", 2);
  2207. if (!this->GlobalGenerator->NeedLinkLibraryDependencies(
  2208. this->GeneratorTarget)) {
  2209. this->WriteString("<ProjectReference>\n", 2);
  2210. this->WriteString(
  2211. "<LinkLibraryDependencies>false</LinkLibraryDependencies>\n", 3);
  2212. this->WriteString("</ProjectReference>\n", 2);
  2213. }
  2214. }
  2215. void cmVisualStudio10TargetGenerator::AddLibraries(
  2216. cmComputeLinkInformation& cli, std::vector<std::string>& libVec)
  2217. {
  2218. typedef cmComputeLinkInformation::ItemVector ItemVector;
  2219. ItemVector libs = cli.GetItems();
  2220. for (ItemVector::const_iterator l = libs.begin(); l != libs.end(); ++l) {
  2221. if (l->IsPath) {
  2222. std::string path = this->LocalGenerator->Convert(
  2223. l->Value.c_str(), cmOutputConverter::START_OUTPUT,
  2224. cmOutputConverter::UNCHANGED);
  2225. this->ConvertToWindowsSlash(path);
  2226. libVec.push_back(path);
  2227. } else if (!l->Target ||
  2228. l->Target->GetType() != cmState::INTERFACE_LIBRARY) {
  2229. libVec.push_back(l->Value);
  2230. }
  2231. }
  2232. }
  2233. void cmVisualStudio10TargetGenerator::WriteMidlOptions(
  2234. std::string const& /*config*/, std::vector<std::string> const& includes)
  2235. {
  2236. if (!this->MSTools) {
  2237. return;
  2238. }
  2239. // This processes *any* of the .idl files specified in the project's file
  2240. // list (and passed as the item metadata %(Filename) expressing the rule
  2241. // input filename) into output files at the per-config *build* dir
  2242. // ($(IntDir)) each.
  2243. //
  2244. // IOW, this MIDL section is intended to provide a fully generic syntax
  2245. // content suitable for most cases (read: if you get errors, then it's quite
  2246. // probable that the error is on your side of the .idl setup).
  2247. //
  2248. // Also, note that the marked-as-generated _i.c file in the Visual Studio
  2249. // generator case needs to be referred to as $(IntDir)\foo_i.c at the
  2250. // project's file list, otherwise the compiler-side processing won't pick it
  2251. // up (for non-directory form, it ends up looking in project binary dir
  2252. // only). Perhaps there's something to be done to make this more automatic
  2253. // on the CMake side?
  2254. this->WriteString("<Midl>\n", 2);
  2255. this->WriteString("<AdditionalIncludeDirectories>", 3);
  2256. for (std::vector<std::string>::const_iterator i = includes.begin();
  2257. i != includes.end(); ++i) {
  2258. *this->BuildFileStream << cmVS10EscapeXML(*i) << ";";
  2259. }
  2260. this->WriteString("%(AdditionalIncludeDirectories)"
  2261. "</AdditionalIncludeDirectories>\n",
  2262. 0);
  2263. this->WriteString("<OutputDirectory>$(ProjectDir)/$(IntDir)"
  2264. "</OutputDirectory>\n",
  2265. 3);
  2266. this->WriteString("<HeaderFileName>%(Filename).h</HeaderFileName>\n", 3);
  2267. this->WriteString("<TypeLibraryName>%(Filename).tlb</TypeLibraryName>\n", 3);
  2268. this->WriteString("<InterfaceIdentifierFileName>"
  2269. "%(Filename)_i.c</InterfaceIdentifierFileName>\n",
  2270. 3);
  2271. this->WriteString("<ProxyFileName>%(Filename)_p.c</ProxyFileName>\n", 3);
  2272. this->WriteString("</Midl>\n", 2);
  2273. }
  2274. void cmVisualStudio10TargetGenerator::WriteItemDefinitionGroups()
  2275. {
  2276. for (std::vector<std::string>::const_iterator i =
  2277. this->Configurations.begin();
  2278. i != this->Configurations.end(); ++i) {
  2279. std::vector<std::string> includes;
  2280. this->LocalGenerator->GetIncludeDirectories(
  2281. includes, this->GeneratorTarget, "C", i->c_str());
  2282. for (std::vector<std::string>::iterator ii = includes.begin();
  2283. ii != includes.end(); ++ii) {
  2284. this->ConvertToWindowsSlash(*ii);
  2285. }
  2286. this->WritePlatformConfigTag("ItemDefinitionGroup", i->c_str(), 1);
  2287. *this->BuildFileStream << "\n";
  2288. // output cl compile flags <ClCompile></ClCompile>
  2289. if (this->GeneratorTarget->GetType() <= cmState::OBJECT_LIBRARY) {
  2290. this->WriteClOptions(*i, includes);
  2291. // output rc compile flags <ResourceCompile></ResourceCompile>
  2292. this->WriteRCOptions(*i, includes);
  2293. this->WriteMasmOptions(*i, includes);
  2294. }
  2295. // output midl flags <Midl></Midl>
  2296. this->WriteMidlOptions(*i, includes);
  2297. // write events
  2298. this->WriteEvents(*i);
  2299. // output link flags <Link></Link>
  2300. this->WriteLinkOptions(*i);
  2301. // output lib flags <Lib></Lib>
  2302. this->WriteLibOptions(*i);
  2303. // output manifest flags <Manifest></Manifest>
  2304. this->WriteManifestOptions(*i);
  2305. if (this->NsightTegra &&
  2306. this->GeneratorTarget->GetType() == cmState::EXECUTABLE &&
  2307. this->GeneratorTarget->GetPropertyAsBool("ANDROID_GUI")) {
  2308. this->WriteAntBuildOptions(*i);
  2309. }
  2310. this->WriteString("</ItemDefinitionGroup>\n", 1);
  2311. }
  2312. }
  2313. void cmVisualStudio10TargetGenerator::WriteEvents(
  2314. std::string const& configName)
  2315. {
  2316. bool addedPrelink = false;
  2317. if ((this->GeneratorTarget->GetType() == cmState::SHARED_LIBRARY ||
  2318. this->GeneratorTarget->IsExecutableWithExports()) &&
  2319. this->Makefile->IsOn("CMAKE_SUPPORT_WINDOWS_EXPORT_ALL_SYMBOLS")) {
  2320. if (this->GeneratorTarget->GetPropertyAsBool(
  2321. "WINDOWS_EXPORT_ALL_SYMBOLS")) {
  2322. addedPrelink = true;
  2323. std::vector<cmCustomCommand> commands =
  2324. this->GeneratorTarget->GetPreLinkCommands();
  2325. this->GlobalGenerator->AddSymbolExportCommand(this->GeneratorTarget,
  2326. commands, configName);
  2327. this->WriteEvent("PreLinkEvent", commands, configName);
  2328. }
  2329. }
  2330. if (!addedPrelink) {
  2331. this->WriteEvent("PreLinkEvent",
  2332. this->GeneratorTarget->GetPreLinkCommands(), configName);
  2333. }
  2334. this->WriteEvent("PreBuildEvent",
  2335. this->GeneratorTarget->GetPreBuildCommands(), configName);
  2336. this->WriteEvent("PostBuildEvent",
  2337. this->GeneratorTarget->GetPostBuildCommands(), configName);
  2338. }
  2339. void cmVisualStudio10TargetGenerator::WriteEvent(
  2340. const char* name, std::vector<cmCustomCommand> const& commands,
  2341. std::string const& configName)
  2342. {
  2343. if (commands.empty()) {
  2344. return;
  2345. }
  2346. this->WriteString("<", 2);
  2347. (*this->BuildFileStream) << name << ">\n";
  2348. cmLocalVisualStudio7Generator* lg = this->LocalGenerator;
  2349. std::string script;
  2350. const char* pre = "";
  2351. std::string comment;
  2352. for (std::vector<cmCustomCommand>::const_iterator i = commands.begin();
  2353. i != commands.end(); ++i) {
  2354. cmCustomCommandGenerator ccg(*i, configName, this->LocalGenerator);
  2355. comment += pre;
  2356. comment += lg->ConstructComment(ccg);
  2357. script += pre;
  2358. pre = "\n";
  2359. script += cmVS10EscapeXML(lg->ConstructScript(ccg));
  2360. }
  2361. comment = cmVS10EscapeComment(comment);
  2362. this->WriteString("<Message>", 3);
  2363. (*this->BuildFileStream) << cmVS10EscapeXML(comment) << "</Message>\n";
  2364. this->WriteString("<Command>", 3);
  2365. (*this->BuildFileStream) << script;
  2366. (*this->BuildFileStream) << "</Command>"
  2367. << "\n";
  2368. this->WriteString("</", 2);
  2369. (*this->BuildFileStream) << name << ">\n";
  2370. }
  2371. void cmVisualStudio10TargetGenerator::WriteProjectReferences()
  2372. {
  2373. cmGlobalGenerator::TargetDependSet const& unordered =
  2374. this->GlobalGenerator->GetTargetDirectDepends(this->GeneratorTarget);
  2375. typedef cmGlobalVisualStudioGenerator::OrderedTargetDependSet
  2376. OrderedTargetDependSet;
  2377. OrderedTargetDependSet depends(unordered, CMAKE_CHECK_BUILD_SYSTEM_TARGET);
  2378. this->WriteString("<ItemGroup>\n", 1);
  2379. for (OrderedTargetDependSet::const_iterator i = depends.begin();
  2380. i != depends.end(); ++i) {
  2381. cmGeneratorTarget const* dt = *i;
  2382. if (dt->GetType() == cmState::INTERFACE_LIBRARY) {
  2383. continue;
  2384. }
  2385. // skip fortran targets as they can not be processed by MSBuild
  2386. // the only reference will be in the .sln file
  2387. if (static_cast<cmGlobalVisualStudioGenerator*>(this->GlobalGenerator)
  2388. ->TargetIsFortranOnly(dt)) {
  2389. continue;
  2390. }
  2391. this->WriteString("<ProjectReference Include=\"", 2);
  2392. cmLocalGenerator* lg = dt->GetLocalGenerator();
  2393. std::string name = dt->GetName();
  2394. std::string path;
  2395. const char* p = dt->GetProperty("EXTERNAL_MSPROJECT");
  2396. if (p) {
  2397. path = p;
  2398. } else {
  2399. path = lg->GetCurrentBinaryDirectory();
  2400. path += "/";
  2401. path += dt->GetName();
  2402. path += ".vcxproj";
  2403. }
  2404. (*this->BuildFileStream) << cmVS10EscapeXML(path) << "\">\n";
  2405. this->WriteString("<Project>", 3);
  2406. (*this->BuildFileStream) << this->GlobalGenerator->GetGUID(name.c_str())
  2407. << "</Project>\n";
  2408. this->WriteString("</ProjectReference>\n", 2);
  2409. }
  2410. this->WriteString("</ItemGroup>\n", 1);
  2411. }
  2412. void cmVisualStudio10TargetGenerator::WritePlatformExtensions()
  2413. {
  2414. // This only applies to Windows 10 apps
  2415. if (this->GlobalGenerator->TargetsWindowsStore() &&
  2416. cmHasLiteralPrefix(this->GlobalGenerator->GetSystemVersion(), "10.0")) {
  2417. const char* desktopExtensionsVersion =
  2418. this->GeneratorTarget->GetProperty("VS_DESKTOP_EXTENSIONS_VERSION");
  2419. if (desktopExtensionsVersion) {
  2420. this->WriteSinglePlatformExtension("WindowsDesktop",
  2421. desktopExtensionsVersion);
  2422. }
  2423. const char* mobileExtensionsVersion =
  2424. this->GeneratorTarget->GetProperty("VS_MOBILE_EXTENSIONS_VERSION");
  2425. if (mobileExtensionsVersion) {
  2426. this->WriteSinglePlatformExtension("WindowsMobile",
  2427. mobileExtensionsVersion);
  2428. }
  2429. }
  2430. }
  2431. void cmVisualStudio10TargetGenerator::WriteSinglePlatformExtension(
  2432. std::string const& extension, std::string const& version)
  2433. {
  2434. this->WriteString("<Import Project=", 2);
  2435. (*this->BuildFileStream)
  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\" "
  2443. << "Condition=\"exists('$("
  2444. << "[Microsoft.Build.Utilities.ToolLocationHelper]"
  2445. << "::GetPlatformExtensionSDKLocation(`" << extension
  2446. << ", Version=" << version
  2447. << "`, $(TargetPlatformIdentifier), $(TargetPlatformVersion), null, "
  2448. << "$(ExtensionSDKDirectoryRoot), null))"
  2449. << "\\DesignTime\\CommonConfiguration\\Neutral\\" << extension
  2450. << ".props')\" />\n";
  2451. }
  2452. void cmVisualStudio10TargetGenerator::WriteSDKReferences()
  2453. {
  2454. std::vector<std::string> sdkReferences;
  2455. bool hasWrittenItemGroup = false;
  2456. if (const char* vsSDKReferences =
  2457. this->GeneratorTarget->GetProperty("VS_SDK_REFERENCES")) {
  2458. cmSystemTools::ExpandListArgument(vsSDKReferences, sdkReferences);
  2459. this->WriteString("<ItemGroup>\n", 1);
  2460. hasWrittenItemGroup = true;
  2461. for (std::vector<std::string>::iterator ri = sdkReferences.begin();
  2462. ri != sdkReferences.end(); ++ri) {
  2463. this->WriteString("<SDKReference Include=\"", 2);
  2464. (*this->BuildFileStream) << cmVS10EscapeXML(*ri) << "\"/>\n";
  2465. }
  2466. }
  2467. // This only applies to Windows 10 apps
  2468. if (this->GlobalGenerator->TargetsWindowsStore() &&
  2469. cmHasLiteralPrefix(this->GlobalGenerator->GetSystemVersion(), "10.0")) {
  2470. const char* desktopExtensionsVersion =
  2471. this->GeneratorTarget->GetProperty("VS_DESKTOP_EXTENSIONS_VERSION");
  2472. const char* mobileExtensionsVersion =
  2473. this->GeneratorTarget->GetProperty("VS_MOBILE_EXTENSIONS_VERSION");
  2474. const char* iotExtensionsVersion =
  2475. this->GeneratorTarget->GetProperty("VS_IOT_EXTENSIONS_VERSION");
  2476. if (desktopExtensionsVersion || mobileExtensionsVersion ||
  2477. iotExtensionsVersion) {
  2478. if (!hasWrittenItemGroup) {
  2479. this->WriteString("<ItemGroup>\n", 1);
  2480. hasWrittenItemGroup = true;
  2481. }
  2482. if (desktopExtensionsVersion) {
  2483. this->WriteSingleSDKReference("WindowsDesktop",
  2484. desktopExtensionsVersion);
  2485. }
  2486. if (mobileExtensionsVersion) {
  2487. this->WriteSingleSDKReference("WindowsMobile",
  2488. mobileExtensionsVersion);
  2489. }
  2490. if (iotExtensionsVersion) {
  2491. this->WriteSingleSDKReference("WindowsIoT", iotExtensionsVersion);
  2492. }
  2493. }
  2494. if (hasWrittenItemGroup) {
  2495. this->WriteString("</ItemGroup>\n", 1);
  2496. }
  2497. }
  2498. }
  2499. void cmVisualStudio10TargetGenerator::WriteSingleSDKReference(
  2500. std::string const& extension, std::string const& version)
  2501. {
  2502. this->WriteString("<SDKReference Include=\"", 2);
  2503. (*this->BuildFileStream) << extension << ", Version=" << version
  2504. << "\" />\n";
  2505. }
  2506. void cmVisualStudio10TargetGenerator::WriteWinRTPackageCertificateKeyFile()
  2507. {
  2508. if ((this->GlobalGenerator->TargetsWindowsStore() ||
  2509. this->GlobalGenerator->TargetsWindowsPhone()) &&
  2510. (cmState::EXECUTABLE == this->GeneratorTarget->GetType())) {
  2511. std::string pfxFile;
  2512. std::vector<cmSourceFile const*> certificates;
  2513. this->GeneratorTarget->GetCertificates(certificates, "");
  2514. for (std::vector<cmSourceFile const*>::const_iterator si =
  2515. certificates.begin();
  2516. si != certificates.end(); ++si) {
  2517. pfxFile = this->ConvertPath((*si)->GetFullPath(), false);
  2518. this->ConvertToWindowsSlash(pfxFile);
  2519. break;
  2520. }
  2521. if (this->IsMissingFiles &&
  2522. !(this->GlobalGenerator->TargetsWindowsPhone() &&
  2523. this->GlobalGenerator->GetSystemVersion() == "8.0")) {
  2524. // Move the manifest to a project directory to avoid clashes
  2525. std::string artifactDir =
  2526. this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
  2527. this->ConvertToWindowsSlash(artifactDir);
  2528. this->WriteString("<PropertyGroup>\n", 1);
  2529. this->WriteString("<AppxPackageArtifactsDir>", 2);
  2530. (*this->BuildFileStream) << cmVS10EscapeXML(artifactDir)
  2531. << "\\</AppxPackageArtifactsDir>\n";
  2532. this->WriteString("<ProjectPriFullPath>"
  2533. "$(TargetDir)resources.pri</ProjectPriFullPath>\n",
  2534. 2);
  2535. // If we are missing files and we don't have a certificate and
  2536. // aren't targeting WP8.0, add a default certificate
  2537. if (pfxFile.empty()) {
  2538. std::string templateFolder =
  2539. cmSystemTools::GetCMakeRoot() + "/Templates/Windows";
  2540. pfxFile = this->DefaultArtifactDir + "/Windows_TemporaryKey.pfx";
  2541. cmSystemTools::CopyAFile(templateFolder + "/Windows_TemporaryKey.pfx",
  2542. pfxFile, false);
  2543. this->ConvertToWindowsSlash(pfxFile);
  2544. this->AddedFiles.push_back(pfxFile);
  2545. }
  2546. this->WriteString("<", 2);
  2547. (*this->BuildFileStream) << "PackageCertificateKeyFile>" << pfxFile
  2548. << "</PackageCertificateKeyFile>\n";
  2549. std::string thumb = cmSystemTools::ComputeCertificateThumbprint(pfxFile);
  2550. if (!thumb.empty()) {
  2551. this->WriteString("<PackageCertificateThumbprint>", 2);
  2552. (*this->BuildFileStream) << thumb
  2553. << "</PackageCertificateThumbprint>\n";
  2554. }
  2555. this->WriteString("</PropertyGroup>\n", 1);
  2556. } else if (!pfxFile.empty()) {
  2557. this->WriteString("<PropertyGroup>\n", 1);
  2558. this->WriteString("<", 2);
  2559. (*this->BuildFileStream) << "PackageCertificateKeyFile>" << pfxFile
  2560. << "</PackageCertificateKeyFile>\n";
  2561. std::string thumb = cmSystemTools::ComputeCertificateThumbprint(pfxFile);
  2562. if (!thumb.empty()) {
  2563. this->WriteString("<PackageCertificateThumbprint>", 2);
  2564. (*this->BuildFileStream) << thumb
  2565. << "</PackageCertificateThumbprint>\n";
  2566. }
  2567. this->WriteString("</PropertyGroup>\n", 1);
  2568. }
  2569. }
  2570. }
  2571. bool cmVisualStudio10TargetGenerator::IsResxHeader(
  2572. const std::string& headerFile)
  2573. {
  2574. std::set<std::string> expectedResxHeaders;
  2575. this->GeneratorTarget->GetExpectedResxHeaders(expectedResxHeaders, "");
  2576. std::set<std::string>::const_iterator it =
  2577. expectedResxHeaders.find(headerFile);
  2578. return it != expectedResxHeaders.end();
  2579. }
  2580. bool cmVisualStudio10TargetGenerator::IsXamlHeader(
  2581. const std::string& headerFile)
  2582. {
  2583. std::set<std::string> expectedXamlHeaders;
  2584. this->GeneratorTarget->GetExpectedXamlHeaders(expectedXamlHeaders, "");
  2585. std::set<std::string>::const_iterator it =
  2586. expectedXamlHeaders.find(headerFile);
  2587. return it != expectedXamlHeaders.end();
  2588. }
  2589. bool cmVisualStudio10TargetGenerator::IsXamlSource(
  2590. const std::string& sourceFile)
  2591. {
  2592. std::set<std::string> expectedXamlSources;
  2593. this->GeneratorTarget->GetExpectedXamlSources(expectedXamlSources, "");
  2594. std::set<std::string>::const_iterator it =
  2595. expectedXamlSources.find(sourceFile);
  2596. return it != expectedXamlSources.end();
  2597. }
  2598. void cmVisualStudio10TargetGenerator::WriteApplicationTypeSettings()
  2599. {
  2600. cmGlobalVisualStudio10Generator* gg =
  2601. static_cast<cmGlobalVisualStudio10Generator*>(this->GlobalGenerator);
  2602. bool isAppContainer = false;
  2603. bool const isWindowsPhone = this->GlobalGenerator->TargetsWindowsPhone();
  2604. bool const isWindowsStore = this->GlobalGenerator->TargetsWindowsStore();
  2605. std::string const& v = this->GlobalGenerator->GetSystemVersion();
  2606. if (isWindowsPhone || isWindowsStore) {
  2607. this->WriteString("<ApplicationType>", 2);
  2608. (*this->BuildFileStream)
  2609. << (isWindowsPhone ? "Windows Phone" : "Windows Store")
  2610. << "</ApplicationType>\n";
  2611. this->WriteString("<DefaultLanguage>en-US"
  2612. "</DefaultLanguage>\n",
  2613. 2);
  2614. if (cmHasLiteralPrefix(v, "10.0")) {
  2615. this->WriteString("<ApplicationTypeRevision>", 2);
  2616. (*this->BuildFileStream) << cmVS10EscapeXML("10.0")
  2617. << "</ApplicationTypeRevision>\n";
  2618. // Visual Studio 14.0 is necessary for building 10.0 apps
  2619. this->WriteString("<MinimumVisualStudioVersion>14.0"
  2620. "</MinimumVisualStudioVersion>\n",
  2621. 2);
  2622. if (this->GeneratorTarget->GetType() < cmState::UTILITY) {
  2623. isAppContainer = true;
  2624. }
  2625. } else if (v == "8.1") {
  2626. this->WriteString("<ApplicationTypeRevision>", 2);
  2627. (*this->BuildFileStream) << cmVS10EscapeXML(v)
  2628. << "</ApplicationTypeRevision>\n";
  2629. // Visual Studio 12.0 is necessary for building 8.1 apps
  2630. this->WriteString("<MinimumVisualStudioVersion>12.0"
  2631. "</MinimumVisualStudioVersion>\n",
  2632. 2);
  2633. if (this->GeneratorTarget->GetType() < cmState::UTILITY) {
  2634. isAppContainer = true;
  2635. }
  2636. } else if (v == "8.0") {
  2637. this->WriteString("<ApplicationTypeRevision>", 2);
  2638. (*this->BuildFileStream) << cmVS10EscapeXML(v)
  2639. << "</ApplicationTypeRevision>\n";
  2640. // Visual Studio 11.0 is necessary for building 8.0 apps
  2641. this->WriteString("<MinimumVisualStudioVersion>11.0"
  2642. "</MinimumVisualStudioVersion>\n",
  2643. 2);
  2644. if (isWindowsStore &&
  2645. this->GeneratorTarget->GetType() < cmState::UTILITY) {
  2646. isAppContainer = true;
  2647. } else if (isWindowsPhone &&
  2648. this->GeneratorTarget->GetType() == cmState::EXECUTABLE) {
  2649. this->WriteString("<XapOutputs>true</XapOutputs>\n", 2);
  2650. this->WriteString("<XapFilename>", 2);
  2651. (*this->BuildFileStream)
  2652. << cmVS10EscapeXML(this->Name.c_str())
  2653. << "_$(Configuration)_$(Platform).xap</XapFilename>\n";
  2654. }
  2655. }
  2656. }
  2657. if (isAppContainer) {
  2658. this->WriteString("<AppContainerApplication>true"
  2659. "</AppContainerApplication>\n",
  2660. 2);
  2661. } else if (this->Platform == "ARM") {
  2662. this->WriteString("<WindowsSDKDesktopARMSupport>true"
  2663. "</WindowsSDKDesktopARMSupport>\n",
  2664. 2);
  2665. }
  2666. std::string const& targetPlatformVersion =
  2667. gg->GetWindowsTargetPlatformVersion();
  2668. if (!targetPlatformVersion.empty()) {
  2669. this->WriteString("<WindowsTargetPlatformVersion>", 2);
  2670. (*this->BuildFileStream) << cmVS10EscapeXML(targetPlatformVersion)
  2671. << "</WindowsTargetPlatformVersion>\n";
  2672. }
  2673. const char* targetPlatformMinVersion = this->GeneratorTarget->GetProperty(
  2674. "VS_WINDOWS_TARGET_PLATFORM_MIN_VERSION");
  2675. if (targetPlatformMinVersion) {
  2676. this->WriteString("<WindowsTargetPlatformMinVersion>", 2);
  2677. (*this->BuildFileStream) << cmVS10EscapeXML(targetPlatformMinVersion)
  2678. << "</WindowsTargetPlatformMinVersion>\n";
  2679. } else if (isWindowsStore && cmHasLiteralPrefix(v, "10.0")) {
  2680. // If the min version is not set, then use the TargetPlatformVersion
  2681. if (!targetPlatformVersion.empty()) {
  2682. this->WriteString("<WindowsTargetPlatformMinVersion>", 2);
  2683. (*this->BuildFileStream) << cmVS10EscapeXML(targetPlatformVersion)
  2684. << "</WindowsTargetPlatformMinVersion>\n";
  2685. }
  2686. }
  2687. // Added IoT Startup Task support
  2688. if (this->GeneratorTarget->GetPropertyAsBool("VS_IOT_STARTUP_TASK")) {
  2689. this->WriteString("<ContainsStartupTask>true</ContainsStartupTask>\n", 2);
  2690. }
  2691. }
  2692. void cmVisualStudio10TargetGenerator::VerifyNecessaryFiles()
  2693. {
  2694. // For Windows and Windows Phone executables, we will assume that if a
  2695. // manifest is not present that we need to add all the necessary files
  2696. if (this->GeneratorTarget->GetType() == cmState::EXECUTABLE) {
  2697. std::vector<cmSourceFile const*> manifestSources;
  2698. this->GeneratorTarget->GetAppManifest(manifestSources, "");
  2699. {
  2700. std::string const& v = this->GlobalGenerator->GetSystemVersion();
  2701. if (this->GlobalGenerator->TargetsWindowsPhone()) {
  2702. if (v == "8.0") {
  2703. // Look through the sources for WMAppManifest.xml
  2704. std::vector<cmSourceFile const*> extraSources;
  2705. this->GeneratorTarget->GetExtraSources(extraSources, "");
  2706. bool foundManifest = false;
  2707. for (std::vector<cmSourceFile const*>::const_iterator si =
  2708. extraSources.begin();
  2709. si != extraSources.end(); ++si) {
  2710. // Need to do a lowercase comparison on the filename
  2711. if ("wmappmanifest.xml" ==
  2712. cmSystemTools::LowerCase((*si)->GetLocation().GetName())) {
  2713. foundManifest = true;
  2714. break;
  2715. }
  2716. }
  2717. if (!foundManifest) {
  2718. this->IsMissingFiles = true;
  2719. }
  2720. } else if (v == "8.1") {
  2721. if (manifestSources.empty()) {
  2722. this->IsMissingFiles = true;
  2723. }
  2724. }
  2725. } else if (this->GlobalGenerator->TargetsWindowsStore()) {
  2726. if (manifestSources.empty()) {
  2727. if (v == "8.0") {
  2728. this->IsMissingFiles = true;
  2729. } else if (v == "8.1" || cmHasLiteralPrefix(v, "10.0")) {
  2730. this->IsMissingFiles = true;
  2731. }
  2732. }
  2733. }
  2734. }
  2735. }
  2736. }
  2737. void cmVisualStudio10TargetGenerator::WriteMissingFiles()
  2738. {
  2739. std::string const& v = this->GlobalGenerator->GetSystemVersion();
  2740. if (this->GlobalGenerator->TargetsWindowsPhone()) {
  2741. if (v == "8.0") {
  2742. this->WriteMissingFilesWP80();
  2743. } else if (v == "8.1") {
  2744. this->WriteMissingFilesWP81();
  2745. }
  2746. } else if (this->GlobalGenerator->TargetsWindowsStore()) {
  2747. if (v == "8.0") {
  2748. this->WriteMissingFilesWS80();
  2749. } else if (v == "8.1") {
  2750. this->WriteMissingFilesWS81();
  2751. } else if (cmHasLiteralPrefix(v, "10.0")) {
  2752. this->WriteMissingFilesWS10_0();
  2753. }
  2754. }
  2755. }
  2756. void cmVisualStudio10TargetGenerator::WriteMissingFilesWP80()
  2757. {
  2758. std::string templateFolder =
  2759. cmSystemTools::GetCMakeRoot() + "/Templates/Windows";
  2760. // For WP80, the manifest needs to be in the same folder as the project
  2761. // this can cause an overwrite problem if projects aren't organized in
  2762. // folders
  2763. std::string manifestFile =
  2764. this->LocalGenerator->GetCurrentBinaryDirectory() +
  2765. std::string("/WMAppManifest.xml");
  2766. std::string artifactDir =
  2767. this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
  2768. this->ConvertToWindowsSlash(artifactDir);
  2769. std::string artifactDirXML = cmVS10EscapeXML(artifactDir);
  2770. std::string targetNameXML =
  2771. cmVS10EscapeXML(this->GeneratorTarget->GetName());
  2772. cmGeneratedFileStream fout(manifestFile.c_str());
  2773. fout.SetCopyIfDifferent(true);
  2774. /* clang-format off */
  2775. fout <<
  2776. "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
  2777. "<Deployment"
  2778. " xmlns=\"http://schemas.microsoft.com/windowsphone/2012/deployment\""
  2779. " AppPlatformVersion=\"8.0\">\n"
  2780. "\t<DefaultLanguage xmlns=\"\" code=\"en-US\"/>\n"
  2781. "\t<App xmlns=\"\" ProductID=\"{" << this->GUID << "}\""
  2782. " Title=\"CMake Test Program\" RuntimeType=\"Modern Native\""
  2783. " Version=\"1.0.0.0\" Genre=\"apps.normal\" Author=\"CMake\""
  2784. " Description=\"Default CMake App\" Publisher=\"CMake\""
  2785. " PublisherID=\"{" << this->GUID << "}\">\n"
  2786. "\t\t<IconPath IsRelative=\"true\" IsResource=\"false\">"
  2787. << artifactDirXML << "\\ApplicationIcon.png</IconPath>\n"
  2788. "\t\t<Capabilities/>\n"
  2789. "\t\t<Tasks>\n"
  2790. "\t\t\t<DefaultTask Name=\"_default\""
  2791. " ImagePath=\"" << targetNameXML << ".exe\" ImageParams=\"\" />\n"
  2792. "\t\t</Tasks>\n"
  2793. "\t\t<Tokens>\n"
  2794. "\t\t\t<PrimaryToken TokenID=\"" << targetNameXML << "Token\""
  2795. " TaskName=\"_default\">\n"
  2796. "\t\t\t\t<TemplateFlip>\n"
  2797. "\t\t\t\t\t<SmallImageURI IsRelative=\"true\" IsResource=\"false\">"
  2798. << artifactDirXML << "\\SmallLogo.png</SmallImageURI>\n"
  2799. "\t\t\t\t\t<Count>0</Count>\n"
  2800. "\t\t\t\t\t<BackgroundImageURI IsRelative=\"true\" IsResource=\"false\">"
  2801. << artifactDirXML << "\\Logo.png</BackgroundImageURI>\n"
  2802. "\t\t\t\t</TemplateFlip>\n"
  2803. "\t\t\t</PrimaryToken>\n"
  2804. "\t\t</Tokens>\n"
  2805. "\t\t<ScreenResolutions>\n"
  2806. "\t\t\t<ScreenResolution Name=\"ID_RESOLUTION_WVGA\" />\n"
  2807. "\t\t</ScreenResolutions>\n"
  2808. "\t</App>\n"
  2809. "</Deployment>\n";
  2810. /* clang-format on */
  2811. std::string sourceFile = this->ConvertPath(manifestFile, false);
  2812. this->ConvertToWindowsSlash(sourceFile);
  2813. this->WriteString("<Xml Include=\"", 2);
  2814. (*this->BuildFileStream) << cmVS10EscapeXML(sourceFile) << "\">\n";
  2815. this->WriteString("<SubType>Designer</SubType>\n", 3);
  2816. this->WriteString("</Xml>\n", 2);
  2817. this->AddedFiles.push_back(sourceFile);
  2818. std::string smallLogo = this->DefaultArtifactDir + "/SmallLogo.png";
  2819. cmSystemTools::CopyAFile(templateFolder + "/SmallLogo.png", smallLogo,
  2820. false);
  2821. this->ConvertToWindowsSlash(smallLogo);
  2822. this->WriteString("<Image Include=\"", 2);
  2823. (*this->BuildFileStream) << cmVS10EscapeXML(smallLogo) << "\" />\n";
  2824. this->AddedFiles.push_back(smallLogo);
  2825. std::string logo = this->DefaultArtifactDir + "/Logo.png";
  2826. cmSystemTools::CopyAFile(templateFolder + "/Logo.png", logo, false);
  2827. this->ConvertToWindowsSlash(logo);
  2828. this->WriteString("<Image Include=\"", 2);
  2829. (*this->BuildFileStream) << cmVS10EscapeXML(logo) << "\" />\n";
  2830. this->AddedFiles.push_back(logo);
  2831. std::string applicationIcon =
  2832. this->DefaultArtifactDir + "/ApplicationIcon.png";
  2833. cmSystemTools::CopyAFile(templateFolder + "/ApplicationIcon.png",
  2834. applicationIcon, false);
  2835. this->ConvertToWindowsSlash(applicationIcon);
  2836. this->WriteString("<Image Include=\"", 2);
  2837. (*this->BuildFileStream) << cmVS10EscapeXML(applicationIcon) << "\" />\n";
  2838. this->AddedFiles.push_back(applicationIcon);
  2839. }
  2840. void cmVisualStudio10TargetGenerator::WriteMissingFilesWP81()
  2841. {
  2842. std::string manifestFile =
  2843. this->DefaultArtifactDir + "/package.appxManifest";
  2844. std::string artifactDir =
  2845. this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
  2846. this->ConvertToWindowsSlash(artifactDir);
  2847. std::string artifactDirXML = cmVS10EscapeXML(artifactDir);
  2848. std::string targetNameXML =
  2849. cmVS10EscapeXML(this->GeneratorTarget->GetName());
  2850. cmGeneratedFileStream fout(manifestFile.c_str());
  2851. fout.SetCopyIfDifferent(true);
  2852. /* clang-format off */
  2853. fout <<
  2854. "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
  2855. "<Package xmlns=\"http://schemas.microsoft.com/appx/2010/manifest\""
  2856. " xmlns:m2=\"http://schemas.microsoft.com/appx/2013/manifest\""
  2857. " xmlns:mp=\"http://schemas.microsoft.com/appx/2014/phone/manifest\">\n"
  2858. "\t<Identity Name=\"" << this->GUID << "\" Publisher=\"CN=CMake\""
  2859. " Version=\"1.0.0.0\" />\n"
  2860. "\t<mp:PhoneIdentity PhoneProductId=\"" << this->GUID << "\""
  2861. " PhonePublisherId=\"00000000-0000-0000-0000-000000000000\"/>\n"
  2862. "\t<Properties>\n"
  2863. "\t\t<DisplayName>" << targetNameXML << "</DisplayName>\n"
  2864. "\t\t<PublisherDisplayName>CMake</PublisherDisplayName>\n"
  2865. "\t\t<Logo>" << artifactDirXML << "\\StoreLogo.png</Logo>\n"
  2866. "\t</Properties>\n"
  2867. "\t<Prerequisites>\n"
  2868. "\t\t<OSMinVersion>6.3.1</OSMinVersion>\n"
  2869. "\t\t<OSMaxVersionTested>6.3.1</OSMaxVersionTested>\n"
  2870. "\t</Prerequisites>\n"
  2871. "\t<Resources>\n"
  2872. "\t\t<Resource Language=\"x-generate\" />\n"
  2873. "\t</Resources>\n"
  2874. "\t<Applications>\n"
  2875. "\t\t<Application Id=\"App\""
  2876. " Executable=\"" << targetNameXML << ".exe\""
  2877. " EntryPoint=\"" << targetNameXML << ".App\">\n"
  2878. "\t\t\t<m2:VisualElements\n"
  2879. "\t\t\t\tDisplayName=\"" << targetNameXML << "\"\n"
  2880. "\t\t\t\tDescription=\"" << targetNameXML << "\"\n"
  2881. "\t\t\t\tBackgroundColor=\"#336699\"\n"
  2882. "\t\t\t\tForegroundText=\"light\"\n"
  2883. "\t\t\t\tSquare150x150Logo=\"" << artifactDirXML << "\\Logo.png\"\n"
  2884. "\t\t\t\tSquare30x30Logo=\"" << artifactDirXML << "\\SmallLogo.png\">\n"
  2885. "\t\t\t\t<m2:DefaultTile ShortName=\"" << targetNameXML << "\">\n"
  2886. "\t\t\t\t\t<m2:ShowNameOnTiles>\n"
  2887. "\t\t\t\t\t\t<m2:ShowOn Tile=\"square150x150Logo\" />\n"
  2888. "\t\t\t\t\t</m2:ShowNameOnTiles>\n"
  2889. "\t\t\t\t</m2:DefaultTile>\n"
  2890. "\t\t\t\t<m2:SplashScreen"
  2891. " Image=\"" << artifactDirXML << "\\SplashScreen.png\" />\n"
  2892. "\t\t\t</m2:VisualElements>\n"
  2893. "\t\t</Application>\n"
  2894. "\t</Applications>\n"
  2895. "</Package>\n";
  2896. /* clang-format on */
  2897. this->WriteCommonMissingFiles(manifestFile);
  2898. }
  2899. void cmVisualStudio10TargetGenerator::WriteMissingFilesWS80()
  2900. {
  2901. std::string manifestFile =
  2902. this->DefaultArtifactDir + "/package.appxManifest";
  2903. std::string artifactDir =
  2904. this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
  2905. this->ConvertToWindowsSlash(artifactDir);
  2906. std::string artifactDirXML = cmVS10EscapeXML(artifactDir);
  2907. std::string targetNameXML =
  2908. cmVS10EscapeXML(this->GeneratorTarget->GetName());
  2909. cmGeneratedFileStream fout(manifestFile.c_str());
  2910. fout.SetCopyIfDifferent(true);
  2911. /* clang-format off */
  2912. fout <<
  2913. "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
  2914. "<Package xmlns=\"http://schemas.microsoft.com/appx/2010/manifest\">\n"
  2915. "\t<Identity Name=\"" << this->GUID << "\" Publisher=\"CN=CMake\""
  2916. " Version=\"1.0.0.0\" />\n"
  2917. "\t<Properties>\n"
  2918. "\t\t<DisplayName>" << targetNameXML << "</DisplayName>\n"
  2919. "\t\t<PublisherDisplayName>CMake</PublisherDisplayName>\n"
  2920. "\t\t<Logo>" << artifactDirXML << "\\StoreLogo.png</Logo>\n"
  2921. "\t</Properties>\n"
  2922. "\t<Prerequisites>\n"
  2923. "\t\t<OSMinVersion>6.2.1</OSMinVersion>\n"
  2924. "\t\t<OSMaxVersionTested>6.2.1</OSMaxVersionTested>\n"
  2925. "\t</Prerequisites>\n"
  2926. "\t<Resources>\n"
  2927. "\t\t<Resource Language=\"x-generate\" />\n"
  2928. "\t</Resources>\n"
  2929. "\t<Applications>\n"
  2930. "\t\t<Application Id=\"App\""
  2931. " Executable=\"" << targetNameXML << ".exe\""
  2932. " EntryPoint=\"" << targetNameXML << ".App\">\n"
  2933. "\t\t\t<VisualElements"
  2934. " DisplayName=\"" << targetNameXML << "\""
  2935. " Description=\"" << targetNameXML << "\""
  2936. " BackgroundColor=\"#336699\" ForegroundText=\"light\""
  2937. " Logo=\"" << artifactDirXML << "\\Logo.png\""
  2938. " SmallLogo=\"" << artifactDirXML << "\\SmallLogo.png\">\n"
  2939. "\t\t\t\t<DefaultTile ShowName=\"allLogos\""
  2940. " ShortName=\"" << targetNameXML << "\" />\n"
  2941. "\t\t\t\t<SplashScreen"
  2942. " Image=\"" << artifactDirXML << "\\SplashScreen.png\" />\n"
  2943. "\t\t\t</VisualElements>\n"
  2944. "\t\t</Application>\n"
  2945. "\t</Applications>\n"
  2946. "</Package>\n";
  2947. /* clang-format on */
  2948. this->WriteCommonMissingFiles(manifestFile);
  2949. }
  2950. void cmVisualStudio10TargetGenerator::WriteMissingFilesWS81()
  2951. {
  2952. std::string manifestFile =
  2953. this->DefaultArtifactDir + "/package.appxManifest";
  2954. std::string artifactDir =
  2955. this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
  2956. this->ConvertToWindowsSlash(artifactDir);
  2957. std::string artifactDirXML = cmVS10EscapeXML(artifactDir);
  2958. std::string targetNameXML =
  2959. cmVS10EscapeXML(this->GeneratorTarget->GetName());
  2960. cmGeneratedFileStream fout(manifestFile.c_str());
  2961. fout.SetCopyIfDifferent(true);
  2962. /* clang-format off */
  2963. fout <<
  2964. "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
  2965. "<Package xmlns=\"http://schemas.microsoft.com/appx/2010/manifest\""
  2966. " xmlns:m2=\"http://schemas.microsoft.com/appx/2013/manifest\">\n"
  2967. "\t<Identity Name=\"" << this->GUID << "\" Publisher=\"CN=CMake\""
  2968. " Version=\"1.0.0.0\" />\n"
  2969. "\t<Properties>\n"
  2970. "\t\t<DisplayName>" << targetNameXML << "</DisplayName>\n"
  2971. "\t\t<PublisherDisplayName>CMake</PublisherDisplayName>\n"
  2972. "\t\t<Logo>" << artifactDirXML << "\\StoreLogo.png</Logo>\n"
  2973. "\t</Properties>\n"
  2974. "\t<Prerequisites>\n"
  2975. "\t\t<OSMinVersion>6.3</OSMinVersion>\n"
  2976. "\t\t<OSMaxVersionTested>6.3</OSMaxVersionTested>\n"
  2977. "\t</Prerequisites>\n"
  2978. "\t<Resources>\n"
  2979. "\t\t<Resource Language=\"x-generate\" />\n"
  2980. "\t</Resources>\n"
  2981. "\t<Applications>\n"
  2982. "\t\t<Application Id=\"App\""
  2983. " Executable=\"" << targetNameXML << ".exe\""
  2984. " EntryPoint=\"" << targetNameXML << ".App\">\n"
  2985. "\t\t\t<m2:VisualElements\n"
  2986. "\t\t\t\tDisplayName=\"" << targetNameXML << "\"\n"
  2987. "\t\t\t\tDescription=\"" << targetNameXML << "\"\n"
  2988. "\t\t\t\tBackgroundColor=\"#336699\"\n"
  2989. "\t\t\t\tForegroundText=\"light\"\n"
  2990. "\t\t\t\tSquare150x150Logo=\"" << artifactDirXML << "\\Logo.png\"\n"
  2991. "\t\t\t\tSquare30x30Logo=\"" << artifactDirXML << "\\SmallLogo.png\">\n"
  2992. "\t\t\t\t<m2:DefaultTile ShortName=\"" << targetNameXML << "\">\n"
  2993. "\t\t\t\t\t<m2:ShowNameOnTiles>\n"
  2994. "\t\t\t\t\t\t<m2:ShowOn Tile=\"square150x150Logo\" />\n"
  2995. "\t\t\t\t\t</m2:ShowNameOnTiles>\n"
  2996. "\t\t\t\t</m2:DefaultTile>\n"
  2997. "\t\t\t\t<m2:SplashScreen"
  2998. " Image=\"" << artifactDirXML << "\\SplashScreen.png\" />\n"
  2999. "\t\t\t</m2:VisualElements>\n"
  3000. "\t\t</Application>\n"
  3001. "\t</Applications>\n"
  3002. "</Package>\n";
  3003. /* clang-format on */
  3004. this->WriteCommonMissingFiles(manifestFile);
  3005. }
  3006. void cmVisualStudio10TargetGenerator::WriteMissingFilesWS10_0()
  3007. {
  3008. std::string manifestFile =
  3009. this->DefaultArtifactDir + "/package.appxManifest";
  3010. std::string artifactDir =
  3011. this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
  3012. this->ConvertToWindowsSlash(artifactDir);
  3013. std::string artifactDirXML = cmVS10EscapeXML(artifactDir);
  3014. std::string targetNameXML =
  3015. cmVS10EscapeXML(this->GeneratorTarget->GetName());
  3016. cmGeneratedFileStream fout(manifestFile.c_str());
  3017. fout.SetCopyIfDifferent(true);
  3018. /* clang-format off */
  3019. fout <<
  3020. "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
  3021. "<Package\n\t"
  3022. "xmlns=\"http://schemas.microsoft.com/appx/manifest/foundation/windows10\""
  3023. "\txmlns:mp=\"http://schemas.microsoft.com/appx/2014/phone/manifest\"\n"
  3024. "\txmlns:uap=\"http://schemas.microsoft.com/appx/manifest/uap/windows10\""
  3025. "\n\tIgnorableNamespaces=\"uap mp\">\n\n"
  3026. "\t<Identity Name=\"" << this->GUID << "\" Publisher=\"CN=CMake\""
  3027. " Version=\"1.0.0.0\" />\n"
  3028. "\t<mp:PhoneIdentity PhoneProductId=\"" << this->GUID <<
  3029. "\" PhonePublisherId=\"00000000-0000-0000-0000-000000000000\"/>\n"
  3030. "\t<Properties>\n"
  3031. "\t\t<DisplayName>" << targetNameXML << "</DisplayName>\n"
  3032. "\t\t<PublisherDisplayName>CMake</PublisherDisplayName>\n"
  3033. "\t\t<Logo>" << artifactDirXML << "\\StoreLogo.png</Logo>\n"
  3034. "\t</Properties>\n"
  3035. "\t<Dependencies>\n"
  3036. "\t\t<TargetDeviceFamily Name=\"Windows.Universal\" "
  3037. "MinVersion=\"10.0.0.0\" MaxVersionTested=\"10.0.0.0\" />\n"
  3038. "\t</Dependencies>\n"
  3039. "\t<Resources>\n"
  3040. "\t\t<Resource Language=\"x-generate\" />\n"
  3041. "\t</Resources>\n"
  3042. "\t<Applications>\n"
  3043. "\t\t<Application Id=\"App\""
  3044. " Executable=\"" << targetNameXML << ".exe\""
  3045. " EntryPoint=\"" << targetNameXML << ".App\">\n"
  3046. "\t\t\t<uap:VisualElements\n"
  3047. "\t\t\t\tDisplayName=\"" << targetNameXML << "\"\n"
  3048. "\t\t\t\tDescription=\"" << targetNameXML << "\"\n"
  3049. "\t\t\t\tBackgroundColor=\"#336699\"\n"
  3050. "\t\t\t\tSquare150x150Logo=\"" << artifactDirXML << "\\Logo.png\"\n"
  3051. "\t\t\t\tSquare44x44Logo=\"" << artifactDirXML <<
  3052. "\\SmallLogo44x44.png\">\n"
  3053. "\t\t\t\t<uap:SplashScreen"
  3054. " Image=\"" << artifactDirXML << "\\SplashScreen.png\" />\n"
  3055. "\t\t\t</uap:VisualElements>\n"
  3056. "\t\t</Application>\n"
  3057. "\t</Applications>\n"
  3058. "</Package>\n";
  3059. /* clang-format on */
  3060. this->WriteCommonMissingFiles(manifestFile);
  3061. }
  3062. void cmVisualStudio10TargetGenerator::WriteCommonMissingFiles(
  3063. const std::string& manifestFile)
  3064. {
  3065. std::string templateFolder =
  3066. cmSystemTools::GetCMakeRoot() + "/Templates/Windows";
  3067. std::string sourceFile = this->ConvertPath(manifestFile, false);
  3068. this->ConvertToWindowsSlash(sourceFile);
  3069. this->WriteString("<AppxManifest Include=\"", 2);
  3070. (*this->BuildFileStream) << cmVS10EscapeXML(sourceFile) << "\">\n";
  3071. this->WriteString("<SubType>Designer</SubType>\n", 3);
  3072. this->WriteString("</AppxManifest>\n", 2);
  3073. this->AddedFiles.push_back(sourceFile);
  3074. std::string smallLogo = this->DefaultArtifactDir + "/SmallLogo.png";
  3075. cmSystemTools::CopyAFile(templateFolder + "/SmallLogo.png", smallLogo,
  3076. false);
  3077. this->ConvertToWindowsSlash(smallLogo);
  3078. this->WriteString("<Image Include=\"", 2);
  3079. (*this->BuildFileStream) << cmVS10EscapeXML(smallLogo) << "\" />\n";
  3080. this->AddedFiles.push_back(smallLogo);
  3081. std::string smallLogo44 = this->DefaultArtifactDir + "/SmallLogo44x44.png";
  3082. cmSystemTools::CopyAFile(templateFolder + "/SmallLogo44x44.png", smallLogo44,
  3083. false);
  3084. this->ConvertToWindowsSlash(smallLogo44);
  3085. this->WriteString("<Image Include=\"", 2);
  3086. (*this->BuildFileStream) << cmVS10EscapeXML(smallLogo44) << "\" />\n";
  3087. this->AddedFiles.push_back(smallLogo44);
  3088. std::string logo = this->DefaultArtifactDir + "/Logo.png";
  3089. cmSystemTools::CopyAFile(templateFolder + "/Logo.png", logo, false);
  3090. this->ConvertToWindowsSlash(logo);
  3091. this->WriteString("<Image Include=\"", 2);
  3092. (*this->BuildFileStream) << cmVS10EscapeXML(logo) << "\" />\n";
  3093. this->AddedFiles.push_back(logo);
  3094. std::string storeLogo = this->DefaultArtifactDir + "/StoreLogo.png";
  3095. cmSystemTools::CopyAFile(templateFolder + "/StoreLogo.png", storeLogo,
  3096. false);
  3097. this->ConvertToWindowsSlash(storeLogo);
  3098. this->WriteString("<Image Include=\"", 2);
  3099. (*this->BuildFileStream) << cmVS10EscapeXML(storeLogo) << "\" />\n";
  3100. this->AddedFiles.push_back(storeLogo);
  3101. std::string splashScreen = this->DefaultArtifactDir + "/SplashScreen.png";
  3102. cmSystemTools::CopyAFile(templateFolder + "/SplashScreen.png", splashScreen,
  3103. false);
  3104. this->ConvertToWindowsSlash(splashScreen);
  3105. this->WriteString("<Image Include=\"", 2);
  3106. (*this->BuildFileStream) << cmVS10EscapeXML(splashScreen) << "\" />\n";
  3107. this->AddedFiles.push_back(splashScreen);
  3108. // This file has already been added to the build so don't copy it
  3109. std::string keyFile = this->DefaultArtifactDir + "/Windows_TemporaryKey.pfx";
  3110. this->ConvertToWindowsSlash(keyFile);
  3111. this->WriteString("<None Include=\"", 2);
  3112. (*this->BuildFileStream) << cmVS10EscapeXML(keyFile) << "\" />\n";
  3113. }
  3114. bool cmVisualStudio10TargetGenerator::ForceOld(const std::string& source) const
  3115. {
  3116. HANDLE h =
  3117. CreateFileW(cmSystemTools::ConvertToWindowsExtendedPath(source).c_str(),
  3118. FILE_WRITE_ATTRIBUTES, FILE_SHARE_WRITE, 0, OPEN_EXISTING,
  3119. FILE_FLAG_BACKUP_SEMANTICS, 0);
  3120. if (!h) {
  3121. return false;
  3122. }
  3123. FILETIME const ftime_20010101 = { 3365781504u, 29389701u };
  3124. if (!SetFileTime(h, &ftime_20010101, &ftime_20010101, &ftime_20010101)) {
  3125. CloseHandle(h);
  3126. return false;
  3127. }
  3128. CloseHandle(h);
  3129. return true;
  3130. }