cmLocalVisualStudio7Generator.cxx 62 KB

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