cmVisualStudio10TargetGenerator.cxx 161 KB

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