cmVisualStudio10TargetGenerator.cxx 197 KB

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