cmVisualStudio10TargetGenerator.cxx 113 KB

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