cmVisualStudio10TargetGenerator.cxx 158 KB

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