cmVisualStudio10TargetGenerator.cxx 125 KB

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