cmVisualStudio10TargetGenerator.cxx 127 KB

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