cmLocalVisualStudio7Generator.cxx 78 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154
  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 "cmLocalVisualStudio7Generator.h"
  4. #include "cmCustomCommandGenerator.h"
  5. #include "cmGeneratorTarget.h"
  6. #include "cmGlobalVisualStudio7Generator.h"
  7. #include "cmMakefile.h"
  8. #include "cmSourceFile.h"
  9. #include "cmSystemTools.h"
  10. #include "cmXMLParser.h"
  11. #include "cm_expat.h"
  12. #include "cmake.h"
  13. #include "cmComputeLinkInformation.h"
  14. #include "cmGeneratedFileStream.h"
  15. #include <ctype.h> // for isspace
  16. #include <windows.h>
  17. static bool cmLVS7G_IsFAT(const char* dir);
  18. class cmLocalVisualStudio7GeneratorInternals
  19. {
  20. public:
  21. cmLocalVisualStudio7GeneratorInternals(cmLocalVisualStudio7Generator* e)
  22. : LocalGenerator(e)
  23. {
  24. }
  25. typedef cmComputeLinkInformation::ItemVector ItemVector;
  26. void OutputLibraries(std::ostream& fout, ItemVector const& libs);
  27. void OutputObjects(std::ostream& fout, cmGeneratorTarget* t,
  28. std::string const& config, const char* isep = 0);
  29. private:
  30. cmLocalVisualStudio7Generator* LocalGenerator;
  31. };
  32. class cmLocalVisualStudio7Generator::AllConfigSources
  33. {
  34. public:
  35. std::vector<cmGeneratorTarget::AllConfigSource> Sources;
  36. std::map<cmSourceFile const*, size_t> Index;
  37. };
  38. extern cmVS7FlagTable cmLocalVisualStudio7GeneratorFlagTable[];
  39. static void cmConvertToWindowsSlash(std::string& s)
  40. {
  41. std::string::size_type pos = 0;
  42. while ((pos = s.find('/', pos)) != std::string::npos) {
  43. s[pos] = '\\';
  44. pos++;
  45. }
  46. }
  47. cmLocalVisualStudio7Generator::cmLocalVisualStudio7Generator(
  48. cmGlobalGenerator* gg, cmMakefile* mf)
  49. : cmLocalVisualStudioGenerator(gg, mf)
  50. {
  51. this->Internal = new cmLocalVisualStudio7GeneratorInternals(this);
  52. }
  53. cmLocalVisualStudio7Generator::~cmLocalVisualStudio7Generator()
  54. {
  55. delete this->Internal;
  56. }
  57. void cmLocalVisualStudio7Generator::AddHelperCommands()
  58. {
  59. // Now create GUIDs for targets
  60. const std::vector<cmGeneratorTarget*>& tgts = this->GetGeneratorTargets();
  61. for (std::vector<cmGeneratorTarget*>::const_iterator l = tgts.begin();
  62. l != tgts.end(); ++l) {
  63. if ((*l)->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
  64. continue;
  65. }
  66. const char* path = (*l)->GetProperty("EXTERNAL_MSPROJECT");
  67. if (path) {
  68. this->ReadAndStoreExternalGUID((*l)->GetName().c_str(), path);
  69. }
  70. }
  71. this->FixGlobalTargets();
  72. }
  73. void cmLocalVisualStudio7Generator::Generate()
  74. {
  75. this->WriteProjectFiles();
  76. this->WriteStampFiles();
  77. }
  78. void cmLocalVisualStudio7Generator::FixGlobalTargets()
  79. {
  80. // Visual Studio .NET 2003 Service Pack 1 will not run post-build
  81. // commands for targets in which no sources are built. Add dummy
  82. // rules to force these targets to build.
  83. const std::vector<cmGeneratorTarget*>& tgts = this->GetGeneratorTargets();
  84. for (std::vector<cmGeneratorTarget*>::const_iterator l = tgts.begin();
  85. l != tgts.end(); l++) {
  86. if ((*l)->GetType() == cmStateEnums::GLOBAL_TARGET) {
  87. std::vector<std::string> no_depends;
  88. cmCustomCommandLine force_command;
  89. force_command.push_back("cd");
  90. force_command.push_back(".");
  91. cmCustomCommandLines force_commands;
  92. force_commands.push_back(force_command);
  93. std::string no_main_dependency;
  94. std::string force = this->GetCurrentBinaryDirectory();
  95. force += cmake::GetCMakeFilesDirectory();
  96. force += "/";
  97. force += (*l)->GetName();
  98. force += "_force";
  99. if (cmSourceFile* file = this->Makefile->AddCustomCommandToOutput(
  100. force.c_str(), no_depends, no_main_dependency, force_commands, " ",
  101. 0, true)) {
  102. (*l)->AddSource(file->GetFullPath());
  103. }
  104. }
  105. }
  106. }
  107. // TODO
  108. // for CommandLine= need to repleace quotes with &quot
  109. // write out configurations
  110. void cmLocalVisualStudio7Generator::WriteProjectFiles()
  111. {
  112. // If not an in source build, then create the output directory
  113. if (strcmp(this->GetCurrentBinaryDirectory(), this->GetSourceDirectory()) !=
  114. 0) {
  115. if (!cmSystemTools::MakeDirectory(this->GetCurrentBinaryDirectory())) {
  116. cmSystemTools::Error("Error creating directory ",
  117. this->GetCurrentBinaryDirectory());
  118. }
  119. }
  120. // Get the set of targets in this directory.
  121. const std::vector<cmGeneratorTarget*>& tgts = this->GetGeneratorTargets();
  122. // Create the project file for each target.
  123. for (std::vector<cmGeneratorTarget*>::const_iterator l = tgts.begin();
  124. l != tgts.end(); l++) {
  125. if ((*l)->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
  126. continue;
  127. }
  128. // INCLUDE_EXTERNAL_MSPROJECT command only affects the workspace
  129. // so don't build a projectfile for it
  130. if (!(*l)->GetProperty("EXTERNAL_MSPROJECT")) {
  131. this->CreateSingleVCProj((*l)->GetName().c_str(), *l);
  132. }
  133. }
  134. }
  135. void cmLocalVisualStudio7Generator::WriteStampFiles()
  136. {
  137. // Touch a timestamp file used to determine when the project file is
  138. // out of date.
  139. std::string stampName = this->GetCurrentBinaryDirectory();
  140. stampName += cmake::GetCMakeFilesDirectory();
  141. cmSystemTools::MakeDirectory(stampName.c_str());
  142. stampName += "/";
  143. stampName += "generate.stamp";
  144. cmsys::ofstream stamp(stampName.c_str());
  145. stamp << "# CMake generation timestamp file for this directory.\n";
  146. // Create a helper file so CMake can determine when it is run
  147. // through the rule created by CreateVCProjBuildRule whether it
  148. // really needs to regenerate the project. This file lists its own
  149. // dependencies. If any file listed in it is newer than itself then
  150. // CMake must rerun. Otherwise the project files are up to date and
  151. // the stamp file can just be touched.
  152. std::string depName = stampName;
  153. depName += ".depend";
  154. cmsys::ofstream depFile(depName.c_str());
  155. depFile << "# CMake generation dependency list for this directory.\n";
  156. std::vector<std::string> const& listFiles = this->Makefile->GetListFiles();
  157. for (std::vector<std::string>::const_iterator lf = listFiles.begin();
  158. lf != listFiles.end(); ++lf) {
  159. depFile << *lf << std::endl;
  160. }
  161. }
  162. void cmLocalVisualStudio7Generator::CreateSingleVCProj(
  163. const std::string& lname, cmGeneratorTarget* target)
  164. {
  165. cmGlobalVisualStudioGenerator* gg =
  166. static_cast<cmGlobalVisualStudioGenerator*>(this->GlobalGenerator);
  167. this->FortranProject = gg->TargetIsFortranOnly(target);
  168. this->WindowsCEProject = gg->TargetsWindowsCE();
  169. // Intel Fortran for VS10 uses VS9 format ".vfproj" files.
  170. cmGlobalVisualStudioGenerator::VSVersion realVersion = gg->GetVersion();
  171. if (this->FortranProject &&
  172. gg->GetVersion() >= cmGlobalVisualStudioGenerator::VS10) {
  173. gg->SetVersion(cmGlobalVisualStudioGenerator::VS9);
  174. }
  175. // add to the list of projects
  176. target->Target->SetProperty("GENERATOR_FILE_NAME", lname.c_str());
  177. // create the dsp.cmake file
  178. std::string fname;
  179. fname = this->GetCurrentBinaryDirectory();
  180. fname += "/";
  181. fname += lname;
  182. if (this->FortranProject) {
  183. fname += ".vfproj";
  184. } else {
  185. fname += ".vcproj";
  186. }
  187. // Generate the project file and replace it atomically with
  188. // copy-if-different. We use a separate timestamp so that the IDE
  189. // does not reload project files unnecessarily.
  190. cmGeneratedFileStream fout(fname.c_str());
  191. fout.SetCopyIfDifferent(true);
  192. this->WriteVCProjFile(fout, lname, target);
  193. if (fout.Close()) {
  194. this->GlobalGenerator->FileReplacedDuringGenerate(fname);
  195. }
  196. gg->SetVersion(realVersion);
  197. }
  198. cmSourceFile* cmLocalVisualStudio7Generator::CreateVCProjBuildRule()
  199. {
  200. if (this->Makefile->IsOn("CMAKE_SUPPRESS_REGENERATION")) {
  201. return nullptr;
  202. }
  203. std::string makefileIn = this->GetCurrentSourceDirectory();
  204. makefileIn += "/";
  205. makefileIn += "CMakeLists.txt";
  206. makefileIn = cmSystemTools::CollapseFullPath(makefileIn);
  207. if (cmSourceFile* file = this->Makefile->GetSource(makefileIn)) {
  208. if (file->GetCustomCommand()) {
  209. return file;
  210. }
  211. }
  212. if (!cmSystemTools::FileExists(makefileIn)) {
  213. return nullptr;
  214. }
  215. std::string stampName = this->GetCurrentBinaryDirectory();
  216. stampName += "/";
  217. stampName += cmake::GetCMakeFilesDirectoryPostSlash();
  218. stampName += "generate.stamp";
  219. cmCustomCommandLine commandLine;
  220. commandLine.push_back(cmSystemTools::GetCMakeCommand());
  221. std::string comment = "Building Custom Rule ";
  222. comment += makefileIn;
  223. std::string args;
  224. args = "-H";
  225. args += this->GetSourceDirectory();
  226. commandLine.push_back(args);
  227. args = "-B";
  228. args += this->GetBinaryDirectory();
  229. commandLine.push_back(args);
  230. commandLine.push_back("--check-stamp-file");
  231. commandLine.push_back(stampName);
  232. std::vector<std::string> const& listFiles = this->Makefile->GetListFiles();
  233. cmCustomCommandLines commandLines;
  234. commandLines.push_back(commandLine);
  235. const char* no_working_directory = 0;
  236. std::string fullpathStampName =
  237. cmSystemTools::CollapseFullPath(stampName.c_str());
  238. this->Makefile->AddCustomCommandToOutput(
  239. fullpathStampName.c_str(), listFiles, makefileIn.c_str(), commandLines,
  240. comment.c_str(), no_working_directory, true, false);
  241. if (cmSourceFile* file = this->Makefile->GetSource(makefileIn.c_str())) {
  242. // Finalize the source file path now since we're adding this after
  243. // the generator validated all project-named sources.
  244. file->GetFullPath();
  245. return file;
  246. } else {
  247. cmSystemTools::Error("Error adding rule for ", makefileIn.c_str());
  248. return nullptr;
  249. }
  250. }
  251. void cmLocalVisualStudio7Generator::WriteConfigurations(
  252. std::ostream& fout, std::vector<std::string> const& configs,
  253. const std::string& libName, cmGeneratorTarget* target)
  254. {
  255. fout << "\t<Configurations>\n";
  256. for (std::vector<std::string>::const_iterator i = configs.begin();
  257. i != configs.end(); ++i) {
  258. this->WriteConfiguration(fout, i->c_str(), libName, target);
  259. }
  260. fout << "\t</Configurations>\n";
  261. }
  262. cmVS7FlagTable cmLocalVisualStudio7GeneratorFortranFlagTable[] = {
  263. { "Preprocess", "fpp", "Run Preprocessor on files", "preprocessYes", 0 },
  264. { "SuppressStartupBanner", "nologo", "SuppressStartupBanner", "true", 0 },
  265. { "SourceFileFormat", "fixed", "Use Fixed Format", "fileFormatFixed", 0 },
  266. { "SourceFileFormat", "free", "Use Free Format", "fileFormatFree", 0 },
  267. { "DebugInformationFormat", "Zi", "full debug", "debugEnabled", 0 },
  268. { "DebugInformationFormat", "debug:full", "full debug", "debugEnabled", 0 },
  269. { "DebugInformationFormat", "Z7", "c7 compat", "debugOldStyleInfo", 0 },
  270. { "DebugInformationFormat", "Zd", "line numbers", "debugLineInfoOnly", 0 },
  271. { "Optimization", "Od", "disable optimization", "optimizeDisabled", 0 },
  272. { "Optimization", "O1", "min space", "optimizeMinSpace", 0 },
  273. { "Optimization", "O3", "full optimize", "optimizeFull", 0 },
  274. { "GlobalOptimizations", "Og", "global optimize", "true", 0 },
  275. { "InlineFunctionExpansion", "Ob0", "", "expandDisable", 0 },
  276. { "InlineFunctionExpansion", "Ob1", "", "expandOnlyInline", 0 },
  277. { "FavorSizeOrSpeed", "Os", "", "favorSize", 0 },
  278. { "OmitFramePointers", "Oy-", "", "false", 0 },
  279. { "OptimizeForProcessor", "GB", "", "procOptimizeBlended", 0 },
  280. { "OptimizeForProcessor", "G5", "", "procOptimizePentium", 0 },
  281. { "OptimizeForProcessor", "G6", "", "procOptimizePentiumProThruIII", 0 },
  282. { "UseProcessorExtensions", "QzxK", "", "codeForStreamingSIMD", 0 },
  283. { "OptimizeForProcessor", "QaxN", "", "codeForPentium4", 0 },
  284. { "OptimizeForProcessor", "QaxB", "", "codeForPentiumM", 0 },
  285. { "OptimizeForProcessor", "QaxP", "", "codeForCodeNamedPrescott", 0 },
  286. { "OptimizeForProcessor", "QaxT", "", "codeForCore2Duo", 0 },
  287. { "OptimizeForProcessor", "QxK", "", "codeExclusivelyStreamingSIMD", 0 },
  288. { "OptimizeForProcessor", "QxN", "", "codeExclusivelyPentium4", 0 },
  289. { "OptimizeForProcessor", "QxB", "", "codeExclusivelyPentiumM", 0 },
  290. { "OptimizeForProcessor", "QxP", "", "codeExclusivelyCodeNamedPrescott", 0 },
  291. { "OptimizeForProcessor", "QxT", "", "codeExclusivelyCore2Duo", 0 },
  292. { "OptimizeForProcessor", "QxO", "", "codeExclusivelyCore2StreamingSIMD",
  293. 0 },
  294. { "OptimizeForProcessor", "QxS", "", "codeExclusivelyCore2StreamingSIMD4",
  295. 0 },
  296. { "OpenMP", "Qopenmp", "", "OpenMPParallelCode", 0 },
  297. { "OpenMP", "Qopenmp-stubs", "", "OpenMPSequentialCode", 0 },
  298. { "Traceback", "traceback", "", "true", 0 },
  299. { "Traceback", "notraceback", "", "false", 0 },
  300. { "FloatingPointExceptionHandling", "fpe:0", "", "fpe0", 0 },
  301. { "FloatingPointExceptionHandling", "fpe:1", "", "fpe1", 0 },
  302. { "FloatingPointExceptionHandling", "fpe:3", "", "fpe3", 0 },
  303. { "MultiProcessorCompilation", "MP", "", "true",
  304. cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue },
  305. { "ProcessorNumber", "MP", "Multi-processor Compilation", "",
  306. cmVS7FlagTable::UserValueRequired },
  307. { "ModulePath", "module:", "", "", cmVS7FlagTable::UserValueRequired },
  308. { "LoopUnrolling", "Qunroll:", "", "", cmVS7FlagTable::UserValueRequired },
  309. { "AutoParallelThreshold", "Qpar-threshold:", "", "",
  310. cmVS7FlagTable::UserValueRequired },
  311. { "HeapArrays", "heap-arrays:", "", "", cmVS7FlagTable::UserValueRequired },
  312. { "ObjectText", "bintext:", "", "", cmVS7FlagTable::UserValueRequired },
  313. { "Parallelization", "Qparallel", "", "true", 0 },
  314. { "PrefetchInsertion", "Qprefetch-", "", "false", 0 },
  315. { "BufferedIO", "assume:buffered_io", "", "true", 0 },
  316. { "CallingConvention", "iface:stdcall", "", "callConventionStdCall", 0 },
  317. { "CallingConvention", "iface:cref", "", "callConventionCRef", 0 },
  318. { "CallingConvention", "iface:stdref", "", "callConventionStdRef", 0 },
  319. { "CallingConvention", "iface:stdcall", "", "callConventionStdCall", 0 },
  320. { "CallingConvention", "iface:cvf", "", "callConventionCVF", 0 },
  321. { "EnableRecursion", "recursive", "", "true", 0 },
  322. { "ReentrantCode", "reentrancy", "", "true", 0 },
  323. // done up to Language
  324. { 0, 0, 0, 0, 0 }
  325. };
  326. // fill the table here currently the comment field is not used for
  327. // anything other than documentation NOTE: Make sure the longer
  328. // commandFlag comes FIRST!
  329. cmVS7FlagTable cmLocalVisualStudio7GeneratorFlagTable[] = {
  330. // option flags (some flags map to the same option)
  331. { "BasicRuntimeChecks", "GZ", "Stack frame checks", "1", 0 },
  332. { "BasicRuntimeChecks", "RTCsu", "Both stack and uninitialized checks", "3",
  333. 0 },
  334. { "BasicRuntimeChecks", "RTCs", "Stack frame checks", "1", 0 },
  335. { "BasicRuntimeChecks", "RTCu", "Uninitialized Variables ", "2", 0 },
  336. { "BasicRuntimeChecks", "RTC1", "Both stack and uninitialized checks", "3",
  337. 0 },
  338. { "DebugInformationFormat", "Z7", "debug format", "1", 0 },
  339. { "DebugInformationFormat", "Zd", "debug format", "2", 0 },
  340. { "DebugInformationFormat", "Zi", "debug format", "3", 0 },
  341. { "DebugInformationFormat", "ZI", "debug format", "4", 0 },
  342. { "EnableEnhancedInstructionSet", "arch:SSE2", "Use sse2 instructions", "2",
  343. 0 },
  344. { "EnableEnhancedInstructionSet", "arch:SSE", "Use sse instructions", "1",
  345. 0 },
  346. { "FloatingPointModel", "fp:precise", "Use precise floating point model",
  347. "0", 0 },
  348. { "FloatingPointModel", "fp:strict", "Use strict floating point model", "1",
  349. 0 },
  350. { "FloatingPointModel", "fp:fast", "Use fast floating point model", "2", 0 },
  351. { "FavorSizeOrSpeed", "Ot", "Favor fast code", "1", 0 },
  352. { "FavorSizeOrSpeed", "Os", "Favor small code", "2", 0 },
  353. { "CompileAs", "TC", "Compile as c code", "1", 0 },
  354. { "CompileAs", "TP", "Compile as c++ code", "2", 0 },
  355. { "Optimization", "Od", "Non Debug", "0", 0 },
  356. { "Optimization", "O1", "Min Size", "1", 0 },
  357. { "Optimization", "O2", "Max Speed", "2", 0 },
  358. { "Optimization", "Ox", "Max Optimization", "3", 0 },
  359. { "OptimizeForProcessor", "GB", "Blended processor mode", "0", 0 },
  360. { "OptimizeForProcessor", "G5", "Pentium", "1", 0 },
  361. { "OptimizeForProcessor", "G6", "PPro PII PIII", "2", 0 },
  362. { "OptimizeForProcessor", "G7", "Pentium 4 or Athlon", "3", 0 },
  363. { "InlineFunctionExpansion", "Ob0", "no inlines", "0", 0 },
  364. { "InlineFunctionExpansion", "Ob1", "when inline keyword", "1", 0 },
  365. { "InlineFunctionExpansion", "Ob2", "any time you can inline", "2", 0 },
  366. { "RuntimeLibrary", "MTd", "Multithreaded debug", "1", 0 },
  367. { "RuntimeLibrary", "MT", "Multithreaded", "0", 0 },
  368. { "RuntimeLibrary", "MDd", "Multithreaded dll debug", "3", 0 },
  369. { "RuntimeLibrary", "MD", "Multithreaded dll", "2", 0 },
  370. { "RuntimeLibrary", "MLd", "Single Thread debug", "5", 0 },
  371. { "RuntimeLibrary", "ML", "Single Thread", "4", 0 },
  372. { "StructMemberAlignment", "Zp16", "struct align 16 byte ", "5", 0 },
  373. { "StructMemberAlignment", "Zp1", "struct align 1 byte ", "1", 0 },
  374. { "StructMemberAlignment", "Zp2", "struct align 2 byte ", "2", 0 },
  375. { "StructMemberAlignment", "Zp4", "struct align 4 byte ", "3", 0 },
  376. { "StructMemberAlignment", "Zp8", "struct align 8 byte ", "4", 0 },
  377. { "WarningLevel", "W0", "Warning level", "0", 0 },
  378. { "WarningLevel", "W1", "Warning level", "1", 0 },
  379. { "WarningLevel", "W2", "Warning level", "2", 0 },
  380. { "WarningLevel", "W3", "Warning level", "3", 0 },
  381. { "WarningLevel", "W4", "Warning level", "4", 0 },
  382. { "DisableSpecificWarnings", "wd", "Disable specific warnings", "",
  383. cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable },
  384. // Precompiled header and related options. Note that the
  385. // UsePrecompiledHeader entries are marked as "Continue" so that the
  386. // corresponding PrecompiledHeaderThrough entry can be found.
  387. { "UsePrecompiledHeader", "Yc", "Create Precompiled Header", "1",
  388. cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue },
  389. { "PrecompiledHeaderThrough", "Yc", "Precompiled Header Name", "",
  390. cmVS7FlagTable::UserValueRequired },
  391. { "PrecompiledHeaderFile", "Fp", "Generated Precompiled Header", "",
  392. cmVS7FlagTable::UserValue },
  393. // The YX and Yu options are in a per-global-generator table because
  394. // their values differ based on the VS IDE version.
  395. { "ForcedIncludeFiles", "FI", "Forced include files", "",
  396. cmVS7FlagTable::UserValueRequired | cmVS7FlagTable::SemicolonAppendable },
  397. { "AssemblerListingLocation", "Fa", "ASM List Location", "",
  398. cmVS7FlagTable::UserValue },
  399. { "ProgramDataBaseFileName", "Fd", "Program Database File Name", "",
  400. cmVS7FlagTable::UserValue },
  401. // boolean flags
  402. { "BufferSecurityCheck", "GS", "Buffer security check", "true", 0 },
  403. { "BufferSecurityCheck", "GS-", "Turn off Buffer security check", "false",
  404. 0 },
  405. { "Detect64BitPortabilityProblems", "Wp64",
  406. "Detect 64-bit Portability Problems", "true", 0 },
  407. { "EnableFiberSafeOptimizations", "GT", "Enable Fiber-safe Optimizations",
  408. "true", 0 },
  409. { "EnableFunctionLevelLinking", "Gy", "EnableFunctionLevelLinking", "true",
  410. 0 },
  411. { "EnableIntrinsicFunctions", "Oi", "EnableIntrinsicFunctions", "true", 0 },
  412. { "GlobalOptimizations", "Og", "Global Optimize", "true", 0 },
  413. { "ImproveFloatingPointConsistency", "Op", "ImproveFloatingPointConsistency",
  414. "true", 0 },
  415. { "MinimalRebuild", "Gm", "minimal rebuild", "true", 0 },
  416. { "OmitFramePointers", "Oy", "OmitFramePointers", "true", 0 },
  417. { "OptimizeForWindowsApplication", "GA", "Optimize for windows", "true", 0 },
  418. { "RuntimeTypeInfo", "GR", "Turn on Run time type information for c++",
  419. "true", 0 },
  420. { "RuntimeTypeInfo", "GR-", "Turn off Run time type information for c++",
  421. "false", 0 },
  422. { "SmallerTypeCheck", "RTCc", "smaller type check", "true", 0 },
  423. { "SuppressStartupBanner", "nologo", "SuppressStartupBanner", "true", 0 },
  424. { "WholeProgramOptimization", "GL", "Enables whole program optimization",
  425. "true", 0 },
  426. { "WholeProgramOptimization", "GL-", "Disables whole program optimization",
  427. "false", 0 },
  428. { "WarnAsError", "WX", "Treat warnings as errors", "true", 0 },
  429. { "BrowseInformation", "FR", "Generate browse information", "1", 0 },
  430. { "StringPooling", "GF", "Enable StringPooling", "true", 0 },
  431. { 0, 0, 0, 0, 0 }
  432. };
  433. cmVS7FlagTable cmLocalVisualStudio7GeneratorLinkFlagTable[] = {
  434. // option flags (some flags map to the same option)
  435. { "GenerateManifest", "MANIFEST:NO", "disable manifest generation", "false",
  436. 0 },
  437. { "GenerateManifest", "MANIFEST", "enable manifest generation", "true", 0 },
  438. { "LinkIncremental", "INCREMENTAL:NO", "link incremental", "1", 0 },
  439. { "LinkIncremental", "INCREMENTAL:YES", "link incremental", "2", 0 },
  440. { "CLRUnmanagedCodeCheck", "CLRUNMANAGEDCODECHECK:NO", "", "false", 0 },
  441. { "CLRUnmanagedCodeCheck", "CLRUNMANAGEDCODECHECK", "", "true", 0 },
  442. { "DataExecutionPrevention", "NXCOMPAT:NO",
  443. "Not known to work with Windows Data Execution Prevention", "1", 0 },
  444. { "DataExecutionPrevention", "NXCOMPAT",
  445. "Known to work with Windows Data Execution Prevention", "2", 0 },
  446. { "DelaySign", "DELAYSIGN:NO", "", "false", 0 },
  447. { "DelaySign", "DELAYSIGN", "", "true", 0 },
  448. { "EntryPointSymbol", "ENTRY:", "sets the starting address", "",
  449. cmVS7FlagTable::UserValue },
  450. { "IgnoreDefaultLibraryNames", "NODEFAULTLIB:", "default libs to ignore", "",
  451. cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable },
  452. { "IgnoreAllDefaultLibraries", "NODEFAULTLIB", "ignore all default libs",
  453. "true", 0 },
  454. { "FixedBaseAddress", "FIXED:NO", "Generate a relocation section", "1", 0 },
  455. { "FixedBaseAddress", "FIXED", "Image must be loaded at a fixed address",
  456. "2", 0 },
  457. { "EnableCOMDATFolding", "OPT:NOICF", "Do not remove redundant COMDATs", "1",
  458. 0 },
  459. { "EnableCOMDATFolding", "OPT:ICF", "Remove redundant COMDATs", "2", 0 },
  460. { "ResourceOnlyDLL", "NOENTRY", "Create DLL with no entry point", "true",
  461. 0 },
  462. { "OptimizeReferences", "OPT:NOREF", "Keep unreferenced data", "1", 0 },
  463. { "OptimizeReferences", "OPT:REF", "Eliminate unreferenced data", "2", 0 },
  464. { "Profile", "PROFILE", "", "true", 0 },
  465. { "RandomizedBaseAddress", "DYNAMICBASE:NO",
  466. "Image may not be rebased at load-time", "1", 0 },
  467. { "RandomizedBaseAddress", "DYNAMICBASE",
  468. "Image may be rebased at load-time", "2", 0 },
  469. { "SetChecksum", "RELEASE", "Enable setting checksum in header", "true", 0 },
  470. { "SupportUnloadOfDelayLoadedDLL", "DELAY:UNLOAD", "", "true", 0 },
  471. { "TargetMachine", "MACHINE:I386", "Machine x86", "1", 0 },
  472. { "TargetMachine", "MACHINE:X86", "Machine x86", "1", 0 },
  473. { "TargetMachine", "MACHINE:AM33", "Machine AM33", "2", 0 },
  474. { "TargetMachine", "MACHINE:ARM", "Machine ARM", "3", 0 },
  475. { "TargetMachine", "MACHINE:EBC", "Machine EBC", "4", 0 },
  476. { "TargetMachine", "MACHINE:IA64", "Machine IA64", "5", 0 },
  477. { "TargetMachine", "MACHINE:M32R", "Machine M32R", "6", 0 },
  478. { "TargetMachine", "MACHINE:MIPS", "Machine MIPS", "7", 0 },
  479. { "TargetMachine", "MACHINE:MIPS16", "Machine MIPS16", "8", 0 },
  480. { "TargetMachine", "MACHINE:MIPSFPU)", "Machine MIPSFPU", "9", 0 },
  481. { "TargetMachine", "MACHINE:MIPSFPU16", "Machine MIPSFPU16", "10", 0 },
  482. { "TargetMachine", "MACHINE:MIPSR41XX", "Machine MIPSR41XX", "11", 0 },
  483. { "TargetMachine", "MACHINE:SH3", "Machine SH3", "12", 0 },
  484. { "TargetMachine", "MACHINE:SH3DSP", "Machine SH3DSP", "13", 0 },
  485. { "TargetMachine", "MACHINE:SH4", "Machine SH4", "14", 0 },
  486. { "TargetMachine", "MACHINE:SH5", "Machine SH5", "15", 0 },
  487. { "TargetMachine", "MACHINE:THUMB", "Machine THUMB", "16", 0 },
  488. { "TargetMachine", "MACHINE:X64", "Machine x64", "17", 0 },
  489. { "TargetMachine", "MACHINE:ARM64", "Machine ARM64", "18", 0 },
  490. { "TurnOffAssemblyGeneration", "NOASSEMBLY",
  491. "No assembly even if CLR information is present in objects.", "true", 0 },
  492. { "ModuleDefinitionFile", "DEF:", "add an export def file", "",
  493. cmVS7FlagTable::UserValue },
  494. { "GenerateMapFile", "MAP", "enable generation of map file", "true", 0 },
  495. { 0, 0, 0, 0, 0 }
  496. };
  497. cmVS7FlagTable cmLocalVisualStudio7GeneratorFortranLinkFlagTable[] = {
  498. { "LinkIncremental", "INCREMENTAL:NO", "link incremental",
  499. "linkIncrementalNo", 0 },
  500. { "LinkIncremental", "INCREMENTAL:YES", "link incremental",
  501. "linkIncrementalYes", 0 },
  502. { 0, 0, 0, 0, 0 }
  503. };
  504. // Helper class to write build event <Tool .../> elements.
  505. class cmLocalVisualStudio7Generator::EventWriter
  506. {
  507. public:
  508. EventWriter(cmLocalVisualStudio7Generator* lg, const std::string& config,
  509. std::ostream& os)
  510. : LG(lg)
  511. , Config(config)
  512. , Stream(os)
  513. , First(true)
  514. {
  515. }
  516. void Start(const char* tool)
  517. {
  518. this->First = true;
  519. this->Stream << "\t\t\t<Tool\n\t\t\t\tName=\"" << tool << "\"";
  520. }
  521. void Finish() { this->Stream << (this->First ? "" : "\"") << "/>\n"; }
  522. void Write(std::vector<cmCustomCommand> const& ccs)
  523. {
  524. for (std::vector<cmCustomCommand>::const_iterator ci = ccs.begin();
  525. ci != ccs.end(); ++ci) {
  526. this->Write(*ci);
  527. }
  528. }
  529. void Write(cmCustomCommand const& cc)
  530. {
  531. cmCustomCommandGenerator ccg(cc, this->Config, this->LG);
  532. if (this->First) {
  533. const char* comment = ccg.GetComment();
  534. if (comment && *comment) {
  535. this->Stream << "\nDescription=\"" << this->LG->EscapeForXML(comment)
  536. << "\"";
  537. }
  538. this->Stream << "\nCommandLine=\"";
  539. this->First = false;
  540. } else {
  541. this->Stream << this->LG->EscapeForXML("\n");
  542. }
  543. std::string script = this->LG->ConstructScript(ccg);
  544. this->Stream << this->LG->EscapeForXML(script.c_str());
  545. }
  546. private:
  547. cmLocalVisualStudio7Generator* LG;
  548. std::string Config;
  549. std::ostream& Stream;
  550. bool First;
  551. };
  552. void cmLocalVisualStudio7Generator::WriteConfiguration(
  553. std::ostream& fout, const std::string& configName,
  554. const std::string& libName, cmGeneratorTarget* target)
  555. {
  556. const char* mfcFlag = this->Makefile->GetDefinition("CMAKE_MFC_FLAG");
  557. if (!mfcFlag) {
  558. mfcFlag = "0";
  559. }
  560. cmGlobalVisualStudio7Generator* gg =
  561. static_cast<cmGlobalVisualStudio7Generator*>(this->GlobalGenerator);
  562. fout << "\t\t<Configuration\n"
  563. << "\t\t\tName=\"" << configName << "|" << gg->GetPlatformName()
  564. << "\"\n";
  565. // This is an internal type to Visual Studio, it seems that:
  566. // 4 == static library
  567. // 2 == dll
  568. // 1 == executable
  569. // 10 == utility
  570. const char* configType = "10";
  571. const char* projectType = 0;
  572. bool targetBuilds = true;
  573. switch (target->GetType()) {
  574. case cmStateEnums::OBJECT_LIBRARY:
  575. targetBuilds = false; // no manifest tool for object library
  576. case cmStateEnums::STATIC_LIBRARY:
  577. projectType = "typeStaticLibrary";
  578. configType = "4";
  579. break;
  580. case cmStateEnums::SHARED_LIBRARY:
  581. case cmStateEnums::MODULE_LIBRARY:
  582. projectType = "typeDynamicLibrary";
  583. configType = "2";
  584. break;
  585. case cmStateEnums::EXECUTABLE:
  586. configType = "1";
  587. break;
  588. case cmStateEnums::UTILITY:
  589. case cmStateEnums::GLOBAL_TARGET:
  590. configType = "10";
  591. default:
  592. targetBuilds = false;
  593. break;
  594. }
  595. if (this->FortranProject && projectType) {
  596. configType = projectType;
  597. }
  598. std::string flags;
  599. if (strcmp(configType, "10") != 0) {
  600. const std::string& linkLanguage =
  601. (this->FortranProject ? std::string("Fortran")
  602. : target->GetLinkerLanguage(configName));
  603. if (linkLanguage.empty()) {
  604. cmSystemTools::Error(
  605. "CMake can not determine linker language for target: ",
  606. target->GetName().c_str());
  607. return;
  608. }
  609. if (linkLanguage == "C" || linkLanguage == "CXX" ||
  610. linkLanguage == "Fortran") {
  611. std::string baseFlagVar = "CMAKE_";
  612. baseFlagVar += linkLanguage;
  613. baseFlagVar += "_FLAGS";
  614. flags = this->Makefile->GetRequiredDefinition(baseFlagVar.c_str());
  615. std::string flagVar =
  616. baseFlagVar + std::string("_") + cmSystemTools::UpperCase(configName);
  617. flags += " ";
  618. flags += this->Makefile->GetRequiredDefinition(flagVar.c_str());
  619. }
  620. // set the correct language
  621. if (linkLanguage == "C") {
  622. flags += " /TC ";
  623. }
  624. if (linkLanguage == "CXX") {
  625. flags += " /TP ";
  626. }
  627. // Add the target-specific flags.
  628. this->AddCompileOptions(flags, target, linkLanguage, configName);
  629. // Check IPO related warning/error.
  630. target->IsIPOEnabled(linkLanguage, configName);
  631. }
  632. if (this->FortranProject) {
  633. switch (cmOutputConverter::GetFortranFormat(
  634. target->GetProperty("Fortran_FORMAT"))) {
  635. case cmOutputConverter::FortranFormatFixed:
  636. flags += " -fixed";
  637. break;
  638. case cmOutputConverter::FortranFormatFree:
  639. flags += " -free";
  640. break;
  641. default:
  642. break;
  643. }
  644. }
  645. // Get preprocessor definitions for this directory.
  646. std::string defineFlags = this->Makefile->GetDefineFlags();
  647. Options::Tool t = Options::Compiler;
  648. cmVS7FlagTable const* table = cmLocalVisualStudio7GeneratorFlagTable;
  649. if (this->FortranProject) {
  650. t = Options::FortranCompiler;
  651. table = cmLocalVisualStudio7GeneratorFortranFlagTable;
  652. }
  653. Options targetOptions(this, t, table, gg->ExtraFlagTable);
  654. targetOptions.FixExceptionHandlingDefault();
  655. std::string asmLocation = configName + "/";
  656. targetOptions.AddFlag("AssemblerListingLocation", asmLocation.c_str());
  657. targetOptions.Parse(flags.c_str());
  658. targetOptions.Parse(defineFlags.c_str());
  659. targetOptions.ParseFinish();
  660. std::vector<std::string> targetDefines;
  661. target->GetCompileDefinitions(targetDefines, configName, "CXX");
  662. targetOptions.AddDefines(targetDefines);
  663. targetOptions.SetVerboseMakefile(
  664. this->Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE"));
  665. // Add a definition for the configuration name.
  666. std::string configDefine = "CMAKE_INTDIR=\"";
  667. configDefine += configName;
  668. configDefine += "\"";
  669. targetOptions.AddDefine(configDefine);
  670. // Add the export symbol definition for shared library objects.
  671. if (const char* exportMacro = target->GetExportMacro()) {
  672. targetOptions.AddDefine(exportMacro);
  673. }
  674. // The intermediate directory name consists of a directory for the
  675. // target and a subdirectory for the configuration name.
  676. std::string intermediateDir = this->GetTargetDirectory(target);
  677. intermediateDir += "/";
  678. intermediateDir += configName;
  679. if (target->GetType() < cmStateEnums::UTILITY) {
  680. std::string const& outDir =
  681. target->GetType() == cmStateEnums::OBJECT_LIBRARY
  682. ? intermediateDir
  683. : target->GetDirectory(configName);
  684. /* clang-format off */
  685. fout << "\t\t\tOutputDirectory=\""
  686. << this->ConvertToXMLOutputPathSingle(outDir.c_str()) << "\"\n";
  687. /* clang-format on */
  688. }
  689. /* clang-format off */
  690. fout << "\t\t\tIntermediateDirectory=\""
  691. << this->ConvertToXMLOutputPath(intermediateDir.c_str())
  692. << "\"\n"
  693. << "\t\t\tConfigurationType=\"" << configType << "\"\n"
  694. << "\t\t\tUseOfMFC=\"" << mfcFlag << "\"\n"
  695. << "\t\t\tATLMinimizesCRunTimeLibraryUsage=\"false\"\n";
  696. /* clang-format on */
  697. if (this->FortranProject) {
  698. // Intel Fortran >= 15.0 uses TargetName property.
  699. std::string const targetNameFull = target->GetFullName(configName);
  700. std::string const targetName =
  701. cmSystemTools::GetFilenameWithoutLastExtension(targetNameFull);
  702. std::string const targetExt =
  703. target->GetType() == cmStateEnums::OBJECT_LIBRARY
  704. ? ".lib"
  705. : cmSystemTools::GetFilenameLastExtension(targetNameFull);
  706. /* clang-format off */
  707. fout <<
  708. "\t\t\tTargetName=\"" << this->EscapeForXML(targetName) << "\"\n"
  709. "\t\t\tTargetExt=\"" << this->EscapeForXML(targetExt) << "\"\n"
  710. ;
  711. /* clang-format on */
  712. }
  713. // If unicode is enabled change the character set to unicode, if not
  714. // then default to MBCS.
  715. if (targetOptions.UsingUnicode()) {
  716. fout << "\t\t\tCharacterSet=\"1\">\n";
  717. } else if (targetOptions.UsingSBCS()) {
  718. fout << "\t\t\tCharacterSet=\"0\">\n";
  719. } else {
  720. fout << "\t\t\tCharacterSet=\"2\">\n";
  721. }
  722. const char* tool = "VCCLCompilerTool";
  723. if (this->FortranProject) {
  724. tool = "VFFortranCompilerTool";
  725. }
  726. fout << "\t\t\t<Tool\n"
  727. << "\t\t\t\tName=\"" << tool << "\"\n";
  728. if (this->FortranProject) {
  729. const char* target_mod_dir =
  730. target->GetProperty("Fortran_MODULE_DIRECTORY");
  731. std::string modDir;
  732. if (target_mod_dir) {
  733. modDir = this->ConvertToRelativePath(this->GetCurrentBinaryDirectory(),
  734. target_mod_dir);
  735. } else {
  736. modDir = ".";
  737. }
  738. fout << "\t\t\t\tModulePath=\""
  739. << this->ConvertToXMLOutputPath(modDir.c_str())
  740. << "\\$(ConfigurationName)\"\n";
  741. }
  742. fout << "\t\t\t\tAdditionalIncludeDirectories=\"";
  743. std::vector<std::string> includes;
  744. this->GetIncludeDirectories(includes, target, "C", configName);
  745. std::vector<std::string>::iterator i = includes.begin();
  746. for (; i != includes.end(); ++i) {
  747. // output the include path
  748. std::string ipath = this->ConvertToXMLOutputPath(i->c_str());
  749. fout << ipath << ";";
  750. // if this is fortran then output the include with
  751. // a ConfigurationName on the end of it.
  752. if (this->FortranProject) {
  753. ipath = i->c_str();
  754. ipath += "/$(ConfigurationName)";
  755. ipath = this->ConvertToXMLOutputPath(ipath.c_str());
  756. fout << ipath << ";";
  757. }
  758. }
  759. fout << "\"\n";
  760. targetOptions.OutputFlagMap(fout, "\t\t\t\t");
  761. targetOptions.OutputPreprocessorDefinitions(fout, "\t\t\t\t", "\n", "CXX");
  762. fout << "\t\t\t\tObjectFile=\"$(IntDir)\\\"\n";
  763. if (target->GetType() <= cmStateEnums::OBJECT_LIBRARY) {
  764. // Specify the compiler program database file if configured.
  765. std::string pdb = target->GetCompilePDBPath(configName);
  766. if (!pdb.empty()) {
  767. fout << "\t\t\t\tProgramDataBaseFileName=\""
  768. << this->ConvertToXMLOutputPathSingle(pdb.c_str()) << "\"\n";
  769. }
  770. }
  771. fout << "/>\n"; // end of <Tool Name=VCCLCompilerTool
  772. if (gg->IsMasmEnabled() && !this->FortranProject) {
  773. Options masmOptions(this, Options::MasmCompiler, 0, 0);
  774. /* clang-format off */
  775. fout <<
  776. "\t\t\t<Tool\n"
  777. "\t\t\t\tName=\"MASM\"\n"
  778. "\t\t\t\tIncludePaths=\""
  779. ;
  780. /* clang-format on */
  781. const char* sep = "";
  782. for (i = includes.begin(); i != includes.end(); ++i) {
  783. std::string inc = *i;
  784. cmConvertToWindowsSlash(inc);
  785. fout << sep << this->EscapeForXML(inc);
  786. sep = ";";
  787. }
  788. fout << "\"\n";
  789. // Use same preprocessor definitions as VCCLCompilerTool.
  790. targetOptions.OutputPreprocessorDefinitions(fout, "\t\t\t\t", "\n",
  791. "ASM_MASM");
  792. masmOptions.OutputFlagMap(fout, "\t\t\t\t");
  793. /* clang-format off */
  794. fout <<
  795. "\t\t\t\tObjectFile=\"$(IntDir)\\\"\n"
  796. "\t\t\t/>\n";
  797. /* clang-format on */
  798. }
  799. tool = "VCCustomBuildTool";
  800. if (this->FortranProject) {
  801. tool = "VFCustomBuildTool";
  802. }
  803. fout << "\t\t\t<Tool\n\t\t\t\tName=\"" << tool << "\"/>\n";
  804. tool = "VCResourceCompilerTool";
  805. if (this->FortranProject) {
  806. tool = "VFResourceCompilerTool";
  807. }
  808. fout << "\t\t\t<Tool\n\t\t\t\tName=\"" << tool << "\"\n"
  809. << "\t\t\t\tAdditionalIncludeDirectories=\"";
  810. for (i = includes.begin(); i != includes.end(); ++i) {
  811. std::string ipath = this->ConvertToXMLOutputPath(i->c_str());
  812. fout << ipath << ";";
  813. }
  814. // add the -D flags to the RC tool
  815. fout << "\"";
  816. targetOptions.OutputPreprocessorDefinitions(fout, "\n\t\t\t\t", "", "RC");
  817. fout << "/>\n";
  818. tool = "VCMIDLTool";
  819. if (this->FortranProject) {
  820. tool = "VFMIDLTool";
  821. }
  822. fout << "\t\t\t<Tool\n\t\t\t\tName=\"" << tool << "\"\n";
  823. fout << "\t\t\t\tAdditionalIncludeDirectories=\"";
  824. for (i = includes.begin(); i != includes.end(); ++i) {
  825. std::string ipath = this->ConvertToXMLOutputPath(i->c_str());
  826. fout << ipath << ";";
  827. }
  828. fout << "\"\n";
  829. fout << "\t\t\t\tMkTypLibCompatible=\"false\"\n";
  830. if (gg->GetPlatformName() == "x64") {
  831. fout << "\t\t\t\tTargetEnvironment=\"3\"\n";
  832. } else if (gg->GetPlatformName() == "ia64") {
  833. fout << "\t\t\t\tTargetEnvironment=\"2\"\n";
  834. } else {
  835. fout << "\t\t\t\tTargetEnvironment=\"1\"\n";
  836. }
  837. fout << "\t\t\t\tGenerateStublessProxies=\"true\"\n";
  838. fout << "\t\t\t\tTypeLibraryName=\"$(InputName).tlb\"\n";
  839. fout << "\t\t\t\tOutputDirectory=\"$(IntDir)\"\n";
  840. fout << "\t\t\t\tHeaderFileName=\"$(InputName).h\"\n";
  841. fout << "\t\t\t\tDLLDataFileName=\"\"\n";
  842. fout << "\t\t\t\tInterfaceIdentifierFileName=\"$(InputName)_i.c\"\n";
  843. fout << "\t\t\t\tProxyFileName=\"$(InputName)_p.c\"/>\n";
  844. // end of <Tool Name=VCMIDLTool
  845. // Add manifest tool settings.
  846. if (targetBuilds) {
  847. const char* manifestTool = "VCManifestTool";
  848. if (this->FortranProject) {
  849. manifestTool = "VFManifestTool";
  850. }
  851. /* clang-format off */
  852. fout <<
  853. "\t\t\t<Tool\n"
  854. "\t\t\t\tName=\"" << manifestTool << "\"";
  855. /* clang-format on */
  856. std::vector<cmSourceFile const*> manifest_srcs;
  857. target->GetManifests(manifest_srcs, configName);
  858. if (!manifest_srcs.empty()) {
  859. fout << "\n\t\t\t\tAdditionalManifestFiles=\"";
  860. for (std::vector<cmSourceFile const*>::const_iterator mi =
  861. manifest_srcs.begin();
  862. mi != manifest_srcs.end(); ++mi) {
  863. std::string m = (*mi)->GetFullPath();
  864. fout << this->ConvertToXMLOutputPath(m.c_str()) << ";";
  865. }
  866. fout << "\"";
  867. }
  868. // Check if we need the FAT32 workaround.
  869. // Check the filesystem type where the target will be written.
  870. if (cmLVS7G_IsFAT(target->GetDirectory(configName).c_str())) {
  871. // Add a flag telling the manifest tool to use a workaround
  872. // for FAT32 file systems, which can cause an empty manifest
  873. // to be embedded into the resulting executable. See CMake
  874. // bug #2617.
  875. fout << "\n\t\t\t\tUseFAT32Workaround=\"true\"";
  876. }
  877. fout << "/>\n";
  878. }
  879. this->OutputTargetRules(fout, configName, target, libName);
  880. this->OutputBuildTool(fout, configName, target, targetOptions);
  881. this->OutputDeploymentDebuggerTool(fout, configName, target);
  882. fout << "\t\t</Configuration>\n";
  883. }
  884. std::string cmLocalVisualStudio7Generator::GetBuildTypeLinkerFlags(
  885. std::string rootLinkerFlags, const std::string& configName)
  886. {
  887. std::string configTypeUpper = cmSystemTools::UpperCase(configName);
  888. std::string extraLinkOptionsBuildTypeDef =
  889. rootLinkerFlags + "_" + configTypeUpper;
  890. std::string extraLinkOptionsBuildType =
  891. this->Makefile->GetRequiredDefinition(
  892. extraLinkOptionsBuildTypeDef.c_str());
  893. return extraLinkOptionsBuildType;
  894. }
  895. void cmLocalVisualStudio7Generator::OutputBuildTool(
  896. std::ostream& fout, const std::string& configName, cmGeneratorTarget* target,
  897. const Options& targetOptions)
  898. {
  899. cmGlobalVisualStudio7Generator* gg =
  900. static_cast<cmGlobalVisualStudio7Generator*>(this->GlobalGenerator);
  901. std::string temp;
  902. std::string extraLinkOptions;
  903. if (target->GetType() == cmStateEnums::EXECUTABLE) {
  904. extraLinkOptions =
  905. this->Makefile->GetRequiredDefinition("CMAKE_EXE_LINKER_FLAGS") +
  906. std::string(" ") +
  907. GetBuildTypeLinkerFlags("CMAKE_EXE_LINKER_FLAGS", configName);
  908. }
  909. if (target->GetType() == cmStateEnums::SHARED_LIBRARY) {
  910. extraLinkOptions =
  911. this->Makefile->GetRequiredDefinition("CMAKE_SHARED_LINKER_FLAGS") +
  912. std::string(" ") +
  913. GetBuildTypeLinkerFlags("CMAKE_SHARED_LINKER_FLAGS", configName);
  914. }
  915. if (target->GetType() == cmStateEnums::MODULE_LIBRARY) {
  916. extraLinkOptions =
  917. this->Makefile->GetRequiredDefinition("CMAKE_MODULE_LINKER_FLAGS") +
  918. std::string(" ") +
  919. GetBuildTypeLinkerFlags("CMAKE_MODULE_LINKER_FLAGS", configName);
  920. }
  921. const char* targetLinkFlags = target->GetProperty("LINK_FLAGS");
  922. if (targetLinkFlags) {
  923. extraLinkOptions += " ";
  924. extraLinkOptions += targetLinkFlags;
  925. }
  926. std::string configTypeUpper = cmSystemTools::UpperCase(configName);
  927. std::string linkFlagsConfig = "LINK_FLAGS_";
  928. linkFlagsConfig += configTypeUpper;
  929. targetLinkFlags = target->GetProperty(linkFlagsConfig.c_str());
  930. if (targetLinkFlags) {
  931. extraLinkOptions += " ";
  932. extraLinkOptions += targetLinkFlags;
  933. }
  934. Options linkOptions(this, Options::Linker);
  935. if (this->FortranProject) {
  936. linkOptions.AddTable(cmLocalVisualStudio7GeneratorFortranLinkFlagTable);
  937. }
  938. linkOptions.AddTable(cmLocalVisualStudio7GeneratorLinkFlagTable);
  939. linkOptions.Parse(extraLinkOptions.c_str());
  940. cmGeneratorTarget::ModuleDefinitionInfo const* mdi =
  941. target->GetModuleDefinitionInfo(configName);
  942. if (mdi && !mdi->DefFile.empty()) {
  943. std::string defFile =
  944. this->ConvertToOutputFormat(mdi->DefFile, cmOutputConverter::SHELL);
  945. linkOptions.AddFlag("ModuleDefinitionFile", defFile.c_str());
  946. }
  947. switch (target->GetType()) {
  948. case cmStateEnums::UNKNOWN_LIBRARY:
  949. break;
  950. case cmStateEnums::OBJECT_LIBRARY: {
  951. std::string libpath = this->GetTargetDirectory(target);
  952. libpath += "/";
  953. libpath += configName;
  954. libpath += "/";
  955. libpath += target->GetName();
  956. libpath += ".lib";
  957. const char* tool =
  958. this->FortranProject ? "VFLibrarianTool" : "VCLibrarianTool";
  959. fout << "\t\t\t<Tool\n"
  960. << "\t\t\t\tName=\"" << tool << "\"\n";
  961. fout << "\t\t\t\tOutputFile=\""
  962. << this->ConvertToXMLOutputPathSingle(libpath.c_str()) << "\"/>\n";
  963. break;
  964. }
  965. case cmStateEnums::STATIC_LIBRARY: {
  966. std::string targetNameFull = target->GetFullName(configName);
  967. std::string libpath = target->GetDirectory(configName);
  968. libpath += "/";
  969. libpath += targetNameFull;
  970. const char* tool = "VCLibrarianTool";
  971. if (this->FortranProject) {
  972. tool = "VFLibrarianTool";
  973. }
  974. fout << "\t\t\t<Tool\n"
  975. << "\t\t\t\tName=\"" << tool << "\"\n";
  976. if (this->FortranProject) {
  977. std::ostringstream libdeps;
  978. this->Internal->OutputObjects(libdeps, target, configName);
  979. if (!libdeps.str().empty()) {
  980. fout << "\t\t\t\tAdditionalDependencies=\"" << libdeps.str()
  981. << "\"\n";
  982. }
  983. }
  984. std::string libflags;
  985. this->GetStaticLibraryFlags(libflags, configTypeUpper, target);
  986. if (!libflags.empty()) {
  987. fout << "\t\t\t\tAdditionalOptions=\"" << libflags << "\"\n";
  988. }
  989. fout << "\t\t\t\tOutputFile=\""
  990. << this->ConvertToXMLOutputPathSingle(libpath.c_str()) << "\"/>\n";
  991. break;
  992. }
  993. case cmStateEnums::SHARED_LIBRARY:
  994. case cmStateEnums::MODULE_LIBRARY: {
  995. std::string targetName;
  996. std::string targetNameSO;
  997. std::string targetNameFull;
  998. std::string targetNameImport;
  999. std::string targetNamePDB;
  1000. target->GetLibraryNames(targetName, targetNameSO, targetNameFull,
  1001. targetNameImport, targetNamePDB, configName);
  1002. // Compute the link library and directory information.
  1003. cmComputeLinkInformation* pcli = target->GetLinkInformation(configName);
  1004. if (!pcli) {
  1005. return;
  1006. }
  1007. cmComputeLinkInformation& cli = *pcli;
  1008. std::string linkLanguage = cli.GetLinkLanguage();
  1009. // Compute the variable name to lookup standard libraries for this
  1010. // language.
  1011. std::string standardLibsVar = "CMAKE_";
  1012. standardLibsVar += linkLanguage;
  1013. standardLibsVar += "_STANDARD_LIBRARIES";
  1014. const char* tool = "VCLinkerTool";
  1015. if (this->FortranProject) {
  1016. tool = "VFLinkerTool";
  1017. }
  1018. fout << "\t\t\t<Tool\n"
  1019. << "\t\t\t\tName=\"" << tool << "\"\n";
  1020. if (!gg->NeedLinkLibraryDependencies(target)) {
  1021. fout << "\t\t\t\tLinkLibraryDependencies=\"false\"\n";
  1022. }
  1023. // Use the NOINHERIT macro to avoid getting VS project default
  1024. // libraries which may be set by the user to something bad.
  1025. fout << "\t\t\t\tAdditionalDependencies=\"$(NOINHERIT) "
  1026. << this->Makefile->GetSafeDefinition(standardLibsVar.c_str());
  1027. if (this->FortranProject) {
  1028. this->Internal->OutputObjects(fout, target, configName, " ");
  1029. }
  1030. fout << " ";
  1031. this->Internal->OutputLibraries(fout, cli.GetItems());
  1032. fout << "\"\n";
  1033. temp = target->GetDirectory(configName);
  1034. temp += "/";
  1035. temp += targetNameFull;
  1036. fout << "\t\t\t\tOutputFile=\""
  1037. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  1038. this->WriteTargetVersionAttribute(fout, target);
  1039. linkOptions.OutputFlagMap(fout, "\t\t\t\t");
  1040. fout << "\t\t\t\tAdditionalLibraryDirectories=\"";
  1041. this->OutputLibraryDirectories(fout, cli.GetDirectories());
  1042. fout << "\"\n";
  1043. temp = target->GetPDBDirectory(configName);
  1044. temp += "/";
  1045. temp += targetNamePDB;
  1046. fout << "\t\t\t\tProgramDatabaseFile=\""
  1047. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  1048. if (targetOptions.IsDebug()) {
  1049. fout << "\t\t\t\tGenerateDebugInformation=\"true\"\n";
  1050. }
  1051. if (this->WindowsCEProject) {
  1052. if (this->GetVersion() < cmGlobalVisualStudioGenerator::VS9) {
  1053. fout << "\t\t\t\tSubSystem=\"9\"\n";
  1054. } else {
  1055. fout << "\t\t\t\tSubSystem=\"8\"\n";
  1056. }
  1057. }
  1058. std::string stackVar = "CMAKE_";
  1059. stackVar += linkLanguage;
  1060. stackVar += "_STACK_SIZE";
  1061. const char* stackVal = this->Makefile->GetDefinition(stackVar.c_str());
  1062. if (stackVal) {
  1063. fout << "\t\t\t\tStackReserveSize=\"" << stackVal << "\"\n";
  1064. }
  1065. temp =
  1066. target->GetDirectory(configName, cmStateEnums::ImportLibraryArtifact);
  1067. temp += "/";
  1068. temp += targetNameImport;
  1069. fout << "\t\t\t\tImportLibrary=\""
  1070. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"";
  1071. if (this->FortranProject) {
  1072. fout << "\n\t\t\t\tLinkDLL=\"true\"";
  1073. }
  1074. fout << "/>\n";
  1075. } break;
  1076. case cmStateEnums::EXECUTABLE: {
  1077. std::string targetName;
  1078. std::string targetNameFull;
  1079. std::string targetNameImport;
  1080. std::string targetNamePDB;
  1081. target->GetExecutableNames(targetName, targetNameFull, targetNameImport,
  1082. targetNamePDB, configName);
  1083. // Compute the link library and directory information.
  1084. cmComputeLinkInformation* pcli = target->GetLinkInformation(configName);
  1085. if (!pcli) {
  1086. return;
  1087. }
  1088. cmComputeLinkInformation& cli = *pcli;
  1089. std::string linkLanguage = cli.GetLinkLanguage();
  1090. bool isWin32Executable = target->GetPropertyAsBool("WIN32_EXECUTABLE");
  1091. // Compute the variable name to lookup standard libraries for this
  1092. // language.
  1093. std::string standardLibsVar = "CMAKE_";
  1094. standardLibsVar += linkLanguage;
  1095. standardLibsVar += "_STANDARD_LIBRARIES";
  1096. const char* tool = "VCLinkerTool";
  1097. if (this->FortranProject) {
  1098. tool = "VFLinkerTool";
  1099. }
  1100. fout << "\t\t\t<Tool\n"
  1101. << "\t\t\t\tName=\"" << tool << "\"\n";
  1102. if (!gg->NeedLinkLibraryDependencies(target)) {
  1103. fout << "\t\t\t\tLinkLibraryDependencies=\"false\"\n";
  1104. }
  1105. // Use the NOINHERIT macro to avoid getting VS project default
  1106. // libraries which may be set by the user to something bad.
  1107. fout << "\t\t\t\tAdditionalDependencies=\"$(NOINHERIT) "
  1108. << this->Makefile->GetSafeDefinition(standardLibsVar.c_str());
  1109. if (this->FortranProject) {
  1110. this->Internal->OutputObjects(fout, target, configName, " ");
  1111. }
  1112. fout << " ";
  1113. this->Internal->OutputLibraries(fout, cli.GetItems());
  1114. fout << "\"\n";
  1115. temp = target->GetDirectory(configName);
  1116. temp += "/";
  1117. temp += targetNameFull;
  1118. fout << "\t\t\t\tOutputFile=\""
  1119. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  1120. this->WriteTargetVersionAttribute(fout, target);
  1121. linkOptions.OutputFlagMap(fout, "\t\t\t\t");
  1122. fout << "\t\t\t\tAdditionalLibraryDirectories=\"";
  1123. this->OutputLibraryDirectories(fout, cli.GetDirectories());
  1124. fout << "\"\n";
  1125. std::string path = this->ConvertToXMLOutputPathSingle(
  1126. target->GetPDBDirectory(configName).c_str());
  1127. fout << "\t\t\t\tProgramDatabaseFile=\"" << path << "/" << targetNamePDB
  1128. << "\"\n";
  1129. if (targetOptions.IsDebug()) {
  1130. fout << "\t\t\t\tGenerateDebugInformation=\"true\"\n";
  1131. }
  1132. if (this->WindowsCEProject) {
  1133. if (this->GetVersion() < cmGlobalVisualStudioGenerator::VS9) {
  1134. fout << "\t\t\t\tSubSystem=\"9\"\n";
  1135. } else {
  1136. fout << "\t\t\t\tSubSystem=\"8\"\n";
  1137. }
  1138. if (!linkOptions.GetFlag("EntryPointSymbol")) {
  1139. const char* entryPointSymbol = targetOptions.UsingUnicode()
  1140. ? (isWin32Executable ? "wWinMainCRTStartup" : "mainWCRTStartup")
  1141. : (isWin32Executable ? "WinMainCRTStartup" : "mainACRTStartup");
  1142. fout << "\t\t\t\tEntryPointSymbol=\"" << entryPointSymbol << "\"\n";
  1143. }
  1144. } else if (this->FortranProject) {
  1145. fout << "\t\t\t\tSubSystem=\""
  1146. << (isWin32Executable ? "subSystemWindows" : "subSystemConsole")
  1147. << "\"\n";
  1148. } else {
  1149. fout << "\t\t\t\tSubSystem=\"" << (isWin32Executable ? "2" : "1")
  1150. << "\"\n";
  1151. }
  1152. std::string stackVar = "CMAKE_";
  1153. stackVar += linkLanguage;
  1154. stackVar += "_STACK_SIZE";
  1155. const char* stackVal = this->Makefile->GetDefinition(stackVar.c_str());
  1156. if (stackVal) {
  1157. fout << "\t\t\t\tStackReserveSize=\"" << stackVal << "\"";
  1158. }
  1159. temp =
  1160. target->GetDirectory(configName, cmStateEnums::ImportLibraryArtifact);
  1161. temp += "/";
  1162. temp += targetNameImport;
  1163. fout << "\t\t\t\tImportLibrary=\""
  1164. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"/>\n";
  1165. break;
  1166. }
  1167. case cmStateEnums::UTILITY:
  1168. case cmStateEnums::GLOBAL_TARGET:
  1169. case cmStateEnums::INTERFACE_LIBRARY:
  1170. break;
  1171. }
  1172. }
  1173. void cmLocalVisualStudio7Generator::OutputDeploymentDebuggerTool(
  1174. std::ostream& fout, std::string const& config, cmGeneratorTarget* target)
  1175. {
  1176. if (this->WindowsCEProject) {
  1177. if (const char* dir = target->GetProperty("DEPLOYMENT_REMOTE_DIRECTORY")) {
  1178. /* clang-format off */
  1179. fout <<
  1180. "\t\t\t<DeploymentTool\n"
  1181. "\t\t\t\tForceDirty=\"-1\"\n"
  1182. "\t\t\t\tRemoteDirectory=\"" << this->EscapeForXML(dir) << "\"\n"
  1183. "\t\t\t\tRegisterOutput=\"0\"\n"
  1184. "\t\t\t\tAdditionalFiles=\"\"/>\n"
  1185. ;
  1186. /* clang-format on */
  1187. std::string const exe =
  1188. dir + std::string("\\") + target->GetFullName(config);
  1189. /* clang-format off */
  1190. fout <<
  1191. "\t\t\t<DebuggerTool\n"
  1192. "\t\t\t\tRemoteExecutable=\"" << this->EscapeForXML(exe) << "\"\n"
  1193. "\t\t\t\tArguments=\"\"\n"
  1194. "\t\t\t/>\n"
  1195. ;
  1196. /* clang-format on */
  1197. }
  1198. }
  1199. }
  1200. void cmLocalVisualStudio7Generator::WriteTargetVersionAttribute(
  1201. std::ostream& fout, cmGeneratorTarget* gt)
  1202. {
  1203. int major;
  1204. int minor;
  1205. gt->GetTargetVersion(major, minor);
  1206. fout << "\t\t\t\tVersion=\"" << major << "." << minor << "\"\n";
  1207. }
  1208. void cmLocalVisualStudio7GeneratorInternals::OutputLibraries(
  1209. std::ostream& fout, ItemVector const& libs)
  1210. {
  1211. cmLocalVisualStudio7Generator* lg = this->LocalGenerator;
  1212. std::string currentBinDir = lg->GetCurrentBinaryDirectory();
  1213. for (ItemVector::const_iterator l = libs.begin(); l != libs.end(); ++l) {
  1214. if (l->IsPath) {
  1215. std::string rel =
  1216. lg->ConvertToRelativePath(currentBinDir, l->Value.c_str());
  1217. fout << lg->ConvertToXMLOutputPath(rel.c_str()) << " ";
  1218. } else if (!l->Target ||
  1219. l->Target->GetType() != cmStateEnums::INTERFACE_LIBRARY) {
  1220. fout << l->Value << " ";
  1221. }
  1222. }
  1223. }
  1224. void cmLocalVisualStudio7GeneratorInternals::OutputObjects(
  1225. std::ostream& fout, cmGeneratorTarget* gt, std::string const& configName,
  1226. const char* isep)
  1227. {
  1228. // VS < 8 does not support per-config source locations so we
  1229. // list object library content on the link line instead.
  1230. cmLocalVisualStudio7Generator* lg = this->LocalGenerator;
  1231. std::string currentBinDir = lg->GetCurrentBinaryDirectory();
  1232. std::vector<cmSourceFile const*> objs;
  1233. gt->GetExternalObjects(objs, configName);
  1234. const char* sep = isep ? isep : "";
  1235. for (std::vector<cmSourceFile const*>::const_iterator i = objs.begin();
  1236. i != objs.end(); ++i) {
  1237. if (!(*i)->GetObjectLibrary().empty()) {
  1238. std::string const& objFile = (*i)->GetFullPath();
  1239. std::string rel = lg->ConvertToRelativePath(currentBinDir, objFile);
  1240. fout << sep << lg->ConvertToXMLOutputPath(rel.c_str());
  1241. sep = " ";
  1242. }
  1243. }
  1244. }
  1245. void cmLocalVisualStudio7Generator::OutputLibraryDirectories(
  1246. std::ostream& fout, std::vector<std::string> const& dirs)
  1247. {
  1248. const char* comma = "";
  1249. std::string currentBinDir = this->GetCurrentBinaryDirectory();
  1250. for (std::vector<std::string>::const_iterator d = dirs.begin();
  1251. d != dirs.end(); ++d) {
  1252. // Remove any trailing slash and skip empty paths.
  1253. std::string dir = *d;
  1254. if (dir[dir.size() - 1] == '/') {
  1255. dir = dir.substr(0, dir.size() - 1);
  1256. }
  1257. if (dir.empty()) {
  1258. continue;
  1259. }
  1260. // Switch to a relative path specification if it is shorter.
  1261. if (cmSystemTools::FileIsFullPath(dir.c_str())) {
  1262. std::string rel =
  1263. this->ConvertToRelativePath(currentBinDir, dir.c_str());
  1264. if (rel.size() < dir.size()) {
  1265. dir = rel;
  1266. }
  1267. }
  1268. // First search a configuration-specific subdirectory and then the
  1269. // original directory.
  1270. fout << comma
  1271. << this->ConvertToXMLOutputPath(
  1272. (dir + "/$(ConfigurationName)").c_str())
  1273. << "," << this->ConvertToXMLOutputPath(dir.c_str());
  1274. comma = ",";
  1275. }
  1276. }
  1277. void cmLocalVisualStudio7Generator::WriteVCProjFile(std::ostream& fout,
  1278. const std::string& libName,
  1279. cmGeneratorTarget* target)
  1280. {
  1281. std::vector<std::string> configs;
  1282. this->Makefile->GetConfigurations(configs);
  1283. // We may be modifying the source groups temporarily, so make a copy.
  1284. std::vector<cmSourceGroup> sourceGroups = this->Makefile->GetSourceGroups();
  1285. AllConfigSources sources;
  1286. sources.Sources = target->GetAllConfigSources();
  1287. // Add CMakeLists.txt file with rule to re-run CMake for user convenience.
  1288. if (target->GetType() != cmStateEnums::GLOBAL_TARGET &&
  1289. target->GetName() != CMAKE_CHECK_BUILD_SYSTEM_TARGET) {
  1290. if (cmSourceFile const* sf = this->CreateVCProjBuildRule()) {
  1291. cmGeneratorTarget::AllConfigSource acs;
  1292. acs.Source = sf;
  1293. acs.Kind = cmGeneratorTarget::SourceKindCustomCommand;
  1294. for (size_t ci = 0; ci < configs.size(); ++ci) {
  1295. acs.Configs.push_back(ci);
  1296. }
  1297. sources.Sources.emplace_back(std::move(acs));
  1298. }
  1299. }
  1300. for (size_t si = 0; si < sources.Sources.size(); ++si) {
  1301. cmSourceFile const* sf = sources.Sources[si].Source;
  1302. sources.Index[sf] = si;
  1303. if (!sf->GetObjectLibrary().empty()) {
  1304. if (this->FortranProject) {
  1305. // Intel Fortran does not support per-config source locations
  1306. // so we list object library content on the link line instead.
  1307. // See OutputObjects.
  1308. continue;
  1309. }
  1310. }
  1311. // Add the file to the list of sources.
  1312. std::string const source = sf->GetFullPath();
  1313. cmSourceGroup* sourceGroup =
  1314. this->Makefile->FindSourceGroup(source.c_str(), sourceGroups);
  1315. sourceGroup->AssignSource(sf);
  1316. }
  1317. // open the project
  1318. this->WriteProjectStart(fout, libName, target, sourceGroups);
  1319. // write the configuration information
  1320. this->WriteConfigurations(fout, configs, libName, target);
  1321. fout << "\t<Files>\n";
  1322. // Loop through every source group.
  1323. for (unsigned int i = 0; i < sourceGroups.size(); ++i) {
  1324. cmSourceGroup sg = sourceGroups[i];
  1325. this->WriteGroup(&sg, target, fout, libName, configs, sources);
  1326. }
  1327. fout << "\t</Files>\n";
  1328. // Write the VCProj file's footer.
  1329. this->WriteVCProjFooter(fout, target);
  1330. }
  1331. struct cmLVS7GFileConfig
  1332. {
  1333. std::string ObjectName;
  1334. std::string CompileFlags;
  1335. std::string CompileDefs;
  1336. std::string CompileDefsConfig;
  1337. std::string AdditionalDeps;
  1338. bool ExcludedFromBuild;
  1339. };
  1340. class cmLocalVisualStudio7GeneratorFCInfo
  1341. {
  1342. public:
  1343. cmLocalVisualStudio7GeneratorFCInfo(
  1344. cmLocalVisualStudio7Generator* lg, cmGeneratorTarget* target,
  1345. cmGeneratorTarget::AllConfigSource const& acs,
  1346. std::vector<std::string> const& configs);
  1347. std::map<std::string, cmLVS7GFileConfig> FileConfigMap;
  1348. };
  1349. cmLocalVisualStudio7GeneratorFCInfo::cmLocalVisualStudio7GeneratorFCInfo(
  1350. cmLocalVisualStudio7Generator* lg, cmGeneratorTarget* gt,
  1351. cmGeneratorTarget::AllConfigSource const& acs,
  1352. std::vector<std::string> const& configs)
  1353. {
  1354. cmSourceFile const& sf = *acs.Source;
  1355. std::string objectName;
  1356. if (gt->HasExplicitObjectName(&sf)) {
  1357. objectName = gt->GetObjectName(&sf);
  1358. }
  1359. // Compute per-source, per-config information.
  1360. size_t ci = 0;
  1361. for (std::vector<std::string>::const_iterator i = configs.begin();
  1362. i != configs.end(); ++i, ++ci) {
  1363. std::string configUpper = cmSystemTools::UpperCase(*i);
  1364. cmLVS7GFileConfig fc;
  1365. cmGeneratorExpressionInterpreter genexInterpreter(lg, gt, *i);
  1366. bool needfc = false;
  1367. if (!objectName.empty()) {
  1368. fc.ObjectName = objectName;
  1369. needfc = true;
  1370. }
  1371. if (const char* cflags = sf.GetProperty("COMPILE_FLAGS")) {
  1372. fc.CompileFlags = genexInterpreter.Evaluate(cflags);
  1373. needfc = true;
  1374. }
  1375. if (lg->FortranProject) {
  1376. switch (cmOutputConverter::GetFortranFormat(
  1377. sf.GetProperty("Fortran_FORMAT"))) {
  1378. case cmOutputConverter::FortranFormatFixed:
  1379. fc.CompileFlags = "-fixed " + fc.CompileFlags;
  1380. needfc = true;
  1381. break;
  1382. case cmOutputConverter::FortranFormatFree:
  1383. fc.CompileFlags = "-free " + fc.CompileFlags;
  1384. needfc = true;
  1385. break;
  1386. default:
  1387. break;
  1388. }
  1389. }
  1390. if (const char* cdefs = sf.GetProperty("COMPILE_DEFINITIONS")) {
  1391. fc.CompileDefs = cdefs;
  1392. needfc = true;
  1393. }
  1394. std::string defPropName = "COMPILE_DEFINITIONS_";
  1395. defPropName += configUpper;
  1396. if (const char* ccdefs = sf.GetProperty(defPropName.c_str())) {
  1397. fc.CompileDefsConfig = ccdefs;
  1398. needfc = true;
  1399. }
  1400. // Check for extra object-file dependencies.
  1401. if (const char* deps = sf.GetProperty("OBJECT_DEPENDS")) {
  1402. std::vector<std::string> depends;
  1403. cmSystemTools::ExpandListArgument(deps, depends);
  1404. const char* sep = "";
  1405. for (std::vector<std::string>::iterator j = depends.begin();
  1406. j != depends.end(); ++j) {
  1407. fc.AdditionalDeps += sep;
  1408. fc.AdditionalDeps += lg->ConvertToXMLOutputPath(j->c_str());
  1409. sep = ";";
  1410. needfc = true;
  1411. }
  1412. }
  1413. std::string lang =
  1414. lg->GlobalGenerator->GetLanguageFromExtension(sf.GetExtension().c_str());
  1415. const std::string& sourceLang = lg->GetSourceFileLanguage(sf);
  1416. const std::string& linkLanguage = gt->GetLinkerLanguage(i->c_str());
  1417. bool needForceLang = false;
  1418. // source file does not match its extension language
  1419. if (lang != sourceLang) {
  1420. needForceLang = true;
  1421. lang = sourceLang;
  1422. }
  1423. // If HEADER_FILE_ONLY is set, we must suppress this generation in
  1424. // the project file
  1425. fc.ExcludedFromBuild = sf.GetPropertyAsBool("HEADER_FILE_ONLY") ||
  1426. std::find(acs.Configs.begin(), acs.Configs.end(), ci) ==
  1427. acs.Configs.end();
  1428. if (fc.ExcludedFromBuild) {
  1429. needfc = true;
  1430. }
  1431. // if the source file does not match the linker language
  1432. // then force c or c++
  1433. if (needForceLang || (linkLanguage != lang)) {
  1434. if (lang == "CXX") {
  1435. // force a C++ file type
  1436. fc.CompileFlags += " /TP ";
  1437. needfc = true;
  1438. } else if (lang == "C") {
  1439. // force to c
  1440. fc.CompileFlags += " /TC ";
  1441. needfc = true;
  1442. }
  1443. }
  1444. if (needfc) {
  1445. this->FileConfigMap[*i] = fc;
  1446. }
  1447. }
  1448. }
  1449. std::string cmLocalVisualStudio7Generator::ComputeLongestObjectDirectory(
  1450. cmGeneratorTarget const* target) const
  1451. {
  1452. std::vector<std::string> configs;
  1453. target->Target->GetMakefile()->GetConfigurations(configs);
  1454. // Compute the maximum length configuration name.
  1455. std::string config_max;
  1456. for (std::vector<std::string>::iterator i = configs.begin();
  1457. i != configs.end(); ++i) {
  1458. if (i->size() > config_max.size()) {
  1459. config_max = *i;
  1460. }
  1461. }
  1462. // Compute the maximum length full path to the intermediate
  1463. // files directory for any configuration. This is used to construct
  1464. // object file names that do not produce paths that are too long.
  1465. std::string dir_max;
  1466. dir_max += this->GetCurrentBinaryDirectory();
  1467. dir_max += "/";
  1468. dir_max += this->GetTargetDirectory(target);
  1469. dir_max += "/";
  1470. dir_max += config_max;
  1471. dir_max += "/";
  1472. return dir_max;
  1473. }
  1474. bool cmLocalVisualStudio7Generator::WriteGroup(
  1475. const cmSourceGroup* sg, cmGeneratorTarget* target, std::ostream& fout,
  1476. const std::string& libName, std::vector<std::string> const& configs,
  1477. AllConfigSources const& sources)
  1478. {
  1479. cmGlobalVisualStudio7Generator* gg =
  1480. static_cast<cmGlobalVisualStudio7Generator*>(this->GlobalGenerator);
  1481. const std::vector<const cmSourceFile*>& sourceFiles = sg->GetSourceFiles();
  1482. std::vector<cmSourceGroup> const& children = sg->GetGroupChildren();
  1483. // Write the children to temporary output.
  1484. bool hasChildrenWithSources = false;
  1485. std::ostringstream tmpOut;
  1486. for (unsigned int i = 0; i < children.size(); ++i) {
  1487. if (this->WriteGroup(&children[i], target, tmpOut, libName, configs,
  1488. sources)) {
  1489. hasChildrenWithSources = true;
  1490. }
  1491. }
  1492. // If the group is empty, don't write it at all.
  1493. if (sourceFiles.empty() && !hasChildrenWithSources) {
  1494. return false;
  1495. }
  1496. // If the group has a name, write the header.
  1497. std::string const& name = sg->GetName();
  1498. if (!name.empty()) {
  1499. this->WriteVCProjBeginGroup(fout, name.c_str(), "");
  1500. }
  1501. // Loop through each source in the source group.
  1502. for (std::vector<const cmSourceFile*>::const_iterator sf =
  1503. sourceFiles.begin();
  1504. sf != sourceFiles.end(); ++sf) {
  1505. std::string source = (*sf)->GetFullPath();
  1506. if (source != libName || target->GetType() == cmStateEnums::UTILITY ||
  1507. target->GetType() == cmStateEnums::GLOBAL_TARGET) {
  1508. // Look up the source kind and configs.
  1509. std::map<cmSourceFile const*, size_t>::const_iterator map_it =
  1510. sources.Index.find(*sf);
  1511. // The map entry must exist because we populated it earlier.
  1512. assert(map_it != sources.Index.end());
  1513. cmGeneratorTarget::AllConfigSource const& acs =
  1514. sources.Sources[map_it->second];
  1515. FCInfo fcinfo(this, target, acs, configs);
  1516. fout << "\t\t\t<File\n";
  1517. std::string d = this->ConvertToXMLOutputPathSingle(source.c_str());
  1518. // Tell MS-Dev what the source is. If the compiler knows how to
  1519. // build it, then it will.
  1520. fout << "\t\t\t\tRelativePath=\"" << d << "\">\n";
  1521. if (cmCustomCommand const* command = (*sf)->GetCustomCommand()) {
  1522. this->WriteCustomRule(fout, configs, source.c_str(), *command, fcinfo);
  1523. } else if (!fcinfo.FileConfigMap.empty()) {
  1524. const char* aCompilerTool = "VCCLCompilerTool";
  1525. const char* ppLang = "CXX";
  1526. if (this->FortranProject) {
  1527. aCompilerTool = "VFFortranCompilerTool";
  1528. }
  1529. std::string const& lang = (*sf)->GetLanguage();
  1530. std::string ext = (*sf)->GetExtension();
  1531. ext = cmSystemTools::LowerCase(ext);
  1532. if (ext == "idl") {
  1533. aCompilerTool = "VCMIDLTool";
  1534. if (this->FortranProject) {
  1535. aCompilerTool = "VFMIDLTool";
  1536. }
  1537. }
  1538. if (ext == "rc") {
  1539. aCompilerTool = "VCResourceCompilerTool";
  1540. ppLang = "RC";
  1541. if (this->FortranProject) {
  1542. aCompilerTool = "VFResourceCompilerTool";
  1543. }
  1544. }
  1545. if (ext == "def") {
  1546. aCompilerTool = "VCCustomBuildTool";
  1547. if (this->FortranProject) {
  1548. aCompilerTool = "VFCustomBuildTool";
  1549. }
  1550. }
  1551. if (gg->IsMasmEnabled() && !this->FortranProject &&
  1552. lang == "ASM_MASM") {
  1553. aCompilerTool = "MASM";
  1554. }
  1555. if (acs.Kind == cmGeneratorTarget::SourceKindExternalObject) {
  1556. aCompilerTool = "VCCustomBuildTool";
  1557. }
  1558. for (std::map<std::string, cmLVS7GFileConfig>::const_iterator fci =
  1559. fcinfo.FileConfigMap.begin();
  1560. fci != fcinfo.FileConfigMap.end(); ++fci) {
  1561. cmLVS7GFileConfig const& fc = fci->second;
  1562. fout << "\t\t\t\t<FileConfiguration\n"
  1563. << "\t\t\t\t\tName=\"" << fci->first << "|"
  1564. << gg->GetPlatformName() << "\"";
  1565. if (fc.ExcludedFromBuild) {
  1566. fout << " ExcludedFromBuild=\"true\"";
  1567. }
  1568. fout << ">\n";
  1569. fout << "\t\t\t\t\t<Tool\n"
  1570. << "\t\t\t\t\tName=\"" << aCompilerTool << "\"\n";
  1571. if (!fc.CompileFlags.empty() || !fc.CompileDefs.empty() ||
  1572. !fc.CompileDefsConfig.empty()) {
  1573. Options::Tool tool = Options::Compiler;
  1574. cmVS7FlagTable const* table =
  1575. cmLocalVisualStudio7GeneratorFlagTable;
  1576. if (this->FortranProject) {
  1577. tool = Options::FortranCompiler;
  1578. table = cmLocalVisualStudio7GeneratorFortranFlagTable;
  1579. }
  1580. Options fileOptions(this, tool, table, gg->ExtraFlagTable);
  1581. fileOptions.Parse(fc.CompileFlags.c_str());
  1582. fileOptions.AddDefines(fc.CompileDefs.c_str());
  1583. fileOptions.AddDefines(fc.CompileDefsConfig.c_str());
  1584. fileOptions.OutputFlagMap(fout, "\t\t\t\t\t");
  1585. fileOptions.OutputPreprocessorDefinitions(fout, "\t\t\t\t\t", "\n",
  1586. ppLang);
  1587. }
  1588. if (!fc.AdditionalDeps.empty()) {
  1589. fout << "\t\t\t\t\tAdditionalDependencies=\"" << fc.AdditionalDeps
  1590. << "\"\n";
  1591. }
  1592. if (!fc.ObjectName.empty()) {
  1593. fout << "\t\t\t\t\tObjectFile=\"$(IntDir)/" << fc.ObjectName
  1594. << "\"\n";
  1595. }
  1596. fout << "\t\t\t\t\t/>\n"
  1597. << "\t\t\t\t</FileConfiguration>\n";
  1598. }
  1599. }
  1600. fout << "\t\t\t</File>\n";
  1601. }
  1602. }
  1603. // If the group has children with source files, write the children.
  1604. if (hasChildrenWithSources) {
  1605. fout << tmpOut.str();
  1606. }
  1607. // If the group has a name, write the footer.
  1608. if (!name.empty()) {
  1609. this->WriteVCProjEndGroup(fout);
  1610. }
  1611. return true;
  1612. }
  1613. void cmLocalVisualStudio7Generator::WriteCustomRule(
  1614. std::ostream& fout, std::vector<std::string> const& configs,
  1615. const char* source, const cmCustomCommand& command, FCInfo& fcinfo)
  1616. {
  1617. cmGlobalVisualStudio7Generator* gg =
  1618. static_cast<cmGlobalVisualStudio7Generator*>(this->GlobalGenerator);
  1619. // Write the rule for each configuration.
  1620. const char* compileTool = "VCCLCompilerTool";
  1621. if (this->FortranProject) {
  1622. compileTool = "VFCLCompilerTool";
  1623. }
  1624. const char* customTool = "VCCustomBuildTool";
  1625. if (this->FortranProject) {
  1626. customTool = "VFCustomBuildTool";
  1627. }
  1628. for (std::vector<std::string>::const_iterator i = configs.begin();
  1629. i != configs.end(); ++i) {
  1630. cmCustomCommandGenerator ccg(command, *i, this);
  1631. cmLVS7GFileConfig const& fc = fcinfo.FileConfigMap[*i];
  1632. fout << "\t\t\t\t<FileConfiguration\n";
  1633. fout << "\t\t\t\t\tName=\"" << *i << "|" << gg->GetPlatformName()
  1634. << "\">\n";
  1635. if (!fc.CompileFlags.empty()) {
  1636. fout << "\t\t\t\t\t<Tool\n"
  1637. << "\t\t\t\t\tName=\"" << compileTool << "\"\n"
  1638. << "\t\t\t\t\tAdditionalOptions=\""
  1639. << this->EscapeForXML(fc.CompileFlags.c_str()) << "\"/>\n";
  1640. }
  1641. std::string comment = this->ConstructComment(ccg);
  1642. std::string script = this->ConstructScript(ccg);
  1643. if (this->FortranProject) {
  1644. cmSystemTools::ReplaceString(script, "$(Configuration)", i->c_str());
  1645. }
  1646. /* clang-format off */
  1647. fout << "\t\t\t\t\t<Tool\n"
  1648. << "\t\t\t\t\tName=\"" << customTool << "\"\n"
  1649. << "\t\t\t\t\tDescription=\""
  1650. << this->EscapeForXML(comment.c_str()) << "\"\n"
  1651. << "\t\t\t\t\tCommandLine=\""
  1652. << this->EscapeForXML(script.c_str()) << "\"\n"
  1653. << "\t\t\t\t\tAdditionalDependencies=\"";
  1654. /* clang-format on */
  1655. if (ccg.GetDepends().empty()) {
  1656. // There are no real dependencies. Produce an artificial one to
  1657. // make sure the rule runs reliably.
  1658. if (!cmSystemTools::FileExists(source)) {
  1659. cmsys::ofstream depout(source);
  1660. depout << "Artificial dependency for a custom command.\n";
  1661. }
  1662. fout << this->ConvertToXMLOutputPath(source);
  1663. } else {
  1664. // Write out the dependencies for the rule.
  1665. for (std::vector<std::string>::const_iterator d =
  1666. ccg.GetDepends().begin();
  1667. d != ccg.GetDepends().end(); ++d) {
  1668. // Get the real name of the dependency in case it is a CMake target.
  1669. std::string dep;
  1670. if (this->GetRealDependency(d->c_str(), i->c_str(), dep)) {
  1671. fout << this->ConvertToXMLOutputPath(dep.c_str()) << ";";
  1672. }
  1673. }
  1674. }
  1675. fout << "\"\n";
  1676. fout << "\t\t\t\t\tOutputs=\"";
  1677. if (ccg.GetOutputs().empty()) {
  1678. fout << source << "_force";
  1679. } else {
  1680. // Write a rule for the output generated by this command.
  1681. const char* sep = "";
  1682. for (std::vector<std::string>::const_iterator o =
  1683. ccg.GetOutputs().begin();
  1684. o != ccg.GetOutputs().end(); ++o) {
  1685. fout << sep << this->ConvertToXMLOutputPathSingle(o->c_str());
  1686. sep = ";";
  1687. }
  1688. }
  1689. fout << "\"/>\n";
  1690. fout << "\t\t\t\t</FileConfiguration>\n";
  1691. }
  1692. }
  1693. void cmLocalVisualStudio7Generator::WriteVCProjBeginGroup(std::ostream& fout,
  1694. const char* group,
  1695. const char*)
  1696. {
  1697. /* clang-format off */
  1698. fout << "\t\t<Filter\n"
  1699. << "\t\t\tName=\"" << group << "\"\n"
  1700. << "\t\t\tFilter=\"\">\n";
  1701. /* clang-format on */
  1702. }
  1703. void cmLocalVisualStudio7Generator::WriteVCProjEndGroup(std::ostream& fout)
  1704. {
  1705. fout << "\t\t</Filter>\n";
  1706. }
  1707. // look for custom rules on a target and collect them together
  1708. void cmLocalVisualStudio7Generator::OutputTargetRules(
  1709. std::ostream& fout, const std::string& configName, cmGeneratorTarget* target,
  1710. const std::string& /*libName*/)
  1711. {
  1712. if (target->GetType() > cmStateEnums::GLOBAL_TARGET) {
  1713. return;
  1714. }
  1715. EventWriter event(this, configName, fout);
  1716. // Add pre-build event.
  1717. const char* tool =
  1718. this->FortranProject ? "VFPreBuildEventTool" : "VCPreBuildEventTool";
  1719. event.Start(tool);
  1720. event.Write(target->GetPreBuildCommands());
  1721. event.Finish();
  1722. // Add pre-link event.
  1723. tool = this->FortranProject ? "VFPreLinkEventTool" : "VCPreLinkEventTool";
  1724. event.Start(tool);
  1725. bool addedPrelink = false;
  1726. cmGeneratorTarget::ModuleDefinitionInfo const* mdi =
  1727. target->GetModuleDefinitionInfo(configName);
  1728. if (mdi && mdi->DefFileGenerated) {
  1729. addedPrelink = true;
  1730. std::vector<cmCustomCommand> commands = target->GetPreLinkCommands();
  1731. cmGlobalVisualStudioGenerator* gg =
  1732. static_cast<cmGlobalVisualStudioGenerator*>(this->GlobalGenerator);
  1733. gg->AddSymbolExportCommand(target, commands, configName);
  1734. event.Write(commands);
  1735. }
  1736. if (!addedPrelink) {
  1737. event.Write(target->GetPreLinkCommands());
  1738. }
  1739. std::unique_ptr<cmCustomCommand> pcc(
  1740. this->MaybeCreateImplibDir(target, configName, this->FortranProject));
  1741. if (pcc.get()) {
  1742. event.Write(*pcc);
  1743. }
  1744. event.Finish();
  1745. // Add post-build event.
  1746. tool =
  1747. this->FortranProject ? "VFPostBuildEventTool" : "VCPostBuildEventTool";
  1748. event.Start(tool);
  1749. event.Write(target->GetPostBuildCommands());
  1750. event.Finish();
  1751. }
  1752. void cmLocalVisualStudio7Generator::WriteProjectSCC(std::ostream& fout,
  1753. cmGeneratorTarget* target)
  1754. {
  1755. // if we have all the required Source code control tags
  1756. // then add that to the project
  1757. const char* vsProjectname = target->GetProperty("VS_SCC_PROJECTNAME");
  1758. const char* vsLocalpath = target->GetProperty("VS_SCC_LOCALPATH");
  1759. const char* vsProvider = target->GetProperty("VS_SCC_PROVIDER");
  1760. if (vsProvider && vsLocalpath && vsProjectname) {
  1761. /* clang-format off */
  1762. fout << "\tSccProjectName=\"" << vsProjectname << "\"\n"
  1763. << "\tSccLocalPath=\"" << vsLocalpath << "\"\n"
  1764. << "\tSccProvider=\"" << vsProvider << "\"\n";
  1765. /* clang-format on */
  1766. const char* vsAuxPath = target->GetProperty("VS_SCC_AUXPATH");
  1767. if (vsAuxPath) {
  1768. fout << "\tSccAuxPath=\"" << vsAuxPath << "\"\n";
  1769. }
  1770. }
  1771. }
  1772. void cmLocalVisualStudio7Generator::WriteProjectStartFortran(
  1773. std::ostream& fout, const std::string& libName, cmGeneratorTarget* target)
  1774. {
  1775. cmGlobalVisualStudio7Generator* gg =
  1776. static_cast<cmGlobalVisualStudio7Generator*>(this->GlobalGenerator);
  1777. /* clang-format off */
  1778. fout << "<?xml version=\"1.0\" encoding = \""
  1779. << gg->Encoding() << "\"?>\n"
  1780. << "<VisualStudioProject\n"
  1781. << "\tProjectCreator=\"Intel Fortran\"\n"
  1782. << "\tVersion=\"" << gg->GetIntelProjectVersion() << "\"\n";
  1783. /* clang-format on */
  1784. const char* keyword = target->GetProperty("VS_KEYWORD");
  1785. if (!keyword) {
  1786. keyword = "Console Application";
  1787. }
  1788. const char* projectType = 0;
  1789. switch (target->GetType()) {
  1790. case cmStateEnums::STATIC_LIBRARY:
  1791. projectType = "typeStaticLibrary";
  1792. if (keyword) {
  1793. keyword = "Static Library";
  1794. }
  1795. break;
  1796. case cmStateEnums::SHARED_LIBRARY:
  1797. case cmStateEnums::MODULE_LIBRARY:
  1798. projectType = "typeDynamicLibrary";
  1799. if (!keyword) {
  1800. keyword = "Dll";
  1801. }
  1802. break;
  1803. case cmStateEnums::EXECUTABLE:
  1804. if (!keyword) {
  1805. keyword = "Console Application";
  1806. }
  1807. projectType = 0;
  1808. break;
  1809. case cmStateEnums::UTILITY:
  1810. case cmStateEnums::GLOBAL_TARGET:
  1811. default:
  1812. break;
  1813. }
  1814. if (projectType) {
  1815. fout << "\tProjectType=\"" << projectType << "\"\n";
  1816. }
  1817. this->WriteProjectSCC(fout, target);
  1818. /* clang-format off */
  1819. fout<< "\tKeyword=\"" << keyword << "\">\n"
  1820. << "\tProjectGUID=\"{" << gg->GetGUID(libName.c_str()) << "}\">\n"
  1821. << "\t<Platforms>\n"
  1822. << "\t\t<Platform\n\t\t\tName=\"" << gg->GetPlatformName() << "\"/>\n"
  1823. << "\t</Platforms>\n";
  1824. /* clang-format on */
  1825. }
  1826. void cmLocalVisualStudio7Generator::WriteProjectStart(
  1827. std::ostream& fout, const std::string& libName, cmGeneratorTarget* target,
  1828. std::vector<cmSourceGroup>&)
  1829. {
  1830. if (this->FortranProject) {
  1831. this->WriteProjectStartFortran(fout, libName, target);
  1832. return;
  1833. }
  1834. cmGlobalVisualStudio7Generator* gg =
  1835. static_cast<cmGlobalVisualStudio7Generator*>(this->GlobalGenerator);
  1836. /* clang-format off */
  1837. fout << "<?xml version=\"1.0\" encoding = \""
  1838. << gg->Encoding() << "\"?>\n"
  1839. << "<VisualStudioProject\n"
  1840. << "\tProjectType=\"Visual C++\"\n";
  1841. /* clang-format on */
  1842. fout << "\tVersion=\"" << (gg->GetVersion() / 10) << ".00\"\n";
  1843. const char* projLabel = target->GetProperty("PROJECT_LABEL");
  1844. if (!projLabel) {
  1845. projLabel = libName.c_str();
  1846. }
  1847. const char* keyword = target->GetProperty("VS_KEYWORD");
  1848. if (!keyword) {
  1849. keyword = "Win32Proj";
  1850. }
  1851. fout << "\tName=\"" << projLabel << "\"\n";
  1852. fout << "\tProjectGUID=\"{" << gg->GetGUID(libName.c_str()) << "}\"\n";
  1853. this->WriteProjectSCC(fout, target);
  1854. if (const char* targetFrameworkVersion =
  1855. target->GetProperty("VS_DOTNET_TARGET_FRAMEWORK_VERSION")) {
  1856. fout << "\tTargetFrameworkVersion=\"" << targetFrameworkVersion << "\"\n";
  1857. }
  1858. /* clang-format off */
  1859. fout << "\tKeyword=\"" << keyword << "\">\n"
  1860. << "\t<Platforms>\n"
  1861. << "\t\t<Platform\n\t\t\tName=\"" << gg->GetPlatformName() << "\"/>\n"
  1862. << "\t</Platforms>\n";
  1863. /* clang-format on */
  1864. if (gg->IsMasmEnabled()) {
  1865. /* clang-format off */
  1866. fout <<
  1867. "\t<ToolFiles>\n"
  1868. "\t\t<DefaultToolFile\n"
  1869. "\t\t\tFileName=\"masm.rules\"\n"
  1870. "\t\t/>\n"
  1871. "\t</ToolFiles>\n"
  1872. ;
  1873. /* clang-format on */
  1874. }
  1875. }
  1876. void cmLocalVisualStudio7Generator::WriteVCProjFooter(
  1877. std::ostream& fout, cmGeneratorTarget* target)
  1878. {
  1879. fout << "\t<Globals>\n";
  1880. std::vector<std::string> const& props = target->GetPropertyKeys();
  1881. for (std::vector<std::string>::const_iterator i = props.begin();
  1882. i != props.end(); ++i) {
  1883. if (i->find("VS_GLOBAL_") == 0) {
  1884. std::string name = i->substr(10);
  1885. if (!name.empty()) {
  1886. /* clang-format off */
  1887. fout << "\t\t<Global\n"
  1888. << "\t\t\tName=\"" << name << "\"\n"
  1889. << "\t\t\tValue=\"" << target->GetProperty(*i) << "\"\n"
  1890. << "\t\t/>\n";
  1891. /* clang-format on */
  1892. }
  1893. }
  1894. }
  1895. fout << "\t</Globals>\n"
  1896. << "</VisualStudioProject>\n";
  1897. }
  1898. std::string cmLocalVisualStudio7GeneratorEscapeForXML(const std::string& s)
  1899. {
  1900. std::string ret = s;
  1901. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  1902. cmSystemTools::ReplaceString(ret, "\"", "&quot;");
  1903. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  1904. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  1905. cmSystemTools::ReplaceString(ret, "\n", "&#x0D;&#x0A;");
  1906. return ret;
  1907. }
  1908. std::string cmLocalVisualStudio7Generator::EscapeForXML(const std::string& s)
  1909. {
  1910. return cmLocalVisualStudio7GeneratorEscapeForXML(s);
  1911. }
  1912. std::string cmLocalVisualStudio7Generator::ConvertToXMLOutputPath(
  1913. const char* path)
  1914. {
  1915. std::string ret =
  1916. this->ConvertToOutputFormat(path, cmOutputConverter::SHELL);
  1917. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  1918. cmSystemTools::ReplaceString(ret, "\"", "&quot;");
  1919. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  1920. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  1921. return ret;
  1922. }
  1923. std::string cmLocalVisualStudio7Generator::ConvertToXMLOutputPathSingle(
  1924. const char* path)
  1925. {
  1926. std::string ret =
  1927. this->ConvertToOutputFormat(path, cmOutputConverter::SHELL);
  1928. cmSystemTools::ReplaceString(ret, "\"", "");
  1929. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  1930. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  1931. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  1932. return ret;
  1933. }
  1934. // This class is used to parse an existing vs 7 project
  1935. // and extract the GUID
  1936. class cmVS7XMLParser : public cmXMLParser
  1937. {
  1938. public:
  1939. virtual void EndElement(const std::string& /* name */) {}
  1940. virtual void StartElement(const std::string& name, const char** atts)
  1941. {
  1942. // once the GUID is found do nothing
  1943. if (!this->GUID.empty()) {
  1944. return;
  1945. }
  1946. int i = 0;
  1947. if ("VisualStudioProject" == name) {
  1948. while (atts[i]) {
  1949. if (strcmp(atts[i], "ProjectGUID") == 0) {
  1950. if (atts[i + 1]) {
  1951. this->GUID = atts[i + 1];
  1952. if (this->GUID[0] == '{') {
  1953. // remove surrounding curly brackets
  1954. this->GUID = this->GUID.substr(1, this->GUID.size() - 2);
  1955. }
  1956. } else {
  1957. this->GUID.clear();
  1958. }
  1959. return;
  1960. }
  1961. ++i;
  1962. }
  1963. }
  1964. }
  1965. int InitializeParser()
  1966. {
  1967. int ret = cmXMLParser::InitializeParser();
  1968. if (ret == 0) {
  1969. return ret;
  1970. }
  1971. // visual studio projects have a strange encoding, but it is
  1972. // really utf-8
  1973. XML_SetEncoding(static_cast<XML_Parser>(this->Parser), "utf-8");
  1974. return 1;
  1975. }
  1976. std::string GUID;
  1977. };
  1978. void cmLocalVisualStudio7Generator::ReadAndStoreExternalGUID(
  1979. const std::string& name, const char* path)
  1980. {
  1981. cmVS7XMLParser parser;
  1982. parser.ParseFile(path);
  1983. // if we can not find a GUID then we will generate one later
  1984. if (parser.GUID.empty()) {
  1985. return;
  1986. }
  1987. std::string guidStoreName = name;
  1988. guidStoreName += "_GUID_CMAKE";
  1989. // save the GUID in the cache
  1990. this->GlobalGenerator->GetCMakeInstance()->AddCacheEntry(
  1991. guidStoreName.c_str(), parser.GUID.c_str(), "Stored GUID",
  1992. cmStateEnums::INTERNAL);
  1993. }
  1994. std::string cmLocalVisualStudio7Generator::GetTargetDirectory(
  1995. cmGeneratorTarget const* target) const
  1996. {
  1997. std::string dir;
  1998. dir += target->GetName();
  1999. dir += ".dir";
  2000. return dir;
  2001. }
  2002. static bool cmLVS7G_IsFAT(const char* dir)
  2003. {
  2004. if (dir[0] && dir[1] == ':') {
  2005. char volRoot[4] = "_:/";
  2006. volRoot[0] = dir[0];
  2007. char fsName[16];
  2008. if (GetVolumeInformationA(volRoot, 0, 0, 0, 0, 0, fsName, 16) &&
  2009. strstr(fsName, "FAT") != 0) {
  2010. return true;
  2011. }
  2012. }
  2013. return false;
  2014. }