cmVisualStudio10TargetGenerator.cxx 149 KB

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