cmVisualStudio10TargetGenerator.cxx 116 KB

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