cmVisualStudio10TargetGenerator.cxx 197 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540
  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 <algorithm>
  5. #include <cstdio>
  6. #include <cstring>
  7. #include <iterator>
  8. #include <set>
  9. #include <sstream>
  10. #include <cm/memory>
  11. #include <cm/optional>
  12. #include <cm/string_view>
  13. #include <cm/vector>
  14. #include <cmext/algorithm>
  15. #include "windows.h"
  16. #include "cmsys/FStream.hxx"
  17. #include "cmsys/RegularExpression.hxx"
  18. #include "cmComputeLinkInformation.h"
  19. #include "cmCustomCommand.h"
  20. #include "cmCustomCommandGenerator.h"
  21. #include "cmGeneratedFileStream.h"
  22. #include "cmGeneratorExpression.h"
  23. #include "cmGeneratorTarget.h"
  24. #include "cmGlobalGenerator.h"
  25. #include "cmGlobalVisualStudio10Generator.h"
  26. #include "cmGlobalVisualStudio7Generator.h"
  27. #include "cmGlobalVisualStudioGenerator.h"
  28. #include "cmLinkLineDeviceComputer.h"
  29. #include "cmListFileCache.h"
  30. #include "cmLocalGenerator.h"
  31. #include "cmLocalVisualStudio10Generator.h"
  32. #include "cmLocalVisualStudio7Generator.h"
  33. #include "cmLocalVisualStudioGenerator.h"
  34. #include "cmMakefile.h"
  35. #include "cmMessageType.h"
  36. #include "cmPropertyMap.h"
  37. #include "cmSourceFile.h"
  38. #include "cmSourceFileLocation.h"
  39. #include "cmSourceFileLocationKind.h"
  40. #include "cmSourceGroup.h"
  41. #include "cmStateTypes.h"
  42. #include "cmStringAlgorithms.h"
  43. #include "cmSystemTools.h"
  44. #include "cmTarget.h"
  45. #include "cmValue.h"
  46. #include "cmVisualStudioGeneratorOptions.h"
  47. struct cmIDEFlagTable;
  48. static void ConvertToWindowsSlash(std::string& s);
  49. static std::string cmVS10EscapeXML(std::string arg)
  50. {
  51. cmSystemTools::ReplaceString(arg, "&", "&amp;");
  52. cmSystemTools::ReplaceString(arg, "<", "&lt;");
  53. cmSystemTools::ReplaceString(arg, ">", "&gt;");
  54. return arg;
  55. }
  56. static std::string cmVS10EscapeAttr(std::string arg)
  57. {
  58. cmSystemTools::ReplaceString(arg, "&", "&amp;");
  59. cmSystemTools::ReplaceString(arg, "<", "&lt;");
  60. cmSystemTools::ReplaceString(arg, ">", "&gt;");
  61. cmSystemTools::ReplaceString(arg, "\"", "&quot;");
  62. cmSystemTools::ReplaceString(arg, "\n", "&#10;");
  63. return arg;
  64. }
  65. struct cmVisualStudio10TargetGenerator::Elem
  66. {
  67. std::ostream& S;
  68. const int Indent;
  69. bool HasElements = false;
  70. bool HasContent = false;
  71. std::string Tag;
  72. Elem(std::ostream& s, std::string tag)
  73. : S(s)
  74. , Indent(0)
  75. , Tag(std::move(tag))
  76. {
  77. this->StartElement();
  78. }
  79. Elem(const Elem&) = delete;
  80. Elem(Elem& par, cm::string_view tag)
  81. : S(par.S)
  82. , Indent(par.Indent + 1)
  83. , Tag(std::string(tag))
  84. {
  85. par.SetHasElements();
  86. this->StartElement();
  87. }
  88. void SetHasElements()
  89. {
  90. if (!HasElements) {
  91. this->S << ">";
  92. HasElements = true;
  93. }
  94. }
  95. std::ostream& WriteString(const char* line);
  96. void StartElement() { this->WriteString("<") << this->Tag; }
  97. void Element(cm::string_view tag, std::string val)
  98. {
  99. Elem(*this, tag).Content(std::move(val));
  100. }
  101. Elem& Attribute(const char* an, std::string av)
  102. {
  103. this->S << " " << an << "=\"" << cmVS10EscapeAttr(std::move(av)) << "\"";
  104. return *this;
  105. }
  106. void Content(std::string val)
  107. {
  108. if (!this->HasContent) {
  109. this->S << ">";
  110. this->HasContent = true;
  111. }
  112. this->S << cmVS10EscapeXML(std::move(val));
  113. }
  114. ~Elem()
  115. {
  116. // Do not emit element which has not been started
  117. if (Tag.empty()) {
  118. return;
  119. }
  120. if (HasElements) {
  121. this->WriteString("</") << this->Tag << ">";
  122. } else if (HasContent) {
  123. this->S << "</" << this->Tag << ">";
  124. } else {
  125. this->S << " />";
  126. }
  127. }
  128. void WritePlatformConfigTag(const std::string& tag, const std::string& cond,
  129. const std::string& content);
  130. };
  131. class cmVS10GeneratorOptions : public cmVisualStudioGeneratorOptions
  132. {
  133. public:
  134. using Elem = cmVisualStudio10TargetGenerator::Elem;
  135. cmVS10GeneratorOptions(cmLocalVisualStudioGenerator* lg, Tool tool,
  136. cmVS7FlagTable const* table,
  137. cmVisualStudio10TargetGenerator* g = nullptr)
  138. : cmVisualStudioGeneratorOptions(lg, tool, table)
  139. , TargetGenerator(g)
  140. {
  141. }
  142. void OutputFlag(std::ostream& /*fout*/, int /*indent*/,
  143. const std::string& tag, const std::string& content) override
  144. {
  145. if (!this->GetConfiguration().empty()) {
  146. // if there are configuration specific flags, then
  147. // use the configuration specific tag for PreprocessorDefinitions
  148. const std::string cond =
  149. this->TargetGenerator->CalcCondition(this->GetConfiguration());
  150. this->Parent->WritePlatformConfigTag(tag, cond, content);
  151. } else {
  152. this->Parent->Element(tag, content);
  153. }
  154. }
  155. private:
  156. cmVisualStudio10TargetGenerator* const TargetGenerator;
  157. Elem* Parent = nullptr;
  158. friend cmVisualStudio10TargetGenerator::OptionsHelper;
  159. };
  160. struct cmVisualStudio10TargetGenerator::OptionsHelper
  161. {
  162. cmVS10GeneratorOptions& O;
  163. OptionsHelper(cmVS10GeneratorOptions& o, Elem& e)
  164. : O(o)
  165. {
  166. O.Parent = &e;
  167. }
  168. ~OptionsHelper() { O.Parent = nullptr; }
  169. void OutputPreprocessorDefinitions(const std::string& lang)
  170. {
  171. O.OutputPreprocessorDefinitions(O.Parent->S, O.Parent->Indent + 1, lang);
  172. }
  173. void OutputAdditionalIncludeDirectories(const std::string& lang)
  174. {
  175. O.OutputAdditionalIncludeDirectories(O.Parent->S, O.Parent->Indent + 1,
  176. lang);
  177. }
  178. void OutputFlagMap() { O.OutputFlagMap(O.Parent->S, O.Parent->Indent + 1); }
  179. void PrependInheritedString(std::string const& key)
  180. {
  181. O.PrependInheritedString(key);
  182. }
  183. };
  184. static std::string cmVS10EscapeComment(std::string comment)
  185. {
  186. // MSBuild takes the CDATA of a <Message></Message> element and just
  187. // does "echo $CDATA" with no escapes. We must encode the string.
  188. // http://technet.microsoft.com/en-us/library/cc772462%28WS.10%29.aspx
  189. std::string echoable;
  190. for (char c : comment) {
  191. switch (c) {
  192. case '\r':
  193. break;
  194. case '\n':
  195. echoable += '\t';
  196. break;
  197. case '"': /* no break */
  198. case '|': /* no break */
  199. case '&': /* no break */
  200. case '<': /* no break */
  201. case '>': /* no break */
  202. case '^':
  203. echoable += '^'; /* no break */
  204. CM_FALLTHROUGH;
  205. default:
  206. echoable += c;
  207. break;
  208. }
  209. }
  210. return echoable;
  211. }
  212. static bool cmVS10IsTargetsFile(std::string const& path)
  213. {
  214. std::string const ext = cmSystemTools::GetFilenameLastExtension(path);
  215. return cmSystemTools::Strucmp(ext.c_str(), ".targets") == 0;
  216. }
  217. static VsProjectType computeProjectType(cmGeneratorTarget const* t)
  218. {
  219. if (t->IsCSharpOnly()) {
  220. return VsProjectType::csproj;
  221. }
  222. return VsProjectType::vcxproj;
  223. }
  224. static std::string computeProjectFileExtension(VsProjectType projectType)
  225. {
  226. switch (projectType) {
  227. case VsProjectType::csproj:
  228. return ".csproj";
  229. case VsProjectType::proj:
  230. return ".proj";
  231. default:
  232. return ".vcxproj";
  233. }
  234. }
  235. static std::string computeProjectFileExtension(cmGeneratorTarget const* t)
  236. {
  237. return computeProjectFileExtension(computeProjectType(t));
  238. }
  239. cmVisualStudio10TargetGenerator::cmVisualStudio10TargetGenerator(
  240. cmGeneratorTarget* target, cmGlobalVisualStudio10Generator* gg)
  241. : GeneratorTarget(target)
  242. , Makefile(target->Target->GetMakefile())
  243. , Platform(gg->GetPlatformName())
  244. , Name(target->GetName())
  245. , GUID(gg->GetGUID(this->Name))
  246. , GlobalGenerator(gg)
  247. , LocalGenerator(
  248. (cmLocalVisualStudio10Generator*)target->GetLocalGenerator())
  249. {
  250. this->Configurations =
  251. this->Makefile->GetGeneratorConfigs(cmMakefile::ExcludeEmptyConfig);
  252. this->NsightTegra = gg->IsNsightTegra();
  253. this->Android = gg->TargetsAndroid();
  254. for (int i = 0; i < 4; ++i) {
  255. this->NsightTegraVersion[i] = 0;
  256. }
  257. sscanf(gg->GetNsightTegraVersion().c_str(), "%u.%u.%u.%u",
  258. &this->NsightTegraVersion[0], &this->NsightTegraVersion[1],
  259. &this->NsightTegraVersion[2], &this->NsightTegraVersion[3]);
  260. this->MSTools = !this->NsightTegra && !this->Android;
  261. this->Managed = false;
  262. this->TargetCompileAsWinRT = false;
  263. this->IsMissingFiles = false;
  264. this->DefaultArtifactDir =
  265. this->LocalGenerator->GetCurrentBinaryDirectory() + "/" +
  266. this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
  267. this->InSourceBuild = (this->Makefile->GetCurrentSourceDirectory() ==
  268. this->Makefile->GetCurrentBinaryDirectory());
  269. this->ClassifyAllConfigSources();
  270. }
  271. cmVisualStudio10TargetGenerator::~cmVisualStudio10TargetGenerator() = default;
  272. std::string cmVisualStudio10TargetGenerator::CalcCondition(
  273. const std::string& config) const
  274. {
  275. std::ostringstream oss;
  276. oss << "'$(Configuration)|$(Platform)'=='";
  277. oss << config << "|" << this->Platform;
  278. oss << "'";
  279. // handle special case for 32 bit C# targets
  280. if (this->ProjectType == VsProjectType::csproj &&
  281. this->Platform == "Win32") {
  282. oss << " Or ";
  283. oss << "'$(Configuration)|$(Platform)'=='";
  284. oss << config << "|x86";
  285. oss << "'";
  286. }
  287. return oss.str();
  288. }
  289. void cmVisualStudio10TargetGenerator::Elem::WritePlatformConfigTag(
  290. const std::string& tag, const std::string& cond, const std::string& content)
  291. {
  292. Elem(*this, tag).Attribute("Condition", cond).Content(content);
  293. }
  294. std::ostream& cmVisualStudio10TargetGenerator::Elem::WriteString(
  295. const char* line)
  296. {
  297. this->S << '\n';
  298. this->S.fill(' ');
  299. this->S.width(this->Indent * 2);
  300. // write an empty string to get the fill level indent to print
  301. this->S << "";
  302. this->S << line;
  303. return this->S;
  304. }
  305. #define VS10_CXX_DEFAULT_PROPS "$(VCTargetsPath)\\Microsoft.Cpp.Default.props"
  306. #define VS10_CXX_PROPS "$(VCTargetsPath)\\Microsoft.Cpp.props"
  307. #define VS10_CXX_USER_PROPS \
  308. "$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props"
  309. #define VS10_CXX_TARGETS "$(VCTargetsPath)\\Microsoft.Cpp.targets"
  310. #define VS10_CSharp_DEFAULT_PROPS \
  311. "$(MSBuildExtensionsPath)\\$(MSBuildToolsVersion)\\Microsoft.Common.props"
  312. // This does not seem to exist by default, it's just provided for consistency
  313. // in case users want to have default custom props for C# targets
  314. #define VS10_CSharp_USER_PROPS \
  315. "$(UserRootDir)\\Microsoft.CSharp.$(Platform).user.props"
  316. #define VS10_CSharp_TARGETS "$(MSBuildToolsPath)\\Microsoft.CSharp.targets"
  317. #define VS10_CSharp_NETCF_TARGETS \
  318. "$(MSBuildExtensionsPath)\\Microsoft\\$(TargetFrameworkIdentifier)\\" \
  319. "$(TargetFrameworkTargetsVersion)\\Microsoft.$(TargetFrameworkIdentifier)" \
  320. ".CSharp.targets"
  321. void cmVisualStudio10TargetGenerator::Generate()
  322. {
  323. for (std::string const& config : this->Configurations) {
  324. this->GeneratorTarget->CheckCxxModuleStatus(config);
  325. }
  326. if (this->GeneratorTarget->HaveCxx20ModuleSources()) {
  327. this->Makefile->IssueMessage(
  328. MessageType::FATAL_ERROR,
  329. cmStrCat("The \"", this->GeneratorTarget->GetName(),
  330. "\" target contains C++ module sources which are not supported "
  331. "by the generator"));
  332. }
  333. this->ProjectType = computeProjectType(this->GeneratorTarget);
  334. this->Managed = this->ProjectType == VsProjectType::csproj;
  335. const std::string ProjectFileExtension =
  336. computeProjectFileExtension(this->ProjectType);
  337. if (this->ProjectType == VsProjectType::csproj &&
  338. this->GeneratorTarget->GetType() == cmStateEnums::STATIC_LIBRARY) {
  339. std::string message = "The C# target \"" +
  340. this->GeneratorTarget->GetName() +
  341. "\" is of type STATIC_LIBRARY. This is discouraged (and may be "
  342. "disabled in future). Make it a SHARED library instead.";
  343. this->Makefile->IssueMessage(MessageType::DEPRECATION_WARNING, message);
  344. }
  345. if (this->Android &&
  346. this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE &&
  347. !this->GeneratorTarget->Target->IsAndroidGuiExecutable()) {
  348. this->GlobalGenerator->AddAndroidExecutableWarning(this->Name);
  349. }
  350. // Tell the global generator the name of the project file
  351. this->GeneratorTarget->Target->SetProperty("GENERATOR_FILE_NAME",
  352. this->Name);
  353. this->GeneratorTarget->Target->SetProperty("GENERATOR_FILE_NAME_EXT",
  354. ProjectFileExtension);
  355. this->DotNetHintReferences.clear();
  356. this->AdditionalUsingDirectories.clear();
  357. if (this->GeneratorTarget->GetType() <= cmStateEnums::OBJECT_LIBRARY) {
  358. if (!this->ComputeClOptions()) {
  359. return;
  360. }
  361. if (!this->ComputeRcOptions()) {
  362. return;
  363. }
  364. if (!this->ComputeCudaOptions()) {
  365. return;
  366. }
  367. if (!this->ComputeCudaLinkOptions()) {
  368. return;
  369. }
  370. if (!this->ComputeMarmasmOptions()) {
  371. return;
  372. }
  373. if (!this->ComputeMasmOptions()) {
  374. return;
  375. }
  376. if (!this->ComputeNasmOptions()) {
  377. return;
  378. }
  379. if (!this->ComputeLinkOptions()) {
  380. return;
  381. }
  382. if (!this->ComputeLibOptions()) {
  383. return;
  384. }
  385. }
  386. std::string path =
  387. cmStrCat(this->LocalGenerator->GetCurrentBinaryDirectory(), '/',
  388. this->Name, ProjectFileExtension);
  389. cmGeneratedFileStream BuildFileStream(path);
  390. const std::string& PathToProjectFile = path;
  391. BuildFileStream.SetCopyIfDifferent(true);
  392. // Write the encoding header into the file
  393. char magic[] = { char(0xEF), char(0xBB), char(0xBF) };
  394. BuildFileStream.write(magic, 3);
  395. if (this->ProjectType == VsProjectType::csproj &&
  396. this->GeneratorTarget->IsDotNetSdkTarget() &&
  397. this->GlobalGenerator->GetVersion() >=
  398. cmGlobalVisualStudioGenerator::VSVersion::VS16) {
  399. this->WriteSdkStyleProjectFile(BuildFileStream);
  400. } else {
  401. this->WriteClassicMsBuildProjectFile(BuildFileStream);
  402. }
  403. if (BuildFileStream.Close()) {
  404. this->GlobalGenerator->FileReplacedDuringGenerate(PathToProjectFile);
  405. }
  406. // The groups are stored in a separate file for VS 10
  407. this->WriteGroups();
  408. // Update cache with project-specific entries.
  409. this->UpdateCache();
  410. }
  411. void cmVisualStudio10TargetGenerator::WriteClassicMsBuildProjectFile(
  412. cmGeneratedFileStream& BuildFileStream)
  413. {
  414. BuildFileStream << "<?xml version=\"1.0\" encoding=\""
  415. << this->GlobalGenerator->Encoding() << "\"?>";
  416. {
  417. Elem e0(BuildFileStream, "Project");
  418. e0.Attribute("DefaultTargets", "Build");
  419. const char* toolsVersion = this->GlobalGenerator->GetToolsVersion();
  420. if (this->GlobalGenerator->GetVersion() ==
  421. cmGlobalVisualStudioGenerator::VSVersion::VS12 &&
  422. this->GlobalGenerator->TargetsWindowsCE()) {
  423. toolsVersion = "4.0";
  424. }
  425. e0.Attribute("ToolsVersion", toolsVersion);
  426. e0.Attribute("xmlns",
  427. "http://schemas.microsoft.com/developer/msbuild/2003");
  428. if (this->NsightTegra) {
  429. Elem e1(e0, "PropertyGroup");
  430. e1.Attribute("Label", "NsightTegraProject");
  431. const unsigned int nsightTegraMajorVersion = this->NsightTegraVersion[0];
  432. const unsigned int nsightTegraMinorVersion = this->NsightTegraVersion[1];
  433. if (nsightTegraMajorVersion >= 2) {
  434. if (nsightTegraMajorVersion > 3 ||
  435. (nsightTegraMajorVersion == 3 && nsightTegraMinorVersion >= 1)) {
  436. e1.Element("NsightTegraProjectRevisionNumber", "11");
  437. } else {
  438. // Nsight Tegra 2.0 uses project revision 9.
  439. e1.Element("NsightTegraProjectRevisionNumber", "9");
  440. }
  441. // Tell newer versions to upgrade silently when loading.
  442. e1.Element("NsightTegraUpgradeOnceWithoutPrompt", "true");
  443. } else {
  444. // Require Nsight Tegra 1.6 for JCompile support.
  445. e1.Element("NsightTegraProjectRevisionNumber", "7");
  446. }
  447. }
  448. if (const char* hostArch =
  449. this->GlobalGenerator->GetPlatformToolsetHostArchitecture()) {
  450. Elem e1(e0, "PropertyGroup");
  451. e1.Element("PreferredToolArchitecture", hostArch);
  452. }
  453. // The ALL_BUILD, PACKAGE, and ZERO_CHECK projects transitively include
  454. // Microsoft.Common.CurrentVersion.targets which triggers Target
  455. // ResolveNugetPackageAssets when SDK-style targets are in the project.
  456. // However, these projects have no nuget packages to reference and the
  457. // build fails.
  458. // Setting ResolveNugetPackages to false skips this target and the build
  459. // succeeds.
  460. cm::string_view targetName{ this->GeneratorTarget->GetName() };
  461. if (targetName == "ALL_BUILD" || targetName == "PACKAGE" ||
  462. targetName == CMAKE_CHECK_BUILD_SYSTEM_TARGET) {
  463. Elem e1(e0, "PropertyGroup");
  464. e1.Element("ResolveNugetPackages", "false");
  465. }
  466. if (this->ProjectType != VsProjectType::csproj) {
  467. this->WriteProjectConfigurations(e0);
  468. }
  469. {
  470. Elem e1(e0, "PropertyGroup");
  471. this->WriteCommonPropertyGroupGlobals(e1);
  472. if ((this->MSTools || this->Android) &&
  473. this->GeneratorTarget->IsInBuildSystem()) {
  474. this->WriteApplicationTypeSettings(e1);
  475. this->VerifyNecessaryFiles();
  476. }
  477. cmValue vsProjectName =
  478. this->GeneratorTarget->GetProperty("VS_SCC_PROJECTNAME");
  479. cmValue vsLocalPath =
  480. this->GeneratorTarget->GetProperty("VS_SCC_LOCALPATH");
  481. cmValue vsProvider =
  482. this->GeneratorTarget->GetProperty("VS_SCC_PROVIDER");
  483. if (vsProjectName && vsLocalPath && vsProvider) {
  484. e1.Element("SccProjectName", *vsProjectName);
  485. e1.Element("SccLocalPath", *vsLocalPath);
  486. e1.Element("SccProvider", *vsProvider);
  487. cmValue vsAuxPath =
  488. this->GeneratorTarget->GetProperty("VS_SCC_AUXPATH");
  489. if (vsAuxPath) {
  490. e1.Element("SccAuxPath", *vsAuxPath);
  491. }
  492. }
  493. if (this->GeneratorTarget->GetPropertyAsBool("VS_WINRT_COMPONENT")) {
  494. e1.Element("WinMDAssembly", "true");
  495. }
  496. e1.Element("Platform", this->Platform);
  497. cmValue projLabel = this->GeneratorTarget->GetProperty("PROJECT_LABEL");
  498. e1.Element("ProjectName", projLabel ? projLabel : this->Name);
  499. {
  500. cm::optional<std::string> targetFramework;
  501. cm::optional<std::string> targetFrameworkVersion;
  502. cm::optional<std::string> targetFrameworkIdentifier;
  503. cm::optional<std::string> targetFrameworkTargetsVersion;
  504. if (cmValue tf =
  505. this->GeneratorTarget->GetProperty("DOTNET_TARGET_FRAMEWORK")) {
  506. targetFramework = *tf;
  507. } else if (cmValue vstfVer = this->GeneratorTarget->GetProperty(
  508. "VS_DOTNET_TARGET_FRAMEWORK_VERSION")) {
  509. // FIXME: Someday, add a deprecation warning for VS_* property.
  510. targetFrameworkVersion = *vstfVer;
  511. } else if (cmValue tfVer = this->GeneratorTarget->GetProperty(
  512. "DOTNET_TARGET_FRAMEWORK_VERSION")) {
  513. targetFrameworkVersion = *tfVer;
  514. } else if (this->ProjectType == VsProjectType::csproj) {
  515. targetFrameworkVersion =
  516. this->GlobalGenerator->GetTargetFrameworkVersion();
  517. }
  518. if (this->ProjectType == VsProjectType::vcxproj &&
  519. this->GlobalGenerator->TargetsWindowsCE()) {
  520. e1.Element("EnableRedirectPlatform", "true");
  521. e1.Element("RedirectPlatformValue", this->Platform);
  522. }
  523. if (this->ProjectType == VsProjectType::csproj) {
  524. if (this->GlobalGenerator->TargetsWindowsCE()) {
  525. // FIXME: These target VS_TARGET_FRAMEWORK* target properties
  526. // are undocumented settings only ever supported for WinCE.
  527. // We need a better way to control these in general.
  528. if (cmValue tfId = this->GeneratorTarget->GetProperty(
  529. "VS_TARGET_FRAMEWORK_IDENTIFIER")) {
  530. targetFrameworkIdentifier = *tfId;
  531. }
  532. if (cmValue tfTargetsVer = this->GeneratorTarget->GetProperty(
  533. "VS_TARGET_FRAMEWORKS_TARGET_VERSION")) {
  534. targetFrameworkTargetsVersion = *tfTargetsVer;
  535. }
  536. }
  537. if (!targetFrameworkIdentifier) {
  538. targetFrameworkIdentifier =
  539. this->GlobalGenerator->GetTargetFrameworkIdentifier();
  540. }
  541. if (!targetFrameworkTargetsVersion) {
  542. targetFrameworkTargetsVersion =
  543. this->GlobalGenerator->GetTargetFrameworkTargetsVersion();
  544. }
  545. }
  546. if (targetFramework) {
  547. if (targetFramework->find(';') != std::string::npos) {
  548. e1.Element("TargetFrameworks", *targetFramework);
  549. } else {
  550. e1.Element("TargetFramework", *targetFramework);
  551. }
  552. }
  553. if (targetFrameworkVersion) {
  554. e1.Element("TargetFrameworkVersion", *targetFrameworkVersion);
  555. }
  556. if (targetFrameworkIdentifier) {
  557. e1.Element("TargetFrameworkIdentifier", *targetFrameworkIdentifier);
  558. }
  559. if (targetFrameworkTargetsVersion) {
  560. e1.Element("TargetFrameworkTargetsVersion",
  561. *targetFrameworkTargetsVersion);
  562. }
  563. if (!this->GlobalGenerator->GetPlatformToolsetCudaCustomDirString()
  564. .empty()) {
  565. e1.Element(
  566. "CudaToolkitCustomDir",
  567. this->GlobalGenerator->GetPlatformToolsetCudaCustomDirString() +
  568. this->GlobalGenerator->GetPlatformToolsetCudaNvccSubdirString());
  569. }
  570. }
  571. // Disable the project upgrade prompt that is displayed the first time a
  572. // project using an older toolset version is opened in a newer version of
  573. // the IDE (respected by VS 2013 and above).
  574. if (this->GlobalGenerator->GetVersion() >=
  575. cmGlobalVisualStudioGenerator::VSVersion::VS12) {
  576. e1.Element("VCProjectUpgraderObjectName", "NoUpgrade");
  577. }
  578. if (const char* vcTargetsPath =
  579. this->GlobalGenerator->GetCustomVCTargetsPath()) {
  580. e1.Element("VCTargetsPath", vcTargetsPath);
  581. }
  582. if (this->Managed) {
  583. if (this->LocalGenerator->GetVersion() >=
  584. cmGlobalVisualStudioGenerator::VSVersion::VS17) {
  585. e1.Element("ManagedAssembly", "true");
  586. }
  587. std::string outputType;
  588. switch (this->GeneratorTarget->GetType()) {
  589. case cmStateEnums::OBJECT_LIBRARY:
  590. case cmStateEnums::STATIC_LIBRARY:
  591. case cmStateEnums::SHARED_LIBRARY:
  592. outputType = "Library";
  593. break;
  594. case cmStateEnums::MODULE_LIBRARY:
  595. outputType = "Module";
  596. break;
  597. case cmStateEnums::EXECUTABLE: {
  598. auto const win32 =
  599. this->GeneratorTarget->GetSafeProperty("WIN32_EXECUTABLE");
  600. if (win32.find("$<") != std::string::npos) {
  601. this->Makefile->IssueMessage(
  602. MessageType::FATAL_ERROR,
  603. cmStrCat(
  604. "Target \"", this->GeneratorTarget->GetName(),
  605. "\" has a generator expression in its WIN32_EXECUTABLE "
  606. "property. This is not supported on managed executables."));
  607. return;
  608. }
  609. if (cmIsOn(win32)) {
  610. outputType = "WinExe";
  611. } else {
  612. outputType = "Exe";
  613. }
  614. } break;
  615. case cmStateEnums::UTILITY:
  616. case cmStateEnums::INTERFACE_LIBRARY:
  617. case cmStateEnums::GLOBAL_TARGET:
  618. outputType = "Utility";
  619. break;
  620. case cmStateEnums::UNKNOWN_LIBRARY:
  621. break;
  622. }
  623. e1.Element("OutputType", outputType);
  624. e1.Element("AppDesignerFolder", "Properties");
  625. }
  626. }
  627. cmValue startupObject =
  628. this->GeneratorTarget->GetProperty("VS_DOTNET_STARTUP_OBJECT");
  629. if (startupObject && this->Managed) {
  630. Elem e1(e0, "PropertyGroup");
  631. e1.Element("StartupObject", *startupObject);
  632. }
  633. switch (this->ProjectType) {
  634. case VsProjectType::vcxproj: {
  635. std::string const& props =
  636. this->GlobalGenerator->GetPlatformToolsetVersionProps();
  637. if (!props.empty()) {
  638. Elem(e0, "Import").Attribute("Project", props);
  639. }
  640. Elem(e0, "Import").Attribute("Project", VS10_CXX_DEFAULT_PROPS);
  641. } break;
  642. case VsProjectType::csproj:
  643. Elem(e0, "Import")
  644. .Attribute("Project", VS10_CSharp_DEFAULT_PROPS)
  645. .Attribute("Condition", "Exists('" VS10_CSharp_DEFAULT_PROPS "')");
  646. break;
  647. default:
  648. break;
  649. }
  650. this->WriteProjectConfigurationValues(e0);
  651. if (this->ProjectType == VsProjectType::vcxproj) {
  652. Elem(e0, "Import").Attribute("Project", VS10_CXX_PROPS);
  653. }
  654. {
  655. Elem e1(e0, "ImportGroup");
  656. e1.Attribute("Label", "ExtensionSettings");
  657. e1.SetHasElements();
  658. if (this->GlobalGenerator->IsCudaEnabled()) {
  659. auto customDir =
  660. this->GlobalGenerator->GetPlatformToolsetCudaCustomDirString();
  661. std::string cudaPath = customDir.empty()
  662. ? "$(VCTargetsPath)\\BuildCustomizations\\"
  663. : customDir +
  664. this->GlobalGenerator
  665. ->GetPlatformToolsetCudaVSIntegrationSubdirString() +
  666. "extras\\visual_studio_integration\\MSBuildExtensions\\";
  667. Elem(e1, "Import")
  668. .Attribute("Project",
  669. std::move(cudaPath) + "CUDA " +
  670. this->GlobalGenerator->GetPlatformToolsetCuda() +
  671. ".props");
  672. }
  673. if (this->GlobalGenerator->IsMarmasmEnabled()) {
  674. Elem(e1, "Import")
  675. .Attribute("Project",
  676. "$(VCTargetsPath)\\BuildCustomizations\\marmasm.props");
  677. }
  678. if (this->GlobalGenerator->IsMasmEnabled()) {
  679. Elem(e1, "Import")
  680. .Attribute("Project",
  681. "$(VCTargetsPath)\\BuildCustomizations\\masm.props");
  682. }
  683. if (this->GlobalGenerator->IsNasmEnabled()) {
  684. // Always search in the standard modules location.
  685. std::string propsTemplate =
  686. GetCMakeFilePath("Templates/MSBuild/nasm.props.in");
  687. std::string propsLocal =
  688. cmStrCat(this->DefaultArtifactDir, "\\nasm.props");
  689. ConvertToWindowsSlash(propsLocal);
  690. this->Makefile->ConfigureFile(propsTemplate, propsLocal, false, true,
  691. true);
  692. Elem(e1, "Import").Attribute("Project", propsLocal);
  693. }
  694. }
  695. {
  696. Elem e1(e0, "ImportGroup");
  697. e1.Attribute("Label", "PropertySheets");
  698. std::string props;
  699. switch (this->ProjectType) {
  700. case VsProjectType::vcxproj:
  701. props = VS10_CXX_USER_PROPS;
  702. break;
  703. case VsProjectType::csproj:
  704. props = VS10_CSharp_USER_PROPS;
  705. break;
  706. default:
  707. break;
  708. }
  709. if (cmValue p = this->GeneratorTarget->GetProperty("VS_USER_PROPS")) {
  710. props = *p;
  711. }
  712. if (!props.empty()) {
  713. ConvertToWindowsSlash(props);
  714. Elem(e1, "Import")
  715. .Attribute("Project", props)
  716. .Attribute("Condition", "exists('" + props + "')")
  717. .Attribute("Label", "LocalAppDataPlatform");
  718. }
  719. this->WritePlatformExtensions(e1);
  720. }
  721. this->WriteDotNetDocumentationFile(e0);
  722. Elem(e0, "PropertyGroup").Attribute("Label", "UserMacros");
  723. this->WriteWinRTPackageCertificateKeyFile(e0);
  724. this->WritePathAndIncrementalLinkOptions(e0);
  725. this->WriteCEDebugProjectConfigurationValues(e0);
  726. this->WriteItemDefinitionGroups(e0);
  727. this->WriteCustomCommands(e0);
  728. this->WriteAllSources(e0);
  729. this->WriteDotNetReferences(e0);
  730. this->WritePackageReferences(e0);
  731. this->WriteImports(e0);
  732. this->WriteEmbeddedResourceGroup(e0);
  733. this->WriteXamlFilesGroup(e0);
  734. this->WriteWinRTReferences(e0);
  735. this->WriteProjectReferences(e0);
  736. this->WriteSDKReferences(e0);
  737. switch (this->ProjectType) {
  738. case VsProjectType::vcxproj:
  739. Elem(e0, "Import").Attribute("Project", VS10_CXX_TARGETS);
  740. break;
  741. case VsProjectType::csproj:
  742. if (this->GlobalGenerator->TargetsWindowsCE()) {
  743. Elem(e0, "Import").Attribute("Project", VS10_CSharp_NETCF_TARGETS);
  744. } else {
  745. Elem(e0, "Import").Attribute("Project", VS10_CSharp_TARGETS);
  746. }
  747. break;
  748. default:
  749. break;
  750. }
  751. this->WriteTargetSpecificReferences(e0);
  752. {
  753. Elem e1(e0, "ImportGroup");
  754. e1.Attribute("Label", "ExtensionTargets");
  755. e1.SetHasElements();
  756. this->WriteTargetsFileReferences(e1);
  757. if (this->GlobalGenerator->IsCudaEnabled()) {
  758. auto customDir =
  759. this->GlobalGenerator->GetPlatformToolsetCudaCustomDirString();
  760. std::string cudaPath = customDir.empty()
  761. ? "$(VCTargetsPath)\\BuildCustomizations\\"
  762. : customDir +
  763. this->GlobalGenerator
  764. ->GetPlatformToolsetCudaVSIntegrationSubdirString() +
  765. "extras\\visual_studio_integration\\MSBuildExtensions\\";
  766. Elem(e1, "Import")
  767. .Attribute("Project",
  768. std::move(cudaPath) + "CUDA " +
  769. this->GlobalGenerator->GetPlatformToolsetCuda() +
  770. ".targets");
  771. }
  772. if (this->GlobalGenerator->IsMarmasmEnabled()) {
  773. Elem(e1, "Import")
  774. .Attribute("Project",
  775. "$(VCTargetsPath)\\BuildCustomizations\\marmasm.targets");
  776. }
  777. if (this->GlobalGenerator->IsMasmEnabled()) {
  778. Elem(e1, "Import")
  779. .Attribute("Project",
  780. "$(VCTargetsPath)\\BuildCustomizations\\masm.targets");
  781. }
  782. if (this->GlobalGenerator->IsNasmEnabled()) {
  783. std::string nasmTargets =
  784. GetCMakeFilePath("Templates/MSBuild/nasm.targets");
  785. Elem(e1, "Import").Attribute("Project", nasmTargets);
  786. }
  787. }
  788. if (this->ProjectType == VsProjectType::vcxproj &&
  789. this->HaveCustomCommandDepfile) {
  790. std::string depfileTargets =
  791. GetCMakeFilePath("Templates/MSBuild/CustomBuildDepFile.targets");
  792. Elem(e0, "Import").Attribute("Project", depfileTargets);
  793. }
  794. if (this->ProjectType == VsProjectType::csproj) {
  795. for (std::string const& c : this->Configurations) {
  796. Elem e1(e0, "PropertyGroup");
  797. e1.Attribute("Condition", "'$(Configuration)' == '" + c + "'");
  798. e1.SetHasElements();
  799. this->WriteEvents(e1, c);
  800. }
  801. // make sure custom commands are executed before build (if necessary)
  802. {
  803. Elem e1(e0, "PropertyGroup");
  804. std::ostringstream oss;
  805. oss << "\n";
  806. for (std::string const& i : this->CSharpCustomCommandNames) {
  807. oss << " " << i << ";\n";
  808. }
  809. oss << " "
  810. << "$(BuildDependsOn)\n";
  811. e1.Element("BuildDependsOn", oss.str());
  812. }
  813. }
  814. }
  815. }
  816. void cmVisualStudio10TargetGenerator::WriteSdkStyleProjectFile(
  817. cmGeneratedFileStream& BuildFileStream)
  818. {
  819. if (this->ProjectType != VsProjectType::csproj ||
  820. !this->GeneratorTarget->IsDotNetSdkTarget()) {
  821. std::string message = "The target \"" + this->GeneratorTarget->GetName() +
  822. "\" is not eligible for .Net SDK style project.";
  823. this->Makefile->IssueMessage(MessageType::INTERNAL_ERROR, message);
  824. return;
  825. }
  826. if (this->HasCustomCommands()) {
  827. std::string message = "The target \"" + this->GeneratorTarget->GetName() +
  828. "\" does not currently support add_custom_command as the Visual Studio "
  829. "generators have not yet learned how to generate custom commands in "
  830. ".Net SDK-style projects.";
  831. this->Makefile->IssueMessage(MessageType::FATAL_ERROR, message);
  832. return;
  833. }
  834. Elem e0(BuildFileStream, "Project");
  835. e0.Attribute("Sdk", *this->GeneratorTarget->GetProperty("DOTNET_SDK"));
  836. {
  837. Elem e1(e0, "PropertyGroup");
  838. this->WriteCommonPropertyGroupGlobals(e1);
  839. e1.Element("EnableDefaultItems", "false");
  840. // Disable the project upgrade prompt that is displayed the first time a
  841. // project using an older toolset version is opened in a newer version
  842. // of the IDE.
  843. e1.Element("VCProjectUpgraderObjectName", "NoUpgrade");
  844. e1.Element("ManagedAssembly", "true");
  845. cmValue targetFramework =
  846. this->GeneratorTarget->GetProperty("DOTNET_TARGET_FRAMEWORK");
  847. if (targetFramework) {
  848. if (targetFramework->find(';') != std::string::npos) {
  849. e1.Element("TargetFrameworks", *targetFramework);
  850. } else {
  851. e1.Element("TargetFramework", *targetFramework);
  852. e1.Element("AppendTargetFrameworkToOutputPath", "false");
  853. }
  854. } else {
  855. e1.Element("TargetFramework", "net5.0");
  856. e1.Element("AppendTargetFrameworkToOutputPath", "false");
  857. }
  858. std::string outputType;
  859. switch (this->GeneratorTarget->GetType()) {
  860. case cmStateEnums::OBJECT_LIBRARY:
  861. case cmStateEnums::STATIC_LIBRARY:
  862. case cmStateEnums::MODULE_LIBRARY:
  863. this->Makefile->IssueMessage(
  864. MessageType::FATAL_ERROR,
  865. cmStrCat("Target \"", this->GeneratorTarget->GetName(),
  866. "\" is of a type not supported for managed binaries."));
  867. return;
  868. case cmStateEnums::SHARED_LIBRARY:
  869. outputType = "Library";
  870. break;
  871. case cmStateEnums::EXECUTABLE: {
  872. auto const win32 =
  873. this->GeneratorTarget->GetSafeProperty("WIN32_EXECUTABLE");
  874. if (win32.find("$<") != std::string::npos) {
  875. this->Makefile->IssueMessage(
  876. MessageType::FATAL_ERROR,
  877. cmStrCat("Target \"", this->GeneratorTarget->GetName(),
  878. "\" has a generator expression in its WIN32_EXECUTABLE "
  879. "property. This is not supported on managed "
  880. "executables."));
  881. return;
  882. }
  883. outputType = "Exe";
  884. } break;
  885. case cmStateEnums::UTILITY:
  886. case cmStateEnums::INTERFACE_LIBRARY:
  887. case cmStateEnums::GLOBAL_TARGET:
  888. outputType = "Utility";
  889. break;
  890. case cmStateEnums::UNKNOWN_LIBRARY:
  891. break;
  892. }
  893. e1.Element("OutputType", outputType);
  894. cmValue startupObject =
  895. this->GeneratorTarget->GetProperty("VS_DOTNET_STARTUP_OBJECT");
  896. if (startupObject) {
  897. e1.Element("StartupObject", *startupObject);
  898. }
  899. }
  900. for (const std::string& config : this->Configurations) {
  901. Elem e1(e0, "PropertyGroup");
  902. e1.Attribute("Condition", "'$(Configuration)' == '" + config + "'");
  903. e1.SetHasElements();
  904. this->WriteEvents(e1, config);
  905. std::string outDir = this->GeneratorTarget->GetDirectory(config) + "/";
  906. ConvertToWindowsSlash(outDir);
  907. e1.Element("OutputPath", outDir);
  908. Options& o = *(this->ClOptions[config]);
  909. OptionsHelper oh(o, e1);
  910. oh.OutputFlagMap();
  911. }
  912. this->WriteDotNetDocumentationFile(e0);
  913. this->WriteAllSources(e0);
  914. this->WriteDotNetReferences(e0);
  915. this->WritePackageReferences(e0);
  916. this->WriteProjectReferences(e0);
  917. }
  918. void cmVisualStudio10TargetGenerator::WriteCommonPropertyGroupGlobals(Elem& e1)
  919. {
  920. e1.Attribute("Label", "Globals");
  921. e1.Element("ProjectGuid", "{" + this->GUID + "}");
  922. cmValue vsProjectTypes =
  923. this->GeneratorTarget->GetProperty("VS_GLOBAL_PROJECT_TYPES");
  924. if (vsProjectTypes) {
  925. const char* tagName = "ProjectTypes";
  926. if (this->ProjectType == VsProjectType::csproj) {
  927. tagName = "ProjectTypeGuids";
  928. }
  929. e1.Element(tagName, *vsProjectTypes);
  930. }
  931. cmValue vsGlobalKeyword =
  932. this->GeneratorTarget->GetProperty("VS_GLOBAL_KEYWORD");
  933. if (!vsGlobalKeyword) {
  934. if (this->GlobalGenerator->TargetsAndroid()) {
  935. e1.Element("Keyword", "Android");
  936. } else {
  937. e1.Element("Keyword", "Win32Proj");
  938. }
  939. } else {
  940. e1.Element("Keyword", *vsGlobalKeyword);
  941. }
  942. cmValue vsGlobalRootNamespace =
  943. this->GeneratorTarget->GetProperty("VS_GLOBAL_ROOTNAMESPACE");
  944. if (vsGlobalRootNamespace) {
  945. e1.Element("RootNamespace", *vsGlobalRootNamespace);
  946. }
  947. std::vector<std::string> keys = this->GeneratorTarget->GetPropertyKeys();
  948. for (std::string const& keyIt : keys) {
  949. static const cm::string_view prefix = "VS_GLOBAL_";
  950. if (!cmHasPrefix(keyIt, prefix)) {
  951. continue;
  952. }
  953. cm::string_view globalKey = cm::string_view(keyIt).substr(prefix.length());
  954. // Skip invalid or separately-handled properties.
  955. if (globalKey.empty() || globalKey == "PROJECT_TYPES" ||
  956. globalKey == "ROOTNAMESPACE" || globalKey == "KEYWORD") {
  957. continue;
  958. }
  959. cmValue value = this->GeneratorTarget->GetProperty(keyIt);
  960. if (!value) {
  961. continue;
  962. }
  963. e1.Element(globalKey, *value);
  964. }
  965. }
  966. bool cmVisualStudio10TargetGenerator::HasCustomCommands() const
  967. {
  968. if (!this->GeneratorTarget->GetPreBuildCommands().empty() ||
  969. !this->GeneratorTarget->GetPreLinkCommands().empty() ||
  970. !this->GeneratorTarget->GetPostBuildCommands().empty()) {
  971. return true;
  972. }
  973. for (cmGeneratorTarget::AllConfigSource const& si :
  974. this->GeneratorTarget->GetAllConfigSources()) {
  975. if (si.Source->GetCustomCommand()) {
  976. return true;
  977. }
  978. }
  979. return false;
  980. }
  981. void cmVisualStudio10TargetGenerator::WritePackageReferences(Elem& e0)
  982. {
  983. std::vector<std::string> packageReferences =
  984. this->GeneratorTarget->GetPackageReferences();
  985. if (!packageReferences.empty()) {
  986. Elem e1(e0, "ItemGroup");
  987. for (std::string const& ri : packageReferences) {
  988. size_t versionIndex = ri.find_last_of('_');
  989. if (versionIndex != std::string::npos) {
  990. Elem e2(e1, "PackageReference");
  991. e2.Attribute("Include", ri.substr(0, versionIndex));
  992. e2.Attribute("Version", ri.substr(versionIndex + 1));
  993. }
  994. }
  995. }
  996. }
  997. void cmVisualStudio10TargetGenerator::WriteDotNetReferences(Elem& e0)
  998. {
  999. std::vector<std::string> references;
  1000. if (cmValue vsDotNetReferences =
  1001. this->GeneratorTarget->GetProperty("VS_DOTNET_REFERENCES")) {
  1002. cmExpandList(*vsDotNetReferences, references);
  1003. }
  1004. cmPropertyMap const& props = this->GeneratorTarget->Target->GetProperties();
  1005. for (auto const& i : props.GetList()) {
  1006. static const cm::string_view vsDnRef = "VS_DOTNET_REFERENCE_";
  1007. if (cmHasPrefix(i.first, vsDnRef)) {
  1008. std::string path = i.second;
  1009. if (!cmsys::SystemTools::FileIsFullPath(path)) {
  1010. path = this->Makefile->GetCurrentSourceDirectory() + "/" + path;
  1011. }
  1012. ConvertToWindowsSlash(path);
  1013. this->DotNetHintReferences[""].emplace_back(
  1014. DotNetHintReference(i.first.substr(vsDnRef.length()), path));
  1015. }
  1016. }
  1017. if (!references.empty() || !this->DotNetHintReferences.empty()) {
  1018. Elem e1(e0, "ItemGroup");
  1019. for (std::string const& ri : references) {
  1020. // if the entry from VS_DOTNET_REFERENCES is an existing file, generate
  1021. // a new hint-reference and name it from the filename
  1022. if (cmsys::SystemTools::FileExists(ri, true)) {
  1023. std::string name =
  1024. cmsys::SystemTools::GetFilenameWithoutLastExtension(ri);
  1025. std::string path = ri;
  1026. ConvertToWindowsSlash(path);
  1027. this->DotNetHintReferences[""].emplace_back(
  1028. DotNetHintReference(name, path));
  1029. } else {
  1030. this->WriteDotNetReference(e1, ri, "", "");
  1031. }
  1032. }
  1033. for (const auto& h : this->DotNetHintReferences) {
  1034. // DotNetHintReferences is also populated from AddLibraries().
  1035. // The configuration specific hint references are added there.
  1036. for (const auto& i : h.second) {
  1037. this->WriteDotNetReference(e1, i.first, i.second, h.first);
  1038. }
  1039. }
  1040. }
  1041. }
  1042. void cmVisualStudio10TargetGenerator::WriteDotNetReference(
  1043. Elem& e1, std::string const& ref, std::string const& hint,
  1044. std::string const& config)
  1045. {
  1046. Elem e2(e1, "Reference");
  1047. // If 'config' is not empty, the reference is only added for the given
  1048. // configuration. This is used when referencing imported managed assemblies.
  1049. // See also cmVisualStudio10TargetGenerator::AddLibraries().
  1050. if (!config.empty()) {
  1051. e2.Attribute("Condition", this->CalcCondition(config));
  1052. }
  1053. e2.Attribute("Include", ref);
  1054. e2.Element("CopyLocalSatelliteAssemblies", "true");
  1055. e2.Element("ReferenceOutputAssembly", "true");
  1056. if (!hint.empty()) {
  1057. const char* privateReference = "True";
  1058. if (cmValue value = this->GeneratorTarget->GetProperty(
  1059. "VS_DOTNET_REFERENCES_COPY_LOCAL")) {
  1060. if (cmIsOff(*value)) {
  1061. privateReference = "False";
  1062. }
  1063. }
  1064. e2.Element("Private", privateReference);
  1065. e2.Element("HintPath", hint);
  1066. }
  1067. this->WriteDotNetReferenceCustomTags(e2, ref);
  1068. }
  1069. void cmVisualStudio10TargetGenerator::WriteImports(Elem& e0)
  1070. {
  1071. cmValue imports =
  1072. this->GeneratorTarget->Target->GetProperty("VS_PROJECT_IMPORT");
  1073. if (imports) {
  1074. std::vector<std::string> argsSplit = cmExpandedList(*imports, false);
  1075. for (auto& path : argsSplit) {
  1076. if (!cmsys::SystemTools::FileIsFullPath(path)) {
  1077. path = this->Makefile->GetCurrentSourceDirectory() + "/" + path;
  1078. }
  1079. ConvertToWindowsSlash(path);
  1080. Elem e1(e0, "Import");
  1081. e1.Attribute("Project", path);
  1082. }
  1083. }
  1084. }
  1085. void cmVisualStudio10TargetGenerator::WriteDotNetReferenceCustomTags(
  1086. Elem& e2, std::string const& ref)
  1087. {
  1088. static const std::string refpropPrefix = "VS_DOTNET_REFERENCEPROP_";
  1089. static const std::string refpropInfix = "_TAG_";
  1090. const std::string refPropFullPrefix = refpropPrefix + ref + refpropInfix;
  1091. using CustomTags = std::map<std::string, std::string>;
  1092. CustomTags tags;
  1093. cmPropertyMap const& props = this->GeneratorTarget->Target->GetProperties();
  1094. for (const auto& i : props.GetList()) {
  1095. if (cmHasPrefix(i.first, refPropFullPrefix) && !i.second.empty()) {
  1096. tags[i.first.substr(refPropFullPrefix.length())] = i.second;
  1097. }
  1098. }
  1099. for (auto const& tag : tags) {
  1100. e2.Element(tag.first, tag.second);
  1101. }
  1102. }
  1103. void cmVisualStudio10TargetGenerator::WriteDotNetDocumentationFile(Elem& e0)
  1104. {
  1105. std::string const& documentationFile =
  1106. this->GeneratorTarget->GetSafeProperty("VS_DOTNET_DOCUMENTATION_FILE");
  1107. if (this->ProjectType == VsProjectType::csproj &&
  1108. !documentationFile.empty()) {
  1109. Elem e1(e0, "PropertyGroup");
  1110. Elem e2(e1, "DocumentationFile");
  1111. e2.Content(documentationFile);
  1112. }
  1113. }
  1114. void cmVisualStudio10TargetGenerator::WriteEmbeddedResourceGroup(Elem& e0)
  1115. {
  1116. if (!this->ResxObjs.empty()) {
  1117. Elem e1(e0, "ItemGroup");
  1118. std::string srcDir = this->Makefile->GetCurrentSourceDirectory();
  1119. ConvertToWindowsSlash(srcDir);
  1120. for (cmSourceFile const* oi : this->ResxObjs) {
  1121. std::string obj = oi->GetFullPath();
  1122. ConvertToWindowsSlash(obj);
  1123. bool useRelativePath = false;
  1124. if (this->ProjectType == VsProjectType::csproj && this->InSourceBuild) {
  1125. // If we do an in-source build and the resource file is in a
  1126. // subdirectory
  1127. // of the .csproj file, we have to use relative pathnames, otherwise
  1128. // visual studio does not show the file in the IDE. Sorry.
  1129. if (cmHasPrefix(obj, srcDir)) {
  1130. obj = this->ConvertPath(obj, true);
  1131. ConvertToWindowsSlash(obj);
  1132. useRelativePath = true;
  1133. }
  1134. }
  1135. Elem e2(e1, "EmbeddedResource");
  1136. e2.Attribute("Include", obj);
  1137. if (this->ProjectType != VsProjectType::csproj) {
  1138. std::string hFileName = obj.substr(0, obj.find_last_of(".")) + ".h";
  1139. e2.Element("DependentUpon", hFileName);
  1140. for (std::string const& c : this->Configurations) {
  1141. std::string s;
  1142. if (this->GeneratorTarget->GetProperty("VS_GLOBAL_ROOTNAMESPACE") ||
  1143. // Handle variant of VS_GLOBAL_<variable> for RootNamespace.
  1144. this->GeneratorTarget->GetProperty("VS_GLOBAL_RootNamespace")) {
  1145. s = "$(RootNamespace).";
  1146. }
  1147. s += "%(Filename).resources";
  1148. e2.WritePlatformConfigTag("LogicalName", this->CalcCondition(c), s);
  1149. }
  1150. } else {
  1151. std::string binDir = this->Makefile->GetCurrentBinaryDirectory();
  1152. ConvertToWindowsSlash(binDir);
  1153. // If the resource was NOT added using a relative path (which should
  1154. // be the default), we have to provide a link here
  1155. if (!useRelativePath) {
  1156. std::string link = this->GetCSharpSourceLink(oi);
  1157. if (link.empty()) {
  1158. link = cmsys::SystemTools::GetFilenameName(obj);
  1159. }
  1160. e2.Element("Link", link);
  1161. }
  1162. // Determine if this is a generated resource from a .Designer.cs file
  1163. std::string designerResource =
  1164. cmSystemTools::GetFilenamePath(oi->GetFullPath()) + "/" +
  1165. cmSystemTools::GetFilenameWithoutLastExtension(oi->GetFullPath()) +
  1166. ".Designer.cs";
  1167. if (cmsys::SystemTools::FileExists(designerResource)) {
  1168. std::string generator = "PublicResXFileCodeGenerator";
  1169. if (cmValue g = oi->GetProperty("VS_RESOURCE_GENERATOR")) {
  1170. generator = *g;
  1171. }
  1172. if (!generator.empty()) {
  1173. e2.Element("Generator", generator);
  1174. if (cmHasPrefix(designerResource, srcDir)) {
  1175. designerResource.erase(0, srcDir.length());
  1176. } else if (cmHasPrefix(designerResource, binDir)) {
  1177. designerResource.erase(0, binDir.length());
  1178. } else {
  1179. designerResource =
  1180. cmsys::SystemTools::GetFilenameName(designerResource);
  1181. }
  1182. ConvertToWindowsSlash(designerResource);
  1183. e2.Element("LastGenOutput", designerResource);
  1184. }
  1185. }
  1186. const cmPropertyMap& props = oi->GetProperties();
  1187. for (const std::string& p : props.GetKeys()) {
  1188. static const cm::string_view propNamePrefix = "VS_CSHARP_";
  1189. if (cmHasPrefix(p, propNamePrefix)) {
  1190. cm::string_view tagName =
  1191. cm::string_view(p).substr(propNamePrefix.length());
  1192. if (!tagName.empty()) {
  1193. cmValue value = props.GetPropertyValue(p);
  1194. if (cmNonempty(value)) {
  1195. e2.Element(tagName, *value);
  1196. }
  1197. }
  1198. }
  1199. }
  1200. }
  1201. }
  1202. }
  1203. }
  1204. void cmVisualStudio10TargetGenerator::WriteXamlFilesGroup(Elem& e0)
  1205. {
  1206. if (!this->XamlObjs.empty()) {
  1207. Elem e1(e0, "ItemGroup");
  1208. for (cmSourceFile const* oi : this->XamlObjs) {
  1209. std::string obj = oi->GetFullPath();
  1210. std::string xamlType;
  1211. cmValue xamlTypeProperty = oi->GetProperty("VS_XAML_TYPE");
  1212. if (xamlTypeProperty) {
  1213. xamlType = *xamlTypeProperty;
  1214. } else {
  1215. xamlType = "Page";
  1216. }
  1217. Elem e2(e1, xamlType);
  1218. this->WriteSource(e2, oi);
  1219. e2.SetHasElements();
  1220. e2.Element("SubType", "Designer");
  1221. }
  1222. }
  1223. }
  1224. void cmVisualStudio10TargetGenerator::WriteTargetSpecificReferences(Elem& e0)
  1225. {
  1226. if (this->MSTools) {
  1227. if (this->GlobalGenerator->TargetsWindowsPhone() &&
  1228. this->GlobalGenerator->GetSystemVersion() == "8.0") {
  1229. Elem(e0, "Import")
  1230. .Attribute("Project",
  1231. "$(MSBuildExtensionsPath)\\Microsoft\\WindowsPhone\\v"
  1232. "$(TargetPlatformVersion)\\Microsoft.Cpp.WindowsPhone."
  1233. "$(TargetPlatformVersion).targets");
  1234. }
  1235. }
  1236. }
  1237. void cmVisualStudio10TargetGenerator::WriteTargetsFileReferences(Elem& e1)
  1238. {
  1239. for (TargetsFileAndConfigs const& tac : this->TargetsFileAndConfigsVec) {
  1240. std::ostringstream oss;
  1241. oss << "Exists('" << tac.File << "')";
  1242. if (!tac.Configs.empty()) {
  1243. oss << " And (";
  1244. for (size_t j = 0; j < tac.Configs.size(); ++j) {
  1245. if (j > 0) {
  1246. oss << " Or ";
  1247. }
  1248. oss << "'$(Configuration)'=='" << tac.Configs[j] << "'";
  1249. }
  1250. oss << ")";
  1251. }
  1252. Elem(e1, "Import")
  1253. .Attribute("Project", tac.File)
  1254. .Attribute("Condition", oss.str());
  1255. }
  1256. }
  1257. void cmVisualStudio10TargetGenerator::WriteWinRTReferences(Elem& e0)
  1258. {
  1259. std::vector<std::string> references;
  1260. if (cmValue vsWinRTReferences =
  1261. this->GeneratorTarget->GetProperty("VS_WINRT_REFERENCES")) {
  1262. cmExpandList(*vsWinRTReferences, references);
  1263. }
  1264. if (this->GlobalGenerator->TargetsWindowsPhone() &&
  1265. this->GlobalGenerator->GetSystemVersion() == "8.0" &&
  1266. references.empty()) {
  1267. references.push_back("platform.winmd");
  1268. }
  1269. if (!references.empty()) {
  1270. Elem e1(e0, "ItemGroup");
  1271. for (std::string const& ri : references) {
  1272. Elem e2(e1, "Reference");
  1273. e2.Attribute("Include", ri);
  1274. e2.Element("IsWinMDFile", "true");
  1275. }
  1276. }
  1277. }
  1278. // ConfigurationType Application, Utility StaticLibrary DynamicLibrary
  1279. void cmVisualStudio10TargetGenerator::WriteProjectConfigurations(Elem& e0)
  1280. {
  1281. Elem e1(e0, "ItemGroup");
  1282. e1.Attribute("Label", "ProjectConfigurations");
  1283. for (std::string const& c : this->Configurations) {
  1284. Elem e2(e1, "ProjectConfiguration");
  1285. e2.Attribute("Include", c + "|" + this->Platform);
  1286. e2.Element("Configuration", c);
  1287. e2.Element("Platform", this->Platform);
  1288. }
  1289. }
  1290. void cmVisualStudio10TargetGenerator::WriteProjectConfigurationValues(Elem& e0)
  1291. {
  1292. for (std::string const& c : this->Configurations) {
  1293. Elem e1(e0, "PropertyGroup");
  1294. e1.Attribute("Condition", this->CalcCondition(c));
  1295. e1.Attribute("Label", "Configuration");
  1296. if (this->ProjectType != VsProjectType::csproj) {
  1297. std::string configType;
  1298. if (cmValue vsConfigurationType =
  1299. this->GeneratorTarget->GetProperty("VS_CONFIGURATION_TYPE")) {
  1300. configType = cmGeneratorExpression::Evaluate(*vsConfigurationType,
  1301. this->LocalGenerator, c);
  1302. } else {
  1303. switch (this->GeneratorTarget->GetType()) {
  1304. case cmStateEnums::SHARED_LIBRARY:
  1305. case cmStateEnums::MODULE_LIBRARY:
  1306. configType = "DynamicLibrary";
  1307. break;
  1308. case cmStateEnums::OBJECT_LIBRARY:
  1309. case cmStateEnums::STATIC_LIBRARY:
  1310. configType = "StaticLibrary";
  1311. break;
  1312. case cmStateEnums::EXECUTABLE:
  1313. if (this->NsightTegra &&
  1314. !this->GeneratorTarget->Target->IsAndroidGuiExecutable()) {
  1315. // Android executables are .so too.
  1316. configType = "DynamicLibrary";
  1317. } else if (this->Android) {
  1318. configType = "DynamicLibrary";
  1319. } else {
  1320. configType = "Application";
  1321. }
  1322. break;
  1323. case cmStateEnums::UTILITY:
  1324. case cmStateEnums::INTERFACE_LIBRARY:
  1325. case cmStateEnums::GLOBAL_TARGET:
  1326. if (this->NsightTegra) {
  1327. // Tegra-Android platform does not understand "Utility".
  1328. configType = "StaticLibrary";
  1329. } else {
  1330. configType = "Utility";
  1331. }
  1332. break;
  1333. case cmStateEnums::UNKNOWN_LIBRARY:
  1334. break;
  1335. }
  1336. }
  1337. e1.Element("ConfigurationType", configType);
  1338. }
  1339. if (this->MSTools) {
  1340. if (!this->Managed) {
  1341. this->WriteMSToolConfigurationValues(e1, c);
  1342. } else {
  1343. this->WriteMSToolConfigurationValuesManaged(e1, c);
  1344. }
  1345. } else if (this->NsightTegra) {
  1346. this->WriteNsightTegraConfigurationValues(e1, c);
  1347. } else if (this->Android) {
  1348. this->WriteAndroidConfigurationValues(e1, c);
  1349. }
  1350. }
  1351. }
  1352. void cmVisualStudio10TargetGenerator::WriteCEDebugProjectConfigurationValues(
  1353. Elem& e0)
  1354. {
  1355. if (!this->GlobalGenerator->TargetsWindowsCE()) {
  1356. return;
  1357. }
  1358. cmValue additionalFiles =
  1359. this->GeneratorTarget->GetProperty("DEPLOYMENT_ADDITIONAL_FILES");
  1360. cmValue remoteDirectory =
  1361. this->GeneratorTarget->GetProperty("DEPLOYMENT_REMOTE_DIRECTORY");
  1362. if (!(additionalFiles || remoteDirectory)) {
  1363. return;
  1364. }
  1365. for (std::string const& c : this->Configurations) {
  1366. Elem e1(e0, "PropertyGroup");
  1367. e1.Attribute("Condition", this->CalcCondition(c));
  1368. if (remoteDirectory) {
  1369. e1.Element("RemoteDirectory", *remoteDirectory);
  1370. }
  1371. if (additionalFiles) {
  1372. e1.Element("CEAdditionalFiles", *additionalFiles);
  1373. }
  1374. }
  1375. }
  1376. void cmVisualStudio10TargetGenerator::WriteMSToolConfigurationValues(
  1377. Elem& e1, std::string const& config)
  1378. {
  1379. cmGlobalVisualStudio10Generator* gg = this->GlobalGenerator;
  1380. cmValue mfcFlag = this->Makefile->GetDefinition("CMAKE_MFC_FLAG");
  1381. if (mfcFlag) {
  1382. std::string const mfcFlagValue =
  1383. cmGeneratorExpression::Evaluate(*mfcFlag, this->LocalGenerator, config);
  1384. std::string useOfMfcValue = "false";
  1385. if (this->GeneratorTarget->GetType() <= cmStateEnums::OBJECT_LIBRARY) {
  1386. if (mfcFlagValue == "1") {
  1387. useOfMfcValue = "Static";
  1388. } else if (mfcFlagValue == "2") {
  1389. useOfMfcValue = "Dynamic";
  1390. }
  1391. }
  1392. e1.Element("UseOfMfc", useOfMfcValue);
  1393. }
  1394. if ((this->GeneratorTarget->GetType() <= cmStateEnums::OBJECT_LIBRARY &&
  1395. this->ClOptions[config]->UsingUnicode()) ||
  1396. this->GeneratorTarget->GetPropertyAsBool("VS_WINRT_COMPONENT") ||
  1397. this->GlobalGenerator->TargetsWindowsPhone() ||
  1398. this->GlobalGenerator->TargetsWindowsStore() ||
  1399. this->GeneratorTarget->GetPropertyAsBool("VS_WINRT_EXTENSIONS")) {
  1400. e1.Element("CharacterSet", "Unicode");
  1401. } else if (this->GeneratorTarget->GetType() <=
  1402. cmStateEnums::OBJECT_LIBRARY &&
  1403. this->ClOptions[config]->UsingSBCS()) {
  1404. e1.Element("CharacterSet", "NotSet");
  1405. } else {
  1406. e1.Element("CharacterSet", "MultiByte");
  1407. }
  1408. if (cmValue projectToolsetOverride =
  1409. this->GeneratorTarget->GetProperty("VS_PLATFORM_TOOLSET")) {
  1410. e1.Element("PlatformToolset", *projectToolsetOverride);
  1411. } else if (const char* toolset = gg->GetPlatformToolset()) {
  1412. e1.Element("PlatformToolset", toolset);
  1413. }
  1414. if (this->GeneratorTarget->GetPropertyAsBool("VS_WINRT_COMPONENT") ||
  1415. this->GeneratorTarget->GetPropertyAsBool("VS_WINRT_EXTENSIONS")) {
  1416. e1.Element("WindowsAppContainer", "true");
  1417. }
  1418. if (this->IPOEnabledConfigurations.count(config) > 0) {
  1419. e1.Element("WholeProgramOptimization", "true");
  1420. }
  1421. if (this->ASanEnabledConfigurations.find(config) !=
  1422. this->ASanEnabledConfigurations.end()) {
  1423. e1.Element("EnableAsan", "true");
  1424. }
  1425. if (this->FuzzerEnabledConfigurations.find(config) !=
  1426. this->FuzzerEnabledConfigurations.end()) {
  1427. e1.Element("EnableFuzzer", "true");
  1428. }
  1429. {
  1430. auto s = this->SpectreMitigation.find(config);
  1431. if (s != this->SpectreMitigation.end()) {
  1432. e1.Element("SpectreMitigation", s->second);
  1433. }
  1434. }
  1435. }
  1436. void cmVisualStudio10TargetGenerator::WriteMSToolConfigurationValuesManaged(
  1437. Elem& e1, std::string const& config)
  1438. {
  1439. if (this->GeneratorTarget->GetType() > cmStateEnums::OBJECT_LIBRARY) {
  1440. return;
  1441. }
  1442. cmGlobalVisualStudio10Generator* gg = this->GlobalGenerator;
  1443. Options& o = *(this->ClOptions[config]);
  1444. if (o.IsDebug()) {
  1445. e1.Element("DebugSymbols", "true");
  1446. e1.Element("DefineDebug", "true");
  1447. }
  1448. std::string outDir = this->GeneratorTarget->GetDirectory(config) + "/";
  1449. ConvertToWindowsSlash(outDir);
  1450. e1.Element("OutputPath", outDir);
  1451. if (o.HasFlag("Platform")) {
  1452. e1.Element("PlatformTarget", o.GetFlag("Platform"));
  1453. o.RemoveFlag("Platform");
  1454. }
  1455. if (cmValue projectToolsetOverride =
  1456. this->GeneratorTarget->GetProperty("VS_PLATFORM_TOOLSET")) {
  1457. e1.Element("PlatformToolset", *projectToolsetOverride);
  1458. } else if (const char* toolset = gg->GetPlatformToolset()) {
  1459. e1.Element("PlatformToolset", toolset);
  1460. }
  1461. std::string postfixName =
  1462. cmStrCat(cmSystemTools::UpperCase(config), "_POSTFIX");
  1463. std::string assemblyName = this->GeneratorTarget->GetOutputName(
  1464. config, cmStateEnums::RuntimeBinaryArtifact);
  1465. if (cmValue postfix = this->GeneratorTarget->GetProperty(postfixName)) {
  1466. assemblyName += *postfix;
  1467. }
  1468. e1.Element("AssemblyName", assemblyName);
  1469. if (cmStateEnums::EXECUTABLE == this->GeneratorTarget->GetType()) {
  1470. e1.Element("StartAction", "Program");
  1471. e1.Element("StartProgram", outDir + assemblyName + ".exe");
  1472. }
  1473. OptionsHelper oh(o, e1);
  1474. oh.OutputFlagMap();
  1475. }
  1476. //----------------------------------------------------------------------------
  1477. void cmVisualStudio10TargetGenerator::WriteNsightTegraConfigurationValues(
  1478. Elem& e1, std::string const&)
  1479. {
  1480. cmGlobalVisualStudio10Generator* gg = this->GlobalGenerator;
  1481. const char* toolset = gg->GetPlatformToolset();
  1482. e1.Element("NdkToolchainVersion", toolset ? toolset : "Default");
  1483. if (cmValue minApi = this->GeneratorTarget->GetProperty("ANDROID_API_MIN")) {
  1484. e1.Element("AndroidMinAPI", "android-" + *minApi);
  1485. }
  1486. if (cmValue api = this->GeneratorTarget->GetProperty("ANDROID_API")) {
  1487. e1.Element("AndroidTargetAPI", "android-" + *api);
  1488. }
  1489. if (cmValue cpuArch = this->GeneratorTarget->GetProperty("ANDROID_ARCH")) {
  1490. e1.Element("AndroidArch", *cpuArch);
  1491. }
  1492. if (cmValue stlType =
  1493. this->GeneratorTarget->GetProperty("ANDROID_STL_TYPE")) {
  1494. e1.Element("AndroidStlType", *stlType);
  1495. }
  1496. }
  1497. void cmVisualStudio10TargetGenerator::WriteAndroidConfigurationValues(
  1498. Elem& e1, std::string const&)
  1499. {
  1500. cmGlobalVisualStudio10Generator* gg = this->GlobalGenerator;
  1501. if (cmValue projectToolsetOverride =
  1502. this->GeneratorTarget->GetProperty("VS_PLATFORM_TOOLSET")) {
  1503. e1.Element("PlatformToolset", *projectToolsetOverride);
  1504. } else if (const char* toolset = gg->GetPlatformToolset()) {
  1505. e1.Element("PlatformToolset", toolset);
  1506. }
  1507. if (cmValue stlType =
  1508. this->GeneratorTarget->GetProperty("ANDROID_STL_TYPE")) {
  1509. if (*stlType != "none") {
  1510. e1.Element("UseOfStl", *stlType);
  1511. }
  1512. }
  1513. std::string const& apiLevel = gg->GetSystemVersion();
  1514. if (!apiLevel.empty()) {
  1515. e1.Element("AndroidAPILevel", cmStrCat("android-", apiLevel));
  1516. }
  1517. }
  1518. void cmVisualStudio10TargetGenerator::WriteCustomCommands(Elem& e0)
  1519. {
  1520. this->CSharpCustomCommandNames.clear();
  1521. cmSourceFile const* srcCMakeLists =
  1522. this->LocalGenerator->CreateVCProjBuildRule();
  1523. for (cmGeneratorTarget::AllConfigSource const& si :
  1524. this->GeneratorTarget->GetAllConfigSources()) {
  1525. if (si.Source == srcCMakeLists) {
  1526. // Skip explicit reference to CMakeLists.txt source.
  1527. continue;
  1528. }
  1529. this->WriteCustomCommand(e0, si.Source);
  1530. }
  1531. // Add CMakeLists.txt file with rule to re-run CMake for user convenience.
  1532. if (this->GeneratorTarget->GetType() != cmStateEnums::GLOBAL_TARGET &&
  1533. this->GeneratorTarget->GetName() != CMAKE_CHECK_BUILD_SYSTEM_TARGET) {
  1534. if (srcCMakeLists) {
  1535. // Write directly rather than through WriteCustomCommand because
  1536. // we do not want the de-duplication and it has no dependencies.
  1537. if (cmCustomCommand const* command = srcCMakeLists->GetCustomCommand()) {
  1538. this->WriteCustomRule(e0, srcCMakeLists, *command);
  1539. }
  1540. }
  1541. }
  1542. }
  1543. void cmVisualStudio10TargetGenerator::WriteCustomCommand(
  1544. Elem& e0, cmSourceFile const* sf)
  1545. {
  1546. if (this->LocalGenerator->GetSourcesVisited(this->GeneratorTarget)
  1547. .insert(sf)
  1548. .second) {
  1549. if (std::vector<cmSourceFile*> const* depends =
  1550. this->GeneratorTarget->GetSourceDepends(sf)) {
  1551. for (cmSourceFile const* di : *depends) {
  1552. this->WriteCustomCommand(e0, di);
  1553. }
  1554. }
  1555. if (cmCustomCommand const* command = sf->GetCustomCommand()) {
  1556. // C# projects write their <Target> within WriteCustomRule()
  1557. this->WriteCustomRule(e0, sf, *command);
  1558. }
  1559. }
  1560. }
  1561. void cmVisualStudio10TargetGenerator::WriteCustomRule(
  1562. Elem& e0, cmSourceFile const* source, cmCustomCommand const& command)
  1563. {
  1564. std::string sourcePath = source->GetFullPath();
  1565. // VS 10 will always rebuild a custom command attached to a .rule
  1566. // file that doesn't exist so create the file explicitly.
  1567. if (source->GetPropertyAsBool("__CMAKE_RULE")) {
  1568. if (!cmSystemTools::FileExists(sourcePath)) {
  1569. // Make sure the path exists for the file
  1570. std::string path = cmSystemTools::GetFilenamePath(sourcePath);
  1571. cmSystemTools::MakeDirectory(path);
  1572. cmsys::ofstream fout(sourcePath.c_str());
  1573. if (fout) {
  1574. fout << "# generated from CMake\n";
  1575. fout.flush();
  1576. fout.close();
  1577. // Force given file to have a very old timestamp, thus
  1578. // preventing dependent rebuilds.
  1579. this->ForceOld(sourcePath);
  1580. } else {
  1581. std::string error =
  1582. cmStrCat("Could not create file: [", sourcePath, "] ");
  1583. cmSystemTools::Error(error + cmSystemTools::GetLastSystemError());
  1584. }
  1585. }
  1586. }
  1587. cmLocalVisualStudio7Generator* lg = this->LocalGenerator;
  1588. std::unique_ptr<Elem> spe1;
  1589. std::unique_ptr<Elem> spe2;
  1590. if (this->ProjectType != VsProjectType::csproj) {
  1591. spe1 = cm::make_unique<Elem>(e0, "ItemGroup");
  1592. spe2 = cm::make_unique<Elem>(*spe1, "CustomBuild");
  1593. this->WriteSource(*spe2, source);
  1594. spe2->SetHasElements();
  1595. if (command.GetStdPipesUTF8()) {
  1596. this->WriteStdOutEncodingUtf8(*spe2);
  1597. }
  1598. } else {
  1599. Elem e1(e0, "ItemGroup");
  1600. Elem e2(e1, "None");
  1601. this->WriteSource(e2, source);
  1602. e2.SetHasElements();
  1603. }
  1604. for (std::string const& c : this->Configurations) {
  1605. cmCustomCommandGenerator ccg(command, c, lg, true);
  1606. std::string comment = lg->ConstructComment(ccg);
  1607. comment = cmVS10EscapeComment(comment);
  1608. std::string script = lg->ConstructScript(ccg);
  1609. bool symbolic = false;
  1610. // input files for custom command
  1611. std::stringstream additional_inputs;
  1612. {
  1613. const char* sep = "";
  1614. if (this->ProjectType == VsProjectType::csproj) {
  1615. // csproj files do not attach the command to a specific file
  1616. // so the primary input must be listed explicitly.
  1617. additional_inputs << source->GetFullPath();
  1618. sep = ";";
  1619. }
  1620. // Avoid listing an input more than once.
  1621. std::set<std::string> unique_inputs;
  1622. // The source is either implicit an input or has been added above.
  1623. unique_inputs.insert(source->GetFullPath());
  1624. for (std::string const& d : ccg.GetDepends()) {
  1625. std::string dep;
  1626. if (lg->GetRealDependency(d, c, dep)) {
  1627. if (!unique_inputs.insert(dep).second) {
  1628. // already listed
  1629. continue;
  1630. }
  1631. ConvertToWindowsSlash(dep);
  1632. additional_inputs << sep << dep;
  1633. sep = ";";
  1634. if (!symbolic) {
  1635. if (cmSourceFile* sf = this->Makefile->GetSource(
  1636. dep, cmSourceFileLocationKind::Known)) {
  1637. symbolic = sf->GetPropertyAsBool("SYMBOLIC");
  1638. }
  1639. }
  1640. }
  1641. }
  1642. if (this->ProjectType != VsProjectType::csproj) {
  1643. additional_inputs << sep << "%(AdditionalInputs)";
  1644. }
  1645. }
  1646. // output files for custom command
  1647. std::stringstream outputs;
  1648. {
  1649. const char* sep = "";
  1650. for (std::string const& o : ccg.GetOutputs()) {
  1651. std::string out = o;
  1652. ConvertToWindowsSlash(out);
  1653. outputs << sep << out;
  1654. sep = ";";
  1655. if (!symbolic) {
  1656. if (cmSourceFile* sf = this->Makefile->GetSource(
  1657. o, cmSourceFileLocationKind::Known)) {
  1658. symbolic = sf->GetPropertyAsBool("SYMBOLIC");
  1659. }
  1660. }
  1661. }
  1662. }
  1663. script += lg->FinishConstructScript(this->ProjectType);
  1664. if (this->ProjectType == VsProjectType::csproj) {
  1665. std::string name = "CustomCommand_" + c + "_" +
  1666. cmSystemTools::ComputeStringMD5(sourcePath);
  1667. this->WriteCustomRuleCSharp(e0, c, name, script, additional_inputs.str(),
  1668. outputs.str(), comment, ccg);
  1669. } else {
  1670. this->WriteCustomRuleCpp(*spe2, c, script, additional_inputs.str(),
  1671. outputs.str(), comment, ccg, symbolic);
  1672. }
  1673. }
  1674. }
  1675. void cmVisualStudio10TargetGenerator::WriteCustomRuleCpp(
  1676. Elem& e2, std::string const& config, std::string const& script,
  1677. std::string const& additional_inputs, std::string const& outputs,
  1678. std::string const& comment, cmCustomCommandGenerator const& ccg,
  1679. bool symbolic)
  1680. {
  1681. const std::string cond = this->CalcCondition(config);
  1682. e2.WritePlatformConfigTag("Message", cond, comment);
  1683. e2.WritePlatformConfigTag("Command", cond, script);
  1684. e2.WritePlatformConfigTag("AdditionalInputs", cond, additional_inputs);
  1685. e2.WritePlatformConfigTag("Outputs", cond, outputs);
  1686. // Turn off linking of custom command outputs.
  1687. e2.WritePlatformConfigTag("LinkObjects", cond, "false");
  1688. if (symbolic &&
  1689. this->LocalGenerator->GetVersion() >=
  1690. cmGlobalVisualStudioGenerator::VSVersion::VS16) {
  1691. // VS >= 16.4 warn if outputs are not created, but one of our
  1692. // outputs is marked SYMBOLIC and not expected to be created.
  1693. e2.WritePlatformConfigTag("VerifyInputsAndOutputsExist", cond, "false");
  1694. }
  1695. std::string depfile = ccg.GetFullDepfile();
  1696. if (!depfile.empty()) {
  1697. this->HaveCustomCommandDepfile = true;
  1698. std::string internal_depfile = ccg.GetInternalDepfile();
  1699. ConvertToWindowsSlash(internal_depfile);
  1700. e2.WritePlatformConfigTag("DepFileAdditionalInputsFile", cond,
  1701. internal_depfile);
  1702. }
  1703. }
  1704. void cmVisualStudio10TargetGenerator::WriteCustomRuleCSharp(
  1705. Elem& e0, std::string const& config, std::string const& name,
  1706. std::string const& script, std::string const& inputs,
  1707. std::string const& outputs, std::string const& comment,
  1708. cmCustomCommandGenerator const& ccg)
  1709. {
  1710. if (!ccg.GetFullDepfile().empty()) {
  1711. this->Makefile->IssueMessage(
  1712. MessageType::FATAL_ERROR,
  1713. cmStrCat("CSharp target \"", this->GeneratorTarget->GetName(),
  1714. "\" does not support add_custom_command DEPFILE."));
  1715. }
  1716. this->CSharpCustomCommandNames.insert(name);
  1717. Elem e1(e0, "Target");
  1718. e1.Attribute("Condition", this->CalcCondition(config));
  1719. e1.S << "\n Name=\"" << name << "\"";
  1720. e1.S << "\n Inputs=\"" << cmVS10EscapeAttr(inputs) << "\"";
  1721. e1.S << "\n Outputs=\"" << cmVS10EscapeAttr(outputs) << "\"";
  1722. if (!comment.empty()) {
  1723. Elem(e1, "Exec").Attribute("Command", "echo " + comment);
  1724. }
  1725. Elem(e1, "Exec").Attribute("Command", script);
  1726. }
  1727. std::string cmVisualStudio10TargetGenerator::ConvertPath(
  1728. std::string const& path, bool forceRelative)
  1729. {
  1730. return forceRelative
  1731. ? cmSystemTools::RelativePath(
  1732. this->LocalGenerator->GetCurrentBinaryDirectory(), path)
  1733. : path;
  1734. }
  1735. static void ConvertToWindowsSlash(std::string& s)
  1736. {
  1737. // first convert all of the slashes
  1738. for (auto& ch : s) {
  1739. if (ch == '/') {
  1740. ch = '\\';
  1741. }
  1742. }
  1743. }
  1744. void cmVisualStudio10TargetGenerator::WriteGroups()
  1745. {
  1746. if (this->ProjectType == VsProjectType::csproj) {
  1747. return;
  1748. }
  1749. // collect up group information
  1750. std::vector<cmSourceGroup> sourceGroups = this->Makefile->GetSourceGroups();
  1751. std::vector<cmGeneratorTarget::AllConfigSource> const& sources =
  1752. this->GeneratorTarget->GetAllConfigSources();
  1753. std::set<cmSourceGroup const*> groupsUsed;
  1754. for (cmGeneratorTarget::AllConfigSource const& si : sources) {
  1755. std::string const& source = si.Source->GetFullPath();
  1756. cmSourceGroup* sourceGroup =
  1757. this->Makefile->FindSourceGroup(source, sourceGroups);
  1758. groupsUsed.insert(sourceGroup);
  1759. }
  1760. if (cmSourceFile const* srcCMakeLists =
  1761. this->LocalGenerator->CreateVCProjBuildRule()) {
  1762. std::string const& source = srcCMakeLists->GetFullPath();
  1763. cmSourceGroup* sourceGroup =
  1764. this->Makefile->FindSourceGroup(source, sourceGroups);
  1765. groupsUsed.insert(sourceGroup);
  1766. }
  1767. this->AddMissingSourceGroups(groupsUsed, sourceGroups);
  1768. // Write out group file
  1769. std::string path = cmStrCat(
  1770. this->LocalGenerator->GetCurrentBinaryDirectory(), '/', this->Name,
  1771. computeProjectFileExtension(this->GeneratorTarget), ".filters");
  1772. cmGeneratedFileStream fout(path);
  1773. fout.SetCopyIfDifferent(true);
  1774. char magic[] = { char(0xEF), char(0xBB), char(0xBF) };
  1775. fout.write(magic, 3);
  1776. fout << "<?xml version=\"1.0\" encoding=\""
  1777. << this->GlobalGenerator->Encoding() << "\"?>";
  1778. {
  1779. Elem e0(fout, "Project");
  1780. e0.Attribute("ToolsVersion", this->GlobalGenerator->GetToolsVersion());
  1781. e0.Attribute("xmlns",
  1782. "http://schemas.microsoft.com/developer/msbuild/2003");
  1783. for (auto const& ti : this->Tools) {
  1784. this->WriteGroupSources(e0, ti.first, ti.second, sourceGroups);
  1785. }
  1786. // Added files are images and the manifest.
  1787. if (!this->AddedFiles.empty()) {
  1788. Elem e1(e0, "ItemGroup");
  1789. e1.SetHasElements();
  1790. for (std::string const& oi : this->AddedFiles) {
  1791. std::string fileName =
  1792. cmSystemTools::LowerCase(cmSystemTools::GetFilenameName(oi));
  1793. if (fileName == "wmappmanifest.xml") {
  1794. Elem e2(e1, "XML");
  1795. e2.Attribute("Include", oi);
  1796. e2.Element("Filter", "Resource Files");
  1797. } else if (cmSystemTools::GetFilenameExtension(fileName) ==
  1798. ".appxmanifest") {
  1799. Elem e2(e1, "AppxManifest");
  1800. e2.Attribute("Include", oi);
  1801. e2.Element("Filter", "Resource Files");
  1802. } else if (cmSystemTools::GetFilenameExtension(fileName) == ".pfx") {
  1803. Elem e2(e1, "None");
  1804. e2.Attribute("Include", oi);
  1805. e2.Element("Filter", "Resource Files");
  1806. } else {
  1807. Elem e2(e1, "Image");
  1808. e2.Attribute("Include", oi);
  1809. e2.Element("Filter", "Resource Files");
  1810. }
  1811. }
  1812. }
  1813. if (!this->ResxObjs.empty()) {
  1814. Elem e1(e0, "ItemGroup");
  1815. for (cmSourceFile const* oi : this->ResxObjs) {
  1816. std::string obj = oi->GetFullPath();
  1817. ConvertToWindowsSlash(obj);
  1818. Elem e2(e1, "EmbeddedResource");
  1819. e2.Attribute("Include", obj);
  1820. e2.Element("Filter", "Resource Files");
  1821. }
  1822. }
  1823. {
  1824. Elem e1(e0, "ItemGroup");
  1825. e1.SetHasElements();
  1826. std::vector<cmSourceGroup const*> groupsVec(groupsUsed.begin(),
  1827. groupsUsed.end());
  1828. std::sort(groupsVec.begin(), groupsVec.end(),
  1829. [](cmSourceGroup const* l, cmSourceGroup const* r) {
  1830. return l->GetFullName() < r->GetFullName();
  1831. });
  1832. for (cmSourceGroup const* sg : groupsVec) {
  1833. std::string const& name = sg->GetFullName();
  1834. if (!name.empty()) {
  1835. std::string guidName = "SG_Filter_" + name;
  1836. std::string guid = this->GlobalGenerator->GetGUID(guidName);
  1837. Elem e2(e1, "Filter");
  1838. e2.Attribute("Include", name);
  1839. e2.Element("UniqueIdentifier", "{" + guid + "}");
  1840. }
  1841. }
  1842. if (!this->ResxObjs.empty() || !this->AddedFiles.empty()) {
  1843. std::string guidName = "SG_Filter_Resource Files";
  1844. std::string guid = this->GlobalGenerator->GetGUID(guidName);
  1845. Elem e2(e1, "Filter");
  1846. e2.Attribute("Include", "Resource Files");
  1847. e2.Element("UniqueIdentifier", "{" + guid + "}");
  1848. e2.Element("Extensions",
  1849. "rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;"
  1850. "gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms");
  1851. }
  1852. }
  1853. }
  1854. fout << '\n';
  1855. if (fout.Close()) {
  1856. this->GlobalGenerator->FileReplacedDuringGenerate(path);
  1857. }
  1858. }
  1859. // Add to groupsUsed empty source groups that have non-empty children.
  1860. void cmVisualStudio10TargetGenerator::AddMissingSourceGroups(
  1861. std::set<cmSourceGroup const*>& groupsUsed,
  1862. const std::vector<cmSourceGroup>& allGroups)
  1863. {
  1864. for (cmSourceGroup const& current : allGroups) {
  1865. std::vector<cmSourceGroup> const& children = current.GetGroupChildren();
  1866. if (children.empty()) {
  1867. continue; // the group is really empty
  1868. }
  1869. this->AddMissingSourceGroups(groupsUsed, children);
  1870. if (groupsUsed.count(&current) > 0) {
  1871. continue; // group has already been added to set
  1872. }
  1873. // check if it least one of the group's descendants is not empty
  1874. // (at least one child must already have been added)
  1875. auto child_it = children.begin();
  1876. while (child_it != children.end()) {
  1877. if (groupsUsed.count(&(*child_it)) > 0) {
  1878. break; // found a child that was already added => add current group too
  1879. }
  1880. child_it++;
  1881. }
  1882. if (child_it == children.end()) {
  1883. continue; // no descendants have source files => ignore this group
  1884. }
  1885. groupsUsed.insert(&current);
  1886. }
  1887. }
  1888. void cmVisualStudio10TargetGenerator::WriteGroupSources(
  1889. Elem& e0, std::string const& name, ToolSources const& sources,
  1890. std::vector<cmSourceGroup>& sourceGroups)
  1891. {
  1892. Elem e1(e0, "ItemGroup");
  1893. e1.SetHasElements();
  1894. for (ToolSource const& s : sources) {
  1895. cmSourceFile const* sf = s.SourceFile;
  1896. std::string const& source = sf->GetFullPath();
  1897. cmSourceGroup* sourceGroup =
  1898. this->Makefile->FindSourceGroup(source, sourceGroups);
  1899. std::string const& filter = sourceGroup->GetFullName();
  1900. std::string path = this->ConvertPath(source, s.RelativePath);
  1901. ConvertToWindowsSlash(path);
  1902. Elem e2(e1, name);
  1903. e2.Attribute("Include", path);
  1904. if (!filter.empty()) {
  1905. e2.Element("Filter", filter);
  1906. }
  1907. }
  1908. }
  1909. void cmVisualStudio10TargetGenerator::WriteHeaderSource(
  1910. Elem& e1, cmSourceFile const* sf, ConfigToSettings const& toolSettings)
  1911. {
  1912. std::string const& fileName = sf->GetFullPath();
  1913. Elem e2(e1, "ClInclude");
  1914. this->WriteSource(e2, sf);
  1915. if (this->IsResxHeader(fileName)) {
  1916. e2.Element("FileType", "CppForm");
  1917. } else if (this->IsXamlHeader(fileName)) {
  1918. e2.Element("DependentUpon",
  1919. fileName.substr(0, fileName.find_last_of(".")));
  1920. }
  1921. this->FinishWritingSource(e2, toolSettings);
  1922. }
  1923. void cmVisualStudio10TargetGenerator::ParseSettingsProperty(
  1924. const std::string& settingsPropertyValue, ConfigToSettings& toolSettings)
  1925. {
  1926. if (!settingsPropertyValue.empty()) {
  1927. cmGeneratorExpression ge(*this->LocalGenerator->GetCMakeInstance());
  1928. std::unique_ptr<cmCompiledGeneratorExpression> cge =
  1929. ge.Parse(settingsPropertyValue);
  1930. for (const std::string& config : this->Configurations) {
  1931. std::string evaluated = cge->Evaluate(this->LocalGenerator, config);
  1932. std::vector<std::string> settings = cmExpandedList(evaluated);
  1933. for (const std::string& setting : settings) {
  1934. const std::string::size_type assignment = setting.find('=');
  1935. if (assignment != std::string::npos) {
  1936. const std::string propName = setting.substr(0, assignment);
  1937. const std::string propValue = setting.substr(assignment + 1);
  1938. if (!propValue.empty()) {
  1939. toolSettings[config][propName] = propValue;
  1940. }
  1941. }
  1942. }
  1943. }
  1944. }
  1945. }
  1946. bool cmVisualStudio10TargetGenerator::PropertyIsSameInAllConfigs(
  1947. const ConfigToSettings& toolSettings, const std::string& propName)
  1948. {
  1949. std::string firstPropValue = "";
  1950. for (const auto& configToSettings : toolSettings) {
  1951. const std::unordered_map<std::string, std::string>& settings =
  1952. configToSettings.second;
  1953. if (firstPropValue.empty()) {
  1954. if (settings.find(propName) != settings.end()) {
  1955. firstPropValue = settings.find(propName)->second;
  1956. }
  1957. }
  1958. if (settings.find(propName) == settings.end()) {
  1959. return false;
  1960. }
  1961. if (settings.find(propName)->second != firstPropValue) {
  1962. return false;
  1963. }
  1964. }
  1965. return true;
  1966. }
  1967. void cmVisualStudio10TargetGenerator::WriteExtraSource(
  1968. Elem& e1, cmSourceFile const* sf, ConfigToSettings& toolSettings)
  1969. {
  1970. bool toolHasSettings = false;
  1971. const char* tool = "None";
  1972. std::string settingsGenerator;
  1973. std::string settingsLastGenOutput;
  1974. std::string sourceLink;
  1975. std::string subType;
  1976. std::string copyToOutDir;
  1977. std::string includeInVsix;
  1978. std::string ext = cmSystemTools::LowerCase(sf->GetExtension());
  1979. if (this->ProjectType == VsProjectType::csproj && !this->InSourceBuild) {
  1980. toolHasSettings = true;
  1981. }
  1982. if (ext == "hlsl") {
  1983. tool = "FXCompile";
  1984. // Figure out the type of shader compiler to use.
  1985. if (cmValue st = sf->GetProperty("VS_SHADER_TYPE")) {
  1986. for (const std::string& config : this->Configurations) {
  1987. toolSettings[config]["ShaderType"] = *st;
  1988. }
  1989. }
  1990. // Figure out which entry point to use if any
  1991. if (cmValue se = sf->GetProperty("VS_SHADER_ENTRYPOINT")) {
  1992. for (const std::string& config : this->Configurations) {
  1993. toolSettings[config]["EntryPointName"] = *se;
  1994. }
  1995. }
  1996. // Figure out which shader model to use if any
  1997. if (cmValue sm = sf->GetProperty("VS_SHADER_MODEL")) {
  1998. for (const std::string& config : this->Configurations) {
  1999. toolSettings[config]["ShaderModel"] = *sm;
  2000. }
  2001. }
  2002. // Figure out which output header file to use if any
  2003. if (cmValue ohf = sf->GetProperty("VS_SHADER_OUTPUT_HEADER_FILE")) {
  2004. for (const std::string& config : this->Configurations) {
  2005. toolSettings[config]["HeaderFileOutput"] = *ohf;
  2006. }
  2007. }
  2008. // Figure out which variable name to use if any
  2009. if (cmValue vn = sf->GetProperty("VS_SHADER_VARIABLE_NAME")) {
  2010. for (const std::string& config : this->Configurations) {
  2011. toolSettings[config]["VariableName"] = *vn;
  2012. }
  2013. }
  2014. // Figure out if there's any additional flags to use
  2015. if (cmValue saf = sf->GetProperty("VS_SHADER_FLAGS")) {
  2016. cmGeneratorExpression ge(*this->LocalGenerator->GetCMakeInstance());
  2017. std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(*saf);
  2018. for (const std::string& config : this->Configurations) {
  2019. std::string evaluated = cge->Evaluate(this->LocalGenerator, config);
  2020. if (!evaluated.empty()) {
  2021. toolSettings[config]["AdditionalOptions"] = evaluated;
  2022. }
  2023. }
  2024. }
  2025. // Figure out if debug information should be generated
  2026. if (cmValue sed = sf->GetProperty("VS_SHADER_ENABLE_DEBUG")) {
  2027. cmGeneratorExpression ge(*this->LocalGenerator->GetCMakeInstance());
  2028. std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(*sed);
  2029. for (const std::string& config : this->Configurations) {
  2030. std::string evaluated = cge->Evaluate(this->LocalGenerator, config);
  2031. if (!evaluated.empty()) {
  2032. toolSettings[config]["EnableDebuggingInformation"] =
  2033. cmIsOn(evaluated) ? "true" : "false";
  2034. }
  2035. }
  2036. }
  2037. // Figure out if optimizations should be disabled
  2038. if (cmValue sdo = sf->GetProperty("VS_SHADER_DISABLE_OPTIMIZATIONS")) {
  2039. cmGeneratorExpression ge(*this->LocalGenerator->GetCMakeInstance());
  2040. std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(*sdo);
  2041. for (const std::string& config : this->Configurations) {
  2042. std::string evaluated = cge->Evaluate(this->LocalGenerator, config);
  2043. if (!evaluated.empty()) {
  2044. toolSettings[config]["DisableOptimizations"] =
  2045. cmIsOn(evaluated) ? "true" : "false";
  2046. }
  2047. }
  2048. }
  2049. if (cmValue sofn = sf->GetProperty("VS_SHADER_OBJECT_FILE_NAME")) {
  2050. for (const std::string& config : this->Configurations) {
  2051. toolSettings[config]["ObjectFileOutput"] = *sofn;
  2052. }
  2053. }
  2054. } else if (ext == "jpg" || ext == "png") {
  2055. tool = "Image";
  2056. } else if (ext == "resw") {
  2057. tool = "PRIResource";
  2058. } else if (ext == "xml") {
  2059. tool = "XML";
  2060. } else if (ext == "natvis") {
  2061. tool = "Natvis";
  2062. } else if (ext == "settings") {
  2063. settingsLastGenOutput =
  2064. cmsys::SystemTools::GetFilenameName(sf->GetFullPath());
  2065. std::size_t pos = settingsLastGenOutput.find(".settings");
  2066. settingsLastGenOutput.replace(pos, 9, ".Designer.cs");
  2067. settingsGenerator = "SettingsSingleFileGenerator";
  2068. toolHasSettings = true;
  2069. } else if (ext == "vsixmanifest") {
  2070. subType = "Designer";
  2071. }
  2072. if (cmValue c = sf->GetProperty("VS_COPY_TO_OUT_DIR")) {
  2073. tool = "Content";
  2074. copyToOutDir = *c;
  2075. toolHasSettings = true;
  2076. }
  2077. if (sf->GetPropertyAsBool("VS_INCLUDE_IN_VSIX")) {
  2078. includeInVsix = "True";
  2079. tool = "Content";
  2080. toolHasSettings = true;
  2081. }
  2082. // Collect VS_CSHARP_* property values (if some are set)
  2083. std::map<std::string, std::string> sourceFileTags;
  2084. this->GetCSharpSourceProperties(sf, sourceFileTags);
  2085. if (this->NsightTegra) {
  2086. // Nsight Tegra needs specific file types to check up-to-dateness.
  2087. std::string name = cmSystemTools::LowerCase(sf->GetLocation().GetName());
  2088. if (name == "androidmanifest.xml" || name == "build.xml" ||
  2089. name == "proguard.cfg" || name == "proguard-project.txt" ||
  2090. ext == "properties") {
  2091. tool = "AndroidBuild";
  2092. } else if (ext == "java") {
  2093. tool = "JCompile";
  2094. } else if (ext == "asm" || ext == "s") {
  2095. tool = "ClCompile";
  2096. }
  2097. }
  2098. cmValue toolOverride = sf->GetProperty("VS_TOOL_OVERRIDE");
  2099. if (cmNonempty(toolOverride)) {
  2100. tool = toolOverride->c_str();
  2101. }
  2102. std::string deployContent;
  2103. std::string deployLocation;
  2104. if (this->GlobalGenerator->TargetsWindowsPhone() ||
  2105. this->GlobalGenerator->TargetsWindowsStore()) {
  2106. cmValue content = sf->GetProperty("VS_DEPLOYMENT_CONTENT");
  2107. if (cmNonempty(content)) {
  2108. toolHasSettings = true;
  2109. deployContent = *content;
  2110. cmValue location = sf->GetProperty("VS_DEPLOYMENT_LOCATION");
  2111. if (cmNonempty(location)) {
  2112. deployLocation = *location;
  2113. }
  2114. }
  2115. }
  2116. if (ParsedToolTargetSettings.find(tool) == ParsedToolTargetSettings.end()) {
  2117. cmValue toolTargetProperty = this->GeneratorTarget->Target->GetProperty(
  2118. "VS_SOURCE_SETTINGS_" + std::string(tool));
  2119. ConfigToSettings toolTargetSettings;
  2120. if (toolTargetProperty) {
  2121. ParseSettingsProperty(*toolTargetProperty, toolTargetSettings);
  2122. }
  2123. ParsedToolTargetSettings[tool] = toolTargetSettings;
  2124. }
  2125. for (const auto& configToSetting : ParsedToolTargetSettings[tool]) {
  2126. for (const auto& setting : configToSetting.second) {
  2127. toolSettings[configToSetting.first][setting.first] = setting.second;
  2128. }
  2129. }
  2130. if (!toolSettings.empty()) {
  2131. toolHasSettings = true;
  2132. }
  2133. Elem e2(e1, tool);
  2134. this->WriteSource(e2, sf);
  2135. if (toolHasSettings) {
  2136. e2.SetHasElements();
  2137. this->FinishWritingSource(e2, toolSettings);
  2138. if (!deployContent.empty()) {
  2139. cmGeneratorExpression ge(*this->LocalGenerator->GetCMakeInstance());
  2140. std::unique_ptr<cmCompiledGeneratorExpression> cge =
  2141. ge.Parse(deployContent);
  2142. // Deployment location cannot be set on a configuration basis
  2143. if (!deployLocation.empty()) {
  2144. e2.Element("Link", deployLocation + "\\%(FileName)%(Extension)");
  2145. }
  2146. for (size_t i = 0; i != this->Configurations.size(); ++i) {
  2147. if (cge->Evaluate(this->LocalGenerator, this->Configurations[i]) ==
  2148. "1") {
  2149. e2.WritePlatformConfigTag("DeploymentContent",
  2150. "'$(Configuration)|$(Platform)'=='" +
  2151. this->Configurations[i] + "|" +
  2152. this->Platform + "'",
  2153. "true");
  2154. } else {
  2155. e2.WritePlatformConfigTag("ExcludedFromBuild",
  2156. "'$(Configuration)|$(Platform)'=='" +
  2157. this->Configurations[i] + "|" +
  2158. this->Platform + "'",
  2159. "true");
  2160. }
  2161. }
  2162. }
  2163. if (!settingsGenerator.empty()) {
  2164. e2.Element("Generator", settingsGenerator);
  2165. }
  2166. if (!settingsLastGenOutput.empty()) {
  2167. e2.Element("LastGenOutput", settingsLastGenOutput);
  2168. }
  2169. if (!subType.empty()) {
  2170. e2.Element("SubType", subType);
  2171. }
  2172. if (!copyToOutDir.empty()) {
  2173. e2.Element("CopyToOutputDirectory", copyToOutDir);
  2174. }
  2175. if (!includeInVsix.empty()) {
  2176. e2.Element("IncludeInVSIX", includeInVsix);
  2177. }
  2178. // write source file specific tags
  2179. this->WriteCSharpSourceProperties(e2, sourceFileTags);
  2180. }
  2181. }
  2182. void cmVisualStudio10TargetGenerator::WriteSource(Elem& e2,
  2183. cmSourceFile const* sf)
  2184. {
  2185. // Visual Studio tools append relative paths to the current dir, as in:
  2186. //
  2187. // c:\path\to\current\dir\..\..\..\relative\path\to\source.c
  2188. //
  2189. // and fail if this exceeds the maximum allowed path length. Our path
  2190. // conversion uses full paths when possible to allow deeper trees.
  2191. // However, CUDA 8.0 msbuild rules fail on absolute paths so for CUDA
  2192. // we must use relative paths.
  2193. bool forceRelative = sf->GetLanguage() == "CUDA";
  2194. std::string sourceFile = this->ConvertPath(sf->GetFullPath(), forceRelative);
  2195. ConvertToWindowsSlash(sourceFile);
  2196. e2.Attribute("Include", sourceFile);
  2197. if (this->ProjectType == VsProjectType::csproj && !this->InSourceBuild) {
  2198. // For out of source projects we have to provide a link (if not specified
  2199. // via property) for every source file (besides .cs files) otherwise they
  2200. // will not be visible in VS at all.
  2201. // First we check if the file is in a source group, then we check if the
  2202. // file path is relative to current source- or binary-dir, otherwise it is
  2203. // added with the plain filename without any path. This means the file will
  2204. // show up at root-level of the csproj (where CMakeLists.txt etc. are).
  2205. std::string link = this->GetCSharpSourceLink(sf);
  2206. if (link.empty()) {
  2207. link = cmsys::SystemTools::GetFilenameName(sf->GetFullPath());
  2208. }
  2209. e2.Element("Link", link);
  2210. }
  2211. ToolSource toolSource = { sf, forceRelative };
  2212. this->Tools[e2.Tag].push_back(toolSource);
  2213. }
  2214. void cmVisualStudio10TargetGenerator::WriteAllSources(Elem& e0)
  2215. {
  2216. if (this->GeneratorTarget->GetType() == cmStateEnums::GLOBAL_TARGET) {
  2217. return;
  2218. }
  2219. const bool haveUnityBuild =
  2220. this->GeneratorTarget->GetPropertyAsBool("UNITY_BUILD");
  2221. if (haveUnityBuild && this->GlobalGenerator->GetSupportsUnityBuilds()) {
  2222. Elem e1(e0, "PropertyGroup");
  2223. e1.Element("EnableUnitySupport", "true");
  2224. }
  2225. Elem e1(e0, "ItemGroup");
  2226. e1.SetHasElements();
  2227. std::vector<size_t> all_configs;
  2228. for (size_t ci = 0; ci < this->Configurations.size(); ++ci) {
  2229. all_configs.push_back(ci);
  2230. }
  2231. std::vector<cmGeneratorTarget::AllConfigSource> const& sources =
  2232. this->GeneratorTarget->GetAllConfigSources();
  2233. cmSourceFile const* srcCMakeLists =
  2234. this->LocalGenerator->CreateVCProjBuildRule();
  2235. for (cmGeneratorTarget::AllConfigSource const& si : sources) {
  2236. if (si.Source == srcCMakeLists) {
  2237. // Skip explicit reference to CMakeLists.txt source.
  2238. continue;
  2239. }
  2240. ConfigToSettings toolSettings;
  2241. for (const auto& config : this->Configurations) {
  2242. toolSettings[config];
  2243. }
  2244. if (cmValue p = si.Source->GetProperty("VS_SETTINGS")) {
  2245. ParseSettingsProperty(*p, toolSettings);
  2246. }
  2247. const char* tool = nullptr;
  2248. switch (si.Kind) {
  2249. case cmGeneratorTarget::SourceKindAppManifest:
  2250. tool = "AppxManifest";
  2251. break;
  2252. case cmGeneratorTarget::SourceKindCertificate:
  2253. tool = "None";
  2254. break;
  2255. case cmGeneratorTarget::SourceKindCustomCommand:
  2256. // Handled elsewhere.
  2257. break;
  2258. case cmGeneratorTarget::SourceKindExternalObject:
  2259. tool = "Object";
  2260. if (this->LocalGenerator->GetVersion() <
  2261. cmGlobalVisualStudioGenerator::VSVersion::VS11) {
  2262. // For VS == 10 we cannot use LinkObjects to avoid linking custom
  2263. // command outputs. If an object file is generated in this target,
  2264. // then vs10 will use it in the build, and we have to list it as
  2265. // None instead of Object.
  2266. std::vector<cmSourceFile*> const* d =
  2267. this->GeneratorTarget->GetSourceDepends(si.Source);
  2268. if (d && !d->empty()) {
  2269. tool = "None";
  2270. }
  2271. }
  2272. break;
  2273. case cmGeneratorTarget::SourceKindExtra:
  2274. this->WriteExtraSource(e1, si.Source, toolSettings);
  2275. break;
  2276. case cmGeneratorTarget::SourceKindHeader:
  2277. this->WriteHeaderSource(e1, si.Source, toolSettings);
  2278. break;
  2279. case cmGeneratorTarget::SourceKindIDL:
  2280. tool = "Midl";
  2281. break;
  2282. case cmGeneratorTarget::SourceKindManifest:
  2283. // Handled elsewhere.
  2284. break;
  2285. case cmGeneratorTarget::SourceKindModuleDefinition:
  2286. tool = "None";
  2287. break;
  2288. case cmGeneratorTarget::SourceKindUnityBatched:
  2289. case cmGeneratorTarget::SourceKindObjectSource: {
  2290. const std::string& lang = si.Source->GetLanguage();
  2291. if (lang == "C" || lang == "CXX") {
  2292. tool = "ClCompile";
  2293. } else if (lang == "ASM_MARMASM" &&
  2294. this->GlobalGenerator->IsMarmasmEnabled()) {
  2295. tool = "MARMASM";
  2296. } else if (lang == "ASM_MASM" &&
  2297. this->GlobalGenerator->IsMasmEnabled()) {
  2298. tool = "MASM";
  2299. } else if (lang == "ASM_NASM" &&
  2300. this->GlobalGenerator->IsNasmEnabled()) {
  2301. tool = "NASM";
  2302. } else if (lang == "RC") {
  2303. tool = "ResourceCompile";
  2304. } else if (lang == "CSharp") {
  2305. tool = "Compile";
  2306. } else if (lang == "CUDA" && this->GlobalGenerator->IsCudaEnabled()) {
  2307. tool = "CudaCompile";
  2308. } else {
  2309. tool = "None";
  2310. }
  2311. } break;
  2312. case cmGeneratorTarget::SourceKindResx:
  2313. this->ResxObjs.push_back(si.Source);
  2314. break;
  2315. case cmGeneratorTarget::SourceKindXaml:
  2316. this->XamlObjs.push_back(si.Source);
  2317. break;
  2318. }
  2319. if (tool) {
  2320. // Compute set of configurations to exclude, if any.
  2321. std::vector<size_t> const& include_configs = si.Configs;
  2322. std::vector<size_t> exclude_configs;
  2323. std::set_difference(all_configs.begin(), all_configs.end(),
  2324. include_configs.begin(), include_configs.end(),
  2325. std::back_inserter(exclude_configs));
  2326. Elem e2(e1, tool);
  2327. bool isCSharp = (si.Source->GetLanguage() == "CSharp");
  2328. if (isCSharp && !exclude_configs.empty()) {
  2329. std::stringstream conditions;
  2330. bool firstConditionSet{ false };
  2331. for (const auto& ci : include_configs) {
  2332. if (firstConditionSet) {
  2333. conditions << " Or ";
  2334. }
  2335. conditions << "('$(Configuration)|$(Platform)'=='" +
  2336. this->Configurations[ci] + "|" + this->Platform + "')";
  2337. firstConditionSet = true;
  2338. }
  2339. e2.Attribute("Condition", conditions.str());
  2340. }
  2341. this->WriteSource(e2, si.Source);
  2342. bool useNativeUnityBuild = false;
  2343. if (haveUnityBuild && this->GlobalGenerator->GetSupportsUnityBuilds()) {
  2344. // Magic value taken from cmGlobalVisualStudioVersionedGenerator.cxx
  2345. static const std::string vs15 = "141";
  2346. std::string toolset =
  2347. this->GlobalGenerator->GetPlatformToolsetString();
  2348. cmSystemTools::ReplaceString(toolset, "v", "");
  2349. if (toolset.empty() ||
  2350. cmSystemTools::VersionCompareGreaterEq(toolset, vs15)) {
  2351. useNativeUnityBuild = true;
  2352. }
  2353. }
  2354. if (haveUnityBuild && strcmp(tool, "ClCompile") == 0 &&
  2355. si.Source->GetProperty("UNITY_SOURCE_FILE")) {
  2356. if (useNativeUnityBuild) {
  2357. e2.Attribute(
  2358. "IncludeInUnityFile",
  2359. si.Source->GetPropertyAsBool("SKIP_UNITY_BUILD_INCLUSION")
  2360. ? "false"
  2361. : "true");
  2362. e2.Attribute("CustomUnityFile", "true");
  2363. std::string unityDir = cmSystemTools::GetFilenamePath(
  2364. *si.Source->GetProperty("UNITY_SOURCE_FILE"));
  2365. e2.Attribute("UnityFilesDirectory", unityDir);
  2366. } else {
  2367. // Visual Studio versions prior to 2017 15.8 do not know about unity
  2368. // builds, thus we exclude the files already part of unity sources.
  2369. if (!si.Source->GetPropertyAsBool("SKIP_UNITY_BUILD_INCLUSION")) {
  2370. exclude_configs = all_configs;
  2371. }
  2372. }
  2373. }
  2374. if (si.Kind == cmGeneratorTarget::SourceKindObjectSource ||
  2375. si.Kind == cmGeneratorTarget::SourceKindUnityBatched) {
  2376. this->OutputSourceSpecificFlags(e2, si.Source);
  2377. }
  2378. if (si.Source->GetPropertyAsBool("SKIP_PRECOMPILE_HEADERS")) {
  2379. e2.Element("PrecompiledHeader", "NotUsing");
  2380. }
  2381. if (!isCSharp && !exclude_configs.empty()) {
  2382. this->WriteExcludeFromBuild(e2, exclude_configs);
  2383. }
  2384. this->FinishWritingSource(e2, toolSettings);
  2385. }
  2386. }
  2387. if (this->IsMissingFiles) {
  2388. this->WriteMissingFiles(e1);
  2389. }
  2390. }
  2391. void cmVisualStudio10TargetGenerator::FinishWritingSource(
  2392. Elem& e2, ConfigToSettings const& toolSettings)
  2393. {
  2394. std::vector<std::string> writtenSettings;
  2395. for (const auto& configSettings : toolSettings) {
  2396. for (const auto& setting : configSettings.second) {
  2397. if (std::find(writtenSettings.begin(), writtenSettings.end(),
  2398. setting.first) != writtenSettings.end()) {
  2399. continue;
  2400. }
  2401. if (PropertyIsSameInAllConfigs(toolSettings, setting.first)) {
  2402. e2.Element(setting.first, setting.second);
  2403. writtenSettings.push_back(setting.first);
  2404. } else {
  2405. e2.WritePlatformConfigTag(setting.first,
  2406. "'$(Configuration)|$(Platform)'=='" +
  2407. configSettings.first + "|" +
  2408. this->Platform + "'",
  2409. setting.second);
  2410. }
  2411. }
  2412. }
  2413. }
  2414. void cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags(
  2415. Elem& e2, cmSourceFile const* source)
  2416. {
  2417. cmSourceFile const& sf = *source;
  2418. std::string objectName;
  2419. if (this->GeneratorTarget->HasExplicitObjectName(&sf)) {
  2420. objectName = this->GeneratorTarget->GetObjectName(&sf);
  2421. }
  2422. std::string flags;
  2423. bool configDependentFlags = false;
  2424. std::string options;
  2425. bool configDependentOptions = false;
  2426. std::string defines;
  2427. bool configDependentDefines = false;
  2428. std::string includes;
  2429. bool configDependentIncludes = false;
  2430. if (cmValue cflags = sf.GetProperty("COMPILE_FLAGS")) {
  2431. configDependentFlags =
  2432. cmGeneratorExpression::Find(*cflags) != std::string::npos;
  2433. flags += *cflags;
  2434. }
  2435. if (cmValue coptions = sf.GetProperty("COMPILE_OPTIONS")) {
  2436. configDependentOptions =
  2437. cmGeneratorExpression::Find(*coptions) != std::string::npos;
  2438. options += *coptions;
  2439. }
  2440. if (cmValue cdefs = sf.GetProperty("COMPILE_DEFINITIONS")) {
  2441. configDependentDefines =
  2442. cmGeneratorExpression::Find(*cdefs) != std::string::npos;
  2443. defines += *cdefs;
  2444. }
  2445. if (cmValue cincludes = sf.GetProperty("INCLUDE_DIRECTORIES")) {
  2446. configDependentIncludes =
  2447. cmGeneratorExpression::Find(*cincludes) != std::string::npos;
  2448. includes += *cincludes;
  2449. }
  2450. // Force language if the file extension does not match.
  2451. // Note that MSVC treats the upper-case '.C' extension as C and not C++.
  2452. std::string const ext = sf.GetExtension();
  2453. std::string const extLang = ext == "C"
  2454. ? "C"
  2455. : this->GlobalGenerator->GetLanguageFromExtension(ext.c_str());
  2456. std::string lang = this->LocalGenerator->GetSourceFileLanguage(sf);
  2457. const char* compileAs = nullptr;
  2458. if (lang != extLang) {
  2459. if (lang == "CXX") {
  2460. // force a C++ file type
  2461. compileAs = "CompileAsCpp";
  2462. } else if (lang == "C") {
  2463. // force to c
  2464. compileAs = "CompileAsC";
  2465. }
  2466. }
  2467. bool noWinRT = this->TargetCompileAsWinRT && lang == "C";
  2468. // for the first time we need a new line if there is something
  2469. // produced here.
  2470. if (!objectName.empty()) {
  2471. if (lang == "CUDA") {
  2472. e2.Element("CompileOut", "$(IntDir)/" + objectName);
  2473. } else {
  2474. e2.Element("ObjectFileName", "$(IntDir)/" + objectName);
  2475. }
  2476. }
  2477. if (lang == "ASM_NASM") {
  2478. if (cmValue objectDeps = sf.GetProperty("OBJECT_DEPENDS")) {
  2479. std::string dependencies;
  2480. std::vector<std::string> depends = cmExpandedList(*objectDeps);
  2481. const char* sep = "";
  2482. for (std::string& d : depends) {
  2483. ConvertToWindowsSlash(d);
  2484. dependencies += sep;
  2485. dependencies += d;
  2486. sep = ";";
  2487. }
  2488. e2.Element("AdditionalDependencies", dependencies);
  2489. }
  2490. }
  2491. for (std::string const& config : this->Configurations) {
  2492. std::string configUpper = cmSystemTools::UpperCase(config);
  2493. std::string configDefines = defines;
  2494. std::string defPropName = cmStrCat("COMPILE_DEFINITIONS_", configUpper);
  2495. if (cmValue ccdefs = sf.GetProperty(defPropName)) {
  2496. if (!configDefines.empty()) {
  2497. configDefines += ";";
  2498. }
  2499. configDependentDefines |=
  2500. cmGeneratorExpression::Find(*ccdefs) != std::string::npos;
  2501. configDefines += *ccdefs;
  2502. }
  2503. // We have pch state in the following situation:
  2504. // 1. We have SKIP_PRECOMPILE_HEADERS == true
  2505. // 2. We are creating the pre-compiled header
  2506. // 3. We are a different language than the linker language AND pch is
  2507. // enabled.
  2508. std::string const& linkLanguage =
  2509. this->GeneratorTarget->GetLinkerLanguage(config);
  2510. std::string const& pchSource =
  2511. this->GeneratorTarget->GetPchSource(config, lang);
  2512. const bool skipPCH =
  2513. pchSource.empty() || sf.GetPropertyAsBool("SKIP_PRECOMPILE_HEADERS");
  2514. const bool makePCH = (sf.GetFullPath() == pchSource);
  2515. const bool useSharedPCH = !skipPCH && (lang == linkLanguage);
  2516. const bool useDifferentLangPCH = !skipPCH && (lang != linkLanguage);
  2517. const bool useNoPCH = skipPCH && (lang != linkLanguage) &&
  2518. !this->GeneratorTarget->GetPchHeader(config, linkLanguage).empty();
  2519. const bool needsPCHFlags =
  2520. (makePCH || useSharedPCH || useDifferentLangPCH || useNoPCH);
  2521. // if we have flags or defines for this config then
  2522. // use them
  2523. if (!flags.empty() || !options.empty() || !configDefines.empty() ||
  2524. !includes.empty() || compileAs || noWinRT || !options.empty() ||
  2525. needsPCHFlags) {
  2526. cmGlobalVisualStudio10Generator* gg = this->GlobalGenerator;
  2527. cmIDEFlagTable const* flagtable = nullptr;
  2528. const std::string& srclang = source->GetLanguage();
  2529. if (srclang == "C" || srclang == "CXX") {
  2530. flagtable = gg->GetClFlagTable();
  2531. } else if (srclang == "ASM_MARMASM" &&
  2532. this->GlobalGenerator->IsMarmasmEnabled()) {
  2533. flagtable = gg->GetMarmasmFlagTable();
  2534. } else if (srclang == "ASM_MASM" &&
  2535. this->GlobalGenerator->IsMasmEnabled()) {
  2536. flagtable = gg->GetMasmFlagTable();
  2537. } else if (lang == "ASM_NASM" &&
  2538. this->GlobalGenerator->IsNasmEnabled()) {
  2539. flagtable = gg->GetNasmFlagTable();
  2540. } else if (srclang == "RC") {
  2541. flagtable = gg->GetRcFlagTable();
  2542. } else if (srclang == "CSharp") {
  2543. flagtable = gg->GetCSharpFlagTable();
  2544. }
  2545. cmGeneratorExpressionInterpreter genexInterpreter(
  2546. this->LocalGenerator, config, this->GeneratorTarget, lang);
  2547. cmVS10GeneratorOptions clOptions(
  2548. this->LocalGenerator, cmVisualStudioGeneratorOptions::Compiler,
  2549. flagtable, this);
  2550. if (compileAs) {
  2551. clOptions.AddFlag("CompileAs", compileAs);
  2552. }
  2553. if (noWinRT) {
  2554. clOptions.AddFlag("CompileAsWinRT", "false");
  2555. }
  2556. if (configDependentFlags) {
  2557. clOptions.Parse(genexInterpreter.Evaluate(flags, "COMPILE_FLAGS"));
  2558. } else {
  2559. clOptions.Parse(flags);
  2560. }
  2561. if (needsPCHFlags) {
  2562. // Add precompile headers compile options.
  2563. if (makePCH) {
  2564. clOptions.AddFlag("PrecompiledHeader", "Create");
  2565. std::string pchHeader =
  2566. this->GeneratorTarget->GetPchHeader(config, lang);
  2567. clOptions.AddFlag("PrecompiledHeaderFile", pchHeader);
  2568. std::string pchFile =
  2569. this->GeneratorTarget->GetPchFile(config, lang);
  2570. clOptions.AddFlag("PrecompiledHeaderOutputFile", pchFile);
  2571. clOptions.AddFlag("ForcedIncludeFiles", pchHeader);
  2572. } else if (useNoPCH) {
  2573. clOptions.AddFlag("PrecompiledHeader", "NotUsing");
  2574. } else if (useSharedPCH) {
  2575. std::string pchHeader =
  2576. this->GeneratorTarget->GetPchHeader(config, lang);
  2577. clOptions.AddFlag("ForcedIncludeFiles", pchHeader);
  2578. } else if (useDifferentLangPCH) {
  2579. clOptions.AddFlag("PrecompiledHeader", "Use");
  2580. std::string pchHeader =
  2581. this->GeneratorTarget->GetPchHeader(config, lang);
  2582. clOptions.AddFlag("PrecompiledHeaderFile", pchHeader);
  2583. std::string pchFile =
  2584. this->GeneratorTarget->GetPchFile(config, lang);
  2585. clOptions.AddFlag("PrecompiledHeaderOutputFile", pchFile);
  2586. clOptions.AddFlag("ForcedIncludeFiles", pchHeader);
  2587. }
  2588. }
  2589. if (!options.empty()) {
  2590. std::string expandedOptions;
  2591. if (configDependentOptions) {
  2592. this->LocalGenerator->AppendCompileOptions(
  2593. expandedOptions,
  2594. genexInterpreter.Evaluate(options, "COMPILE_OPTIONS"));
  2595. } else {
  2596. this->LocalGenerator->AppendCompileOptions(expandedOptions, options);
  2597. }
  2598. clOptions.Parse(expandedOptions);
  2599. }
  2600. if (clOptions.HasFlag("DisableSpecificWarnings")) {
  2601. clOptions.AppendFlag("DisableSpecificWarnings",
  2602. "%(DisableSpecificWarnings)");
  2603. }
  2604. if (clOptions.HasFlag("ForcedIncludeFiles")) {
  2605. clOptions.AppendFlag("ForcedIncludeFiles", "%(ForcedIncludeFiles)");
  2606. }
  2607. if (configDependentDefines) {
  2608. clOptions.AddDefines(
  2609. genexInterpreter.Evaluate(configDefines, "COMPILE_DEFINITIONS"));
  2610. } else {
  2611. clOptions.AddDefines(configDefines);
  2612. }
  2613. std::vector<std::string> includeList;
  2614. if (configDependentIncludes) {
  2615. this->LocalGenerator->AppendIncludeDirectories(
  2616. includeList,
  2617. genexInterpreter.Evaluate(includes, "INCLUDE_DIRECTORIES"), *source);
  2618. } else {
  2619. this->LocalGenerator->AppendIncludeDirectories(includeList, includes,
  2620. *source);
  2621. }
  2622. clOptions.AddIncludes(includeList);
  2623. clOptions.SetConfiguration(config);
  2624. OptionsHelper oh(clOptions, e2);
  2625. oh.PrependInheritedString("AdditionalOptions");
  2626. oh.OutputAdditionalIncludeDirectories(lang);
  2627. oh.OutputFlagMap();
  2628. oh.OutputPreprocessorDefinitions(lang);
  2629. }
  2630. }
  2631. if (this->IsXamlSource(source->GetFullPath())) {
  2632. const std::string& fileName = source->GetFullPath();
  2633. e2.Element("DependentUpon",
  2634. fileName.substr(0, fileName.find_last_of(".")));
  2635. }
  2636. if (this->ProjectType == VsProjectType::csproj) {
  2637. using CsPropMap = std::map<std::string, std::string>;
  2638. CsPropMap sourceFileTags;
  2639. this->GetCSharpSourceProperties(&sf, sourceFileTags);
  2640. // write source file specific tags
  2641. if (!sourceFileTags.empty()) {
  2642. this->WriteCSharpSourceProperties(e2, sourceFileTags);
  2643. }
  2644. }
  2645. }
  2646. void cmVisualStudio10TargetGenerator::WriteExcludeFromBuild(
  2647. Elem& e2, std::vector<size_t> const& exclude_configs)
  2648. {
  2649. for (size_t ci : exclude_configs) {
  2650. e2.WritePlatformConfigTag("ExcludedFromBuild",
  2651. "'$(Configuration)|$(Platform)'=='" +
  2652. this->Configurations[ci] + "|" +
  2653. this->Platform + "'",
  2654. "true");
  2655. }
  2656. }
  2657. void cmVisualStudio10TargetGenerator::WritePathAndIncrementalLinkOptions(
  2658. Elem& e0)
  2659. {
  2660. cmStateEnums::TargetType ttype = this->GeneratorTarget->GetType();
  2661. if (ttype > cmStateEnums::INTERFACE_LIBRARY) {
  2662. return;
  2663. }
  2664. if (this->ProjectType == VsProjectType::csproj) {
  2665. return;
  2666. }
  2667. Elem e1(e0, "PropertyGroup");
  2668. e1.Element("_ProjectFileVersion", "10.0.20506.1");
  2669. for (std::string const& config : this->Configurations) {
  2670. const std::string cond = this->CalcCondition(config);
  2671. if (ttype >= cmStateEnums::UTILITY) {
  2672. e1.WritePlatformConfigTag(
  2673. "IntDir", cond, "$(Platform)\\$(Configuration)\\$(ProjectName)\\");
  2674. } else {
  2675. std::string intermediateDir = cmStrCat(
  2676. this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget), '/',
  2677. config, '/');
  2678. std::string outDir;
  2679. std::string targetNameFull;
  2680. if (ttype == cmStateEnums::OBJECT_LIBRARY) {
  2681. outDir = intermediateDir;
  2682. targetNameFull = cmStrCat(this->GeneratorTarget->GetName(), ".lib");
  2683. } else {
  2684. outDir = this->GeneratorTarget->GetDirectory(config) + "/";
  2685. targetNameFull = this->GeneratorTarget->GetFullName(config);
  2686. }
  2687. ConvertToWindowsSlash(intermediateDir);
  2688. ConvertToWindowsSlash(outDir);
  2689. e1.WritePlatformConfigTag("OutDir", cond, outDir);
  2690. e1.WritePlatformConfigTag("IntDir", cond, intermediateDir);
  2691. if (cmValue sdkExecutableDirectories = this->Makefile->GetDefinition(
  2692. "CMAKE_VS_SDK_EXECUTABLE_DIRECTORIES")) {
  2693. e1.WritePlatformConfigTag("ExecutablePath", cond,
  2694. *sdkExecutableDirectories);
  2695. }
  2696. if (cmValue sdkIncludeDirectories = this->Makefile->GetDefinition(
  2697. "CMAKE_VS_SDK_INCLUDE_DIRECTORIES")) {
  2698. e1.WritePlatformConfigTag("IncludePath", cond, *sdkIncludeDirectories);
  2699. }
  2700. if (cmValue sdkReferenceDirectories = this->Makefile->GetDefinition(
  2701. "CMAKE_VS_SDK_REFERENCE_DIRECTORIES")) {
  2702. e1.WritePlatformConfigTag("ReferencePath", cond,
  2703. *sdkReferenceDirectories);
  2704. }
  2705. if (cmValue sdkLibraryDirectories = this->Makefile->GetDefinition(
  2706. "CMAKE_VS_SDK_LIBRARY_DIRECTORIES")) {
  2707. e1.WritePlatformConfigTag("LibraryPath", cond, *sdkLibraryDirectories);
  2708. }
  2709. if (cmValue sdkLibraryWDirectories = this->Makefile->GetDefinition(
  2710. "CMAKE_VS_SDK_LIBRARY_WINRT_DIRECTORIES")) {
  2711. e1.WritePlatformConfigTag("LibraryWPath", cond,
  2712. *sdkLibraryWDirectories);
  2713. }
  2714. if (cmValue sdkSourceDirectories =
  2715. this->Makefile->GetDefinition("CMAKE_VS_SDK_SOURCE_DIRECTORIES")) {
  2716. e1.WritePlatformConfigTag("SourcePath", cond, *sdkSourceDirectories);
  2717. }
  2718. if (cmValue sdkExcludeDirectories = this->Makefile->GetDefinition(
  2719. "CMAKE_VS_SDK_EXCLUDE_DIRECTORIES")) {
  2720. e1.WritePlatformConfigTag("ExcludePath", cond, *sdkExcludeDirectories);
  2721. }
  2722. std::string name =
  2723. cmSystemTools::GetFilenameWithoutLastExtension(targetNameFull);
  2724. e1.WritePlatformConfigTag("TargetName", cond, name);
  2725. std::string ext =
  2726. cmSystemTools::GetFilenameLastExtension(targetNameFull);
  2727. if (ext.empty()) {
  2728. // An empty TargetExt causes a default extension to be used.
  2729. // A single "." appears to be treated as an empty extension.
  2730. ext = ".";
  2731. }
  2732. e1.WritePlatformConfigTag("TargetExt", cond, ext);
  2733. this->OutputLinkIncremental(e1, config);
  2734. }
  2735. if (ttype <= cmStateEnums::UTILITY) {
  2736. if (cmValue workingDir = this->GeneratorTarget->GetProperty(
  2737. "VS_DEBUGGER_WORKING_DIRECTORY")) {
  2738. std::string genWorkingDir = cmGeneratorExpression::Evaluate(
  2739. *workingDir, this->LocalGenerator, config);
  2740. e1.WritePlatformConfigTag("LocalDebuggerWorkingDirectory", cond,
  2741. genWorkingDir);
  2742. }
  2743. if (cmValue environment =
  2744. this->GeneratorTarget->GetProperty("VS_DEBUGGER_ENVIRONMENT")) {
  2745. std::string genEnvironment = cmGeneratorExpression::Evaluate(
  2746. *environment, this->LocalGenerator, config);
  2747. e1.WritePlatformConfigTag("LocalDebuggerEnvironment", cond,
  2748. genEnvironment);
  2749. }
  2750. if (cmValue debuggerCommand =
  2751. this->GeneratorTarget->GetProperty("VS_DEBUGGER_COMMAND")) {
  2752. std::string genDebuggerCommand = cmGeneratorExpression::Evaluate(
  2753. *debuggerCommand, this->LocalGenerator, config);
  2754. e1.WritePlatformConfigTag("LocalDebuggerCommand", cond,
  2755. genDebuggerCommand);
  2756. }
  2757. if (cmValue commandArguments = this->GeneratorTarget->GetProperty(
  2758. "VS_DEBUGGER_COMMAND_ARGUMENTS")) {
  2759. std::string genCommandArguments = cmGeneratorExpression::Evaluate(
  2760. *commandArguments, this->LocalGenerator, config);
  2761. e1.WritePlatformConfigTag("LocalDebuggerCommandArguments", cond,
  2762. genCommandArguments);
  2763. }
  2764. }
  2765. }
  2766. }
  2767. void cmVisualStudio10TargetGenerator::OutputLinkIncremental(
  2768. Elem& e1, std::string const& configName)
  2769. {
  2770. if (!this->MSTools) {
  2771. return;
  2772. }
  2773. if (this->ProjectType == VsProjectType::csproj) {
  2774. return;
  2775. }
  2776. // static libraries and things greater than modules do not need
  2777. // to set this option
  2778. if (this->GeneratorTarget->GetType() == cmStateEnums::STATIC_LIBRARY ||
  2779. this->GeneratorTarget->GetType() > cmStateEnums::MODULE_LIBRARY) {
  2780. return;
  2781. }
  2782. Options& linkOptions = *(this->LinkOptions[configName]);
  2783. const std::string cond = this->CalcCondition(configName);
  2784. if (this->IPOEnabledConfigurations.count(configName) == 0) {
  2785. const char* incremental = linkOptions.GetFlag("LinkIncremental");
  2786. e1.WritePlatformConfigTag("LinkIncremental", cond,
  2787. (incremental ? incremental : "true"));
  2788. }
  2789. linkOptions.RemoveFlag("LinkIncremental");
  2790. const char* manifest = linkOptions.GetFlag("GenerateManifest");
  2791. e1.WritePlatformConfigTag("GenerateManifest", cond,
  2792. (manifest ? manifest : "true"));
  2793. linkOptions.RemoveFlag("GenerateManifest");
  2794. // Some link options belong here. Use them now and remove them so that
  2795. // WriteLinkOptions does not use them.
  2796. static const std::vector<std::string> flags{ "LinkDelaySign",
  2797. "LinkKeyFile" };
  2798. for (const std::string& flag : flags) {
  2799. if (const char* value = linkOptions.GetFlag(flag)) {
  2800. e1.WritePlatformConfigTag(flag, cond, value);
  2801. linkOptions.RemoveFlag(flag);
  2802. }
  2803. }
  2804. }
  2805. std::vector<std::string> cmVisualStudio10TargetGenerator::GetIncludes(
  2806. std::string const& config, std::string const& lang) const
  2807. {
  2808. std::vector<std::string> includes;
  2809. this->LocalGenerator->GetIncludeDirectories(includes, this->GeneratorTarget,
  2810. lang, config);
  2811. for (std::string& i : includes) {
  2812. ConvertToWindowsSlash(i);
  2813. }
  2814. return includes;
  2815. }
  2816. bool cmVisualStudio10TargetGenerator::ComputeClOptions()
  2817. {
  2818. for (std::string const& c : this->Configurations) {
  2819. if (!this->ComputeClOptions(c)) {
  2820. return false;
  2821. }
  2822. }
  2823. return true;
  2824. }
  2825. bool cmVisualStudio10TargetGenerator::ComputeClOptions(
  2826. std::string const& configName)
  2827. {
  2828. // much of this was copied from here:
  2829. // copied from cmLocalVisualStudio7Generator.cxx 805
  2830. // TODO: Integrate code below with cmLocalVisualStudio7Generator.
  2831. cmGlobalVisualStudio10Generator* gg = this->GlobalGenerator;
  2832. std::unique_ptr<Options> pOptions;
  2833. switch (this->ProjectType) {
  2834. case VsProjectType::vcxproj:
  2835. pOptions = cm::make_unique<Options>(
  2836. this->LocalGenerator, Options::Compiler, gg->GetClFlagTable());
  2837. break;
  2838. case VsProjectType::csproj:
  2839. pOptions =
  2840. cm::make_unique<Options>(this->LocalGenerator, Options::CSharpCompiler,
  2841. gg->GetCSharpFlagTable());
  2842. break;
  2843. default:
  2844. break;
  2845. }
  2846. Options& clOptions = *pOptions;
  2847. std::string flags;
  2848. const std::string& linkLanguage =
  2849. this->GeneratorTarget->GetLinkerLanguage(configName);
  2850. if (linkLanguage.empty()) {
  2851. cmSystemTools::Error(
  2852. "CMake can not determine linker language for target: " + this->Name);
  2853. return false;
  2854. }
  2855. // Choose a language whose flags to use for ClCompile.
  2856. static const char* clLangs[] = { "CXX", "C", "Fortran" };
  2857. std::string langForClCompile;
  2858. if (this->ProjectType == VsProjectType::csproj) {
  2859. langForClCompile = "CSharp";
  2860. } else if (cm::contains(clLangs, linkLanguage)) {
  2861. langForClCompile = linkLanguage;
  2862. } else {
  2863. std::set<std::string> languages;
  2864. this->GeneratorTarget->GetLanguages(languages, configName);
  2865. for (const char* l : clLangs) {
  2866. if (languages.count(l)) {
  2867. langForClCompile = l;
  2868. break;
  2869. }
  2870. }
  2871. }
  2872. this->LangForClCompile = langForClCompile;
  2873. if (!langForClCompile.empty()) {
  2874. this->LocalGenerator->AddLanguageFlags(flags, this->GeneratorTarget,
  2875. cmBuildStep::Compile,
  2876. langForClCompile, configName);
  2877. this->LocalGenerator->AddCompileOptions(flags, this->GeneratorTarget,
  2878. langForClCompile, configName);
  2879. }
  2880. // Put the IPO enabled configurations into a set.
  2881. if (this->GeneratorTarget->IsIPOEnabled(linkLanguage, configName)) {
  2882. this->IPOEnabledConfigurations.insert(configName);
  2883. }
  2884. // Check if ASan is enabled.
  2885. if (flags.find("/fsanitize=address") != std::string::npos ||
  2886. flags.find("-fsanitize=address") != std::string::npos) {
  2887. this->ASanEnabledConfigurations.insert(configName);
  2888. }
  2889. // Check if (lib)Fuzzer is enabled.
  2890. if (flags.find("/fsanitize=fuzzer") != std::string::npos ||
  2891. flags.find("-fsanitize=fuzzer") != std::string::npos) {
  2892. this->FuzzerEnabledConfigurations.insert(configName);
  2893. }
  2894. // Precompile Headers
  2895. std::string pchHeader =
  2896. this->GeneratorTarget->GetPchHeader(configName, linkLanguage);
  2897. if (this->MSTools && VsProjectType::vcxproj == this->ProjectType &&
  2898. pchHeader.empty()) {
  2899. clOptions.AddFlag("PrecompiledHeader", "NotUsing");
  2900. } else if (this->MSTools && VsProjectType::vcxproj == this->ProjectType &&
  2901. !pchHeader.empty()) {
  2902. clOptions.AddFlag("PrecompiledHeader", "Use");
  2903. clOptions.AddFlag("PrecompiledHeaderFile", pchHeader);
  2904. std::string pchFile =
  2905. this->GeneratorTarget->GetPchFile(configName, linkLanguage);
  2906. clOptions.AddFlag("PrecompiledHeaderOutputFile", pchFile);
  2907. }
  2908. // Get preprocessor definitions for this directory.
  2909. std::string defineFlags = this->Makefile->GetDefineFlags();
  2910. if (this->MSTools) {
  2911. if (this->ProjectType == VsProjectType::vcxproj) {
  2912. clOptions.FixExceptionHandlingDefault();
  2913. if (this->GlobalGenerator->GetVersion() >=
  2914. cmGlobalVisualStudioGenerator::VSVersion::VS15) {
  2915. // Toolsets that come with VS 2017 may now enable UseFullPaths
  2916. // by default and there is no negative /FC option that projects
  2917. // can use to switch it back. Older toolsets disable this by
  2918. // default anyway so this will not hurt them. If the project
  2919. // is using an explicit /FC option then parsing flags will
  2920. // replace this setting with "true" below.
  2921. clOptions.AddFlag("UseFullPaths", "false");
  2922. }
  2923. clOptions.AddFlag("AssemblerListingLocation", "$(IntDir)");
  2924. }
  2925. }
  2926. // check for managed C++ assembly compiler flag. This overrides any
  2927. // /clr* compiler flags which may be defined in the flags variable(s).
  2928. if (this->ProjectType != VsProjectType::csproj) {
  2929. // Warn if /clr was added manually. This should not be done
  2930. // anymore, because cmGeneratorTarget may not be aware that the
  2931. // target uses C++/CLI.
  2932. if (flags.find("/clr") != std::string::npos ||
  2933. flags.find("-clr") != std::string::npos ||
  2934. defineFlags.find("/clr") != std::string::npos ||
  2935. defineFlags.find("-clr") != std::string::npos) {
  2936. if (configName == this->Configurations[0]) {
  2937. std::string message = "For the target \"" +
  2938. this->GeneratorTarget->GetName() +
  2939. "\" the /clr compiler flag was added manually. " +
  2940. "Set usage of C++/CLI by setting COMMON_LANGUAGE_RUNTIME "
  2941. "target property.";
  2942. this->Makefile->IssueMessage(MessageType::WARNING, message);
  2943. }
  2944. }
  2945. if (cmValue clr =
  2946. this->GeneratorTarget->GetProperty("COMMON_LANGUAGE_RUNTIME")) {
  2947. std::string clrString = *clr;
  2948. if (!clrString.empty()) {
  2949. clrString = ":" + clrString;
  2950. }
  2951. flags += " /clr" + clrString;
  2952. }
  2953. }
  2954. // Get includes for this target
  2955. if (!this->LangForClCompile.empty()) {
  2956. auto includeList = this->GetIncludes(configName, this->LangForClCompile);
  2957. auto sysIncludeFlag = this->Makefile->GetDefinition(
  2958. cmStrCat("CMAKE_INCLUDE_SYSTEM_FLAG_", this->LangForClCompile));
  2959. if (sysIncludeFlag) {
  2960. bool gotOneSys = false;
  2961. for (auto i : includeList) {
  2962. cmSystemTools::ConvertToUnixSlashes(i);
  2963. if (this->GeneratorTarget->IsSystemIncludeDirectory(
  2964. i, configName, this->LangForClCompile)) {
  2965. auto flag = cmTrimWhitespace(*sysIncludeFlag);
  2966. if (this->MSTools) {
  2967. cmSystemTools::ReplaceString(flag, "-external:I", "/external:I");
  2968. }
  2969. clOptions.AppendFlagString("AdditionalOptions",
  2970. cmStrCat(flag, " \"", i, '"'));
  2971. gotOneSys = true;
  2972. } else {
  2973. clOptions.AddInclude(i);
  2974. }
  2975. }
  2976. if (gotOneSys) {
  2977. if (auto sysIncludeFlagWarning = this->Makefile->GetDefinition(
  2978. cmStrCat("_CMAKE_INCLUDE_SYSTEM_FLAG_", this->LangForClCompile,
  2979. "_WARNING"))) {
  2980. flags = cmStrCat(flags, ' ', *sysIncludeFlagWarning);
  2981. }
  2982. }
  2983. } else {
  2984. clOptions.AddIncludes(includeList);
  2985. }
  2986. }
  2987. clOptions.Parse(flags);
  2988. clOptions.Parse(defineFlags);
  2989. std::vector<std::string> targetDefines;
  2990. switch (this->ProjectType) {
  2991. case VsProjectType::vcxproj:
  2992. if (!langForClCompile.empty()) {
  2993. this->GeneratorTarget->GetCompileDefinitions(targetDefines, configName,
  2994. langForClCompile);
  2995. }
  2996. break;
  2997. case VsProjectType::csproj:
  2998. this->GeneratorTarget->GetCompileDefinitions(targetDefines, configName,
  2999. "CSharp");
  3000. cm::erase_if(targetDefines, [](std::string const& def) {
  3001. return def.find('=') != std::string::npos;
  3002. });
  3003. break;
  3004. default:
  3005. break;
  3006. }
  3007. clOptions.AddDefines(targetDefines);
  3008. if (this->ProjectType == VsProjectType::csproj) {
  3009. clOptions.AppendFlag("DefineConstants", targetDefines);
  3010. }
  3011. if (this->MSTools) {
  3012. clOptions.SetVerboseMakefile(
  3013. this->Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE"));
  3014. }
  3015. // Add C-specific flags expressible in a ClCompile meant for C++.
  3016. if (langForClCompile == "CXX") {
  3017. std::set<std::string> languages;
  3018. this->GeneratorTarget->GetLanguages(languages, configName);
  3019. if (languages.count("C")) {
  3020. std::string flagsC;
  3021. this->LocalGenerator->AddLanguageFlags(
  3022. flagsC, this->GeneratorTarget, cmBuildStep::Compile, "C", configName);
  3023. this->LocalGenerator->AddCompileOptions(flagsC, this->GeneratorTarget,
  3024. "C", configName);
  3025. Options optC(this->LocalGenerator, Options::Compiler,
  3026. gg->GetClFlagTable());
  3027. optC.Parse(flagsC);
  3028. if (const char* stdC = optC.GetFlag("LanguageStandard_C")) {
  3029. clOptions.AddFlag("LanguageStandard_C", stdC);
  3030. }
  3031. }
  3032. }
  3033. // Add a definition for the configuration name.
  3034. std::string configDefine = cmStrCat("CMAKE_INTDIR=\"", configName, '"');
  3035. clOptions.AddDefine(configDefine);
  3036. if (const std::string* exportMacro =
  3037. this->GeneratorTarget->GetExportMacro()) {
  3038. clOptions.AddDefine(*exportMacro);
  3039. }
  3040. if (this->MSTools) {
  3041. // If we have the VS_WINRT_COMPONENT set then force Compile as WinRT
  3042. if (this->GeneratorTarget->GetPropertyAsBool("VS_WINRT_COMPONENT")) {
  3043. clOptions.AddFlag("CompileAsWinRT", "true");
  3044. // For WinRT components, add the _WINRT_DLL define to produce a lib
  3045. if (this->GeneratorTarget->GetType() == cmStateEnums::SHARED_LIBRARY ||
  3046. this->GeneratorTarget->GetType() == cmStateEnums::MODULE_LIBRARY) {
  3047. clOptions.AddDefine("_WINRT_DLL");
  3048. }
  3049. } else if (this->GlobalGenerator->TargetsWindowsStore() ||
  3050. this->GlobalGenerator->TargetsWindowsPhone() ||
  3051. this->Makefile->IsOn("CMAKE_VS_WINRT_BY_DEFAULT")) {
  3052. if (!clOptions.IsWinRt()) {
  3053. clOptions.AddFlag("CompileAsWinRT", "false");
  3054. }
  3055. }
  3056. if (const char* winRT = clOptions.GetFlag("CompileAsWinRT")) {
  3057. if (cmIsOn(winRT)) {
  3058. this->TargetCompileAsWinRT = true;
  3059. }
  3060. }
  3061. }
  3062. if (this->ProjectType != VsProjectType::csproj &&
  3063. (clOptions.IsManaged() || clOptions.HasFlag("CLRSupport"))) {
  3064. this->Managed = true;
  3065. std::string managedType = clOptions.HasFlag("CompileAsManaged")
  3066. ? clOptions.GetFlag("CompileAsManaged")
  3067. : "Mixed";
  3068. if (managedType == "Safe" || managedType == "Pure") {
  3069. // force empty calling convention if safe clr is used
  3070. clOptions.AddFlag("CallingConvention", "");
  3071. }
  3072. // The default values of these flags are incompatible to
  3073. // managed assemblies. We have to force valid values if
  3074. // the target is a managed C++ target.
  3075. clOptions.AddFlag("ExceptionHandling", "Async");
  3076. clOptions.AddFlag("BasicRuntimeChecks", "Default");
  3077. }
  3078. if (this->ProjectType == VsProjectType::csproj) {
  3079. // /nowin32manifest overrides /win32manifest: parameter
  3080. if (clOptions.HasFlag("NoWin32Manifest")) {
  3081. clOptions.RemoveFlag("ApplicationManifest");
  3082. }
  3083. }
  3084. if (const char* s = clOptions.GetFlag("SpectreMitigation")) {
  3085. this->SpectreMitigation[configName] = s;
  3086. clOptions.RemoveFlag("SpectreMitigation");
  3087. }
  3088. // Remove any target-wide -TC or -TP flag added by the project.
  3089. // Such flags are unnecessary and break our model of language selection.
  3090. if (langForClCompile == "C" || langForClCompile == "CXX") {
  3091. clOptions.RemoveFlag("CompileAs");
  3092. }
  3093. this->ClOptions[configName] = std::move(pOptions);
  3094. return true;
  3095. }
  3096. void cmVisualStudio10TargetGenerator::WriteClOptions(
  3097. Elem& e1, std::string const& configName)
  3098. {
  3099. Options& clOptions = *(this->ClOptions[configName]);
  3100. if (this->ProjectType == VsProjectType::csproj) {
  3101. return;
  3102. }
  3103. Elem e2(e1, "ClCompile");
  3104. OptionsHelper oh(clOptions, e2);
  3105. oh.PrependInheritedString("AdditionalOptions");
  3106. oh.OutputAdditionalIncludeDirectories(this->LangForClCompile);
  3107. oh.OutputFlagMap();
  3108. oh.OutputPreprocessorDefinitions(this->LangForClCompile);
  3109. if (this->NsightTegra) {
  3110. if (cmValue processMax =
  3111. this->GeneratorTarget->GetProperty("ANDROID_PROCESS_MAX")) {
  3112. e2.Element("ProcessMax", *processMax);
  3113. }
  3114. }
  3115. if (this->Android) {
  3116. e2.Element("ObjectFileName", "$(IntDir)%(filename).o");
  3117. } else if (this->MSTools) {
  3118. cmsys::RegularExpression clangToolset("v[0-9]+_clang_.*");
  3119. const char* toolset = this->GlobalGenerator->GetPlatformToolset();
  3120. cmValue noCompileBatching =
  3121. this->GeneratorTarget->GetProperty("VS_NO_COMPILE_BATCHING");
  3122. if (noCompileBatching.IsOn() || (toolset && clangToolset.find(toolset))) {
  3123. e2.Element("ObjectFileName", "$(IntDir)%(filename).obj");
  3124. } else {
  3125. e2.Element("ObjectFileName", "$(IntDir)");
  3126. }
  3127. // If not in debug mode, write the DebugInformationFormat field
  3128. // without value so PDBs don't get generated uselessly. Each tag
  3129. // goes on its own line because Visual Studio corrects it this
  3130. // way when saving the project after CMake generates it.
  3131. if (!clOptions.IsDebug()) {
  3132. Elem e3(e2, "DebugInformationFormat");
  3133. e3.SetHasElements();
  3134. }
  3135. // Specify the compiler program database file if configured.
  3136. std::string pdb = this->GeneratorTarget->GetCompilePDBPath(configName);
  3137. if (!pdb.empty()) {
  3138. if (this->GlobalGenerator->IsCudaEnabled()) {
  3139. // CUDA does not quote paths with spaces correctly when forwarding
  3140. // this to the host compiler. Use a relative path to avoid spaces.
  3141. // FIXME: We can likely do this even when CUDA is not involved,
  3142. // but for now we will make a minimal change.
  3143. pdb = this->ConvertPath(pdb, true);
  3144. }
  3145. ConvertToWindowsSlash(pdb);
  3146. e2.Element("ProgramDataBaseFileName", pdb);
  3147. }
  3148. // add AdditionalUsingDirectories
  3149. if (this->AdditionalUsingDirectories.count(configName) > 0) {
  3150. std::string dirs;
  3151. for (auto u : this->AdditionalUsingDirectories[configName]) {
  3152. if (!dirs.empty()) {
  3153. dirs.append(";");
  3154. }
  3155. dirs.append(u);
  3156. }
  3157. e2.Element("AdditionalUsingDirectories", dirs);
  3158. }
  3159. }
  3160. }
  3161. bool cmVisualStudio10TargetGenerator::ComputeRcOptions()
  3162. {
  3163. for (std::string const& c : this->Configurations) {
  3164. if (!this->ComputeRcOptions(c)) {
  3165. return false;
  3166. }
  3167. }
  3168. return true;
  3169. }
  3170. bool cmVisualStudio10TargetGenerator::ComputeRcOptions(
  3171. std::string const& configName)
  3172. {
  3173. cmGlobalVisualStudio10Generator* gg = this->GlobalGenerator;
  3174. auto pOptions = cm::make_unique<Options>(
  3175. this->LocalGenerator, Options::ResourceCompiler, gg->GetRcFlagTable());
  3176. Options& rcOptions = *pOptions;
  3177. std::string CONFIG = cmSystemTools::UpperCase(configName);
  3178. std::string rcConfigFlagsVar = "CMAKE_RC_FLAGS_" + CONFIG;
  3179. std::string flags = this->Makefile->GetSafeDefinition("CMAKE_RC_FLAGS") +
  3180. " " + this->Makefile->GetSafeDefinition(rcConfigFlagsVar);
  3181. rcOptions.Parse(flags);
  3182. // For historical reasons, add the C preprocessor defines to RC.
  3183. Options& clOptions = *(this->ClOptions[configName]);
  3184. rcOptions.AddDefines(clOptions.GetDefines());
  3185. // Get includes for this target
  3186. rcOptions.AddIncludes(this->GetIncludes(configName, "RC"));
  3187. this->RcOptions[configName] = std::move(pOptions);
  3188. return true;
  3189. }
  3190. void cmVisualStudio10TargetGenerator::WriteRCOptions(
  3191. Elem& e1, std::string const& configName)
  3192. {
  3193. if (!this->MSTools) {
  3194. return;
  3195. }
  3196. Elem e2(e1, "ResourceCompile");
  3197. OptionsHelper rcOptions(*(this->RcOptions[configName]), e2);
  3198. rcOptions.OutputPreprocessorDefinitions("RC");
  3199. rcOptions.OutputAdditionalIncludeDirectories("RC");
  3200. rcOptions.PrependInheritedString("AdditionalOptions");
  3201. rcOptions.OutputFlagMap();
  3202. }
  3203. bool cmVisualStudio10TargetGenerator::ComputeCudaOptions()
  3204. {
  3205. if (!this->GlobalGenerator->IsCudaEnabled()) {
  3206. return true;
  3207. }
  3208. for (std::string const& c : this->Configurations) {
  3209. if (this->GeneratorTarget->IsLanguageUsed("CUDA", c) &&
  3210. !this->ComputeCudaOptions(c)) {
  3211. return false;
  3212. }
  3213. }
  3214. return true;
  3215. }
  3216. bool cmVisualStudio10TargetGenerator::ComputeCudaOptions(
  3217. std::string const& configName)
  3218. {
  3219. cmGlobalVisualStudio10Generator* gg = this->GlobalGenerator;
  3220. auto pOptions = cm::make_unique<Options>(
  3221. this->LocalGenerator, Options::CudaCompiler, gg->GetCudaFlagTable());
  3222. Options& cudaOptions = *pOptions;
  3223. auto cudaVersion = this->GlobalGenerator->GetPlatformToolsetCudaString();
  3224. // Get compile flags for CUDA in this directory.
  3225. std::string flags;
  3226. this->LocalGenerator->AddLanguageFlags(
  3227. flags, this->GeneratorTarget, cmBuildStep::Compile, "CUDA", configName);
  3228. this->LocalGenerator->AddCompileOptions(flags, this->GeneratorTarget, "CUDA",
  3229. configName);
  3230. // Get preprocessor definitions for this directory.
  3231. std::string defineFlags = this->Makefile->GetDefineFlags();
  3232. cudaOptions.Parse(flags);
  3233. cudaOptions.Parse(defineFlags);
  3234. cudaOptions.ParseFinish();
  3235. // If we haven't explicitly enabled GPU debug information
  3236. // explicitly disable it
  3237. if (!cudaOptions.HasFlag("GPUDebugInfo")) {
  3238. cudaOptions.AddFlag("GPUDebugInfo", "false");
  3239. }
  3240. // The extension on object libraries the CUDA gives isn't
  3241. // consistent with how MSVC generates object libraries for C+, so set
  3242. // the default to not have any extension
  3243. cudaOptions.AddFlag("CompileOut", "$(IntDir)%(Filename).obj");
  3244. if (this->GeneratorTarget->GetPropertyAsBool("CUDA_SEPARABLE_COMPILATION")) {
  3245. cudaOptions.AddFlag("GenerateRelocatableDeviceCode", "true");
  3246. }
  3247. bool notPtx = true;
  3248. if (this->GeneratorTarget->GetPropertyAsBool("CUDA_PTX_COMPILATION")) {
  3249. cudaOptions.AddFlag("NvccCompilation", "ptx");
  3250. // We drop the %(Extension) component as CMake expects all PTX files
  3251. // to not have the source file extension at all
  3252. cudaOptions.AddFlag("CompileOut", "$(IntDir)%(Filename).ptx");
  3253. notPtx = false;
  3254. if (cmSystemTools::VersionCompare(cmSystemTools::OP_GREATER_EQUAL,
  3255. cudaVersion, "9.0") &&
  3256. cmSystemTools::VersionCompare(cmSystemTools::OP_LESS, cudaVersion,
  3257. "11.5")) {
  3258. // The DriverApi flag before 11.5 ( verified back to 9.0 ) which controls
  3259. // PTX compilation doesn't propagate user defines causing
  3260. // target_compile_definitions to behave differently for VS +
  3261. // PTX compared to other generators so we patch the rules
  3262. // to normalize behavior
  3263. cudaOptions.AddFlag("DriverApiCommandLineTemplate",
  3264. "%(BaseCommandLineTemplate) [CompileOut] [FastMath] "
  3265. "[Defines] \"%(FullPath)\"");
  3266. }
  3267. }
  3268. if (notPtx &&
  3269. cmSystemTools::VersionCompareGreaterEq(
  3270. "8.0", this->GlobalGenerator->GetPlatformToolsetCudaString())) {
  3271. // Explicitly state that we want this file to be treated as a
  3272. // CUDA file no matter what the file extensions is
  3273. // This is only needed for < CUDA 9
  3274. cudaOptions.AppendFlagString("AdditionalOptions", "-x cu");
  3275. }
  3276. // Specify the compiler program database file if configured.
  3277. std::string pdb = this->GeneratorTarget->GetCompilePDBPath(configName);
  3278. if (!pdb.empty()) {
  3279. // CUDA does not make the directory if it is non-standard.
  3280. std::string const pdbDir = cmSystemTools::GetFilenamePath(pdb);
  3281. cmSystemTools::MakeDirectory(pdbDir);
  3282. if (cmSystemTools::VersionCompareGreaterEq(
  3283. "9.2", this->GlobalGenerator->GetPlatformToolsetCudaString())) {
  3284. // CUDA does not have a field for this and does not honor the
  3285. // ProgramDataBaseFileName field in ClCompile. Work around this
  3286. // limitation by creating the directory and passing the flag ourselves.
  3287. pdb = this->ConvertPath(pdb, true);
  3288. ConvertToWindowsSlash(pdb);
  3289. std::string const clFd = "-Xcompiler=\"-Fd\\\"" + pdb + "\\\"\"";
  3290. cudaOptions.AppendFlagString("AdditionalOptions", clFd);
  3291. }
  3292. }
  3293. // CUDA automatically passes the proper '--machine' flag to nvcc
  3294. // for the current architecture, but does not reflect this default
  3295. // in the user-visible IDE settings. Set it explicitly.
  3296. if (this->Platform == "x64") {
  3297. cudaOptions.AddFlag("TargetMachinePlatform", "64");
  3298. }
  3299. // Convert the host compiler options to the toolset's abstractions
  3300. // using a secondary flag table.
  3301. cudaOptions.ClearTables();
  3302. cudaOptions.AddTable(gg->GetCudaHostFlagTable());
  3303. cudaOptions.Reparse("AdditionalCompilerOptions");
  3304. // `CUDA 8.0.targets` places AdditionalCompilerOptions before nvcc!
  3305. // Pass them through -Xcompiler in AdditionalOptions instead.
  3306. if (const char* acoPtr = cudaOptions.GetFlag("AdditionalCompilerOptions")) {
  3307. std::string aco = acoPtr;
  3308. cudaOptions.RemoveFlag("AdditionalCompilerOptions");
  3309. if (!aco.empty()) {
  3310. aco = this->LocalGenerator->EscapeForShell(aco, false);
  3311. cudaOptions.AppendFlagString("AdditionalOptions", "-Xcompiler=" + aco);
  3312. }
  3313. }
  3314. cudaOptions.FixCudaCodeGeneration();
  3315. std::vector<std::string> targetDefines;
  3316. this->GeneratorTarget->GetCompileDefinitions(targetDefines, configName,
  3317. "CUDA");
  3318. cudaOptions.AddDefines(targetDefines);
  3319. // Add a definition for the configuration name.
  3320. std::string configDefine = cmStrCat("CMAKE_INTDIR=\"", configName, '"');
  3321. cudaOptions.AddDefine(configDefine);
  3322. if (const std::string* exportMacro =
  3323. this->GeneratorTarget->GetExportMacro()) {
  3324. cudaOptions.AddDefine(*exportMacro);
  3325. }
  3326. // Get includes for this target
  3327. cudaOptions.AddIncludes(this->GetIncludes(configName, "CUDA"));
  3328. cudaOptions.AddFlag("UseHostInclude", "false");
  3329. // Add runtime library selection flag.
  3330. std::string const& cudaRuntime =
  3331. this->GeneratorTarget->GetRuntimeLinkLibrary("CUDA", configName);
  3332. if (cudaRuntime == "STATIC") {
  3333. cudaOptions.AddFlag("CudaRuntime", "Static");
  3334. } else if (cudaRuntime == "SHARED") {
  3335. cudaOptions.AddFlag("CudaRuntime", "Shared");
  3336. } else if (cudaRuntime == "NONE") {
  3337. cudaOptions.AddFlag("CudaRuntime", "None");
  3338. }
  3339. this->CudaOptions[configName] = std::move(pOptions);
  3340. return true;
  3341. }
  3342. void cmVisualStudio10TargetGenerator::WriteCudaOptions(
  3343. Elem& e1, std::string const& configName)
  3344. {
  3345. if (!this->MSTools || !this->GlobalGenerator->IsCudaEnabled() ||
  3346. !this->GeneratorTarget->IsLanguageUsed("CUDA", configName)) {
  3347. return;
  3348. }
  3349. Elem e2(e1, "CudaCompile");
  3350. OptionsHelper cudaOptions(*(this->CudaOptions[configName]), e2);
  3351. cudaOptions.OutputAdditionalIncludeDirectories("CUDA");
  3352. cudaOptions.OutputPreprocessorDefinitions("CUDA");
  3353. cudaOptions.PrependInheritedString("AdditionalOptions");
  3354. cudaOptions.OutputFlagMap();
  3355. }
  3356. bool cmVisualStudio10TargetGenerator::ComputeCudaLinkOptions()
  3357. {
  3358. if (!this->GlobalGenerator->IsCudaEnabled()) {
  3359. return true;
  3360. }
  3361. for (std::string const& c : this->Configurations) {
  3362. if (!this->ComputeCudaLinkOptions(c)) {
  3363. return false;
  3364. }
  3365. }
  3366. return true;
  3367. }
  3368. bool cmVisualStudio10TargetGenerator::ComputeCudaLinkOptions(
  3369. std::string const& configName)
  3370. {
  3371. cmGlobalVisualStudio10Generator* gg = this->GlobalGenerator;
  3372. auto pOptions = cm::make_unique<Options>(
  3373. this->LocalGenerator, Options::CudaCompiler, gg->GetCudaFlagTable());
  3374. Options& cudaLinkOptions = *pOptions;
  3375. cmGeneratorTarget::DeviceLinkSetter setter(*this->GeneratorTarget);
  3376. // Determine if we need to do a device link
  3377. const bool doDeviceLinking = requireDeviceLinking(
  3378. *this->GeneratorTarget, *this->LocalGenerator, configName);
  3379. cudaLinkOptions.AddFlag("PerformDeviceLink",
  3380. doDeviceLinking ? "true" : "false");
  3381. // Add extra flags for device linking
  3382. cudaLinkOptions.AppendFlagString(
  3383. "AdditionalOptions",
  3384. this->Makefile->GetSafeDefinition("_CMAKE_CUDA_EXTRA_FLAGS"));
  3385. cudaLinkOptions.AppendFlagString(
  3386. "AdditionalOptions",
  3387. this->Makefile->GetSafeDefinition("_CMAKE_CUDA_EXTRA_DEVICE_LINK_FLAGS"));
  3388. std::vector<std::string> linkOpts;
  3389. std::string linkFlags;
  3390. this->GeneratorTarget->GetLinkOptions(linkOpts, configName, "CUDA");
  3391. // LINK_OPTIONS are escaped.
  3392. this->LocalGenerator->AppendCompileOptions(linkFlags, linkOpts);
  3393. cmComputeLinkInformation* pcli =
  3394. this->GeneratorTarget->GetLinkInformation(configName);
  3395. if (doDeviceLinking && pcli) {
  3396. cmLinkLineDeviceComputer computer(
  3397. this->LocalGenerator,
  3398. this->LocalGenerator->GetStateSnapshot().GetDirectory());
  3399. std::string ignored_;
  3400. this->LocalGenerator->GetDeviceLinkFlags(computer, configName, ignored_,
  3401. linkFlags, ignored_, ignored_,
  3402. this->GeneratorTarget);
  3403. this->LocalGenerator->AddLanguageFlagsForLinking(
  3404. linkFlags, this->GeneratorTarget, "CUDA", configName);
  3405. }
  3406. cudaLinkOptions.AppendFlagString("AdditionalOptions", linkFlags);
  3407. // For static libraries that have device linking enabled compute
  3408. // the libraries
  3409. if (this->GeneratorTarget->GetType() == cmStateEnums::STATIC_LIBRARY &&
  3410. doDeviceLinking) {
  3411. cmComputeLinkInformation& cli = *pcli;
  3412. cmLinkLineDeviceComputer computer(
  3413. this->LocalGenerator,
  3414. this->LocalGenerator->GetStateSnapshot().GetDirectory());
  3415. std::vector<BT<std::string>> btLibVec;
  3416. computer.ComputeLinkLibraries(cli, std::string{}, btLibVec);
  3417. std::vector<std::string> libVec;
  3418. for (auto const& item : btLibVec) {
  3419. libVec.emplace_back(item.Value);
  3420. }
  3421. cudaLinkOptions.AddFlag("AdditionalDependencies", libVec);
  3422. }
  3423. this->CudaLinkOptions[configName] = std::move(pOptions);
  3424. return true;
  3425. }
  3426. void cmVisualStudio10TargetGenerator::WriteCudaLinkOptions(
  3427. Elem& e1, std::string const& configName)
  3428. {
  3429. if (this->GeneratorTarget->GetType() > cmStateEnums::MODULE_LIBRARY) {
  3430. return;
  3431. }
  3432. if (!this->MSTools || !this->GlobalGenerator->IsCudaEnabled()) {
  3433. return;
  3434. }
  3435. Elem e2(e1, "CudaLink");
  3436. OptionsHelper cudaLinkOptions(*(this->CudaLinkOptions[configName]), e2);
  3437. cudaLinkOptions.OutputFlagMap();
  3438. }
  3439. bool cmVisualStudio10TargetGenerator::ComputeMarmasmOptions()
  3440. {
  3441. if (!this->GlobalGenerator->IsMarmasmEnabled()) {
  3442. return true;
  3443. }
  3444. for (std::string const& c : this->Configurations) {
  3445. if (!this->ComputeMarmasmOptions(c)) {
  3446. return false;
  3447. }
  3448. }
  3449. return true;
  3450. }
  3451. bool cmVisualStudio10TargetGenerator::ComputeMarmasmOptions(
  3452. std::string const& configName)
  3453. {
  3454. cmGlobalVisualStudio10Generator* gg = this->GlobalGenerator;
  3455. auto pOptions = cm::make_unique<Options>(
  3456. this->LocalGenerator, Options::MarmasmCompiler, gg->GetMarmasmFlagTable());
  3457. Options& marmasmOptions = *pOptions;
  3458. std::string flags;
  3459. this->LocalGenerator->AddLanguageFlags(flags, this->GeneratorTarget,
  3460. cmBuildStep::Compile, "ASM_MARMASM",
  3461. configName);
  3462. marmasmOptions.Parse(flags);
  3463. // Get includes for this target
  3464. marmasmOptions.AddIncludes(this->GetIncludes(configName, "ASM_MARMASM"));
  3465. this->MarmasmOptions[configName] = std::move(pOptions);
  3466. return true;
  3467. }
  3468. void cmVisualStudio10TargetGenerator::WriteMarmasmOptions(
  3469. Elem& e1, std::string const& configName)
  3470. {
  3471. if (!this->MSTools || !this->GlobalGenerator->IsMarmasmEnabled()) {
  3472. return;
  3473. }
  3474. Elem e2(e1, "MARMASM");
  3475. // Preprocessor definitions and includes are shared with clOptions.
  3476. OptionsHelper clOptions(*(this->ClOptions[configName]), e2);
  3477. clOptions.OutputPreprocessorDefinitions("ASM_MARMASM");
  3478. OptionsHelper marmasmOptions(*(this->MarmasmOptions[configName]), e2);
  3479. marmasmOptions.OutputAdditionalIncludeDirectories("ASM_MARMASM");
  3480. marmasmOptions.PrependInheritedString("AdditionalOptions");
  3481. marmasmOptions.OutputFlagMap();
  3482. }
  3483. bool cmVisualStudio10TargetGenerator::ComputeMasmOptions()
  3484. {
  3485. if (!this->GlobalGenerator->IsMasmEnabled()) {
  3486. return true;
  3487. }
  3488. for (std::string const& c : this->Configurations) {
  3489. if (!this->ComputeMasmOptions(c)) {
  3490. return false;
  3491. }
  3492. }
  3493. return true;
  3494. }
  3495. bool cmVisualStudio10TargetGenerator::ComputeMasmOptions(
  3496. std::string const& configName)
  3497. {
  3498. cmGlobalVisualStudio10Generator* gg = this->GlobalGenerator;
  3499. auto pOptions = cm::make_unique<Options>(
  3500. this->LocalGenerator, Options::MasmCompiler, gg->GetMasmFlagTable());
  3501. Options& masmOptions = *pOptions;
  3502. std::string flags;
  3503. this->LocalGenerator->AddLanguageFlags(flags, this->GeneratorTarget,
  3504. cmBuildStep::Compile, "ASM_MASM",
  3505. configName);
  3506. masmOptions.Parse(flags);
  3507. // Get includes for this target
  3508. masmOptions.AddIncludes(this->GetIncludes(configName, "ASM_MASM"));
  3509. this->MasmOptions[configName] = std::move(pOptions);
  3510. return true;
  3511. }
  3512. void cmVisualStudio10TargetGenerator::WriteMasmOptions(
  3513. Elem& e1, std::string const& configName)
  3514. {
  3515. if (!this->MSTools || !this->GlobalGenerator->IsMasmEnabled()) {
  3516. return;
  3517. }
  3518. Elem e2(e1, "MASM");
  3519. // Preprocessor definitions and includes are shared with clOptions.
  3520. OptionsHelper clOptions(*(this->ClOptions[configName]), e2);
  3521. clOptions.OutputPreprocessorDefinitions("ASM_MASM");
  3522. OptionsHelper masmOptions(*(this->MasmOptions[configName]), e2);
  3523. masmOptions.OutputAdditionalIncludeDirectories("ASM_MASM");
  3524. masmOptions.PrependInheritedString("AdditionalOptions");
  3525. masmOptions.OutputFlagMap();
  3526. }
  3527. bool cmVisualStudio10TargetGenerator::ComputeNasmOptions()
  3528. {
  3529. if (!this->GlobalGenerator->IsNasmEnabled()) {
  3530. return true;
  3531. }
  3532. for (std::string const& c : this->Configurations) {
  3533. if (!this->ComputeNasmOptions(c)) {
  3534. return false;
  3535. }
  3536. }
  3537. return true;
  3538. }
  3539. bool cmVisualStudio10TargetGenerator::ComputeNasmOptions(
  3540. std::string const& configName)
  3541. {
  3542. cmGlobalVisualStudio10Generator* gg = this->GlobalGenerator;
  3543. auto pOptions = cm::make_unique<Options>(
  3544. this->LocalGenerator, Options::NasmCompiler, gg->GetNasmFlagTable());
  3545. Options& nasmOptions = *pOptions;
  3546. std::string flags;
  3547. this->LocalGenerator->AddLanguageFlags(flags, this->GeneratorTarget,
  3548. cmBuildStep::Compile, "ASM_NASM",
  3549. configName);
  3550. flags += " -f";
  3551. flags += this->Makefile->GetSafeDefinition("CMAKE_ASM_NASM_OBJECT_FORMAT");
  3552. nasmOptions.Parse(flags);
  3553. // Get includes for this target
  3554. nasmOptions.AddIncludes(this->GetIncludes(configName, "ASM_NASM"));
  3555. this->NasmOptions[configName] = std::move(pOptions);
  3556. return true;
  3557. }
  3558. void cmVisualStudio10TargetGenerator::WriteNasmOptions(
  3559. Elem& e1, std::string const& configName)
  3560. {
  3561. if (!this->GlobalGenerator->IsNasmEnabled()) {
  3562. return;
  3563. }
  3564. Elem e2(e1, "NASM");
  3565. OptionsHelper nasmOptions(*(this->NasmOptions[configName]), e2);
  3566. nasmOptions.OutputAdditionalIncludeDirectories("ASM_NASM");
  3567. nasmOptions.OutputFlagMap();
  3568. nasmOptions.PrependInheritedString("AdditionalOptions");
  3569. nasmOptions.OutputPreprocessorDefinitions("ASM_NASM");
  3570. // Preprocessor definitions and includes are shared with clOptions.
  3571. OptionsHelper clOptions(*(this->ClOptions[configName]), e2);
  3572. clOptions.OutputPreprocessorDefinitions("ASM_NASM");
  3573. }
  3574. void cmVisualStudio10TargetGenerator::WriteLibOptions(
  3575. Elem& e1, std::string const& config)
  3576. {
  3577. if (this->GeneratorTarget->GetType() != cmStateEnums::STATIC_LIBRARY &&
  3578. this->GeneratorTarget->GetType() != cmStateEnums::OBJECT_LIBRARY) {
  3579. return;
  3580. }
  3581. const std::string& linkLanguage =
  3582. this->GeneratorTarget->GetLinkClosure(config)->LinkerLanguage;
  3583. std::string libflags;
  3584. this->LocalGenerator->GetStaticLibraryFlags(libflags, config, linkLanguage,
  3585. this->GeneratorTarget);
  3586. if (!libflags.empty()) {
  3587. Elem e2(e1, "Lib");
  3588. cmGlobalVisualStudio10Generator* gg = this->GlobalGenerator;
  3589. cmVS10GeneratorOptions libOptions(this->LocalGenerator,
  3590. cmVisualStudioGeneratorOptions::Linker,
  3591. gg->GetLibFlagTable(), this);
  3592. libOptions.Parse(libflags);
  3593. OptionsHelper oh(libOptions, e2);
  3594. oh.PrependInheritedString("AdditionalOptions");
  3595. oh.OutputFlagMap();
  3596. }
  3597. // We cannot generate metadata for static libraries. WindowsPhone
  3598. // and WindowsStore tools look at GenerateWindowsMetadata in the
  3599. // Link tool options even for static libraries.
  3600. if (this->GlobalGenerator->TargetsWindowsPhone() ||
  3601. this->GlobalGenerator->TargetsWindowsStore()) {
  3602. Elem e2(e1, "Link");
  3603. e2.Element("GenerateWindowsMetadata", "false");
  3604. }
  3605. }
  3606. void cmVisualStudio10TargetGenerator::WriteManifestOptions(
  3607. Elem& e1, std::string const& config)
  3608. {
  3609. if (this->GeneratorTarget->GetType() != cmStateEnums::EXECUTABLE &&
  3610. this->GeneratorTarget->GetType() != cmStateEnums::SHARED_LIBRARY &&
  3611. this->GeneratorTarget->GetType() != cmStateEnums::MODULE_LIBRARY) {
  3612. return;
  3613. }
  3614. std::vector<cmSourceFile const*> manifest_srcs;
  3615. this->GeneratorTarget->GetManifests(manifest_srcs, config);
  3616. cmValue dpiAware = this->GeneratorTarget->GetProperty("VS_DPI_AWARE");
  3617. if (!manifest_srcs.empty() || dpiAware) {
  3618. Elem e2(e1, "Manifest");
  3619. if (!manifest_srcs.empty()) {
  3620. std::ostringstream oss;
  3621. for (cmSourceFile const* mi : manifest_srcs) {
  3622. std::string m = this->ConvertPath(mi->GetFullPath(), false);
  3623. ConvertToWindowsSlash(m);
  3624. oss << m << ";";
  3625. }
  3626. e2.Element("AdditionalManifestFiles", oss.str());
  3627. }
  3628. if (dpiAware) {
  3629. if (*dpiAware == "PerMonitor") {
  3630. e2.Element("EnableDpiAwareness", "PerMonitorHighDPIAware");
  3631. } else if (cmIsOn(*dpiAware)) {
  3632. e2.Element("EnableDpiAwareness", "true");
  3633. } else if (cmIsOff(*dpiAware)) {
  3634. e2.Element("EnableDpiAwareness", "false");
  3635. } else {
  3636. cmSystemTools::Error("Bad parameter for VS_DPI_AWARE: " + *dpiAware);
  3637. }
  3638. }
  3639. }
  3640. }
  3641. void cmVisualStudio10TargetGenerator::WriteAntBuildOptions(
  3642. Elem& e1, std::string const& configName)
  3643. {
  3644. // Look through the sources for AndroidManifest.xml and use
  3645. // its location as the root source directory.
  3646. std::string rootDir = this->LocalGenerator->GetCurrentSourceDirectory();
  3647. {
  3648. for (cmGeneratorTarget::AllConfigSource const& source :
  3649. this->GeneratorTarget->GetAllConfigSources()) {
  3650. if (source.Kind == cmGeneratorTarget::SourceKindExtra &&
  3651. "androidmanifest.xml" ==
  3652. cmSystemTools::LowerCase(source.Source->GetLocation().GetName())) {
  3653. rootDir = source.Source->GetLocation().GetDirectory();
  3654. break;
  3655. }
  3656. }
  3657. }
  3658. // Tell MSBuild to launch Ant.
  3659. Elem e2(e1, "AntBuild");
  3660. {
  3661. std::string antBuildPath = rootDir;
  3662. ConvertToWindowsSlash(antBuildPath);
  3663. e2.Element("AntBuildPath", antBuildPath);
  3664. }
  3665. if (this->GeneratorTarget->GetPropertyAsBool("ANDROID_SKIP_ANT_STEP")) {
  3666. e2.Element("SkipAntStep", "true");
  3667. }
  3668. if (this->GeneratorTarget->GetPropertyAsBool("ANDROID_PROGUARD")) {
  3669. e2.Element("EnableProGuard", "true");
  3670. }
  3671. if (cmValue proGuardConfigLocation =
  3672. this->GeneratorTarget->GetProperty("ANDROID_PROGUARD_CONFIG_PATH")) {
  3673. e2.Element("ProGuardConfigLocation", *proGuardConfigLocation);
  3674. }
  3675. if (cmValue securePropertiesLocation =
  3676. this->GeneratorTarget->GetProperty("ANDROID_SECURE_PROPS_PATH")) {
  3677. e2.Element("SecurePropertiesLocation", *securePropertiesLocation);
  3678. }
  3679. if (cmValue nativeLibDirectoriesExpression =
  3680. this->GeneratorTarget->GetProperty("ANDROID_NATIVE_LIB_DIRECTORIES")) {
  3681. std::string nativeLibDirs = cmGeneratorExpression::Evaluate(
  3682. *nativeLibDirectoriesExpression, this->LocalGenerator, configName);
  3683. e2.Element("NativeLibDirectories", nativeLibDirs);
  3684. }
  3685. if (cmValue nativeLibDependenciesExpression =
  3686. this->GeneratorTarget->GetProperty(
  3687. "ANDROID_NATIVE_LIB_DEPENDENCIES")) {
  3688. std::string nativeLibDeps = cmGeneratorExpression::Evaluate(
  3689. *nativeLibDependenciesExpression, this->LocalGenerator, configName);
  3690. e2.Element("NativeLibDependencies", nativeLibDeps);
  3691. }
  3692. if (cmValue javaSourceDir =
  3693. this->GeneratorTarget->GetProperty("ANDROID_JAVA_SOURCE_DIR")) {
  3694. e2.Element("JavaSourceDir", *javaSourceDir);
  3695. }
  3696. if (cmValue jarDirectoriesExpression =
  3697. this->GeneratorTarget->GetProperty("ANDROID_JAR_DIRECTORIES")) {
  3698. std::string jarDirectories = cmGeneratorExpression::Evaluate(
  3699. *jarDirectoriesExpression, this->LocalGenerator, configName);
  3700. e2.Element("JarDirectories", jarDirectories);
  3701. }
  3702. if (cmValue jarDeps =
  3703. this->GeneratorTarget->GetProperty("ANDROID_JAR_DEPENDENCIES")) {
  3704. e2.Element("JarDependencies", *jarDeps);
  3705. }
  3706. if (cmValue assetsDirectories =
  3707. this->GeneratorTarget->GetProperty("ANDROID_ASSETS_DIRECTORIES")) {
  3708. e2.Element("AssetsDirectories", *assetsDirectories);
  3709. }
  3710. {
  3711. std::string manifest_xml = rootDir + "/AndroidManifest.xml";
  3712. ConvertToWindowsSlash(manifest_xml);
  3713. e2.Element("AndroidManifestLocation", manifest_xml);
  3714. }
  3715. if (cmValue antAdditionalOptions =
  3716. this->GeneratorTarget->GetProperty("ANDROID_ANT_ADDITIONAL_OPTIONS")) {
  3717. e2.Element("AdditionalOptions",
  3718. *antAdditionalOptions + " %(AdditionalOptions)");
  3719. }
  3720. }
  3721. bool cmVisualStudio10TargetGenerator::ComputeLinkOptions()
  3722. {
  3723. if (this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE ||
  3724. this->GeneratorTarget->GetType() == cmStateEnums::SHARED_LIBRARY ||
  3725. this->GeneratorTarget->GetType() == cmStateEnums::MODULE_LIBRARY) {
  3726. for (std::string const& c : this->Configurations) {
  3727. if (!this->ComputeLinkOptions(c)) {
  3728. return false;
  3729. }
  3730. }
  3731. }
  3732. return true;
  3733. }
  3734. bool cmVisualStudio10TargetGenerator::ComputeLinkOptions(
  3735. std::string const& config)
  3736. {
  3737. cmGlobalVisualStudio10Generator* gg = this->GlobalGenerator;
  3738. auto pOptions = cm::make_unique<Options>(
  3739. this->LocalGenerator, Options::Linker, gg->GetLinkFlagTable(), this);
  3740. Options& linkOptions = *pOptions;
  3741. cmGeneratorTarget::LinkClosure const* linkClosure =
  3742. this->GeneratorTarget->GetLinkClosure(config);
  3743. const std::string& linkLanguage = linkClosure->LinkerLanguage;
  3744. if (linkLanguage.empty()) {
  3745. cmSystemTools::Error(
  3746. "CMake can not determine linker language for target: " + this->Name);
  3747. return false;
  3748. }
  3749. std::string CONFIG = cmSystemTools::UpperCase(config);
  3750. const char* linkType = "SHARED";
  3751. if (this->GeneratorTarget->GetType() == cmStateEnums::MODULE_LIBRARY) {
  3752. linkType = "MODULE";
  3753. }
  3754. if (this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE) {
  3755. linkType = "EXE";
  3756. }
  3757. std::string flags;
  3758. std::string linkFlagVarBase = cmStrCat("CMAKE_", linkType, "_LINKER_FLAGS");
  3759. flags += " ";
  3760. flags += this->Makefile->GetRequiredDefinition(linkFlagVarBase);
  3761. std::string linkFlagVar = linkFlagVarBase + "_" + CONFIG;
  3762. flags += " ";
  3763. flags += this->Makefile->GetRequiredDefinition(linkFlagVar);
  3764. cmValue targetLinkFlags = this->GeneratorTarget->GetProperty("LINK_FLAGS");
  3765. if (targetLinkFlags) {
  3766. flags += " ";
  3767. flags += *targetLinkFlags;
  3768. }
  3769. std::string flagsProp = cmStrCat("LINK_FLAGS_", CONFIG);
  3770. if (cmValue flagsConfig = this->GeneratorTarget->GetProperty(flagsProp)) {
  3771. flags += " ";
  3772. flags += *flagsConfig;
  3773. }
  3774. std::vector<std::string> opts;
  3775. this->GeneratorTarget->GetLinkOptions(opts, config, linkLanguage);
  3776. // LINK_OPTIONS are escaped.
  3777. this->LocalGenerator->AppendCompileOptions(flags, opts);
  3778. cmComputeLinkInformation* pcli =
  3779. this->GeneratorTarget->GetLinkInformation(config);
  3780. if (!pcli) {
  3781. cmSystemTools::Error(
  3782. "CMake can not compute cmComputeLinkInformation for target: " +
  3783. this->Name);
  3784. return false;
  3785. }
  3786. cmComputeLinkInformation& cli = *pcli;
  3787. std::vector<std::string> libVec;
  3788. std::vector<std::string> vsTargetVec;
  3789. this->AddLibraries(cli, libVec, vsTargetVec, config);
  3790. std::string standardLibsVar =
  3791. cmStrCat("CMAKE_", linkLanguage, "_STANDARD_LIBRARIES");
  3792. std::string const& libs = this->Makefile->GetSafeDefinition(standardLibsVar);
  3793. cmSystemTools::ParseWindowsCommandLine(libs.c_str(), libVec);
  3794. linkOptions.AddFlag("AdditionalDependencies", libVec);
  3795. // Populate TargetsFileAndConfigsVec
  3796. for (std::string const& ti : vsTargetVec) {
  3797. this->AddTargetsFileAndConfigPair(ti, config);
  3798. }
  3799. std::vector<std::string> const& ldirs = cli.GetDirectories();
  3800. std::vector<std::string> linkDirs;
  3801. for (std::string const& d : ldirs) {
  3802. // first just full path
  3803. linkDirs.push_back(d);
  3804. // next path with configuration type Debug, Release, etc
  3805. linkDirs.push_back(d + "/$(Configuration)");
  3806. }
  3807. linkDirs.push_back("%(AdditionalLibraryDirectories)");
  3808. linkOptions.AddFlag("AdditionalLibraryDirectories", linkDirs);
  3809. cmGeneratorTarget::Names targetNames;
  3810. if (this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE) {
  3811. targetNames = this->GeneratorTarget->GetExecutableNames(config);
  3812. } else {
  3813. targetNames = this->GeneratorTarget->GetLibraryNames(config);
  3814. }
  3815. if (this->MSTools) {
  3816. if (this->GeneratorTarget->IsWin32Executable(config)) {
  3817. if (this->GlobalGenerator->TargetsWindowsCE()) {
  3818. linkOptions.AddFlag("SubSystem", "WindowsCE");
  3819. if (this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE) {
  3820. if (this->ClOptions[config]->UsingUnicode()) {
  3821. linkOptions.AddFlag("EntryPointSymbol", "wWinMainCRTStartup");
  3822. } else {
  3823. linkOptions.AddFlag("EntryPointSymbol", "WinMainCRTStartup");
  3824. }
  3825. }
  3826. } else {
  3827. linkOptions.AddFlag("SubSystem", "Windows");
  3828. }
  3829. } else {
  3830. if (this->GlobalGenerator->TargetsWindowsCE()) {
  3831. linkOptions.AddFlag("SubSystem", "WindowsCE");
  3832. if (this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE) {
  3833. if (this->ClOptions[config]->UsingUnicode()) {
  3834. linkOptions.AddFlag("EntryPointSymbol", "mainWCRTStartup");
  3835. } else {
  3836. linkOptions.AddFlag("EntryPointSymbol", "mainACRTStartup");
  3837. }
  3838. }
  3839. } else {
  3840. linkOptions.AddFlag("SubSystem", "Console");
  3841. };
  3842. }
  3843. if (cmValue stackVal = this->Makefile->GetDefinition(
  3844. "CMAKE_" + linkLanguage + "_STACK_SIZE")) {
  3845. linkOptions.AddFlag("StackReserveSize", *stackVal);
  3846. }
  3847. linkOptions.AddFlag("GenerateDebugInformation", "false");
  3848. std::string pdb = cmStrCat(this->GeneratorTarget->GetPDBDirectory(config),
  3849. '/', targetNames.PDB);
  3850. if (!targetNames.ImportLibrary.empty()) {
  3851. std::string imLib =
  3852. cmStrCat(this->GeneratorTarget->GetDirectory(
  3853. config, cmStateEnums::ImportLibraryArtifact),
  3854. '/', targetNames.ImportLibrary);
  3855. linkOptions.AddFlag("ImportLibrary", imLib);
  3856. }
  3857. linkOptions.AddFlag("ProgramDataBaseFile", pdb);
  3858. // A Windows Runtime component uses internal .NET metadata,
  3859. // so does not have an import library.
  3860. if (this->GeneratorTarget->GetPropertyAsBool("VS_WINRT_COMPONENT") &&
  3861. this->GeneratorTarget->GetType() != cmStateEnums::EXECUTABLE) {
  3862. linkOptions.AddFlag("GenerateWindowsMetadata", "true");
  3863. } else if (this->GlobalGenerator->TargetsWindowsPhone() ||
  3864. this->GlobalGenerator->TargetsWindowsStore()) {
  3865. // WindowsPhone and WindowsStore components are in an app container
  3866. // and produce WindowsMetadata. If we are not producing a WINRT
  3867. // component, then do not generate the metadata here.
  3868. linkOptions.AddFlag("GenerateWindowsMetadata", "false");
  3869. }
  3870. if (this->GlobalGenerator->TargetsWindowsPhone() &&
  3871. this->GlobalGenerator->GetSystemVersion() == "8.0") {
  3872. // WindowsPhone 8.0 does not have ole32.
  3873. linkOptions.AppendFlag("IgnoreSpecificDefaultLibraries", "ole32.lib");
  3874. }
  3875. } else if (this->NsightTegra) {
  3876. linkOptions.AddFlag("SoName", targetNames.SharedObject);
  3877. }
  3878. linkOptions.Parse(flags);
  3879. linkOptions.FixManifestUACFlags();
  3880. if (this->MSTools) {
  3881. cmGeneratorTarget::ModuleDefinitionInfo const* mdi =
  3882. this->GeneratorTarget->GetModuleDefinitionInfo(config);
  3883. if (mdi && !mdi->DefFile.empty()) {
  3884. linkOptions.AddFlag("ModuleDefinitionFile", mdi->DefFile);
  3885. }
  3886. linkOptions.AppendFlag("IgnoreSpecificDefaultLibraries",
  3887. "%(IgnoreSpecificDefaultLibraries)");
  3888. }
  3889. // VS 2015 without all updates has a v140 toolset whose
  3890. // GenerateDebugInformation expects No/Debug instead of false/true.
  3891. if (gg->GetPlatformToolsetNeedsDebugEnum()) {
  3892. if (const char* debug = linkOptions.GetFlag("GenerateDebugInformation")) {
  3893. if (strcmp(debug, "false") == 0) {
  3894. linkOptions.AddFlag("GenerateDebugInformation", "No");
  3895. } else if (strcmp(debug, "true") == 0) {
  3896. linkOptions.AddFlag("GenerateDebugInformation", "Debug");
  3897. }
  3898. }
  3899. }
  3900. // Managed code cannot be linked with /DEBUG:FASTLINK
  3901. if (this->Managed) {
  3902. if (const char* debug = linkOptions.GetFlag("GenerateDebugInformation")) {
  3903. if (strcmp(debug, "DebugFastLink") == 0) {
  3904. linkOptions.AddFlag("GenerateDebugInformation", "Debug");
  3905. }
  3906. }
  3907. }
  3908. this->LinkOptions[config] = std::move(pOptions);
  3909. return true;
  3910. }
  3911. bool cmVisualStudio10TargetGenerator::ComputeLibOptions()
  3912. {
  3913. if (this->GeneratorTarget->GetType() == cmStateEnums::STATIC_LIBRARY) {
  3914. for (std::string const& c : this->Configurations) {
  3915. if (!this->ComputeLibOptions(c)) {
  3916. return false;
  3917. }
  3918. }
  3919. }
  3920. return true;
  3921. }
  3922. bool cmVisualStudio10TargetGenerator::ComputeLibOptions(
  3923. std::string const& config)
  3924. {
  3925. cmComputeLinkInformation* pcli =
  3926. this->GeneratorTarget->GetLinkInformation(config);
  3927. if (!pcli) {
  3928. cmSystemTools::Error(
  3929. "CMake can not compute cmComputeLinkInformation for target: " +
  3930. this->Name);
  3931. return false;
  3932. }
  3933. cmComputeLinkInformation& cli = *pcli;
  3934. using ItemVector = cmComputeLinkInformation::ItemVector;
  3935. const ItemVector& libs = cli.GetItems();
  3936. for (cmComputeLinkInformation::Item const& l : libs) {
  3937. if (l.IsPath == cmComputeLinkInformation::ItemIsPath::Yes &&
  3938. cmVS10IsTargetsFile(l.Value.Value)) {
  3939. std::string path =
  3940. this->LocalGenerator->MaybeRelativeToCurBinDir(l.Value.Value);
  3941. ConvertToWindowsSlash(path);
  3942. this->AddTargetsFileAndConfigPair(path, config);
  3943. }
  3944. }
  3945. return true;
  3946. }
  3947. void cmVisualStudio10TargetGenerator::WriteLinkOptions(
  3948. Elem& e1, std::string const& config)
  3949. {
  3950. if (this->GeneratorTarget->GetType() == cmStateEnums::STATIC_LIBRARY ||
  3951. this->GeneratorTarget->GetType() > cmStateEnums::MODULE_LIBRARY) {
  3952. return;
  3953. }
  3954. if (this->ProjectType == VsProjectType::csproj) {
  3955. return;
  3956. }
  3957. {
  3958. Elem e2(e1, "Link");
  3959. OptionsHelper linkOptions(*(this->LinkOptions[config]), e2);
  3960. linkOptions.PrependInheritedString("AdditionalOptions");
  3961. linkOptions.OutputFlagMap();
  3962. }
  3963. if (!this->GlobalGenerator->NeedLinkLibraryDependencies(
  3964. this->GeneratorTarget)) {
  3965. Elem e2(e1, "ProjectReference");
  3966. e2.Element("LinkLibraryDependencies", "false");
  3967. }
  3968. }
  3969. void cmVisualStudio10TargetGenerator::AddLibraries(
  3970. const cmComputeLinkInformation& cli, std::vector<std::string>& libVec,
  3971. std::vector<std::string>& vsTargetVec, const std::string& config)
  3972. {
  3973. using ItemVector = cmComputeLinkInformation::ItemVector;
  3974. ItemVector const& libs = cli.GetItems();
  3975. for (cmComputeLinkInformation::Item const& l : libs) {
  3976. if (l.Target) {
  3977. auto managedType = l.Target->GetManagedType(config);
  3978. if (managedType != cmGeneratorTarget::ManagedType::Native &&
  3979. this->GeneratorTarget->GetManagedType(config) !=
  3980. cmGeneratorTarget::ManagedType::Native &&
  3981. l.Target->IsImported() &&
  3982. l.Target->GetType() != cmStateEnums::INTERFACE_LIBRARY) {
  3983. auto location = l.Target->GetFullPath(config);
  3984. if (!location.empty()) {
  3985. ConvertToWindowsSlash(location);
  3986. switch (this->ProjectType) {
  3987. case VsProjectType::csproj:
  3988. // If the target we want to "link" to is an imported managed
  3989. // target and this is a C# project, we add a hint reference. This
  3990. // reference is written to project file in
  3991. // WriteDotNetReferences().
  3992. this->DotNetHintReferences[config].push_back(
  3993. DotNetHintReference(l.Target->GetName(), location));
  3994. break;
  3995. case VsProjectType::vcxproj:
  3996. // Add path of assembly to list of using-directories, so the
  3997. // managed assembly can be used by '#using <assembly.dll>' in
  3998. // code.
  3999. this->AdditionalUsingDirectories[config].insert(
  4000. cmSystemTools::GetFilenamePath(location));
  4001. break;
  4002. default:
  4003. // In .proj files, we wouldn't be referencing libraries.
  4004. break;
  4005. }
  4006. }
  4007. }
  4008. // Do not allow C# targets to be added to the LIB listing. LIB files are
  4009. // used for linking C++ dependencies. C# libraries do not have lib files.
  4010. // Instead, they compile down to C# reference libraries (DLL files). The
  4011. // `<ProjectReference>` elements added to the vcxproj are enough for the
  4012. // IDE to deduce the DLL file required by other C# projects that need its
  4013. // reference library.
  4014. if (managedType == cmGeneratorTarget::ManagedType::Managed) {
  4015. continue;
  4016. }
  4017. }
  4018. if (l.IsPath == cmComputeLinkInformation::ItemIsPath::Yes) {
  4019. std::string path =
  4020. this->LocalGenerator->MaybeRelativeToCurBinDir(l.Value.Value);
  4021. ConvertToWindowsSlash(path);
  4022. if (cmVS10IsTargetsFile(l.Value.Value)) {
  4023. vsTargetVec.push_back(path);
  4024. } else {
  4025. libVec.push_back(l.HasFeature() ? l.GetFormattedItem(path).Value
  4026. : path);
  4027. }
  4028. } else if (!l.Target ||
  4029. l.Target->GetType() != cmStateEnums::INTERFACE_LIBRARY) {
  4030. libVec.push_back(l.Value.Value);
  4031. }
  4032. }
  4033. }
  4034. void cmVisualStudio10TargetGenerator::AddTargetsFileAndConfigPair(
  4035. std::string const& targetsFile, std::string const& config)
  4036. {
  4037. for (TargetsFileAndConfigs& i : this->TargetsFileAndConfigsVec) {
  4038. if (cmSystemTools::ComparePath(targetsFile, i.File)) {
  4039. if (!cm::contains(i.Configs, config)) {
  4040. i.Configs.push_back(config);
  4041. }
  4042. return;
  4043. }
  4044. }
  4045. TargetsFileAndConfigs entry;
  4046. entry.File = targetsFile;
  4047. entry.Configs.push_back(config);
  4048. this->TargetsFileAndConfigsVec.push_back(entry);
  4049. }
  4050. void cmVisualStudio10TargetGenerator::WriteMidlOptions(
  4051. Elem& e1, std::string const& configName)
  4052. {
  4053. if (!this->MSTools) {
  4054. return;
  4055. }
  4056. if (this->ProjectType == VsProjectType::csproj) {
  4057. return;
  4058. }
  4059. if (this->GeneratorTarget->GetType() > cmStateEnums::UTILITY) {
  4060. return;
  4061. }
  4062. // This processes *any* of the .idl files specified in the project's file
  4063. // list (and passed as the item metadata %(Filename) expressing the rule
  4064. // input filename) into output files at the per-config *build* dir
  4065. // ($(IntDir)) each.
  4066. //
  4067. // IOW, this MIDL section is intended to provide a fully generic syntax
  4068. // content suitable for most cases (read: if you get errors, then it's quite
  4069. // probable that the error is on your side of the .idl setup).
  4070. //
  4071. // Also, note that the marked-as-generated _i.c file in the Visual Studio
  4072. // generator case needs to be referred to as $(IntDir)\foo_i.c at the
  4073. // project's file list, otherwise the compiler-side processing won't pick it
  4074. // up (for non-directory form, it ends up looking in project binary dir
  4075. // only). Perhaps there's something to be done to make this more automatic
  4076. // on the CMake side?
  4077. std::vector<std::string> const includes =
  4078. this->GetIncludes(configName, "MIDL");
  4079. std::ostringstream oss;
  4080. for (std::string const& i : includes) {
  4081. oss << i << ";";
  4082. }
  4083. oss << "%(AdditionalIncludeDirectories)";
  4084. Elem e2(e1, "Midl");
  4085. e2.Element("AdditionalIncludeDirectories", oss.str());
  4086. e2.Element("OutputDirectory", "$(ProjectDir)/$(IntDir)");
  4087. e2.Element("HeaderFileName", "%(Filename).h");
  4088. e2.Element("TypeLibraryName", "%(Filename).tlb");
  4089. e2.Element("InterfaceIdentifierFileName", "%(Filename)_i.c");
  4090. e2.Element("ProxyFileName", "%(Filename)_p.c");
  4091. }
  4092. void cmVisualStudio10TargetGenerator::WriteItemDefinitionGroups(Elem& e0)
  4093. {
  4094. if (this->ProjectType == VsProjectType::csproj) {
  4095. return;
  4096. }
  4097. for (const std::string& c : this->Configurations) {
  4098. Elem e1(e0, "ItemDefinitionGroup");
  4099. e1.Attribute("Condition", this->CalcCondition(c));
  4100. // output cl compile flags <ClCompile></ClCompile>
  4101. if (this->GeneratorTarget->GetType() <= cmStateEnums::OBJECT_LIBRARY) {
  4102. this->WriteClOptions(e1, c);
  4103. // output rc compile flags <ResourceCompile></ResourceCompile>
  4104. this->WriteRCOptions(e1, c);
  4105. this->WriteCudaOptions(e1, c);
  4106. this->WriteMarmasmOptions(e1, c);
  4107. this->WriteMasmOptions(e1, c);
  4108. this->WriteNasmOptions(e1, c);
  4109. }
  4110. // output midl flags <Midl></Midl>
  4111. this->WriteMidlOptions(e1, c);
  4112. // write events
  4113. if (this->ProjectType != VsProjectType::csproj) {
  4114. this->WriteEvents(e1, c);
  4115. }
  4116. // output link flags <Link></Link>
  4117. this->WriteLinkOptions(e1, c);
  4118. this->WriteCudaLinkOptions(e1, c);
  4119. // output lib flags <Lib></Lib>
  4120. this->WriteLibOptions(e1, c);
  4121. // output manifest flags <Manifest></Manifest>
  4122. this->WriteManifestOptions(e1, c);
  4123. if (this->NsightTegra &&
  4124. this->GeneratorTarget->Target->IsAndroidGuiExecutable()) {
  4125. this->WriteAntBuildOptions(e1, c);
  4126. }
  4127. }
  4128. }
  4129. void cmVisualStudio10TargetGenerator::WriteEvents(
  4130. Elem& e1, std::string const& configName)
  4131. {
  4132. bool addedPrelink = false;
  4133. cmGeneratorTarget::ModuleDefinitionInfo const* mdi =
  4134. this->GeneratorTarget->GetModuleDefinitionInfo(configName);
  4135. if (mdi && mdi->DefFileGenerated) {
  4136. addedPrelink = true;
  4137. std::vector<cmCustomCommand> commands =
  4138. this->GeneratorTarget->GetPreLinkCommands();
  4139. this->GlobalGenerator->AddSymbolExportCommand(this->GeneratorTarget,
  4140. commands, configName);
  4141. this->WriteEvent(e1, "PreLinkEvent", commands, configName);
  4142. }
  4143. if (!addedPrelink) {
  4144. this->WriteEvent(e1, "PreLinkEvent",
  4145. this->GeneratorTarget->GetPreLinkCommands(), configName);
  4146. }
  4147. this->WriteEvent(e1, "PreBuildEvent",
  4148. this->GeneratorTarget->GetPreBuildCommands(), configName);
  4149. this->WriteEvent(e1, "PostBuildEvent",
  4150. this->GeneratorTarget->GetPostBuildCommands(), configName);
  4151. }
  4152. void cmVisualStudio10TargetGenerator::WriteEvent(
  4153. Elem& e1, const std::string& name,
  4154. std::vector<cmCustomCommand> const& commands, std::string const& configName)
  4155. {
  4156. if (commands.empty()) {
  4157. return;
  4158. }
  4159. cmLocalVisualStudio7Generator* lg = this->LocalGenerator;
  4160. std::string script;
  4161. const char* pre = "";
  4162. std::string comment;
  4163. bool stdPipesUTF8 = false;
  4164. for (cmCustomCommand const& cc : commands) {
  4165. cmCustomCommandGenerator ccg(cc, configName, lg);
  4166. if (!ccg.HasOnlyEmptyCommandLines()) {
  4167. comment += pre;
  4168. comment += lg->ConstructComment(ccg);
  4169. script += pre;
  4170. pre = "\n";
  4171. script += lg->ConstructScript(ccg);
  4172. stdPipesUTF8 = stdPipesUTF8 || cc.GetStdPipesUTF8();
  4173. }
  4174. }
  4175. if (!script.empty()) {
  4176. script += lg->FinishConstructScript(this->ProjectType);
  4177. }
  4178. comment = cmVS10EscapeComment(comment);
  4179. if (this->ProjectType != VsProjectType::csproj) {
  4180. Elem e2(e1, name);
  4181. if (stdPipesUTF8) {
  4182. this->WriteStdOutEncodingUtf8(e2);
  4183. }
  4184. e2.Element("Message", comment);
  4185. e2.Element("Command", script);
  4186. } else {
  4187. std::string strippedComment = comment;
  4188. strippedComment.erase(
  4189. std::remove(strippedComment.begin(), strippedComment.end(), '\t'),
  4190. strippedComment.end());
  4191. std::ostringstream oss;
  4192. if (!comment.empty() && !strippedComment.empty()) {
  4193. oss << "echo " << comment << "\n";
  4194. }
  4195. oss << script << "\n";
  4196. e1.Element(name, oss.str());
  4197. }
  4198. }
  4199. void cmVisualStudio10TargetGenerator::WriteProjectReferences(Elem& e0)
  4200. {
  4201. cmGlobalGenerator::TargetDependSet const& unordered =
  4202. this->GlobalGenerator->GetTargetDirectDepends(this->GeneratorTarget);
  4203. using OrderedTargetDependSet =
  4204. cmGlobalVisualStudioGenerator::OrderedTargetDependSet;
  4205. OrderedTargetDependSet depends(unordered, CMAKE_CHECK_BUILD_SYSTEM_TARGET);
  4206. Elem e1(e0, "ItemGroup");
  4207. e1.SetHasElements();
  4208. for (cmGeneratorTarget const* dt : depends) {
  4209. if (!dt->IsInBuildSystem()) {
  4210. continue;
  4211. }
  4212. // skip fortran targets as they can not be processed by MSBuild
  4213. // the only reference will be in the .sln file
  4214. if (this->GlobalGenerator->TargetIsFortranOnly(dt)) {
  4215. continue;
  4216. }
  4217. cmLocalGenerator* lg = dt->GetLocalGenerator();
  4218. std::string name = dt->GetName();
  4219. std::string path;
  4220. if (cmValue p = dt->GetProperty("EXTERNAL_MSPROJECT")) {
  4221. path = *p;
  4222. } else {
  4223. path = cmStrCat(lg->GetCurrentBinaryDirectory(), '/', dt->GetName(),
  4224. computeProjectFileExtension(dt));
  4225. }
  4226. ConvertToWindowsSlash(path);
  4227. Elem e2(e1, "ProjectReference");
  4228. e2.Attribute("Include", path);
  4229. e2.Element("Project", "{" + this->GlobalGenerator->GetGUID(name) + "}");
  4230. e2.Element("Name", name);
  4231. this->WriteDotNetReferenceCustomTags(e2, name);
  4232. if (dt->IsCSharpOnly() || cmHasLiteralSuffix(path, "csproj")) {
  4233. e2.Element("SkipGetTargetFrameworkProperties", "true");
  4234. }
  4235. // Don't reference targets that don't produce any output.
  4236. else if (this->Configurations.empty() ||
  4237. dt->GetManagedType(this->Configurations[0]) ==
  4238. cmGeneratorTarget::ManagedType::Undefined) {
  4239. e2.Element("ReferenceOutputAssembly", "false");
  4240. e2.Element("CopyToOutputDirectory", "Never");
  4241. }
  4242. }
  4243. }
  4244. void cmVisualStudio10TargetGenerator::WritePlatformExtensions(Elem& e1)
  4245. {
  4246. // This only applies to Windows 10 apps
  4247. if (this->GlobalGenerator->TargetsWindowsStore() &&
  4248. cmHasLiteralPrefix(this->GlobalGenerator->GetSystemVersion(), "10.0")) {
  4249. cmValue desktopExtensionsVersion =
  4250. this->GeneratorTarget->GetProperty("VS_DESKTOP_EXTENSIONS_VERSION");
  4251. if (desktopExtensionsVersion) {
  4252. this->WriteSinglePlatformExtension(e1, "WindowsDesktop",
  4253. *desktopExtensionsVersion);
  4254. }
  4255. cmValue mobileExtensionsVersion =
  4256. this->GeneratorTarget->GetProperty("VS_MOBILE_EXTENSIONS_VERSION");
  4257. if (mobileExtensionsVersion) {
  4258. this->WriteSinglePlatformExtension(e1, "WindowsMobile",
  4259. *mobileExtensionsVersion);
  4260. }
  4261. }
  4262. }
  4263. void cmVisualStudio10TargetGenerator::WriteSinglePlatformExtension(
  4264. Elem& e1, std::string const& extension, std::string const& version)
  4265. {
  4266. const std::string s = "$([Microsoft.Build.Utilities.ToolLocationHelper]"
  4267. "::GetPlatformExtensionSDKLocation(`" +
  4268. extension + ", Version=" + version +
  4269. "`, $(TargetPlatformIdentifier), $(TargetPlatformVersion), null, "
  4270. "$(ExtensionSDKDirectoryRoot), null))"
  4271. "\\DesignTime\\CommonConfiguration\\Neutral\\" +
  4272. extension + ".props";
  4273. Elem e2(e1, "Import");
  4274. e2.Attribute("Project", s);
  4275. e2.Attribute("Condition", "exists('" + s + "')");
  4276. }
  4277. void cmVisualStudio10TargetGenerator::WriteSDKReferences(Elem& e0)
  4278. {
  4279. std::vector<std::string> sdkReferences;
  4280. std::unique_ptr<Elem> spe1;
  4281. if (cmValue vsSDKReferences =
  4282. this->GeneratorTarget->GetProperty("VS_SDK_REFERENCES")) {
  4283. cmExpandList(*vsSDKReferences, sdkReferences);
  4284. spe1 = cm::make_unique<Elem>(e0, "ItemGroup");
  4285. for (std::string const& ri : sdkReferences) {
  4286. Elem(*spe1, "SDKReference").Attribute("Include", ri);
  4287. }
  4288. }
  4289. // This only applies to Windows 10 apps
  4290. if (this->GlobalGenerator->TargetsWindowsStore() &&
  4291. cmHasLiteralPrefix(this->GlobalGenerator->GetSystemVersion(), "10.0")) {
  4292. cmValue desktopExtensionsVersion =
  4293. this->GeneratorTarget->GetProperty("VS_DESKTOP_EXTENSIONS_VERSION");
  4294. cmValue mobileExtensionsVersion =
  4295. this->GeneratorTarget->GetProperty("VS_MOBILE_EXTENSIONS_VERSION");
  4296. cmValue iotExtensionsVersion =
  4297. this->GeneratorTarget->GetProperty("VS_IOT_EXTENSIONS_VERSION");
  4298. if (desktopExtensionsVersion || mobileExtensionsVersion ||
  4299. iotExtensionsVersion) {
  4300. if (!spe1) {
  4301. spe1 = cm::make_unique<Elem>(e0, "ItemGroup");
  4302. }
  4303. if (desktopExtensionsVersion) {
  4304. this->WriteSingleSDKReference(*spe1, "WindowsDesktop",
  4305. *desktopExtensionsVersion);
  4306. }
  4307. if (mobileExtensionsVersion) {
  4308. this->WriteSingleSDKReference(*spe1, "WindowsMobile",
  4309. *mobileExtensionsVersion);
  4310. }
  4311. if (iotExtensionsVersion) {
  4312. this->WriteSingleSDKReference(*spe1, "WindowsIoT",
  4313. *iotExtensionsVersion);
  4314. }
  4315. }
  4316. }
  4317. }
  4318. void cmVisualStudio10TargetGenerator::WriteSingleSDKReference(
  4319. Elem& e1, std::string const& extension, std::string const& version)
  4320. {
  4321. Elem(e1, "SDKReference")
  4322. .Attribute("Include", extension + ", Version=" + version);
  4323. }
  4324. void cmVisualStudio10TargetGenerator::WriteWinRTPackageCertificateKeyFile(
  4325. Elem& e0)
  4326. {
  4327. if ((this->GlobalGenerator->TargetsWindowsStore() ||
  4328. this->GlobalGenerator->TargetsWindowsPhone()) &&
  4329. (cmStateEnums::EXECUTABLE == this->GeneratorTarget->GetType())) {
  4330. std::string pfxFile;
  4331. for (cmGeneratorTarget::AllConfigSource const& source :
  4332. this->GeneratorTarget->GetAllConfigSources()) {
  4333. if (source.Kind == cmGeneratorTarget::SourceKindCertificate) {
  4334. pfxFile = this->ConvertPath(source.Source->GetFullPath(), false);
  4335. ConvertToWindowsSlash(pfxFile);
  4336. break;
  4337. }
  4338. }
  4339. if (this->IsMissingFiles &&
  4340. !(this->GlobalGenerator->TargetsWindowsPhone() &&
  4341. this->GlobalGenerator->GetSystemVersion() == "8.0")) {
  4342. // Move the manifest to a project directory to avoid clashes
  4343. std::string artifactDir =
  4344. this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
  4345. ConvertToWindowsSlash(artifactDir);
  4346. Elem e1(e0, "PropertyGroup");
  4347. e1.Element("AppxPackageArtifactsDir", artifactDir + "\\");
  4348. std::string resourcePriFile =
  4349. this->DefaultArtifactDir + "/resources.pri";
  4350. ConvertToWindowsSlash(resourcePriFile);
  4351. e1.Element("ProjectPriFullPath", resourcePriFile);
  4352. // If we are missing files and we don't have a certificate and
  4353. // aren't targeting WP8.0, add a default certificate
  4354. if (pfxFile.empty()) {
  4355. std::string templateFolder =
  4356. cmSystemTools::GetCMakeRoot() + "/Templates/Windows";
  4357. pfxFile = this->DefaultArtifactDir + "/Windows_TemporaryKey.pfx";
  4358. cmSystemTools::CopyAFile(templateFolder + "/Windows_TemporaryKey.pfx",
  4359. pfxFile, false);
  4360. ConvertToWindowsSlash(pfxFile);
  4361. this->AddedFiles.push_back(pfxFile);
  4362. this->AddedDefaultCertificate = true;
  4363. }
  4364. e1.Element("PackageCertificateKeyFile", pfxFile);
  4365. std::string thumb = cmSystemTools::ComputeCertificateThumbprint(pfxFile);
  4366. if (!thumb.empty()) {
  4367. e1.Element("PackageCertificateThumbprint", thumb);
  4368. }
  4369. } else if (!pfxFile.empty()) {
  4370. Elem e1(e0, "PropertyGroup");
  4371. e1.Element("PackageCertificateKeyFile", pfxFile);
  4372. std::string thumb = cmSystemTools::ComputeCertificateThumbprint(pfxFile);
  4373. if (!thumb.empty()) {
  4374. e1.Element("PackageCertificateThumbprint", thumb);
  4375. }
  4376. }
  4377. }
  4378. }
  4379. void cmVisualStudio10TargetGenerator::ClassifyAllConfigSources()
  4380. {
  4381. for (cmGeneratorTarget::AllConfigSource const& source :
  4382. this->GeneratorTarget->GetAllConfigSources()) {
  4383. this->ClassifyAllConfigSource(source);
  4384. }
  4385. }
  4386. void cmVisualStudio10TargetGenerator::ClassifyAllConfigSource(
  4387. cmGeneratorTarget::AllConfigSource const& acs)
  4388. {
  4389. switch (acs.Kind) {
  4390. case cmGeneratorTarget::SourceKindResx: {
  4391. // Build and save the name of the corresponding .h file
  4392. // This relationship will be used later when building the project files.
  4393. // Both names would have been auto generated from Visual Studio
  4394. // where the user supplied the file name and Visual Studio
  4395. // appended the suffix.
  4396. std::string resx = acs.Source->ResolveFullPath();
  4397. std::string hFileName = resx.substr(0, resx.find_last_of('.')) + ".h";
  4398. this->ExpectedResxHeaders.insert(hFileName);
  4399. } break;
  4400. case cmGeneratorTarget::SourceKindXaml: {
  4401. // Build and save the name of the corresponding .h and .cpp file
  4402. // This relationship will be used later when building the project files.
  4403. // Both names would have been auto generated from Visual Studio
  4404. // where the user supplied the file name and Visual Studio
  4405. // appended the suffix.
  4406. std::string xaml = acs.Source->ResolveFullPath();
  4407. std::string hFileName = xaml + ".h";
  4408. std::string cppFileName = xaml + ".cpp";
  4409. this->ExpectedXamlHeaders.insert(hFileName);
  4410. this->ExpectedXamlSources.insert(cppFileName);
  4411. } break;
  4412. default:
  4413. break;
  4414. }
  4415. }
  4416. bool cmVisualStudio10TargetGenerator::IsResxHeader(
  4417. const std::string& headerFile)
  4418. {
  4419. return this->ExpectedResxHeaders.count(headerFile) > 0;
  4420. }
  4421. bool cmVisualStudio10TargetGenerator::IsXamlHeader(
  4422. const std::string& headerFile)
  4423. {
  4424. return this->ExpectedXamlHeaders.count(headerFile) > 0;
  4425. }
  4426. bool cmVisualStudio10TargetGenerator::IsXamlSource(
  4427. const std::string& sourceFile)
  4428. {
  4429. return this->ExpectedXamlSources.count(sourceFile) > 0;
  4430. }
  4431. void cmVisualStudio10TargetGenerator::WriteApplicationTypeSettings(Elem& e1)
  4432. {
  4433. cmGlobalVisualStudio10Generator* gg = this->GlobalGenerator;
  4434. bool isAppContainer = false;
  4435. bool const isWindowsPhone = this->GlobalGenerator->TargetsWindowsPhone();
  4436. bool const isWindowsStore = this->GlobalGenerator->TargetsWindowsStore();
  4437. bool const isAndroid = this->GlobalGenerator->TargetsAndroid();
  4438. std::string const& rev = this->GlobalGenerator->GetApplicationTypeRevision();
  4439. if (isWindowsPhone || isWindowsStore) {
  4440. e1.Element("ApplicationType",
  4441. (isWindowsPhone ? "Windows Phone" : "Windows Store"));
  4442. e1.Element("DefaultLanguage", "en-US");
  4443. if (rev == "10.0") {
  4444. e1.Element("ApplicationTypeRevision", rev);
  4445. // Visual Studio 14.0 is necessary for building 10.0 apps
  4446. e1.Element("MinimumVisualStudioVersion", "14.0");
  4447. if (this->GeneratorTarget->GetType() < cmStateEnums::UTILITY) {
  4448. isAppContainer = true;
  4449. }
  4450. } else if (rev == "8.1") {
  4451. e1.Element("ApplicationTypeRevision", rev);
  4452. // Visual Studio 12.0 is necessary for building 8.1 apps
  4453. e1.Element("MinimumVisualStudioVersion", "12.0");
  4454. if (this->GeneratorTarget->GetType() < cmStateEnums::UTILITY) {
  4455. isAppContainer = true;
  4456. }
  4457. } else if (rev == "8.0") {
  4458. e1.Element("ApplicationTypeRevision", rev);
  4459. // Visual Studio 11.0 is necessary for building 8.0 apps
  4460. e1.Element("MinimumVisualStudioVersion", "11.0");
  4461. if (isWindowsStore &&
  4462. this->GeneratorTarget->GetType() < cmStateEnums::UTILITY) {
  4463. isAppContainer = true;
  4464. } else if (isWindowsPhone &&
  4465. this->GeneratorTarget->GetType() ==
  4466. cmStateEnums::EXECUTABLE) {
  4467. e1.Element("XapOutputs", "true");
  4468. e1.Element("XapFilename",
  4469. this->Name + "_$(Configuration)_$(Platform).xap");
  4470. }
  4471. }
  4472. } else if (isAndroid) {
  4473. e1.Element("ApplicationType", "Android");
  4474. e1.Element("ApplicationTypeRevision",
  4475. gg->GetAndroidApplicationTypeRevision());
  4476. }
  4477. if (isAppContainer) {
  4478. e1.Element("AppContainerApplication", "true");
  4479. } else if (!isAndroid) {
  4480. if (this->Platform == "ARM64") {
  4481. e1.Element("WindowsSDKDesktopARM64Support", "true");
  4482. } else if (this->Platform == "ARM") {
  4483. e1.Element("WindowsSDKDesktopARMSupport", "true");
  4484. }
  4485. }
  4486. std::string const& targetPlatformVersion =
  4487. gg->GetWindowsTargetPlatformVersion();
  4488. if (!targetPlatformVersion.empty()) {
  4489. e1.Element("WindowsTargetPlatformVersion", targetPlatformVersion);
  4490. }
  4491. cmValue targetPlatformMinVersion = this->GeneratorTarget->GetProperty(
  4492. "VS_WINDOWS_TARGET_PLATFORM_MIN_VERSION");
  4493. if (targetPlatformMinVersion) {
  4494. e1.Element("WindowsTargetPlatformMinVersion", *targetPlatformMinVersion);
  4495. } else if (isWindowsStore && rev == "10.0") {
  4496. // If the min version is not set, then use the TargetPlatformVersion
  4497. if (!targetPlatformVersion.empty()) {
  4498. e1.Element("WindowsTargetPlatformMinVersion", targetPlatformVersion);
  4499. }
  4500. }
  4501. // Added IoT Startup Task support
  4502. if (this->GeneratorTarget->GetPropertyAsBool("VS_IOT_STARTUP_TASK")) {
  4503. e1.Element("ContainsStartupTask", "true");
  4504. }
  4505. }
  4506. void cmVisualStudio10TargetGenerator::VerifyNecessaryFiles()
  4507. {
  4508. // For Windows and Windows Phone executables, we will assume that if a
  4509. // manifest is not present that we need to add all the necessary files
  4510. if (this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE) {
  4511. std::vector<cmGeneratorTarget::AllConfigSource> manifestSources =
  4512. this->GeneratorTarget->GetAllConfigSources(
  4513. cmGeneratorTarget::SourceKindAppManifest);
  4514. std::string const& v = this->GlobalGenerator->GetSystemVersion();
  4515. if (this->GlobalGenerator->TargetsWindowsPhone()) {
  4516. if (v == "8.0") {
  4517. // Look through the sources for WMAppManifest.xml
  4518. bool foundManifest = false;
  4519. for (cmGeneratorTarget::AllConfigSource const& source :
  4520. this->GeneratorTarget->GetAllConfigSources()) {
  4521. if (source.Kind == cmGeneratorTarget::SourceKindExtra &&
  4522. "wmappmanifest.xml" ==
  4523. cmSystemTools::LowerCase(
  4524. source.Source->GetLocation().GetName())) {
  4525. foundManifest = true;
  4526. break;
  4527. }
  4528. }
  4529. if (!foundManifest) {
  4530. this->IsMissingFiles = true;
  4531. }
  4532. } else if (v == "8.1") {
  4533. if (manifestSources.empty()) {
  4534. this->IsMissingFiles = true;
  4535. }
  4536. }
  4537. } else if (this->GlobalGenerator->TargetsWindowsStore()) {
  4538. if (manifestSources.empty()) {
  4539. if (v == "8.0") {
  4540. this->IsMissingFiles = true;
  4541. } else if (v == "8.1" || cmHasLiteralPrefix(v, "10.0")) {
  4542. this->IsMissingFiles = true;
  4543. }
  4544. }
  4545. }
  4546. }
  4547. }
  4548. void cmVisualStudio10TargetGenerator::WriteMissingFiles(Elem& e1)
  4549. {
  4550. std::string const& v = this->GlobalGenerator->GetSystemVersion();
  4551. if (this->GlobalGenerator->TargetsWindowsPhone()) {
  4552. if (v == "8.0") {
  4553. this->WriteMissingFilesWP80(e1);
  4554. } else if (v == "8.1") {
  4555. this->WriteMissingFilesWP81(e1);
  4556. }
  4557. } else if (this->GlobalGenerator->TargetsWindowsStore()) {
  4558. if (v == "8.0") {
  4559. this->WriteMissingFilesWS80(e1);
  4560. } else if (v == "8.1") {
  4561. this->WriteMissingFilesWS81(e1);
  4562. } else if (cmHasLiteralPrefix(v, "10.0")) {
  4563. this->WriteMissingFilesWS10_0(e1);
  4564. }
  4565. }
  4566. }
  4567. void cmVisualStudio10TargetGenerator::WriteMissingFilesWP80(Elem& e1)
  4568. {
  4569. std::string templateFolder =
  4570. cmSystemTools::GetCMakeRoot() + "/Templates/Windows";
  4571. // For WP80, the manifest needs to be in the same folder as the project
  4572. // this can cause an overwrite problem if projects aren't organized in
  4573. // folders
  4574. std::string manifestFile =
  4575. this->LocalGenerator->GetCurrentBinaryDirectory() + "/WMAppManifest.xml";
  4576. std::string artifactDir =
  4577. this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
  4578. ConvertToWindowsSlash(artifactDir);
  4579. std::string artifactDirXML = cmVS10EscapeXML(artifactDir);
  4580. std::string targetNameXML =
  4581. cmVS10EscapeXML(this->GeneratorTarget->GetName());
  4582. cmGeneratedFileStream fout(manifestFile);
  4583. fout.SetCopyIfDifferent(true);
  4584. /* clang-format off */
  4585. fout <<
  4586. "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
  4587. "<Deployment"
  4588. " xmlns=\"http://schemas.microsoft.com/windowsphone/2012/deployment\""
  4589. " AppPlatformVersion=\"8.0\">\n"
  4590. "\t<DefaultLanguage xmlns=\"\" code=\"en-US\"/>\n"
  4591. "\t<App xmlns=\"\" ProductID=\"{" << this->GUID << "}\""
  4592. " Title=\"CMake Test Program\" RuntimeType=\"Modern Native\""
  4593. " Version=\"1.0.0.0\" Genre=\"apps.normal\" Author=\"CMake\""
  4594. " Description=\"Default CMake App\" Publisher=\"CMake\""
  4595. " PublisherID=\"{" << this->GUID << "}\">\n"
  4596. "\t\t<IconPath IsRelative=\"true\" IsResource=\"false\">"
  4597. << artifactDirXML << "\\ApplicationIcon.png</IconPath>\n"
  4598. "\t\t<Capabilities/>\n"
  4599. "\t\t<Tasks>\n"
  4600. "\t\t\t<DefaultTask Name=\"_default\""
  4601. " ImagePath=\"" << targetNameXML << ".exe\" ImageParams=\"\" />\n"
  4602. "\t\t</Tasks>\n"
  4603. "\t\t<Tokens>\n"
  4604. "\t\t\t<PrimaryToken TokenID=\"" << targetNameXML << "Token\""
  4605. " TaskName=\"_default\">\n"
  4606. "\t\t\t\t<TemplateFlip>\n"
  4607. "\t\t\t\t\t<SmallImageURI IsRelative=\"true\" IsResource=\"false\">"
  4608. << artifactDirXML << "\\SmallLogo.png</SmallImageURI>\n"
  4609. "\t\t\t\t\t<Count>0</Count>\n"
  4610. "\t\t\t\t\t<BackgroundImageURI IsRelative=\"true\" IsResource=\"false\">"
  4611. << artifactDirXML << "\\Logo.png</BackgroundImageURI>\n"
  4612. "\t\t\t\t</TemplateFlip>\n"
  4613. "\t\t\t</PrimaryToken>\n"
  4614. "\t\t</Tokens>\n"
  4615. "\t\t<ScreenResolutions>\n"
  4616. "\t\t\t<ScreenResolution Name=\"ID_RESOLUTION_WVGA\" />\n"
  4617. "\t\t</ScreenResolutions>\n"
  4618. "\t</App>\n"
  4619. "</Deployment>\n";
  4620. /* clang-format on */
  4621. std::string sourceFile = this->ConvertPath(manifestFile, false);
  4622. ConvertToWindowsSlash(sourceFile);
  4623. {
  4624. Elem e2(e1, "Xml");
  4625. e2.Attribute("Include", sourceFile);
  4626. e2.Element("SubType", "Designer");
  4627. }
  4628. this->AddedFiles.push_back(sourceFile);
  4629. std::string smallLogo = this->DefaultArtifactDir + "/SmallLogo.png";
  4630. cmSystemTools::CopyAFile(templateFolder + "/SmallLogo.png", smallLogo,
  4631. false);
  4632. ConvertToWindowsSlash(smallLogo);
  4633. Elem(e1, "Image").Attribute("Include", smallLogo);
  4634. this->AddedFiles.push_back(smallLogo);
  4635. std::string logo = this->DefaultArtifactDir + "/Logo.png";
  4636. cmSystemTools::CopyAFile(templateFolder + "/Logo.png", logo, false);
  4637. ConvertToWindowsSlash(logo);
  4638. Elem(e1, "Image").Attribute("Include", logo);
  4639. this->AddedFiles.push_back(logo);
  4640. std::string applicationIcon =
  4641. this->DefaultArtifactDir + "/ApplicationIcon.png";
  4642. cmSystemTools::CopyAFile(templateFolder + "/ApplicationIcon.png",
  4643. applicationIcon, false);
  4644. ConvertToWindowsSlash(applicationIcon);
  4645. Elem(e1, "Image").Attribute("Include", applicationIcon);
  4646. this->AddedFiles.push_back(applicationIcon);
  4647. }
  4648. void cmVisualStudio10TargetGenerator::WriteMissingFilesWP81(Elem& e1)
  4649. {
  4650. std::string manifestFile =
  4651. this->DefaultArtifactDir + "/package.appxManifest";
  4652. std::string artifactDir =
  4653. this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
  4654. ConvertToWindowsSlash(artifactDir);
  4655. std::string artifactDirXML = cmVS10EscapeXML(artifactDir);
  4656. std::string targetNameXML =
  4657. cmVS10EscapeXML(this->GeneratorTarget->GetName());
  4658. cmGeneratedFileStream fout(manifestFile);
  4659. fout.SetCopyIfDifferent(true);
  4660. /* clang-format off */
  4661. fout <<
  4662. "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
  4663. "<Package xmlns=\"http://schemas.microsoft.com/appx/2010/manifest\""
  4664. " xmlns:m2=\"http://schemas.microsoft.com/appx/2013/manifest\""
  4665. " xmlns:mp=\"http://schemas.microsoft.com/appx/2014/phone/manifest\">\n"
  4666. "\t<Identity Name=\"" << this->GUID << "\" Publisher=\"CN=CMake\""
  4667. " Version=\"1.0.0.0\" />\n"
  4668. "\t<mp:PhoneIdentity PhoneProductId=\"" << this->GUID << "\""
  4669. " PhonePublisherId=\"00000000-0000-0000-0000-000000000000\"/>\n"
  4670. "\t<Properties>\n"
  4671. "\t\t<DisplayName>" << targetNameXML << "</DisplayName>\n"
  4672. "\t\t<PublisherDisplayName>CMake</PublisherDisplayName>\n"
  4673. "\t\t<Logo>" << artifactDirXML << "\\StoreLogo.png</Logo>\n"
  4674. "\t</Properties>\n"
  4675. "\t<Prerequisites>\n"
  4676. "\t\t<OSMinVersion>6.3.1</OSMinVersion>\n"
  4677. "\t\t<OSMaxVersionTested>6.3.1</OSMaxVersionTested>\n"
  4678. "\t</Prerequisites>\n"
  4679. "\t<Resources>\n"
  4680. "\t\t<Resource Language=\"x-generate\" />\n"
  4681. "\t</Resources>\n"
  4682. "\t<Applications>\n"
  4683. "\t\t<Application Id=\"App\""
  4684. " Executable=\"" << targetNameXML << ".exe\""
  4685. " EntryPoint=\"" << targetNameXML << ".App\">\n"
  4686. "\t\t\t<m2:VisualElements\n"
  4687. "\t\t\t\tDisplayName=\"" << targetNameXML << "\"\n"
  4688. "\t\t\t\tDescription=\"" << targetNameXML << "\"\n"
  4689. "\t\t\t\tBackgroundColor=\"#336699\"\n"
  4690. "\t\t\t\tForegroundText=\"light\"\n"
  4691. "\t\t\t\tSquare150x150Logo=\"" << artifactDirXML << "\\Logo.png\"\n"
  4692. "\t\t\t\tSquare30x30Logo=\"" << artifactDirXML << "\\SmallLogo.png\">\n"
  4693. "\t\t\t\t<m2:DefaultTile ShortName=\"" << targetNameXML << "\">\n"
  4694. "\t\t\t\t\t<m2:ShowNameOnTiles>\n"
  4695. "\t\t\t\t\t\t<m2:ShowOn Tile=\"square150x150Logo\" />\n"
  4696. "\t\t\t\t\t</m2:ShowNameOnTiles>\n"
  4697. "\t\t\t\t</m2:DefaultTile>\n"
  4698. "\t\t\t\t<m2:SplashScreen"
  4699. " Image=\"" << artifactDirXML << "\\SplashScreen.png\" />\n"
  4700. "\t\t\t</m2:VisualElements>\n"
  4701. "\t\t</Application>\n"
  4702. "\t</Applications>\n"
  4703. "</Package>\n";
  4704. /* clang-format on */
  4705. this->WriteCommonMissingFiles(e1, manifestFile);
  4706. }
  4707. void cmVisualStudio10TargetGenerator::WriteMissingFilesWS80(Elem& e1)
  4708. {
  4709. std::string manifestFile =
  4710. this->DefaultArtifactDir + "/package.appxManifest";
  4711. std::string artifactDir =
  4712. this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
  4713. ConvertToWindowsSlash(artifactDir);
  4714. std::string artifactDirXML = cmVS10EscapeXML(artifactDir);
  4715. std::string targetNameXML =
  4716. cmVS10EscapeXML(this->GeneratorTarget->GetName());
  4717. cmGeneratedFileStream fout(manifestFile);
  4718. fout.SetCopyIfDifferent(true);
  4719. /* clang-format off */
  4720. fout <<
  4721. "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
  4722. "<Package xmlns=\"http://schemas.microsoft.com/appx/2010/manifest\">\n"
  4723. "\t<Identity Name=\"" << this->GUID << "\" Publisher=\"CN=CMake\""
  4724. " Version=\"1.0.0.0\" />\n"
  4725. "\t<Properties>\n"
  4726. "\t\t<DisplayName>" << targetNameXML << "</DisplayName>\n"
  4727. "\t\t<PublisherDisplayName>CMake</PublisherDisplayName>\n"
  4728. "\t\t<Logo>" << artifactDirXML << "\\StoreLogo.png</Logo>\n"
  4729. "\t</Properties>\n"
  4730. "\t<Prerequisites>\n"
  4731. "\t\t<OSMinVersion>6.2.1</OSMinVersion>\n"
  4732. "\t\t<OSMaxVersionTested>6.2.1</OSMaxVersionTested>\n"
  4733. "\t</Prerequisites>\n"
  4734. "\t<Resources>\n"
  4735. "\t\t<Resource Language=\"x-generate\" />\n"
  4736. "\t</Resources>\n"
  4737. "\t<Applications>\n"
  4738. "\t\t<Application Id=\"App\""
  4739. " Executable=\"" << targetNameXML << ".exe\""
  4740. " EntryPoint=\"" << targetNameXML << ".App\">\n"
  4741. "\t\t\t<VisualElements"
  4742. " DisplayName=\"" << targetNameXML << "\""
  4743. " Description=\"" << targetNameXML << "\""
  4744. " BackgroundColor=\"#336699\" ForegroundText=\"light\""
  4745. " Logo=\"" << artifactDirXML << "\\Logo.png\""
  4746. " SmallLogo=\"" << artifactDirXML << "\\SmallLogo.png\">\n"
  4747. "\t\t\t\t<DefaultTile ShowName=\"allLogos\""
  4748. " ShortName=\"" << targetNameXML << "\" />\n"
  4749. "\t\t\t\t<SplashScreen"
  4750. " Image=\"" << artifactDirXML << "\\SplashScreen.png\" />\n"
  4751. "\t\t\t</VisualElements>\n"
  4752. "\t\t</Application>\n"
  4753. "\t</Applications>\n"
  4754. "</Package>\n";
  4755. /* clang-format on */
  4756. this->WriteCommonMissingFiles(e1, manifestFile);
  4757. }
  4758. void cmVisualStudio10TargetGenerator::WriteMissingFilesWS81(Elem& e1)
  4759. {
  4760. std::string manifestFile =
  4761. this->DefaultArtifactDir + "/package.appxManifest";
  4762. std::string artifactDir =
  4763. this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
  4764. ConvertToWindowsSlash(artifactDir);
  4765. std::string artifactDirXML = cmVS10EscapeXML(artifactDir);
  4766. std::string targetNameXML =
  4767. cmVS10EscapeXML(this->GeneratorTarget->GetName());
  4768. cmGeneratedFileStream fout(manifestFile);
  4769. fout.SetCopyIfDifferent(true);
  4770. /* clang-format off */
  4771. fout <<
  4772. "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
  4773. "<Package xmlns=\"http://schemas.microsoft.com/appx/2010/manifest\""
  4774. " xmlns:m2=\"http://schemas.microsoft.com/appx/2013/manifest\">\n"
  4775. "\t<Identity Name=\"" << this->GUID << "\" Publisher=\"CN=CMake\""
  4776. " Version=\"1.0.0.0\" />\n"
  4777. "\t<Properties>\n"
  4778. "\t\t<DisplayName>" << targetNameXML << "</DisplayName>\n"
  4779. "\t\t<PublisherDisplayName>CMake</PublisherDisplayName>\n"
  4780. "\t\t<Logo>" << artifactDirXML << "\\StoreLogo.png</Logo>\n"
  4781. "\t</Properties>\n"
  4782. "\t<Prerequisites>\n"
  4783. "\t\t<OSMinVersion>6.3</OSMinVersion>\n"
  4784. "\t\t<OSMaxVersionTested>6.3</OSMaxVersionTested>\n"
  4785. "\t</Prerequisites>\n"
  4786. "\t<Resources>\n"
  4787. "\t\t<Resource Language=\"x-generate\" />\n"
  4788. "\t</Resources>\n"
  4789. "\t<Applications>\n"
  4790. "\t\t<Application Id=\"App\""
  4791. " Executable=\"" << targetNameXML << ".exe\""
  4792. " EntryPoint=\"" << targetNameXML << ".App\">\n"
  4793. "\t\t\t<m2:VisualElements\n"
  4794. "\t\t\t\tDisplayName=\"" << targetNameXML << "\"\n"
  4795. "\t\t\t\tDescription=\"" << targetNameXML << "\"\n"
  4796. "\t\t\t\tBackgroundColor=\"#336699\"\n"
  4797. "\t\t\t\tForegroundText=\"light\"\n"
  4798. "\t\t\t\tSquare150x150Logo=\"" << artifactDirXML << "\\Logo.png\"\n"
  4799. "\t\t\t\tSquare30x30Logo=\"" << artifactDirXML << "\\SmallLogo.png\">\n"
  4800. "\t\t\t\t<m2:DefaultTile ShortName=\"" << targetNameXML << "\">\n"
  4801. "\t\t\t\t\t<m2:ShowNameOnTiles>\n"
  4802. "\t\t\t\t\t\t<m2:ShowOn Tile=\"square150x150Logo\" />\n"
  4803. "\t\t\t\t\t</m2:ShowNameOnTiles>\n"
  4804. "\t\t\t\t</m2:DefaultTile>\n"
  4805. "\t\t\t\t<m2:SplashScreen"
  4806. " Image=\"" << artifactDirXML << "\\SplashScreen.png\" />\n"
  4807. "\t\t\t</m2:VisualElements>\n"
  4808. "\t\t</Application>\n"
  4809. "\t</Applications>\n"
  4810. "</Package>\n";
  4811. /* clang-format on */
  4812. this->WriteCommonMissingFiles(e1, manifestFile);
  4813. }
  4814. void cmVisualStudio10TargetGenerator::WriteMissingFilesWS10_0(Elem& e1)
  4815. {
  4816. std::string manifestFile =
  4817. this->DefaultArtifactDir + "/package.appxManifest";
  4818. std::string artifactDir =
  4819. this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
  4820. ConvertToWindowsSlash(artifactDir);
  4821. std::string artifactDirXML = cmVS10EscapeXML(artifactDir);
  4822. std::string targetNameXML =
  4823. cmVS10EscapeXML(this->GeneratorTarget->GetName());
  4824. cmGeneratedFileStream fout(manifestFile);
  4825. fout.SetCopyIfDifferent(true);
  4826. /* clang-format off */
  4827. fout <<
  4828. "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
  4829. "<Package\n\t"
  4830. "xmlns=\"http://schemas.microsoft.com/appx/manifest/foundation/windows10\""
  4831. "\txmlns:mp=\"http://schemas.microsoft.com/appx/2014/phone/manifest\"\n"
  4832. "\txmlns:uap=\"http://schemas.microsoft.com/appx/manifest/uap/windows10\""
  4833. "\n\tIgnorableNamespaces=\"uap mp\">\n\n"
  4834. "\t<Identity Name=\"" << this->GUID << "\" Publisher=\"CN=CMake\""
  4835. " Version=\"1.0.0.0\" />\n"
  4836. "\t<mp:PhoneIdentity PhoneProductId=\"" << this->GUID <<
  4837. "\" PhonePublisherId=\"00000000-0000-0000-0000-000000000000\"/>\n"
  4838. "\t<Properties>\n"
  4839. "\t\t<DisplayName>" << targetNameXML << "</DisplayName>\n"
  4840. "\t\t<PublisherDisplayName>CMake</PublisherDisplayName>\n"
  4841. "\t\t<Logo>" << artifactDirXML << "\\StoreLogo.png</Logo>\n"
  4842. "\t</Properties>\n"
  4843. "\t<Dependencies>\n"
  4844. "\t\t<TargetDeviceFamily Name=\"Windows.Universal\" "
  4845. "MinVersion=\"10.0.0.0\" MaxVersionTested=\"10.0.0.0\" />\n"
  4846. "\t</Dependencies>\n"
  4847. "\t<Resources>\n"
  4848. "\t\t<Resource Language=\"x-generate\" />\n"
  4849. "\t</Resources>\n"
  4850. "\t<Applications>\n"
  4851. "\t\t<Application Id=\"App\""
  4852. " Executable=\"" << targetNameXML << ".exe\""
  4853. " EntryPoint=\"" << targetNameXML << ".App\">\n"
  4854. "\t\t\t<uap:VisualElements\n"
  4855. "\t\t\t\tDisplayName=\"" << targetNameXML << "\"\n"
  4856. "\t\t\t\tDescription=\"" << targetNameXML << "\"\n"
  4857. "\t\t\t\tBackgroundColor=\"#336699\"\n"
  4858. "\t\t\t\tSquare150x150Logo=\"" << artifactDirXML << "\\Logo.png\"\n"
  4859. "\t\t\t\tSquare44x44Logo=\"" << artifactDirXML <<
  4860. "\\SmallLogo44x44.png\">\n"
  4861. "\t\t\t\t<uap:SplashScreen"
  4862. " Image=\"" << artifactDirXML << "\\SplashScreen.png\" />\n"
  4863. "\t\t\t</uap:VisualElements>\n"
  4864. "\t\t</Application>\n"
  4865. "\t</Applications>\n"
  4866. "</Package>\n";
  4867. /* clang-format on */
  4868. this->WriteCommonMissingFiles(e1, manifestFile);
  4869. }
  4870. void cmVisualStudio10TargetGenerator::WriteCommonMissingFiles(
  4871. Elem& e1, const std::string& manifestFile)
  4872. {
  4873. std::string templateFolder =
  4874. cmSystemTools::GetCMakeRoot() + "/Templates/Windows";
  4875. std::string sourceFile = this->ConvertPath(manifestFile, false);
  4876. ConvertToWindowsSlash(sourceFile);
  4877. {
  4878. Elem e2(e1, "AppxManifest");
  4879. e2.Attribute("Include", sourceFile);
  4880. e2.Element("SubType", "Designer");
  4881. }
  4882. this->AddedFiles.push_back(sourceFile);
  4883. std::string smallLogo = this->DefaultArtifactDir + "/SmallLogo.png";
  4884. cmSystemTools::CopyAFile(templateFolder + "/SmallLogo.png", smallLogo,
  4885. false);
  4886. ConvertToWindowsSlash(smallLogo);
  4887. Elem(e1, "Image").Attribute("Include", smallLogo);
  4888. this->AddedFiles.push_back(smallLogo);
  4889. std::string smallLogo44 = this->DefaultArtifactDir + "/SmallLogo44x44.png";
  4890. cmSystemTools::CopyAFile(templateFolder + "/SmallLogo44x44.png", smallLogo44,
  4891. false);
  4892. ConvertToWindowsSlash(smallLogo44);
  4893. Elem(e1, "Image").Attribute("Include", smallLogo44);
  4894. this->AddedFiles.push_back(smallLogo44);
  4895. std::string logo = this->DefaultArtifactDir + "/Logo.png";
  4896. cmSystemTools::CopyAFile(templateFolder + "/Logo.png", logo, false);
  4897. ConvertToWindowsSlash(logo);
  4898. Elem(e1, "Image").Attribute("Include", logo);
  4899. this->AddedFiles.push_back(logo);
  4900. std::string storeLogo = this->DefaultArtifactDir + "/StoreLogo.png";
  4901. cmSystemTools::CopyAFile(templateFolder + "/StoreLogo.png", storeLogo,
  4902. false);
  4903. ConvertToWindowsSlash(storeLogo);
  4904. Elem(e1, "Image").Attribute("Include", storeLogo);
  4905. this->AddedFiles.push_back(storeLogo);
  4906. std::string splashScreen = this->DefaultArtifactDir + "/SplashScreen.png";
  4907. cmSystemTools::CopyAFile(templateFolder + "/SplashScreen.png", splashScreen,
  4908. false);
  4909. ConvertToWindowsSlash(splashScreen);
  4910. Elem(e1, "Image").Attribute("Include", splashScreen);
  4911. this->AddedFiles.push_back(splashScreen);
  4912. if (this->AddedDefaultCertificate) {
  4913. // This file has already been added to the build so don't copy it
  4914. std::string keyFile =
  4915. this->DefaultArtifactDir + "/Windows_TemporaryKey.pfx";
  4916. ConvertToWindowsSlash(keyFile);
  4917. Elem(e1, "None").Attribute("Include", keyFile);
  4918. }
  4919. }
  4920. bool cmVisualStudio10TargetGenerator::ForceOld(const std::string& source) const
  4921. {
  4922. HANDLE h =
  4923. CreateFileW(cmSystemTools::ConvertToWindowsExtendedPath(source).c_str(),
  4924. FILE_WRITE_ATTRIBUTES, FILE_SHARE_WRITE, 0, OPEN_EXISTING,
  4925. FILE_FLAG_BACKUP_SEMANTICS, 0);
  4926. if (!h) {
  4927. return false;
  4928. }
  4929. FILETIME const ftime_20010101 = { 3365781504u, 29389701u };
  4930. if (!SetFileTime(h, &ftime_20010101, &ftime_20010101, &ftime_20010101)) {
  4931. CloseHandle(h);
  4932. return false;
  4933. }
  4934. CloseHandle(h);
  4935. return true;
  4936. }
  4937. void cmVisualStudio10TargetGenerator::GetCSharpSourceProperties(
  4938. cmSourceFile const* sf, std::map<std::string, std::string>& tags)
  4939. {
  4940. if (this->ProjectType == VsProjectType::csproj) {
  4941. const cmPropertyMap& props = sf->GetProperties();
  4942. for (const std::string& p : props.GetKeys()) {
  4943. static const cm::string_view propNamePrefix = "VS_CSHARP_";
  4944. if (cmHasPrefix(p, propNamePrefix)) {
  4945. std::string tagName = p.substr(propNamePrefix.length());
  4946. if (!tagName.empty()) {
  4947. cmValue val = props.GetPropertyValue(p);
  4948. if (cmNonempty(val)) {
  4949. tags[tagName] = *val;
  4950. } else {
  4951. tags.erase(tagName);
  4952. }
  4953. }
  4954. }
  4955. }
  4956. }
  4957. }
  4958. void cmVisualStudio10TargetGenerator::WriteCSharpSourceProperties(
  4959. Elem& e2, const std::map<std::string, std::string>& tags)
  4960. {
  4961. for (const auto& i : tags) {
  4962. e2.Element(i.first, i.second);
  4963. }
  4964. }
  4965. std::string cmVisualStudio10TargetGenerator::GetCSharpSourceLink(
  4966. cmSourceFile const* source)
  4967. {
  4968. // For out of source files, we first check if a matching source group
  4969. // for this file exists, otherwise we check if the path relative to current
  4970. // source- or binary-dir is used within the link and return that.
  4971. // In case of .cs files we can't do that automatically for files in the
  4972. // binary directory, because this leads to compilation errors.
  4973. std::string link;
  4974. std::string sourceGroupedFile;
  4975. std::string const& fullFileName = source->GetFullPath();
  4976. std::string const& srcDir = this->Makefile->GetCurrentSourceDirectory();
  4977. std::string const& binDir = this->Makefile->GetCurrentBinaryDirectory();
  4978. // unfortunately we have to copy the source groups, because
  4979. // FindSourceGroup uses a regex which is modifying the group
  4980. std::vector<cmSourceGroup> sourceGroups = this->Makefile->GetSourceGroups();
  4981. cmSourceGroup* sourceGroup =
  4982. this->Makefile->FindSourceGroup(fullFileName, sourceGroups);
  4983. if (sourceGroup && !sourceGroup->GetFullName().empty()) {
  4984. sourceGroupedFile = sourceGroup->GetFullName() + "/" +
  4985. cmsys::SystemTools::GetFilenameName(fullFileName);
  4986. cmsys::SystemTools::ConvertToUnixSlashes(sourceGroupedFile);
  4987. }
  4988. if (!sourceGroupedFile.empty() &&
  4989. cmHasSuffix(fullFileName, sourceGroupedFile)) {
  4990. link = sourceGroupedFile;
  4991. } else if (cmHasPrefix(fullFileName, srcDir)) {
  4992. link = fullFileName.substr(srcDir.length() + 1);
  4993. } else if (!cmHasSuffix(fullFileName, ".cs") &&
  4994. cmHasPrefix(fullFileName, binDir)) {
  4995. link = fullFileName.substr(binDir.length() + 1);
  4996. } else if (cmValue l = source->GetProperty("VS_CSHARP_Link")) {
  4997. link = *l;
  4998. }
  4999. ConvertToWindowsSlash(link);
  5000. return link;
  5001. }
  5002. std::string cmVisualStudio10TargetGenerator::GetCMakeFilePath(
  5003. const char* relativeFilePath) const
  5004. {
  5005. // Always search in the standard modules location.
  5006. std::string path =
  5007. cmStrCat(cmSystemTools::GetCMakeRoot(), '/', relativeFilePath);
  5008. ConvertToWindowsSlash(path);
  5009. return path;
  5010. }
  5011. void cmVisualStudio10TargetGenerator::WriteStdOutEncodingUtf8(Elem& e1)
  5012. {
  5013. if (this->GlobalGenerator->IsUtf8EncodingSupported()) {
  5014. e1.Element("UseUtf8Encoding", "Always");
  5015. } else if (this->GlobalGenerator->IsStdOutEncodingSupported()) {
  5016. e1.Element("StdOutEncoding", "UTF-8");
  5017. }
  5018. }
  5019. void cmVisualStudio10TargetGenerator::UpdateCache()
  5020. {
  5021. std::vector<std::string> packageReferences;
  5022. if (this->GeneratorTarget->HasPackageReferences()) {
  5023. // Store a cache entry that later determines, if a package restore is
  5024. // required.
  5025. this->GeneratorTarget->Makefile->AddCacheDefinition(
  5026. this->GeneratorTarget->GetName() + "_REQUIRES_VS_PACKAGE_RESTORE", "ON",
  5027. "Value Computed by CMake", cmStateEnums::STATIC);
  5028. } else {
  5029. // If there are any dependencies that require package restore, inherit the
  5030. // cache variable.
  5031. cmGlobalGenerator::TargetDependSet const& unordered =
  5032. this->GlobalGenerator->GetTargetDirectDepends(this->GeneratorTarget);
  5033. using OrderedTargetDependSet =
  5034. cmGlobalVisualStudioGenerator::OrderedTargetDependSet;
  5035. OrderedTargetDependSet depends(unordered, CMAKE_CHECK_BUILD_SYSTEM_TARGET);
  5036. for (cmGeneratorTarget const* dt : depends) {
  5037. if (dt->HasPackageReferences()) {
  5038. this->GeneratorTarget->Makefile->AddCacheDefinition(
  5039. this->GeneratorTarget->GetName() + "_REQUIRES_VS_PACKAGE_RESTORE",
  5040. "ON", "Value Computed by CMake", cmStateEnums::STATIC);
  5041. }
  5042. }
  5043. }
  5044. }