cmVisualStudio10TargetGenerator.cxx 159 KB

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