cmLocalVisualStudio7Generator.cxx 79 KB

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