cmVisualStudio10TargetGenerator.cxx 99 KB

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