cmLocalVisualStudio7Generator.cxx 70 KB

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