1
0

cmVisualStudio10TargetGenerator.cxx 156 KB

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