cmLocalVisualStudio7Generator.cxx 80 KB

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