cmVisualStudio10TargetGenerator.cxx 133 KB

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