cmVisualStudio10TargetGenerator.cxx 152 KB

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