cmVisualStudio10TargetGenerator.cxx 161 KB

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