cmVisualStudio10TargetGenerator.cxx 168 KB

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