cmVisualStudio10TargetGenerator.cxx 168 KB

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