cmVisualStudio10TargetGenerator.cxx 126 KB

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