cmLocalVisualStudio7Generator.cxx 69 KB

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