cmVisualStudio10TargetGenerator.cxx 159 KB

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