cmVisualStudio10TargetGenerator.cxx 149 KB

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