cmVisualStudio10TargetGenerator.cxx 113 KB

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