cmVisualStudio10TargetGenerator.cxx 133 KB

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