cmVisualStudio10TargetGenerator.cxx 166 KB

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