cmLocalVisualStudio7Generator.cxx 66 KB

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