cmVisualStudio10TargetGenerator.cxx 131 KB

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