cmVisualStudio10TargetGenerator.cxx 160 KB

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