cmVisualStudio10TargetGenerator.cxx 105 KB

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