cmVisualStudio10TargetGenerator.cxx 166 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736
  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 <memory> // IWYU pragma: keep
  21. #include <set>
  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 = this->LocalGenerator->GetCurrentBinaryDirectory();
  341. path += "/";
  342. path += this->Name;
  343. path += ProjectFileExtension;
  344. cmGeneratedFileStream BuildFileStream(path);
  345. const std::string PathToProjectFile = path;
  346. BuildFileStream.SetCopyIfDifferent(true);
  347. // Write the encoding header into the file
  348. char magic[] = { char(0xEF), char(0xBB), char(0xBF) };
  349. BuildFileStream.write(magic, 3);
  350. BuildFileStream << "<?xml version=\"1.0\" encoding=\""
  351. << this->GlobalGenerator->Encoding() << "\"?>"
  352. << "\n";
  353. {
  354. Elem e0(BuildFileStream, "Project");
  355. e0.Attribute("DefaultTargets", "Build");
  356. const char* toolsVersion = this->GlobalGenerator->GetToolsVersion();
  357. if (this->GlobalGenerator->GetVersion() ==
  358. cmGlobalVisualStudioGenerator::VS12 &&
  359. this->GlobalGenerator->TargetsWindowsCE()) {
  360. toolsVersion = "4.0";
  361. }
  362. e0.Attribute("ToolsVersion", toolsVersion);
  363. e0.Attribute("xmlns",
  364. "http://schemas.microsoft.com/developer/msbuild/2003");
  365. if (this->NsightTegra) {
  366. Elem e1(e0, "PropertyGroup");
  367. e1.Attribute("Label", "NsightTegraProject");
  368. const unsigned int nsightTegraMajorVersion = this->NsightTegraVersion[0];
  369. const unsigned int nsightTegraMinorVersion = this->NsightTegraVersion[1];
  370. if (nsightTegraMajorVersion >= 2) {
  371. if (nsightTegraMajorVersion > 3 ||
  372. (nsightTegraMajorVersion == 3 && nsightTegraMinorVersion >= 1)) {
  373. e1.Element("NsightTegraProjectRevisionNumber", "11");
  374. } else {
  375. // Nsight Tegra 2.0 uses project revision 9.
  376. e1.Element("NsightTegraProjectRevisionNumber", "9");
  377. }
  378. // Tell newer versions to upgrade silently when loading.
  379. e1.Element("NsightTegraUpgradeOnceWithoutPrompt", "true");
  380. } else {
  381. // Require Nsight Tegra 1.6 for JCompile support.
  382. e1.Element("NsightTegraProjectRevisionNumber", "7");
  383. }
  384. }
  385. if (const char* hostArch =
  386. this->GlobalGenerator->GetPlatformToolsetHostArchitecture()) {
  387. Elem e1(e0, "PropertyGroup");
  388. e1.Element("PreferredToolArchitecture", hostArch);
  389. }
  390. if (this->ProjectType != csproj) {
  391. this->WriteProjectConfigurations(e0);
  392. }
  393. {
  394. Elem e1(e0, "PropertyGroup");
  395. e1.Attribute("Label", "Globals");
  396. e1.Element("ProjectGuid", "{" + this->GUID + "}");
  397. if (this->MSTools &&
  398. this->GeneratorTarget->GetType() <= cmStateEnums::GLOBAL_TARGET) {
  399. this->WriteApplicationTypeSettings(e1);
  400. this->VerifyNecessaryFiles();
  401. }
  402. const char* vsProjectTypes =
  403. this->GeneratorTarget->GetProperty("VS_GLOBAL_PROJECT_TYPES");
  404. if (vsProjectTypes) {
  405. const char* tagName = "ProjectTypes";
  406. if (this->ProjectType == csproj) {
  407. tagName = "ProjectTypeGuids";
  408. }
  409. e1.Element(tagName, vsProjectTypes);
  410. }
  411. const char* vsProjectName =
  412. this->GeneratorTarget->GetProperty("VS_SCC_PROJECTNAME");
  413. const char* vsLocalPath =
  414. this->GeneratorTarget->GetProperty("VS_SCC_LOCALPATH");
  415. const char* vsProvider =
  416. this->GeneratorTarget->GetProperty("VS_SCC_PROVIDER");
  417. if (vsProjectName && vsLocalPath && vsProvider) {
  418. e1.Element("SccProjectName", vsProjectName);
  419. e1.Element("SccLocalPath", vsLocalPath);
  420. e1.Element("SccProvider", vsProvider);
  421. const char* vsAuxPath =
  422. this->GeneratorTarget->GetProperty("VS_SCC_AUXPATH");
  423. if (vsAuxPath) {
  424. e1.Element("SccAuxPath", vsAuxPath);
  425. }
  426. }
  427. if (this->GeneratorTarget->GetPropertyAsBool("VS_WINRT_COMPONENT")) {
  428. e1.Element("WinMDAssembly", "true");
  429. }
  430. const char* vsGlobalKeyword =
  431. this->GeneratorTarget->GetProperty("VS_GLOBAL_KEYWORD");
  432. if (!vsGlobalKeyword) {
  433. e1.Element("Keyword", "Win32Proj");
  434. } else {
  435. e1.Element("Keyword", vsGlobalKeyword);
  436. }
  437. const char* vsGlobalRootNamespace =
  438. this->GeneratorTarget->GetProperty("VS_GLOBAL_ROOTNAMESPACE");
  439. if (vsGlobalRootNamespace) {
  440. e1.Element("RootNamespace", vsGlobalRootNamespace);
  441. }
  442. e1.Element("Platform", this->Platform);
  443. const char* projLabel =
  444. this->GeneratorTarget->GetProperty("PROJECT_LABEL");
  445. if (!projLabel) {
  446. projLabel = this->Name.c_str();
  447. }
  448. e1.Element("ProjectName", projLabel);
  449. {
  450. // TODO: add deprecation warning for VS_* property?
  451. const char* targetFrameworkVersion =
  452. this->GeneratorTarget->GetProperty(
  453. "VS_DOTNET_TARGET_FRAMEWORK_VERSION");
  454. if (!targetFrameworkVersion) {
  455. targetFrameworkVersion = this->GeneratorTarget->GetProperty(
  456. "DOTNET_TARGET_FRAMEWORK_VERSION");
  457. }
  458. if (!targetFrameworkVersion && this->ProjectType == csproj &&
  459. this->GlobalGenerator->TargetsWindowsCE() &&
  460. this->GlobalGenerator->GetVersion() ==
  461. cmGlobalVisualStudioGenerator::VS12) {
  462. // VS12 .NETCF default to .NET framework 3.9
  463. targetFrameworkVersion = "v3.9";
  464. }
  465. if (targetFrameworkVersion) {
  466. e1.Element("TargetFrameworkVersion", targetFrameworkVersion);
  467. }
  468. if (this->ProjectType == csproj &&
  469. this->GlobalGenerator->TargetsWindowsCE()) {
  470. const char* targetFrameworkId = this->GeneratorTarget->GetProperty(
  471. "VS_TARGET_FRAMEWORK_IDENTIFIER");
  472. if (!targetFrameworkId) {
  473. targetFrameworkId = "WindowsEmbeddedCompact";
  474. }
  475. e1.Element("TargetFrameworkIdentifier", targetFrameworkId);
  476. const char* targetFrameworkVer = this->GeneratorTarget->GetProperty(
  477. "VS_TARGET_FRAMEWORKS_TARGET_VERSION");
  478. if (!targetFrameworkVer) {
  479. targetFrameworkVer = "v8.0";
  480. }
  481. e1.Element("TargetFrameworkTargetsVersion", targetFrameworkVer);
  482. }
  483. }
  484. // Disable the project upgrade prompt that is displayed the first time a
  485. // project using an older toolset version is opened in a newer version of
  486. // the IDE (respected by VS 2013 and above).
  487. if (this->GlobalGenerator->GetVersion() >=
  488. cmGlobalVisualStudioGenerator::VS12) {
  489. e1.Element("VCProjectUpgraderObjectName", "NoUpgrade");
  490. }
  491. std::vector<std::string> keys = this->GeneratorTarget->GetPropertyKeys();
  492. for (std::string const& keyIt : keys) {
  493. static const char* prefix = "VS_GLOBAL_";
  494. if (keyIt.find(prefix) != 0)
  495. continue;
  496. std::string globalKey = keyIt.substr(strlen(prefix));
  497. // Skip invalid or separately-handled properties.
  498. if (globalKey.empty() || globalKey == "PROJECT_TYPES" ||
  499. globalKey == "ROOTNAMESPACE" || globalKey == "KEYWORD") {
  500. continue;
  501. }
  502. const char* value = this->GeneratorTarget->GetProperty(keyIt);
  503. if (!value)
  504. continue;
  505. e1.Element(globalKey.c_str(), value);
  506. }
  507. if (this->Managed) {
  508. std::string outputType;
  509. switch (this->GeneratorTarget->GetType()) {
  510. case cmStateEnums::OBJECT_LIBRARY:
  511. case cmStateEnums::STATIC_LIBRARY:
  512. case cmStateEnums::SHARED_LIBRARY:
  513. outputType = "Library";
  514. break;
  515. case cmStateEnums::MODULE_LIBRARY:
  516. outputType = "Module";
  517. break;
  518. case cmStateEnums::EXECUTABLE:
  519. if (this->GeneratorTarget->Target->GetPropertyAsBool(
  520. "WIN32_EXECUTABLE")) {
  521. outputType = "WinExe";
  522. } else {
  523. outputType = "Exe";
  524. }
  525. break;
  526. case cmStateEnums::UTILITY:
  527. case cmStateEnums::GLOBAL_TARGET:
  528. outputType = "Utility";
  529. break;
  530. case cmStateEnums::UNKNOWN_LIBRARY:
  531. case cmStateEnums::INTERFACE_LIBRARY:
  532. break;
  533. }
  534. e1.Element("OutputType", outputType);
  535. e1.Element("AppDesignerFolder", "Properties");
  536. }
  537. }
  538. switch (this->ProjectType) {
  539. case vcxproj:
  540. if (this->GlobalGenerator->GetPlatformToolsetVersion()) {
  541. Elem(e0, "Import")
  542. .Attribute("Project",
  543. this->GlobalGenerator->GetAuxiliaryToolset());
  544. }
  545. Elem(e0, "Import").Attribute("Project", VS10_CXX_DEFAULT_PROPS);
  546. break;
  547. case csproj:
  548. Elem(e0, "Import")
  549. .Attribute("Project", VS10_CSharp_DEFAULT_PROPS)
  550. .Attribute("Condition", "Exists('" VS10_CSharp_DEFAULT_PROPS "')");
  551. break;
  552. }
  553. this->WriteProjectConfigurationValues(e0);
  554. if (this->ProjectType == vcxproj) {
  555. Elem(e0, "Import").Attribute("Project", VS10_CXX_PROPS);
  556. }
  557. {
  558. Elem e1(e0, "ImportGroup");
  559. e1.Attribute("Label", "ExtensionSettings");
  560. e1.SetHasElements();
  561. if (this->GlobalGenerator->IsCudaEnabled()) {
  562. Elem(e1, "Import")
  563. .Attribute("Project",
  564. "$(VCTargetsPath)\\BuildCustomizations\\CUDA " +
  565. this->GlobalGenerator->GetPlatformToolsetCudaString() +
  566. ".props");
  567. }
  568. if (this->GlobalGenerator->IsMasmEnabled()) {
  569. Elem(e1, "Import")
  570. .Attribute("Project",
  571. "$(VCTargetsPath)\\BuildCustomizations\\masm.props");
  572. }
  573. if (this->GlobalGenerator->IsNasmEnabled()) {
  574. // Always search in the standard modules location.
  575. std::string propsTemplate =
  576. GetCMakeFilePath("Templates/MSBuild/nasm.props.in");
  577. std::string propsLocal;
  578. propsLocal += this->DefaultArtifactDir;
  579. propsLocal += "\\nasm.props";
  580. ConvertToWindowsSlash(propsLocal);
  581. this->Makefile->ConfigureFile(propsTemplate, propsLocal, false, true,
  582. true);
  583. Elem(e1, "Import").Attribute("Project", propsLocal);
  584. }
  585. }
  586. {
  587. Elem e1(e0, "ImportGroup");
  588. e1.Attribute("Label", "PropertySheets");
  589. std::string props;
  590. switch (this->ProjectType) {
  591. case vcxproj:
  592. props = VS10_CXX_USER_PROPS;
  593. break;
  594. case csproj:
  595. props = VS10_CSharp_USER_PROPS;
  596. break;
  597. }
  598. if (const char* p =
  599. this->GeneratorTarget->GetProperty("VS_USER_PROPS")) {
  600. props = p;
  601. }
  602. if (!props.empty()) {
  603. ConvertToWindowsSlash(props);
  604. Elem(e1, "Import")
  605. .Attribute("Project", props)
  606. .Attribute("Condition", "exists('" + props + "')")
  607. .Attribute("Label", "LocalAppDataPlatform");
  608. }
  609. this->WritePlatformExtensions(e1);
  610. }
  611. Elem(e0, "PropertyGroup").Attribute("Label", "UserMacros");
  612. this->WriteWinRTPackageCertificateKeyFile(e0);
  613. this->WritePathAndIncrementalLinkOptions(e0);
  614. this->WriteCEDebugProjectConfigurationValues(e0);
  615. this->WriteItemDefinitionGroups(e0);
  616. this->WriteCustomCommands(e0);
  617. this->WriteAllSources(e0);
  618. this->WriteDotNetReferences(e0);
  619. this->WritePackageReferences(e0);
  620. this->WriteImports(e0);
  621. this->WriteEmbeddedResourceGroup(e0);
  622. this->WriteXamlFilesGroup(e0);
  623. this->WriteWinRTReferences(e0);
  624. this->WriteProjectReferences(e0);
  625. this->WriteSDKReferences(e0);
  626. switch (this->ProjectType) {
  627. case vcxproj:
  628. Elem(e0, "Import").Attribute("Project", VS10_CXX_TARGETS);
  629. break;
  630. case csproj:
  631. if (this->GlobalGenerator->TargetsWindowsCE()) {
  632. Elem(e0, "Import").Attribute("Project", VS10_CSharp_NETCF_TARGETS);
  633. } else {
  634. Elem(e0, "Import").Attribute("Project", VS10_CSharp_TARGETS);
  635. }
  636. break;
  637. }
  638. this->WriteTargetSpecificReferences(e0);
  639. {
  640. Elem e1(e0, "ImportGroup");
  641. e1.Attribute("Label", "ExtensionTargets");
  642. e1.SetHasElements();
  643. this->WriteTargetsFileReferences(e1);
  644. if (this->GlobalGenerator->IsCudaEnabled()) {
  645. Elem(e1, "Import")
  646. .Attribute("Project",
  647. "$(VCTargetsPath)\\BuildCustomizations\\CUDA " +
  648. this->GlobalGenerator->GetPlatformToolsetCudaString() +
  649. ".targets");
  650. }
  651. if (this->GlobalGenerator->IsMasmEnabled()) {
  652. Elem(e1, "Import")
  653. .Attribute("Project",
  654. "$(VCTargetsPath)\\BuildCustomizations\\masm.targets");
  655. }
  656. if (this->GlobalGenerator->IsNasmEnabled()) {
  657. std::string nasmTargets =
  658. GetCMakeFilePath("Templates/MSBuild/nasm.targets");
  659. Elem(e1, "Import").Attribute("Project", nasmTargets);
  660. }
  661. }
  662. if (this->ProjectType == csproj) {
  663. for (std::string const& c : this->Configurations) {
  664. Elem e1(e0, "PropertyGroup");
  665. e1.Attribute("Condition", "'$(Configuration)' == '" + c + "'");
  666. e1.SetHasElements();
  667. this->WriteEvents(e1, c);
  668. }
  669. // make sure custom commands are executed before build (if necessary)
  670. {
  671. Elem e1(e0, "PropertyGroup");
  672. std::ostringstream oss;
  673. oss << "\n";
  674. for (std::string const& i : this->CSharpCustomCommandNames) {
  675. oss << " " << i << ";\n";
  676. }
  677. oss << " "
  678. << "$(BuildDependsOn)\n";
  679. e1.Element("BuildDependsOn", oss.str());
  680. }
  681. }
  682. }
  683. if (BuildFileStream.Close()) {
  684. this->GlobalGenerator->FileReplacedDuringGenerate(PathToProjectFile);
  685. }
  686. // The groups are stored in a separate file for VS 10
  687. this->WriteGroups();
  688. }
  689. void cmVisualStudio10TargetGenerator::WritePackageReferences(Elem& e0)
  690. {
  691. std::vector<std::string> packageReferences;
  692. if (const char* vsPackageReferences =
  693. this->GeneratorTarget->GetProperty("VS_PACKAGE_REFERENCES")) {
  694. cmSystemTools::ExpandListArgument(vsPackageReferences, packageReferences);
  695. }
  696. if (!packageReferences.empty()) {
  697. Elem e1(e0, "ItemGroup");
  698. for (std::string const& ri : packageReferences) {
  699. size_t versionIndex = ri.find_last_of('_');
  700. if (versionIndex != std::string::npos) {
  701. WritePackageReference(e1, ri.substr(0, versionIndex),
  702. ri.substr(versionIndex + 1));
  703. }
  704. }
  705. }
  706. }
  707. void cmVisualStudio10TargetGenerator::WritePackageReference(
  708. Elem& e1, std::string const& ref, std::string const& version)
  709. {
  710. Elem e2(e1, "PackageReference");
  711. e2.Attribute("Include", ref);
  712. e2.Attribute("Version", version);
  713. }
  714. void cmVisualStudio10TargetGenerator::WriteDotNetReferences(Elem& e0)
  715. {
  716. std::vector<std::string> references;
  717. if (const char* vsDotNetReferences =
  718. this->GeneratorTarget->GetProperty("VS_DOTNET_REFERENCES")) {
  719. cmSystemTools::ExpandListArgument(vsDotNetReferences, references);
  720. }
  721. cmPropertyMap const& props = this->GeneratorTarget->Target->GetProperties();
  722. for (auto const& i : props) {
  723. if (i.first.find("VS_DOTNET_REFERENCE_") == 0) {
  724. std::string name = i.first.substr(20);
  725. if (!name.empty()) {
  726. std::string path = i.second.GetValue();
  727. if (!cmsys::SystemTools::FileIsFullPath(path)) {
  728. path = this->Makefile->GetCurrentSourceDirectory() + "/" + path;
  729. }
  730. ConvertToWindowsSlash(path);
  731. this->DotNetHintReferences[""].push_back(
  732. DotNetHintReference(name, path));
  733. }
  734. }
  735. }
  736. if (!references.empty() || !this->DotNetHintReferences.empty()) {
  737. Elem e1(e0, "ItemGroup");
  738. for (std::string const& ri : references) {
  739. // if the entry from VS_DOTNET_REFERENCES is an existing file, generate
  740. // a new hint-reference and name it from the filename
  741. if (cmsys::SystemTools::FileExists(ri, true)) {
  742. std::string name =
  743. cmsys::SystemTools::GetFilenameWithoutLastExtension(ri);
  744. std::string path = ri;
  745. ConvertToWindowsSlash(path);
  746. this->DotNetHintReferences[""].push_back(
  747. DotNetHintReference(name, path));
  748. } else {
  749. this->WriteDotNetReference(e1, ri, "", "");
  750. }
  751. }
  752. for (const auto& h : this->DotNetHintReferences) {
  753. // DotNetHintReferences is also populated from AddLibraries().
  754. // The configuration specific hint references are added there.
  755. for (const auto& i : h.second) {
  756. this->WriteDotNetReference(e1, i.first, i.second, h.first);
  757. }
  758. }
  759. }
  760. }
  761. void cmVisualStudio10TargetGenerator::WriteDotNetReference(
  762. Elem& e1, std::string const& ref, std::string const& hint,
  763. std::string const& config)
  764. {
  765. Elem e2(e1, "Reference");
  766. // If 'config' is not empty, the reference is only added for the given
  767. // configuration. This is used when referencing imported managed assemblies.
  768. // See also cmVisualStudio10TargetGenerator::AddLibraries().
  769. if (!config.empty()) {
  770. e2.Attribute("Condition", this->CalcCondition(config));
  771. }
  772. e2.Attribute("Include", ref);
  773. e2.Element("CopyLocalSatelliteAssemblies", "true");
  774. e2.Element("ReferenceOutputAssembly", "true");
  775. if (!hint.empty()) {
  776. const char* privateReference = "True";
  777. if (const char* value = this->GeneratorTarget->GetProperty(
  778. "VS_DOTNET_REFERENCES_COPY_LOCAL")) {
  779. if (cmSystemTools::IsOff(value)) {
  780. privateReference = "False";
  781. }
  782. }
  783. e2.Element("Private", privateReference);
  784. e2.Element("HintPath", hint);
  785. }
  786. this->WriteDotNetReferenceCustomTags(e2, ref);
  787. }
  788. void cmVisualStudio10TargetGenerator::WriteImports(Elem& e0)
  789. {
  790. const char* imports =
  791. this->GeneratorTarget->Target->GetProperty("VS_PROJECT_IMPORT");
  792. if (imports) {
  793. std::vector<std::string> argsSplit;
  794. cmSystemTools::ExpandListArgument(std::string(imports), argsSplit, false);
  795. for (auto& path : argsSplit) {
  796. if (!cmsys::SystemTools::FileIsFullPath(path)) {
  797. path = this->Makefile->GetCurrentSourceDirectory() + "/" + path;
  798. }
  799. ConvertToWindowsSlash(path);
  800. Elem e1(e0, "Import");
  801. e1.Attribute("Project", path);
  802. }
  803. }
  804. }
  805. void cmVisualStudio10TargetGenerator::WriteDotNetReferenceCustomTags(
  806. Elem& e2, std::string const& ref)
  807. {
  808. static const std::string refpropPrefix = "VS_DOTNET_REFERENCEPROP_";
  809. static const std::string refpropInfix = "_TAG_";
  810. const std::string refPropFullPrefix = refpropPrefix + ref + refpropInfix;
  811. typedef std::map<std::string, std::string> CustomTags;
  812. CustomTags tags;
  813. cmPropertyMap const& props = this->GeneratorTarget->Target->GetProperties();
  814. for (const auto& i : props) {
  815. if (i.first.find(refPropFullPrefix) == 0) {
  816. std::string refTag = i.first.substr(refPropFullPrefix.length());
  817. std::string refVal = i.second.GetValue();
  818. if (!refTag.empty() && !refVal.empty()) {
  819. tags[refTag] = refVal;
  820. }
  821. }
  822. }
  823. for (auto const& tag : tags) {
  824. e2.Element(tag.first.c_str(), tag.second);
  825. }
  826. }
  827. void cmVisualStudio10TargetGenerator::WriteEmbeddedResourceGroup(Elem& e0)
  828. {
  829. std::vector<cmSourceFile const*> resxObjs;
  830. this->GeneratorTarget->GetResxSources(resxObjs, "");
  831. if (!resxObjs.empty()) {
  832. Elem e1(e0, "ItemGroup");
  833. std::string srcDir = this->Makefile->GetCurrentSourceDirectory();
  834. ConvertToWindowsSlash(srcDir);
  835. for (cmSourceFile const* oi : resxObjs) {
  836. std::string obj = oi->GetFullPath();
  837. ConvertToWindowsSlash(obj);
  838. bool useRelativePath = false;
  839. if (this->ProjectType == csproj && this->InSourceBuild) {
  840. // If we do an in-source build and the resource file is in a
  841. // subdirectory
  842. // of the .csproj file, we have to use relative pathnames, otherwise
  843. // visual studio does not show the file in the IDE. Sorry.
  844. if (obj.find(srcDir) == 0) {
  845. obj = this->ConvertPath(obj, true);
  846. ConvertToWindowsSlash(obj);
  847. useRelativePath = true;
  848. }
  849. }
  850. Elem e2(e1, "EmbeddedResource");
  851. e2.Attribute("Include", obj);
  852. if (this->ProjectType != csproj) {
  853. std::string hFileName = obj.substr(0, obj.find_last_of(".")) + ".h";
  854. e2.Element("DependentUpon", hFileName);
  855. for (std::string const& c : this->Configurations) {
  856. std::string s;
  857. if (this->GeneratorTarget->GetProperty("VS_GLOBAL_ROOTNAMESPACE") ||
  858. // Handle variant of VS_GLOBAL_<variable> for RootNamespace.
  859. this->GeneratorTarget->GetProperty("VS_GLOBAL_RootNamespace")) {
  860. s = "$(RootNamespace).";
  861. }
  862. s += "%(Filename).resources";
  863. e2.WritePlatformConfigTag("LogicalName", this->CalcCondition(c), s);
  864. }
  865. } else {
  866. std::string binDir = this->Makefile->GetCurrentBinaryDirectory();
  867. ConvertToWindowsSlash(binDir);
  868. // If the resource was NOT added using a relative path (which should
  869. // be the default), we have to provide a link here
  870. if (!useRelativePath) {
  871. std::string link;
  872. if (obj.find(srcDir) == 0) {
  873. link = obj.substr(srcDir.length() + 1);
  874. } else if (obj.find(binDir) == 0) {
  875. link = obj.substr(binDir.length() + 1);
  876. } else {
  877. link = cmsys::SystemTools::GetFilenameName(obj);
  878. }
  879. if (!link.empty()) {
  880. e2.Element("Link", link);
  881. }
  882. }
  883. // Determine if this is a generated resource from a .Designer.cs file
  884. std::string designerResource =
  885. cmSystemTools::GetFilenamePath(oi->GetFullPath()) + "/" +
  886. cmSystemTools::GetFilenameWithoutLastExtension(oi->GetFullPath()) +
  887. ".Designer.cs";
  888. if (cmsys::SystemTools::FileExists(designerResource)) {
  889. std::string generator = "PublicResXFileCodeGenerator";
  890. if (const char* g = oi->GetProperty("VS_RESOURCE_GENERATOR")) {
  891. generator = g;
  892. }
  893. if (!generator.empty()) {
  894. e2.Element("Generator", generator);
  895. if (designerResource.find(srcDir) == 0) {
  896. designerResource = designerResource.substr(srcDir.length() + 1);
  897. } else if (designerResource.find(binDir) == 0) {
  898. designerResource = designerResource.substr(binDir.length() + 1);
  899. } else {
  900. designerResource =
  901. cmsys::SystemTools::GetFilenameName(designerResource);
  902. }
  903. ConvertToWindowsSlash(designerResource);
  904. e2.Element("LastGenOutput", designerResource);
  905. }
  906. }
  907. const cmPropertyMap& props = oi->GetProperties();
  908. for (const auto& p : props) {
  909. static const std::string propNamePrefix = "VS_CSHARP_";
  910. if (p.first.find(propNamePrefix) == 0) {
  911. std::string tagName = p.first.substr(propNamePrefix.length());
  912. if (!tagName.empty()) {
  913. std::string value = props.GetPropertyValue(p.first);
  914. if (!value.empty()) {
  915. e2.Element(tagName.c_str(), value);
  916. }
  917. }
  918. }
  919. }
  920. }
  921. }
  922. }
  923. }
  924. void cmVisualStudio10TargetGenerator::WriteXamlFilesGroup(Elem& e0)
  925. {
  926. std::vector<cmSourceFile const*> xamlObjs;
  927. this->GeneratorTarget->GetXamlSources(xamlObjs, "");
  928. if (!xamlObjs.empty()) {
  929. Elem e1(e0, "ItemGroup");
  930. for (cmSourceFile const* oi : xamlObjs) {
  931. std::string obj = oi->GetFullPath();
  932. const char* xamlType;
  933. const char* xamlTypeProperty = oi->GetProperty("VS_XAML_TYPE");
  934. if (xamlTypeProperty) {
  935. xamlType = xamlTypeProperty;
  936. } else {
  937. xamlType = "Page";
  938. }
  939. Elem e2(e1, xamlType);
  940. this->WriteSource(e2, oi);
  941. e2.SetHasElements();
  942. if (this->ProjectType == csproj && !this->InSourceBuild) {
  943. // add <Link> tag to written XAML source if necessary
  944. const std::string& srcDir =
  945. this->Makefile->GetCurrentSourceDirectory();
  946. const std::string& binDir =
  947. this->Makefile->GetCurrentBinaryDirectory();
  948. std::string link;
  949. if (obj.find(srcDir) == 0) {
  950. link = obj.substr(srcDir.length() + 1);
  951. } else if (obj.find(binDir) == 0) {
  952. link = obj.substr(binDir.length() + 1);
  953. } else {
  954. link = cmsys::SystemTools::GetFilenameName(obj);
  955. }
  956. if (!link.empty()) {
  957. ConvertToWindowsSlash(link);
  958. e2.Element("Link", link);
  959. }
  960. }
  961. e2.Element("SubType", "Designer");
  962. }
  963. }
  964. }
  965. void cmVisualStudio10TargetGenerator::WriteTargetSpecificReferences(Elem& e0)
  966. {
  967. if (this->MSTools) {
  968. if (this->GlobalGenerator->TargetsWindowsPhone() &&
  969. this->GlobalGenerator->GetSystemVersion() == "8.0") {
  970. Elem(e0, "Import")
  971. .Attribute("Project",
  972. "$(MSBuildExtensionsPath)\\Microsoft\\WindowsPhone\\v"
  973. "$(TargetPlatformVersion)\\Microsoft.Cpp.WindowsPhone."
  974. "$(TargetPlatformVersion).targets");
  975. }
  976. }
  977. }
  978. void cmVisualStudio10TargetGenerator::WriteTargetsFileReferences(Elem& e1)
  979. {
  980. for (TargetsFileAndConfigs const& tac : this->TargetsFileAndConfigsVec) {
  981. std::ostringstream oss;
  982. oss << "Exists('" << tac.File << "')";
  983. if (!tac.Configs.empty()) {
  984. oss << " And (";
  985. for (size_t j = 0; j < tac.Configs.size(); ++j) {
  986. if (j > 0) {
  987. oss << " Or ";
  988. }
  989. oss << "'$(Configuration)'=='" << tac.Configs[j] << "'";
  990. }
  991. oss << ")";
  992. }
  993. Elem(e1, "Import")
  994. .Attribute("Project", tac.File)
  995. .Attribute("Condition", oss.str());
  996. }
  997. }
  998. void cmVisualStudio10TargetGenerator::WriteWinRTReferences(Elem& e0)
  999. {
  1000. std::vector<std::string> references;
  1001. if (const char* vsWinRTReferences =
  1002. this->GeneratorTarget->GetProperty("VS_WINRT_REFERENCES")) {
  1003. cmSystemTools::ExpandListArgument(vsWinRTReferences, references);
  1004. }
  1005. if (this->GlobalGenerator->TargetsWindowsPhone() &&
  1006. this->GlobalGenerator->GetSystemVersion() == "8.0" &&
  1007. references.empty()) {
  1008. references.push_back("platform.winmd");
  1009. }
  1010. if (!references.empty()) {
  1011. Elem e1(e0, "ItemGroup");
  1012. for (std::string const& ri : references) {
  1013. Elem e2(e1, "Reference");
  1014. e2.Attribute("Include", ri);
  1015. e2.Element("IsWinMDFile", "true");
  1016. }
  1017. }
  1018. }
  1019. // ConfigurationType Application, Utility StaticLibrary DynamicLibrary
  1020. void cmVisualStudio10TargetGenerator::WriteProjectConfigurations(Elem& e0)
  1021. {
  1022. Elem e1(e0, "ItemGroup");
  1023. e1.Attribute("Label", "ProjectConfigurations");
  1024. for (std::string const& c : this->Configurations) {
  1025. Elem e2(e1, "ProjectConfiguration");
  1026. e2.Attribute("Include", c + "|" + this->Platform);
  1027. e2.Element("Configuration", c);
  1028. e2.Element("Platform", this->Platform);
  1029. }
  1030. }
  1031. void cmVisualStudio10TargetGenerator::WriteProjectConfigurationValues(Elem& e0)
  1032. {
  1033. for (std::string const& c : this->Configurations) {
  1034. Elem e1(e0, "PropertyGroup");
  1035. e1.Attribute("Condition", this->CalcCondition(c));
  1036. e1.Attribute("Label", "Configuration");
  1037. if (this->ProjectType != csproj) {
  1038. std::string configType;
  1039. if (const char* vsConfigurationType =
  1040. this->GeneratorTarget->GetProperty("VS_CONFIGURATION_TYPE")) {
  1041. configType = vsConfigurationType;
  1042. } else {
  1043. switch (this->GeneratorTarget->GetType()) {
  1044. case cmStateEnums::SHARED_LIBRARY:
  1045. case cmStateEnums::MODULE_LIBRARY:
  1046. configType = "DynamicLibrary";
  1047. break;
  1048. case cmStateEnums::OBJECT_LIBRARY:
  1049. case cmStateEnums::STATIC_LIBRARY:
  1050. configType = "StaticLibrary";
  1051. break;
  1052. case cmStateEnums::EXECUTABLE:
  1053. if (this->NsightTegra &&
  1054. !this->GeneratorTarget->GetPropertyAsBool("ANDROID_GUI")) {
  1055. // Android executables are .so too.
  1056. configType = "DynamicLibrary";
  1057. } else {
  1058. configType = "Application";
  1059. }
  1060. break;
  1061. case cmStateEnums::UTILITY:
  1062. case cmStateEnums::GLOBAL_TARGET:
  1063. if (this->NsightTegra) {
  1064. // Tegra-Android platform does not understand "Utility".
  1065. configType = "StaticLibrary";
  1066. } else {
  1067. configType = "Utility";
  1068. }
  1069. break;
  1070. case cmStateEnums::UNKNOWN_LIBRARY:
  1071. case cmStateEnums::INTERFACE_LIBRARY:
  1072. break;
  1073. }
  1074. }
  1075. e1.Element("ConfigurationType", configType);
  1076. }
  1077. if (this->MSTools) {
  1078. if (!this->Managed) {
  1079. this->WriteMSToolConfigurationValues(e1, c);
  1080. } else {
  1081. this->WriteMSToolConfigurationValuesManaged(e1, c);
  1082. }
  1083. } else if (this->NsightTegra) {
  1084. this->WriteNsightTegraConfigurationValues(e1, c);
  1085. }
  1086. }
  1087. }
  1088. void cmVisualStudio10TargetGenerator::WriteCEDebugProjectConfigurationValues(
  1089. Elem& e0)
  1090. {
  1091. if (!this->GlobalGenerator->TargetsWindowsCE()) {
  1092. return;
  1093. }
  1094. const char* additionalFiles =
  1095. this->GeneratorTarget->GetProperty("DEPLOYMENT_ADDITIONAL_FILES");
  1096. const char* remoteDirectory =
  1097. this->GeneratorTarget->GetProperty("DEPLOYMENT_REMOTE_DIRECTORY");
  1098. if (!(additionalFiles || remoteDirectory)) {
  1099. return;
  1100. }
  1101. for (std::string const& c : this->Configurations) {
  1102. Elem e1(e0, "PropertyGroup");
  1103. e1.Attribute("Condition", this->CalcCondition(c));
  1104. if (remoteDirectory) {
  1105. e1.Element("RemoteDirectory", remoteDirectory);
  1106. }
  1107. if (additionalFiles) {
  1108. e1.Element("CEAdditionalFiles", additionalFiles);
  1109. }
  1110. }
  1111. }
  1112. void cmVisualStudio10TargetGenerator::WriteMSToolConfigurationValues(
  1113. Elem& e1, std::string const& config)
  1114. {
  1115. cmGlobalVisualStudio10Generator* gg = this->GlobalGenerator;
  1116. const char* mfcFlag = this->Makefile->GetDefinition("CMAKE_MFC_FLAG");
  1117. if (mfcFlag) {
  1118. std::string const mfcFlagValue = mfcFlag;
  1119. std::string useOfMfcValue = "false";
  1120. if (this->GeneratorTarget->GetType() <= cmStateEnums::OBJECT_LIBRARY) {
  1121. if (mfcFlagValue == "1") {
  1122. useOfMfcValue = "Static";
  1123. } else if (mfcFlagValue == "2") {
  1124. useOfMfcValue = "Dynamic";
  1125. }
  1126. }
  1127. e1.Element("UseOfMfc", useOfMfcValue);
  1128. }
  1129. if ((this->GeneratorTarget->GetType() <= cmStateEnums::OBJECT_LIBRARY &&
  1130. this->ClOptions[config]->UsingUnicode()) ||
  1131. this->GeneratorTarget->GetPropertyAsBool("VS_WINRT_COMPONENT") ||
  1132. this->GlobalGenerator->TargetsWindowsPhone() ||
  1133. this->GlobalGenerator->TargetsWindowsStore() ||
  1134. this->GeneratorTarget->GetPropertyAsBool("VS_WINRT_EXTENSIONS")) {
  1135. e1.Element("CharacterSet", "Unicode");
  1136. } else if (this->GeneratorTarget->GetType() <=
  1137. cmStateEnums::OBJECT_LIBRARY &&
  1138. this->ClOptions[config]->UsingSBCS()) {
  1139. e1.Element("CharacterSet", "NotSet");
  1140. } else {
  1141. e1.Element("CharacterSet", "MultiByte");
  1142. }
  1143. if (const char* toolset = gg->GetPlatformToolset()) {
  1144. e1.Element("PlatformToolset", toolset);
  1145. }
  1146. if (this->GeneratorTarget->GetPropertyAsBool("VS_WINRT_COMPONENT") ||
  1147. this->GeneratorTarget->GetPropertyAsBool("VS_WINRT_EXTENSIONS")) {
  1148. e1.Element("WindowsAppContainer", "true");
  1149. }
  1150. if (this->IPOEnabledConfigurations.count(config) > 0) {
  1151. e1.Element("WholeProgramOptimization", "true");
  1152. }
  1153. {
  1154. auto s = this->SpectreMitigation.find(config);
  1155. if (s != this->SpectreMitigation.end()) {
  1156. e1.Element("SpectreMitigation", s->second);
  1157. }
  1158. }
  1159. }
  1160. void cmVisualStudio10TargetGenerator::WriteMSToolConfigurationValuesManaged(
  1161. Elem& e1, std::string const& config)
  1162. {
  1163. if (this->GeneratorTarget->GetType() > cmStateEnums::OBJECT_LIBRARY) {
  1164. return;
  1165. }
  1166. cmGlobalVisualStudio10Generator* gg = this->GlobalGenerator;
  1167. Options& o = *(this->ClOptions[config]);
  1168. if (o.IsDebug()) {
  1169. e1.Element("DebugSymbols", "true");
  1170. e1.Element("DefineDebug", "true");
  1171. }
  1172. std::string outDir = this->GeneratorTarget->GetDirectory(config) + "/";
  1173. ConvertToWindowsSlash(outDir);
  1174. e1.Element("OutputPath", outDir);
  1175. if (o.HasFlag("Platform")) {
  1176. e1.Element("PlatformTarget", o.GetFlag("Platform"));
  1177. o.RemoveFlag("Platform");
  1178. }
  1179. if (const char* toolset = gg->GetPlatformToolset()) {
  1180. e1.Element("PlatformToolset", toolset);
  1181. }
  1182. std::string postfixName = cmSystemTools::UpperCase(config);
  1183. postfixName += "_POSTFIX";
  1184. std::string assemblyName = this->GeneratorTarget->GetOutputName(
  1185. config, cmStateEnums::RuntimeBinaryArtifact);
  1186. if (const char* postfix = this->GeneratorTarget->GetProperty(postfixName)) {
  1187. assemblyName += postfix;
  1188. }
  1189. e1.Element("AssemblyName", assemblyName);
  1190. if (cmStateEnums::EXECUTABLE == this->GeneratorTarget->GetType()) {
  1191. e1.Element("StartAction", "Program");
  1192. e1.Element("StartProgram", outDir + assemblyName + ".exe");
  1193. }
  1194. OptionsHelper oh(o, e1);
  1195. oh.OutputFlagMap();
  1196. }
  1197. //----------------------------------------------------------------------------
  1198. void cmVisualStudio10TargetGenerator::WriteNsightTegraConfigurationValues(
  1199. Elem& e1, std::string const&)
  1200. {
  1201. cmGlobalVisualStudio10Generator* gg = this->GlobalGenerator;
  1202. const char* toolset = gg->GetPlatformToolset();
  1203. e1.Element("NdkToolchainVersion", toolset ? toolset : "Default");
  1204. if (const char* minApi =
  1205. this->GeneratorTarget->GetProperty("ANDROID_API_MIN")) {
  1206. e1.Element("AndroidMinAPI", "android-" + std::string(minApi));
  1207. }
  1208. if (const char* api = this->GeneratorTarget->GetProperty("ANDROID_API")) {
  1209. e1.Element("AndroidTargetAPI", "android-" + std::string(api));
  1210. }
  1211. if (const char* cpuArch =
  1212. this->GeneratorTarget->GetProperty("ANDROID_ARCH")) {
  1213. e1.Element("AndroidArch", cpuArch);
  1214. }
  1215. if (const char* stlType =
  1216. this->GeneratorTarget->GetProperty("ANDROID_STL_TYPE")) {
  1217. e1.Element("AndroidStlType", stlType);
  1218. }
  1219. }
  1220. void cmVisualStudio10TargetGenerator::WriteCustomCommands(Elem& e0)
  1221. {
  1222. this->CSharpCustomCommandNames.clear();
  1223. std::vector<cmSourceFile const*> customCommands;
  1224. this->GeneratorTarget->GetCustomCommands(customCommands, "");
  1225. for (cmSourceFile const* si : customCommands) {
  1226. this->WriteCustomCommand(e0, si);
  1227. }
  1228. // Add CMakeLists.txt file with rule to re-run CMake for user convenience.
  1229. if (this->GeneratorTarget->GetType() != cmStateEnums::GLOBAL_TARGET &&
  1230. this->GeneratorTarget->GetName() != CMAKE_CHECK_BUILD_SYSTEM_TARGET) {
  1231. if (cmSourceFile const* sf =
  1232. this->LocalGenerator->CreateVCProjBuildRule()) {
  1233. // Write directly rather than through WriteCustomCommand because
  1234. // we do not want the de-duplication and it has no dependencies.
  1235. if (cmCustomCommand const* command = sf->GetCustomCommand()) {
  1236. this->WriteCustomRule(e0, sf, *command);
  1237. }
  1238. }
  1239. }
  1240. }
  1241. void cmVisualStudio10TargetGenerator::WriteCustomCommand(
  1242. Elem& e0, cmSourceFile const* sf)
  1243. {
  1244. if (this->LocalGenerator->GetSourcesVisited(this->GeneratorTarget)
  1245. .insert(sf)
  1246. .second) {
  1247. if (std::vector<cmSourceFile*> const* depends =
  1248. this->GeneratorTarget->GetSourceDepends(sf)) {
  1249. for (cmSourceFile const* di : *depends) {
  1250. this->WriteCustomCommand(e0, di);
  1251. }
  1252. }
  1253. if (cmCustomCommand const* command = sf->GetCustomCommand()) {
  1254. // C# projects write their <Target> within WriteCustomRule()
  1255. this->WriteCustomRule(e0, sf, *command);
  1256. }
  1257. }
  1258. }
  1259. void cmVisualStudio10TargetGenerator::WriteCustomRule(
  1260. Elem& e0, cmSourceFile const* source, cmCustomCommand const& command)
  1261. {
  1262. std::string sourcePath = source->GetFullPath();
  1263. // VS 10 will always rebuild a custom command attached to a .rule
  1264. // file that doesn't exist so create the file explicitly.
  1265. if (source->GetPropertyAsBool("__CMAKE_RULE")) {
  1266. if (!cmSystemTools::FileExists(sourcePath)) {
  1267. // Make sure the path exists for the file
  1268. std::string path = cmSystemTools::GetFilenamePath(sourcePath);
  1269. cmSystemTools::MakeDirectory(path);
  1270. cmsys::ofstream fout(sourcePath.c_str());
  1271. if (fout) {
  1272. fout << "# generated from CMake\n";
  1273. fout.flush();
  1274. fout.close();
  1275. // Force given file to have a very old timestamp, thus
  1276. // preventing dependent rebuilds.
  1277. this->ForceOld(sourcePath);
  1278. } else {
  1279. std::string error = "Could not create file: [";
  1280. error += sourcePath;
  1281. error += "] ";
  1282. cmSystemTools::Error(error + cmSystemTools::GetLastSystemError());
  1283. }
  1284. }
  1285. }
  1286. cmLocalVisualStudio7Generator* lg = this->LocalGenerator;
  1287. std::unique_ptr<Elem> spe1;
  1288. std::unique_ptr<Elem> spe2;
  1289. if (this->ProjectType != csproj) {
  1290. spe1 = cm::make_unique<Elem>(e0, "ItemGroup");
  1291. spe2 = cm::make_unique<Elem>(*spe1, "CustomBuild");
  1292. this->WriteSource(*spe2, source);
  1293. spe2->SetHasElements();
  1294. } else {
  1295. Elem e1(e0, "ItemGroup");
  1296. Elem e2(e1, "None");
  1297. std::string link;
  1298. this->GetCSharpSourceLink(source, link);
  1299. this->WriteSource(e2, source);
  1300. e2.SetHasElements();
  1301. if (!link.empty()) {
  1302. e2.Element("Link", link);
  1303. }
  1304. }
  1305. for (std::string const& c : this->Configurations) {
  1306. cmCustomCommandGenerator ccg(command, c, lg);
  1307. std::string comment = lg->ConstructComment(ccg);
  1308. comment = cmVS10EscapeComment(comment);
  1309. std::string script = lg->ConstructScript(ccg);
  1310. // input files for custom command
  1311. std::stringstream additional_inputs;
  1312. {
  1313. const char* sep = "";
  1314. if (this->ProjectType == csproj) {
  1315. // csproj files do not attach the command to a specific file
  1316. // so the primary input must be listed explicitly.
  1317. additional_inputs << source->GetFullPath();
  1318. sep = ";";
  1319. }
  1320. // Avoid listing an input more than once.
  1321. std::set<std::string> unique_inputs;
  1322. // The source is either implicit an input or has been added above.
  1323. unique_inputs.insert(source->GetFullPath());
  1324. for (std::string const& d : ccg.GetDepends()) {
  1325. std::string dep;
  1326. if (lg->GetRealDependency(d, c, dep)) {
  1327. if (!unique_inputs.insert(dep).second) {
  1328. // already listed
  1329. continue;
  1330. }
  1331. ConvertToWindowsSlash(dep);
  1332. additional_inputs << sep << dep;
  1333. sep = ";";
  1334. }
  1335. }
  1336. if (this->ProjectType != csproj) {
  1337. additional_inputs << sep << "%(AdditionalInputs)";
  1338. }
  1339. }
  1340. // output files for custom command
  1341. std::stringstream outputs;
  1342. {
  1343. const char* sep = "";
  1344. for (std::string const& o : ccg.GetOutputs()) {
  1345. std::string out = o;
  1346. ConvertToWindowsSlash(out);
  1347. outputs << sep << out;
  1348. sep = ";";
  1349. }
  1350. }
  1351. if (this->ProjectType == csproj) {
  1352. std::string name = "CustomCommand_" + c + "_" +
  1353. cmSystemTools::ComputeStringMD5(sourcePath);
  1354. this->WriteCustomRuleCSharp(e0, c, name, script, additional_inputs.str(),
  1355. outputs.str(), comment);
  1356. } else {
  1357. this->WriteCustomRuleCpp(*spe2, c, script, additional_inputs.str(),
  1358. outputs.str(), comment);
  1359. }
  1360. }
  1361. }
  1362. void cmVisualStudio10TargetGenerator::WriteCustomRuleCpp(
  1363. Elem& e2, std::string const& config, std::string const& script,
  1364. std::string const& additional_inputs, std::string const& outputs,
  1365. std::string const& comment)
  1366. {
  1367. const std::string cond = this->CalcCondition(config);
  1368. e2.WritePlatformConfigTag("Message", cond, comment);
  1369. e2.WritePlatformConfigTag("Command", cond, script);
  1370. e2.WritePlatformConfigTag("AdditionalInputs", cond, additional_inputs);
  1371. e2.WritePlatformConfigTag("Outputs", cond, outputs);
  1372. if (this->LocalGenerator->GetVersion() >
  1373. cmGlobalVisualStudioGenerator::VS10) {
  1374. // VS >= 11 let us turn off linking of custom command outputs.
  1375. e2.WritePlatformConfigTag("LinkObjects", cond, "false");
  1376. }
  1377. }
  1378. void cmVisualStudio10TargetGenerator::WriteCustomRuleCSharp(
  1379. Elem& e0, std::string const& config, std::string const& name,
  1380. std::string const& script, std::string const& inputs,
  1381. std::string const& outputs, std::string const& comment)
  1382. {
  1383. this->CSharpCustomCommandNames.insert(name);
  1384. Elem e1(e0, "Target");
  1385. e1.Attribute("Condition", this->CalcCondition(config));
  1386. e1.S << "\n Name=\"" << name << "\"";
  1387. e1.S << "\n Inputs=\"" << cmVS10EscapeAttr(inputs) << "\"";
  1388. e1.S << "\n Outputs=\"" << cmVS10EscapeAttr(outputs) << "\"";
  1389. if (!comment.empty()) {
  1390. Elem(e1, "Exec").Attribute("Command", "echo " + comment);
  1391. }
  1392. Elem(e1, "Exec").Attribute("Command", script);
  1393. }
  1394. std::string cmVisualStudio10TargetGenerator::ConvertPath(
  1395. std::string const& path, bool forceRelative)
  1396. {
  1397. return forceRelative
  1398. ? cmSystemTools::RelativePath(
  1399. this->LocalGenerator->GetCurrentBinaryDirectory(), path)
  1400. : path;
  1401. }
  1402. static void ConvertToWindowsSlash(std::string& s)
  1403. {
  1404. // first convert all of the slashes
  1405. for (auto& ch : s) {
  1406. if (ch == '/') {
  1407. ch = '\\';
  1408. }
  1409. }
  1410. }
  1411. void cmVisualStudio10TargetGenerator::WriteGroups()
  1412. {
  1413. if (this->ProjectType == csproj) {
  1414. return;
  1415. }
  1416. // collect up group information
  1417. std::vector<cmSourceGroup> sourceGroups = this->Makefile->GetSourceGroups();
  1418. std::vector<cmGeneratorTarget::AllConfigSource> const& sources =
  1419. this->GeneratorTarget->GetAllConfigSources();
  1420. std::set<cmSourceGroup const*> groupsUsed;
  1421. for (cmGeneratorTarget::AllConfigSource const& si : sources) {
  1422. std::string const& source = si.Source->GetFullPath();
  1423. cmSourceGroup* sourceGroup =
  1424. this->Makefile->FindSourceGroup(source, sourceGroups);
  1425. groupsUsed.insert(sourceGroup);
  1426. }
  1427. if (cmSourceFile const* srcCMakeLists =
  1428. this->LocalGenerator->CreateVCProjBuildRule()) {
  1429. std::string const& source = srcCMakeLists->GetFullPath();
  1430. cmSourceGroup* sourceGroup =
  1431. this->Makefile->FindSourceGroup(source, sourceGroups);
  1432. groupsUsed.insert(sourceGroup);
  1433. }
  1434. this->AddMissingSourceGroups(groupsUsed, sourceGroups);
  1435. // Write out group file
  1436. std::string path = this->LocalGenerator->GetCurrentBinaryDirectory();
  1437. path += "/";
  1438. path += this->Name;
  1439. path += computeProjectFileExtension(this->GeneratorTarget);
  1440. path += ".filters";
  1441. cmGeneratedFileStream fout(path);
  1442. fout.SetCopyIfDifferent(true);
  1443. char magic[] = { char(0xEF), char(0xBB), char(0xBF) };
  1444. fout.write(magic, 3);
  1445. fout << "<?xml version=\"1.0\" encoding=\""
  1446. << this->GlobalGenerator->Encoding() << "\"?>"
  1447. << "\n";
  1448. {
  1449. Elem e0(fout, "Project");
  1450. e0.Attribute("ToolsVersion", this->GlobalGenerator->GetToolsVersion());
  1451. e0.Attribute("xmlns",
  1452. "http://schemas.microsoft.com/developer/msbuild/2003");
  1453. for (auto const& ti : this->Tools) {
  1454. this->WriteGroupSources(e0, ti.first, ti.second, sourceGroups);
  1455. }
  1456. // Added files are images and the manifest.
  1457. if (!this->AddedFiles.empty()) {
  1458. Elem e1(e0, "ItemGroup");
  1459. e1.SetHasElements();
  1460. for (std::string const& oi : this->AddedFiles) {
  1461. std::string fileName =
  1462. cmSystemTools::LowerCase(cmSystemTools::GetFilenameName(oi));
  1463. if (fileName == "wmappmanifest.xml") {
  1464. Elem e2(e1, "XML");
  1465. e2.Attribute("Include", oi);
  1466. e2.Element("Filter", "Resource Files");
  1467. } else if (cmSystemTools::GetFilenameExtension(fileName) ==
  1468. ".appxmanifest") {
  1469. Elem e2(e1, "AppxManifest");
  1470. e2.Attribute("Include", oi);
  1471. e2.Element("Filter", "Resource Files");
  1472. } else if (cmSystemTools::GetFilenameExtension(fileName) == ".pfx") {
  1473. Elem e2(e1, "None");
  1474. e2.Attribute("Include", oi);
  1475. e2.Element("Filter", "Resource Files");
  1476. } else {
  1477. Elem e2(e1, "Image");
  1478. e2.Attribute("Include", oi);
  1479. e2.Element("Filter", "Resource Files");
  1480. }
  1481. }
  1482. }
  1483. std::vector<cmSourceFile const*> resxObjs;
  1484. this->GeneratorTarget->GetResxSources(resxObjs, "");
  1485. if (!resxObjs.empty()) {
  1486. Elem e1(e0, "ItemGroup");
  1487. for (cmSourceFile const* oi : resxObjs) {
  1488. std::string obj = oi->GetFullPath();
  1489. ConvertToWindowsSlash(obj);
  1490. Elem e2(e1, "EmbeddedResource");
  1491. e2.Attribute("Include", obj);
  1492. e2.Element("Filter", "Resource Files");
  1493. }
  1494. }
  1495. {
  1496. Elem e1(e0, "ItemGroup");
  1497. e1.SetHasElements();
  1498. std::vector<cmSourceGroup const*> groupsVec(groupsUsed.begin(),
  1499. groupsUsed.end());
  1500. std::sort(groupsVec.begin(), groupsVec.end(),
  1501. [](cmSourceGroup const* l, cmSourceGroup const* r) {
  1502. return l->GetFullName() < r->GetFullName();
  1503. });
  1504. for (cmSourceGroup const* sg : groupsVec) {
  1505. std::string const& name = sg->GetFullName();
  1506. if (!name.empty()) {
  1507. std::string guidName = "SG_Filter_" + name;
  1508. std::string guid = this->GlobalGenerator->GetGUID(guidName);
  1509. Elem e2(e1, "Filter");
  1510. e2.Attribute("Include", name);
  1511. e2.Element("UniqueIdentifier", "{" + guid + "}");
  1512. }
  1513. }
  1514. if (!resxObjs.empty() || !this->AddedFiles.empty()) {
  1515. std::string guidName = "SG_Filter_Resource Files";
  1516. std::string guid = this->GlobalGenerator->GetGUID(guidName);
  1517. Elem e2(e1, "Filter");
  1518. e2.Attribute("Include", "Resource Files");
  1519. e2.Element("UniqueIdentifier", "{" + guid + "}");
  1520. e2.Element("Extensions",
  1521. "rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;"
  1522. "gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms");
  1523. }
  1524. }
  1525. }
  1526. fout << '\n';
  1527. if (fout.Close()) {
  1528. this->GlobalGenerator->FileReplacedDuringGenerate(path);
  1529. }
  1530. }
  1531. // Add to groupsUsed empty source groups that have non-empty children.
  1532. void cmVisualStudio10TargetGenerator::AddMissingSourceGroups(
  1533. std::set<cmSourceGroup const*>& groupsUsed,
  1534. const std::vector<cmSourceGroup>& allGroups)
  1535. {
  1536. for (cmSourceGroup const& current : allGroups) {
  1537. std::vector<cmSourceGroup> const& children = current.GetGroupChildren();
  1538. if (children.empty()) {
  1539. continue; // the group is really empty
  1540. }
  1541. this->AddMissingSourceGroups(groupsUsed, children);
  1542. if (groupsUsed.count(&current) > 0) {
  1543. continue; // group has already been added to set
  1544. }
  1545. // check if it least one of the group's descendants is not empty
  1546. // (at least one child must already have been added)
  1547. auto child_it = children.begin();
  1548. while (child_it != children.end()) {
  1549. if (groupsUsed.count(&(*child_it)) > 0) {
  1550. break; // found a child that was already added => add current group too
  1551. }
  1552. child_it++;
  1553. }
  1554. if (child_it == children.end()) {
  1555. continue; // no descendants have source files => ignore this group
  1556. }
  1557. groupsUsed.insert(&current);
  1558. }
  1559. }
  1560. void cmVisualStudio10TargetGenerator::WriteGroupSources(
  1561. Elem& e0, std::string const& name, ToolSources const& sources,
  1562. std::vector<cmSourceGroup>& sourceGroups)
  1563. {
  1564. Elem e1(e0, "ItemGroup");
  1565. e1.SetHasElements();
  1566. for (ToolSource const& s : sources) {
  1567. cmSourceFile const* sf = s.SourceFile;
  1568. std::string const& source = sf->GetFullPath();
  1569. cmSourceGroup* sourceGroup =
  1570. this->Makefile->FindSourceGroup(source, sourceGroups);
  1571. std::string const& filter = sourceGroup->GetFullName();
  1572. std::string path = this->ConvertPath(source, s.RelativePath);
  1573. ConvertToWindowsSlash(path);
  1574. Elem e2(e1, name.c_str());
  1575. e2.Attribute("Include", path);
  1576. if (!filter.empty()) {
  1577. e2.Element("Filter", filter);
  1578. }
  1579. }
  1580. }
  1581. void cmVisualStudio10TargetGenerator::WriteHeaderSource(Elem& e1,
  1582. cmSourceFile const* sf)
  1583. {
  1584. std::string const& fileName = sf->GetFullPath();
  1585. Elem e2(e1, "ClInclude");
  1586. this->WriteSource(e2, sf);
  1587. if (this->IsResxHeader(fileName)) {
  1588. e2.Element("FileType", "CppForm");
  1589. } else if (this->IsXamlHeader(fileName)) {
  1590. std::string xamlFileName = fileName.substr(0, fileName.find_last_of("."));
  1591. e2.Element("DependentUpon", xamlFileName);
  1592. }
  1593. }
  1594. void cmVisualStudio10TargetGenerator::WriteExtraSource(Elem& e1,
  1595. cmSourceFile const* sf)
  1596. {
  1597. bool toolHasSettings = false;
  1598. const char* tool = "None";
  1599. std::string shaderType;
  1600. std::string shaderEntryPoint;
  1601. std::string shaderModel;
  1602. std::string shaderAdditionalFlags;
  1603. std::string shaderDisableOptimizations;
  1604. std::string shaderEnableDebug;
  1605. std::string shaderObjectFileName;
  1606. std::string outputHeaderFile;
  1607. std::string variableName;
  1608. std::string settingsGenerator;
  1609. std::string settingsLastGenOutput;
  1610. std::string sourceLink;
  1611. std::string subType;
  1612. std::string copyToOutDir;
  1613. std::string includeInVsix;
  1614. std::string ext = cmSystemTools::LowerCase(sf->GetExtension());
  1615. if (this->ProjectType == csproj) {
  1616. // EVERY extra source file must have a <Link>, otherwise it might not
  1617. // be visible in Visual Studio at all. The path relative to current
  1618. // source- or binary-dir is used within the link, if the file is
  1619. // in none of these paths, it is added with the plain filename without
  1620. // any path. This means the file will show up at root-level of the csproj
  1621. // (where CMakeLists.txt etc. are).
  1622. if (!this->InSourceBuild) {
  1623. toolHasSettings = true;
  1624. std::string fullFileName = sf->GetFullPath();
  1625. std::string srcDir = this->Makefile->GetCurrentSourceDirectory();
  1626. std::string binDir = this->Makefile->GetCurrentBinaryDirectory();
  1627. if (fullFileName.find(binDir) != std::string::npos) {
  1628. sourceLink.clear();
  1629. } else if (fullFileName.find(srcDir) != std::string::npos) {
  1630. sourceLink = fullFileName.substr(srcDir.length() + 1);
  1631. } else {
  1632. // fallback: add plain filename without any path
  1633. sourceLink = cmsys::SystemTools::GetFilenameName(fullFileName);
  1634. }
  1635. if (!sourceLink.empty()) {
  1636. ConvertToWindowsSlash(sourceLink);
  1637. }
  1638. }
  1639. }
  1640. if (ext == "hlsl") {
  1641. tool = "FXCompile";
  1642. // Figure out the type of shader compiler to use.
  1643. if (const char* st = sf->GetProperty("VS_SHADER_TYPE")) {
  1644. shaderType = st;
  1645. toolHasSettings = true;
  1646. }
  1647. // Figure out which entry point to use if any
  1648. if (const char* se = sf->GetProperty("VS_SHADER_ENTRYPOINT")) {
  1649. shaderEntryPoint = se;
  1650. toolHasSettings = true;
  1651. }
  1652. // Figure out which shader model to use if any
  1653. if (const char* sm = sf->GetProperty("VS_SHADER_MODEL")) {
  1654. shaderModel = sm;
  1655. toolHasSettings = true;
  1656. }
  1657. // Figure out which output header file to use if any
  1658. if (const char* ohf = sf->GetProperty("VS_SHADER_OUTPUT_HEADER_FILE")) {
  1659. outputHeaderFile = ohf;
  1660. toolHasSettings = true;
  1661. }
  1662. // Figure out which variable name to use if any
  1663. if (const char* vn = sf->GetProperty("VS_SHADER_VARIABLE_NAME")) {
  1664. variableName = vn;
  1665. toolHasSettings = true;
  1666. }
  1667. // Figure out if there's any additional flags to use
  1668. if (const char* saf = sf->GetProperty("VS_SHADER_FLAGS")) {
  1669. shaderAdditionalFlags = saf;
  1670. toolHasSettings = true;
  1671. }
  1672. // Figure out if debug information should be generated
  1673. if (const char* sed = sf->GetProperty("VS_SHADER_ENABLE_DEBUG")) {
  1674. shaderEnableDebug = sed;
  1675. toolHasSettings = true;
  1676. }
  1677. // Figure out if optimizations should be disabled
  1678. if (const char* sdo = sf->GetProperty("VS_SHADER_DISABLE_OPTIMIZATIONS")) {
  1679. shaderDisableOptimizations = sdo;
  1680. toolHasSettings = true;
  1681. }
  1682. if (const char* sofn = sf->GetProperty("VS_SHADER_OBJECT_FILE_NAME")) {
  1683. shaderObjectFileName = sofn;
  1684. toolHasSettings = true;
  1685. }
  1686. } else if (ext == "jpg" || ext == "png") {
  1687. tool = "Image";
  1688. } else if (ext == "resw") {
  1689. tool = "PRIResource";
  1690. } else if (ext == "xml") {
  1691. tool = "XML";
  1692. } else if (ext == "natvis") {
  1693. tool = "Natvis";
  1694. } else if (ext == "settings") {
  1695. settingsLastGenOutput =
  1696. cmsys::SystemTools::GetFilenameName(sf->GetFullPath());
  1697. std::size_t pos = settingsLastGenOutput.find(".settings");
  1698. settingsLastGenOutput.replace(pos, 9, ".Designer.cs");
  1699. settingsGenerator = "SettingsSingleFileGenerator";
  1700. toolHasSettings = true;
  1701. } else if (ext == "vsixmanifest") {
  1702. subType = "Designer";
  1703. }
  1704. if (const char* c = sf->GetProperty("VS_COPY_TO_OUT_DIR")) {
  1705. tool = "Content";
  1706. copyToOutDir = c;
  1707. toolHasSettings = true;
  1708. }
  1709. if (sf->GetPropertyAsBool("VS_INCLUDE_IN_VSIX")) {
  1710. includeInVsix = "True";
  1711. tool = "Content";
  1712. toolHasSettings = true;
  1713. }
  1714. // Collect VS_CSHARP_* property values (if some are set)
  1715. std::map<std::string, std::string> sourceFileTags;
  1716. this->GetCSharpSourceProperties(sf, sourceFileTags);
  1717. if (this->NsightTegra) {
  1718. // Nsight Tegra needs specific file types to check up-to-dateness.
  1719. std::string name = cmSystemTools::LowerCase(sf->GetLocation().GetName());
  1720. if (name == "androidmanifest.xml" || name == "build.xml" ||
  1721. name == "proguard.cfg" || name == "proguard-project.txt" ||
  1722. ext == "properties") {
  1723. tool = "AndroidBuild";
  1724. } else if (ext == "java") {
  1725. tool = "JCompile";
  1726. } else if (ext == "asm" || ext == "s") {
  1727. tool = "ClCompile";
  1728. }
  1729. }
  1730. const char* toolOverride = sf->GetProperty("VS_TOOL_OVERRIDE");
  1731. if (toolOverride && *toolOverride) {
  1732. tool = toolOverride;
  1733. }
  1734. std::string deployContent;
  1735. std::string deployLocation;
  1736. if (this->GlobalGenerator->TargetsWindowsPhone() ||
  1737. this->GlobalGenerator->TargetsWindowsStore()) {
  1738. const char* content = sf->GetProperty("VS_DEPLOYMENT_CONTENT");
  1739. if (content && *content) {
  1740. toolHasSettings = true;
  1741. deployContent = content;
  1742. const char* location = sf->GetProperty("VS_DEPLOYMENT_LOCATION");
  1743. if (location && *location) {
  1744. deployLocation = location;
  1745. }
  1746. }
  1747. }
  1748. Elem e2(e1, tool);
  1749. this->WriteSource(e2, sf);
  1750. if (toolHasSettings) {
  1751. e2.SetHasElements();
  1752. if (!deployContent.empty()) {
  1753. cmGeneratorExpression ge;
  1754. std::unique_ptr<cmCompiledGeneratorExpression> cge =
  1755. ge.Parse(deployContent);
  1756. // Deployment location cannot be set on a configuration basis
  1757. if (!deployLocation.empty()) {
  1758. e2.Element("Link", deployLocation + "\\%(FileName)%(Extension)");
  1759. }
  1760. for (size_t i = 0; i != this->Configurations.size(); ++i) {
  1761. if (cge->Evaluate(this->LocalGenerator, this->Configurations[i]) ==
  1762. "1") {
  1763. e2.WritePlatformConfigTag("DeploymentContent",
  1764. "'$(Configuration)|$(Platform)'=='" +
  1765. this->Configurations[i] + "|" +
  1766. this->Platform + "'",
  1767. "true");
  1768. } else {
  1769. e2.WritePlatformConfigTag("ExcludedFromBuild",
  1770. "'$(Configuration)|$(Platform)'=='" +
  1771. this->Configurations[i] + "|" +
  1772. this->Platform + "'",
  1773. "true");
  1774. }
  1775. }
  1776. }
  1777. if (!shaderType.empty()) {
  1778. e2.Element("ShaderType", shaderType);
  1779. }
  1780. if (!shaderEntryPoint.empty()) {
  1781. e2.Element("EntryPointName", shaderEntryPoint);
  1782. }
  1783. if (!shaderModel.empty()) {
  1784. e2.Element("ShaderModel", shaderModel);
  1785. }
  1786. if (!outputHeaderFile.empty()) {
  1787. for (size_t i = 0; i != this->Configurations.size(); ++i) {
  1788. e2.WritePlatformConfigTag("HeaderFileOutput",
  1789. "'$(Configuration)|$(Platform)'=='" +
  1790. this->Configurations[i] + "|" +
  1791. this->Platform + "'",
  1792. outputHeaderFile);
  1793. }
  1794. }
  1795. if (!variableName.empty()) {
  1796. for (size_t i = 0; i != this->Configurations.size(); ++i) {
  1797. e2.WritePlatformConfigTag("VariableName",
  1798. "'$(Configuration)|$(Platform)'=='" +
  1799. this->Configurations[i] + "|" +
  1800. this->Platform + "'",
  1801. variableName);
  1802. }
  1803. }
  1804. if (!shaderEnableDebug.empty()) {
  1805. cmGeneratorExpression ge;
  1806. std::unique_ptr<cmCompiledGeneratorExpression> cge =
  1807. ge.Parse(shaderEnableDebug);
  1808. for (size_t i = 0; i != this->Configurations.size(); ++i) {
  1809. const std::string& enableDebug =
  1810. cge->Evaluate(this->LocalGenerator, this->Configurations[i]);
  1811. if (!enableDebug.empty()) {
  1812. e2.WritePlatformConfigTag(
  1813. "EnableDebuggingInformation",
  1814. "'$(Configuration)|$(Platform)'=='" + this->Configurations[i] +
  1815. "|" + this->Platform + "'",
  1816. cmSystemTools::IsOn(enableDebug) ? "true" : "false");
  1817. }
  1818. }
  1819. }
  1820. if (!shaderDisableOptimizations.empty()) {
  1821. cmGeneratorExpression ge;
  1822. std::unique_ptr<cmCompiledGeneratorExpression> cge =
  1823. ge.Parse(shaderDisableOptimizations);
  1824. for (size_t i = 0; i != this->Configurations.size(); ++i) {
  1825. const std::string& disableOptimizations =
  1826. cge->Evaluate(this->LocalGenerator, this->Configurations[i]);
  1827. if (!disableOptimizations.empty()) {
  1828. e2.WritePlatformConfigTag(
  1829. "DisableOptimizations",
  1830. "'$(Configuration)|$(Platform)'=='" + this->Configurations[i] +
  1831. "|" + this->Platform + "'",
  1832. (cmSystemTools::IsOn(disableOptimizations) ? "true" : "false"));
  1833. }
  1834. }
  1835. }
  1836. if (!shaderObjectFileName.empty()) {
  1837. e2.Element("ObjectFileOutput", shaderObjectFileName);
  1838. }
  1839. if (!shaderAdditionalFlags.empty()) {
  1840. e2.Element("AdditionalOptions", shaderAdditionalFlags);
  1841. }
  1842. if (!settingsGenerator.empty()) {
  1843. e2.Element("Generator", settingsGenerator);
  1844. }
  1845. if (!settingsLastGenOutput.empty()) {
  1846. e2.Element("LastGenOutput", settingsLastGenOutput);
  1847. }
  1848. if (!sourceLink.empty()) {
  1849. e2.Element("Link", sourceLink);
  1850. }
  1851. if (!subType.empty()) {
  1852. e2.Element("SubType", subType);
  1853. }
  1854. if (!copyToOutDir.empty()) {
  1855. e2.Element("CopyToOutputDirectory", copyToOutDir);
  1856. }
  1857. if (!includeInVsix.empty()) {
  1858. e2.Element("IncludeInVSIX", includeInVsix);
  1859. }
  1860. // write source file specific tags
  1861. this->WriteCSharpSourceProperties(e2, sourceFileTags);
  1862. }
  1863. }
  1864. void cmVisualStudio10TargetGenerator::WriteSource(Elem& e2,
  1865. cmSourceFile const* sf)
  1866. {
  1867. // Visual Studio tools append relative paths to the current dir, as in:
  1868. //
  1869. // c:\path\to\current\dir\..\..\..\relative\path\to\source.c
  1870. //
  1871. // and fail if this exceeds the maximum allowed path length. Our path
  1872. // conversion uses full paths when possible to allow deeper trees.
  1873. // However, CUDA 8.0 msbuild rules fail on absolute paths so for CUDA
  1874. // we must use relative paths.
  1875. bool forceRelative = sf->GetLanguage() == "CUDA";
  1876. std::string sourceFile = this->ConvertPath(sf->GetFullPath(), forceRelative);
  1877. if (this->LocalGenerator->GetVersion() ==
  1878. cmGlobalVisualStudioGenerator::VS10 &&
  1879. cmSystemTools::FileIsFullPath(sourceFile)) {
  1880. // Normal path conversion resulted in a full path. VS 10 (but not 11)
  1881. // refuses to show the property page in the IDE for a source file with a
  1882. // full path (not starting in a '.' or '/' AFAICT). CMake <= 2.8.4 used a
  1883. // relative path but to allow deeper build trees CMake 2.8.[5678] used a
  1884. // full path except for custom commands. Custom commands do not work
  1885. // without a relative path, but they do not seem to be involved in tools
  1886. // with the above behavior. For other sources we now use a relative path
  1887. // when the combined path will not be too long so property pages appear.
  1888. std::string sourceRel = this->ConvertPath(sf->GetFullPath(), true);
  1889. size_t const maxLen = 250;
  1890. if (sf->GetCustomCommand() ||
  1891. ((this->LocalGenerator->GetCurrentBinaryDirectory().length() + 1 +
  1892. sourceRel.length()) <= maxLen)) {
  1893. forceRelative = true;
  1894. sourceFile = sourceRel;
  1895. } else {
  1896. this->GlobalGenerator->PathTooLong(this->GeneratorTarget, sf, sourceRel);
  1897. }
  1898. }
  1899. ConvertToWindowsSlash(sourceFile);
  1900. e2.Attribute("Include", sourceFile);
  1901. ToolSource toolSource = { sf, forceRelative };
  1902. this->Tools[e2.Tag].push_back(toolSource);
  1903. }
  1904. void cmVisualStudio10TargetGenerator::WriteAllSources(Elem& e0)
  1905. {
  1906. if (this->GeneratorTarget->GetType() > cmStateEnums::UTILITY) {
  1907. return;
  1908. }
  1909. Elem e1(e0, "ItemGroup");
  1910. e1.SetHasElements();
  1911. std::vector<size_t> all_configs;
  1912. for (size_t ci = 0; ci < this->Configurations.size(); ++ci) {
  1913. all_configs.push_back(ci);
  1914. }
  1915. std::vector<cmGeneratorTarget::AllConfigSource> const& sources =
  1916. this->GeneratorTarget->GetAllConfigSources();
  1917. cmSourceFile const* srcCMakeLists =
  1918. this->LocalGenerator->CreateVCProjBuildRule();
  1919. for (cmGeneratorTarget::AllConfigSource const& si : sources) {
  1920. if (si.Source == srcCMakeLists) {
  1921. // Skip explicit reference to CMakeLists.txt source.
  1922. continue;
  1923. }
  1924. const char* tool = nullptr;
  1925. switch (si.Kind) {
  1926. case cmGeneratorTarget::SourceKindAppManifest:
  1927. tool = "AppxManifest";
  1928. break;
  1929. case cmGeneratorTarget::SourceKindCertificate:
  1930. tool = "None";
  1931. break;
  1932. case cmGeneratorTarget::SourceKindCustomCommand:
  1933. // Handled elsewhere.
  1934. break;
  1935. case cmGeneratorTarget::SourceKindExternalObject:
  1936. tool = "Object";
  1937. if (this->LocalGenerator->GetVersion() <
  1938. cmGlobalVisualStudioGenerator::VS11) {
  1939. // For VS == 10 we cannot use LinkObjects to avoid linking custom
  1940. // command outputs. If an object file is generated in this target,
  1941. // then vs10 will use it in the build, and we have to list it as
  1942. // None instead of Object.
  1943. std::vector<cmSourceFile*> const* d =
  1944. this->GeneratorTarget->GetSourceDepends(si.Source);
  1945. if (d && !d->empty()) {
  1946. tool = "None";
  1947. }
  1948. }
  1949. break;
  1950. case cmGeneratorTarget::SourceKindExtra:
  1951. this->WriteExtraSource(e1, si.Source);
  1952. break;
  1953. case cmGeneratorTarget::SourceKindHeader:
  1954. this->WriteHeaderSource(e1, si.Source);
  1955. break;
  1956. case cmGeneratorTarget::SourceKindIDL:
  1957. tool = "Midl";
  1958. break;
  1959. case cmGeneratorTarget::SourceKindManifest:
  1960. // Handled elsewhere.
  1961. break;
  1962. case cmGeneratorTarget::SourceKindModuleDefinition:
  1963. tool = "None";
  1964. break;
  1965. case cmGeneratorTarget::SourceKindObjectSource: {
  1966. const std::string& lang = si.Source->GetLanguage();
  1967. if (lang == "C" || lang == "CXX") {
  1968. tool = "ClCompile";
  1969. } else if (lang == "ASM_MASM" &&
  1970. this->GlobalGenerator->IsMasmEnabled()) {
  1971. tool = "MASM";
  1972. } else if (lang == "ASM_NASM" &&
  1973. this->GlobalGenerator->IsNasmEnabled()) {
  1974. tool = "NASM";
  1975. } else if (lang == "RC") {
  1976. tool = "ResourceCompile";
  1977. } else if (lang == "CSharp") {
  1978. tool = "Compile";
  1979. } else if (lang == "CUDA" && this->GlobalGenerator->IsCudaEnabled()) {
  1980. tool = "CudaCompile";
  1981. } else {
  1982. tool = "None";
  1983. }
  1984. } break;
  1985. case cmGeneratorTarget::SourceKindResx:
  1986. // Handled elsewhere.
  1987. break;
  1988. case cmGeneratorTarget::SourceKindXaml:
  1989. // Handled elsewhere.
  1990. break;
  1991. }
  1992. if (tool) {
  1993. // Compute set of configurations to exclude, if any.
  1994. std::vector<size_t> const& include_configs = si.Configs;
  1995. std::vector<size_t> exclude_configs;
  1996. std::set_difference(all_configs.begin(), all_configs.end(),
  1997. include_configs.begin(), include_configs.end(),
  1998. std::back_inserter(exclude_configs));
  1999. Elem e2(e1, tool);
  2000. this->WriteSource(e2, si.Source);
  2001. if (si.Kind == cmGeneratorTarget::SourceKindObjectSource) {
  2002. this->OutputSourceSpecificFlags(e2, si.Source);
  2003. }
  2004. if (!exclude_configs.empty()) {
  2005. this->WriteExcludeFromBuild(e2, exclude_configs);
  2006. }
  2007. }
  2008. }
  2009. if (this->IsMissingFiles) {
  2010. this->WriteMissingFiles(e1);
  2011. }
  2012. }
  2013. void cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags(
  2014. Elem& e2, cmSourceFile const* source)
  2015. {
  2016. cmSourceFile const& sf = *source;
  2017. std::string objectName;
  2018. if (this->GeneratorTarget->HasExplicitObjectName(&sf)) {
  2019. objectName = this->GeneratorTarget->GetObjectName(&sf);
  2020. }
  2021. std::string flags;
  2022. bool configDependentFlags = false;
  2023. std::string options;
  2024. bool configDependentOptions = false;
  2025. std::string defines;
  2026. bool configDependentDefines = false;
  2027. std::string includes;
  2028. bool configDependentIncludes = false;
  2029. if (const char* cflags = sf.GetProperty("COMPILE_FLAGS")) {
  2030. configDependentFlags =
  2031. cmGeneratorExpression::Find(cflags) != std::string::npos;
  2032. flags += cflags;
  2033. }
  2034. if (const char* coptions = sf.GetProperty("COMPILE_OPTIONS")) {
  2035. configDependentOptions =
  2036. cmGeneratorExpression::Find(coptions) != std::string::npos;
  2037. options += coptions;
  2038. }
  2039. if (const char* cdefs = sf.GetProperty("COMPILE_DEFINITIONS")) {
  2040. configDependentDefines =
  2041. cmGeneratorExpression::Find(cdefs) != std::string::npos;
  2042. defines += cdefs;
  2043. }
  2044. if (const char* cincludes = sf.GetProperty("INCLUDE_DIRECTORIES")) {
  2045. configDependentIncludes =
  2046. cmGeneratorExpression::Find(cincludes) != std::string::npos;
  2047. includes += cincludes;
  2048. }
  2049. std::string lang =
  2050. this->GlobalGenerator->GetLanguageFromExtension(sf.GetExtension().c_str());
  2051. std::string sourceLang = this->LocalGenerator->GetSourceFileLanguage(sf);
  2052. const std::string& linkLanguage =
  2053. this->GeneratorTarget->GetLinkerLanguage("");
  2054. bool needForceLang = false;
  2055. // source file does not match its extension language
  2056. if (lang != sourceLang) {
  2057. needForceLang = true;
  2058. lang = sourceLang;
  2059. }
  2060. // if the source file does not match the linker language
  2061. // then force c or c++
  2062. const char* compileAs = 0;
  2063. if (needForceLang || (linkLanguage != lang)) {
  2064. if (lang == "CXX") {
  2065. // force a C++ file type
  2066. compileAs = "CompileAsCpp";
  2067. } else if (lang == "C") {
  2068. // force to c
  2069. compileAs = "CompileAsC";
  2070. }
  2071. }
  2072. bool noWinRT = this->TargetCompileAsWinRT && lang == "C";
  2073. // for the first time we need a new line if there is something
  2074. // produced here.
  2075. if (!objectName.empty()) {
  2076. if (lang == "CUDA") {
  2077. e2.Element("CompileOut", "$(IntDir)/" + objectName);
  2078. } else {
  2079. e2.Element("ObjectFileName", "$(IntDir)/" + objectName);
  2080. }
  2081. }
  2082. for (std::string const& config : this->Configurations) {
  2083. std::string configUpper = cmSystemTools::UpperCase(config);
  2084. std::string configDefines = defines;
  2085. std::string defPropName = "COMPILE_DEFINITIONS_";
  2086. defPropName += configUpper;
  2087. if (const char* ccdefs = sf.GetProperty(defPropName)) {
  2088. if (!configDefines.empty()) {
  2089. configDefines += ";";
  2090. }
  2091. configDependentDefines |=
  2092. cmGeneratorExpression::Find(ccdefs) != std::string::npos;
  2093. configDefines += ccdefs;
  2094. }
  2095. // if we have flags or defines for this config then
  2096. // use them
  2097. if (!flags.empty() || !options.empty() || !configDefines.empty() ||
  2098. !includes.empty() || compileAs || noWinRT) {
  2099. cmGlobalVisualStudio10Generator* gg = this->GlobalGenerator;
  2100. cmIDEFlagTable const* flagtable = nullptr;
  2101. const std::string& srclang = source->GetLanguage();
  2102. if (srclang == "C" || srclang == "CXX") {
  2103. flagtable = gg->GetClFlagTable();
  2104. } else if (srclang == "ASM_MASM" &&
  2105. this->GlobalGenerator->IsMasmEnabled()) {
  2106. flagtable = gg->GetMasmFlagTable();
  2107. } else if (lang == "ASM_NASM" &&
  2108. this->GlobalGenerator->IsNasmEnabled()) {
  2109. flagtable = gg->GetNasmFlagTable();
  2110. } else if (srclang == "RC") {
  2111. flagtable = gg->GetRcFlagTable();
  2112. } else if (srclang == "CSharp") {
  2113. flagtable = gg->GetCSharpFlagTable();
  2114. }
  2115. cmGeneratorExpressionInterpreter genexInterpreter(
  2116. this->LocalGenerator, config, this->GeneratorTarget, lang);
  2117. cmVS10GeneratorOptions clOptions(
  2118. this->LocalGenerator, cmVisualStudioGeneratorOptions::Compiler,
  2119. flagtable, this);
  2120. if (compileAs) {
  2121. clOptions.AddFlag("CompileAs", compileAs);
  2122. }
  2123. if (noWinRT) {
  2124. clOptions.AddFlag("CompileAsWinRT", "false");
  2125. }
  2126. if (configDependentFlags) {
  2127. clOptions.Parse(genexInterpreter.Evaluate(flags, "COMPILE_FLAGS"));
  2128. } else {
  2129. clOptions.Parse(flags);
  2130. }
  2131. if (!options.empty()) {
  2132. std::string expandedOptions;
  2133. if (configDependentOptions) {
  2134. this->LocalGenerator->AppendCompileOptions(
  2135. expandedOptions,
  2136. genexInterpreter.Evaluate(options, "COMPILE_OPTIONS"));
  2137. } else {
  2138. this->LocalGenerator->AppendCompileOptions(expandedOptions, options);
  2139. }
  2140. clOptions.Parse(expandedOptions);
  2141. }
  2142. if (clOptions.HasFlag("DisableSpecificWarnings")) {
  2143. clOptions.AppendFlag("DisableSpecificWarnings",
  2144. "%(DisableSpecificWarnings)");
  2145. }
  2146. if (configDependentDefines) {
  2147. clOptions.AddDefines(
  2148. genexInterpreter.Evaluate(configDefines, "COMPILE_DEFINITIONS"));
  2149. } else {
  2150. clOptions.AddDefines(configDefines);
  2151. }
  2152. std::vector<std::string> includeList;
  2153. if (configDependentIncludes) {
  2154. this->LocalGenerator->AppendIncludeDirectories(
  2155. includeList,
  2156. genexInterpreter.Evaluate(includes, "INCLUDE_DIRECTORIES"), *source);
  2157. } else {
  2158. this->LocalGenerator->AppendIncludeDirectories(includeList, includes,
  2159. *source);
  2160. }
  2161. clOptions.AddIncludes(includeList);
  2162. clOptions.SetConfiguration(config);
  2163. OptionsHelper oh(clOptions, e2);
  2164. oh.PrependInheritedString("AdditionalOptions");
  2165. oh.OutputAdditionalIncludeDirectories(lang);
  2166. oh.OutputFlagMap();
  2167. oh.OutputPreprocessorDefinitions(lang);
  2168. }
  2169. }
  2170. if (this->IsXamlSource(source->GetFullPath())) {
  2171. const std::string& fileName = source->GetFullPath();
  2172. std::string xamlFileName = fileName.substr(0, fileName.find_last_of("."));
  2173. e2.Element("DependentUpon", xamlFileName);
  2174. }
  2175. if (this->ProjectType == csproj) {
  2176. std::string f = source->GetFullPath();
  2177. typedef std::map<std::string, std::string> CsPropMap;
  2178. CsPropMap sourceFileTags;
  2179. // set <Link> tag if necessary
  2180. std::string link;
  2181. this->GetCSharpSourceLink(source, link);
  2182. if (!link.empty()) {
  2183. sourceFileTags["Link"] = link;
  2184. }
  2185. this->GetCSharpSourceProperties(&sf, sourceFileTags);
  2186. // write source file specific tags
  2187. if (!sourceFileTags.empty()) {
  2188. this->WriteCSharpSourceProperties(e2, sourceFileTags);
  2189. }
  2190. }
  2191. }
  2192. void cmVisualStudio10TargetGenerator::WriteExcludeFromBuild(
  2193. Elem& e2, std::vector<size_t> const& exclude_configs)
  2194. {
  2195. for (size_t ci : exclude_configs) {
  2196. e2.WritePlatformConfigTag("ExcludedFromBuild",
  2197. "'$(Configuration)|$(Platform)'=='" +
  2198. this->Configurations[ci] + "|" +
  2199. this->Platform + "'",
  2200. "true");
  2201. }
  2202. }
  2203. void cmVisualStudio10TargetGenerator::WritePathAndIncrementalLinkOptions(
  2204. Elem& e0)
  2205. {
  2206. cmStateEnums::TargetType ttype = this->GeneratorTarget->GetType();
  2207. if (ttype > cmStateEnums::GLOBAL_TARGET) {
  2208. return;
  2209. }
  2210. if (this->ProjectType == csproj) {
  2211. return;
  2212. }
  2213. Elem e1(e0, "PropertyGroup");
  2214. e1.Element("_ProjectFileVersion", "10.0.20506.1");
  2215. for (std::string const& config : this->Configurations) {
  2216. const std::string cond = this->CalcCondition(config);
  2217. if (ttype <= cmStateEnums::UTILITY) {
  2218. if (const char* workingDir = this->GeneratorTarget->GetProperty(
  2219. "VS_DEBUGGER_WORKING_DIRECTORY")) {
  2220. cmGeneratorExpression ge;
  2221. std::unique_ptr<cmCompiledGeneratorExpression> cge =
  2222. ge.Parse(workingDir);
  2223. std::string genWorkingDir =
  2224. cge->Evaluate(this->LocalGenerator, config);
  2225. e1.WritePlatformConfigTag("LocalDebuggerWorkingDirectory", cond,
  2226. genWorkingDir);
  2227. }
  2228. if (const char* environment =
  2229. this->GeneratorTarget->GetProperty("VS_DEBUGGER_ENVIRONMENT")) {
  2230. cmGeneratorExpression ge;
  2231. std::unique_ptr<cmCompiledGeneratorExpression> cge =
  2232. ge.Parse(environment);
  2233. std::string genEnvironment =
  2234. cge->Evaluate(this->LocalGenerator, config);
  2235. e1.WritePlatformConfigTag("LocalDebuggerEnvironment", cond,
  2236. genEnvironment);
  2237. }
  2238. if (const char* debuggerCommand =
  2239. this->GeneratorTarget->GetProperty("VS_DEBUGGER_COMMAND")) {
  2240. cmGeneratorExpression ge;
  2241. std::unique_ptr<cmCompiledGeneratorExpression> cge =
  2242. ge.Parse(debuggerCommand);
  2243. std::string genDebuggerCommand =
  2244. cge->Evaluate(this->LocalGenerator, config);
  2245. e1.WritePlatformConfigTag("LocalDebuggerCommand", cond,
  2246. genDebuggerCommand);
  2247. }
  2248. if (const char* commandArguments = this->GeneratorTarget->GetProperty(
  2249. "VS_DEBUGGER_COMMAND_ARGUMENTS")) {
  2250. cmGeneratorExpression ge;
  2251. std::unique_ptr<cmCompiledGeneratorExpression> cge =
  2252. ge.Parse(commandArguments);
  2253. std::string genCommandArguments =
  2254. cge->Evaluate(this->LocalGenerator, config);
  2255. e1.WritePlatformConfigTag("LocalDebuggerCommandArguments", cond,
  2256. genCommandArguments);
  2257. }
  2258. }
  2259. if (ttype >= cmStateEnums::UTILITY) {
  2260. e1.WritePlatformConfigTag(
  2261. "IntDir", cond, "$(Platform)\\$(Configuration)\\$(ProjectName)\\");
  2262. } else {
  2263. std::string intermediateDir =
  2264. this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
  2265. intermediateDir += "/";
  2266. intermediateDir += config;
  2267. intermediateDir += "/";
  2268. std::string outDir;
  2269. std::string targetNameFull;
  2270. if (ttype == cmStateEnums::OBJECT_LIBRARY) {
  2271. outDir = intermediateDir;
  2272. targetNameFull = this->GeneratorTarget->GetName();
  2273. targetNameFull += ".lib";
  2274. } else {
  2275. outDir = this->GeneratorTarget->GetDirectory(config) + "/";
  2276. targetNameFull = this->GeneratorTarget->GetFullName(config);
  2277. }
  2278. ConvertToWindowsSlash(intermediateDir);
  2279. ConvertToWindowsSlash(outDir);
  2280. e1.WritePlatformConfigTag("OutDir", cond, outDir);
  2281. e1.WritePlatformConfigTag("IntDir", cond, intermediateDir);
  2282. if (const char* sdkExecutableDirectories = this->Makefile->GetDefinition(
  2283. "CMAKE_VS_SDK_EXECUTABLE_DIRECTORIES")) {
  2284. e1.WritePlatformConfigTag("ExecutablePath", cond,
  2285. sdkExecutableDirectories);
  2286. }
  2287. if (const char* sdkIncludeDirectories = this->Makefile->GetDefinition(
  2288. "CMAKE_VS_SDK_INCLUDE_DIRECTORIES")) {
  2289. e1.WritePlatformConfigTag("IncludePath", cond, sdkIncludeDirectories);
  2290. }
  2291. if (const char* sdkReferenceDirectories = this->Makefile->GetDefinition(
  2292. "CMAKE_VS_SDK_REFERENCE_DIRECTORIES")) {
  2293. e1.WritePlatformConfigTag("ReferencePath", cond,
  2294. sdkReferenceDirectories);
  2295. }
  2296. if (const char* sdkLibraryDirectories = this->Makefile->GetDefinition(
  2297. "CMAKE_VS_SDK_LIBRARY_DIRECTORIES")) {
  2298. e1.WritePlatformConfigTag("LibraryPath", cond, sdkLibraryDirectories);
  2299. }
  2300. if (const char* sdkLibraryWDirectories = this->Makefile->GetDefinition(
  2301. "CMAKE_VS_SDK_LIBRARY_WINRT_DIRECTORIES")) {
  2302. e1.WritePlatformConfigTag("LibraryWPath", cond,
  2303. sdkLibraryWDirectories);
  2304. }
  2305. if (const char* sdkSourceDirectories =
  2306. this->Makefile->GetDefinition("CMAKE_VS_SDK_SOURCE_DIRECTORIES")) {
  2307. e1.WritePlatformConfigTag("SourcePath", cond, sdkSourceDirectories);
  2308. }
  2309. if (const char* sdkExcludeDirectories = this->Makefile->GetDefinition(
  2310. "CMAKE_VS_SDK_EXCLUDE_DIRECTORIES")) {
  2311. e1.WritePlatformConfigTag("ExcludePath", cond, sdkExcludeDirectories);
  2312. }
  2313. std::string name =
  2314. cmSystemTools::GetFilenameWithoutLastExtension(targetNameFull);
  2315. e1.WritePlatformConfigTag("TargetName", cond, name);
  2316. std::string ext =
  2317. cmSystemTools::GetFilenameLastExtension(targetNameFull);
  2318. if (ext.empty()) {
  2319. // An empty TargetExt causes a default extension to be used.
  2320. // A single "." appears to be treated as an empty extension.
  2321. ext = ".";
  2322. }
  2323. e1.WritePlatformConfigTag("TargetExt", cond, ext);
  2324. this->OutputLinkIncremental(e1, config);
  2325. }
  2326. }
  2327. }
  2328. void cmVisualStudio10TargetGenerator::OutputLinkIncremental(
  2329. Elem& e1, std::string const& configName)
  2330. {
  2331. if (!this->MSTools) {
  2332. return;
  2333. }
  2334. if (this->ProjectType == csproj) {
  2335. return;
  2336. }
  2337. // static libraries and things greater than modules do not need
  2338. // to set this option
  2339. if (this->GeneratorTarget->GetType() == cmStateEnums::STATIC_LIBRARY ||
  2340. this->GeneratorTarget->GetType() > cmStateEnums::MODULE_LIBRARY) {
  2341. return;
  2342. }
  2343. Options& linkOptions = *(this->LinkOptions[configName]);
  2344. const std::string cond = this->CalcCondition(configName);
  2345. if (this->IPOEnabledConfigurations.count(configName) == 0) {
  2346. const char* incremental = linkOptions.GetFlag("LinkIncremental");
  2347. e1.WritePlatformConfigTag("LinkIncremental", cond,
  2348. (incremental ? incremental : "true"));
  2349. }
  2350. linkOptions.RemoveFlag("LinkIncremental");
  2351. const char* manifest = linkOptions.GetFlag("GenerateManifest");
  2352. e1.WritePlatformConfigTag("GenerateManifest", cond,
  2353. (manifest ? manifest : "true"));
  2354. linkOptions.RemoveFlag("GenerateManifest");
  2355. // Some link options belong here. Use them now and remove them so that
  2356. // WriteLinkOptions does not use them.
  2357. const char* flags[] = { "LinkDelaySign", "LinkKeyFile", 0 };
  2358. for (const char** f = flags; *f; ++f) {
  2359. const char* flag = *f;
  2360. if (const char* value = linkOptions.GetFlag(flag)) {
  2361. e1.WritePlatformConfigTag(flag, cond, value);
  2362. linkOptions.RemoveFlag(flag);
  2363. }
  2364. }
  2365. }
  2366. std::vector<std::string> cmVisualStudio10TargetGenerator::GetIncludes(
  2367. std::string const& config, std::string const& lang) const
  2368. {
  2369. std::vector<std::string> includes;
  2370. this->LocalGenerator->GetIncludeDirectories(includes, this->GeneratorTarget,
  2371. lang, config);
  2372. for (std::string& i : includes) {
  2373. ConvertToWindowsSlash(i);
  2374. }
  2375. return includes;
  2376. }
  2377. bool cmVisualStudio10TargetGenerator::ComputeClOptions()
  2378. {
  2379. for (std::string const& c : this->Configurations) {
  2380. if (!this->ComputeClOptions(c)) {
  2381. return false;
  2382. }
  2383. }
  2384. return true;
  2385. }
  2386. bool cmVisualStudio10TargetGenerator::ComputeClOptions(
  2387. std::string const& configName)
  2388. {
  2389. // much of this was copied from here:
  2390. // copied from cmLocalVisualStudio7Generator.cxx 805
  2391. // TODO: Integrate code below with cmLocalVisualStudio7Generator.
  2392. cmGlobalVisualStudio10Generator* gg = this->GlobalGenerator;
  2393. std::unique_ptr<Options> pOptions;
  2394. switch (this->ProjectType) {
  2395. case vcxproj:
  2396. pOptions = cm::make_unique<Options>(
  2397. this->LocalGenerator, Options::Compiler, gg->GetClFlagTable());
  2398. break;
  2399. case csproj:
  2400. pOptions =
  2401. cm::make_unique<Options>(this->LocalGenerator, Options::CSharpCompiler,
  2402. gg->GetCSharpFlagTable());
  2403. break;
  2404. }
  2405. Options& clOptions = *pOptions;
  2406. std::string flags;
  2407. const std::string& linkLanguage =
  2408. this->GeneratorTarget->GetLinkerLanguage(configName);
  2409. if (linkLanguage.empty()) {
  2410. cmSystemTools::Error(
  2411. "CMake can not determine linker language for target: " + this->Name);
  2412. return false;
  2413. }
  2414. // Choose a language whose flags to use for ClCompile.
  2415. static const char* clLangs[] = { "CXX", "C", "Fortran" };
  2416. std::string langForClCompile;
  2417. if (this->ProjectType == csproj) {
  2418. langForClCompile = "CSharp";
  2419. } else if (std::find(cm::cbegin(clLangs), cm::cend(clLangs), linkLanguage) !=
  2420. cm::cend(clLangs)) {
  2421. langForClCompile = linkLanguage;
  2422. } else {
  2423. std::set<std::string> languages;
  2424. this->GeneratorTarget->GetLanguages(languages, configName);
  2425. for (const char* l : clLangs) {
  2426. if (languages.count(l)) {
  2427. langForClCompile = l;
  2428. break;
  2429. }
  2430. }
  2431. }
  2432. this->LangForClCompile = langForClCompile;
  2433. if (!langForClCompile.empty()) {
  2434. this->LocalGenerator->AddLanguageFlags(flags, this->GeneratorTarget,
  2435. langForClCompile, configName);
  2436. this->LocalGenerator->AddCompileOptions(flags, this->GeneratorTarget,
  2437. langForClCompile, configName);
  2438. }
  2439. // set the correct language
  2440. if (linkLanguage == "C") {
  2441. clOptions.AddFlag("CompileAs", "CompileAsC");
  2442. }
  2443. if (linkLanguage == "CXX") {
  2444. clOptions.AddFlag("CompileAs", "CompileAsCpp");
  2445. }
  2446. // Put the IPO enabled configurations into a set.
  2447. if (this->GeneratorTarget->IsIPOEnabled(linkLanguage, configName)) {
  2448. this->IPOEnabledConfigurations.insert(configName);
  2449. }
  2450. // Get preprocessor definitions for this directory.
  2451. std::string defineFlags = this->Makefile->GetDefineFlags();
  2452. if (this->MSTools) {
  2453. if (this->ProjectType == vcxproj) {
  2454. clOptions.FixExceptionHandlingDefault();
  2455. if (this->GlobalGenerator->GetVersion() >=
  2456. cmGlobalVisualStudioGenerator::VS15) {
  2457. // Toolsets that come with VS 2017 may now enable UseFullPaths
  2458. // by default and there is no negative /FC option that projects
  2459. // can use to switch it back. Older toolsets disable this by
  2460. // default anyway so this will not hurt them. If the project
  2461. // is using an explicit /FC option then parsing flags will
  2462. // replace this setting with "true" below.
  2463. clOptions.AddFlag("UseFullPaths", "false");
  2464. }
  2465. clOptions.AddFlag("PrecompiledHeader", "NotUsing");
  2466. clOptions.AddFlag("AssemblerListingLocation", "$(IntDir)");
  2467. }
  2468. }
  2469. // check for managed C++ assembly compiler flag. This overrides any
  2470. // /clr* compiler flags which may be defined in the flags variable(s).
  2471. if (this->ProjectType != csproj) {
  2472. // Warn if /clr was added manually. This should not be done
  2473. // anymore, because cmGeneratorTarget may not be aware that the
  2474. // target uses C++/CLI.
  2475. if (flags.find("/clr") != std::string::npos ||
  2476. defineFlags.find("/clr") != std::string::npos) {
  2477. if (configName == this->Configurations[0]) {
  2478. std::string message = "For the target \"" +
  2479. this->GeneratorTarget->GetName() +
  2480. "\" the /clr compiler flag was added manually. " +
  2481. "Set usage of C++/CLI by setting COMMON_LANGUAGE_RUNTIME "
  2482. "target property.";
  2483. this->Makefile->IssueMessage(MessageType::WARNING, message);
  2484. }
  2485. }
  2486. if (auto* clr =
  2487. this->GeneratorTarget->GetProperty("COMMON_LANGUAGE_RUNTIME")) {
  2488. std::string clrString = clr;
  2489. if (!clrString.empty()) {
  2490. clrString = ":" + clrString;
  2491. }
  2492. flags += " /clr" + clrString;
  2493. }
  2494. }
  2495. clOptions.Parse(flags);
  2496. clOptions.Parse(defineFlags);
  2497. std::vector<std::string> targetDefines;
  2498. switch (this->ProjectType) {
  2499. case vcxproj:
  2500. if (!langForClCompile.empty()) {
  2501. this->GeneratorTarget->GetCompileDefinitions(targetDefines, configName,
  2502. langForClCompile);
  2503. }
  2504. break;
  2505. case csproj:
  2506. this->GeneratorTarget->GetCompileDefinitions(targetDefines, configName,
  2507. "CSharp");
  2508. break;
  2509. }
  2510. clOptions.AddDefines(targetDefines);
  2511. if (this->ProjectType == csproj) {
  2512. clOptions.AppendFlag("DefineConstants", targetDefines);
  2513. }
  2514. // Get includes for this target
  2515. if (!this->LangForClCompile.empty()) {
  2516. clOptions.AddIncludes(
  2517. this->GetIncludes(configName, this->LangForClCompile));
  2518. }
  2519. if (this->MSTools) {
  2520. clOptions.SetVerboseMakefile(
  2521. this->Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE"));
  2522. }
  2523. // Add a definition for the configuration name.
  2524. std::string configDefine = "CMAKE_INTDIR=\"";
  2525. configDefine += configName;
  2526. configDefine += "\"";
  2527. clOptions.AddDefine(configDefine);
  2528. if (const std::string* exportMacro =
  2529. this->GeneratorTarget->GetExportMacro()) {
  2530. clOptions.AddDefine(*exportMacro);
  2531. }
  2532. if (this->MSTools) {
  2533. // If we have the VS_WINRT_COMPONENT or CMAKE_VS_WINRT_BY_DEFAULT
  2534. // set then force Compile as WinRT.
  2535. if (this->GeneratorTarget->GetPropertyAsBool("VS_WINRT_COMPONENT") ||
  2536. this->Makefile->IsOn("CMAKE_VS_WINRT_BY_DEFAULT")) {
  2537. clOptions.AddFlag("CompileAsWinRT", "true");
  2538. // For WinRT components, add the _WINRT_DLL define to produce a lib
  2539. if (this->GeneratorTarget->GetType() == cmStateEnums::SHARED_LIBRARY ||
  2540. this->GeneratorTarget->GetType() == cmStateEnums::MODULE_LIBRARY) {
  2541. clOptions.AddDefine("_WINRT_DLL");
  2542. }
  2543. } else if (this->GlobalGenerator->TargetsWindowsStore() ||
  2544. this->GlobalGenerator->TargetsWindowsPhone()) {
  2545. if (!clOptions.IsWinRt()) {
  2546. clOptions.AddFlag("CompileAsWinRT", "false");
  2547. }
  2548. }
  2549. if (const char* winRT = clOptions.GetFlag("CompileAsWinRT")) {
  2550. if (cmSystemTools::IsOn(winRT)) {
  2551. this->TargetCompileAsWinRT = true;
  2552. }
  2553. }
  2554. }
  2555. if (this->ProjectType != csproj && clOptions.IsManaged()) {
  2556. this->Managed = true;
  2557. std::string managedType = clOptions.GetFlag("CompileAsManaged");
  2558. if (managedType == "Safe" || managedType == "Pure") {
  2559. // force empty calling convention if safe clr is used
  2560. clOptions.AddFlag("CallingConvention", "");
  2561. }
  2562. // The default values of these flags are incompatible to
  2563. // managed assemblies. We have to force valid values if
  2564. // the target is a managed C++ target.
  2565. clOptions.AddFlag("ExceptionHandling", "Async");
  2566. clOptions.AddFlag("BasicRuntimeChecks", "Default");
  2567. }
  2568. if (this->ProjectType == csproj) {
  2569. // /nowin32manifest overrides /win32manifest: parameter
  2570. if (clOptions.HasFlag("NoWin32Manifest")) {
  2571. clOptions.RemoveFlag("ApplicationManifest");
  2572. }
  2573. }
  2574. if (const char* s = clOptions.GetFlag("SpectreMitigation")) {
  2575. this->SpectreMitigation[configName] = s;
  2576. clOptions.RemoveFlag("SpectreMitigation");
  2577. }
  2578. this->ClOptions[configName] = std::move(pOptions);
  2579. return true;
  2580. }
  2581. void cmVisualStudio10TargetGenerator::WriteClOptions(
  2582. Elem& e1, std::string const& configName)
  2583. {
  2584. Options& clOptions = *(this->ClOptions[configName]);
  2585. if (this->ProjectType == csproj) {
  2586. return;
  2587. }
  2588. Elem e2(e1, "ClCompile");
  2589. OptionsHelper oh(clOptions, e2);
  2590. oh.PrependInheritedString("AdditionalOptions");
  2591. oh.OutputAdditionalIncludeDirectories(this->LangForClCompile);
  2592. oh.OutputFlagMap();
  2593. oh.OutputPreprocessorDefinitions(this->LangForClCompile);
  2594. if (this->NsightTegra) {
  2595. if (const char* processMax =
  2596. this->GeneratorTarget->GetProperty("ANDROID_PROCESS_MAX")) {
  2597. e2.Element("ProcessMax", processMax);
  2598. }
  2599. }
  2600. if (this->MSTools) {
  2601. cmsys::RegularExpression clangToolset("v[0-9]+_clang_.*");
  2602. const char* toolset = this->GlobalGenerator->GetPlatformToolset();
  2603. if (toolset && clangToolset.find(toolset)) {
  2604. e2.Element("ObjectFileName", "$(IntDir)%(filename).obj");
  2605. } else {
  2606. e2.Element("ObjectFileName", "$(IntDir)");
  2607. }
  2608. // If not in debug mode, write the DebugInformationFormat field
  2609. // without value so PDBs don't get generated uselessly. Each tag
  2610. // goes on its own line because Visual Studio corrects it this
  2611. // way when saving the project after CMake generates it.
  2612. if (!clOptions.IsDebug()) {
  2613. Elem e3(e2, "DebugInformationFormat");
  2614. e3.SetHasElements();
  2615. }
  2616. // Specify the compiler program database file if configured.
  2617. std::string pdb = this->GeneratorTarget->GetCompilePDBPath(configName);
  2618. if (!pdb.empty()) {
  2619. if (this->GlobalGenerator->IsCudaEnabled()) {
  2620. // CUDA does not quote paths with spaces correctly when forwarding
  2621. // this to the host compiler. Use a relative path to avoid spaces.
  2622. // FIXME: We can likely do this even when CUDA is not involved,
  2623. // but for now we will make a minimal change.
  2624. pdb = this->ConvertPath(pdb, true);
  2625. }
  2626. ConvertToWindowsSlash(pdb);
  2627. e2.Element("ProgramDataBaseFileName", pdb);
  2628. }
  2629. // add AdditionalUsingDirectories
  2630. if (this->AdditionalUsingDirectories.count(configName) > 0) {
  2631. std::string dirs;
  2632. for (auto u : this->AdditionalUsingDirectories[configName]) {
  2633. if (!dirs.empty()) {
  2634. dirs.append(";");
  2635. }
  2636. dirs.append(u);
  2637. }
  2638. e2.Element("AdditionalUsingDirectories", dirs);
  2639. }
  2640. }
  2641. }
  2642. bool cmVisualStudio10TargetGenerator::ComputeRcOptions()
  2643. {
  2644. for (std::string const& c : this->Configurations) {
  2645. if (!this->ComputeRcOptions(c)) {
  2646. return false;
  2647. }
  2648. }
  2649. return true;
  2650. }
  2651. bool cmVisualStudio10TargetGenerator::ComputeRcOptions(
  2652. std::string const& configName)
  2653. {
  2654. cmGlobalVisualStudio10Generator* gg = this->GlobalGenerator;
  2655. auto pOptions = cm::make_unique<Options>(
  2656. this->LocalGenerator, Options::ResourceCompiler, gg->GetRcFlagTable());
  2657. Options& rcOptions = *pOptions;
  2658. std::string CONFIG = cmSystemTools::UpperCase(configName);
  2659. std::string rcConfigFlagsVar = "CMAKE_RC_FLAGS_" + CONFIG;
  2660. std::string flags = this->Makefile->GetSafeDefinition("CMAKE_RC_FLAGS") +
  2661. " " + this->Makefile->GetSafeDefinition(rcConfigFlagsVar);
  2662. rcOptions.Parse(flags);
  2663. // For historical reasons, add the C preprocessor defines to RC.
  2664. Options& clOptions = *(this->ClOptions[configName]);
  2665. rcOptions.AddDefines(clOptions.GetDefines());
  2666. // Get includes for this target
  2667. rcOptions.AddIncludes(this->GetIncludes(configName, "RC"));
  2668. this->RcOptions[configName] = std::move(pOptions);
  2669. return true;
  2670. }
  2671. void cmVisualStudio10TargetGenerator::WriteRCOptions(
  2672. Elem& e1, std::string const& configName)
  2673. {
  2674. if (!this->MSTools) {
  2675. return;
  2676. }
  2677. Elem e2(e1, "ResourceCompile");
  2678. OptionsHelper rcOptions(*(this->RcOptions[configName]), e2);
  2679. rcOptions.OutputPreprocessorDefinitions("RC");
  2680. rcOptions.OutputAdditionalIncludeDirectories("RC");
  2681. rcOptions.PrependInheritedString("AdditionalOptions");
  2682. rcOptions.OutputFlagMap();
  2683. }
  2684. bool cmVisualStudio10TargetGenerator::ComputeCudaOptions()
  2685. {
  2686. if (!this->GlobalGenerator->IsCudaEnabled()) {
  2687. return true;
  2688. }
  2689. for (std::string const& c : this->Configurations) {
  2690. if (!this->ComputeCudaOptions(c)) {
  2691. return false;
  2692. }
  2693. }
  2694. return true;
  2695. }
  2696. bool cmVisualStudio10TargetGenerator::ComputeCudaOptions(
  2697. std::string const& configName)
  2698. {
  2699. cmGlobalVisualStudio10Generator* gg = this->GlobalGenerator;
  2700. auto pOptions = cm::make_unique<Options>(
  2701. this->LocalGenerator, Options::CudaCompiler, gg->GetCudaFlagTable());
  2702. Options& cudaOptions = *pOptions;
  2703. // Get compile flags for CUDA in this directory.
  2704. std::string flags;
  2705. this->LocalGenerator->AddLanguageFlags(flags, this->GeneratorTarget, "CUDA",
  2706. configName);
  2707. this->LocalGenerator->AddCompileOptions(flags, this->GeneratorTarget, "CUDA",
  2708. configName);
  2709. // Get preprocessor definitions for this directory.
  2710. std::string defineFlags = this->Makefile->GetDefineFlags();
  2711. cudaOptions.Parse(flags);
  2712. cudaOptions.Parse(defineFlags);
  2713. cudaOptions.ParseFinish();
  2714. // If we haven't explicitly enabled GPU debug information
  2715. // explicitly disable it
  2716. if (!cudaOptions.HasFlag("GPUDebugInfo")) {
  2717. cudaOptions.AddFlag("GPUDebugInfo", "false");
  2718. }
  2719. // The extension on object libraries the CUDA gives isn't
  2720. // consistent with how MSVC generates object libraries for C+, so set
  2721. // the default to not have any extension
  2722. cudaOptions.AddFlag("CompileOut", "$(IntDir)%(Filename).obj");
  2723. bool notPtx = true;
  2724. if (this->GeneratorTarget->GetPropertyAsBool("CUDA_SEPARABLE_COMPILATION")) {
  2725. cudaOptions.AddFlag("GenerateRelocatableDeviceCode", "true");
  2726. } else if (this->GeneratorTarget->GetPropertyAsBool(
  2727. "CUDA_PTX_COMPILATION")) {
  2728. cudaOptions.AddFlag("NvccCompilation", "ptx");
  2729. // We drop the %(Extension) component as CMake expects all PTX files
  2730. // to not have the source file extension at all
  2731. cudaOptions.AddFlag("CompileOut", "$(IntDir)%(Filename).ptx");
  2732. notPtx = false;
  2733. }
  2734. if (notPtx &&
  2735. cmSystemTools::VersionCompareGreaterEq(
  2736. "8.0", this->GlobalGenerator->GetPlatformToolsetCudaString())) {
  2737. // Explicitly state that we want this file to be treated as a
  2738. // CUDA file no matter what the file extensions is
  2739. // This is only needed for < CUDA 9
  2740. cudaOptions.AppendFlagString("AdditionalOptions", "-x cu");
  2741. }
  2742. // Specify the compiler program database file if configured.
  2743. std::string pdb = this->GeneratorTarget->GetCompilePDBPath(configName);
  2744. if (!pdb.empty()) {
  2745. // CUDA does not make the directory if it is non-standard.
  2746. std::string const pdbDir = cmSystemTools::GetFilenamePath(pdb);
  2747. cmSystemTools::MakeDirectory(pdbDir);
  2748. if (cmSystemTools::VersionCompareGreaterEq(
  2749. "9.2", this->GlobalGenerator->GetPlatformToolsetCudaString())) {
  2750. // CUDA does not have a field for this and does not honor the
  2751. // ProgramDataBaseFileName field in ClCompile. Work around this
  2752. // limitation by creating the directory and passing the flag ourselves.
  2753. pdb = this->ConvertPath(pdb, true);
  2754. ConvertToWindowsSlash(pdb);
  2755. std::string const clFd = "-Xcompiler=\"-Fd\\\"" + pdb + "\\\"\"";
  2756. cudaOptions.AppendFlagString("AdditionalOptions", clFd);
  2757. }
  2758. }
  2759. // CUDA automatically passes the proper '--machine' flag to nvcc
  2760. // for the current architecture, but does not reflect this default
  2761. // in the user-visible IDE settings. Set it explicitly.
  2762. if (this->Platform == "x64") {
  2763. cudaOptions.AddFlag("TargetMachinePlatform", "64");
  2764. }
  2765. // Convert the host compiler options to the toolset's abstractions
  2766. // using a secondary flag table.
  2767. cudaOptions.ClearTables();
  2768. cudaOptions.AddTable(gg->GetCudaHostFlagTable());
  2769. cudaOptions.Reparse("AdditionalCompilerOptions");
  2770. // `CUDA 8.0.targets` places AdditionalCompilerOptions before nvcc!
  2771. // Pass them through -Xcompiler in AdditionalOptions instead.
  2772. if (const char* acoPtr = cudaOptions.GetFlag("AdditionalCompilerOptions")) {
  2773. std::string aco = acoPtr;
  2774. cudaOptions.RemoveFlag("AdditionalCompilerOptions");
  2775. if (!aco.empty()) {
  2776. aco = this->LocalGenerator->EscapeForShell(aco, false);
  2777. cudaOptions.AppendFlagString("AdditionalOptions", "-Xcompiler=" + aco);
  2778. }
  2779. }
  2780. cudaOptions.FixCudaCodeGeneration();
  2781. std::vector<std::string> targetDefines;
  2782. this->GeneratorTarget->GetCompileDefinitions(targetDefines, configName,
  2783. "CUDA");
  2784. cudaOptions.AddDefines(targetDefines);
  2785. // Add a definition for the configuration name.
  2786. std::string configDefine = "CMAKE_INTDIR=\"";
  2787. configDefine += configName;
  2788. configDefine += "\"";
  2789. cudaOptions.AddDefine(configDefine);
  2790. if (const std::string* exportMacro =
  2791. this->GeneratorTarget->GetExportMacro()) {
  2792. cudaOptions.AddDefine(*exportMacro);
  2793. }
  2794. // Get includes for this target
  2795. cudaOptions.AddIncludes(this->GetIncludes(configName, "CUDA"));
  2796. cudaOptions.AddFlag("UseHostInclude", "false");
  2797. this->CudaOptions[configName] = std::move(pOptions);
  2798. return true;
  2799. }
  2800. void cmVisualStudio10TargetGenerator::WriteCudaOptions(
  2801. Elem& e1, std::string const& configName)
  2802. {
  2803. if (!this->MSTools || !this->GlobalGenerator->IsCudaEnabled()) {
  2804. return;
  2805. }
  2806. Elem e2(e1, "CudaCompile");
  2807. OptionsHelper cudaOptions(*(this->CudaOptions[configName]), e2);
  2808. cudaOptions.OutputAdditionalIncludeDirectories("CUDA");
  2809. cudaOptions.OutputPreprocessorDefinitions("CUDA");
  2810. cudaOptions.PrependInheritedString("AdditionalOptions");
  2811. cudaOptions.OutputFlagMap();
  2812. }
  2813. bool cmVisualStudio10TargetGenerator::ComputeCudaLinkOptions()
  2814. {
  2815. if (!this->GlobalGenerator->IsCudaEnabled()) {
  2816. return true;
  2817. }
  2818. for (std::string const& c : this->Configurations) {
  2819. if (!this->ComputeCudaLinkOptions(c)) {
  2820. return false;
  2821. }
  2822. }
  2823. return true;
  2824. }
  2825. bool cmVisualStudio10TargetGenerator::ComputeCudaLinkOptions(
  2826. std::string const& configName)
  2827. {
  2828. cmGlobalVisualStudio10Generator* gg = this->GlobalGenerator;
  2829. auto pOptions = cm::make_unique<Options>(
  2830. this->LocalGenerator, Options::CudaCompiler, gg->GetCudaFlagTable());
  2831. Options& cudaLinkOptions = *pOptions;
  2832. // Determine if we need to do a device link
  2833. const bool doDeviceLinking = requireDeviceLinking(
  2834. *this->GeneratorTarget, *this->LocalGenerator, configName);
  2835. cudaLinkOptions.AddFlag("PerformDeviceLink",
  2836. doDeviceLinking ? "true" : "false");
  2837. // Suppress deprecation warnings for default GPU targets during device link.
  2838. if (cmSystemTools::VersionCompareGreaterEq(
  2839. this->GlobalGenerator->GetPlatformToolsetCudaString(), "8.0")) {
  2840. cudaLinkOptions.AppendFlagString("AdditionalOptions",
  2841. "-Wno-deprecated-gpu-targets");
  2842. }
  2843. this->CudaLinkOptions[configName] = std::move(pOptions);
  2844. return true;
  2845. }
  2846. void cmVisualStudio10TargetGenerator::WriteCudaLinkOptions(
  2847. Elem& e1, std::string const& configName)
  2848. {
  2849. if (this->GeneratorTarget->GetType() > cmStateEnums::MODULE_LIBRARY) {
  2850. return;
  2851. }
  2852. if (!this->MSTools || !this->GlobalGenerator->IsCudaEnabled()) {
  2853. return;
  2854. }
  2855. Elem e2(e1, "CudaLink");
  2856. OptionsHelper cudaLinkOptions(*(this->CudaLinkOptions[configName]), e2);
  2857. cudaLinkOptions.OutputFlagMap();
  2858. }
  2859. bool cmVisualStudio10TargetGenerator::ComputeMasmOptions()
  2860. {
  2861. if (!this->GlobalGenerator->IsMasmEnabled()) {
  2862. return true;
  2863. }
  2864. for (std::string const& c : this->Configurations) {
  2865. if (!this->ComputeMasmOptions(c)) {
  2866. return false;
  2867. }
  2868. }
  2869. return true;
  2870. }
  2871. bool cmVisualStudio10TargetGenerator::ComputeMasmOptions(
  2872. std::string const& configName)
  2873. {
  2874. cmGlobalVisualStudio10Generator* gg = this->GlobalGenerator;
  2875. auto pOptions = cm::make_unique<Options>(
  2876. this->LocalGenerator, Options::MasmCompiler, gg->GetMasmFlagTable());
  2877. Options& masmOptions = *pOptions;
  2878. std::string flags;
  2879. this->LocalGenerator->AddLanguageFlags(flags, this->GeneratorTarget,
  2880. "ASM_MASM", configName);
  2881. masmOptions.Parse(flags);
  2882. // Get includes for this target
  2883. masmOptions.AddIncludes(this->GetIncludes(configName, "ASM_MASM"));
  2884. this->MasmOptions[configName] = std::move(pOptions);
  2885. return true;
  2886. }
  2887. void cmVisualStudio10TargetGenerator::WriteMasmOptions(
  2888. Elem& e1, std::string const& configName)
  2889. {
  2890. if (!this->MSTools || !this->GlobalGenerator->IsMasmEnabled()) {
  2891. return;
  2892. }
  2893. Elem e2(e1, "MASM");
  2894. // Preprocessor definitions and includes are shared with clOptions.
  2895. OptionsHelper clOptions(*(this->ClOptions[configName]), e2);
  2896. clOptions.OutputPreprocessorDefinitions("ASM_MASM");
  2897. OptionsHelper masmOptions(*(this->MasmOptions[configName]), e2);
  2898. masmOptions.OutputAdditionalIncludeDirectories("ASM_MASM");
  2899. masmOptions.PrependInheritedString("AdditionalOptions");
  2900. masmOptions.OutputFlagMap();
  2901. }
  2902. bool cmVisualStudio10TargetGenerator::ComputeNasmOptions()
  2903. {
  2904. if (!this->GlobalGenerator->IsNasmEnabled()) {
  2905. return true;
  2906. }
  2907. for (std::string const& c : this->Configurations) {
  2908. if (!this->ComputeNasmOptions(c)) {
  2909. return false;
  2910. }
  2911. }
  2912. return true;
  2913. }
  2914. bool cmVisualStudio10TargetGenerator::ComputeNasmOptions(
  2915. std::string const& configName)
  2916. {
  2917. cmGlobalVisualStudio10Generator* gg = this->GlobalGenerator;
  2918. auto pOptions = cm::make_unique<Options>(
  2919. this->LocalGenerator, Options::NasmCompiler, gg->GetNasmFlagTable());
  2920. Options& nasmOptions = *pOptions;
  2921. std::string flags;
  2922. this->LocalGenerator->AddLanguageFlags(flags, this->GeneratorTarget,
  2923. "ASM_NASM", configName);
  2924. flags += " -f";
  2925. flags += this->Makefile->GetSafeDefinition("CMAKE_ASM_NASM_OBJECT_FORMAT");
  2926. nasmOptions.Parse(flags);
  2927. // Get includes for this target
  2928. nasmOptions.AddIncludes(this->GetIncludes(configName, "ASM_NASM"));
  2929. this->NasmOptions[configName] = std::move(pOptions);
  2930. return true;
  2931. }
  2932. void cmVisualStudio10TargetGenerator::WriteNasmOptions(
  2933. Elem& e1, std::string const& configName)
  2934. {
  2935. if (!this->GlobalGenerator->IsNasmEnabled()) {
  2936. return;
  2937. }
  2938. Elem e2(e1, "NASM");
  2939. std::vector<std::string> includes =
  2940. this->GetIncludes(configName, "ASM_NASM");
  2941. OptionsHelper nasmOptions(*(this->NasmOptions[configName]), e2);
  2942. nasmOptions.OutputAdditionalIncludeDirectories("ASM_NASM");
  2943. nasmOptions.OutputFlagMap();
  2944. nasmOptions.PrependInheritedString("AdditionalOptions");
  2945. nasmOptions.OutputPreprocessorDefinitions("ASM_NASM");
  2946. // Preprocessor definitions and includes are shared with clOptions.
  2947. OptionsHelper clOptions(*(this->ClOptions[configName]), e2);
  2948. clOptions.OutputPreprocessorDefinitions("ASM_NASM");
  2949. }
  2950. void cmVisualStudio10TargetGenerator::WriteLibOptions(
  2951. Elem& e1, std::string const& config)
  2952. {
  2953. if (this->GeneratorTarget->GetType() != cmStateEnums::STATIC_LIBRARY &&
  2954. this->GeneratorTarget->GetType() != cmStateEnums::OBJECT_LIBRARY) {
  2955. return;
  2956. }
  2957. const std::string& linkLanguage =
  2958. this->GeneratorTarget->GetLinkClosure(config)->LinkerLanguage;
  2959. std::string libflags;
  2960. this->LocalGenerator->GetStaticLibraryFlags(
  2961. libflags, cmSystemTools::UpperCase(config), linkLanguage,
  2962. this->GeneratorTarget);
  2963. if (!libflags.empty()) {
  2964. Elem e2(e1, "Lib");
  2965. cmGlobalVisualStudio10Generator* gg = this->GlobalGenerator;
  2966. cmVS10GeneratorOptions libOptions(this->LocalGenerator,
  2967. cmVisualStudioGeneratorOptions::Linker,
  2968. gg->GetLibFlagTable(), this);
  2969. libOptions.Parse(libflags);
  2970. OptionsHelper oh(libOptions, e2);
  2971. oh.PrependInheritedString("AdditionalOptions");
  2972. oh.OutputFlagMap();
  2973. }
  2974. // We cannot generate metadata for static libraries. WindowsPhone
  2975. // and WindowsStore tools look at GenerateWindowsMetadata in the
  2976. // Link tool options even for static libraries.
  2977. if (this->GlobalGenerator->TargetsWindowsPhone() ||
  2978. this->GlobalGenerator->TargetsWindowsStore()) {
  2979. Elem e2(e1, "Link");
  2980. e2.Element("GenerateWindowsMetadata", "false");
  2981. }
  2982. }
  2983. void cmVisualStudio10TargetGenerator::WriteManifestOptions(
  2984. Elem& e1, std::string const& config)
  2985. {
  2986. if (this->GeneratorTarget->GetType() != cmStateEnums::EXECUTABLE &&
  2987. this->GeneratorTarget->GetType() != cmStateEnums::SHARED_LIBRARY &&
  2988. this->GeneratorTarget->GetType() != cmStateEnums::MODULE_LIBRARY) {
  2989. return;
  2990. }
  2991. std::vector<cmSourceFile const*> manifest_srcs;
  2992. this->GeneratorTarget->GetManifests(manifest_srcs, config);
  2993. if (!manifest_srcs.empty()) {
  2994. std::ostringstream oss;
  2995. for (cmSourceFile const* mi : manifest_srcs) {
  2996. std::string m = this->ConvertPath(mi->GetFullPath(), false);
  2997. ConvertToWindowsSlash(m);
  2998. oss << m << ";";
  2999. }
  3000. Elem e2(e1, "Manifest");
  3001. e2.Element("AdditionalManifestFiles", oss.str());
  3002. }
  3003. }
  3004. void cmVisualStudio10TargetGenerator::WriteAntBuildOptions(
  3005. Elem& e1, std::string const& configName)
  3006. {
  3007. // Look through the sources for AndroidManifest.xml and use
  3008. // its location as the root source directory.
  3009. std::string rootDir = this->LocalGenerator->GetCurrentSourceDirectory();
  3010. {
  3011. std::vector<cmSourceFile const*> extraSources;
  3012. this->GeneratorTarget->GetExtraSources(extraSources, "");
  3013. for (cmSourceFile const* si : extraSources) {
  3014. if ("androidmanifest.xml" ==
  3015. cmSystemTools::LowerCase(si->GetLocation().GetName())) {
  3016. rootDir = si->GetLocation().GetDirectory();
  3017. break;
  3018. }
  3019. }
  3020. }
  3021. // Tell MSBuild to launch Ant.
  3022. Elem e2(e1, "AntBuild");
  3023. {
  3024. std::string antBuildPath = rootDir;
  3025. ConvertToWindowsSlash(antBuildPath);
  3026. e2.Element("AntBuildPath", antBuildPath);
  3027. }
  3028. if (this->GeneratorTarget->GetPropertyAsBool("ANDROID_SKIP_ANT_STEP")) {
  3029. e2.Element("SkipAntStep", "true");
  3030. }
  3031. if (this->GeneratorTarget->GetPropertyAsBool("ANDROID_PROGUARD")) {
  3032. e2.Element("EnableProGuard", "true");
  3033. }
  3034. if (const char* proGuardConfigLocation =
  3035. this->GeneratorTarget->GetProperty("ANDROID_PROGUARD_CONFIG_PATH")) {
  3036. e2.Element("ProGuardConfigLocation", proGuardConfigLocation);
  3037. }
  3038. if (const char* securePropertiesLocation =
  3039. this->GeneratorTarget->GetProperty("ANDROID_SECURE_PROPS_PATH")) {
  3040. e2.Element("SecurePropertiesLocation", securePropertiesLocation);
  3041. }
  3042. if (const char* nativeLibDirectoriesExpression =
  3043. this->GeneratorTarget->GetProperty("ANDROID_NATIVE_LIB_DIRECTORIES")) {
  3044. cmGeneratorExpression ge;
  3045. std::unique_ptr<cmCompiledGeneratorExpression> cge =
  3046. ge.Parse(nativeLibDirectoriesExpression);
  3047. std::string nativeLibDirs =
  3048. cge->Evaluate(this->LocalGenerator, configName);
  3049. e2.Element("NativeLibDirectories", nativeLibDirs);
  3050. }
  3051. if (const char* nativeLibDependenciesExpression =
  3052. this->GeneratorTarget->GetProperty(
  3053. "ANDROID_NATIVE_LIB_DEPENDENCIES")) {
  3054. cmGeneratorExpression ge;
  3055. std::unique_ptr<cmCompiledGeneratorExpression> cge =
  3056. ge.Parse(nativeLibDependenciesExpression);
  3057. std::string nativeLibDeps =
  3058. cge->Evaluate(this->LocalGenerator, configName);
  3059. e2.Element("NativeLibDependencies", nativeLibDeps);
  3060. }
  3061. if (const char* javaSourceDir =
  3062. this->GeneratorTarget->GetProperty("ANDROID_JAVA_SOURCE_DIR")) {
  3063. e2.Element("JavaSourceDir", javaSourceDir);
  3064. }
  3065. if (const char* jarDirectoriesExpression =
  3066. this->GeneratorTarget->GetProperty("ANDROID_JAR_DIRECTORIES")) {
  3067. cmGeneratorExpression ge;
  3068. std::unique_ptr<cmCompiledGeneratorExpression> cge =
  3069. ge.Parse(jarDirectoriesExpression);
  3070. std::string jarDirectories =
  3071. cge->Evaluate(this->LocalGenerator, configName);
  3072. e2.Element("JarDirectories", jarDirectories);
  3073. }
  3074. if (const char* jarDeps =
  3075. this->GeneratorTarget->GetProperty("ANDROID_JAR_DEPENDENCIES")) {
  3076. e2.Element("JarDependencies", jarDeps);
  3077. }
  3078. if (const char* assetsDirectories =
  3079. this->GeneratorTarget->GetProperty("ANDROID_ASSETS_DIRECTORIES")) {
  3080. e2.Element("AssetsDirectories", assetsDirectories);
  3081. }
  3082. {
  3083. std::string manifest_xml = rootDir + "/AndroidManifest.xml";
  3084. ConvertToWindowsSlash(manifest_xml);
  3085. e2.Element("AndroidManifestLocation", manifest_xml);
  3086. }
  3087. if (const char* antAdditionalOptions =
  3088. this->GeneratorTarget->GetProperty("ANDROID_ANT_ADDITIONAL_OPTIONS")) {
  3089. e2.Element("AdditionalOptions",
  3090. std::string(antAdditionalOptions) + " %(AdditionalOptions)");
  3091. }
  3092. }
  3093. bool cmVisualStudio10TargetGenerator::ComputeLinkOptions()
  3094. {
  3095. if (this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE ||
  3096. this->GeneratorTarget->GetType() == cmStateEnums::SHARED_LIBRARY ||
  3097. this->GeneratorTarget->GetType() == cmStateEnums::MODULE_LIBRARY) {
  3098. for (std::string const& c : this->Configurations) {
  3099. if (!this->ComputeLinkOptions(c)) {
  3100. return false;
  3101. }
  3102. }
  3103. }
  3104. return true;
  3105. }
  3106. bool cmVisualStudio10TargetGenerator::ComputeLinkOptions(
  3107. std::string const& config)
  3108. {
  3109. cmGlobalVisualStudio10Generator* gg = this->GlobalGenerator;
  3110. auto pOptions = cm::make_unique<Options>(
  3111. this->LocalGenerator, Options::Linker, gg->GetLinkFlagTable(), this);
  3112. Options& linkOptions = *pOptions;
  3113. cmGeneratorTarget::LinkClosure const* linkClosure =
  3114. this->GeneratorTarget->GetLinkClosure(config);
  3115. const std::string& linkLanguage = linkClosure->LinkerLanguage;
  3116. if (linkLanguage.empty()) {
  3117. cmSystemTools::Error(
  3118. "CMake can not determine linker language for target: " + this->Name);
  3119. return false;
  3120. }
  3121. std::string CONFIG = cmSystemTools::UpperCase(config);
  3122. const char* linkType = "SHARED";
  3123. if (this->GeneratorTarget->GetType() == cmStateEnums::MODULE_LIBRARY) {
  3124. linkType = "MODULE";
  3125. }
  3126. if (this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE) {
  3127. linkType = "EXE";
  3128. }
  3129. std::string flags;
  3130. std::string linkFlagVarBase = "CMAKE_";
  3131. linkFlagVarBase += linkType;
  3132. linkFlagVarBase += "_LINKER_FLAGS";
  3133. flags += " ";
  3134. flags += this->Makefile->GetRequiredDefinition(linkFlagVarBase);
  3135. std::string linkFlagVar = linkFlagVarBase + "_" + CONFIG;
  3136. flags += " ";
  3137. flags += this->Makefile->GetRequiredDefinition(linkFlagVar);
  3138. const char* targetLinkFlags =
  3139. this->GeneratorTarget->GetProperty("LINK_FLAGS");
  3140. if (targetLinkFlags) {
  3141. flags += " ";
  3142. flags += targetLinkFlags;
  3143. }
  3144. std::string flagsProp = "LINK_FLAGS_";
  3145. flagsProp += CONFIG;
  3146. if (const char* flagsConfig =
  3147. this->GeneratorTarget->GetProperty(flagsProp)) {
  3148. flags += " ";
  3149. flags += flagsConfig;
  3150. }
  3151. std::vector<std::string> opts;
  3152. this->GeneratorTarget->GetLinkOptions(opts, config, linkLanguage);
  3153. // LINK_OPTIONS are escaped.
  3154. this->LocalGenerator->AppendCompileOptions(flags, opts);
  3155. cmComputeLinkInformation* pcli =
  3156. this->GeneratorTarget->GetLinkInformation(config);
  3157. if (!pcli) {
  3158. cmSystemTools::Error(
  3159. "CMake can not compute cmComputeLinkInformation for target: " +
  3160. this->Name);
  3161. return false;
  3162. }
  3163. cmComputeLinkInformation& cli = *pcli;
  3164. std::vector<std::string> libVec;
  3165. std::vector<std::string> vsTargetVec;
  3166. this->AddLibraries(cli, libVec, vsTargetVec, config);
  3167. if (std::find(linkClosure->Languages.begin(), linkClosure->Languages.end(),
  3168. "CUDA") != linkClosure->Languages.end() &&
  3169. this->CudaOptions[config] != nullptr) {
  3170. switch (this->CudaOptions[config]->GetCudaRuntime()) {
  3171. case cmVisualStudioGeneratorOptions::CudaRuntimeStatic:
  3172. libVec.push_back("cudadevrt.lib");
  3173. libVec.push_back("cudart_static.lib");
  3174. break;
  3175. case cmVisualStudioGeneratorOptions::CudaRuntimeShared:
  3176. libVec.push_back("cudadevrt.lib");
  3177. libVec.push_back("cudart.lib");
  3178. break;
  3179. case cmVisualStudioGeneratorOptions::CudaRuntimeNone:
  3180. break;
  3181. }
  3182. }
  3183. std::string standardLibsVar = "CMAKE_";
  3184. standardLibsVar += linkLanguage;
  3185. standardLibsVar += "_STANDARD_LIBRARIES";
  3186. std::string const& libs = this->Makefile->GetSafeDefinition(standardLibsVar);
  3187. cmSystemTools::ParseWindowsCommandLine(libs.c_str(), libVec);
  3188. linkOptions.AddFlag("AdditionalDependencies", libVec);
  3189. // Populate TargetsFileAndConfigsVec
  3190. for (std::string const& ti : vsTargetVec) {
  3191. this->AddTargetsFileAndConfigPair(ti, config);
  3192. }
  3193. std::vector<std::string> const& ldirs = cli.GetDirectories();
  3194. std::vector<std::string> linkDirs;
  3195. for (std::string const& d : ldirs) {
  3196. // first just full path
  3197. linkDirs.push_back(d);
  3198. // next path with configuration type Debug, Release, etc
  3199. linkDirs.push_back(d + "/$(Configuration)");
  3200. }
  3201. linkDirs.push_back("%(AdditionalLibraryDirectories)");
  3202. linkOptions.AddFlag("AdditionalLibraryDirectories", linkDirs);
  3203. cmGeneratorTarget::Names targetNames;
  3204. if (this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE) {
  3205. targetNames = this->GeneratorTarget->GetExecutableNames(config);
  3206. } else {
  3207. targetNames = this->GeneratorTarget->GetLibraryNames(config);
  3208. }
  3209. if (this->MSTools) {
  3210. if (this->GeneratorTarget->GetPropertyAsBool("WIN32_EXECUTABLE")) {
  3211. if (this->GlobalGenerator->TargetsWindowsCE()) {
  3212. linkOptions.AddFlag("SubSystem", "WindowsCE");
  3213. if (this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE) {
  3214. if (this->ClOptions[config]->UsingUnicode()) {
  3215. linkOptions.AddFlag("EntryPointSymbol", "wWinMainCRTStartup");
  3216. } else {
  3217. linkOptions.AddFlag("EntryPointSymbol", "WinMainCRTStartup");
  3218. }
  3219. }
  3220. } else {
  3221. linkOptions.AddFlag("SubSystem", "Windows");
  3222. }
  3223. } else {
  3224. if (this->GlobalGenerator->TargetsWindowsCE()) {
  3225. linkOptions.AddFlag("SubSystem", "WindowsCE");
  3226. if (this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE) {
  3227. if (this->ClOptions[config]->UsingUnicode()) {
  3228. linkOptions.AddFlag("EntryPointSymbol", "mainWCRTStartup");
  3229. } else {
  3230. linkOptions.AddFlag("EntryPointSymbol", "mainACRTStartup");
  3231. }
  3232. }
  3233. } else {
  3234. linkOptions.AddFlag("SubSystem", "Console");
  3235. };
  3236. }
  3237. if (const char* stackVal = this->Makefile->GetDefinition(
  3238. "CMAKE_" + linkLanguage + "_STACK_SIZE")) {
  3239. linkOptions.AddFlag("StackReserveSize", stackVal);
  3240. }
  3241. linkOptions.AddFlag("GenerateDebugInformation", "false");
  3242. std::string pdb = this->GeneratorTarget->GetPDBDirectory(config);
  3243. pdb += "/";
  3244. pdb += targetNames.PDB;
  3245. std::string imLib = this->GeneratorTarget->GetDirectory(
  3246. config, cmStateEnums::ImportLibraryArtifact);
  3247. imLib += "/";
  3248. imLib += targetNames.ImportLibrary;
  3249. linkOptions.AddFlag("ImportLibrary", imLib);
  3250. linkOptions.AddFlag("ProgramDataBaseFile", pdb);
  3251. // A Windows Runtime component uses internal .NET metadata,
  3252. // so does not have an import library.
  3253. if (this->GeneratorTarget->GetPropertyAsBool("VS_WINRT_COMPONENT") &&
  3254. this->GeneratorTarget->GetType() != cmStateEnums::EXECUTABLE) {
  3255. linkOptions.AddFlag("GenerateWindowsMetadata", "true");
  3256. } else if (this->GlobalGenerator->TargetsWindowsPhone() ||
  3257. this->GlobalGenerator->TargetsWindowsStore()) {
  3258. // WindowsPhone and WindowsStore components are in an app container
  3259. // and produce WindowsMetadata. If we are not producing a WINRT
  3260. // component, then do not generate the metadata here.
  3261. linkOptions.AddFlag("GenerateWindowsMetadata", "false");
  3262. }
  3263. if (this->GlobalGenerator->TargetsWindowsPhone() &&
  3264. this->GlobalGenerator->GetSystemVersion() == "8.0") {
  3265. // WindowsPhone 8.0 does not have ole32.
  3266. linkOptions.AppendFlag("IgnoreSpecificDefaultLibraries", "ole32.lib");
  3267. }
  3268. } else if (this->NsightTegra) {
  3269. linkOptions.AddFlag("SoName", targetNames.SharedObject);
  3270. }
  3271. linkOptions.Parse(flags);
  3272. linkOptions.FixManifestUACFlags();
  3273. if (this->MSTools) {
  3274. cmGeneratorTarget::ModuleDefinitionInfo const* mdi =
  3275. this->GeneratorTarget->GetModuleDefinitionInfo(config);
  3276. if (mdi && !mdi->DefFile.empty()) {
  3277. linkOptions.AddFlag("ModuleDefinitionFile", mdi->DefFile);
  3278. }
  3279. linkOptions.AppendFlag("IgnoreSpecificDefaultLibraries",
  3280. "%(IgnoreSpecificDefaultLibraries)");
  3281. }
  3282. // VS 2015 without all updates has a v140 toolset whose
  3283. // GenerateDebugInformation expects No/Debug instead of false/true.
  3284. if (gg->GetPlatformToolsetNeedsDebugEnum()) {
  3285. if (const char* debug = linkOptions.GetFlag("GenerateDebugInformation")) {
  3286. if (strcmp(debug, "false") == 0) {
  3287. linkOptions.AddFlag("GenerateDebugInformation", "No");
  3288. } else if (strcmp(debug, "true") == 0) {
  3289. linkOptions.AddFlag("GenerateDebugInformation", "Debug");
  3290. }
  3291. }
  3292. }
  3293. // Managed code cannot be linked with /DEBUG:FASTLINK
  3294. if (this->Managed) {
  3295. if (const char* debug = linkOptions.GetFlag("GenerateDebugInformation")) {
  3296. if (strcmp(debug, "DebugFastLink") == 0) {
  3297. linkOptions.AddFlag("GenerateDebugInformation", "Debug");
  3298. }
  3299. }
  3300. }
  3301. this->LinkOptions[config] = std::move(pOptions);
  3302. return true;
  3303. }
  3304. bool cmVisualStudio10TargetGenerator::ComputeLibOptions()
  3305. {
  3306. if (this->GeneratorTarget->GetType() == cmStateEnums::STATIC_LIBRARY) {
  3307. for (std::string const& c : this->Configurations) {
  3308. if (!this->ComputeLibOptions(c)) {
  3309. return false;
  3310. }
  3311. }
  3312. }
  3313. return true;
  3314. }
  3315. bool cmVisualStudio10TargetGenerator::ComputeLibOptions(
  3316. std::string const& config)
  3317. {
  3318. cmComputeLinkInformation* pcli =
  3319. this->GeneratorTarget->GetLinkInformation(config);
  3320. if (!pcli) {
  3321. cmSystemTools::Error(
  3322. "CMake can not compute cmComputeLinkInformation for target: " +
  3323. this->Name);
  3324. return false;
  3325. }
  3326. cmComputeLinkInformation& cli = *pcli;
  3327. typedef cmComputeLinkInformation::ItemVector ItemVector;
  3328. const ItemVector& libs = cli.GetItems();
  3329. std::string currentBinDir =
  3330. this->LocalGenerator->GetCurrentBinaryDirectory();
  3331. for (cmComputeLinkInformation::Item const& l : libs) {
  3332. if (l.IsPath && cmVS10IsTargetsFile(l.Value)) {
  3333. std::string path = this->LocalGenerator->MaybeConvertToRelativePath(
  3334. currentBinDir, l.Value);
  3335. ConvertToWindowsSlash(path);
  3336. this->AddTargetsFileAndConfigPair(path, config);
  3337. }
  3338. }
  3339. return true;
  3340. }
  3341. void cmVisualStudio10TargetGenerator::WriteLinkOptions(
  3342. Elem& e1, std::string const& config)
  3343. {
  3344. if (this->GeneratorTarget->GetType() == cmStateEnums::STATIC_LIBRARY ||
  3345. this->GeneratorTarget->GetType() > cmStateEnums::MODULE_LIBRARY) {
  3346. return;
  3347. }
  3348. if (this->ProjectType == csproj) {
  3349. return;
  3350. }
  3351. {
  3352. Elem e2(e1, "Link");
  3353. OptionsHelper linkOptions(*(this->LinkOptions[config]), e2);
  3354. linkOptions.PrependInheritedString("AdditionalOptions");
  3355. linkOptions.OutputFlagMap();
  3356. }
  3357. if (!this->GlobalGenerator->NeedLinkLibraryDependencies(
  3358. this->GeneratorTarget)) {
  3359. Elem e2(e1, "ProjectReference");
  3360. e2.Element("LinkLibraryDependencies", "false");
  3361. }
  3362. }
  3363. void cmVisualStudio10TargetGenerator::AddLibraries(
  3364. const cmComputeLinkInformation& cli, std::vector<std::string>& libVec,
  3365. std::vector<std::string>& vsTargetVec, const std::string& config)
  3366. {
  3367. typedef cmComputeLinkInformation::ItemVector ItemVector;
  3368. ItemVector const& libs = cli.GetItems();
  3369. std::string currentBinDir =
  3370. this->LocalGenerator->GetCurrentBinaryDirectory();
  3371. for (cmComputeLinkInformation::Item const& l : libs) {
  3372. if (l.Target) {
  3373. auto managedType = l.Target->GetManagedType(config);
  3374. if (managedType != cmGeneratorTarget::ManagedType::Native &&
  3375. this->GeneratorTarget->GetManagedType(config) !=
  3376. cmGeneratorTarget::ManagedType::Native &&
  3377. l.Target->IsImported()) {
  3378. auto location = l.Target->GetFullPath(config);
  3379. if (!location.empty()) {
  3380. ConvertToWindowsSlash(location);
  3381. switch (this->ProjectType) {
  3382. case csproj:
  3383. // If the target we want to "link" to is an imported managed
  3384. // target and this is a C# project, we add a hint reference. This
  3385. // reference is written to project file in
  3386. // WriteDotNetReferences().
  3387. this->DotNetHintReferences[config].push_back(
  3388. DotNetHintReference(l.Target->GetName(), location));
  3389. break;
  3390. case vcxproj:
  3391. // Add path of assembly to list of using-directories, so the
  3392. // managed assembly can be used by '#using <assembly.dll>' in
  3393. // code.
  3394. this->AdditionalUsingDirectories[config].insert(
  3395. cmSystemTools::GetFilenamePath(location));
  3396. break;
  3397. }
  3398. }
  3399. }
  3400. // Do not allow C# targets to be added to the LIB listing. LIB files are
  3401. // used for linking C++ dependencies. C# libraries do not have lib files.
  3402. // Instead, they compile down to C# reference libraries (DLL files). The
  3403. // `<ProjectReference>` elements added to the vcxproj are enough for the
  3404. // IDE to deduce the DLL file required by other C# projects that need its
  3405. // reference library.
  3406. if (managedType == cmGeneratorTarget::ManagedType::Managed) {
  3407. continue;
  3408. }
  3409. }
  3410. if (l.IsPath) {
  3411. std::string path = this->LocalGenerator->MaybeConvertToRelativePath(
  3412. currentBinDir, l.Value);
  3413. ConvertToWindowsSlash(path);
  3414. if (cmVS10IsTargetsFile(l.Value)) {
  3415. vsTargetVec.push_back(path);
  3416. } else {
  3417. libVec.push_back(path);
  3418. }
  3419. } else if (!l.Target ||
  3420. l.Target->GetType() != cmStateEnums::INTERFACE_LIBRARY) {
  3421. libVec.push_back(l.Value);
  3422. }
  3423. }
  3424. }
  3425. void cmVisualStudio10TargetGenerator::AddTargetsFileAndConfigPair(
  3426. std::string const& targetsFile, std::string const& config)
  3427. {
  3428. for (TargetsFileAndConfigs& i : this->TargetsFileAndConfigsVec) {
  3429. if (cmSystemTools::ComparePath(targetsFile, i.File)) {
  3430. if (std::find(i.Configs.begin(), i.Configs.end(), config) ==
  3431. i.Configs.end()) {
  3432. i.Configs.push_back(config);
  3433. }
  3434. return;
  3435. }
  3436. }
  3437. TargetsFileAndConfigs entry;
  3438. entry.File = targetsFile;
  3439. entry.Configs.push_back(config);
  3440. this->TargetsFileAndConfigsVec.push_back(entry);
  3441. }
  3442. void cmVisualStudio10TargetGenerator::WriteMidlOptions(
  3443. Elem& e1, std::string const& configName)
  3444. {
  3445. if (!this->MSTools) {
  3446. return;
  3447. }
  3448. if (this->ProjectType == csproj) {
  3449. return;
  3450. }
  3451. // This processes *any* of the .idl files specified in the project's file
  3452. // list (and passed as the item metadata %(Filename) expressing the rule
  3453. // input filename) into output files at the per-config *build* dir
  3454. // ($(IntDir)) each.
  3455. //
  3456. // IOW, this MIDL section is intended to provide a fully generic syntax
  3457. // content suitable for most cases (read: if you get errors, then it's quite
  3458. // probable that the error is on your side of the .idl setup).
  3459. //
  3460. // Also, note that the marked-as-generated _i.c file in the Visual Studio
  3461. // generator case needs to be referred to as $(IntDir)\foo_i.c at the
  3462. // project's file list, otherwise the compiler-side processing won't pick it
  3463. // up (for non-directory form, it ends up looking in project binary dir
  3464. // only). Perhaps there's something to be done to make this more automatic
  3465. // on the CMake side?
  3466. std::vector<std::string> const includes =
  3467. this->GetIncludes(configName, "MIDL");
  3468. std::ostringstream oss;
  3469. for (std::string const& i : includes) {
  3470. oss << i << ";";
  3471. }
  3472. oss << "%(AdditionalIncludeDirectories)";
  3473. Elem e2(e1, "Midl");
  3474. e2.Element("AdditionalIncludeDirectories", oss.str());
  3475. e2.Element("OutputDirectory", "$(ProjectDir)/$(IntDir)");
  3476. e2.Element("HeaderFileName", "%(Filename).h");
  3477. e2.Element("TypeLibraryName", "%(Filename).tlb");
  3478. e2.Element("InterfaceIdentifierFileName", "%(Filename)_i.c");
  3479. e2.Element("ProxyFileName", "%(Filename)_p.c");
  3480. }
  3481. void cmVisualStudio10TargetGenerator::WriteItemDefinitionGroups(Elem& e0)
  3482. {
  3483. if (this->ProjectType == csproj) {
  3484. return;
  3485. }
  3486. for (const std::string& c : this->Configurations) {
  3487. Elem e1(e0, "ItemDefinitionGroup");
  3488. e1.Attribute("Condition", this->CalcCondition(c));
  3489. // output cl compile flags <ClCompile></ClCompile>
  3490. if (this->GeneratorTarget->GetType() <= cmStateEnums::OBJECT_LIBRARY) {
  3491. this->WriteClOptions(e1, c);
  3492. // output rc compile flags <ResourceCompile></ResourceCompile>
  3493. this->WriteRCOptions(e1, c);
  3494. this->WriteCudaOptions(e1, c);
  3495. this->WriteMasmOptions(e1, c);
  3496. this->WriteNasmOptions(e1, c);
  3497. }
  3498. // output midl flags <Midl></Midl>
  3499. this->WriteMidlOptions(e1, c);
  3500. // write events
  3501. if (this->ProjectType != csproj) {
  3502. this->WriteEvents(e1, c);
  3503. }
  3504. // output link flags <Link></Link>
  3505. this->WriteLinkOptions(e1, c);
  3506. this->WriteCudaLinkOptions(e1, c);
  3507. // output lib flags <Lib></Lib>
  3508. this->WriteLibOptions(e1, c);
  3509. // output manifest flags <Manifest></Manifest>
  3510. this->WriteManifestOptions(e1, c);
  3511. if (this->NsightTegra &&
  3512. this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE &&
  3513. this->GeneratorTarget->GetPropertyAsBool("ANDROID_GUI")) {
  3514. this->WriteAntBuildOptions(e1, c);
  3515. }
  3516. }
  3517. }
  3518. void cmVisualStudio10TargetGenerator::WriteEvents(
  3519. Elem& e1, std::string const& configName)
  3520. {
  3521. bool addedPrelink = false;
  3522. cmGeneratorTarget::ModuleDefinitionInfo const* mdi =
  3523. this->GeneratorTarget->GetModuleDefinitionInfo(configName);
  3524. if (mdi && mdi->DefFileGenerated) {
  3525. addedPrelink = true;
  3526. std::vector<cmCustomCommand> commands =
  3527. this->GeneratorTarget->GetPreLinkCommands();
  3528. this->GlobalGenerator->AddSymbolExportCommand(this->GeneratorTarget,
  3529. commands, configName);
  3530. this->WriteEvent(e1, "PreLinkEvent", commands, configName);
  3531. }
  3532. if (!addedPrelink) {
  3533. this->WriteEvent(e1, "PreLinkEvent",
  3534. this->GeneratorTarget->GetPreLinkCommands(), configName);
  3535. }
  3536. this->WriteEvent(e1, "PreBuildEvent",
  3537. this->GeneratorTarget->GetPreBuildCommands(), configName);
  3538. this->WriteEvent(e1, "PostBuildEvent",
  3539. this->GeneratorTarget->GetPostBuildCommands(), configName);
  3540. }
  3541. void cmVisualStudio10TargetGenerator::WriteEvent(
  3542. Elem& e1, const char* name, std::vector<cmCustomCommand> const& commands,
  3543. std::string const& configName)
  3544. {
  3545. if (commands.empty()) {
  3546. return;
  3547. }
  3548. cmLocalVisualStudio7Generator* lg = this->LocalGenerator;
  3549. std::string script;
  3550. const char* pre = "";
  3551. std::string comment;
  3552. for (cmCustomCommand const& cc : commands) {
  3553. cmCustomCommandGenerator ccg(cc, configName, lg);
  3554. if (!ccg.HasOnlyEmptyCommandLines()) {
  3555. comment += pre;
  3556. comment += lg->ConstructComment(ccg);
  3557. script += pre;
  3558. pre = "\n";
  3559. script += lg->ConstructScript(ccg);
  3560. }
  3561. }
  3562. comment = cmVS10EscapeComment(comment);
  3563. if (this->ProjectType != csproj) {
  3564. Elem e2(e1, name);
  3565. e2.Element("Message", comment);
  3566. e2.Element("Command", script);
  3567. } else {
  3568. std::string strippedComment = comment;
  3569. strippedComment.erase(
  3570. std::remove(strippedComment.begin(), strippedComment.end(), '\t'),
  3571. strippedComment.end());
  3572. std::ostringstream oss;
  3573. if (!comment.empty() && !strippedComment.empty()) {
  3574. oss << "echo " << comment << "\n";
  3575. }
  3576. oss << script << "\n";
  3577. e1.Element(name, oss.str());
  3578. }
  3579. }
  3580. void cmVisualStudio10TargetGenerator::WriteProjectReferences(Elem& e0)
  3581. {
  3582. cmGlobalGenerator::TargetDependSet const& unordered =
  3583. this->GlobalGenerator->GetTargetDirectDepends(this->GeneratorTarget);
  3584. typedef cmGlobalVisualStudioGenerator::OrderedTargetDependSet
  3585. OrderedTargetDependSet;
  3586. OrderedTargetDependSet depends(unordered, CMAKE_CHECK_BUILD_SYSTEM_TARGET);
  3587. Elem e1(e0, "ItemGroup");
  3588. e1.SetHasElements();
  3589. for (cmGeneratorTarget const* dt : depends) {
  3590. if (dt->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
  3591. continue;
  3592. }
  3593. // skip fortran targets as they can not be processed by MSBuild
  3594. // the only reference will be in the .sln file
  3595. if (this->GlobalGenerator->TargetIsFortranOnly(dt)) {
  3596. continue;
  3597. }
  3598. cmLocalGenerator* lg = dt->GetLocalGenerator();
  3599. std::string name = dt->GetName();
  3600. std::string path;
  3601. const char* p = dt->GetProperty("EXTERNAL_MSPROJECT");
  3602. if (p) {
  3603. path = p;
  3604. } else {
  3605. path = lg->GetCurrentBinaryDirectory();
  3606. path += "/";
  3607. path += dt->GetName();
  3608. path += 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. cmSystemTools::ExpandListArgument(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 (auto const& p : props) {
  4306. static const std::string propNamePrefix = "VS_CSHARP_";
  4307. if (p.first.find(propNamePrefix) == 0) {
  4308. std::string tagName = p.first.substr(propNamePrefix.length());
  4309. if (!tagName.empty()) {
  4310. const std::string val = props.GetPropertyValue(p.first);
  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 = cmSystemTools::GetCMakeRoot() + "/";
  4351. path += relativeFilePath;
  4352. ConvertToWindowsSlash(path);
  4353. return path;
  4354. }