cmVisualStudio10TargetGenerator.cxx 127 KB

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