cmVisualStudio10TargetGenerator.cxx 165 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697
  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, propsLocal, false, true,
  578. 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 + cmSystemTools::GetLastSystemError());
  1232. }
  1233. }
  1234. }
  1235. cmLocalVisualStudio7Generator* lg = this->LocalGenerator;
  1236. std::unique_ptr<Elem> spe1;
  1237. std::unique_ptr<Elem> spe2;
  1238. if (this->ProjectType != csproj) {
  1239. spe1 = cm::make_unique<Elem>(e0, "ItemGroup");
  1240. spe2 = cm::make_unique<Elem>(*spe1, "CustomBuild");
  1241. this->WriteSource(*spe2, source);
  1242. spe2->SetHasElements();
  1243. } else {
  1244. Elem e1(e0, "ItemGroup");
  1245. Elem e2(e1, "None");
  1246. std::string link;
  1247. this->GetCSharpSourceLink(source, link);
  1248. this->WriteSource(e2, source);
  1249. e2.SetHasElements();
  1250. if (!link.empty()) {
  1251. e2.Element("Link", link);
  1252. }
  1253. }
  1254. for (std::string const& c : this->Configurations) {
  1255. cmCustomCommandGenerator ccg(command, c, lg);
  1256. std::string comment = lg->ConstructComment(ccg);
  1257. comment = cmVS10EscapeComment(comment);
  1258. std::string script = lg->ConstructScript(ccg);
  1259. // input files for custom command
  1260. std::stringstream inputs;
  1261. inputs << source->GetFullPath();
  1262. for (std::string const& d : ccg.GetDepends()) {
  1263. std::string dep;
  1264. if (lg->GetRealDependency(d, c, dep)) {
  1265. ConvertToWindowsSlash(dep);
  1266. inputs << ";" << dep;
  1267. }
  1268. }
  1269. // output files for custom command
  1270. std::stringstream outputs;
  1271. const char* sep = "";
  1272. for (std::string const& o : ccg.GetOutputs()) {
  1273. std::string out = o;
  1274. ConvertToWindowsSlash(out);
  1275. outputs << sep << out;
  1276. sep = ";";
  1277. }
  1278. if (this->ProjectType == csproj) {
  1279. std::string name = "CustomCommand_" + c + "_" +
  1280. cmSystemTools::ComputeStringMD5(sourcePath);
  1281. this->WriteCustomRuleCSharp(e0, c, name, script, inputs.str(),
  1282. outputs.str(), comment);
  1283. } else {
  1284. this->WriteCustomRuleCpp(*spe2, c, script, inputs.str(), outputs.str(),
  1285. comment);
  1286. }
  1287. }
  1288. }
  1289. void cmVisualStudio10TargetGenerator::WriteCustomRuleCpp(
  1290. Elem& e2, std::string const& config, std::string const& script,
  1291. std::string const& inputs, std::string const& outputs,
  1292. std::string const& comment)
  1293. {
  1294. const std::string cond = this->CalcCondition(config);
  1295. e2.WritePlatformConfigTag("Message", cond, comment);
  1296. e2.WritePlatformConfigTag("Command", cond, script);
  1297. e2.WritePlatformConfigTag("AdditionalInputs", cond,
  1298. inputs + ";%(AdditionalInputs)");
  1299. e2.WritePlatformConfigTag("Outputs", cond, outputs);
  1300. if (this->LocalGenerator->GetVersion() >
  1301. cmGlobalVisualStudioGenerator::VS10) {
  1302. // VS >= 11 let us turn off linking of custom command outputs.
  1303. e2.WritePlatformConfigTag("LinkObjects", cond, "false");
  1304. }
  1305. }
  1306. void cmVisualStudio10TargetGenerator::WriteCustomRuleCSharp(
  1307. Elem& e0, std::string const& config, std::string const& name,
  1308. std::string const& script, std::string const& inputs,
  1309. std::string const& outputs, std::string const& comment)
  1310. {
  1311. this->CSharpCustomCommandNames.insert(name);
  1312. Elem e1(e0, "Target");
  1313. e1.Attribute("Condition", this->CalcCondition(config));
  1314. e1.S << "\n Name=\"" << name << "\"";
  1315. e1.S << "\n Inputs=\"" << cmVS10EscapeAttr(inputs) << "\"";
  1316. e1.S << "\n Outputs=\"" << cmVS10EscapeAttr(outputs) << "\"";
  1317. if (!comment.empty()) {
  1318. Elem(e1, "Exec").Attribute("Command", "echo " + comment);
  1319. }
  1320. Elem(e1, "Exec").Attribute("Command", script);
  1321. }
  1322. std::string cmVisualStudio10TargetGenerator::ConvertPath(
  1323. std::string const& path, bool forceRelative)
  1324. {
  1325. return forceRelative
  1326. ? cmSystemTools::RelativePath(
  1327. this->LocalGenerator->GetCurrentBinaryDirectory(), path)
  1328. : path;
  1329. }
  1330. static void ConvertToWindowsSlash(std::string& s)
  1331. {
  1332. // first convert all of the slashes
  1333. std::string::size_type pos = 0;
  1334. while ((pos = s.find('/', pos)) != std::string::npos) {
  1335. s[pos] = '\\';
  1336. pos++;
  1337. }
  1338. }
  1339. void cmVisualStudio10TargetGenerator::WriteGroups()
  1340. {
  1341. if (this->ProjectType == csproj) {
  1342. return;
  1343. }
  1344. // collect up group information
  1345. std::vector<cmSourceGroup> sourceGroups = this->Makefile->GetSourceGroups();
  1346. std::vector<cmGeneratorTarget::AllConfigSource> const& sources =
  1347. this->GeneratorTarget->GetAllConfigSources();
  1348. std::set<cmSourceGroup*> groupsUsed;
  1349. for (cmGeneratorTarget::AllConfigSource const& si : sources) {
  1350. std::string const& source = si.Source->GetFullPath();
  1351. cmSourceGroup* sourceGroup =
  1352. this->Makefile->FindSourceGroup(source, sourceGroups);
  1353. groupsUsed.insert(sourceGroup);
  1354. }
  1355. if (cmSourceFile const* srcCMakeLists =
  1356. this->LocalGenerator->CreateVCProjBuildRule()) {
  1357. std::string const& source = srcCMakeLists->GetFullPath();
  1358. cmSourceGroup* sourceGroup =
  1359. this->Makefile->FindSourceGroup(source, sourceGroups);
  1360. groupsUsed.insert(sourceGroup);
  1361. }
  1362. this->AddMissingSourceGroups(groupsUsed, sourceGroups);
  1363. // Write out group file
  1364. std::string path = this->LocalGenerator->GetCurrentBinaryDirectory();
  1365. path += "/";
  1366. path += this->Name;
  1367. path += computeProjectFileExtension(this->GeneratorTarget);
  1368. path += ".filters";
  1369. cmGeneratedFileStream fout(path);
  1370. fout.SetCopyIfDifferent(true);
  1371. char magic[] = { char(0xEF), char(0xBB), char(0xBF) };
  1372. fout.write(magic, 3);
  1373. fout << "<?xml version=\"1.0\" encoding=\""
  1374. << this->GlobalGenerator->Encoding() << "\"?>"
  1375. << "\n";
  1376. {
  1377. Elem e0(fout, "Project");
  1378. e0.Attribute("ToolsVersion", this->GlobalGenerator->GetToolsVersion());
  1379. e0.Attribute("xmlns",
  1380. "http://schemas.microsoft.com/developer/msbuild/2003");
  1381. for (auto const& ti : this->Tools) {
  1382. this->WriteGroupSources(e0, ti.first, ti.second, sourceGroups);
  1383. }
  1384. // Added files are images and the manifest.
  1385. if (!this->AddedFiles.empty()) {
  1386. Elem e1(e0, "ItemGroup");
  1387. e1.SetHasElements();
  1388. for (std::string const& oi : this->AddedFiles) {
  1389. std::string fileName =
  1390. cmSystemTools::LowerCase(cmSystemTools::GetFilenameName(oi));
  1391. if (fileName == "wmappmanifest.xml") {
  1392. Elem e2(e1, "XML");
  1393. e2.Attribute("Include", oi);
  1394. e2.Element("Filter", "Resource Files");
  1395. } else if (cmSystemTools::GetFilenameExtension(fileName) ==
  1396. ".appxmanifest") {
  1397. Elem e2(e1, "AppxManifest");
  1398. e2.Attribute("Include", oi);
  1399. e2.Element("Filter", "Resource Files");
  1400. } else if (cmSystemTools::GetFilenameExtension(fileName) == ".pfx") {
  1401. Elem e2(e1, "None");
  1402. e2.Attribute("Include", oi);
  1403. e2.Element("Filter", "Resource Files");
  1404. } else {
  1405. Elem e2(e1, "Image");
  1406. e2.Attribute("Include", oi);
  1407. e2.Element("Filter", "Resource Files");
  1408. }
  1409. }
  1410. }
  1411. std::vector<cmSourceFile const*> resxObjs;
  1412. this->GeneratorTarget->GetResxSources(resxObjs, "");
  1413. if (!resxObjs.empty()) {
  1414. Elem e1(e0, "ItemGroup");
  1415. for (cmSourceFile const* oi : resxObjs) {
  1416. std::string obj = oi->GetFullPath();
  1417. ConvertToWindowsSlash(obj);
  1418. Elem e2(e1, "EmbeddedResource");
  1419. e2.Attribute("Include", obj);
  1420. e2.Element("Filter", "Resource Files");
  1421. }
  1422. }
  1423. {
  1424. Elem e1(e0, "ItemGroup");
  1425. e1.SetHasElements();
  1426. std::vector<cmSourceGroup*> groupsVec(groupsUsed.begin(),
  1427. groupsUsed.end());
  1428. std::sort(groupsVec.begin(), groupsVec.end(),
  1429. [](cmSourceGroup* l, cmSourceGroup* r) {
  1430. return l->GetFullName() < r->GetFullName();
  1431. });
  1432. for (cmSourceGroup* sg : groupsVec) {
  1433. std::string const& name = sg->GetFullName();
  1434. if (!name.empty()) {
  1435. std::string guidName = "SG_Filter_" + name;
  1436. std::string guid = this->GlobalGenerator->GetGUID(guidName);
  1437. Elem e2(e1, "Filter");
  1438. e2.Attribute("Include", name);
  1439. e2.Element("UniqueIdentifier", "{" + guid + "}");
  1440. }
  1441. }
  1442. if (!resxObjs.empty() || !this->AddedFiles.empty()) {
  1443. std::string guidName = "SG_Filter_Resource Files";
  1444. std::string guid = this->GlobalGenerator->GetGUID(guidName);
  1445. Elem e2(e1, "Filter");
  1446. e2.Attribute("Include", "Resource Files");
  1447. e2.Element("UniqueIdentifier", "{" + guid + "}");
  1448. e2.Element("Extensions",
  1449. "rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;"
  1450. "gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms");
  1451. }
  1452. }
  1453. }
  1454. fout << '\n';
  1455. if (fout.Close()) {
  1456. this->GlobalGenerator->FileReplacedDuringGenerate(path);
  1457. }
  1458. }
  1459. // Add to groupsUsed empty source groups that have non-empty children.
  1460. void cmVisualStudio10TargetGenerator::AddMissingSourceGroups(
  1461. std::set<cmSourceGroup*>& groupsUsed,
  1462. const std::vector<cmSourceGroup>& allGroups)
  1463. {
  1464. for (cmSourceGroup const& current : allGroups) {
  1465. std::vector<cmSourceGroup> const& children = current.GetGroupChildren();
  1466. if (children.empty()) {
  1467. continue; // the group is really empty
  1468. }
  1469. this->AddMissingSourceGroups(groupsUsed, children);
  1470. cmSourceGroup* current_ptr = const_cast<cmSourceGroup*>(&current);
  1471. if (groupsUsed.find(current_ptr) != groupsUsed.end()) {
  1472. continue; // group has already been added to set
  1473. }
  1474. // check if it least one of the group's descendants is not empty
  1475. // (at least one child must already have been added)
  1476. std::vector<cmSourceGroup>::const_iterator child_it = children.begin();
  1477. while (child_it != children.end()) {
  1478. cmSourceGroup* child_ptr = const_cast<cmSourceGroup*>(&(*child_it));
  1479. if (groupsUsed.find(child_ptr) != groupsUsed.end()) {
  1480. break; // found a child that was already added => add current group too
  1481. }
  1482. child_it++;
  1483. }
  1484. if (child_it == children.end()) {
  1485. continue; // no descendants have source files => ignore this group
  1486. }
  1487. groupsUsed.insert(current_ptr);
  1488. }
  1489. }
  1490. void cmVisualStudio10TargetGenerator::WriteGroupSources(
  1491. Elem& e0, std::string const& name, ToolSources const& sources,
  1492. std::vector<cmSourceGroup>& sourceGroups)
  1493. {
  1494. Elem e1(e0, "ItemGroup");
  1495. e1.SetHasElements();
  1496. for (ToolSource const& s : sources) {
  1497. cmSourceFile const* sf = s.SourceFile;
  1498. std::string const& source = sf->GetFullPath();
  1499. cmSourceGroup* sourceGroup =
  1500. this->Makefile->FindSourceGroup(source, sourceGroups);
  1501. std::string const& filter = sourceGroup->GetFullName();
  1502. std::string path = this->ConvertPath(source, s.RelativePath);
  1503. ConvertToWindowsSlash(path);
  1504. Elem e2(e1, name.c_str());
  1505. e2.Attribute("Include", path);
  1506. if (!filter.empty()) {
  1507. e2.Element("Filter", filter);
  1508. }
  1509. }
  1510. }
  1511. void cmVisualStudio10TargetGenerator::WriteHeaderSource(Elem& e1,
  1512. cmSourceFile const* sf)
  1513. {
  1514. std::string const& fileName = sf->GetFullPath();
  1515. Elem e2(e1, "ClInclude");
  1516. this->WriteSource(e2, sf);
  1517. if (this->IsResxHeader(fileName)) {
  1518. e2.Element("FileType", "CppForm");
  1519. } else if (this->IsXamlHeader(fileName)) {
  1520. std::string xamlFileName = fileName.substr(0, fileName.find_last_of("."));
  1521. e2.Element("DependentUpon", xamlFileName);
  1522. }
  1523. }
  1524. void cmVisualStudio10TargetGenerator::WriteExtraSource(Elem& e1,
  1525. cmSourceFile const* sf)
  1526. {
  1527. bool toolHasSettings = false;
  1528. const char* tool = "None";
  1529. std::string shaderType;
  1530. std::string shaderEntryPoint;
  1531. std::string shaderModel;
  1532. std::string shaderAdditionalFlags;
  1533. std::string shaderDisableOptimizations;
  1534. std::string shaderEnableDebug;
  1535. std::string shaderObjectFileName;
  1536. std::string outputHeaderFile;
  1537. std::string variableName;
  1538. std::string settingsGenerator;
  1539. std::string settingsLastGenOutput;
  1540. std::string sourceLink;
  1541. std::string subType;
  1542. std::string copyToOutDir;
  1543. std::string includeInVsix;
  1544. std::string ext = cmSystemTools::LowerCase(sf->GetExtension());
  1545. if (this->ProjectType == csproj) {
  1546. // EVERY extra source file must have a <Link>, otherwise it might not
  1547. // be visible in Visual Studio at all. The path relative to current
  1548. // source- or binary-dir is used within the link, if the file is
  1549. // in none of these paths, it is added with the plain filename without
  1550. // any path. This means the file will show up at root-level of the csproj
  1551. // (where CMakeLists.txt etc. are).
  1552. if (!this->InSourceBuild) {
  1553. toolHasSettings = true;
  1554. std::string fullFileName = sf->GetFullPath();
  1555. std::string srcDir = this->Makefile->GetCurrentSourceDirectory();
  1556. std::string binDir = this->Makefile->GetCurrentBinaryDirectory();
  1557. if (fullFileName.find(binDir) != std::string::npos) {
  1558. sourceLink.clear();
  1559. } else if (fullFileName.find(srcDir) != std::string::npos) {
  1560. sourceLink = fullFileName.substr(srcDir.length() + 1);
  1561. } else {
  1562. // fallback: add plain filename without any path
  1563. sourceLink = cmsys::SystemTools::GetFilenameName(fullFileName);
  1564. }
  1565. if (!sourceLink.empty()) {
  1566. ConvertToWindowsSlash(sourceLink);
  1567. }
  1568. }
  1569. }
  1570. if (ext == "hlsl") {
  1571. tool = "FXCompile";
  1572. // Figure out the type of shader compiler to use.
  1573. if (const char* st = sf->GetProperty("VS_SHADER_TYPE")) {
  1574. shaderType = st;
  1575. toolHasSettings = true;
  1576. }
  1577. // Figure out which entry point to use if any
  1578. if (const char* se = sf->GetProperty("VS_SHADER_ENTRYPOINT")) {
  1579. shaderEntryPoint = se;
  1580. toolHasSettings = true;
  1581. }
  1582. // Figure out which shader model to use if any
  1583. if (const char* sm = sf->GetProperty("VS_SHADER_MODEL")) {
  1584. shaderModel = sm;
  1585. toolHasSettings = true;
  1586. }
  1587. // Figure out which output header file to use if any
  1588. if (const char* ohf = sf->GetProperty("VS_SHADER_OUTPUT_HEADER_FILE")) {
  1589. outputHeaderFile = ohf;
  1590. toolHasSettings = true;
  1591. }
  1592. // Figure out which variable name to use if any
  1593. if (const char* vn = sf->GetProperty("VS_SHADER_VARIABLE_NAME")) {
  1594. variableName = vn;
  1595. toolHasSettings = true;
  1596. }
  1597. // Figure out if there's any additional flags to use
  1598. if (const char* saf = sf->GetProperty("VS_SHADER_FLAGS")) {
  1599. shaderAdditionalFlags = saf;
  1600. toolHasSettings = true;
  1601. }
  1602. // Figure out if debug information should be generated
  1603. if (const char* sed = sf->GetProperty("VS_SHADER_ENABLE_DEBUG")) {
  1604. shaderEnableDebug = sed;
  1605. toolHasSettings = true;
  1606. }
  1607. // Figure out if optimizations should be disabled
  1608. if (const char* sdo = sf->GetProperty("VS_SHADER_DISABLE_OPTIMIZATIONS")) {
  1609. shaderDisableOptimizations = sdo;
  1610. toolHasSettings = true;
  1611. }
  1612. if (const char* sofn = sf->GetProperty("VS_SHADER_OBJECT_FILE_NAME")) {
  1613. shaderObjectFileName = sofn;
  1614. toolHasSettings = true;
  1615. }
  1616. } else if (ext == "jpg" || ext == "png") {
  1617. tool = "Image";
  1618. } else if (ext == "resw") {
  1619. tool = "PRIResource";
  1620. } else if (ext == "xml") {
  1621. tool = "XML";
  1622. } else if (ext == "natvis") {
  1623. tool = "Natvis";
  1624. } else if (ext == "settings") {
  1625. settingsLastGenOutput =
  1626. cmsys::SystemTools::GetFilenameName(sf->GetFullPath());
  1627. std::size_t pos = settingsLastGenOutput.find(".settings");
  1628. settingsLastGenOutput.replace(pos, 9, ".Designer.cs");
  1629. settingsGenerator = "SettingsSingleFileGenerator";
  1630. toolHasSettings = true;
  1631. } else if (ext == "vsixmanifest") {
  1632. subType = "Designer";
  1633. }
  1634. if (const char* c = sf->GetProperty("VS_COPY_TO_OUT_DIR")) {
  1635. tool = "Content";
  1636. copyToOutDir = c;
  1637. toolHasSettings = true;
  1638. }
  1639. if (sf->GetPropertyAsBool("VS_INCLUDE_IN_VSIX")) {
  1640. includeInVsix = "True";
  1641. tool = "Content";
  1642. toolHasSettings = true;
  1643. }
  1644. // Collect VS_CSHARP_* property values (if some are set)
  1645. std::map<std::string, std::string> sourceFileTags;
  1646. this->GetCSharpSourceProperties(sf, sourceFileTags);
  1647. if (this->NsightTegra) {
  1648. // Nsight Tegra needs specific file types to check up-to-dateness.
  1649. std::string name = cmSystemTools::LowerCase(sf->GetLocation().GetName());
  1650. if (name == "androidmanifest.xml" || name == "build.xml" ||
  1651. name == "proguard.cfg" || name == "proguard-project.txt" ||
  1652. ext == "properties") {
  1653. tool = "AndroidBuild";
  1654. } else if (ext == "java") {
  1655. tool = "JCompile";
  1656. } else if (ext == "asm" || ext == "s") {
  1657. tool = "ClCompile";
  1658. }
  1659. }
  1660. const char* toolOverride = sf->GetProperty("VS_TOOL_OVERRIDE");
  1661. if (toolOverride && *toolOverride) {
  1662. tool = toolOverride;
  1663. }
  1664. std::string deployContent;
  1665. std::string deployLocation;
  1666. if (this->GlobalGenerator->TargetsWindowsPhone() ||
  1667. this->GlobalGenerator->TargetsWindowsStore()) {
  1668. const char* content = sf->GetProperty("VS_DEPLOYMENT_CONTENT");
  1669. if (content && *content) {
  1670. toolHasSettings = true;
  1671. deployContent = content;
  1672. const char* location = sf->GetProperty("VS_DEPLOYMENT_LOCATION");
  1673. if (location && *location) {
  1674. deployLocation = location;
  1675. }
  1676. }
  1677. }
  1678. Elem e2(e1, tool);
  1679. this->WriteSource(e2, sf);
  1680. if (toolHasSettings) {
  1681. e2.SetHasElements();
  1682. if (!deployContent.empty()) {
  1683. cmGeneratorExpression ge;
  1684. std::unique_ptr<cmCompiledGeneratorExpression> cge =
  1685. ge.Parse(deployContent);
  1686. // Deployment location cannot be set on a configuration basis
  1687. if (!deployLocation.empty()) {
  1688. e2.Element("Link", deployLocation + "\\%(FileName)%(Extension)");
  1689. }
  1690. for (size_t i = 0; i != this->Configurations.size(); ++i) {
  1691. if (cge->Evaluate(this->LocalGenerator, this->Configurations[i]) ==
  1692. "1") {
  1693. e2.WritePlatformConfigTag("DeploymentContent",
  1694. "'$(Configuration)|$(Platform)'=='" +
  1695. this->Configurations[i] + "|" +
  1696. this->Platform + "'",
  1697. "true");
  1698. } else {
  1699. e2.WritePlatformConfigTag("ExcludedFromBuild",
  1700. "'$(Configuration)|$(Platform)'=='" +
  1701. this->Configurations[i] + "|" +
  1702. this->Platform + "'",
  1703. "true");
  1704. }
  1705. }
  1706. }
  1707. if (!shaderType.empty()) {
  1708. e2.Element("ShaderType", shaderType);
  1709. }
  1710. if (!shaderEntryPoint.empty()) {
  1711. e2.Element("EntryPointName", shaderEntryPoint);
  1712. }
  1713. if (!shaderModel.empty()) {
  1714. e2.Element("ShaderModel", shaderModel);
  1715. }
  1716. if (!outputHeaderFile.empty()) {
  1717. for (size_t i = 0; i != this->Configurations.size(); ++i) {
  1718. e2.WritePlatformConfigTag("HeaderFileOutput",
  1719. "'$(Configuration)|$(Platform)'=='" +
  1720. this->Configurations[i] + "|" +
  1721. this->Platform + "'",
  1722. outputHeaderFile);
  1723. }
  1724. }
  1725. if (!variableName.empty()) {
  1726. for (size_t i = 0; i != this->Configurations.size(); ++i) {
  1727. e2.WritePlatformConfigTag("VariableName",
  1728. "'$(Configuration)|$(Platform)'=='" +
  1729. this->Configurations[i] + "|" +
  1730. this->Platform + "'",
  1731. variableName);
  1732. }
  1733. }
  1734. if (!shaderEnableDebug.empty()) {
  1735. cmGeneratorExpression ge;
  1736. std::unique_ptr<cmCompiledGeneratorExpression> cge =
  1737. ge.Parse(shaderEnableDebug);
  1738. for (size_t i = 0; i != this->Configurations.size(); ++i) {
  1739. const std::string& enableDebug =
  1740. cge->Evaluate(this->LocalGenerator, this->Configurations[i]);
  1741. if (!enableDebug.empty()) {
  1742. e2.WritePlatformConfigTag(
  1743. "EnableDebuggingInformation",
  1744. "'$(Configuration)|$(Platform)'=='" + this->Configurations[i] +
  1745. "|" + this->Platform + "'",
  1746. cmSystemTools::IsOn(enableDebug) ? "true" : "false");
  1747. }
  1748. }
  1749. }
  1750. if (!shaderDisableOptimizations.empty()) {
  1751. cmGeneratorExpression ge;
  1752. std::unique_ptr<cmCompiledGeneratorExpression> cge =
  1753. ge.Parse(shaderDisableOptimizations);
  1754. for (size_t i = 0; i != this->Configurations.size(); ++i) {
  1755. const std::string& disableOptimizations =
  1756. cge->Evaluate(this->LocalGenerator, this->Configurations[i]);
  1757. if (!disableOptimizations.empty()) {
  1758. e2.WritePlatformConfigTag(
  1759. "DisableOptimizations",
  1760. "'$(Configuration)|$(Platform)'=='" + this->Configurations[i] +
  1761. "|" + this->Platform + "'",
  1762. (cmSystemTools::IsOn(disableOptimizations) ? "true" : "false"));
  1763. }
  1764. }
  1765. }
  1766. if (!shaderObjectFileName.empty()) {
  1767. e2.Element("ObjectFileOutput", shaderObjectFileName);
  1768. }
  1769. if (!shaderAdditionalFlags.empty()) {
  1770. e2.Element("AdditionalOptions", shaderAdditionalFlags);
  1771. }
  1772. if (!settingsGenerator.empty()) {
  1773. e2.Element("Generator", settingsGenerator);
  1774. }
  1775. if (!settingsLastGenOutput.empty()) {
  1776. e2.Element("LastGenOutput", settingsLastGenOutput);
  1777. }
  1778. if (!sourceLink.empty()) {
  1779. e2.Element("Link", sourceLink);
  1780. }
  1781. if (!subType.empty()) {
  1782. e2.Element("SubType", subType);
  1783. }
  1784. if (!copyToOutDir.empty()) {
  1785. e2.Element("CopyToOutputDirectory", copyToOutDir);
  1786. }
  1787. if (!includeInVsix.empty()) {
  1788. e2.Element("IncludeInVSIX", includeInVsix);
  1789. }
  1790. // write source file specific tags
  1791. this->WriteCSharpSourceProperties(e2, sourceFileTags);
  1792. }
  1793. }
  1794. void cmVisualStudio10TargetGenerator::WriteSource(Elem& e2,
  1795. cmSourceFile const* sf)
  1796. {
  1797. // Visual Studio tools append relative paths to the current dir, as in:
  1798. //
  1799. // c:\path\to\current\dir\..\..\..\relative\path\to\source.c
  1800. //
  1801. // and fail if this exceeds the maximum allowed path length. Our path
  1802. // conversion uses full paths when possible to allow deeper trees.
  1803. // However, CUDA 8.0 msbuild rules fail on absolute paths so for CUDA
  1804. // we must use relative paths.
  1805. bool forceRelative = sf->GetLanguage() == "CUDA";
  1806. std::string sourceFile = this->ConvertPath(sf->GetFullPath(), forceRelative);
  1807. if (this->LocalGenerator->GetVersion() ==
  1808. cmGlobalVisualStudioGenerator::VS10 &&
  1809. cmSystemTools::FileIsFullPath(sourceFile)) {
  1810. // Normal path conversion resulted in a full path. VS 10 (but not 11)
  1811. // refuses to show the property page in the IDE for a source file with a
  1812. // full path (not starting in a '.' or '/' AFAICT). CMake <= 2.8.4 used a
  1813. // relative path but to allow deeper build trees CMake 2.8.[5678] used a
  1814. // full path except for custom commands. Custom commands do not work
  1815. // without a relative path, but they do not seem to be involved in tools
  1816. // with the above behavior. For other sources we now use a relative path
  1817. // when the combined path will not be too long so property pages appear.
  1818. std::string sourceRel = this->ConvertPath(sf->GetFullPath(), true);
  1819. size_t const maxLen = 250;
  1820. if (sf->GetCustomCommand() ||
  1821. ((this->LocalGenerator->GetCurrentBinaryDirectory().length() + 1 +
  1822. sourceRel.length()) <= maxLen)) {
  1823. forceRelative = true;
  1824. sourceFile = sourceRel;
  1825. } else {
  1826. this->GlobalGenerator->PathTooLong(this->GeneratorTarget, sf, sourceRel);
  1827. }
  1828. }
  1829. ConvertToWindowsSlash(sourceFile);
  1830. e2.Attribute("Include", sourceFile);
  1831. ToolSource toolSource = { sf, forceRelative };
  1832. this->Tools[e2.Tag].push_back(toolSource);
  1833. }
  1834. void cmVisualStudio10TargetGenerator::WriteAllSources(Elem& e0)
  1835. {
  1836. if (this->GeneratorTarget->GetType() > cmStateEnums::UTILITY) {
  1837. return;
  1838. }
  1839. Elem e1(e0, "ItemGroup");
  1840. e1.SetHasElements();
  1841. std::vector<size_t> all_configs;
  1842. for (size_t ci = 0; ci < this->Configurations.size(); ++ci) {
  1843. all_configs.push_back(ci);
  1844. }
  1845. std::vector<cmGeneratorTarget::AllConfigSource> const& sources =
  1846. this->GeneratorTarget->GetAllConfigSources();
  1847. cmSourceFile const* srcCMakeLists =
  1848. this->LocalGenerator->CreateVCProjBuildRule();
  1849. for (cmGeneratorTarget::AllConfigSource const& si : sources) {
  1850. if (si.Source == srcCMakeLists) {
  1851. // Skip explicit reference to CMakeLists.txt source.
  1852. continue;
  1853. }
  1854. const char* tool = nullptr;
  1855. switch (si.Kind) {
  1856. case cmGeneratorTarget::SourceKindAppManifest:
  1857. tool = "AppxManifest";
  1858. break;
  1859. case cmGeneratorTarget::SourceKindCertificate:
  1860. tool = "None";
  1861. break;
  1862. case cmGeneratorTarget::SourceKindCustomCommand:
  1863. // Handled elsewhere.
  1864. break;
  1865. case cmGeneratorTarget::SourceKindExternalObject:
  1866. tool = "Object";
  1867. if (this->LocalGenerator->GetVersion() <
  1868. cmGlobalVisualStudioGenerator::VS11) {
  1869. // For VS == 10 we cannot use LinkObjects to avoid linking custom
  1870. // command outputs. If an object file is generated in this target,
  1871. // then vs10 will use it in the build, and we have to list it as
  1872. // None instead of Object.
  1873. std::vector<cmSourceFile*> const* d =
  1874. this->GeneratorTarget->GetSourceDepends(si.Source);
  1875. if (d && !d->empty()) {
  1876. tool = "None";
  1877. }
  1878. }
  1879. break;
  1880. case cmGeneratorTarget::SourceKindExtra:
  1881. this->WriteExtraSource(e1, si.Source);
  1882. break;
  1883. case cmGeneratorTarget::SourceKindHeader:
  1884. this->WriteHeaderSource(e1, si.Source);
  1885. break;
  1886. case cmGeneratorTarget::SourceKindIDL:
  1887. tool = "Midl";
  1888. break;
  1889. case cmGeneratorTarget::SourceKindManifest:
  1890. // Handled elsewhere.
  1891. break;
  1892. case cmGeneratorTarget::SourceKindModuleDefinition:
  1893. tool = "None";
  1894. break;
  1895. case cmGeneratorTarget::SourceKindObjectSource: {
  1896. const std::string& lang = si.Source->GetLanguage();
  1897. if (lang == "C" || lang == "CXX") {
  1898. tool = "ClCompile";
  1899. } else if (lang == "ASM_MASM" &&
  1900. this->GlobalGenerator->IsMasmEnabled()) {
  1901. tool = "MASM";
  1902. } else if (lang == "ASM_NASM" &&
  1903. this->GlobalGenerator->IsNasmEnabled()) {
  1904. tool = "NASM";
  1905. } else if (lang == "RC") {
  1906. tool = "ResourceCompile";
  1907. } else if (lang == "CSharp") {
  1908. tool = "Compile";
  1909. } else if (lang == "CUDA" && this->GlobalGenerator->IsCudaEnabled()) {
  1910. tool = "CudaCompile";
  1911. } else {
  1912. tool = "None";
  1913. }
  1914. } break;
  1915. case cmGeneratorTarget::SourceKindResx:
  1916. // Handled elsewhere.
  1917. break;
  1918. case cmGeneratorTarget::SourceKindXaml:
  1919. // Handled elsewhere.
  1920. break;
  1921. }
  1922. if (tool) {
  1923. // Compute set of configurations to exclude, if any.
  1924. std::vector<size_t> const& include_configs = si.Configs;
  1925. std::vector<size_t> exclude_configs;
  1926. std::set_difference(all_configs.begin(), all_configs.end(),
  1927. include_configs.begin(), include_configs.end(),
  1928. std::back_inserter(exclude_configs));
  1929. Elem e2(e1, tool);
  1930. this->WriteSource(e2, si.Source);
  1931. if (si.Kind == cmGeneratorTarget::SourceKindObjectSource) {
  1932. this->OutputSourceSpecificFlags(e2, si.Source);
  1933. }
  1934. if (!exclude_configs.empty()) {
  1935. this->WriteExcludeFromBuild(e2, exclude_configs);
  1936. }
  1937. }
  1938. }
  1939. if (this->IsMissingFiles) {
  1940. this->WriteMissingFiles(e1);
  1941. }
  1942. }
  1943. void cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags(
  1944. Elem& e2, cmSourceFile const* source)
  1945. {
  1946. cmSourceFile const& sf = *source;
  1947. std::string objectName;
  1948. if (this->GeneratorTarget->HasExplicitObjectName(&sf)) {
  1949. objectName = this->GeneratorTarget->GetObjectName(&sf);
  1950. }
  1951. std::string flags;
  1952. bool configDependentFlags = false;
  1953. std::string options;
  1954. bool configDependentOptions = false;
  1955. std::string defines;
  1956. bool configDependentDefines = false;
  1957. std::string includes;
  1958. bool configDependentIncludes = false;
  1959. if (const char* cflags = sf.GetProperty("COMPILE_FLAGS")) {
  1960. configDependentFlags =
  1961. cmGeneratorExpression::Find(cflags) != std::string::npos;
  1962. flags += cflags;
  1963. }
  1964. if (const char* coptions = sf.GetProperty("COMPILE_OPTIONS")) {
  1965. configDependentOptions =
  1966. cmGeneratorExpression::Find(coptions) != std::string::npos;
  1967. options += coptions;
  1968. }
  1969. if (const char* cdefs = sf.GetProperty("COMPILE_DEFINITIONS")) {
  1970. configDependentDefines =
  1971. cmGeneratorExpression::Find(cdefs) != std::string::npos;
  1972. defines += cdefs;
  1973. }
  1974. if (const char* cincludes = sf.GetProperty("INCLUDE_DIRECTORIES")) {
  1975. configDependentIncludes =
  1976. cmGeneratorExpression::Find(cincludes) != std::string::npos;
  1977. includes += cincludes;
  1978. }
  1979. std::string lang =
  1980. this->GlobalGenerator->GetLanguageFromExtension(sf.GetExtension().c_str());
  1981. std::string sourceLang = this->LocalGenerator->GetSourceFileLanguage(sf);
  1982. const std::string& linkLanguage =
  1983. this->GeneratorTarget->GetLinkerLanguage("");
  1984. bool needForceLang = false;
  1985. // source file does not match its extension language
  1986. if (lang != sourceLang) {
  1987. needForceLang = true;
  1988. lang = sourceLang;
  1989. }
  1990. // if the source file does not match the linker language
  1991. // then force c or c++
  1992. const char* compileAs = 0;
  1993. if (needForceLang || (linkLanguage != lang)) {
  1994. if (lang == "CXX") {
  1995. // force a C++ file type
  1996. compileAs = "CompileAsCpp";
  1997. } else if (lang == "C") {
  1998. // force to c
  1999. compileAs = "CompileAsC";
  2000. }
  2001. }
  2002. bool noWinRT = this->TargetCompileAsWinRT && lang == "C";
  2003. // for the first time we need a new line if there is something
  2004. // produced here.
  2005. if (!objectName.empty()) {
  2006. if (lang == "CUDA") {
  2007. e2.Element("CompileOut", "$(IntDir)/" + objectName);
  2008. } else {
  2009. e2.Element("ObjectFileName", "$(IntDir)/" + objectName);
  2010. }
  2011. }
  2012. for (std::string const& config : this->Configurations) {
  2013. std::string configUpper = cmSystemTools::UpperCase(config);
  2014. std::string configDefines = defines;
  2015. std::string defPropName = "COMPILE_DEFINITIONS_";
  2016. defPropName += configUpper;
  2017. if (const char* ccdefs = sf.GetProperty(defPropName)) {
  2018. if (!configDefines.empty()) {
  2019. configDefines += ";";
  2020. }
  2021. configDependentDefines |=
  2022. cmGeneratorExpression::Find(ccdefs) != std::string::npos;
  2023. configDefines += ccdefs;
  2024. }
  2025. // if we have flags or defines for this config then
  2026. // use them
  2027. if (!flags.empty() || !options.empty() || !configDefines.empty() ||
  2028. !includes.empty() || compileAs || noWinRT) {
  2029. cmGlobalVisualStudio10Generator* gg = this->GlobalGenerator;
  2030. cmIDEFlagTable const* flagtable = nullptr;
  2031. const std::string& srclang = source->GetLanguage();
  2032. if (srclang == "C" || srclang == "CXX") {
  2033. flagtable = gg->GetClFlagTable();
  2034. } else if (srclang == "ASM_MASM" &&
  2035. this->GlobalGenerator->IsMasmEnabled()) {
  2036. flagtable = gg->GetMasmFlagTable();
  2037. } else if (lang == "ASM_NASM" &&
  2038. this->GlobalGenerator->IsNasmEnabled()) {
  2039. flagtable = gg->GetNasmFlagTable();
  2040. } else if (srclang == "RC") {
  2041. flagtable = gg->GetRcFlagTable();
  2042. } else if (srclang == "CSharp") {
  2043. flagtable = gg->GetCSharpFlagTable();
  2044. }
  2045. cmGeneratorExpressionInterpreter genexInterpreter(
  2046. this->LocalGenerator, config, this->GeneratorTarget, lang);
  2047. cmVS10GeneratorOptions clOptions(
  2048. this->LocalGenerator, cmVisualStudioGeneratorOptions::Compiler,
  2049. flagtable, this);
  2050. if (compileAs) {
  2051. clOptions.AddFlag("CompileAs", compileAs);
  2052. }
  2053. if (noWinRT) {
  2054. clOptions.AddFlag("CompileAsWinRT", "false");
  2055. }
  2056. if (configDependentFlags) {
  2057. clOptions.Parse(genexInterpreter.Evaluate(flags, "COMPILE_FLAGS"));
  2058. } else {
  2059. clOptions.Parse(flags);
  2060. }
  2061. if (!options.empty()) {
  2062. std::string expandedOptions;
  2063. if (configDependentOptions) {
  2064. this->LocalGenerator->AppendCompileOptions(
  2065. expandedOptions,
  2066. genexInterpreter.Evaluate(options, "COMPILE_OPTIONS"));
  2067. } else {
  2068. this->LocalGenerator->AppendCompileOptions(expandedOptions, options);
  2069. }
  2070. clOptions.Parse(expandedOptions);
  2071. }
  2072. if (clOptions.HasFlag("DisableSpecificWarnings")) {
  2073. clOptions.AppendFlag("DisableSpecificWarnings",
  2074. "%(DisableSpecificWarnings)");
  2075. }
  2076. if (configDependentDefines) {
  2077. clOptions.AddDefines(
  2078. genexInterpreter.Evaluate(configDefines, "COMPILE_DEFINITIONS"));
  2079. } else {
  2080. clOptions.AddDefines(configDefines);
  2081. }
  2082. std::vector<std::string> includeList;
  2083. if (configDependentIncludes) {
  2084. this->LocalGenerator->AppendIncludeDirectories(
  2085. includeList,
  2086. genexInterpreter.Evaluate(includes, "INCLUDE_DIRECTORIES"), *source);
  2087. } else {
  2088. this->LocalGenerator->AppendIncludeDirectories(includeList, includes,
  2089. *source);
  2090. }
  2091. clOptions.AddIncludes(includeList);
  2092. clOptions.SetConfiguration(config);
  2093. OptionsHelper oh(clOptions, e2);
  2094. oh.PrependInheritedString("AdditionalOptions");
  2095. oh.OutputAdditionalIncludeDirectories(lang);
  2096. oh.OutputFlagMap();
  2097. oh.OutputPreprocessorDefinitions(lang);
  2098. }
  2099. }
  2100. if (this->IsXamlSource(source->GetFullPath())) {
  2101. const std::string& fileName = source->GetFullPath();
  2102. std::string xamlFileName = fileName.substr(0, fileName.find_last_of("."));
  2103. e2.Element("DependentUpon", xamlFileName);
  2104. }
  2105. if (this->ProjectType == csproj) {
  2106. std::string f = source->GetFullPath();
  2107. typedef std::map<std::string, std::string> CsPropMap;
  2108. CsPropMap sourceFileTags;
  2109. // set <Link> tag if necessary
  2110. std::string link;
  2111. this->GetCSharpSourceLink(source, link);
  2112. if (!link.empty()) {
  2113. sourceFileTags["Link"] = link;
  2114. }
  2115. this->GetCSharpSourceProperties(&sf, sourceFileTags);
  2116. // write source file specific tags
  2117. if (!sourceFileTags.empty()) {
  2118. this->WriteCSharpSourceProperties(e2, sourceFileTags);
  2119. }
  2120. }
  2121. }
  2122. void cmVisualStudio10TargetGenerator::WriteExcludeFromBuild(
  2123. Elem& e2, std::vector<size_t> const& exclude_configs)
  2124. {
  2125. for (size_t ci : exclude_configs) {
  2126. e2.WritePlatformConfigTag("ExcludedFromBuild",
  2127. "'$(Configuration)|$(Platform)'=='" +
  2128. this->Configurations[ci] + "|" +
  2129. this->Platform + "'",
  2130. "true");
  2131. }
  2132. }
  2133. void cmVisualStudio10TargetGenerator::WritePathAndIncrementalLinkOptions(
  2134. Elem& e0)
  2135. {
  2136. cmStateEnums::TargetType ttype = this->GeneratorTarget->GetType();
  2137. if (ttype > cmStateEnums::GLOBAL_TARGET) {
  2138. return;
  2139. }
  2140. if (this->ProjectType == csproj) {
  2141. return;
  2142. }
  2143. Elem e1(e0, "PropertyGroup");
  2144. e1.Element("_ProjectFileVersion", "10.0.20506.1");
  2145. for (std::string const& config : this->Configurations) {
  2146. const std::string cond = this->CalcCondition(config);
  2147. if (ttype <= cmStateEnums::UTILITY) {
  2148. if (const char* workingDir = this->GeneratorTarget->GetProperty(
  2149. "VS_DEBUGGER_WORKING_DIRECTORY")) {
  2150. cmGeneratorExpression ge;
  2151. std::unique_ptr<cmCompiledGeneratorExpression> cge =
  2152. ge.Parse(workingDir);
  2153. std::string genWorkingDir =
  2154. cge->Evaluate(this->LocalGenerator, config);
  2155. e1.WritePlatformConfigTag("LocalDebuggerWorkingDirectory", cond,
  2156. genWorkingDir);
  2157. }
  2158. if (const char* environment =
  2159. this->GeneratorTarget->GetProperty("VS_DEBUGGER_ENVIRONMENT")) {
  2160. cmGeneratorExpression ge;
  2161. std::unique_ptr<cmCompiledGeneratorExpression> cge =
  2162. ge.Parse(environment);
  2163. std::string genEnvironment =
  2164. cge->Evaluate(this->LocalGenerator, config);
  2165. e1.WritePlatformConfigTag("LocalDebuggerEnvironment", cond,
  2166. genEnvironment);
  2167. }
  2168. if (const char* debuggerCommand =
  2169. this->GeneratorTarget->GetProperty("VS_DEBUGGER_COMMAND")) {
  2170. cmGeneratorExpression ge;
  2171. std::unique_ptr<cmCompiledGeneratorExpression> cge =
  2172. ge.Parse(debuggerCommand);
  2173. std::string genDebuggerCommand =
  2174. cge->Evaluate(this->LocalGenerator, config);
  2175. e1.WritePlatformConfigTag("LocalDebuggerCommand", cond,
  2176. genDebuggerCommand);
  2177. }
  2178. if (const char* commandArguments = this->GeneratorTarget->GetProperty(
  2179. "VS_DEBUGGER_COMMAND_ARGUMENTS")) {
  2180. cmGeneratorExpression ge;
  2181. std::unique_ptr<cmCompiledGeneratorExpression> cge =
  2182. ge.Parse(commandArguments);
  2183. std::string genCommandArguments =
  2184. cge->Evaluate(this->LocalGenerator, config);
  2185. e1.WritePlatformConfigTag("LocalDebuggerCommandArguments", cond,
  2186. genCommandArguments);
  2187. }
  2188. }
  2189. if (ttype >= cmStateEnums::UTILITY) {
  2190. e1.WritePlatformConfigTag(
  2191. "IntDir", cond, "$(Platform)\\$(Configuration)\\$(ProjectName)\\");
  2192. } else {
  2193. std::string intermediateDir =
  2194. this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
  2195. intermediateDir += "/";
  2196. intermediateDir += config;
  2197. intermediateDir += "/";
  2198. std::string outDir;
  2199. std::string targetNameFull;
  2200. if (ttype == cmStateEnums::OBJECT_LIBRARY) {
  2201. outDir = intermediateDir;
  2202. targetNameFull = this->GeneratorTarget->GetName();
  2203. targetNameFull += ".lib";
  2204. } else {
  2205. outDir = this->GeneratorTarget->GetDirectory(config) + "/";
  2206. targetNameFull = this->GeneratorTarget->GetFullName(config);
  2207. }
  2208. ConvertToWindowsSlash(intermediateDir);
  2209. ConvertToWindowsSlash(outDir);
  2210. e1.WritePlatformConfigTag("OutDir", cond, outDir);
  2211. e1.WritePlatformConfigTag("IntDir", cond, intermediateDir);
  2212. if (const char* sdkExecutableDirectories = this->Makefile->GetDefinition(
  2213. "CMAKE_VS_SDK_EXECUTABLE_DIRECTORIES")) {
  2214. e1.WritePlatformConfigTag("ExecutablePath", cond,
  2215. sdkExecutableDirectories);
  2216. }
  2217. if (const char* sdkIncludeDirectories = this->Makefile->GetDefinition(
  2218. "CMAKE_VS_SDK_INCLUDE_DIRECTORIES")) {
  2219. e1.WritePlatformConfigTag("IncludePath", cond, sdkIncludeDirectories);
  2220. }
  2221. if (const char* sdkReferenceDirectories = this->Makefile->GetDefinition(
  2222. "CMAKE_VS_SDK_REFERENCE_DIRECTORIES")) {
  2223. e1.WritePlatformConfigTag("ReferencePath", cond,
  2224. sdkReferenceDirectories);
  2225. }
  2226. if (const char* sdkLibraryDirectories = this->Makefile->GetDefinition(
  2227. "CMAKE_VS_SDK_LIBRARY_DIRECTORIES")) {
  2228. e1.WritePlatformConfigTag("LibraryPath", cond, sdkLibraryDirectories);
  2229. }
  2230. if (const char* sdkLibraryWDirectories = this->Makefile->GetDefinition(
  2231. "CMAKE_VS_SDK_LIBRARY_WINRT_DIRECTORIES")) {
  2232. e1.WritePlatformConfigTag("LibraryWPath", cond,
  2233. sdkLibraryWDirectories);
  2234. }
  2235. if (const char* sdkSourceDirectories =
  2236. this->Makefile->GetDefinition("CMAKE_VS_SDK_SOURCE_DIRECTORIES")) {
  2237. e1.WritePlatformConfigTag("SourcePath", cond, sdkSourceDirectories);
  2238. }
  2239. if (const char* sdkExcludeDirectories = this->Makefile->GetDefinition(
  2240. "CMAKE_VS_SDK_EXCLUDE_DIRECTORIES")) {
  2241. e1.WritePlatformConfigTag("ExcludePath", cond, sdkExcludeDirectories);
  2242. }
  2243. std::string name =
  2244. cmSystemTools::GetFilenameWithoutLastExtension(targetNameFull);
  2245. e1.WritePlatformConfigTag("TargetName", cond, name);
  2246. std::string ext =
  2247. cmSystemTools::GetFilenameLastExtension(targetNameFull);
  2248. if (ext.empty()) {
  2249. // An empty TargetExt causes a default extension to be used.
  2250. // A single "." appears to be treated as an empty extension.
  2251. ext = ".";
  2252. }
  2253. e1.WritePlatformConfigTag("TargetExt", cond, ext);
  2254. this->OutputLinkIncremental(e1, config);
  2255. }
  2256. }
  2257. }
  2258. void cmVisualStudio10TargetGenerator::OutputLinkIncremental(
  2259. Elem& e1, std::string const& configName)
  2260. {
  2261. if (!this->MSTools) {
  2262. return;
  2263. }
  2264. if (this->ProjectType == csproj) {
  2265. return;
  2266. }
  2267. // static libraries and things greater than modules do not need
  2268. // to set this option
  2269. if (this->GeneratorTarget->GetType() == cmStateEnums::STATIC_LIBRARY ||
  2270. this->GeneratorTarget->GetType() > cmStateEnums::MODULE_LIBRARY) {
  2271. return;
  2272. }
  2273. Options& linkOptions = *(this->LinkOptions[configName]);
  2274. const std::string cond = this->CalcCondition(configName);
  2275. if (this->IPOEnabledConfigurations.count(configName) == 0) {
  2276. const char* incremental = linkOptions.GetFlag("LinkIncremental");
  2277. e1.WritePlatformConfigTag("LinkIncremental", cond,
  2278. (incremental ? incremental : "true"));
  2279. }
  2280. linkOptions.RemoveFlag("LinkIncremental");
  2281. const char* manifest = linkOptions.GetFlag("GenerateManifest");
  2282. e1.WritePlatformConfigTag("GenerateManifest", cond,
  2283. (manifest ? manifest : "true"));
  2284. linkOptions.RemoveFlag("GenerateManifest");
  2285. // Some link options belong here. Use them now and remove them so that
  2286. // WriteLinkOptions does not use them.
  2287. const char* flags[] = { "LinkDelaySign", "LinkKeyFile", 0 };
  2288. for (const char** f = flags; *f; ++f) {
  2289. const char* flag = *f;
  2290. if (const char* value = linkOptions.GetFlag(flag)) {
  2291. e1.WritePlatformConfigTag(flag, cond, value);
  2292. linkOptions.RemoveFlag(flag);
  2293. }
  2294. }
  2295. }
  2296. std::vector<std::string> cmVisualStudio10TargetGenerator::GetIncludes(
  2297. std::string const& config, std::string const& lang) const
  2298. {
  2299. std::vector<std::string> includes;
  2300. this->LocalGenerator->GetIncludeDirectories(includes, this->GeneratorTarget,
  2301. lang, config);
  2302. for (std::string& i : includes) {
  2303. ConvertToWindowsSlash(i);
  2304. }
  2305. return includes;
  2306. }
  2307. bool cmVisualStudio10TargetGenerator::ComputeClOptions()
  2308. {
  2309. for (std::string const& c : this->Configurations) {
  2310. if (!this->ComputeClOptions(c)) {
  2311. return false;
  2312. }
  2313. }
  2314. return true;
  2315. }
  2316. bool cmVisualStudio10TargetGenerator::ComputeClOptions(
  2317. std::string const& configName)
  2318. {
  2319. // much of this was copied from here:
  2320. // copied from cmLocalVisualStudio7Generator.cxx 805
  2321. // TODO: Integrate code below with cmLocalVisualStudio7Generator.
  2322. cmGlobalVisualStudio10Generator* gg = this->GlobalGenerator;
  2323. std::unique_ptr<Options> pOptions;
  2324. switch (this->ProjectType) {
  2325. case vcxproj:
  2326. pOptions = cm::make_unique<Options>(
  2327. this->LocalGenerator, Options::Compiler, gg->GetClFlagTable());
  2328. break;
  2329. case csproj:
  2330. pOptions =
  2331. cm::make_unique<Options>(this->LocalGenerator, Options::CSharpCompiler,
  2332. gg->GetCSharpFlagTable());
  2333. break;
  2334. }
  2335. Options& clOptions = *pOptions;
  2336. std::string flags;
  2337. const std::string& linkLanguage =
  2338. this->GeneratorTarget->GetLinkerLanguage(configName);
  2339. if (linkLanguage.empty()) {
  2340. cmSystemTools::Error(
  2341. "CMake can not determine linker language for target: " + this->Name);
  2342. return false;
  2343. }
  2344. // Choose a language whose flags to use for ClCompile.
  2345. static const char* clLangs[] = { "CXX", "C", "Fortran" };
  2346. std::string langForClCompile;
  2347. if (this->ProjectType == csproj) {
  2348. langForClCompile = "CSharp";
  2349. } else if (std::find(cm::cbegin(clLangs), cm::cend(clLangs), linkLanguage) !=
  2350. cm::cend(clLangs)) {
  2351. langForClCompile = linkLanguage;
  2352. } else {
  2353. std::set<std::string> languages;
  2354. this->GeneratorTarget->GetLanguages(languages, configName);
  2355. for (const char* const* l = cm::cbegin(clLangs); l != cm::cend(clLangs);
  2356. ++l) {
  2357. if (languages.find(*l) != languages.end()) {
  2358. langForClCompile = *l;
  2359. break;
  2360. }
  2361. }
  2362. }
  2363. this->LangForClCompile = langForClCompile;
  2364. if (!langForClCompile.empty()) {
  2365. std::string baseFlagVar = "CMAKE_";
  2366. baseFlagVar += langForClCompile;
  2367. baseFlagVar += "_FLAGS";
  2368. flags = this->Makefile->GetRequiredDefinition(baseFlagVar);
  2369. std::string flagVar =
  2370. baseFlagVar + "_" + cmSystemTools::UpperCase(configName);
  2371. flags += " ";
  2372. flags += this->Makefile->GetRequiredDefinition(flagVar);
  2373. this->LocalGenerator->AddCompileOptions(flags, this->GeneratorTarget,
  2374. langForClCompile, configName);
  2375. }
  2376. // set the correct language
  2377. if (linkLanguage == "C") {
  2378. clOptions.AddFlag("CompileAs", "CompileAsC");
  2379. }
  2380. if (linkLanguage == "CXX") {
  2381. clOptions.AddFlag("CompileAs", "CompileAsCpp");
  2382. }
  2383. // Put the IPO enabled configurations into a set.
  2384. if (this->GeneratorTarget->IsIPOEnabled(linkLanguage, configName)) {
  2385. this->IPOEnabledConfigurations.insert(configName);
  2386. }
  2387. // Get preprocessor definitions for this directory.
  2388. std::string defineFlags = this->Makefile->GetDefineFlags();
  2389. if (this->MSTools) {
  2390. if (this->ProjectType == vcxproj) {
  2391. clOptions.FixExceptionHandlingDefault();
  2392. if (this->GlobalGenerator->GetVersion() >=
  2393. cmGlobalVisualStudioGenerator::VS15) {
  2394. // Toolsets that come with VS 2017 may now enable UseFullPaths
  2395. // by default and there is no negative /FC option that projects
  2396. // can use to switch it back. Older toolsets disable this by
  2397. // default anyway so this will not hurt them. If the project
  2398. // is using an explicit /FC option then parsing flags will
  2399. // replace this setting with "true" below.
  2400. clOptions.AddFlag("UseFullPaths", "false");
  2401. }
  2402. clOptions.AddFlag("PrecompiledHeader", "NotUsing");
  2403. std::string asmLocation = configName + "/";
  2404. clOptions.AddFlag("AssemblerListingLocation", asmLocation);
  2405. }
  2406. }
  2407. // check for managed C++ assembly compiler flag. This overrides any
  2408. // /clr* compiler flags which may be defined in the flags variable(s).
  2409. if (this->ProjectType != csproj) {
  2410. // Warn if /clr was added manually. This should not be done
  2411. // anymore, because cmGeneratorTarget may not be aware that the
  2412. // target uses C++/CLI.
  2413. if (flags.find("/clr") != std::string::npos ||
  2414. defineFlags.find("/clr") != std::string::npos) {
  2415. if (configName == this->Configurations[0]) {
  2416. std::string message = "For the target \"" +
  2417. this->GeneratorTarget->GetName() +
  2418. "\" the /clr compiler flag was added manually. " +
  2419. "Set usage of C++/CLI by setting COMMON_LANGUAGE_RUNTIME "
  2420. "target property.";
  2421. this->Makefile->IssueMessage(MessageType::WARNING, message);
  2422. }
  2423. }
  2424. if (auto* clr =
  2425. this->GeneratorTarget->GetProperty("COMMON_LANGUAGE_RUNTIME")) {
  2426. std::string clrString = clr;
  2427. if (!clrString.empty()) {
  2428. clrString = ":" + clrString;
  2429. }
  2430. flags += " /clr" + clrString;
  2431. }
  2432. }
  2433. clOptions.Parse(flags);
  2434. clOptions.Parse(defineFlags);
  2435. std::vector<std::string> targetDefines;
  2436. switch (this->ProjectType) {
  2437. case vcxproj:
  2438. if (!langForClCompile.empty()) {
  2439. this->GeneratorTarget->GetCompileDefinitions(targetDefines, configName,
  2440. langForClCompile);
  2441. }
  2442. break;
  2443. case csproj:
  2444. this->GeneratorTarget->GetCompileDefinitions(targetDefines, configName,
  2445. "CSharp");
  2446. break;
  2447. }
  2448. clOptions.AddDefines(targetDefines);
  2449. if (this->ProjectType == csproj) {
  2450. clOptions.AppendFlag("DefineConstants", targetDefines);
  2451. }
  2452. // Get includes for this target
  2453. if (!this->LangForClCompile.empty()) {
  2454. clOptions.AddIncludes(
  2455. this->GetIncludes(configName, this->LangForClCompile));
  2456. }
  2457. if (this->MSTools) {
  2458. clOptions.SetVerboseMakefile(
  2459. this->Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE"));
  2460. }
  2461. // Add a definition for the configuration name.
  2462. std::string configDefine = "CMAKE_INTDIR=\"";
  2463. configDefine += configName;
  2464. configDefine += "\"";
  2465. clOptions.AddDefine(configDefine);
  2466. if (const std::string* exportMacro =
  2467. this->GeneratorTarget->GetExportMacro()) {
  2468. clOptions.AddDefine(*exportMacro);
  2469. }
  2470. if (this->MSTools) {
  2471. // If we have the VS_WINRT_COMPONENT or CMAKE_VS_WINRT_BY_DEFAULT
  2472. // set then force Compile as WinRT.
  2473. if (this->GeneratorTarget->GetPropertyAsBool("VS_WINRT_COMPONENT") ||
  2474. this->Makefile->IsOn("CMAKE_VS_WINRT_BY_DEFAULT")) {
  2475. clOptions.AddFlag("CompileAsWinRT", "true");
  2476. // For WinRT components, add the _WINRT_DLL define to produce a lib
  2477. if (this->GeneratorTarget->GetType() == cmStateEnums::SHARED_LIBRARY ||
  2478. this->GeneratorTarget->GetType() == cmStateEnums::MODULE_LIBRARY) {
  2479. clOptions.AddDefine("_WINRT_DLL");
  2480. }
  2481. } else if (this->GlobalGenerator->TargetsWindowsStore() ||
  2482. this->GlobalGenerator->TargetsWindowsPhone()) {
  2483. if (!clOptions.IsWinRt()) {
  2484. clOptions.AddFlag("CompileAsWinRT", "false");
  2485. }
  2486. }
  2487. if (const char* winRT = clOptions.GetFlag("CompileAsWinRT")) {
  2488. if (cmSystemTools::IsOn(winRT)) {
  2489. this->TargetCompileAsWinRT = true;
  2490. }
  2491. }
  2492. }
  2493. if (this->ProjectType != csproj && clOptions.IsManaged()) {
  2494. this->Managed = true;
  2495. std::string managedType = clOptions.GetFlag("CompileAsManaged");
  2496. if (managedType == "Safe" || managedType == "Pure") {
  2497. // force empty calling convention if safe clr is used
  2498. clOptions.AddFlag("CallingConvention", "");
  2499. }
  2500. // The default values of these flags are incompatible to
  2501. // managed assemblies. We have to force valid values if
  2502. // the target is a managed C++ target.
  2503. clOptions.AddFlag("ExceptionHandling", "Async");
  2504. clOptions.AddFlag("BasicRuntimeChecks", "Default");
  2505. }
  2506. if (this->ProjectType == csproj) {
  2507. // /nowin32manifest overrides /win32manifest: parameter
  2508. if (clOptions.HasFlag("NoWin32Manifest")) {
  2509. clOptions.RemoveFlag("ApplicationManifest");
  2510. }
  2511. }
  2512. if (clOptions.HasFlag("SpectreMitigation")) {
  2513. this->SpectreMitigationConfigurations.insert(configName);
  2514. clOptions.RemoveFlag("SpectreMitigation");
  2515. }
  2516. this->ClOptions[configName] = std::move(pOptions);
  2517. return true;
  2518. }
  2519. void cmVisualStudio10TargetGenerator::WriteClOptions(
  2520. Elem& e1, std::string const& configName)
  2521. {
  2522. Options& clOptions = *(this->ClOptions[configName]);
  2523. if (this->ProjectType == csproj) {
  2524. return;
  2525. }
  2526. Elem e2(e1, "ClCompile");
  2527. OptionsHelper oh(clOptions, e2);
  2528. oh.PrependInheritedString("AdditionalOptions");
  2529. oh.OutputAdditionalIncludeDirectories(this->LangForClCompile);
  2530. oh.OutputFlagMap();
  2531. oh.OutputPreprocessorDefinitions(this->LangForClCompile);
  2532. if (this->NsightTegra) {
  2533. if (const char* processMax =
  2534. this->GeneratorTarget->GetProperty("ANDROID_PROCESS_MAX")) {
  2535. e2.Element("ProcessMax", processMax);
  2536. }
  2537. }
  2538. if (this->MSTools) {
  2539. cmsys::RegularExpression clangToolset("v[0-9]+_clang_.*");
  2540. const char* toolset = this->GlobalGenerator->GetPlatformToolset();
  2541. if (toolset && clangToolset.find(toolset)) {
  2542. e2.Element("ObjectFileName", "$(IntDir)%(filename).obj");
  2543. } else {
  2544. e2.Element("ObjectFileName", "$(IntDir)");
  2545. }
  2546. // If not in debug mode, write the DebugInformationFormat field
  2547. // without value so PDBs don't get generated uselessly. Each tag
  2548. // goes on its own line because Visual Studio corrects it this
  2549. // way when saving the project after CMake generates it.
  2550. if (!clOptions.IsDebug()) {
  2551. Elem e3(e2, "DebugInformationFormat");
  2552. e3.SetHasElements();
  2553. }
  2554. // Specify the compiler program database file if configured.
  2555. std::string pdb = this->GeneratorTarget->GetCompilePDBPath(configName);
  2556. if (!pdb.empty()) {
  2557. if (this->GlobalGenerator->IsCudaEnabled()) {
  2558. // CUDA does not quote paths with spaces correctly when forwarding
  2559. // this to the host compiler. Use a relative path to avoid spaces.
  2560. // FIXME: We can likely do this even when CUDA is not involved,
  2561. // but for now we will make a minimal change.
  2562. pdb = this->ConvertPath(pdb, true);
  2563. }
  2564. ConvertToWindowsSlash(pdb);
  2565. e2.Element("ProgramDataBaseFileName", pdb);
  2566. }
  2567. // add AdditionalUsingDirectories
  2568. if (this->AdditionalUsingDirectories.count(configName) > 0) {
  2569. std::string dirs;
  2570. for (auto u : this->AdditionalUsingDirectories[configName]) {
  2571. if (!dirs.empty()) {
  2572. dirs.append(";");
  2573. }
  2574. dirs.append(u);
  2575. }
  2576. e2.Element("AdditionalUsingDirectories", dirs);
  2577. }
  2578. }
  2579. }
  2580. bool cmVisualStudio10TargetGenerator::ComputeRcOptions()
  2581. {
  2582. for (std::string const& c : this->Configurations) {
  2583. if (!this->ComputeRcOptions(c)) {
  2584. return false;
  2585. }
  2586. }
  2587. return true;
  2588. }
  2589. bool cmVisualStudio10TargetGenerator::ComputeRcOptions(
  2590. std::string const& configName)
  2591. {
  2592. cmGlobalVisualStudio10Generator* gg = this->GlobalGenerator;
  2593. auto pOptions = cm::make_unique<Options>(
  2594. this->LocalGenerator, Options::ResourceCompiler, gg->GetRcFlagTable());
  2595. Options& rcOptions = *pOptions;
  2596. std::string CONFIG = cmSystemTools::UpperCase(configName);
  2597. std::string rcConfigFlagsVar = "CMAKE_RC_FLAGS_" + CONFIG;
  2598. std::string flags = this->Makefile->GetSafeDefinition("CMAKE_RC_FLAGS") +
  2599. " " + this->Makefile->GetSafeDefinition(rcConfigFlagsVar);
  2600. rcOptions.Parse(flags);
  2601. // For historical reasons, add the C preprocessor defines to RC.
  2602. Options& clOptions = *(this->ClOptions[configName]);
  2603. rcOptions.AddDefines(clOptions.GetDefines());
  2604. // Get includes for this target
  2605. rcOptions.AddIncludes(this->GetIncludes(configName, "RC"));
  2606. this->RcOptions[configName] = std::move(pOptions);
  2607. return true;
  2608. }
  2609. void cmVisualStudio10TargetGenerator::WriteRCOptions(
  2610. Elem& e1, std::string const& configName)
  2611. {
  2612. if (!this->MSTools) {
  2613. return;
  2614. }
  2615. Elem e2(e1, "ResourceCompile");
  2616. OptionsHelper rcOptions(*(this->RcOptions[configName]), e2);
  2617. rcOptions.OutputPreprocessorDefinitions("RC");
  2618. rcOptions.OutputAdditionalIncludeDirectories("RC");
  2619. rcOptions.PrependInheritedString("AdditionalOptions");
  2620. rcOptions.OutputFlagMap();
  2621. }
  2622. bool cmVisualStudio10TargetGenerator::ComputeCudaOptions()
  2623. {
  2624. if (!this->GlobalGenerator->IsCudaEnabled()) {
  2625. return true;
  2626. }
  2627. for (std::string const& c : this->Configurations) {
  2628. if (!this->ComputeCudaOptions(c)) {
  2629. return false;
  2630. }
  2631. }
  2632. return true;
  2633. }
  2634. bool cmVisualStudio10TargetGenerator::ComputeCudaOptions(
  2635. std::string const& configName)
  2636. {
  2637. cmGlobalVisualStudio10Generator* gg = this->GlobalGenerator;
  2638. auto pOptions = cm::make_unique<Options>(
  2639. this->LocalGenerator, Options::CudaCompiler, gg->GetCudaFlagTable());
  2640. Options& cudaOptions = *pOptions;
  2641. // Get compile flags for CUDA in this directory.
  2642. std::string CONFIG = cmSystemTools::UpperCase(configName);
  2643. std::string configFlagsVar = std::string("CMAKE_CUDA_FLAGS_") + CONFIG;
  2644. std::string flags = this->Makefile->GetSafeDefinition("CMAKE_CUDA_FLAGS") +
  2645. " " + this->Makefile->GetSafeDefinition(configFlagsVar);
  2646. this->LocalGenerator->AddCompileOptions(flags, this->GeneratorTarget, "CUDA",
  2647. configName);
  2648. // Get preprocessor definitions for this directory.
  2649. std::string defineFlags = this->Makefile->GetDefineFlags();
  2650. cudaOptions.Parse(flags);
  2651. cudaOptions.Parse(defineFlags);
  2652. cudaOptions.ParseFinish();
  2653. // If we haven't explicitly enabled GPU debug information
  2654. // explicitly disable it
  2655. if (!cudaOptions.HasFlag("GPUDebugInfo")) {
  2656. cudaOptions.AddFlag("GPUDebugInfo", "false");
  2657. }
  2658. // The extension on object libraries the CUDA gives isn't
  2659. // consistent with how MSVC generates object libraries for C+, so set
  2660. // the default to not have any extension
  2661. cudaOptions.AddFlag("CompileOut", "$(IntDir)%(Filename).obj");
  2662. bool notPtx = true;
  2663. if (this->GeneratorTarget->GetPropertyAsBool("CUDA_SEPARABLE_COMPILATION")) {
  2664. cudaOptions.AddFlag("GenerateRelocatableDeviceCode", "true");
  2665. } else if (this->GeneratorTarget->GetPropertyAsBool(
  2666. "CUDA_PTX_COMPILATION")) {
  2667. cudaOptions.AddFlag("NvccCompilation", "ptx");
  2668. // We drop the %(Extension) component as CMake expects all PTX files
  2669. // to not have the source file extension at all
  2670. cudaOptions.AddFlag("CompileOut", "$(IntDir)%(Filename).ptx");
  2671. notPtx = false;
  2672. }
  2673. if (notPtx &&
  2674. cmSystemTools::VersionCompareGreaterEq(
  2675. "8.0", this->GlobalGenerator->GetPlatformToolsetCudaString())) {
  2676. // Explicitly state that we want this file to be treated as a
  2677. // CUDA file no matter what the file extensions is
  2678. // This is only needed for < CUDA 9
  2679. cudaOptions.AppendFlagString("AdditionalOptions", "-x cu");
  2680. }
  2681. // Specify the compiler program database file if configured.
  2682. std::string pdb = this->GeneratorTarget->GetCompilePDBPath(configName);
  2683. if (!pdb.empty()) {
  2684. // CUDA does not make the directory if it is non-standard.
  2685. std::string const pdbDir = cmSystemTools::GetFilenamePath(pdb);
  2686. cmSystemTools::MakeDirectory(pdbDir);
  2687. if (cmSystemTools::VersionCompareGreaterEq(
  2688. "9.2", this->GlobalGenerator->GetPlatformToolsetCudaString())) {
  2689. // CUDA does not have a field for this and does not honor the
  2690. // ProgramDataBaseFileName field in ClCompile. Work around this
  2691. // limitation by creating the directory and passing the flag ourselves.
  2692. pdb = this->ConvertPath(pdb, true);
  2693. ConvertToWindowsSlash(pdb);
  2694. std::string const clFd = "-Xcompiler=\"-Fd\\\"" + pdb + "\\\"\"";
  2695. cudaOptions.AppendFlagString("AdditionalOptions", clFd);
  2696. }
  2697. }
  2698. // CUDA automatically passes the proper '--machine' flag to nvcc
  2699. // for the current architecture, but does not reflect this default
  2700. // in the user-visible IDE settings. Set it explicitly.
  2701. if (this->Platform == "x64") {
  2702. cudaOptions.AddFlag("TargetMachinePlatform", "64");
  2703. }
  2704. // Convert the host compiler options to the toolset's abstractions
  2705. // using a secondary flag table.
  2706. cudaOptions.ClearTables();
  2707. cudaOptions.AddTable(gg->GetCudaHostFlagTable());
  2708. cudaOptions.Reparse("AdditionalCompilerOptions");
  2709. // `CUDA 8.0.targets` places AdditionalCompilerOptions before nvcc!
  2710. // Pass them through -Xcompiler in AdditionalOptions instead.
  2711. if (const char* acoPtr = cudaOptions.GetFlag("AdditionalCompilerOptions")) {
  2712. std::string aco = acoPtr;
  2713. cudaOptions.RemoveFlag("AdditionalCompilerOptions");
  2714. if (!aco.empty()) {
  2715. aco = this->LocalGenerator->EscapeForShell(aco, false);
  2716. cudaOptions.AppendFlagString("AdditionalOptions", "-Xcompiler=" + aco);
  2717. }
  2718. }
  2719. cudaOptions.FixCudaCodeGeneration();
  2720. std::vector<std::string> targetDefines;
  2721. this->GeneratorTarget->GetCompileDefinitions(targetDefines, configName,
  2722. "CUDA");
  2723. cudaOptions.AddDefines(targetDefines);
  2724. // Add a definition for the configuration name.
  2725. std::string configDefine = "CMAKE_INTDIR=\"";
  2726. configDefine += configName;
  2727. configDefine += "\"";
  2728. cudaOptions.AddDefine(configDefine);
  2729. if (const std::string* exportMacro =
  2730. this->GeneratorTarget->GetExportMacro()) {
  2731. cudaOptions.AddDefine(*exportMacro);
  2732. }
  2733. // Get includes for this target
  2734. cudaOptions.AddIncludes(this->GetIncludes(configName, "CUDA"));
  2735. cudaOptions.AddFlag("UseHostInclude", "false");
  2736. this->CudaOptions[configName] = std::move(pOptions);
  2737. return true;
  2738. }
  2739. void cmVisualStudio10TargetGenerator::WriteCudaOptions(
  2740. Elem& e1, std::string const& configName)
  2741. {
  2742. if (!this->MSTools || !this->GlobalGenerator->IsCudaEnabled()) {
  2743. return;
  2744. }
  2745. Elem e2(e1, "CudaCompile");
  2746. OptionsHelper cudaOptions(*(this->CudaOptions[configName]), e2);
  2747. cudaOptions.OutputAdditionalIncludeDirectories("CUDA");
  2748. cudaOptions.OutputPreprocessorDefinitions("CUDA");
  2749. cudaOptions.PrependInheritedString("AdditionalOptions");
  2750. cudaOptions.OutputFlagMap();
  2751. }
  2752. bool cmVisualStudio10TargetGenerator::ComputeCudaLinkOptions()
  2753. {
  2754. if (!this->GlobalGenerator->IsCudaEnabled()) {
  2755. return true;
  2756. }
  2757. for (std::string const& c : this->Configurations) {
  2758. if (!this->ComputeCudaLinkOptions(c)) {
  2759. return false;
  2760. }
  2761. }
  2762. return true;
  2763. }
  2764. bool cmVisualStudio10TargetGenerator::ComputeCudaLinkOptions(
  2765. std::string const& configName)
  2766. {
  2767. cmGlobalVisualStudio10Generator* gg = this->GlobalGenerator;
  2768. auto pOptions = cm::make_unique<Options>(
  2769. this->LocalGenerator, Options::CudaCompiler, gg->GetCudaFlagTable());
  2770. Options& cudaLinkOptions = *pOptions;
  2771. // Determine if we need to do a device link
  2772. bool doDeviceLinking = false;
  2773. if (const char* resolveDeviceSymbols =
  2774. this->GeneratorTarget->GetProperty("CUDA_RESOLVE_DEVICE_SYMBOLS")) {
  2775. doDeviceLinking = cmSystemTools::IsOn(resolveDeviceSymbols);
  2776. } else {
  2777. switch (this->GeneratorTarget->GetType()) {
  2778. case cmStateEnums::SHARED_LIBRARY:
  2779. case cmStateEnums::MODULE_LIBRARY:
  2780. case cmStateEnums::EXECUTABLE:
  2781. doDeviceLinking = true;
  2782. break;
  2783. default:
  2784. break;
  2785. }
  2786. }
  2787. cudaLinkOptions.AddFlag("PerformDeviceLink",
  2788. doDeviceLinking ? "true" : "false");
  2789. // Suppress deprecation warnings for default GPU targets during device link.
  2790. if (cmSystemTools::VersionCompareGreaterEq(
  2791. this->GlobalGenerator->GetPlatformToolsetCudaString(), "8.0")) {
  2792. cudaLinkOptions.AppendFlagString("AdditionalOptions",
  2793. "-Wno-deprecated-gpu-targets");
  2794. }
  2795. this->CudaLinkOptions[configName] = std::move(pOptions);
  2796. return true;
  2797. }
  2798. void cmVisualStudio10TargetGenerator::WriteCudaLinkOptions(
  2799. Elem& e1, std::string const& configName)
  2800. {
  2801. if (this->GeneratorTarget->GetType() > cmStateEnums::MODULE_LIBRARY) {
  2802. return;
  2803. }
  2804. if (!this->MSTools || !this->GlobalGenerator->IsCudaEnabled()) {
  2805. return;
  2806. }
  2807. Elem e2(e1, "CudaLink");
  2808. OptionsHelper cudaLinkOptions(*(this->CudaLinkOptions[configName]), e2);
  2809. cudaLinkOptions.OutputFlagMap();
  2810. }
  2811. bool cmVisualStudio10TargetGenerator::ComputeMasmOptions()
  2812. {
  2813. if (!this->GlobalGenerator->IsMasmEnabled()) {
  2814. return true;
  2815. }
  2816. for (std::string const& c : this->Configurations) {
  2817. if (!this->ComputeMasmOptions(c)) {
  2818. return false;
  2819. }
  2820. }
  2821. return true;
  2822. }
  2823. bool cmVisualStudio10TargetGenerator::ComputeMasmOptions(
  2824. std::string const& configName)
  2825. {
  2826. cmGlobalVisualStudio10Generator* gg = this->GlobalGenerator;
  2827. auto pOptions = cm::make_unique<Options>(
  2828. this->LocalGenerator, Options::MasmCompiler, gg->GetMasmFlagTable());
  2829. Options& masmOptions = *pOptions;
  2830. std::string CONFIG = cmSystemTools::UpperCase(configName);
  2831. std::string configFlagsVar = std::string("CMAKE_ASM_MASM_FLAGS_") + CONFIG;
  2832. std::string flags =
  2833. this->Makefile->GetSafeDefinition("CMAKE_ASM_MASM_FLAGS") + " " +
  2834. this->Makefile->GetSafeDefinition(configFlagsVar);
  2835. masmOptions.Parse(flags);
  2836. // Get includes for this target
  2837. masmOptions.AddIncludes(this->GetIncludes(configName, "ASM_MASM"));
  2838. this->MasmOptions[configName] = std::move(pOptions);
  2839. return true;
  2840. }
  2841. void cmVisualStudio10TargetGenerator::WriteMasmOptions(
  2842. Elem& e1, std::string const& configName)
  2843. {
  2844. if (!this->MSTools || !this->GlobalGenerator->IsMasmEnabled()) {
  2845. return;
  2846. }
  2847. Elem e2(e1, "MASM");
  2848. // Preprocessor definitions and includes are shared with clOptions.
  2849. OptionsHelper clOptions(*(this->ClOptions[configName]), e2);
  2850. clOptions.OutputPreprocessorDefinitions("ASM_MASM");
  2851. OptionsHelper masmOptions(*(this->MasmOptions[configName]), e2);
  2852. masmOptions.OutputAdditionalIncludeDirectories("ASM_MASM");
  2853. masmOptions.PrependInheritedString("AdditionalOptions");
  2854. masmOptions.OutputFlagMap();
  2855. }
  2856. bool cmVisualStudio10TargetGenerator::ComputeNasmOptions()
  2857. {
  2858. if (!this->GlobalGenerator->IsNasmEnabled()) {
  2859. return true;
  2860. }
  2861. for (std::string const& c : this->Configurations) {
  2862. if (!this->ComputeNasmOptions(c)) {
  2863. return false;
  2864. }
  2865. }
  2866. return true;
  2867. }
  2868. bool cmVisualStudio10TargetGenerator::ComputeNasmOptions(
  2869. std::string const& configName)
  2870. {
  2871. cmGlobalVisualStudio10Generator* gg = this->GlobalGenerator;
  2872. auto pOptions = cm::make_unique<Options>(
  2873. this->LocalGenerator, Options::NasmCompiler, gg->GetNasmFlagTable());
  2874. Options& nasmOptions = *pOptions;
  2875. std::string CONFIG = cmSystemTools::UpperCase(configName);
  2876. std::string configFlagsVar = "CMAKE_ASM_NASM_FLAGS_" + CONFIG;
  2877. std::string flags =
  2878. this->Makefile->GetSafeDefinition("CMAKE_ASM_NASM_FLAGS") + " -f" +
  2879. this->Makefile->GetSafeDefinition("CMAKE_ASM_NASM_OBJECT_FORMAT") + " " +
  2880. this->Makefile->GetSafeDefinition(configFlagsVar);
  2881. nasmOptions.Parse(flags);
  2882. // Get includes for this target
  2883. nasmOptions.AddIncludes(this->GetIncludes(configName, "ASM_NASM"));
  2884. this->NasmOptions[configName] = std::move(pOptions);
  2885. return true;
  2886. }
  2887. void cmVisualStudio10TargetGenerator::WriteNasmOptions(
  2888. Elem& e1, std::string const& configName)
  2889. {
  2890. if (!this->GlobalGenerator->IsNasmEnabled()) {
  2891. return;
  2892. }
  2893. Elem e2(e1, "NASM");
  2894. std::vector<std::string> includes =
  2895. this->GetIncludes(configName, "ASM_NASM");
  2896. OptionsHelper nasmOptions(*(this->NasmOptions[configName]), e2);
  2897. nasmOptions.OutputAdditionalIncludeDirectories("ASM_NASM");
  2898. nasmOptions.OutputFlagMap();
  2899. nasmOptions.PrependInheritedString("AdditionalOptions");
  2900. nasmOptions.OutputPreprocessorDefinitions("ASM_NASM");
  2901. // Preprocessor definitions and includes are shared with clOptions.
  2902. OptionsHelper clOptions(*(this->ClOptions[configName]), e2);
  2903. clOptions.OutputPreprocessorDefinitions("ASM_NASM");
  2904. }
  2905. void cmVisualStudio10TargetGenerator::WriteLibOptions(
  2906. Elem& e1, std::string const& config)
  2907. {
  2908. if (this->GeneratorTarget->GetType() != cmStateEnums::STATIC_LIBRARY &&
  2909. this->GeneratorTarget->GetType() != cmStateEnums::OBJECT_LIBRARY) {
  2910. return;
  2911. }
  2912. const std::string& linkLanguage =
  2913. this->GeneratorTarget->GetLinkClosure(config)->LinkerLanguage;
  2914. std::string libflags;
  2915. this->LocalGenerator->GetStaticLibraryFlags(
  2916. libflags, cmSystemTools::UpperCase(config), linkLanguage,
  2917. this->GeneratorTarget);
  2918. if (!libflags.empty()) {
  2919. Elem e2(e1, "Lib");
  2920. cmGlobalVisualStudio10Generator* gg = this->GlobalGenerator;
  2921. cmVS10GeneratorOptions libOptions(this->LocalGenerator,
  2922. cmVisualStudioGeneratorOptions::Linker,
  2923. gg->GetLibFlagTable(), this);
  2924. libOptions.Parse(libflags);
  2925. OptionsHelper oh(libOptions, e2);
  2926. oh.PrependInheritedString("AdditionalOptions");
  2927. oh.OutputFlagMap();
  2928. }
  2929. // We cannot generate metadata for static libraries. WindowsPhone
  2930. // and WindowsStore tools look at GenerateWindowsMetadata in the
  2931. // Link tool options even for static libraries.
  2932. if (this->GlobalGenerator->TargetsWindowsPhone() ||
  2933. this->GlobalGenerator->TargetsWindowsStore()) {
  2934. Elem e2(e1, "Link");
  2935. e2.Element("GenerateWindowsMetadata", "false");
  2936. }
  2937. }
  2938. void cmVisualStudio10TargetGenerator::WriteManifestOptions(
  2939. Elem& e1, std::string const& config)
  2940. {
  2941. if (this->GeneratorTarget->GetType() != cmStateEnums::EXECUTABLE &&
  2942. this->GeneratorTarget->GetType() != cmStateEnums::SHARED_LIBRARY &&
  2943. this->GeneratorTarget->GetType() != cmStateEnums::MODULE_LIBRARY) {
  2944. return;
  2945. }
  2946. std::vector<cmSourceFile const*> manifest_srcs;
  2947. this->GeneratorTarget->GetManifests(manifest_srcs, config);
  2948. if (!manifest_srcs.empty()) {
  2949. std::ostringstream oss;
  2950. for (cmSourceFile const* mi : manifest_srcs) {
  2951. std::string m = this->ConvertPath(mi->GetFullPath(), false);
  2952. ConvertToWindowsSlash(m);
  2953. oss << m << ";";
  2954. }
  2955. Elem e2(e1, "Manifest");
  2956. e2.Element("AdditionalManifestFiles", oss.str());
  2957. }
  2958. }
  2959. void cmVisualStudio10TargetGenerator::WriteAntBuildOptions(
  2960. Elem& e1, std::string const& configName)
  2961. {
  2962. // Look through the sources for AndroidManifest.xml and use
  2963. // its location as the root source directory.
  2964. std::string rootDir = this->LocalGenerator->GetCurrentSourceDirectory();
  2965. {
  2966. std::vector<cmSourceFile const*> extraSources;
  2967. this->GeneratorTarget->GetExtraSources(extraSources, "");
  2968. for (cmSourceFile const* si : extraSources) {
  2969. if ("androidmanifest.xml" ==
  2970. cmSystemTools::LowerCase(si->GetLocation().GetName())) {
  2971. rootDir = si->GetLocation().GetDirectory();
  2972. break;
  2973. }
  2974. }
  2975. }
  2976. // Tell MSBuild to launch Ant.
  2977. Elem e2(e1, "AntBuild");
  2978. {
  2979. std::string antBuildPath = rootDir;
  2980. ConvertToWindowsSlash(antBuildPath);
  2981. e2.Element("AntBuildPath", antBuildPath);
  2982. }
  2983. if (this->GeneratorTarget->GetPropertyAsBool("ANDROID_SKIP_ANT_STEP")) {
  2984. e2.Element("SkipAntStep", "true");
  2985. }
  2986. if (this->GeneratorTarget->GetPropertyAsBool("ANDROID_PROGUARD")) {
  2987. e2.Element("EnableProGuard", "true");
  2988. }
  2989. if (const char* proGuardConfigLocation =
  2990. this->GeneratorTarget->GetProperty("ANDROID_PROGUARD_CONFIG_PATH")) {
  2991. e2.Element("ProGuardConfigLocation", proGuardConfigLocation);
  2992. }
  2993. if (const char* securePropertiesLocation =
  2994. this->GeneratorTarget->GetProperty("ANDROID_SECURE_PROPS_PATH")) {
  2995. e2.Element("SecurePropertiesLocation", securePropertiesLocation);
  2996. }
  2997. if (const char* nativeLibDirectoriesExpression =
  2998. this->GeneratorTarget->GetProperty("ANDROID_NATIVE_LIB_DIRECTORIES")) {
  2999. cmGeneratorExpression ge;
  3000. std::unique_ptr<cmCompiledGeneratorExpression> cge =
  3001. ge.Parse(nativeLibDirectoriesExpression);
  3002. std::string nativeLibDirs =
  3003. cge->Evaluate(this->LocalGenerator, configName);
  3004. e2.Element("NativeLibDirectories", nativeLibDirs);
  3005. }
  3006. if (const char* nativeLibDependenciesExpression =
  3007. this->GeneratorTarget->GetProperty(
  3008. "ANDROID_NATIVE_LIB_DEPENDENCIES")) {
  3009. cmGeneratorExpression ge;
  3010. std::unique_ptr<cmCompiledGeneratorExpression> cge =
  3011. ge.Parse(nativeLibDependenciesExpression);
  3012. std::string nativeLibDeps =
  3013. cge->Evaluate(this->LocalGenerator, configName);
  3014. e2.Element("NativeLibDependencies", nativeLibDeps);
  3015. }
  3016. if (const char* javaSourceDir =
  3017. this->GeneratorTarget->GetProperty("ANDROID_JAVA_SOURCE_DIR")) {
  3018. e2.Element("JavaSourceDir", javaSourceDir);
  3019. }
  3020. if (const char* jarDirectoriesExpression =
  3021. this->GeneratorTarget->GetProperty("ANDROID_JAR_DIRECTORIES")) {
  3022. cmGeneratorExpression ge;
  3023. std::unique_ptr<cmCompiledGeneratorExpression> cge =
  3024. ge.Parse(jarDirectoriesExpression);
  3025. std::string jarDirectories =
  3026. cge->Evaluate(this->LocalGenerator, configName);
  3027. e2.Element("JarDirectories", jarDirectories);
  3028. }
  3029. if (const char* jarDeps =
  3030. this->GeneratorTarget->GetProperty("ANDROID_JAR_DEPENDENCIES")) {
  3031. e2.Element("JarDependencies", jarDeps);
  3032. }
  3033. if (const char* assetsDirectories =
  3034. this->GeneratorTarget->GetProperty("ANDROID_ASSETS_DIRECTORIES")) {
  3035. e2.Element("AssetsDirectories", assetsDirectories);
  3036. }
  3037. {
  3038. std::string manifest_xml = rootDir + "/AndroidManifest.xml";
  3039. ConvertToWindowsSlash(manifest_xml);
  3040. e2.Element("AndroidManifestLocation", manifest_xml);
  3041. }
  3042. if (const char* antAdditionalOptions =
  3043. this->GeneratorTarget->GetProperty("ANDROID_ANT_ADDITIONAL_OPTIONS")) {
  3044. e2.Element("AdditionalOptions",
  3045. std::string(antAdditionalOptions) + " %(AdditionalOptions)");
  3046. }
  3047. }
  3048. bool cmVisualStudio10TargetGenerator::ComputeLinkOptions()
  3049. {
  3050. if (this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE ||
  3051. this->GeneratorTarget->GetType() == cmStateEnums::SHARED_LIBRARY ||
  3052. this->GeneratorTarget->GetType() == cmStateEnums::MODULE_LIBRARY) {
  3053. for (std::string const& c : this->Configurations) {
  3054. if (!this->ComputeLinkOptions(c)) {
  3055. return false;
  3056. }
  3057. }
  3058. }
  3059. return true;
  3060. }
  3061. bool cmVisualStudio10TargetGenerator::ComputeLinkOptions(
  3062. std::string const& config)
  3063. {
  3064. cmGlobalVisualStudio10Generator* gg = this->GlobalGenerator;
  3065. auto pOptions = cm::make_unique<Options>(
  3066. this->LocalGenerator, Options::Linker, gg->GetLinkFlagTable(), this);
  3067. Options& linkOptions = *pOptions;
  3068. cmGeneratorTarget::LinkClosure const* linkClosure =
  3069. this->GeneratorTarget->GetLinkClosure(config);
  3070. const std::string& linkLanguage = linkClosure->LinkerLanguage;
  3071. if (linkLanguage.empty()) {
  3072. cmSystemTools::Error(
  3073. "CMake can not determine linker language for target: " + this->Name);
  3074. return false;
  3075. }
  3076. std::string CONFIG = cmSystemTools::UpperCase(config);
  3077. const char* linkType = "SHARED";
  3078. if (this->GeneratorTarget->GetType() == cmStateEnums::MODULE_LIBRARY) {
  3079. linkType = "MODULE";
  3080. }
  3081. if (this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE) {
  3082. linkType = "EXE";
  3083. }
  3084. std::string flags;
  3085. std::string linkFlagVarBase = "CMAKE_";
  3086. linkFlagVarBase += linkType;
  3087. linkFlagVarBase += "_LINKER_FLAGS";
  3088. flags += " ";
  3089. flags += this->Makefile->GetRequiredDefinition(linkFlagVarBase);
  3090. std::string linkFlagVar = linkFlagVarBase + "_" + CONFIG;
  3091. flags += " ";
  3092. flags += this->Makefile->GetRequiredDefinition(linkFlagVar);
  3093. const char* targetLinkFlags =
  3094. this->GeneratorTarget->GetProperty("LINK_FLAGS");
  3095. if (targetLinkFlags) {
  3096. flags += " ";
  3097. flags += targetLinkFlags;
  3098. }
  3099. std::string flagsProp = "LINK_FLAGS_";
  3100. flagsProp += CONFIG;
  3101. if (const char* flagsConfig =
  3102. this->GeneratorTarget->GetProperty(flagsProp)) {
  3103. flags += " ";
  3104. flags += flagsConfig;
  3105. }
  3106. std::vector<std::string> opts;
  3107. this->GeneratorTarget->GetLinkOptions(opts, config, linkLanguage);
  3108. // LINK_OPTIONS are escaped.
  3109. this->LocalGenerator->AppendCompileOptions(flags, opts);
  3110. cmComputeLinkInformation* pcli =
  3111. this->GeneratorTarget->GetLinkInformation(config);
  3112. if (!pcli) {
  3113. cmSystemTools::Error(
  3114. "CMake can not compute cmComputeLinkInformation for target: " +
  3115. this->Name);
  3116. return false;
  3117. }
  3118. cmComputeLinkInformation& cli = *pcli;
  3119. std::vector<std::string> libVec;
  3120. std::vector<std::string> vsTargetVec;
  3121. this->AddLibraries(cli, libVec, vsTargetVec, config);
  3122. if (std::find(linkClosure->Languages.begin(), linkClosure->Languages.end(),
  3123. "CUDA") != linkClosure->Languages.end() &&
  3124. this->CudaOptions[config] != nullptr) {
  3125. switch (this->CudaOptions[config]->GetCudaRuntime()) {
  3126. case cmVisualStudioGeneratorOptions::CudaRuntimeStatic:
  3127. libVec.push_back("cudadevrt.lib");
  3128. libVec.push_back("cudart_static.lib");
  3129. break;
  3130. case cmVisualStudioGeneratorOptions::CudaRuntimeShared:
  3131. libVec.push_back("cudadevrt.lib");
  3132. libVec.push_back("cudart.lib");
  3133. break;
  3134. case cmVisualStudioGeneratorOptions::CudaRuntimeNone:
  3135. break;
  3136. }
  3137. }
  3138. std::string standardLibsVar = "CMAKE_";
  3139. standardLibsVar += linkLanguage;
  3140. standardLibsVar += "_STANDARD_LIBRARIES";
  3141. std::string const libs = this->Makefile->GetSafeDefinition(standardLibsVar);
  3142. cmSystemTools::ParseWindowsCommandLine(libs.c_str(), libVec);
  3143. linkOptions.AddFlag("AdditionalDependencies", libVec);
  3144. // Populate TargetsFileAndConfigsVec
  3145. for (std::string const& ti : vsTargetVec) {
  3146. this->AddTargetsFileAndConfigPair(ti, config);
  3147. }
  3148. std::vector<std::string> const& ldirs = cli.GetDirectories();
  3149. std::vector<std::string> linkDirs;
  3150. for (std::string const& d : ldirs) {
  3151. // first just full path
  3152. linkDirs.push_back(d);
  3153. // next path with configuration type Debug, Release, etc
  3154. linkDirs.push_back(d + "/$(Configuration)");
  3155. }
  3156. linkDirs.push_back("%(AdditionalLibraryDirectories)");
  3157. linkOptions.AddFlag("AdditionalLibraryDirectories", linkDirs);
  3158. cmGeneratorTarget::Names targetNames;
  3159. if (this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE) {
  3160. targetNames = this->GeneratorTarget->GetExecutableNames(config);
  3161. } else {
  3162. targetNames = this->GeneratorTarget->GetLibraryNames(config);
  3163. }
  3164. if (this->MSTools) {
  3165. if (this->GeneratorTarget->GetPropertyAsBool("WIN32_EXECUTABLE")) {
  3166. if (this->GlobalGenerator->TargetsWindowsCE()) {
  3167. linkOptions.AddFlag("SubSystem", "WindowsCE");
  3168. if (this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE) {
  3169. if (this->ClOptions[config]->UsingUnicode()) {
  3170. linkOptions.AddFlag("EntryPointSymbol", "wWinMainCRTStartup");
  3171. } else {
  3172. linkOptions.AddFlag("EntryPointSymbol", "WinMainCRTStartup");
  3173. }
  3174. }
  3175. } else {
  3176. linkOptions.AddFlag("SubSystem", "Windows");
  3177. }
  3178. } else {
  3179. if (this->GlobalGenerator->TargetsWindowsCE()) {
  3180. linkOptions.AddFlag("SubSystem", "WindowsCE");
  3181. if (this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE) {
  3182. if (this->ClOptions[config]->UsingUnicode()) {
  3183. linkOptions.AddFlag("EntryPointSymbol", "mainWCRTStartup");
  3184. } else {
  3185. linkOptions.AddFlag("EntryPointSymbol", "mainACRTStartup");
  3186. }
  3187. }
  3188. } else {
  3189. linkOptions.AddFlag("SubSystem", "Console");
  3190. };
  3191. }
  3192. if (const char* stackVal = this->Makefile->GetDefinition(
  3193. "CMAKE_" + linkLanguage + "_STACK_SIZE")) {
  3194. linkOptions.AddFlag("StackReserveSize", stackVal);
  3195. }
  3196. linkOptions.AddFlag("GenerateDebugInformation", "false");
  3197. std::string pdb = this->GeneratorTarget->GetPDBDirectory(config);
  3198. pdb += "/";
  3199. pdb += targetNames.PDB;
  3200. std::string imLib = this->GeneratorTarget->GetDirectory(
  3201. config, cmStateEnums::ImportLibraryArtifact);
  3202. imLib += "/";
  3203. imLib += targetNames.ImportLibrary;
  3204. linkOptions.AddFlag("ImportLibrary", imLib);
  3205. linkOptions.AddFlag("ProgramDataBaseFile", pdb);
  3206. // A Windows Runtime component uses internal .NET metadata,
  3207. // so does not have an import library.
  3208. if (this->GeneratorTarget->GetPropertyAsBool("VS_WINRT_COMPONENT") &&
  3209. this->GeneratorTarget->GetType() != cmStateEnums::EXECUTABLE) {
  3210. linkOptions.AddFlag("GenerateWindowsMetadata", "true");
  3211. } else if (this->GlobalGenerator->TargetsWindowsPhone() ||
  3212. this->GlobalGenerator->TargetsWindowsStore()) {
  3213. // WindowsPhone and WindowsStore components are in an app container
  3214. // and produce WindowsMetadata. If we are not producing a WINRT
  3215. // component, then do not generate the metadata here.
  3216. linkOptions.AddFlag("GenerateWindowsMetadata", "false");
  3217. }
  3218. if (this->GlobalGenerator->TargetsWindowsPhone() &&
  3219. this->GlobalGenerator->GetSystemVersion() == "8.0") {
  3220. // WindowsPhone 8.0 does not have ole32.
  3221. linkOptions.AppendFlag("IgnoreSpecificDefaultLibraries", "ole32.lib");
  3222. }
  3223. } else if (this->NsightTegra) {
  3224. linkOptions.AddFlag("SoName", targetNames.SharedObject);
  3225. }
  3226. linkOptions.Parse(flags);
  3227. linkOptions.FixManifestUACFlags();
  3228. if (this->MSTools) {
  3229. cmGeneratorTarget::ModuleDefinitionInfo const* mdi =
  3230. this->GeneratorTarget->GetModuleDefinitionInfo(config);
  3231. if (mdi && !mdi->DefFile.empty()) {
  3232. linkOptions.AddFlag("ModuleDefinitionFile", mdi->DefFile);
  3233. }
  3234. linkOptions.AppendFlag("IgnoreSpecificDefaultLibraries",
  3235. "%(IgnoreSpecificDefaultLibraries)");
  3236. }
  3237. // VS 2015 without all updates has a v140 toolset whose
  3238. // GenerateDebugInformation expects No/Debug instead of false/true.
  3239. if (gg->GetPlatformToolsetNeedsDebugEnum()) {
  3240. if (const char* debug = linkOptions.GetFlag("GenerateDebugInformation")) {
  3241. if (strcmp(debug, "false") == 0) {
  3242. linkOptions.AddFlag("GenerateDebugInformation", "No");
  3243. } else if (strcmp(debug, "true") == 0) {
  3244. linkOptions.AddFlag("GenerateDebugInformation", "Debug");
  3245. }
  3246. }
  3247. }
  3248. // Managed code cannot be linked with /DEBUG:FASTLINK
  3249. if (this->Managed) {
  3250. if (const char* debug = linkOptions.GetFlag("GenerateDebugInformation")) {
  3251. if (strcmp(debug, "DebugFastLink") == 0) {
  3252. linkOptions.AddFlag("GenerateDebugInformation", "Debug");
  3253. }
  3254. }
  3255. }
  3256. this->LinkOptions[config] = std::move(pOptions);
  3257. return true;
  3258. }
  3259. bool cmVisualStudio10TargetGenerator::ComputeLibOptions()
  3260. {
  3261. if (this->GeneratorTarget->GetType() == cmStateEnums::STATIC_LIBRARY) {
  3262. for (std::string const& c : this->Configurations) {
  3263. if (!this->ComputeLibOptions(c)) {
  3264. return false;
  3265. }
  3266. }
  3267. }
  3268. return true;
  3269. }
  3270. bool cmVisualStudio10TargetGenerator::ComputeLibOptions(
  3271. std::string const& config)
  3272. {
  3273. cmComputeLinkInformation* pcli =
  3274. this->GeneratorTarget->GetLinkInformation(config);
  3275. if (!pcli) {
  3276. cmSystemTools::Error(
  3277. "CMake can not compute cmComputeLinkInformation for target: " +
  3278. this->Name);
  3279. return false;
  3280. }
  3281. cmComputeLinkInformation& cli = *pcli;
  3282. typedef cmComputeLinkInformation::ItemVector ItemVector;
  3283. const ItemVector& libs = cli.GetItems();
  3284. std::string currentBinDir =
  3285. this->LocalGenerator->GetCurrentBinaryDirectory();
  3286. for (cmComputeLinkInformation::Item const& l : libs) {
  3287. if (l.IsPath && cmVS10IsTargetsFile(l.Value)) {
  3288. std::string path = this->LocalGenerator->MaybeConvertToRelativePath(
  3289. currentBinDir, l.Value);
  3290. ConvertToWindowsSlash(path);
  3291. this->AddTargetsFileAndConfigPair(path, config);
  3292. }
  3293. }
  3294. return true;
  3295. }
  3296. void cmVisualStudio10TargetGenerator::WriteLinkOptions(
  3297. Elem& e1, std::string const& config)
  3298. {
  3299. if (this->GeneratorTarget->GetType() == cmStateEnums::STATIC_LIBRARY ||
  3300. this->GeneratorTarget->GetType() > cmStateEnums::MODULE_LIBRARY) {
  3301. return;
  3302. }
  3303. if (this->ProjectType == csproj) {
  3304. return;
  3305. }
  3306. {
  3307. Elem e2(e1, "Link");
  3308. OptionsHelper linkOptions(*(this->LinkOptions[config]), e2);
  3309. linkOptions.PrependInheritedString("AdditionalOptions");
  3310. linkOptions.OutputFlagMap();
  3311. }
  3312. if (!this->GlobalGenerator->NeedLinkLibraryDependencies(
  3313. this->GeneratorTarget)) {
  3314. Elem e2(e1, "ProjectReference");
  3315. e2.Element("LinkLibraryDependencies", "false");
  3316. }
  3317. }
  3318. void cmVisualStudio10TargetGenerator::AddLibraries(
  3319. const cmComputeLinkInformation& cli, std::vector<std::string>& libVec,
  3320. std::vector<std::string>& vsTargetVec, const std::string& config)
  3321. {
  3322. typedef cmComputeLinkInformation::ItemVector ItemVector;
  3323. ItemVector const& libs = cli.GetItems();
  3324. std::string currentBinDir =
  3325. this->LocalGenerator->GetCurrentBinaryDirectory();
  3326. for (cmComputeLinkInformation::Item const& l : libs) {
  3327. if (l.Target) {
  3328. auto managedType = l.Target->GetManagedType(config);
  3329. if (managedType != cmGeneratorTarget::ManagedType::Native &&
  3330. this->GeneratorTarget->GetManagedType(config) !=
  3331. cmGeneratorTarget::ManagedType::Native &&
  3332. l.Target->IsImported()) {
  3333. auto location = l.Target->GetFullPath(config);
  3334. if (!location.empty()) {
  3335. ConvertToWindowsSlash(location);
  3336. switch (this->ProjectType) {
  3337. case csproj:
  3338. // If the target we want to "link" to is an imported managed
  3339. // target and this is a C# project, we add a hint reference. This
  3340. // reference is written to project file in
  3341. // WriteDotNetReferences().
  3342. this->DotNetHintReferences[config].push_back(
  3343. DotNetHintReference(l.Target->GetName(), location));
  3344. break;
  3345. case vcxproj:
  3346. // Add path of assembly to list of using-directories, so the
  3347. // managed assembly can be used by '#using <assembly.dll>' in
  3348. // code.
  3349. this->AdditionalUsingDirectories[config].insert(
  3350. cmSystemTools::GetFilenamePath(location));
  3351. break;
  3352. }
  3353. }
  3354. }
  3355. // Do not allow C# targets to be added to the LIB listing. LIB files are
  3356. // used for linking C++ dependencies. C# libraries do not have lib files.
  3357. // Instead, they compile down to C# reference libraries (DLL files). The
  3358. // `<ProjectReference>` elements added to the vcxproj are enough for the
  3359. // IDE to deduce the DLL file required by other C# projects that need its
  3360. // reference library.
  3361. if (managedType == cmGeneratorTarget::ManagedType::Managed) {
  3362. continue;
  3363. }
  3364. }
  3365. if (l.IsPath) {
  3366. std::string path = this->LocalGenerator->MaybeConvertToRelativePath(
  3367. currentBinDir, l.Value);
  3368. ConvertToWindowsSlash(path);
  3369. if (cmVS10IsTargetsFile(l.Value)) {
  3370. vsTargetVec.push_back(path);
  3371. } else {
  3372. libVec.push_back(path);
  3373. }
  3374. } else if (!l.Target ||
  3375. l.Target->GetType() != cmStateEnums::INTERFACE_LIBRARY) {
  3376. libVec.push_back(l.Value);
  3377. }
  3378. }
  3379. }
  3380. void cmVisualStudio10TargetGenerator::AddTargetsFileAndConfigPair(
  3381. std::string const& targetsFile, std::string const& config)
  3382. {
  3383. for (TargetsFileAndConfigs& i : this->TargetsFileAndConfigsVec) {
  3384. if (cmSystemTools::ComparePath(targetsFile, i.File)) {
  3385. if (std::find(i.Configs.begin(), i.Configs.end(), config) ==
  3386. i.Configs.end()) {
  3387. i.Configs.push_back(config);
  3388. }
  3389. return;
  3390. }
  3391. }
  3392. TargetsFileAndConfigs entry;
  3393. entry.File = targetsFile;
  3394. entry.Configs.push_back(config);
  3395. this->TargetsFileAndConfigsVec.push_back(entry);
  3396. }
  3397. void cmVisualStudio10TargetGenerator::WriteMidlOptions(
  3398. Elem& e1, std::string const& configName)
  3399. {
  3400. if (!this->MSTools) {
  3401. return;
  3402. }
  3403. if (this->ProjectType == csproj) {
  3404. return;
  3405. }
  3406. // This processes *any* of the .idl files specified in the project's file
  3407. // list (and passed as the item metadata %(Filename) expressing the rule
  3408. // input filename) into output files at the per-config *build* dir
  3409. // ($(IntDir)) each.
  3410. //
  3411. // IOW, this MIDL section is intended to provide a fully generic syntax
  3412. // content suitable for most cases (read: if you get errors, then it's quite
  3413. // probable that the error is on your side of the .idl setup).
  3414. //
  3415. // Also, note that the marked-as-generated _i.c file in the Visual Studio
  3416. // generator case needs to be referred to as $(IntDir)\foo_i.c at the
  3417. // project's file list, otherwise the compiler-side processing won't pick it
  3418. // up (for non-directory form, it ends up looking in project binary dir
  3419. // only). Perhaps there's something to be done to make this more automatic
  3420. // on the CMake side?
  3421. std::vector<std::string> const includes =
  3422. this->GetIncludes(configName, "MIDL");
  3423. std::ostringstream oss;
  3424. for (std::string const& i : includes) {
  3425. oss << i << ";";
  3426. }
  3427. oss << "%(AdditionalIncludeDirectories)";
  3428. Elem e2(e1, "Midl");
  3429. e2.Element("AdditionalIncludeDirectories", oss.str());
  3430. e2.Element("OutputDirectory", "$(ProjectDir)/$(IntDir)");
  3431. e2.Element("HeaderFileName", "%(Filename).h");
  3432. e2.Element("TypeLibraryName", "%(Filename).tlb");
  3433. e2.Element("InterfaceIdentifierFileName", "%(Filename)_i.c");
  3434. e2.Element("ProxyFileName", "%(Filename)_p.c");
  3435. }
  3436. void cmVisualStudio10TargetGenerator::WriteItemDefinitionGroups(Elem& e0)
  3437. {
  3438. if (this->ProjectType == csproj) {
  3439. return;
  3440. }
  3441. for (const std::string& c : this->Configurations) {
  3442. Elem e1(e0, "ItemDefinitionGroup");
  3443. e1.Attribute("Condition", this->CalcCondition(c));
  3444. // output cl compile flags <ClCompile></ClCompile>
  3445. if (this->GeneratorTarget->GetType() <= cmStateEnums::OBJECT_LIBRARY) {
  3446. this->WriteClOptions(e1, c);
  3447. // output rc compile flags <ResourceCompile></ResourceCompile>
  3448. this->WriteRCOptions(e1, c);
  3449. this->WriteCudaOptions(e1, c);
  3450. this->WriteMasmOptions(e1, c);
  3451. this->WriteNasmOptions(e1, c);
  3452. }
  3453. // output midl flags <Midl></Midl>
  3454. this->WriteMidlOptions(e1, c);
  3455. // write events
  3456. if (this->ProjectType != csproj) {
  3457. this->WriteEvents(e1, c);
  3458. }
  3459. // output link flags <Link></Link>
  3460. this->WriteLinkOptions(e1, c);
  3461. this->WriteCudaLinkOptions(e1, c);
  3462. // output lib flags <Lib></Lib>
  3463. this->WriteLibOptions(e1, c);
  3464. // output manifest flags <Manifest></Manifest>
  3465. this->WriteManifestOptions(e1, c);
  3466. if (this->NsightTegra &&
  3467. this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE &&
  3468. this->GeneratorTarget->GetPropertyAsBool("ANDROID_GUI")) {
  3469. this->WriteAntBuildOptions(e1, c);
  3470. }
  3471. }
  3472. }
  3473. void cmVisualStudio10TargetGenerator::WriteEvents(
  3474. Elem& e1, std::string const& configName)
  3475. {
  3476. bool addedPrelink = false;
  3477. cmGeneratorTarget::ModuleDefinitionInfo const* mdi =
  3478. this->GeneratorTarget->GetModuleDefinitionInfo(configName);
  3479. if (mdi && mdi->DefFileGenerated) {
  3480. addedPrelink = true;
  3481. std::vector<cmCustomCommand> commands =
  3482. this->GeneratorTarget->GetPreLinkCommands();
  3483. this->GlobalGenerator->AddSymbolExportCommand(this->GeneratorTarget,
  3484. commands, configName);
  3485. this->WriteEvent(e1, "PreLinkEvent", commands, configName);
  3486. }
  3487. if (!addedPrelink) {
  3488. this->WriteEvent(e1, "PreLinkEvent",
  3489. this->GeneratorTarget->GetPreLinkCommands(), configName);
  3490. }
  3491. this->WriteEvent(e1, "PreBuildEvent",
  3492. this->GeneratorTarget->GetPreBuildCommands(), configName);
  3493. this->WriteEvent(e1, "PostBuildEvent",
  3494. this->GeneratorTarget->GetPostBuildCommands(), configName);
  3495. }
  3496. void cmVisualStudio10TargetGenerator::WriteEvent(
  3497. Elem& e1, const char* name, std::vector<cmCustomCommand> const& commands,
  3498. std::string const& configName)
  3499. {
  3500. if (commands.empty()) {
  3501. return;
  3502. }
  3503. cmLocalVisualStudio7Generator* lg = this->LocalGenerator;
  3504. std::string script;
  3505. const char* pre = "";
  3506. std::string comment;
  3507. for (cmCustomCommand const& cc : commands) {
  3508. cmCustomCommandGenerator ccg(cc, configName, lg);
  3509. if (!ccg.HasOnlyEmptyCommandLines()) {
  3510. comment += pre;
  3511. comment += lg->ConstructComment(ccg);
  3512. script += pre;
  3513. pre = "\n";
  3514. script += lg->ConstructScript(ccg);
  3515. }
  3516. }
  3517. comment = cmVS10EscapeComment(comment);
  3518. if (this->ProjectType != csproj) {
  3519. Elem e2(e1, name);
  3520. e2.Element("Message", comment);
  3521. e2.Element("Command", script);
  3522. } else {
  3523. std::string strippedComment = comment;
  3524. strippedComment.erase(
  3525. std::remove(strippedComment.begin(), strippedComment.end(), '\t'),
  3526. strippedComment.end());
  3527. std::ostringstream oss;
  3528. if (!comment.empty() && !strippedComment.empty()) {
  3529. oss << "echo " << comment << "\n";
  3530. }
  3531. oss << script << "\n";
  3532. e1.Element(name, oss.str());
  3533. }
  3534. }
  3535. void cmVisualStudio10TargetGenerator::WriteProjectReferences(Elem& e0)
  3536. {
  3537. cmGlobalGenerator::TargetDependSet const& unordered =
  3538. this->GlobalGenerator->GetTargetDirectDepends(this->GeneratorTarget);
  3539. typedef cmGlobalVisualStudioGenerator::OrderedTargetDependSet
  3540. OrderedTargetDependSet;
  3541. OrderedTargetDependSet depends(unordered, CMAKE_CHECK_BUILD_SYSTEM_TARGET);
  3542. Elem e1(e0, "ItemGroup");
  3543. e1.SetHasElements();
  3544. for (cmGeneratorTarget const* dt : depends) {
  3545. if (dt->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
  3546. continue;
  3547. }
  3548. // skip fortran targets as they can not be processed by MSBuild
  3549. // the only reference will be in the .sln file
  3550. if (this->GlobalGenerator->TargetIsFortranOnly(dt)) {
  3551. continue;
  3552. }
  3553. cmLocalGenerator* lg = dt->GetLocalGenerator();
  3554. std::string name = dt->GetName();
  3555. std::string path;
  3556. const char* p = dt->GetProperty("EXTERNAL_MSPROJECT");
  3557. if (p) {
  3558. path = p;
  3559. } else {
  3560. path = lg->GetCurrentBinaryDirectory();
  3561. path += "/";
  3562. path += dt->GetName();
  3563. path += computeProjectFileExtension(dt);
  3564. }
  3565. ConvertToWindowsSlash(path);
  3566. Elem e2(e1, "ProjectReference");
  3567. e2.Attribute("Include", path);
  3568. e2.Element("Project", "{" + this->GlobalGenerator->GetGUID(name) + "}");
  3569. e2.Element("Name", name);
  3570. this->WriteDotNetReferenceCustomTags(e2, name);
  3571. // If the dependency target is not managed (compiled with /clr or
  3572. // C# target) and not a WinRT component we cannot reference it and
  3573. // have to set 'ReferenceOutputAssembly' to false.
  3574. auto referenceNotManaged =
  3575. dt->GetManagedType("") < cmGeneratorTarget::ManagedType::Mixed;
  3576. // Workaround to check for manually set /clr flags.
  3577. if (referenceNotManaged) {
  3578. if (const auto* flags = dt->GetProperty("COMPILE_OPTIONS")) {
  3579. std::string flagsStr = flags;
  3580. if (flagsStr.find("clr") != std::string::npos) {
  3581. // There is a warning already issued when building the flags.
  3582. referenceNotManaged = false;
  3583. }
  3584. }
  3585. }
  3586. // Workaround for static library C# targets
  3587. if (referenceNotManaged && dt->GetType() == cmStateEnums::STATIC_LIBRARY) {
  3588. referenceNotManaged = !dt->IsCSharpOnly();
  3589. }
  3590. // Referencing WinRT components is okay.
  3591. if (referenceNotManaged) {
  3592. referenceNotManaged = !dt->GetPropertyAsBool("VS_WINRT_COMPONENT");
  3593. }
  3594. if (referenceNotManaged) {
  3595. e2.Element("ReferenceOutputAssembly", "false");
  3596. e2.Element("CopyToOutputDirectory", "Never");
  3597. }
  3598. }
  3599. }
  3600. void cmVisualStudio10TargetGenerator::WritePlatformExtensions(Elem& e1)
  3601. {
  3602. // This only applies to Windows 10 apps
  3603. if (this->GlobalGenerator->TargetsWindowsStore() &&
  3604. cmHasLiteralPrefix(this->GlobalGenerator->GetSystemVersion(), "10.0")) {
  3605. const char* desktopExtensionsVersion =
  3606. this->GeneratorTarget->GetProperty("VS_DESKTOP_EXTENSIONS_VERSION");
  3607. if (desktopExtensionsVersion) {
  3608. this->WriteSinglePlatformExtension(e1, "WindowsDesktop",
  3609. desktopExtensionsVersion);
  3610. }
  3611. const char* mobileExtensionsVersion =
  3612. this->GeneratorTarget->GetProperty("VS_MOBILE_EXTENSIONS_VERSION");
  3613. if (mobileExtensionsVersion) {
  3614. this->WriteSinglePlatformExtension(e1, "WindowsMobile",
  3615. mobileExtensionsVersion);
  3616. }
  3617. }
  3618. }
  3619. void cmVisualStudio10TargetGenerator::WriteSinglePlatformExtension(
  3620. Elem& e1, std::string const& extension, std::string const& version)
  3621. {
  3622. const std::string s = "$([Microsoft.Build.Utilities.ToolLocationHelper]"
  3623. "::GetPlatformExtensionSDKLocation(`" +
  3624. extension + ", Version=" + version +
  3625. "`, $(TargetPlatformIdentifier), $(TargetPlatformVersion), null, "
  3626. "$(ExtensionSDKDirectoryRoot), null))"
  3627. "\\DesignTime\\CommonConfiguration\\Neutral\\" +
  3628. extension + ".props";
  3629. Elem e2(e1, "Import");
  3630. e2.Attribute("Project", s);
  3631. e2.Attribute("Condition", "exists('" + s + "')");
  3632. }
  3633. void cmVisualStudio10TargetGenerator::WriteSDKReferences(Elem& e0)
  3634. {
  3635. std::vector<std::string> sdkReferences;
  3636. std::unique_ptr<Elem> spe1;
  3637. if (const char* vsSDKReferences =
  3638. this->GeneratorTarget->GetProperty("VS_SDK_REFERENCES")) {
  3639. cmSystemTools::ExpandListArgument(vsSDKReferences, sdkReferences);
  3640. spe1 = cm::make_unique<Elem>(e0, "ItemGroup");
  3641. for (std::string const& ri : sdkReferences) {
  3642. Elem(*spe1, "SDKReference").Attribute("Include", ri);
  3643. }
  3644. }
  3645. // This only applies to Windows 10 apps
  3646. if (this->GlobalGenerator->TargetsWindowsStore() &&
  3647. cmHasLiteralPrefix(this->GlobalGenerator->GetSystemVersion(), "10.0")) {
  3648. const char* desktopExtensionsVersion =
  3649. this->GeneratorTarget->GetProperty("VS_DESKTOP_EXTENSIONS_VERSION");
  3650. const char* mobileExtensionsVersion =
  3651. this->GeneratorTarget->GetProperty("VS_MOBILE_EXTENSIONS_VERSION");
  3652. const char* iotExtensionsVersion =
  3653. this->GeneratorTarget->GetProperty("VS_IOT_EXTENSIONS_VERSION");
  3654. if (desktopExtensionsVersion || mobileExtensionsVersion ||
  3655. iotExtensionsVersion) {
  3656. if (!spe1) {
  3657. spe1 = cm::make_unique<Elem>(e0, "ItemGroup");
  3658. }
  3659. if (desktopExtensionsVersion) {
  3660. this->WriteSingleSDKReference(*spe1, "WindowsDesktop",
  3661. desktopExtensionsVersion);
  3662. }
  3663. if (mobileExtensionsVersion) {
  3664. this->WriteSingleSDKReference(*spe1, "WindowsMobile",
  3665. mobileExtensionsVersion);
  3666. }
  3667. if (iotExtensionsVersion) {
  3668. this->WriteSingleSDKReference(*spe1, "WindowsIoT",
  3669. iotExtensionsVersion);
  3670. }
  3671. }
  3672. }
  3673. }
  3674. void cmVisualStudio10TargetGenerator::WriteSingleSDKReference(
  3675. Elem& e1, std::string const& extension, std::string const& version)
  3676. {
  3677. Elem(e1, "SDKReference")
  3678. .Attribute("Include", extension + ", Version=" + version);
  3679. }
  3680. void cmVisualStudio10TargetGenerator::WriteWinRTPackageCertificateKeyFile(
  3681. Elem& e0)
  3682. {
  3683. if ((this->GlobalGenerator->TargetsWindowsStore() ||
  3684. this->GlobalGenerator->TargetsWindowsPhone()) &&
  3685. (cmStateEnums::EXECUTABLE == this->GeneratorTarget->GetType())) {
  3686. std::string pfxFile;
  3687. std::vector<cmSourceFile const*> certificates;
  3688. this->GeneratorTarget->GetCertificates(certificates, "");
  3689. for (cmSourceFile const* si : certificates) {
  3690. pfxFile = this->ConvertPath(si->GetFullPath(), false);
  3691. ConvertToWindowsSlash(pfxFile);
  3692. break;
  3693. }
  3694. if (this->IsMissingFiles &&
  3695. !(this->GlobalGenerator->TargetsWindowsPhone() &&
  3696. this->GlobalGenerator->GetSystemVersion() == "8.0")) {
  3697. // Move the manifest to a project directory to avoid clashes
  3698. std::string artifactDir =
  3699. this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
  3700. ConvertToWindowsSlash(artifactDir);
  3701. Elem e1(e0, "PropertyGroup");
  3702. e1.Element("AppxPackageArtifactsDir", artifactDir + "\\");
  3703. std::string resourcePriFile =
  3704. this->DefaultArtifactDir + "/resources.pri";
  3705. ConvertToWindowsSlash(resourcePriFile);
  3706. e1.Element("ProjectPriFullPath", resourcePriFile);
  3707. // If we are missing files and we don't have a certificate and
  3708. // aren't targeting WP8.0, add a default certificate
  3709. if (pfxFile.empty()) {
  3710. std::string templateFolder =
  3711. cmSystemTools::GetCMakeRoot() + "/Templates/Windows";
  3712. pfxFile = this->DefaultArtifactDir + "/Windows_TemporaryKey.pfx";
  3713. cmSystemTools::CopyAFile(templateFolder + "/Windows_TemporaryKey.pfx",
  3714. pfxFile, false);
  3715. ConvertToWindowsSlash(pfxFile);
  3716. this->AddedFiles.push_back(pfxFile);
  3717. this->AddedDefaultCertificate = true;
  3718. }
  3719. e1.Element("PackageCertificateKeyFile", pfxFile);
  3720. std::string thumb = cmSystemTools::ComputeCertificateThumbprint(pfxFile);
  3721. if (!thumb.empty()) {
  3722. e1.Element("PackageCertificateThumbprint", thumb);
  3723. }
  3724. } else if (!pfxFile.empty()) {
  3725. Elem e1(e0, "PropertyGroup");
  3726. e1.Element("PackageCertificateKeyFile", pfxFile);
  3727. std::string thumb = cmSystemTools::ComputeCertificateThumbprint(pfxFile);
  3728. if (!thumb.empty()) {
  3729. e1.Element("PackageCertificateThumbprint", thumb);
  3730. }
  3731. }
  3732. }
  3733. }
  3734. bool cmVisualStudio10TargetGenerator::IsResxHeader(
  3735. const std::string& headerFile)
  3736. {
  3737. std::set<std::string> expectedResxHeaders;
  3738. this->GeneratorTarget->GetExpectedResxHeaders(expectedResxHeaders, "");
  3739. std::set<std::string>::const_iterator it =
  3740. expectedResxHeaders.find(headerFile);
  3741. return it != expectedResxHeaders.end();
  3742. }
  3743. bool cmVisualStudio10TargetGenerator::IsXamlHeader(
  3744. const std::string& headerFile)
  3745. {
  3746. std::set<std::string> expectedXamlHeaders;
  3747. this->GeneratorTarget->GetExpectedXamlHeaders(expectedXamlHeaders, "");
  3748. std::set<std::string>::const_iterator it =
  3749. expectedXamlHeaders.find(headerFile);
  3750. return it != expectedXamlHeaders.end();
  3751. }
  3752. bool cmVisualStudio10TargetGenerator::IsXamlSource(
  3753. const std::string& sourceFile)
  3754. {
  3755. std::set<std::string> expectedXamlSources;
  3756. this->GeneratorTarget->GetExpectedXamlSources(expectedXamlSources, "");
  3757. std::set<std::string>::const_iterator it =
  3758. expectedXamlSources.find(sourceFile);
  3759. return it != expectedXamlSources.end();
  3760. }
  3761. void cmVisualStudio10TargetGenerator::WriteApplicationTypeSettings(Elem& e1)
  3762. {
  3763. cmGlobalVisualStudio10Generator* gg = this->GlobalGenerator;
  3764. bool isAppContainer = false;
  3765. bool const isWindowsPhone = this->GlobalGenerator->TargetsWindowsPhone();
  3766. bool const isWindowsStore = this->GlobalGenerator->TargetsWindowsStore();
  3767. std::string const& v = this->GlobalGenerator->GetSystemVersion();
  3768. if (isWindowsPhone || isWindowsStore) {
  3769. e1.Element("ApplicationType",
  3770. (isWindowsPhone ? "Windows Phone" : "Windows Store"));
  3771. e1.Element("DefaultLanguage", "en-US");
  3772. if (cmHasLiteralPrefix(v, "10.0")) {
  3773. e1.Element("ApplicationTypeRevision", "10.0");
  3774. // Visual Studio 14.0 is necessary for building 10.0 apps
  3775. e1.Element("MinimumVisualStudioVersion", "14.0");
  3776. if (this->GeneratorTarget->GetType() < cmStateEnums::UTILITY) {
  3777. isAppContainer = true;
  3778. }
  3779. } else if (v == "8.1") {
  3780. e1.Element("ApplicationTypeRevision", v);
  3781. // Visual Studio 12.0 is necessary for building 8.1 apps
  3782. e1.Element("MinimumVisualStudioVersion", "12.0");
  3783. if (this->GeneratorTarget->GetType() < cmStateEnums::UTILITY) {
  3784. isAppContainer = true;
  3785. }
  3786. } else if (v == "8.0") {
  3787. e1.Element("ApplicationTypeRevision", v);
  3788. // Visual Studio 11.0 is necessary for building 8.0 apps
  3789. e1.Element("MinimumVisualStudioVersion", "11.0");
  3790. if (isWindowsStore &&
  3791. this->GeneratorTarget->GetType() < cmStateEnums::UTILITY) {
  3792. isAppContainer = true;
  3793. } else if (isWindowsPhone &&
  3794. this->GeneratorTarget->GetType() ==
  3795. cmStateEnums::EXECUTABLE) {
  3796. e1.Element("XapOutputs", "true");
  3797. e1.Element("XapFilename",
  3798. this->Name + "_$(Configuration)_$(Platform).xap");
  3799. }
  3800. }
  3801. }
  3802. if (isAppContainer) {
  3803. e1.Element("AppContainerApplication", "true");
  3804. } else if (this->Platform == "ARM64") {
  3805. e1.Element("WindowsSDKDesktopARM64Support", "true");
  3806. } else if (this->Platform == "ARM") {
  3807. e1.Element("WindowsSDKDesktopARMSupport", "true");
  3808. }
  3809. std::string const& targetPlatformVersion =
  3810. gg->GetWindowsTargetPlatformVersion();
  3811. if (!targetPlatformVersion.empty()) {
  3812. e1.Element("WindowsTargetPlatformVersion", targetPlatformVersion);
  3813. }
  3814. const char* targetPlatformMinVersion = this->GeneratorTarget->GetProperty(
  3815. "VS_WINDOWS_TARGET_PLATFORM_MIN_VERSION");
  3816. if (targetPlatformMinVersion) {
  3817. e1.Element("WindowsTargetPlatformMinVersion", targetPlatformMinVersion);
  3818. } else if (isWindowsStore && cmHasLiteralPrefix(v, "10.0")) {
  3819. // If the min version is not set, then use the TargetPlatformVersion
  3820. if (!targetPlatformVersion.empty()) {
  3821. e1.Element("WindowsTargetPlatformMinVersion", targetPlatformVersion);
  3822. }
  3823. }
  3824. // Added IoT Startup Task support
  3825. if (this->GeneratorTarget->GetPropertyAsBool("VS_IOT_STARTUP_TASK")) {
  3826. e1.Element("ContainsStartupTask", "true");
  3827. }
  3828. }
  3829. void cmVisualStudio10TargetGenerator::VerifyNecessaryFiles()
  3830. {
  3831. // For Windows and Windows Phone executables, we will assume that if a
  3832. // manifest is not present that we need to add all the necessary files
  3833. if (this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE) {
  3834. std::vector<cmSourceFile const*> manifestSources;
  3835. this->GeneratorTarget->GetAppManifest(manifestSources, "");
  3836. {
  3837. std::string const& v = this->GlobalGenerator->GetSystemVersion();
  3838. if (this->GlobalGenerator->TargetsWindowsPhone()) {
  3839. if (v == "8.0") {
  3840. // Look through the sources for WMAppManifest.xml
  3841. std::vector<cmSourceFile const*> extraSources;
  3842. this->GeneratorTarget->GetExtraSources(extraSources, "");
  3843. bool foundManifest = false;
  3844. for (cmSourceFile const* si : extraSources) {
  3845. // Need to do a lowercase comparison on the filename
  3846. if ("wmappmanifest.xml" ==
  3847. cmSystemTools::LowerCase(si->GetLocation().GetName())) {
  3848. foundManifest = true;
  3849. break;
  3850. }
  3851. }
  3852. if (!foundManifest) {
  3853. this->IsMissingFiles = true;
  3854. }
  3855. } else if (v == "8.1") {
  3856. if (manifestSources.empty()) {
  3857. this->IsMissingFiles = true;
  3858. }
  3859. }
  3860. } else if (this->GlobalGenerator->TargetsWindowsStore()) {
  3861. if (manifestSources.empty()) {
  3862. if (v == "8.0") {
  3863. this->IsMissingFiles = true;
  3864. } else if (v == "8.1" || cmHasLiteralPrefix(v, "10.0")) {
  3865. this->IsMissingFiles = true;
  3866. }
  3867. }
  3868. }
  3869. }
  3870. }
  3871. }
  3872. void cmVisualStudio10TargetGenerator::WriteMissingFiles(Elem& e1)
  3873. {
  3874. std::string const& v = this->GlobalGenerator->GetSystemVersion();
  3875. if (this->GlobalGenerator->TargetsWindowsPhone()) {
  3876. if (v == "8.0") {
  3877. this->WriteMissingFilesWP80(e1);
  3878. } else if (v == "8.1") {
  3879. this->WriteMissingFilesWP81(e1);
  3880. }
  3881. } else if (this->GlobalGenerator->TargetsWindowsStore()) {
  3882. if (v == "8.0") {
  3883. this->WriteMissingFilesWS80(e1);
  3884. } else if (v == "8.1") {
  3885. this->WriteMissingFilesWS81(e1);
  3886. } else if (cmHasLiteralPrefix(v, "10.0")) {
  3887. this->WriteMissingFilesWS10_0(e1);
  3888. }
  3889. }
  3890. }
  3891. void cmVisualStudio10TargetGenerator::WriteMissingFilesWP80(Elem& e1)
  3892. {
  3893. std::string templateFolder =
  3894. cmSystemTools::GetCMakeRoot() + "/Templates/Windows";
  3895. // For WP80, the manifest needs to be in the same folder as the project
  3896. // this can cause an overwrite problem if projects aren't organized in
  3897. // folders
  3898. std::string manifestFile =
  3899. this->LocalGenerator->GetCurrentBinaryDirectory() + "/WMAppManifest.xml";
  3900. std::string artifactDir =
  3901. this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
  3902. ConvertToWindowsSlash(artifactDir);
  3903. std::string artifactDirXML = cmVS10EscapeXML(artifactDir);
  3904. std::string targetNameXML =
  3905. cmVS10EscapeXML(this->GeneratorTarget->GetName());
  3906. cmGeneratedFileStream fout(manifestFile);
  3907. fout.SetCopyIfDifferent(true);
  3908. /* clang-format off */
  3909. fout <<
  3910. "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
  3911. "<Deployment"
  3912. " xmlns=\"http://schemas.microsoft.com/windowsphone/2012/deployment\""
  3913. " AppPlatformVersion=\"8.0\">\n"
  3914. "\t<DefaultLanguage xmlns=\"\" code=\"en-US\"/>\n"
  3915. "\t<App xmlns=\"\" ProductID=\"{" << this->GUID << "}\""
  3916. " Title=\"CMake Test Program\" RuntimeType=\"Modern Native\""
  3917. " Version=\"1.0.0.0\" Genre=\"apps.normal\" Author=\"CMake\""
  3918. " Description=\"Default CMake App\" Publisher=\"CMake\""
  3919. " PublisherID=\"{" << this->GUID << "}\">\n"
  3920. "\t\t<IconPath IsRelative=\"true\" IsResource=\"false\">"
  3921. << artifactDirXML << "\\ApplicationIcon.png</IconPath>\n"
  3922. "\t\t<Capabilities/>\n"
  3923. "\t\t<Tasks>\n"
  3924. "\t\t\t<DefaultTask Name=\"_default\""
  3925. " ImagePath=\"" << targetNameXML << ".exe\" ImageParams=\"\" />\n"
  3926. "\t\t</Tasks>\n"
  3927. "\t\t<Tokens>\n"
  3928. "\t\t\t<PrimaryToken TokenID=\"" << targetNameXML << "Token\""
  3929. " TaskName=\"_default\">\n"
  3930. "\t\t\t\t<TemplateFlip>\n"
  3931. "\t\t\t\t\t<SmallImageURI IsRelative=\"true\" IsResource=\"false\">"
  3932. << artifactDirXML << "\\SmallLogo.png</SmallImageURI>\n"
  3933. "\t\t\t\t\t<Count>0</Count>\n"
  3934. "\t\t\t\t\t<BackgroundImageURI IsRelative=\"true\" IsResource=\"false\">"
  3935. << artifactDirXML << "\\Logo.png</BackgroundImageURI>\n"
  3936. "\t\t\t\t</TemplateFlip>\n"
  3937. "\t\t\t</PrimaryToken>\n"
  3938. "\t\t</Tokens>\n"
  3939. "\t\t<ScreenResolutions>\n"
  3940. "\t\t\t<ScreenResolution Name=\"ID_RESOLUTION_WVGA\" />\n"
  3941. "\t\t</ScreenResolutions>\n"
  3942. "\t</App>\n"
  3943. "</Deployment>\n";
  3944. /* clang-format on */
  3945. std::string sourceFile = this->ConvertPath(manifestFile, false);
  3946. ConvertToWindowsSlash(sourceFile);
  3947. {
  3948. Elem e2(e1, "Xml");
  3949. e2.Attribute("Include", sourceFile);
  3950. e2.Element("SubType", "Designer");
  3951. }
  3952. this->AddedFiles.push_back(sourceFile);
  3953. std::string smallLogo = this->DefaultArtifactDir + "/SmallLogo.png";
  3954. cmSystemTools::CopyAFile(templateFolder + "/SmallLogo.png", smallLogo,
  3955. false);
  3956. ConvertToWindowsSlash(smallLogo);
  3957. Elem(e1, "Image").Attribute("Include", smallLogo);
  3958. this->AddedFiles.push_back(smallLogo);
  3959. std::string logo = this->DefaultArtifactDir + "/Logo.png";
  3960. cmSystemTools::CopyAFile(templateFolder + "/Logo.png", logo, false);
  3961. ConvertToWindowsSlash(logo);
  3962. Elem(e1, "Image").Attribute("Include", logo);
  3963. this->AddedFiles.push_back(logo);
  3964. std::string applicationIcon =
  3965. this->DefaultArtifactDir + "/ApplicationIcon.png";
  3966. cmSystemTools::CopyAFile(templateFolder + "/ApplicationIcon.png",
  3967. applicationIcon, false);
  3968. ConvertToWindowsSlash(applicationIcon);
  3969. Elem(e1, "Image").Attribute("Include", applicationIcon);
  3970. this->AddedFiles.push_back(applicationIcon);
  3971. }
  3972. void cmVisualStudio10TargetGenerator::WriteMissingFilesWP81(Elem& e1)
  3973. {
  3974. std::string manifestFile =
  3975. this->DefaultArtifactDir + "/package.appxManifest";
  3976. std::string artifactDir =
  3977. this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
  3978. ConvertToWindowsSlash(artifactDir);
  3979. std::string artifactDirXML = cmVS10EscapeXML(artifactDir);
  3980. std::string targetNameXML =
  3981. cmVS10EscapeXML(this->GeneratorTarget->GetName());
  3982. cmGeneratedFileStream fout(manifestFile);
  3983. fout.SetCopyIfDifferent(true);
  3984. /* clang-format off */
  3985. fout <<
  3986. "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
  3987. "<Package xmlns=\"http://schemas.microsoft.com/appx/2010/manifest\""
  3988. " xmlns:m2=\"http://schemas.microsoft.com/appx/2013/manifest\""
  3989. " xmlns:mp=\"http://schemas.microsoft.com/appx/2014/phone/manifest\">\n"
  3990. "\t<Identity Name=\"" << this->GUID << "\" Publisher=\"CN=CMake\""
  3991. " Version=\"1.0.0.0\" />\n"
  3992. "\t<mp:PhoneIdentity PhoneProductId=\"" << this->GUID << "\""
  3993. " PhonePublisherId=\"00000000-0000-0000-0000-000000000000\"/>\n"
  3994. "\t<Properties>\n"
  3995. "\t\t<DisplayName>" << targetNameXML << "</DisplayName>\n"
  3996. "\t\t<PublisherDisplayName>CMake</PublisherDisplayName>\n"
  3997. "\t\t<Logo>" << artifactDirXML << "\\StoreLogo.png</Logo>\n"
  3998. "\t</Properties>\n"
  3999. "\t<Prerequisites>\n"
  4000. "\t\t<OSMinVersion>6.3.1</OSMinVersion>\n"
  4001. "\t\t<OSMaxVersionTested>6.3.1</OSMaxVersionTested>\n"
  4002. "\t</Prerequisites>\n"
  4003. "\t<Resources>\n"
  4004. "\t\t<Resource Language=\"x-generate\" />\n"
  4005. "\t</Resources>\n"
  4006. "\t<Applications>\n"
  4007. "\t\t<Application Id=\"App\""
  4008. " Executable=\"" << targetNameXML << ".exe\""
  4009. " EntryPoint=\"" << targetNameXML << ".App\">\n"
  4010. "\t\t\t<m2:VisualElements\n"
  4011. "\t\t\t\tDisplayName=\"" << targetNameXML << "\"\n"
  4012. "\t\t\t\tDescription=\"" << targetNameXML << "\"\n"
  4013. "\t\t\t\tBackgroundColor=\"#336699\"\n"
  4014. "\t\t\t\tForegroundText=\"light\"\n"
  4015. "\t\t\t\tSquare150x150Logo=\"" << artifactDirXML << "\\Logo.png\"\n"
  4016. "\t\t\t\tSquare30x30Logo=\"" << artifactDirXML << "\\SmallLogo.png\">\n"
  4017. "\t\t\t\t<m2:DefaultTile ShortName=\"" << targetNameXML << "\">\n"
  4018. "\t\t\t\t\t<m2:ShowNameOnTiles>\n"
  4019. "\t\t\t\t\t\t<m2:ShowOn Tile=\"square150x150Logo\" />\n"
  4020. "\t\t\t\t\t</m2:ShowNameOnTiles>\n"
  4021. "\t\t\t\t</m2:DefaultTile>\n"
  4022. "\t\t\t\t<m2:SplashScreen"
  4023. " Image=\"" << artifactDirXML << "\\SplashScreen.png\" />\n"
  4024. "\t\t\t</m2:VisualElements>\n"
  4025. "\t\t</Application>\n"
  4026. "\t</Applications>\n"
  4027. "</Package>\n";
  4028. /* clang-format on */
  4029. this->WriteCommonMissingFiles(e1, manifestFile);
  4030. }
  4031. void cmVisualStudio10TargetGenerator::WriteMissingFilesWS80(Elem& e1)
  4032. {
  4033. std::string manifestFile =
  4034. this->DefaultArtifactDir + "/package.appxManifest";
  4035. std::string artifactDir =
  4036. this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
  4037. ConvertToWindowsSlash(artifactDir);
  4038. std::string artifactDirXML = cmVS10EscapeXML(artifactDir);
  4039. std::string targetNameXML =
  4040. cmVS10EscapeXML(this->GeneratorTarget->GetName());
  4041. cmGeneratedFileStream fout(manifestFile);
  4042. fout.SetCopyIfDifferent(true);
  4043. /* clang-format off */
  4044. fout <<
  4045. "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
  4046. "<Package xmlns=\"http://schemas.microsoft.com/appx/2010/manifest\">\n"
  4047. "\t<Identity Name=\"" << this->GUID << "\" Publisher=\"CN=CMake\""
  4048. " Version=\"1.0.0.0\" />\n"
  4049. "\t<Properties>\n"
  4050. "\t\t<DisplayName>" << targetNameXML << "</DisplayName>\n"
  4051. "\t\t<PublisherDisplayName>CMake</PublisherDisplayName>\n"
  4052. "\t\t<Logo>" << artifactDirXML << "\\StoreLogo.png</Logo>\n"
  4053. "\t</Properties>\n"
  4054. "\t<Prerequisites>\n"
  4055. "\t\t<OSMinVersion>6.2.1</OSMinVersion>\n"
  4056. "\t\t<OSMaxVersionTested>6.2.1</OSMaxVersionTested>\n"
  4057. "\t</Prerequisites>\n"
  4058. "\t<Resources>\n"
  4059. "\t\t<Resource Language=\"x-generate\" />\n"
  4060. "\t</Resources>\n"
  4061. "\t<Applications>\n"
  4062. "\t\t<Application Id=\"App\""
  4063. " Executable=\"" << targetNameXML << ".exe\""
  4064. " EntryPoint=\"" << targetNameXML << ".App\">\n"
  4065. "\t\t\t<VisualElements"
  4066. " DisplayName=\"" << targetNameXML << "\""
  4067. " Description=\"" << targetNameXML << "\""
  4068. " BackgroundColor=\"#336699\" ForegroundText=\"light\""
  4069. " Logo=\"" << artifactDirXML << "\\Logo.png\""
  4070. " SmallLogo=\"" << artifactDirXML << "\\SmallLogo.png\">\n"
  4071. "\t\t\t\t<DefaultTile ShowName=\"allLogos\""
  4072. " ShortName=\"" << targetNameXML << "\" />\n"
  4073. "\t\t\t\t<SplashScreen"
  4074. " Image=\"" << artifactDirXML << "\\SplashScreen.png\" />\n"
  4075. "\t\t\t</VisualElements>\n"
  4076. "\t\t</Application>\n"
  4077. "\t</Applications>\n"
  4078. "</Package>\n";
  4079. /* clang-format on */
  4080. this->WriteCommonMissingFiles(e1, manifestFile);
  4081. }
  4082. void cmVisualStudio10TargetGenerator::WriteMissingFilesWS81(Elem& e1)
  4083. {
  4084. std::string manifestFile =
  4085. this->DefaultArtifactDir + "/package.appxManifest";
  4086. std::string artifactDir =
  4087. this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
  4088. ConvertToWindowsSlash(artifactDir);
  4089. std::string artifactDirXML = cmVS10EscapeXML(artifactDir);
  4090. std::string targetNameXML =
  4091. cmVS10EscapeXML(this->GeneratorTarget->GetName());
  4092. cmGeneratedFileStream fout(manifestFile);
  4093. fout.SetCopyIfDifferent(true);
  4094. /* clang-format off */
  4095. fout <<
  4096. "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
  4097. "<Package xmlns=\"http://schemas.microsoft.com/appx/2010/manifest\""
  4098. " xmlns:m2=\"http://schemas.microsoft.com/appx/2013/manifest\">\n"
  4099. "\t<Identity Name=\"" << this->GUID << "\" Publisher=\"CN=CMake\""
  4100. " Version=\"1.0.0.0\" />\n"
  4101. "\t<Properties>\n"
  4102. "\t\t<DisplayName>" << targetNameXML << "</DisplayName>\n"
  4103. "\t\t<PublisherDisplayName>CMake</PublisherDisplayName>\n"
  4104. "\t\t<Logo>" << artifactDirXML << "\\StoreLogo.png</Logo>\n"
  4105. "\t</Properties>\n"
  4106. "\t<Prerequisites>\n"
  4107. "\t\t<OSMinVersion>6.3</OSMinVersion>\n"
  4108. "\t\t<OSMaxVersionTested>6.3</OSMaxVersionTested>\n"
  4109. "\t</Prerequisites>\n"
  4110. "\t<Resources>\n"
  4111. "\t\t<Resource Language=\"x-generate\" />\n"
  4112. "\t</Resources>\n"
  4113. "\t<Applications>\n"
  4114. "\t\t<Application Id=\"App\""
  4115. " Executable=\"" << targetNameXML << ".exe\""
  4116. " EntryPoint=\"" << targetNameXML << ".App\">\n"
  4117. "\t\t\t<m2:VisualElements\n"
  4118. "\t\t\t\tDisplayName=\"" << targetNameXML << "\"\n"
  4119. "\t\t\t\tDescription=\"" << targetNameXML << "\"\n"
  4120. "\t\t\t\tBackgroundColor=\"#336699\"\n"
  4121. "\t\t\t\tForegroundText=\"light\"\n"
  4122. "\t\t\t\tSquare150x150Logo=\"" << artifactDirXML << "\\Logo.png\"\n"
  4123. "\t\t\t\tSquare30x30Logo=\"" << artifactDirXML << "\\SmallLogo.png\">\n"
  4124. "\t\t\t\t<m2:DefaultTile ShortName=\"" << targetNameXML << "\">\n"
  4125. "\t\t\t\t\t<m2:ShowNameOnTiles>\n"
  4126. "\t\t\t\t\t\t<m2:ShowOn Tile=\"square150x150Logo\" />\n"
  4127. "\t\t\t\t\t</m2:ShowNameOnTiles>\n"
  4128. "\t\t\t\t</m2:DefaultTile>\n"
  4129. "\t\t\t\t<m2:SplashScreen"
  4130. " Image=\"" << artifactDirXML << "\\SplashScreen.png\" />\n"
  4131. "\t\t\t</m2:VisualElements>\n"
  4132. "\t\t</Application>\n"
  4133. "\t</Applications>\n"
  4134. "</Package>\n";
  4135. /* clang-format on */
  4136. this->WriteCommonMissingFiles(e1, manifestFile);
  4137. }
  4138. void cmVisualStudio10TargetGenerator::WriteMissingFilesWS10_0(Elem& e1)
  4139. {
  4140. std::string manifestFile =
  4141. this->DefaultArtifactDir + "/package.appxManifest";
  4142. std::string artifactDir =
  4143. this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
  4144. ConvertToWindowsSlash(artifactDir);
  4145. std::string artifactDirXML = cmVS10EscapeXML(artifactDir);
  4146. std::string targetNameXML =
  4147. cmVS10EscapeXML(this->GeneratorTarget->GetName());
  4148. cmGeneratedFileStream fout(manifestFile);
  4149. fout.SetCopyIfDifferent(true);
  4150. /* clang-format off */
  4151. fout <<
  4152. "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
  4153. "<Package\n\t"
  4154. "xmlns=\"http://schemas.microsoft.com/appx/manifest/foundation/windows10\""
  4155. "\txmlns:mp=\"http://schemas.microsoft.com/appx/2014/phone/manifest\"\n"
  4156. "\txmlns:uap=\"http://schemas.microsoft.com/appx/manifest/uap/windows10\""
  4157. "\n\tIgnorableNamespaces=\"uap mp\">\n\n"
  4158. "\t<Identity Name=\"" << this->GUID << "\" Publisher=\"CN=CMake\""
  4159. " Version=\"1.0.0.0\" />\n"
  4160. "\t<mp:PhoneIdentity PhoneProductId=\"" << this->GUID <<
  4161. "\" PhonePublisherId=\"00000000-0000-0000-0000-000000000000\"/>\n"
  4162. "\t<Properties>\n"
  4163. "\t\t<DisplayName>" << targetNameXML << "</DisplayName>\n"
  4164. "\t\t<PublisherDisplayName>CMake</PublisherDisplayName>\n"
  4165. "\t\t<Logo>" << artifactDirXML << "\\StoreLogo.png</Logo>\n"
  4166. "\t</Properties>\n"
  4167. "\t<Dependencies>\n"
  4168. "\t\t<TargetDeviceFamily Name=\"Windows.Universal\" "
  4169. "MinVersion=\"10.0.0.0\" MaxVersionTested=\"10.0.0.0\" />\n"
  4170. "\t</Dependencies>\n"
  4171. "\t<Resources>\n"
  4172. "\t\t<Resource Language=\"x-generate\" />\n"
  4173. "\t</Resources>\n"
  4174. "\t<Applications>\n"
  4175. "\t\t<Application Id=\"App\""
  4176. " Executable=\"" << targetNameXML << ".exe\""
  4177. " EntryPoint=\"" << targetNameXML << ".App\">\n"
  4178. "\t\t\t<uap:VisualElements\n"
  4179. "\t\t\t\tDisplayName=\"" << targetNameXML << "\"\n"
  4180. "\t\t\t\tDescription=\"" << targetNameXML << "\"\n"
  4181. "\t\t\t\tBackgroundColor=\"#336699\"\n"
  4182. "\t\t\t\tSquare150x150Logo=\"" << artifactDirXML << "\\Logo.png\"\n"
  4183. "\t\t\t\tSquare44x44Logo=\"" << artifactDirXML <<
  4184. "\\SmallLogo44x44.png\">\n"
  4185. "\t\t\t\t<uap:SplashScreen"
  4186. " Image=\"" << artifactDirXML << "\\SplashScreen.png\" />\n"
  4187. "\t\t\t</uap:VisualElements>\n"
  4188. "\t\t</Application>\n"
  4189. "\t</Applications>\n"
  4190. "</Package>\n";
  4191. /* clang-format on */
  4192. this->WriteCommonMissingFiles(e1, manifestFile);
  4193. }
  4194. void cmVisualStudio10TargetGenerator::WriteCommonMissingFiles(
  4195. Elem& e1, const std::string& manifestFile)
  4196. {
  4197. std::string templateFolder =
  4198. cmSystemTools::GetCMakeRoot() + "/Templates/Windows";
  4199. std::string sourceFile = this->ConvertPath(manifestFile, false);
  4200. ConvertToWindowsSlash(sourceFile);
  4201. {
  4202. Elem e2(e1, "AppxManifest");
  4203. e2.Attribute("Include", sourceFile);
  4204. e2.Element("SubType", "Designer");
  4205. }
  4206. this->AddedFiles.push_back(sourceFile);
  4207. std::string smallLogo = this->DefaultArtifactDir + "/SmallLogo.png";
  4208. cmSystemTools::CopyAFile(templateFolder + "/SmallLogo.png", smallLogo,
  4209. false);
  4210. ConvertToWindowsSlash(smallLogo);
  4211. Elem(e1, "Image").Attribute("Include", smallLogo);
  4212. this->AddedFiles.push_back(smallLogo);
  4213. std::string smallLogo44 = this->DefaultArtifactDir + "/SmallLogo44x44.png";
  4214. cmSystemTools::CopyAFile(templateFolder + "/SmallLogo44x44.png", smallLogo44,
  4215. false);
  4216. ConvertToWindowsSlash(smallLogo44);
  4217. Elem(e1, "Image").Attribute("Include", smallLogo44);
  4218. this->AddedFiles.push_back(smallLogo44);
  4219. std::string logo = this->DefaultArtifactDir + "/Logo.png";
  4220. cmSystemTools::CopyAFile(templateFolder + "/Logo.png", logo, false);
  4221. ConvertToWindowsSlash(logo);
  4222. Elem(e1, "Image").Attribute("Include", logo);
  4223. this->AddedFiles.push_back(logo);
  4224. std::string storeLogo = this->DefaultArtifactDir + "/StoreLogo.png";
  4225. cmSystemTools::CopyAFile(templateFolder + "/StoreLogo.png", storeLogo,
  4226. false);
  4227. ConvertToWindowsSlash(storeLogo);
  4228. Elem(e1, "Image").Attribute("Include", storeLogo);
  4229. this->AddedFiles.push_back(storeLogo);
  4230. std::string splashScreen = this->DefaultArtifactDir + "/SplashScreen.png";
  4231. cmSystemTools::CopyAFile(templateFolder + "/SplashScreen.png", splashScreen,
  4232. false);
  4233. ConvertToWindowsSlash(splashScreen);
  4234. Elem(e1, "Image").Attribute("Include", splashScreen);
  4235. this->AddedFiles.push_back(splashScreen);
  4236. if (this->AddedDefaultCertificate) {
  4237. // This file has already been added to the build so don't copy it
  4238. std::string keyFile =
  4239. this->DefaultArtifactDir + "/Windows_TemporaryKey.pfx";
  4240. ConvertToWindowsSlash(keyFile);
  4241. Elem(e1, "None").Attribute("Include", keyFile);
  4242. }
  4243. }
  4244. bool cmVisualStudio10TargetGenerator::ForceOld(const std::string& source) const
  4245. {
  4246. HANDLE h =
  4247. CreateFileW(cmSystemTools::ConvertToWindowsExtendedPath(source).c_str(),
  4248. FILE_WRITE_ATTRIBUTES, FILE_SHARE_WRITE, 0, OPEN_EXISTING,
  4249. FILE_FLAG_BACKUP_SEMANTICS, 0);
  4250. if (!h) {
  4251. return false;
  4252. }
  4253. FILETIME const ftime_20010101 = { 3365781504u, 29389701u };
  4254. if (!SetFileTime(h, &ftime_20010101, &ftime_20010101, &ftime_20010101)) {
  4255. CloseHandle(h);
  4256. return false;
  4257. }
  4258. CloseHandle(h);
  4259. return true;
  4260. }
  4261. void cmVisualStudio10TargetGenerator::GetCSharpSourceProperties(
  4262. cmSourceFile const* sf, std::map<std::string, std::string>& tags)
  4263. {
  4264. if (this->ProjectType == csproj) {
  4265. const cmPropertyMap& props = sf->GetProperties();
  4266. for (auto const& p : props) {
  4267. static const std::string propNamePrefix = "VS_CSHARP_";
  4268. if (p.first.find(propNamePrefix) == 0) {
  4269. std::string tagName = p.first.substr(propNamePrefix.length());
  4270. if (!tagName.empty()) {
  4271. const std::string val = props.GetPropertyValue(p.first);
  4272. if (!val.empty()) {
  4273. tags[tagName] = val;
  4274. } else {
  4275. tags.erase(tagName);
  4276. }
  4277. }
  4278. }
  4279. }
  4280. }
  4281. }
  4282. void cmVisualStudio10TargetGenerator::WriteCSharpSourceProperties(
  4283. Elem& e2, const std::map<std::string, std::string>& tags)
  4284. {
  4285. if (!tags.empty()) {
  4286. for (const auto& i : tags) {
  4287. e2.Element(i.first.c_str(), i.second);
  4288. }
  4289. }
  4290. }
  4291. void cmVisualStudio10TargetGenerator::GetCSharpSourceLink(
  4292. cmSourceFile const* sf, std::string& link)
  4293. {
  4294. std::string const& sourceFilePath = sf->GetFullPath();
  4295. std::string const& binaryDir = LocalGenerator->GetCurrentBinaryDirectory();
  4296. if (!cmSystemTools::IsSubDirectory(sourceFilePath, binaryDir)) {
  4297. const std::string& stripFromPath =
  4298. this->Makefile->GetCurrentSourceDirectory();
  4299. if (sourceFilePath.find(stripFromPath) == 0) {
  4300. if (const char* l = sf->GetProperty("VS_CSHARP_Link")) {
  4301. link = l;
  4302. } else {
  4303. link = sourceFilePath.substr(stripFromPath.length() + 1);
  4304. }
  4305. ConvertToWindowsSlash(link);
  4306. }
  4307. }
  4308. }
  4309. std::string cmVisualStudio10TargetGenerator::GetCMakeFilePath(
  4310. const char* relativeFilePath) const
  4311. {
  4312. // Always search in the standard modules location.
  4313. std::string path = cmSystemTools::GetCMakeRoot() + "/";
  4314. path += relativeFilePath;
  4315. ConvertToWindowsSlash(path);
  4316. return path;
  4317. }