cmVisualStudio10TargetGenerator.cxx 160 KB

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