cmLocalVisualStudio7Generator.cxx 78 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157
  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. CM_FALLTHROUGH;
  577. case cmStateEnums::STATIC_LIBRARY:
  578. projectType = "typeStaticLibrary";
  579. configType = "4";
  580. break;
  581. case cmStateEnums::SHARED_LIBRARY:
  582. case cmStateEnums::MODULE_LIBRARY:
  583. projectType = "typeDynamicLibrary";
  584. configType = "2";
  585. break;
  586. case cmStateEnums::EXECUTABLE:
  587. configType = "1";
  588. break;
  589. case cmStateEnums::UTILITY:
  590. case cmStateEnums::GLOBAL_TARGET:
  591. configType = "10";
  592. CM_FALLTHROUGH;
  593. default:
  594. targetBuilds = false;
  595. break;
  596. }
  597. if (this->FortranProject && projectType) {
  598. configType = projectType;
  599. }
  600. std::string flags;
  601. if (strcmp(configType, "10") != 0) {
  602. const std::string& linkLanguage =
  603. (this->FortranProject ? std::string("Fortran")
  604. : target->GetLinkerLanguage(configName));
  605. if (linkLanguage.empty()) {
  606. cmSystemTools::Error(
  607. "CMake can not determine linker language for target: ",
  608. target->GetName().c_str());
  609. return;
  610. }
  611. if (linkLanguage == "C" || linkLanguage == "CXX" ||
  612. linkLanguage == "Fortran") {
  613. std::string baseFlagVar = "CMAKE_";
  614. baseFlagVar += linkLanguage;
  615. baseFlagVar += "_FLAGS";
  616. flags = this->Makefile->GetRequiredDefinition(baseFlagVar.c_str());
  617. std::string flagVar =
  618. baseFlagVar + std::string("_") + cmSystemTools::UpperCase(configName);
  619. flags += " ";
  620. flags += this->Makefile->GetRequiredDefinition(flagVar.c_str());
  621. }
  622. // set the correct language
  623. if (linkLanguage == "C") {
  624. flags += " /TC ";
  625. }
  626. if (linkLanguage == "CXX") {
  627. flags += " /TP ";
  628. }
  629. // Add the target-specific flags.
  630. this->AddCompileOptions(flags, target, linkLanguage, configName);
  631. // Check IPO related warning/error.
  632. target->IsIPOEnabled(linkLanguage, configName);
  633. }
  634. if (this->FortranProject) {
  635. switch (cmOutputConverter::GetFortranFormat(
  636. target->GetProperty("Fortran_FORMAT"))) {
  637. case cmOutputConverter::FortranFormatFixed:
  638. flags += " -fixed";
  639. break;
  640. case cmOutputConverter::FortranFormatFree:
  641. flags += " -free";
  642. break;
  643. default:
  644. break;
  645. }
  646. }
  647. // Get preprocessor definitions for this directory.
  648. std::string defineFlags = this->Makefile->GetDefineFlags();
  649. Options::Tool t = Options::Compiler;
  650. cmVS7FlagTable const* table = cmLocalVisualStudio7GeneratorFlagTable;
  651. if (this->FortranProject) {
  652. t = Options::FortranCompiler;
  653. table = cmLocalVisualStudio7GeneratorFortranFlagTable;
  654. }
  655. Options targetOptions(this, t, table, gg->ExtraFlagTable);
  656. targetOptions.FixExceptionHandlingDefault();
  657. std::string asmLocation = configName + "/";
  658. targetOptions.AddFlag("AssemblerListingLocation", asmLocation.c_str());
  659. targetOptions.Parse(flags.c_str());
  660. targetOptions.Parse(defineFlags.c_str());
  661. targetOptions.ParseFinish();
  662. std::vector<std::string> targetDefines;
  663. target->GetCompileDefinitions(targetDefines, configName, "CXX");
  664. targetOptions.AddDefines(targetDefines);
  665. targetOptions.SetVerboseMakefile(
  666. this->Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE"));
  667. // Add a definition for the configuration name.
  668. std::string configDefine = "CMAKE_INTDIR=\"";
  669. configDefine += configName;
  670. configDefine += "\"";
  671. targetOptions.AddDefine(configDefine);
  672. // Add the export symbol definition for shared library objects.
  673. if (const char* exportMacro = target->GetExportMacro()) {
  674. targetOptions.AddDefine(exportMacro);
  675. }
  676. // The intermediate directory name consists of a directory for the
  677. // target and a subdirectory for the configuration name.
  678. std::string intermediateDir = this->GetTargetDirectory(target);
  679. intermediateDir += "/";
  680. intermediateDir += configName;
  681. if (target->GetType() < cmStateEnums::UTILITY) {
  682. std::string const& outDir =
  683. target->GetType() == cmStateEnums::OBJECT_LIBRARY
  684. ? intermediateDir
  685. : target->GetDirectory(configName);
  686. /* clang-format off */
  687. fout << "\t\t\tOutputDirectory=\""
  688. << this->ConvertToXMLOutputPathSingle(outDir.c_str()) << "\"\n";
  689. /* clang-format on */
  690. }
  691. /* clang-format off */
  692. fout << "\t\t\tIntermediateDirectory=\""
  693. << this->ConvertToXMLOutputPath(intermediateDir.c_str())
  694. << "\"\n"
  695. << "\t\t\tConfigurationType=\"" << configType << "\"\n"
  696. << "\t\t\tUseOfMFC=\"" << mfcFlag << "\"\n"
  697. << "\t\t\tATLMinimizesCRunTimeLibraryUsage=\"false\"\n";
  698. /* clang-format on */
  699. if (this->FortranProject) {
  700. // Intel Fortran >= 15.0 uses TargetName property.
  701. std::string const targetNameFull = target->GetFullName(configName);
  702. std::string const targetName =
  703. cmSystemTools::GetFilenameWithoutLastExtension(targetNameFull);
  704. std::string const targetExt =
  705. target->GetType() == cmStateEnums::OBJECT_LIBRARY
  706. ? ".lib"
  707. : cmSystemTools::GetFilenameLastExtension(targetNameFull);
  708. /* clang-format off */
  709. fout <<
  710. "\t\t\tTargetName=\"" << this->EscapeForXML(targetName) << "\"\n"
  711. "\t\t\tTargetExt=\"" << this->EscapeForXML(targetExt) << "\"\n"
  712. ;
  713. /* clang-format on */
  714. }
  715. // If unicode is enabled change the character set to unicode, if not
  716. // then default to MBCS.
  717. if (targetOptions.UsingUnicode()) {
  718. fout << "\t\t\tCharacterSet=\"1\">\n";
  719. } else if (targetOptions.UsingSBCS()) {
  720. fout << "\t\t\tCharacterSet=\"0\">\n";
  721. } else {
  722. fout << "\t\t\tCharacterSet=\"2\">\n";
  723. }
  724. const char* tool = "VCCLCompilerTool";
  725. if (this->FortranProject) {
  726. tool = "VFFortranCompilerTool";
  727. }
  728. fout << "\t\t\t<Tool\n"
  729. << "\t\t\t\tName=\"" << tool << "\"\n";
  730. if (this->FortranProject) {
  731. const char* target_mod_dir =
  732. target->GetProperty("Fortran_MODULE_DIRECTORY");
  733. std::string modDir;
  734. if (target_mod_dir) {
  735. modDir = this->ConvertToRelativePath(this->GetCurrentBinaryDirectory(),
  736. target_mod_dir);
  737. } else {
  738. modDir = ".";
  739. }
  740. fout << "\t\t\t\tModulePath=\""
  741. << this->ConvertToXMLOutputPath(modDir.c_str())
  742. << "\\$(ConfigurationName)\"\n";
  743. }
  744. fout << "\t\t\t\tAdditionalIncludeDirectories=\"";
  745. std::vector<std::string> includes;
  746. this->GetIncludeDirectories(includes, target, "C", configName);
  747. std::vector<std::string>::iterator i = includes.begin();
  748. for (; i != includes.end(); ++i) {
  749. // output the include path
  750. std::string ipath = this->ConvertToXMLOutputPath(i->c_str());
  751. fout << ipath << ";";
  752. // if this is fortran then output the include with
  753. // a ConfigurationName on the end of it.
  754. if (this->FortranProject) {
  755. ipath = i->c_str();
  756. ipath += "/$(ConfigurationName)";
  757. ipath = this->ConvertToXMLOutputPath(ipath.c_str());
  758. fout << ipath << ";";
  759. }
  760. }
  761. fout << "\"\n";
  762. targetOptions.OutputFlagMap(fout, "\t\t\t\t");
  763. targetOptions.OutputPreprocessorDefinitions(fout, "\t\t\t\t", "\n", "CXX");
  764. fout << "\t\t\t\tObjectFile=\"$(IntDir)\\\"\n";
  765. if (target->GetType() <= cmStateEnums::OBJECT_LIBRARY) {
  766. // Specify the compiler program database file if configured.
  767. std::string pdb = target->GetCompilePDBPath(configName);
  768. if (!pdb.empty()) {
  769. fout << "\t\t\t\tProgramDataBaseFileName=\""
  770. << this->ConvertToXMLOutputPathSingle(pdb.c_str()) << "\"\n";
  771. }
  772. }
  773. fout << "/>\n"; // end of <Tool Name=VCCLCompilerTool
  774. if (gg->IsMasmEnabled() && !this->FortranProject) {
  775. Options masmOptions(this, Options::MasmCompiler, 0, 0);
  776. /* clang-format off */
  777. fout <<
  778. "\t\t\t<Tool\n"
  779. "\t\t\t\tName=\"MASM\"\n"
  780. "\t\t\t\tIncludePaths=\""
  781. ;
  782. /* clang-format on */
  783. const char* sep = "";
  784. for (i = includes.begin(); i != includes.end(); ++i) {
  785. std::string inc = *i;
  786. cmConvertToWindowsSlash(inc);
  787. fout << sep << this->EscapeForXML(inc);
  788. sep = ";";
  789. }
  790. fout << "\"\n";
  791. // Use same preprocessor definitions as VCCLCompilerTool.
  792. targetOptions.OutputPreprocessorDefinitions(fout, "\t\t\t\t", "\n",
  793. "ASM_MASM");
  794. masmOptions.OutputFlagMap(fout, "\t\t\t\t");
  795. /* clang-format off */
  796. fout <<
  797. "\t\t\t\tObjectFile=\"$(IntDir)\\\"\n"
  798. "\t\t\t/>\n";
  799. /* clang-format on */
  800. }
  801. tool = "VCCustomBuildTool";
  802. if (this->FortranProject) {
  803. tool = "VFCustomBuildTool";
  804. }
  805. fout << "\t\t\t<Tool\n\t\t\t\tName=\"" << tool << "\"/>\n";
  806. tool = "VCResourceCompilerTool";
  807. if (this->FortranProject) {
  808. tool = "VFResourceCompilerTool";
  809. }
  810. fout << "\t\t\t<Tool\n\t\t\t\tName=\"" << tool << "\"\n"
  811. << "\t\t\t\tAdditionalIncludeDirectories=\"";
  812. for (i = includes.begin(); i != includes.end(); ++i) {
  813. std::string ipath = this->ConvertToXMLOutputPath(i->c_str());
  814. fout << ipath << ";";
  815. }
  816. // add the -D flags to the RC tool
  817. fout << "\"";
  818. targetOptions.OutputPreprocessorDefinitions(fout, "\n\t\t\t\t", "", "RC");
  819. fout << "/>\n";
  820. tool = "VCMIDLTool";
  821. if (this->FortranProject) {
  822. tool = "VFMIDLTool";
  823. }
  824. fout << "\t\t\t<Tool\n\t\t\t\tName=\"" << tool << "\"\n";
  825. fout << "\t\t\t\tAdditionalIncludeDirectories=\"";
  826. for (i = includes.begin(); i != includes.end(); ++i) {
  827. std::string ipath = this->ConvertToXMLOutputPath(i->c_str());
  828. fout << ipath << ";";
  829. }
  830. fout << "\"\n";
  831. fout << "\t\t\t\tMkTypLibCompatible=\"false\"\n";
  832. if (gg->GetPlatformName() == "x64") {
  833. fout << "\t\t\t\tTargetEnvironment=\"3\"\n";
  834. } else if (gg->GetPlatformName() == "ia64") {
  835. fout << "\t\t\t\tTargetEnvironment=\"2\"\n";
  836. } else {
  837. fout << "\t\t\t\tTargetEnvironment=\"1\"\n";
  838. }
  839. fout << "\t\t\t\tGenerateStublessProxies=\"true\"\n";
  840. fout << "\t\t\t\tTypeLibraryName=\"$(InputName).tlb\"\n";
  841. fout << "\t\t\t\tOutputDirectory=\"$(IntDir)\"\n";
  842. fout << "\t\t\t\tHeaderFileName=\"$(InputName).h\"\n";
  843. fout << "\t\t\t\tDLLDataFileName=\"\"\n";
  844. fout << "\t\t\t\tInterfaceIdentifierFileName=\"$(InputName)_i.c\"\n";
  845. fout << "\t\t\t\tProxyFileName=\"$(InputName)_p.c\"/>\n";
  846. // end of <Tool Name=VCMIDLTool
  847. // Add manifest tool settings.
  848. if (targetBuilds) {
  849. const char* manifestTool = "VCManifestTool";
  850. if (this->FortranProject) {
  851. manifestTool = "VFManifestTool";
  852. }
  853. /* clang-format off */
  854. fout <<
  855. "\t\t\t<Tool\n"
  856. "\t\t\t\tName=\"" << manifestTool << "\"";
  857. /* clang-format on */
  858. std::vector<cmSourceFile const*> manifest_srcs;
  859. target->GetManifests(manifest_srcs, configName);
  860. if (!manifest_srcs.empty()) {
  861. fout << "\n\t\t\t\tAdditionalManifestFiles=\"";
  862. for (std::vector<cmSourceFile const*>::const_iterator mi =
  863. manifest_srcs.begin();
  864. mi != manifest_srcs.end(); ++mi) {
  865. std::string m = (*mi)->GetFullPath();
  866. fout << this->ConvertToXMLOutputPath(m.c_str()) << ";";
  867. }
  868. fout << "\"";
  869. }
  870. // Check if we need the FAT32 workaround.
  871. // Check the filesystem type where the target will be written.
  872. if (cmLVS7G_IsFAT(target->GetDirectory(configName).c_str())) {
  873. // Add a flag telling the manifest tool to use a workaround
  874. // for FAT32 file systems, which can cause an empty manifest
  875. // to be embedded into the resulting executable. See CMake
  876. // bug #2617.
  877. fout << "\n\t\t\t\tUseFAT32Workaround=\"true\"";
  878. }
  879. fout << "/>\n";
  880. }
  881. this->OutputTargetRules(fout, configName, target, libName);
  882. this->OutputBuildTool(fout, configName, target, targetOptions);
  883. this->OutputDeploymentDebuggerTool(fout, configName, target);
  884. fout << "\t\t</Configuration>\n";
  885. }
  886. std::string cmLocalVisualStudio7Generator::GetBuildTypeLinkerFlags(
  887. std::string rootLinkerFlags, const std::string& configName)
  888. {
  889. std::string configTypeUpper = cmSystemTools::UpperCase(configName);
  890. std::string extraLinkOptionsBuildTypeDef =
  891. rootLinkerFlags + "_" + configTypeUpper;
  892. std::string extraLinkOptionsBuildType =
  893. this->Makefile->GetRequiredDefinition(
  894. extraLinkOptionsBuildTypeDef.c_str());
  895. return extraLinkOptionsBuildType;
  896. }
  897. void cmLocalVisualStudio7Generator::OutputBuildTool(
  898. std::ostream& fout, const std::string& configName, cmGeneratorTarget* target,
  899. const Options& targetOptions)
  900. {
  901. cmGlobalVisualStudio7Generator* gg =
  902. static_cast<cmGlobalVisualStudio7Generator*>(this->GlobalGenerator);
  903. std::string temp;
  904. std::string extraLinkOptions;
  905. if (target->GetType() == cmStateEnums::EXECUTABLE) {
  906. extraLinkOptions =
  907. this->Makefile->GetRequiredDefinition("CMAKE_EXE_LINKER_FLAGS") +
  908. std::string(" ") +
  909. GetBuildTypeLinkerFlags("CMAKE_EXE_LINKER_FLAGS", configName);
  910. }
  911. if (target->GetType() == cmStateEnums::SHARED_LIBRARY) {
  912. extraLinkOptions =
  913. this->Makefile->GetRequiredDefinition("CMAKE_SHARED_LINKER_FLAGS") +
  914. std::string(" ") +
  915. GetBuildTypeLinkerFlags("CMAKE_SHARED_LINKER_FLAGS", configName);
  916. }
  917. if (target->GetType() == cmStateEnums::MODULE_LIBRARY) {
  918. extraLinkOptions =
  919. this->Makefile->GetRequiredDefinition("CMAKE_MODULE_LINKER_FLAGS") +
  920. std::string(" ") +
  921. GetBuildTypeLinkerFlags("CMAKE_MODULE_LINKER_FLAGS", configName);
  922. }
  923. const char* targetLinkFlags = target->GetProperty("LINK_FLAGS");
  924. if (targetLinkFlags) {
  925. extraLinkOptions += " ";
  926. extraLinkOptions += targetLinkFlags;
  927. }
  928. std::string configTypeUpper = cmSystemTools::UpperCase(configName);
  929. std::string linkFlagsConfig = "LINK_FLAGS_";
  930. linkFlagsConfig += configTypeUpper;
  931. targetLinkFlags = target->GetProperty(linkFlagsConfig.c_str());
  932. if (targetLinkFlags) {
  933. extraLinkOptions += " ";
  934. extraLinkOptions += targetLinkFlags;
  935. }
  936. Options linkOptions(this, Options::Linker);
  937. if (this->FortranProject) {
  938. linkOptions.AddTable(cmLocalVisualStudio7GeneratorFortranLinkFlagTable);
  939. }
  940. linkOptions.AddTable(cmLocalVisualStudio7GeneratorLinkFlagTable);
  941. linkOptions.Parse(extraLinkOptions.c_str());
  942. cmGeneratorTarget::ModuleDefinitionInfo const* mdi =
  943. target->GetModuleDefinitionInfo(configName);
  944. if (mdi && !mdi->DefFile.empty()) {
  945. std::string defFile =
  946. this->ConvertToOutputFormat(mdi->DefFile, cmOutputConverter::SHELL);
  947. linkOptions.AddFlag("ModuleDefinitionFile", defFile.c_str());
  948. }
  949. switch (target->GetType()) {
  950. case cmStateEnums::UNKNOWN_LIBRARY:
  951. break;
  952. case cmStateEnums::OBJECT_LIBRARY: {
  953. std::string libpath = this->GetTargetDirectory(target);
  954. libpath += "/";
  955. libpath += configName;
  956. libpath += "/";
  957. libpath += target->GetName();
  958. libpath += ".lib";
  959. const char* tool =
  960. this->FortranProject ? "VFLibrarianTool" : "VCLibrarianTool";
  961. fout << "\t\t\t<Tool\n"
  962. << "\t\t\t\tName=\"" << tool << "\"\n";
  963. fout << "\t\t\t\tOutputFile=\""
  964. << this->ConvertToXMLOutputPathSingle(libpath.c_str()) << "\"/>\n";
  965. break;
  966. }
  967. case cmStateEnums::STATIC_LIBRARY: {
  968. std::string targetNameFull = target->GetFullName(configName);
  969. std::string libpath = target->GetDirectory(configName);
  970. libpath += "/";
  971. libpath += targetNameFull;
  972. const char* tool = "VCLibrarianTool";
  973. if (this->FortranProject) {
  974. tool = "VFLibrarianTool";
  975. }
  976. fout << "\t\t\t<Tool\n"
  977. << "\t\t\t\tName=\"" << tool << "\"\n";
  978. if (this->FortranProject) {
  979. std::ostringstream libdeps;
  980. this->Internal->OutputObjects(libdeps, target, configName);
  981. if (!libdeps.str().empty()) {
  982. fout << "\t\t\t\tAdditionalDependencies=\"" << libdeps.str()
  983. << "\"\n";
  984. }
  985. }
  986. std::string libflags;
  987. this->GetStaticLibraryFlags(libflags, configTypeUpper, target);
  988. if (!libflags.empty()) {
  989. fout << "\t\t\t\tAdditionalOptions=\"" << libflags << "\"\n";
  990. }
  991. fout << "\t\t\t\tOutputFile=\""
  992. << this->ConvertToXMLOutputPathSingle(libpath.c_str()) << "\"/>\n";
  993. break;
  994. }
  995. case cmStateEnums::SHARED_LIBRARY:
  996. case cmStateEnums::MODULE_LIBRARY: {
  997. std::string targetName;
  998. std::string targetNameSO;
  999. std::string targetNameFull;
  1000. std::string targetNameImport;
  1001. std::string targetNamePDB;
  1002. target->GetLibraryNames(targetName, targetNameSO, targetNameFull,
  1003. targetNameImport, targetNamePDB, configName);
  1004. // Compute the link library and directory information.
  1005. cmComputeLinkInformation* pcli = target->GetLinkInformation(configName);
  1006. if (!pcli) {
  1007. return;
  1008. }
  1009. cmComputeLinkInformation& cli = *pcli;
  1010. std::string linkLanguage = cli.GetLinkLanguage();
  1011. // Compute the variable name to lookup standard libraries for this
  1012. // language.
  1013. std::string standardLibsVar = "CMAKE_";
  1014. standardLibsVar += linkLanguage;
  1015. standardLibsVar += "_STANDARD_LIBRARIES";
  1016. const char* tool = "VCLinkerTool";
  1017. if (this->FortranProject) {
  1018. tool = "VFLinkerTool";
  1019. }
  1020. fout << "\t\t\t<Tool\n"
  1021. << "\t\t\t\tName=\"" << tool << "\"\n";
  1022. if (!gg->NeedLinkLibraryDependencies(target)) {
  1023. fout << "\t\t\t\tLinkLibraryDependencies=\"false\"\n";
  1024. }
  1025. // Use the NOINHERIT macro to avoid getting VS project default
  1026. // libraries which may be set by the user to something bad.
  1027. fout << "\t\t\t\tAdditionalDependencies=\"$(NOINHERIT) "
  1028. << this->Makefile->GetSafeDefinition(standardLibsVar.c_str());
  1029. if (this->FortranProject) {
  1030. this->Internal->OutputObjects(fout, target, configName, " ");
  1031. }
  1032. fout << " ";
  1033. this->Internal->OutputLibraries(fout, cli.GetItems());
  1034. fout << "\"\n";
  1035. temp = target->GetDirectory(configName);
  1036. temp += "/";
  1037. temp += targetNameFull;
  1038. fout << "\t\t\t\tOutputFile=\""
  1039. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  1040. this->WriteTargetVersionAttribute(fout, target);
  1041. linkOptions.OutputFlagMap(fout, "\t\t\t\t");
  1042. fout << "\t\t\t\tAdditionalLibraryDirectories=\"";
  1043. this->OutputLibraryDirectories(fout, cli.GetDirectories());
  1044. fout << "\"\n";
  1045. temp = target->GetPDBDirectory(configName);
  1046. temp += "/";
  1047. temp += targetNamePDB;
  1048. fout << "\t\t\t\tProgramDatabaseFile=\""
  1049. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  1050. if (targetOptions.IsDebug()) {
  1051. fout << "\t\t\t\tGenerateDebugInformation=\"true\"\n";
  1052. }
  1053. if (this->WindowsCEProject) {
  1054. if (this->GetVersion() < cmGlobalVisualStudioGenerator::VS9) {
  1055. fout << "\t\t\t\tSubSystem=\"9\"\n";
  1056. } else {
  1057. fout << "\t\t\t\tSubSystem=\"8\"\n";
  1058. }
  1059. }
  1060. std::string stackVar = "CMAKE_";
  1061. stackVar += linkLanguage;
  1062. stackVar += "_STACK_SIZE";
  1063. const char* stackVal = this->Makefile->GetDefinition(stackVar.c_str());
  1064. if (stackVal) {
  1065. fout << "\t\t\t\tStackReserveSize=\"" << stackVal << "\"\n";
  1066. }
  1067. temp =
  1068. target->GetDirectory(configName, cmStateEnums::ImportLibraryArtifact);
  1069. temp += "/";
  1070. temp += targetNameImport;
  1071. fout << "\t\t\t\tImportLibrary=\""
  1072. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"";
  1073. if (this->FortranProject) {
  1074. fout << "\n\t\t\t\tLinkDLL=\"true\"";
  1075. }
  1076. fout << "/>\n";
  1077. } break;
  1078. case cmStateEnums::EXECUTABLE: {
  1079. std::string targetName;
  1080. std::string targetNameFull;
  1081. std::string targetNameImport;
  1082. std::string targetNamePDB;
  1083. target->GetExecutableNames(targetName, targetNameFull, targetNameImport,
  1084. targetNamePDB, configName);
  1085. // Compute the link library and directory information.
  1086. cmComputeLinkInformation* pcli = target->GetLinkInformation(configName);
  1087. if (!pcli) {
  1088. return;
  1089. }
  1090. cmComputeLinkInformation& cli = *pcli;
  1091. std::string linkLanguage = cli.GetLinkLanguage();
  1092. bool isWin32Executable = target->GetPropertyAsBool("WIN32_EXECUTABLE");
  1093. // Compute the variable name to lookup standard libraries for this
  1094. // language.
  1095. std::string standardLibsVar = "CMAKE_";
  1096. standardLibsVar += linkLanguage;
  1097. standardLibsVar += "_STANDARD_LIBRARIES";
  1098. const char* tool = "VCLinkerTool";
  1099. if (this->FortranProject) {
  1100. tool = "VFLinkerTool";
  1101. }
  1102. fout << "\t\t\t<Tool\n"
  1103. << "\t\t\t\tName=\"" << tool << "\"\n";
  1104. if (!gg->NeedLinkLibraryDependencies(target)) {
  1105. fout << "\t\t\t\tLinkLibraryDependencies=\"false\"\n";
  1106. }
  1107. // Use the NOINHERIT macro to avoid getting VS project default
  1108. // libraries which may be set by the user to something bad.
  1109. fout << "\t\t\t\tAdditionalDependencies=\"$(NOINHERIT) "
  1110. << this->Makefile->GetSafeDefinition(standardLibsVar.c_str());
  1111. if (this->FortranProject) {
  1112. this->Internal->OutputObjects(fout, target, configName, " ");
  1113. }
  1114. fout << " ";
  1115. this->Internal->OutputLibraries(fout, cli.GetItems());
  1116. fout << "\"\n";
  1117. temp = target->GetDirectory(configName);
  1118. temp += "/";
  1119. temp += targetNameFull;
  1120. fout << "\t\t\t\tOutputFile=\""
  1121. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  1122. this->WriteTargetVersionAttribute(fout, target);
  1123. linkOptions.OutputFlagMap(fout, "\t\t\t\t");
  1124. fout << "\t\t\t\tAdditionalLibraryDirectories=\"";
  1125. this->OutputLibraryDirectories(fout, cli.GetDirectories());
  1126. fout << "\"\n";
  1127. std::string path = this->ConvertToXMLOutputPathSingle(
  1128. target->GetPDBDirectory(configName).c_str());
  1129. fout << "\t\t\t\tProgramDatabaseFile=\"" << path << "/" << targetNamePDB
  1130. << "\"\n";
  1131. if (targetOptions.IsDebug()) {
  1132. fout << "\t\t\t\tGenerateDebugInformation=\"true\"\n";
  1133. }
  1134. if (this->WindowsCEProject) {
  1135. if (this->GetVersion() < cmGlobalVisualStudioGenerator::VS9) {
  1136. fout << "\t\t\t\tSubSystem=\"9\"\n";
  1137. } else {
  1138. fout << "\t\t\t\tSubSystem=\"8\"\n";
  1139. }
  1140. if (!linkOptions.GetFlag("EntryPointSymbol")) {
  1141. const char* entryPointSymbol = targetOptions.UsingUnicode()
  1142. ? (isWin32Executable ? "wWinMainCRTStartup" : "mainWCRTStartup")
  1143. : (isWin32Executable ? "WinMainCRTStartup" : "mainACRTStartup");
  1144. fout << "\t\t\t\tEntryPointSymbol=\"" << entryPointSymbol << "\"\n";
  1145. }
  1146. } else if (this->FortranProject) {
  1147. fout << "\t\t\t\tSubSystem=\""
  1148. << (isWin32Executable ? "subSystemWindows" : "subSystemConsole")
  1149. << "\"\n";
  1150. } else {
  1151. fout << "\t\t\t\tSubSystem=\"" << (isWin32Executable ? "2" : "1")
  1152. << "\"\n";
  1153. }
  1154. std::string stackVar = "CMAKE_";
  1155. stackVar += linkLanguage;
  1156. stackVar += "_STACK_SIZE";
  1157. const char* stackVal = this->Makefile->GetDefinition(stackVar.c_str());
  1158. if (stackVal) {
  1159. fout << "\t\t\t\tStackReserveSize=\"" << stackVal << "\"";
  1160. }
  1161. temp =
  1162. target->GetDirectory(configName, cmStateEnums::ImportLibraryArtifact);
  1163. temp += "/";
  1164. temp += targetNameImport;
  1165. fout << "\t\t\t\tImportLibrary=\""
  1166. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"/>\n";
  1167. break;
  1168. }
  1169. case cmStateEnums::UTILITY:
  1170. case cmStateEnums::GLOBAL_TARGET:
  1171. case cmStateEnums::INTERFACE_LIBRARY:
  1172. break;
  1173. }
  1174. }
  1175. void cmLocalVisualStudio7Generator::OutputDeploymentDebuggerTool(
  1176. std::ostream& fout, std::string const& config, cmGeneratorTarget* target)
  1177. {
  1178. if (this->WindowsCEProject) {
  1179. if (const char* dir = target->GetProperty("DEPLOYMENT_REMOTE_DIRECTORY")) {
  1180. /* clang-format off */
  1181. fout <<
  1182. "\t\t\t<DeploymentTool\n"
  1183. "\t\t\t\tForceDirty=\"-1\"\n"
  1184. "\t\t\t\tRemoteDirectory=\"" << this->EscapeForXML(dir) << "\"\n"
  1185. "\t\t\t\tRegisterOutput=\"0\"\n"
  1186. "\t\t\t\tAdditionalFiles=\"\"/>\n"
  1187. ;
  1188. /* clang-format on */
  1189. std::string const exe =
  1190. dir + std::string("\\") + target->GetFullName(config);
  1191. /* clang-format off */
  1192. fout <<
  1193. "\t\t\t<DebuggerTool\n"
  1194. "\t\t\t\tRemoteExecutable=\"" << this->EscapeForXML(exe) << "\"\n"
  1195. "\t\t\t\tArguments=\"\"\n"
  1196. "\t\t\t/>\n"
  1197. ;
  1198. /* clang-format on */
  1199. }
  1200. }
  1201. }
  1202. void cmLocalVisualStudio7Generator::WriteTargetVersionAttribute(
  1203. std::ostream& fout, cmGeneratorTarget* gt)
  1204. {
  1205. int major;
  1206. int minor;
  1207. gt->GetTargetVersion(major, minor);
  1208. fout << "\t\t\t\tVersion=\"" << major << "." << minor << "\"\n";
  1209. }
  1210. void cmLocalVisualStudio7GeneratorInternals::OutputLibraries(
  1211. std::ostream& fout, ItemVector const& libs)
  1212. {
  1213. cmLocalVisualStudio7Generator* lg = this->LocalGenerator;
  1214. std::string currentBinDir = lg->GetCurrentBinaryDirectory();
  1215. for (ItemVector::const_iterator l = libs.begin(); l != libs.end(); ++l) {
  1216. if (l->IsPath) {
  1217. std::string rel =
  1218. lg->ConvertToRelativePath(currentBinDir, l->Value.c_str());
  1219. fout << lg->ConvertToXMLOutputPath(rel.c_str()) << " ";
  1220. } else if (!l->Target ||
  1221. l->Target->GetType() != cmStateEnums::INTERFACE_LIBRARY) {
  1222. fout << l->Value << " ";
  1223. }
  1224. }
  1225. }
  1226. void cmLocalVisualStudio7GeneratorInternals::OutputObjects(
  1227. std::ostream& fout, cmGeneratorTarget* gt, std::string const& configName,
  1228. const char* isep)
  1229. {
  1230. // VS < 8 does not support per-config source locations so we
  1231. // list object library content on the link line instead.
  1232. cmLocalVisualStudio7Generator* lg = this->LocalGenerator;
  1233. std::string currentBinDir = lg->GetCurrentBinaryDirectory();
  1234. std::vector<cmSourceFile const*> objs;
  1235. gt->GetExternalObjects(objs, configName);
  1236. const char* sep = isep ? isep : "";
  1237. for (std::vector<cmSourceFile const*>::const_iterator i = objs.begin();
  1238. i != objs.end(); ++i) {
  1239. if (!(*i)->GetObjectLibrary().empty()) {
  1240. std::string const& objFile = (*i)->GetFullPath();
  1241. std::string rel = lg->ConvertToRelativePath(currentBinDir, objFile);
  1242. fout << sep << lg->ConvertToXMLOutputPath(rel.c_str());
  1243. sep = " ";
  1244. }
  1245. }
  1246. }
  1247. void cmLocalVisualStudio7Generator::OutputLibraryDirectories(
  1248. std::ostream& fout, std::vector<std::string> const& dirs)
  1249. {
  1250. const char* comma = "";
  1251. std::string currentBinDir = this->GetCurrentBinaryDirectory();
  1252. for (std::vector<std::string>::const_iterator d = dirs.begin();
  1253. d != dirs.end(); ++d) {
  1254. // Remove any trailing slash and skip empty paths.
  1255. std::string dir = *d;
  1256. if (dir[dir.size() - 1] == '/') {
  1257. dir = dir.substr(0, dir.size() - 1);
  1258. }
  1259. if (dir.empty()) {
  1260. continue;
  1261. }
  1262. // Switch to a relative path specification if it is shorter.
  1263. if (cmSystemTools::FileIsFullPath(dir.c_str())) {
  1264. std::string rel =
  1265. this->ConvertToRelativePath(currentBinDir, dir.c_str());
  1266. if (rel.size() < dir.size()) {
  1267. dir = rel;
  1268. }
  1269. }
  1270. // First search a configuration-specific subdirectory and then the
  1271. // original directory.
  1272. fout << comma
  1273. << this->ConvertToXMLOutputPath(
  1274. (dir + "/$(ConfigurationName)").c_str())
  1275. << "," << this->ConvertToXMLOutputPath(dir.c_str());
  1276. comma = ",";
  1277. }
  1278. }
  1279. void cmLocalVisualStudio7Generator::WriteVCProjFile(std::ostream& fout,
  1280. const std::string& libName,
  1281. cmGeneratorTarget* target)
  1282. {
  1283. std::vector<std::string> configs;
  1284. this->Makefile->GetConfigurations(configs);
  1285. // We may be modifying the source groups temporarily, so make a copy.
  1286. std::vector<cmSourceGroup> sourceGroups = this->Makefile->GetSourceGroups();
  1287. AllConfigSources sources;
  1288. sources.Sources = target->GetAllConfigSources();
  1289. // Add CMakeLists.txt file with rule to re-run CMake for user convenience.
  1290. if (target->GetType() != cmStateEnums::GLOBAL_TARGET &&
  1291. target->GetName() != CMAKE_CHECK_BUILD_SYSTEM_TARGET) {
  1292. if (cmSourceFile const* sf = this->CreateVCProjBuildRule()) {
  1293. cmGeneratorTarget::AllConfigSource acs;
  1294. acs.Source = sf;
  1295. acs.Kind = cmGeneratorTarget::SourceKindCustomCommand;
  1296. for (size_t ci = 0; ci < configs.size(); ++ci) {
  1297. acs.Configs.push_back(ci);
  1298. }
  1299. sources.Sources.emplace_back(std::move(acs));
  1300. }
  1301. }
  1302. for (size_t si = 0; si < sources.Sources.size(); ++si) {
  1303. cmSourceFile const* sf = sources.Sources[si].Source;
  1304. sources.Index[sf] = si;
  1305. if (!sf->GetObjectLibrary().empty()) {
  1306. if (this->FortranProject) {
  1307. // Intel Fortran does not support per-config source locations
  1308. // so we list object library content on the link line instead.
  1309. // See OutputObjects.
  1310. continue;
  1311. }
  1312. }
  1313. // Add the file to the list of sources.
  1314. std::string const source = sf->GetFullPath();
  1315. cmSourceGroup* sourceGroup =
  1316. this->Makefile->FindSourceGroup(source.c_str(), sourceGroups);
  1317. sourceGroup->AssignSource(sf);
  1318. }
  1319. // open the project
  1320. this->WriteProjectStart(fout, libName, target, sourceGroups);
  1321. // write the configuration information
  1322. this->WriteConfigurations(fout, configs, libName, target);
  1323. fout << "\t<Files>\n";
  1324. // Loop through every source group.
  1325. for (unsigned int i = 0; i < sourceGroups.size(); ++i) {
  1326. cmSourceGroup sg = sourceGroups[i];
  1327. this->WriteGroup(&sg, target, fout, libName, configs, sources);
  1328. }
  1329. fout << "\t</Files>\n";
  1330. // Write the VCProj file's footer.
  1331. this->WriteVCProjFooter(fout, target);
  1332. }
  1333. struct cmLVS7GFileConfig
  1334. {
  1335. std::string ObjectName;
  1336. std::string CompileFlags;
  1337. std::string CompileDefs;
  1338. std::string CompileDefsConfig;
  1339. std::string AdditionalDeps;
  1340. bool ExcludedFromBuild;
  1341. };
  1342. class cmLocalVisualStudio7GeneratorFCInfo
  1343. {
  1344. public:
  1345. cmLocalVisualStudio7GeneratorFCInfo(
  1346. cmLocalVisualStudio7Generator* lg, cmGeneratorTarget* target,
  1347. cmGeneratorTarget::AllConfigSource const& acs,
  1348. std::vector<std::string> const& configs);
  1349. std::map<std::string, cmLVS7GFileConfig> FileConfigMap;
  1350. };
  1351. cmLocalVisualStudio7GeneratorFCInfo::cmLocalVisualStudio7GeneratorFCInfo(
  1352. cmLocalVisualStudio7Generator* lg, cmGeneratorTarget* gt,
  1353. cmGeneratorTarget::AllConfigSource const& acs,
  1354. std::vector<std::string> const& configs)
  1355. {
  1356. cmSourceFile const& sf = *acs.Source;
  1357. std::string objectName;
  1358. if (gt->HasExplicitObjectName(&sf)) {
  1359. objectName = gt->GetObjectName(&sf);
  1360. }
  1361. // Compute per-source, per-config information.
  1362. size_t ci = 0;
  1363. for (std::vector<std::string>::const_iterator i = configs.begin();
  1364. i != configs.end(); ++i, ++ci) {
  1365. std::string configUpper = cmSystemTools::UpperCase(*i);
  1366. cmLVS7GFileConfig fc;
  1367. bool needfc = false;
  1368. if (!objectName.empty()) {
  1369. fc.ObjectName = objectName;
  1370. needfc = true;
  1371. }
  1372. if (const char* cflags = sf.GetProperty("COMPILE_FLAGS")) {
  1373. cmGeneratorExpression ge;
  1374. std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(cflags);
  1375. fc.CompileFlags = cge->Evaluate(lg, *i, false, gt);
  1376. needfc = true;
  1377. }
  1378. if (lg->FortranProject) {
  1379. switch (cmOutputConverter::GetFortranFormat(
  1380. sf.GetProperty("Fortran_FORMAT"))) {
  1381. case cmOutputConverter::FortranFormatFixed:
  1382. fc.CompileFlags = "-fixed " + fc.CompileFlags;
  1383. needfc = true;
  1384. break;
  1385. case cmOutputConverter::FortranFormatFree:
  1386. fc.CompileFlags = "-free " + fc.CompileFlags;
  1387. needfc = true;
  1388. break;
  1389. default:
  1390. break;
  1391. }
  1392. }
  1393. if (const char* cdefs = sf.GetProperty("COMPILE_DEFINITIONS")) {
  1394. fc.CompileDefs = cdefs;
  1395. needfc = true;
  1396. }
  1397. std::string defPropName = "COMPILE_DEFINITIONS_";
  1398. defPropName += configUpper;
  1399. if (const char* ccdefs = sf.GetProperty(defPropName.c_str())) {
  1400. fc.CompileDefsConfig = ccdefs;
  1401. needfc = true;
  1402. }
  1403. // Check for extra object-file dependencies.
  1404. if (const char* deps = sf.GetProperty("OBJECT_DEPENDS")) {
  1405. std::vector<std::string> depends;
  1406. cmSystemTools::ExpandListArgument(deps, depends);
  1407. const char* sep = "";
  1408. for (std::vector<std::string>::iterator j = depends.begin();
  1409. j != depends.end(); ++j) {
  1410. fc.AdditionalDeps += sep;
  1411. fc.AdditionalDeps += lg->ConvertToXMLOutputPath(j->c_str());
  1412. sep = ";";
  1413. needfc = true;
  1414. }
  1415. }
  1416. std::string lang =
  1417. lg->GlobalGenerator->GetLanguageFromExtension(sf.GetExtension().c_str());
  1418. const std::string& sourceLang = lg->GetSourceFileLanguage(sf);
  1419. const std::string& linkLanguage = gt->GetLinkerLanguage(i->c_str());
  1420. bool needForceLang = false;
  1421. // source file does not match its extension language
  1422. if (lang != sourceLang) {
  1423. needForceLang = true;
  1424. lang = sourceLang;
  1425. }
  1426. // If HEADER_FILE_ONLY is set, we must suppress this generation in
  1427. // the project file
  1428. fc.ExcludedFromBuild = sf.GetPropertyAsBool("HEADER_FILE_ONLY") ||
  1429. std::find(acs.Configs.begin(), acs.Configs.end(), ci) ==
  1430. acs.Configs.end();
  1431. if (fc.ExcludedFromBuild) {
  1432. needfc = true;
  1433. }
  1434. // if the source file does not match the linker language
  1435. // then force c or c++
  1436. if (needForceLang || (linkLanguage != lang)) {
  1437. if (lang == "CXX") {
  1438. // force a C++ file type
  1439. fc.CompileFlags += " /TP ";
  1440. needfc = true;
  1441. } else if (lang == "C") {
  1442. // force to c
  1443. fc.CompileFlags += " /TC ";
  1444. needfc = true;
  1445. }
  1446. }
  1447. if (needfc) {
  1448. this->FileConfigMap[*i] = fc;
  1449. }
  1450. }
  1451. }
  1452. std::string cmLocalVisualStudio7Generator::ComputeLongestObjectDirectory(
  1453. cmGeneratorTarget const* target) const
  1454. {
  1455. std::vector<std::string> configs;
  1456. target->Target->GetMakefile()->GetConfigurations(configs);
  1457. // Compute the maximum length configuration name.
  1458. std::string config_max;
  1459. for (std::vector<std::string>::iterator i = configs.begin();
  1460. i != configs.end(); ++i) {
  1461. if (i->size() > config_max.size()) {
  1462. config_max = *i;
  1463. }
  1464. }
  1465. // Compute the maximum length full path to the intermediate
  1466. // files directory for any configuration. This is used to construct
  1467. // object file names that do not produce paths that are too long.
  1468. std::string dir_max;
  1469. dir_max += this->GetCurrentBinaryDirectory();
  1470. dir_max += "/";
  1471. dir_max += this->GetTargetDirectory(target);
  1472. dir_max += "/";
  1473. dir_max += config_max;
  1474. dir_max += "/";
  1475. return dir_max;
  1476. }
  1477. bool cmLocalVisualStudio7Generator::WriteGroup(
  1478. const cmSourceGroup* sg, cmGeneratorTarget* target, std::ostream& fout,
  1479. const std::string& libName, std::vector<std::string> const& configs,
  1480. AllConfigSources const& sources)
  1481. {
  1482. cmGlobalVisualStudio7Generator* gg =
  1483. static_cast<cmGlobalVisualStudio7Generator*>(this->GlobalGenerator);
  1484. const std::vector<const cmSourceFile*>& sourceFiles = sg->GetSourceFiles();
  1485. std::vector<cmSourceGroup> const& children = sg->GetGroupChildren();
  1486. // Write the children to temporary output.
  1487. bool hasChildrenWithSources = false;
  1488. std::ostringstream tmpOut;
  1489. for (unsigned int i = 0; i < children.size(); ++i) {
  1490. if (this->WriteGroup(&children[i], target, tmpOut, libName, configs,
  1491. sources)) {
  1492. hasChildrenWithSources = true;
  1493. }
  1494. }
  1495. // If the group is empty, don't write it at all.
  1496. if (sourceFiles.empty() && !hasChildrenWithSources) {
  1497. return false;
  1498. }
  1499. // If the group has a name, write the header.
  1500. std::string const& name = sg->GetName();
  1501. if (!name.empty()) {
  1502. this->WriteVCProjBeginGroup(fout, name.c_str(), "");
  1503. }
  1504. // Loop through each source in the source group.
  1505. for (std::vector<const cmSourceFile*>::const_iterator sf =
  1506. sourceFiles.begin();
  1507. sf != sourceFiles.end(); ++sf) {
  1508. std::string source = (*sf)->GetFullPath();
  1509. if (source != libName || target->GetType() == cmStateEnums::UTILITY ||
  1510. target->GetType() == cmStateEnums::GLOBAL_TARGET) {
  1511. // Look up the source kind and configs.
  1512. std::map<cmSourceFile const*, size_t>::const_iterator map_it =
  1513. sources.Index.find(*sf);
  1514. // The map entry must exist because we populated it earlier.
  1515. assert(map_it != sources.Index.end());
  1516. cmGeneratorTarget::AllConfigSource const& acs =
  1517. sources.Sources[map_it->second];
  1518. FCInfo fcinfo(this, target, acs, configs);
  1519. fout << "\t\t\t<File\n";
  1520. std::string d = this->ConvertToXMLOutputPathSingle(source.c_str());
  1521. // Tell MS-Dev what the source is. If the compiler knows how to
  1522. // build it, then it will.
  1523. fout << "\t\t\t\tRelativePath=\"" << d << "\">\n";
  1524. if (cmCustomCommand const* command = (*sf)->GetCustomCommand()) {
  1525. this->WriteCustomRule(fout, configs, source.c_str(), *command, fcinfo);
  1526. } else if (!fcinfo.FileConfigMap.empty()) {
  1527. const char* aCompilerTool = "VCCLCompilerTool";
  1528. const char* ppLang = "CXX";
  1529. if (this->FortranProject) {
  1530. aCompilerTool = "VFFortranCompilerTool";
  1531. }
  1532. std::string const& lang = (*sf)->GetLanguage();
  1533. std::string ext = (*sf)->GetExtension();
  1534. ext = cmSystemTools::LowerCase(ext);
  1535. if (ext == "idl") {
  1536. aCompilerTool = "VCMIDLTool";
  1537. if (this->FortranProject) {
  1538. aCompilerTool = "VFMIDLTool";
  1539. }
  1540. }
  1541. if (ext == "rc") {
  1542. aCompilerTool = "VCResourceCompilerTool";
  1543. ppLang = "RC";
  1544. if (this->FortranProject) {
  1545. aCompilerTool = "VFResourceCompilerTool";
  1546. }
  1547. }
  1548. if (ext == "def") {
  1549. aCompilerTool = "VCCustomBuildTool";
  1550. if (this->FortranProject) {
  1551. aCompilerTool = "VFCustomBuildTool";
  1552. }
  1553. }
  1554. if (gg->IsMasmEnabled() && !this->FortranProject &&
  1555. lang == "ASM_MASM") {
  1556. aCompilerTool = "MASM";
  1557. }
  1558. if (acs.Kind == cmGeneratorTarget::SourceKindExternalObject) {
  1559. aCompilerTool = "VCCustomBuildTool";
  1560. }
  1561. for (std::map<std::string, cmLVS7GFileConfig>::const_iterator fci =
  1562. fcinfo.FileConfigMap.begin();
  1563. fci != fcinfo.FileConfigMap.end(); ++fci) {
  1564. cmLVS7GFileConfig const& fc = fci->second;
  1565. fout << "\t\t\t\t<FileConfiguration\n"
  1566. << "\t\t\t\t\tName=\"" << fci->first << "|"
  1567. << gg->GetPlatformName() << "\"";
  1568. if (fc.ExcludedFromBuild) {
  1569. fout << " ExcludedFromBuild=\"true\"";
  1570. }
  1571. fout << ">\n";
  1572. fout << "\t\t\t\t\t<Tool\n"
  1573. << "\t\t\t\t\tName=\"" << aCompilerTool << "\"\n";
  1574. if (!fc.CompileFlags.empty() || !fc.CompileDefs.empty() ||
  1575. !fc.CompileDefsConfig.empty()) {
  1576. Options::Tool tool = Options::Compiler;
  1577. cmVS7FlagTable const* table =
  1578. cmLocalVisualStudio7GeneratorFlagTable;
  1579. if (this->FortranProject) {
  1580. tool = Options::FortranCompiler;
  1581. table = cmLocalVisualStudio7GeneratorFortranFlagTable;
  1582. }
  1583. Options fileOptions(this, tool, table, gg->ExtraFlagTable);
  1584. fileOptions.Parse(fc.CompileFlags.c_str());
  1585. fileOptions.AddDefines(fc.CompileDefs.c_str());
  1586. fileOptions.AddDefines(fc.CompileDefsConfig.c_str());
  1587. fileOptions.OutputFlagMap(fout, "\t\t\t\t\t");
  1588. fileOptions.OutputPreprocessorDefinitions(fout, "\t\t\t\t\t", "\n",
  1589. ppLang);
  1590. }
  1591. if (!fc.AdditionalDeps.empty()) {
  1592. fout << "\t\t\t\t\tAdditionalDependencies=\"" << fc.AdditionalDeps
  1593. << "\"\n";
  1594. }
  1595. if (!fc.ObjectName.empty()) {
  1596. fout << "\t\t\t\t\tObjectFile=\"$(IntDir)/" << fc.ObjectName
  1597. << "\"\n";
  1598. }
  1599. fout << "\t\t\t\t\t/>\n"
  1600. << "\t\t\t\t</FileConfiguration>\n";
  1601. }
  1602. }
  1603. fout << "\t\t\t</File>\n";
  1604. }
  1605. }
  1606. // If the group has children with source files, write the children.
  1607. if (hasChildrenWithSources) {
  1608. fout << tmpOut.str();
  1609. }
  1610. // If the group has a name, write the footer.
  1611. if (!name.empty()) {
  1612. this->WriteVCProjEndGroup(fout);
  1613. }
  1614. return true;
  1615. }
  1616. void cmLocalVisualStudio7Generator::WriteCustomRule(
  1617. std::ostream& fout, std::vector<std::string> const& configs,
  1618. const char* source, const cmCustomCommand& command, FCInfo& fcinfo)
  1619. {
  1620. cmGlobalVisualStudio7Generator* gg =
  1621. static_cast<cmGlobalVisualStudio7Generator*>(this->GlobalGenerator);
  1622. // Write the rule for each configuration.
  1623. const char* compileTool = "VCCLCompilerTool";
  1624. if (this->FortranProject) {
  1625. compileTool = "VFCLCompilerTool";
  1626. }
  1627. const char* customTool = "VCCustomBuildTool";
  1628. if (this->FortranProject) {
  1629. customTool = "VFCustomBuildTool";
  1630. }
  1631. for (std::vector<std::string>::const_iterator i = configs.begin();
  1632. i != configs.end(); ++i) {
  1633. cmCustomCommandGenerator ccg(command, *i, this);
  1634. cmLVS7GFileConfig const& fc = fcinfo.FileConfigMap[*i];
  1635. fout << "\t\t\t\t<FileConfiguration\n";
  1636. fout << "\t\t\t\t\tName=\"" << *i << "|" << gg->GetPlatformName()
  1637. << "\">\n";
  1638. if (!fc.CompileFlags.empty()) {
  1639. fout << "\t\t\t\t\t<Tool\n"
  1640. << "\t\t\t\t\tName=\"" << compileTool << "\"\n"
  1641. << "\t\t\t\t\tAdditionalOptions=\""
  1642. << this->EscapeForXML(fc.CompileFlags.c_str()) << "\"/>\n";
  1643. }
  1644. std::string comment = this->ConstructComment(ccg);
  1645. std::string script = this->ConstructScript(ccg);
  1646. if (this->FortranProject) {
  1647. cmSystemTools::ReplaceString(script, "$(Configuration)", i->c_str());
  1648. }
  1649. /* clang-format off */
  1650. fout << "\t\t\t\t\t<Tool\n"
  1651. << "\t\t\t\t\tName=\"" << customTool << "\"\n"
  1652. << "\t\t\t\t\tDescription=\""
  1653. << this->EscapeForXML(comment.c_str()) << "\"\n"
  1654. << "\t\t\t\t\tCommandLine=\""
  1655. << this->EscapeForXML(script.c_str()) << "\"\n"
  1656. << "\t\t\t\t\tAdditionalDependencies=\"";
  1657. /* clang-format on */
  1658. if (ccg.GetDepends().empty()) {
  1659. // There are no real dependencies. Produce an artificial one to
  1660. // make sure the rule runs reliably.
  1661. if (!cmSystemTools::FileExists(source)) {
  1662. cmsys::ofstream depout(source);
  1663. depout << "Artificial dependency for a custom command.\n";
  1664. }
  1665. fout << this->ConvertToXMLOutputPath(source);
  1666. } else {
  1667. // Write out the dependencies for the rule.
  1668. for (std::vector<std::string>::const_iterator d =
  1669. ccg.GetDepends().begin();
  1670. d != ccg.GetDepends().end(); ++d) {
  1671. // Get the real name of the dependency in case it is a CMake target.
  1672. std::string dep;
  1673. if (this->GetRealDependency(d->c_str(), i->c_str(), dep)) {
  1674. fout << this->ConvertToXMLOutputPath(dep.c_str()) << ";";
  1675. }
  1676. }
  1677. }
  1678. fout << "\"\n";
  1679. fout << "\t\t\t\t\tOutputs=\"";
  1680. if (ccg.GetOutputs().empty()) {
  1681. fout << source << "_force";
  1682. } else {
  1683. // Write a rule for the output generated by this command.
  1684. const char* sep = "";
  1685. for (std::vector<std::string>::const_iterator o =
  1686. ccg.GetOutputs().begin();
  1687. o != ccg.GetOutputs().end(); ++o) {
  1688. fout << sep << this->ConvertToXMLOutputPathSingle(o->c_str());
  1689. sep = ";";
  1690. }
  1691. }
  1692. fout << "\"/>\n";
  1693. fout << "\t\t\t\t</FileConfiguration>\n";
  1694. }
  1695. }
  1696. void cmLocalVisualStudio7Generator::WriteVCProjBeginGroup(std::ostream& fout,
  1697. const char* group,
  1698. const char*)
  1699. {
  1700. /* clang-format off */
  1701. fout << "\t\t<Filter\n"
  1702. << "\t\t\tName=\"" << group << "\"\n"
  1703. << "\t\t\tFilter=\"\">\n";
  1704. /* clang-format on */
  1705. }
  1706. void cmLocalVisualStudio7Generator::WriteVCProjEndGroup(std::ostream& fout)
  1707. {
  1708. fout << "\t\t</Filter>\n";
  1709. }
  1710. // look for custom rules on a target and collect them together
  1711. void cmLocalVisualStudio7Generator::OutputTargetRules(
  1712. std::ostream& fout, const std::string& configName, cmGeneratorTarget* target,
  1713. const std::string& /*libName*/)
  1714. {
  1715. if (target->GetType() > cmStateEnums::GLOBAL_TARGET) {
  1716. return;
  1717. }
  1718. EventWriter event(this, configName, fout);
  1719. // Add pre-build event.
  1720. const char* tool =
  1721. this->FortranProject ? "VFPreBuildEventTool" : "VCPreBuildEventTool";
  1722. event.Start(tool);
  1723. event.Write(target->GetPreBuildCommands());
  1724. event.Finish();
  1725. // Add pre-link event.
  1726. tool = this->FortranProject ? "VFPreLinkEventTool" : "VCPreLinkEventTool";
  1727. event.Start(tool);
  1728. bool addedPrelink = false;
  1729. cmGeneratorTarget::ModuleDefinitionInfo const* mdi =
  1730. target->GetModuleDefinitionInfo(configName);
  1731. if (mdi && mdi->DefFileGenerated) {
  1732. addedPrelink = true;
  1733. std::vector<cmCustomCommand> commands = target->GetPreLinkCommands();
  1734. cmGlobalVisualStudioGenerator* gg =
  1735. static_cast<cmGlobalVisualStudioGenerator*>(this->GlobalGenerator);
  1736. gg->AddSymbolExportCommand(target, commands, configName);
  1737. event.Write(commands);
  1738. }
  1739. if (!addedPrelink) {
  1740. event.Write(target->GetPreLinkCommands());
  1741. }
  1742. std::unique_ptr<cmCustomCommand> pcc(
  1743. this->MaybeCreateImplibDir(target, configName, this->FortranProject));
  1744. if (pcc.get()) {
  1745. event.Write(*pcc);
  1746. }
  1747. event.Finish();
  1748. // Add post-build event.
  1749. tool =
  1750. this->FortranProject ? "VFPostBuildEventTool" : "VCPostBuildEventTool";
  1751. event.Start(tool);
  1752. event.Write(target->GetPostBuildCommands());
  1753. event.Finish();
  1754. }
  1755. void cmLocalVisualStudio7Generator::WriteProjectSCC(std::ostream& fout,
  1756. cmGeneratorTarget* target)
  1757. {
  1758. // if we have all the required Source code control tags
  1759. // then add that to the project
  1760. const char* vsProjectname = target->GetProperty("VS_SCC_PROJECTNAME");
  1761. const char* vsLocalpath = target->GetProperty("VS_SCC_LOCALPATH");
  1762. const char* vsProvider = target->GetProperty("VS_SCC_PROVIDER");
  1763. if (vsProvider && vsLocalpath && vsProjectname) {
  1764. /* clang-format off */
  1765. fout << "\tSccProjectName=\"" << vsProjectname << "\"\n"
  1766. << "\tSccLocalPath=\"" << vsLocalpath << "\"\n"
  1767. << "\tSccProvider=\"" << vsProvider << "\"\n";
  1768. /* clang-format on */
  1769. const char* vsAuxPath = target->GetProperty("VS_SCC_AUXPATH");
  1770. if (vsAuxPath) {
  1771. fout << "\tSccAuxPath=\"" << vsAuxPath << "\"\n";
  1772. }
  1773. }
  1774. }
  1775. void cmLocalVisualStudio7Generator::WriteProjectStartFortran(
  1776. std::ostream& fout, const std::string& libName, cmGeneratorTarget* target)
  1777. {
  1778. cmGlobalVisualStudio7Generator* gg =
  1779. static_cast<cmGlobalVisualStudio7Generator*>(this->GlobalGenerator);
  1780. /* clang-format off */
  1781. fout << "<?xml version=\"1.0\" encoding = \""
  1782. << gg->Encoding() << "\"?>\n"
  1783. << "<VisualStudioProject\n"
  1784. << "\tProjectCreator=\"Intel Fortran\"\n"
  1785. << "\tVersion=\"" << gg->GetIntelProjectVersion() << "\"\n";
  1786. /* clang-format on */
  1787. const char* keyword = target->GetProperty("VS_KEYWORD");
  1788. if (!keyword) {
  1789. keyword = "Console Application";
  1790. }
  1791. const char* projectType = 0;
  1792. switch (target->GetType()) {
  1793. case cmStateEnums::STATIC_LIBRARY:
  1794. projectType = "typeStaticLibrary";
  1795. if (keyword) {
  1796. keyword = "Static Library";
  1797. }
  1798. break;
  1799. case cmStateEnums::SHARED_LIBRARY:
  1800. case cmStateEnums::MODULE_LIBRARY:
  1801. projectType = "typeDynamicLibrary";
  1802. if (!keyword) {
  1803. keyword = "Dll";
  1804. }
  1805. break;
  1806. case cmStateEnums::EXECUTABLE:
  1807. if (!keyword) {
  1808. keyword = "Console Application";
  1809. }
  1810. projectType = 0;
  1811. break;
  1812. case cmStateEnums::UTILITY:
  1813. case cmStateEnums::GLOBAL_TARGET:
  1814. default:
  1815. break;
  1816. }
  1817. if (projectType) {
  1818. fout << "\tProjectType=\"" << projectType << "\"\n";
  1819. }
  1820. this->WriteProjectSCC(fout, target);
  1821. /* clang-format off */
  1822. fout<< "\tKeyword=\"" << keyword << "\">\n"
  1823. << "\tProjectGUID=\"{" << gg->GetGUID(libName.c_str()) << "}\">\n"
  1824. << "\t<Platforms>\n"
  1825. << "\t\t<Platform\n\t\t\tName=\"" << gg->GetPlatformName() << "\"/>\n"
  1826. << "\t</Platforms>\n";
  1827. /* clang-format on */
  1828. }
  1829. void cmLocalVisualStudio7Generator::WriteProjectStart(
  1830. std::ostream& fout, const std::string& libName, cmGeneratorTarget* target,
  1831. std::vector<cmSourceGroup>&)
  1832. {
  1833. if (this->FortranProject) {
  1834. this->WriteProjectStartFortran(fout, libName, target);
  1835. return;
  1836. }
  1837. cmGlobalVisualStudio7Generator* gg =
  1838. static_cast<cmGlobalVisualStudio7Generator*>(this->GlobalGenerator);
  1839. /* clang-format off */
  1840. fout << "<?xml version=\"1.0\" encoding = \""
  1841. << gg->Encoding() << "\"?>\n"
  1842. << "<VisualStudioProject\n"
  1843. << "\tProjectType=\"Visual C++\"\n";
  1844. /* clang-format on */
  1845. fout << "\tVersion=\"" << (gg->GetVersion() / 10) << ".00\"\n";
  1846. const char* projLabel = target->GetProperty("PROJECT_LABEL");
  1847. if (!projLabel) {
  1848. projLabel = libName.c_str();
  1849. }
  1850. const char* keyword = target->GetProperty("VS_KEYWORD");
  1851. if (!keyword) {
  1852. keyword = "Win32Proj";
  1853. }
  1854. fout << "\tName=\"" << projLabel << "\"\n";
  1855. fout << "\tProjectGUID=\"{" << gg->GetGUID(libName.c_str()) << "}\"\n";
  1856. this->WriteProjectSCC(fout, target);
  1857. if (const char* targetFrameworkVersion =
  1858. target->GetProperty("VS_DOTNET_TARGET_FRAMEWORK_VERSION")) {
  1859. fout << "\tTargetFrameworkVersion=\"" << targetFrameworkVersion << "\"\n";
  1860. }
  1861. /* clang-format off */
  1862. fout << "\tKeyword=\"" << keyword << "\">\n"
  1863. << "\t<Platforms>\n"
  1864. << "\t\t<Platform\n\t\t\tName=\"" << gg->GetPlatformName() << "\"/>\n"
  1865. << "\t</Platforms>\n";
  1866. /* clang-format on */
  1867. if (gg->IsMasmEnabled()) {
  1868. /* clang-format off */
  1869. fout <<
  1870. "\t<ToolFiles>\n"
  1871. "\t\t<DefaultToolFile\n"
  1872. "\t\t\tFileName=\"masm.rules\"\n"
  1873. "\t\t/>\n"
  1874. "\t</ToolFiles>\n"
  1875. ;
  1876. /* clang-format on */
  1877. }
  1878. }
  1879. void cmLocalVisualStudio7Generator::WriteVCProjFooter(
  1880. std::ostream& fout, cmGeneratorTarget* target)
  1881. {
  1882. fout << "\t<Globals>\n";
  1883. std::vector<std::string> const& props = target->GetPropertyKeys();
  1884. for (std::vector<std::string>::const_iterator i = props.begin();
  1885. i != props.end(); ++i) {
  1886. if (i->find("VS_GLOBAL_") == 0) {
  1887. std::string name = i->substr(10);
  1888. if (!name.empty()) {
  1889. /* clang-format off */
  1890. fout << "\t\t<Global\n"
  1891. << "\t\t\tName=\"" << name << "\"\n"
  1892. << "\t\t\tValue=\"" << target->GetProperty(*i) << "\"\n"
  1893. << "\t\t/>\n";
  1894. /* clang-format on */
  1895. }
  1896. }
  1897. }
  1898. fout << "\t</Globals>\n"
  1899. << "</VisualStudioProject>\n";
  1900. }
  1901. std::string cmLocalVisualStudio7GeneratorEscapeForXML(const std::string& s)
  1902. {
  1903. std::string ret = s;
  1904. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  1905. cmSystemTools::ReplaceString(ret, "\"", "&quot;");
  1906. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  1907. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  1908. cmSystemTools::ReplaceString(ret, "\n", "&#x0D;&#x0A;");
  1909. return ret;
  1910. }
  1911. std::string cmLocalVisualStudio7Generator::EscapeForXML(const std::string& s)
  1912. {
  1913. return cmLocalVisualStudio7GeneratorEscapeForXML(s);
  1914. }
  1915. std::string cmLocalVisualStudio7Generator::ConvertToXMLOutputPath(
  1916. const char* path)
  1917. {
  1918. std::string ret =
  1919. this->ConvertToOutputFormat(path, cmOutputConverter::SHELL);
  1920. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  1921. cmSystemTools::ReplaceString(ret, "\"", "&quot;");
  1922. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  1923. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  1924. return ret;
  1925. }
  1926. std::string cmLocalVisualStudio7Generator::ConvertToXMLOutputPathSingle(
  1927. const char* path)
  1928. {
  1929. std::string ret =
  1930. this->ConvertToOutputFormat(path, cmOutputConverter::SHELL);
  1931. cmSystemTools::ReplaceString(ret, "\"", "");
  1932. cmSystemTools::ReplaceString(ret, "&", "&amp;");
  1933. cmSystemTools::ReplaceString(ret, "<", "&lt;");
  1934. cmSystemTools::ReplaceString(ret, ">", "&gt;");
  1935. return ret;
  1936. }
  1937. // This class is used to parse an existing vs 7 project
  1938. // and extract the GUID
  1939. class cmVS7XMLParser : public cmXMLParser
  1940. {
  1941. public:
  1942. virtual void EndElement(const std::string& /* name */) {}
  1943. virtual void StartElement(const std::string& name, const char** atts)
  1944. {
  1945. // once the GUID is found do nothing
  1946. if (!this->GUID.empty()) {
  1947. return;
  1948. }
  1949. int i = 0;
  1950. if ("VisualStudioProject" == name) {
  1951. while (atts[i]) {
  1952. if (strcmp(atts[i], "ProjectGUID") == 0) {
  1953. if (atts[i + 1]) {
  1954. this->GUID = atts[i + 1];
  1955. if (this->GUID[0] == '{') {
  1956. // remove surrounding curly brackets
  1957. this->GUID = this->GUID.substr(1, this->GUID.size() - 2);
  1958. }
  1959. } else {
  1960. this->GUID.clear();
  1961. }
  1962. return;
  1963. }
  1964. ++i;
  1965. }
  1966. }
  1967. }
  1968. int InitializeParser()
  1969. {
  1970. int ret = cmXMLParser::InitializeParser();
  1971. if (ret == 0) {
  1972. return ret;
  1973. }
  1974. // visual studio projects have a strange encoding, but it is
  1975. // really utf-8
  1976. XML_SetEncoding(static_cast<XML_Parser>(this->Parser), "utf-8");
  1977. return 1;
  1978. }
  1979. std::string GUID;
  1980. };
  1981. void cmLocalVisualStudio7Generator::ReadAndStoreExternalGUID(
  1982. const std::string& name, const char* path)
  1983. {
  1984. cmVS7XMLParser parser;
  1985. parser.ParseFile(path);
  1986. // if we can not find a GUID then we will generate one later
  1987. if (parser.GUID.empty()) {
  1988. return;
  1989. }
  1990. std::string guidStoreName = name;
  1991. guidStoreName += "_GUID_CMAKE";
  1992. // save the GUID in the cache
  1993. this->GlobalGenerator->GetCMakeInstance()->AddCacheEntry(
  1994. guidStoreName.c_str(), parser.GUID.c_str(), "Stored GUID",
  1995. cmStateEnums::INTERNAL);
  1996. }
  1997. std::string cmLocalVisualStudio7Generator::GetTargetDirectory(
  1998. cmGeneratorTarget const* target) const
  1999. {
  2000. std::string dir;
  2001. dir += target->GetName();
  2002. dir += ".dir";
  2003. return dir;
  2004. }
  2005. static bool cmLVS7G_IsFAT(const char* dir)
  2006. {
  2007. if (dir[0] && dir[1] == ':') {
  2008. char volRoot[4] = "_:/";
  2009. volRoot[0] = dir[0];
  2010. char fsName[16];
  2011. if (GetVolumeInformationA(volRoot, 0, 0, 0, 0, 0, fsName, 16) &&
  2012. strstr(fsName, "FAT") != 0) {
  2013. return true;
  2014. }
  2015. }
  2016. return false;
  2017. }