cmVisualStudio10TargetGenerator.cxx 157 KB

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