cmVisualStudio10TargetGenerator.cxx 162 KB

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