cmVisualStudio10TargetGenerator.cxx 167 KB

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