cmVisualStudio10TargetGenerator.cxx 165 KB

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