cmVisualStudio10TargetGenerator.cxx 166 KB

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