cmVisualStudio10TargetGenerator.cxx 166 KB

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