cmVisualStudio10TargetGenerator.cxx 167 KB

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