cmVisualStudio10TargetGenerator.cxx 102 KB

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