cmVisualStudio10TargetGenerator.cxx 128 KB

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