1
0

cmVisualStudio10TargetGenerator.cxx 105 KB

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