cmVisualStudio10TargetGenerator.cxx 116 KB

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