cmVisualStudio10TargetGenerator.cxx 114 KB

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