cmVisualStudio10TargetGenerator.cxx 104 KB

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