cmVisualStudio10TargetGenerator.cxx 159 KB

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