cmVisualStudio10TargetGenerator.cxx 166 KB

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