cmVisualStudio10TargetGenerator.cxx 160 KB

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