cmVisualStudio10TargetGenerator.cxx 101 KB

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