cmVisualStudio10TargetGenerator.cxx 165 KB

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