cmVisualStudio10TargetGenerator.cxx 165 KB

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