cmVisualStudio10TargetGenerator.cxx 127 KB

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