cmVisualStudio10TargetGenerator.cxx 165 KB

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