cmLocalVisualStudio7Generator.cxx 67 KB

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