cmVisualStudio10TargetGenerator.cxx 169 KB

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