cmLocalVisualStudio7Generator.cxx 71 KB

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