cmVisualStudio10TargetGenerator.cxx 126 KB

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