cmVisualStudio10TargetGenerator.cxx 159 KB

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