cmVisualStudio10TargetGenerator.cxx 130 KB

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