cmLocalVisualStudio7Generator.cxx 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906
  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.AddSourceFile(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. cmTargets &tgts = this->Makefile->GetTargets();
  102. for(cmTargets::iterator l = tgts.begin();
  103. l != tgts.end(); l++)
  104. {
  105. // Add a rule to regenerate the build system when the target
  106. // specification source changes.
  107. const char* suppRegenRule =
  108. this->Makefile->GetDefinition("CMAKE_SUPPRESS_REGENERATION");
  109. if (!cmSystemTools::IsOn(suppRegenRule) &&
  110. (strcmp(l->first.c_str(), CMAKE_CHECK_BUILD_SYSTEM_TARGET) != 0))
  111. {
  112. this->AddVCProjBuildRule(l->second);
  113. }
  114. }
  115. for(cmTargets::iterator l = tgts.begin();
  116. l != tgts.end(); l++)
  117. {
  118. // INCLUDE_EXTERNAL_MSPROJECT command only affects the workspace
  119. // so don't build a projectfile for it
  120. if (strncmp(l->first.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) != 0)
  121. {
  122. this->CreateSingleVCProj(l->first.c_str(),l->second);
  123. }
  124. }
  125. }
  126. void cmLocalVisualStudio7Generator
  127. ::CreateSingleVCProj(const char *lname, cmTarget &target)
  128. {
  129. // add to the list of projects
  130. std::string pname = lname;
  131. target.SetProperty("GENERATOR_FILE_NAME",lname);
  132. // create the dsp.cmake file
  133. std::string fname;
  134. fname = this->Makefile->GetStartOutputDirectory();
  135. fname += "/";
  136. fname += lname;
  137. fname += ".vcproj";
  138. // save the name of the real dsp file
  139. std::string realVCProj = fname;
  140. fname += ".cmake";
  141. std::ofstream fout(fname.c_str());
  142. if(!fout)
  143. {
  144. cmSystemTools::Error("Error Writing ", fname.c_str());
  145. }
  146. this->WriteVCProjFile(fout,lname,target);
  147. fout.close();
  148. // if the dsp file has changed, then write it.
  149. cmSystemTools::CopyFileIfDifferent(fname.c_str(), realVCProj.c_str());
  150. }
  151. void cmLocalVisualStudio7Generator::AddVCProjBuildRule(cmTarget& tgt)
  152. {
  153. std::string dspname = tgt.GetName();
  154. dspname += ".vcproj.cmake";
  155. const char* dsprule =
  156. this->Makefile->GetRequiredDefinition("CMAKE_COMMAND");
  157. cmCustomCommandLine commandLine;
  158. commandLine.push_back(dsprule);
  159. std::string makefileIn = this->Makefile->GetStartDirectory();
  160. makefileIn += "/";
  161. makefileIn += "CMakeLists.txt";
  162. makefileIn = cmSystemTools::CollapseFullPath(makefileIn.c_str());
  163. std::string comment = "Building Custom Rule ";
  164. comment += makefileIn;
  165. std::string args;
  166. args = "-H";
  167. args += this->Convert(this->Makefile->GetHomeDirectory(),
  168. START_OUTPUT, UNCHANGED, true);
  169. commandLine.push_back(args);
  170. args = "-B";
  171. args +=
  172. this->Convert(this->Makefile->GetHomeOutputDirectory(),
  173. START_OUTPUT, UNCHANGED, true);
  174. commandLine.push_back(args);
  175. std::string configFile =
  176. this->Makefile->GetRequiredDefinition("CMAKE_ROOT");
  177. configFile += "/Templates/CMakeWindowsSystemConfig.cmake";
  178. std::vector<std::string> listFiles = this->Makefile->GetListFiles();
  179. bool found = false;
  180. for(std::vector<std::string>::iterator i = listFiles.begin();
  181. i != listFiles.end(); ++i)
  182. {
  183. if(*i == configFile)
  184. {
  185. found = true;
  186. }
  187. }
  188. if(!found)
  189. {
  190. listFiles.push_back(configFile);
  191. }
  192. cmCustomCommandLines commandLines;
  193. commandLines.push_back(commandLine);
  194. const char* no_working_directory = 0;
  195. this->Makefile->AddCustomCommandToOutput(dspname.c_str(), listFiles,
  196. makefileIn.c_str(), commandLines,
  197. comment.c_str(),
  198. no_working_directory, true);
  199. if(cmSourceFile* file = this->Makefile->GetSource(makefileIn.c_str()))
  200. {
  201. tgt.AddSourceFile(file);
  202. }
  203. else
  204. {
  205. cmSystemTools::Error("Error adding rule for ", makefileIn.c_str());
  206. }
  207. }
  208. void cmLocalVisualStudio7Generator::WriteConfigurations(std::ostream& fout,
  209. const char *libName,
  210. cmTarget &target)
  211. {
  212. std::vector<std::string> *configs =
  213. static_cast<cmGlobalVisualStudio7Generator *>
  214. (this->GlobalGenerator)->GetConfigurations();
  215. fout << "\t<Configurations>\n";
  216. for( std::vector<std::string>::iterator i = configs->begin();
  217. i != configs->end(); ++i)
  218. {
  219. this->WriteConfiguration(fout, i->c_str(), libName, target);
  220. }
  221. fout << "\t</Configurations>\n";
  222. }
  223. // fill the table here currently the comment field is not used for
  224. // anything other than documentation NOTE: Make sure the longer
  225. // commandFlag comes FIRST!
  226. cmVS7FlagTable cmLocalVisualStudio7GeneratorFlagTable[] =
  227. {
  228. // option flags (some flags map to the same option)
  229. {"BasicRuntimeChecks", "GZ", "Stack frame checks", "1", 0},
  230. {"BasicRuntimeChecks", "RTCsu",
  231. "Both stack and uninitialized checks", "3", 0},
  232. {"BasicRuntimeChecks", "RTCs", "Stack frame checks", "1", 0},
  233. {"BasicRuntimeChecks", "RTCu", "Uninitialized Variables ", "2", 0},
  234. {"BasicRuntimeChecks", "RTC1",
  235. "Both stack and uninitialized checks", "3", 0},
  236. {"DebugInformationFormat", "Z7", "debug format", "1", 0},
  237. {"DebugInformationFormat", "Zd", "debug format", "2", 0},
  238. {"DebugInformationFormat", "Zi", "debug format", "3", 0},
  239. {"DebugInformationFormat", "ZI", "debug format", "4", 0},
  240. {"EnableEnhancedInstructionSet", "arch:SSE2",
  241. "Use sse2 instructions", "2", 0},
  242. {"EnableEnhancedInstructionSet", "arch:SSE",
  243. "Use sse instructions", "1", 0},
  244. {"FavorSizeOrSpeed", "Ot", "Favor fast code", "1", 0},
  245. {"FavorSizeOrSpeed", "Os", "Favor small code", "2", 0},
  246. {"CompileAs", "TC", "Compile as c code", "1", 0},
  247. {"CompileAs", "TP", "Compile as c++ code", "2", 0},
  248. {"Optimization", "Od", "Non Debug", "0", 0},
  249. {"Optimization", "O1", "Min Size", "1", 0},
  250. {"Optimization", "O2", "Max Speed", "2", 0},
  251. {"Optimization", "Ox", "Max Optimization", "3", 0},
  252. {"OptimizeForProcessor", "GB", "Blended processor mode", "0", 0},
  253. {"OptimizeForProcessor", "G5", "Pentium", "1", 0},
  254. {"OptimizeForProcessor", "G6", "PPro PII PIII", "2", 0},
  255. {"OptimizeForProcessor", "G7", "Pentium 4 or Athlon", "3", 0},
  256. {"InlineFunctionExpansion", "Ob0", "no inlines", "0", 0},
  257. {"InlineFunctionExpansion", "Ob1", "when inline keyword", "1", 0},
  258. {"InlineFunctionExpansion", "Ob2", "any time you can inline", "2", 0},
  259. {"RuntimeLibrary", "MTd", "Multithreded debug", "1", 0},
  260. {"RuntimeLibrary", "MT", "Multithreded", "0", 0},
  261. {"RuntimeLibrary", "MDd", "Multithreded dll debug", "3", 0},
  262. {"RuntimeLibrary", "MD", "Multithreded dll", "2", 0},
  263. {"RuntimeLibrary", "MLd", "Sinble Thread debug", "5", 0},
  264. {"RuntimeLibrary", "ML", "Sinble Thread", "4", 0},
  265. {"StructMemberAlignment", "Zp16", "struct align 16 byte ", "5", 0},
  266. {"StructMemberAlignment", "Zp1", "struct align 1 byte ", "1", 0},
  267. {"StructMemberAlignment", "Zp2", "struct align 2 byte ", "2", 0},
  268. {"StructMemberAlignment", "Zp4", "struct align 4 byte ", "3", 0},
  269. {"StructMemberAlignment", "Zp8", "struct align 8 byte ", "4", 0},
  270. {"WarningLevel", "W1", "Warning level", "1", 0},
  271. {"WarningLevel", "W2", "Warning level", "2", 0},
  272. {"WarningLevel", "W3", "Warning level", "3", 0},
  273. {"WarningLevel", "W4", "Warning level", "4", 0},
  274. // Precompiled header and related options. Note that the
  275. // UsePrecompiledHeader entries are marked as "Continue" so that the
  276. // corresponding PrecompiledHeaderThrough entry can be found.
  277. {"UsePrecompiledHeader", "Yc", "Create Precompiled Header", "1",
  278. cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue},
  279. {"PrecompiledHeaderThrough", "Yc", "Precompiled Header Name", "",
  280. cmVS7FlagTable::UserValueRequired},
  281. {"PrecompiledHeaderFile", "Fp", "Generated Precompiled Header", "",
  282. cmVS7FlagTable::UserValue},
  283. // The YX and Yu options are in a per-global-generator table because
  284. // their values differ based on the VS IDE version.
  285. {"ForcedIncludeFiles", "FI", "Forced include files", "",
  286. cmVS7FlagTable::UserValueRequired},
  287. // boolean flags
  288. {"BufferSecurityCheck", "GS", "Buffer security check", "TRUE", 0},
  289. {"EnableFibreSafeOptimization", "GT", "OmitFramePointers", "TRUE", 0},
  290. {"EnableFunctionLevelLinking", "Gy",
  291. "EnableFunctionLevelLinking", "TRUE", 0},
  292. {"EnableIntrinsicFunctions", "Oi", "EnableIntrinsicFunctions", "TRUE", 0},
  293. {"ExceptionHandling", "EHsc", "enable c++ exceptions", "TRUE", 0},
  294. {"ExceptionHandling", "EHa", "enable c++ exceptions", "2", 0},
  295. {"ExceptionHandling", "GX", "enable c++ exceptions", "TRUE", 0},
  296. {"GlobalOptimizations", "Og", "Global Optimize", "TRUE", 0},
  297. {"ImproveFloatingPointConsistency", "Op",
  298. "ImproveFloatingPointConsistency", "TRUE", 0},
  299. {"MinimalRebuild", "Gm", "minimal rebuild", "TRUE", 0},
  300. {"OmitFramePointers", "Oy", "OmitFramePointers", "TRUE", 0},
  301. {"OptimizeForWindowsApplication", "GA", "Optimize for windows", "TRUE", 0},
  302. {"RuntimeTypeInfo", "GR",
  303. "Turn on Run time type information for c++", "TRUE", 0},
  304. {"SmallerTypeCheck", "RTCc", "smaller type check", "TRUE", 0},
  305. {"SuppressStartupBanner", "nologo", "SuppressStartupBanner", "TRUE", 0},
  306. {"WarnAsError", "WX", "Treat warnings as errors", "TRUE", 0},
  307. {0,0,0,0,0}
  308. };
  309. cmVS7FlagTable cmLocalVisualStudio7GeneratorLinkFlagTable[] =
  310. {
  311. // option flags (some flags map to the same option)
  312. {"GenerateManifest", "MANIFEST:NO",
  313. "disable manifest generation", "FALSE", 0},
  314. {"GenerateManifest", "MANIFEST", "enable manifest generation", "TRUE", 0},
  315. {"LinkIncremental", "INCREMENTAL:NO", "link incremental", "1", 0},
  316. {"LinkIncremental", "INCREMENTAL:YES", "link incremental", "2", 0},
  317. {"IgnoreDefaultLibraryNames", "NODEFAULTLIB:", "default libs to ignore", "",
  318. cmVS7FlagTable::UserValue},
  319. {"IgnoreAllDefaultLibraries", "NODEFAULTLIB", "ignore all default libs",
  320. "TRUE", 0},
  321. {0,0,0,0,0}
  322. };
  323. //----------------------------------------------------------------------------
  324. class cmLocalVisualStudio7GeneratorOptions
  325. {
  326. public:
  327. // Construct an options table for a given tool.
  328. enum Tool
  329. {
  330. Compiler,
  331. Linker
  332. };
  333. cmLocalVisualStudio7GeneratorOptions(Tool tool,
  334. cmVS7FlagTable const* extraTable = 0);
  335. // Store options from command line flags.
  336. void Parse(const char* flags);
  337. // Fix the ExceptionHandling option to default to off.
  338. void FixExceptionHandlingDefault();
  339. // Store options for verbose builds.
  340. void SetVerboseMakefile(bool verbose);
  341. // Store definitions and flags.
  342. void AddDefine(const std::string& define);
  343. void AddFlag(const char* flag, const char* value);
  344. // Check for specific options.
  345. bool UsingUnicode();
  346. // Write options to output.
  347. void OutputPreprocessorDefinitions(std::ostream& fout,
  348. const char* prefix,
  349. const char* suffix);
  350. void OutputFlagMap(std::ostream& fout, const char* indent);
  351. void OutputAdditionalOptions(std::ostream& fout,
  352. const char* prefix,
  353. const char* suffix);
  354. private:
  355. // create a map of xml tags to the values they should have in the output
  356. // for example, "BufferSecurityCheck" = "TRUE"
  357. // first fill this table with the values for the configuration
  358. // Debug, Release, etc,
  359. // Then parse the command line flags specified in CMAKE_CXX_FLAGS
  360. // and CMAKE_C_FLAGS
  361. // and overwrite or add new values to this map
  362. std::map<cmStdString, cmStdString> FlagMap;
  363. // Preprocessor definitions.
  364. std::vector<cmStdString> Defines;
  365. // Unrecognized flags that get no special handling.
  366. cmStdString FlagString;
  367. bool DoingDefine;
  368. cmVS7FlagTable const* FlagTable;
  369. cmVS7FlagTable const* ExtraFlagTable;
  370. void HandleFlag(const char* flag);
  371. bool CheckFlagTable(cmVS7FlagTable const* table, const char* flag,
  372. bool& flag_handled);
  373. };
  374. void cmLocalVisualStudio7Generator::WriteConfiguration(std::ostream& fout,
  375. const char* configName,
  376. const char *libName,
  377. cmTarget &target)
  378. {
  379. const char* mfcFlag = this->Makefile->GetDefinition("CMAKE_MFC_FLAG");
  380. if(!mfcFlag)
  381. {
  382. mfcFlag = "0";
  383. }
  384. fout << "\t\t<Configuration\n"
  385. << "\t\t\tName=\"" << configName << "|" << this->PlatformName << "\"\n"
  386. << "\t\t\tOutputDirectory=\"" << configName << "\"\n";
  387. // This is an internal type to Visual Studio, it seems that:
  388. // 4 == static library
  389. // 2 == dll
  390. // 1 == executable
  391. // 10 == utility
  392. const char* configType = "10";
  393. switch(target.GetType())
  394. {
  395. case cmTarget::STATIC_LIBRARY:
  396. configType = "4";
  397. break;
  398. case cmTarget::SHARED_LIBRARY:
  399. case cmTarget::MODULE_LIBRARY:
  400. configType = "2";
  401. break;
  402. case cmTarget::EXECUTABLE:
  403. configType = "1";
  404. break;
  405. case cmTarget::UTILITY:
  406. case cmTarget::GLOBAL_TARGET:
  407. configType = "10";
  408. default:
  409. break;
  410. }
  411. std::string flags;
  412. if(strcmp(configType, "10") != 0)
  413. {
  414. const char* linkLanguage =
  415. target.GetLinkerLanguage(this->GetGlobalGenerator());
  416. if(!linkLanguage)
  417. {
  418. cmSystemTools::Error
  419. ("CMake can not determine linker language for target:",
  420. target.GetName());
  421. return;
  422. }
  423. if(strcmp(linkLanguage, "C") == 0 || strcmp(linkLanguage, "CXX") == 0)
  424. {
  425. std::string baseFlagVar = "CMAKE_";
  426. baseFlagVar += linkLanguage;
  427. baseFlagVar += "_FLAGS";
  428. flags = this->Makefile->GetRequiredDefinition(baseFlagVar.c_str());
  429. std::string flagVar = baseFlagVar + std::string("_") +
  430. cmSystemTools::UpperCase(configName);
  431. flags += " ";
  432. flags += this->Makefile->GetRequiredDefinition(flagVar.c_str());
  433. }
  434. // set the correct language
  435. if(strcmp(linkLanguage, "C") == 0)
  436. {
  437. flags += " /TC ";
  438. }
  439. if(strcmp(linkLanguage, "CXX") == 0)
  440. {
  441. flags += " /TP ";
  442. }
  443. }
  444. // Add the target-specific flags.
  445. if(const char* targetFlags = target.GetProperty("COMPILE_FLAGS"))
  446. {
  447. flags += " ";
  448. flags += targetFlags;
  449. }
  450. // Get preprocessor definitions for this directory.
  451. std::string defineFlags = this->Makefile->GetDefineFlags();
  452. // Construct a set of build options for this target.
  453. Options targetOptions(Options::Compiler, this->ExtraFlagTable);
  454. targetOptions.FixExceptionHandlingDefault();
  455. targetOptions.Parse(flags.c_str());
  456. targetOptions.Parse(defineFlags.c_str());
  457. targetOptions.SetVerboseMakefile(
  458. this->Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE"));
  459. // Add a definition for the configuration name.
  460. std::string configDefine = "CMAKE_INTDIR=\"";
  461. configDefine += configName;
  462. configDefine += "\"";
  463. targetOptions.AddDefine(configDefine);
  464. // Add the export symbol definition for shared library objects.
  465. if(const char* exportMacro = target.GetExportMacro())
  466. {
  467. targetOptions.AddDefine(exportMacro);
  468. }
  469. // The intermediate directory name consists of a directory for the
  470. // target and a subdirectory for the configuration name.
  471. std::string intermediateDir = this->GetTargetDirectory(target);
  472. intermediateDir += "/";
  473. intermediateDir += configName;
  474. fout << "\t\t\tIntermediateDirectory=\""
  475. << this->ConvertToXMLOutputPath(intermediateDir.c_str())
  476. << "\"\n"
  477. << "\t\t\tConfigurationType=\"" << configType << "\"\n"
  478. << "\t\t\tUseOfMFC=\"" << mfcFlag << "\"\n"
  479. << "\t\t\tATLMinimizesCRunTimeLibraryUsage=\"FALSE\"\n";
  480. // If unicode is enabled change the character set to unicode, if not
  481. // then default to MBCS.
  482. if(targetOptions.UsingUnicode())
  483. {
  484. fout << "\t\t\tCharacterSet=\"1\">\n";
  485. }
  486. else
  487. {
  488. fout << "\t\t\tCharacterSet=\"2\">\n";
  489. }
  490. fout << "\t\t\t<Tool\n"
  491. << "\t\t\t\tName=\"VCCLCompilerTool\"\n";
  492. targetOptions.OutputAdditionalOptions(fout, "\t\t\t\t", "\n");
  493. fout << "\t\t\t\tAdditionalIncludeDirectories=\"";
  494. std::vector<std::string> includes;
  495. this->GetIncludeDirectories(includes);
  496. std::vector<std::string>::iterator i = includes.begin();
  497. for(;i != includes.end(); ++i)
  498. {
  499. std::string ipath = this->ConvertToXMLOutputPath(i->c_str());
  500. fout << ipath << ";";
  501. }
  502. fout << "\"\n";
  503. targetOptions.OutputFlagMap(fout, "\t\t\t\t");
  504. targetOptions.OutputPreprocessorDefinitions(fout, "\t\t\t\t", "\n");
  505. fout << "\t\t\t\tAssemblerListingLocation=\"" << configName << "\"\n";
  506. fout << "\t\t\t\tObjectFile=\"$(IntDir)\\\"\n";
  507. if(target.GetType() == cmTarget::EXECUTABLE ||
  508. target.GetType() == cmTarget::STATIC_LIBRARY ||
  509. target.GetType() == cmTarget::SHARED_LIBRARY ||
  510. target.GetType() == cmTarget::MODULE_LIBRARY)
  511. {
  512. // We need to specify a program database file name even for
  513. // non-debug configurations because VS still creates .idb files.
  514. fout << "\t\t\t\tProgramDataBaseFileName=\""
  515. << target.GetDirectory(configName) << "/"
  516. << target.GetPDBName(configName) << "\"\n";
  517. }
  518. fout << "/>\n"; // end of <Tool Name=VCCLCompilerTool
  519. fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCCustomBuildTool\"/>\n";
  520. fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCResourceCompilerTool\"\n"
  521. << "\t\t\t\tAdditionalIncludeDirectories=\"";
  522. for(i = includes.begin();i != includes.end(); ++i)
  523. {
  524. std::string ipath = this->ConvertToXMLOutputPath(i->c_str());
  525. fout << ipath << ";";
  526. }
  527. // add the -D flags to the RC tool
  528. fout << "\"";
  529. targetOptions.OutputPreprocessorDefinitions(fout, "\n\t\t\t\t", "");
  530. fout << "/>\n";
  531. fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCMIDLTool\"\n";
  532. targetOptions.OutputPreprocessorDefinitions(fout, "\t\t\t\t", "\n");
  533. fout << "\t\t\t\tMkTypLibCompatible=\"FALSE\"\n";
  534. if( this->PlatformName == "x64" )
  535. {
  536. fout << "\t\t\t\tTargetEnvironment=\"3\"\n";
  537. }
  538. else if( this->PlatformName == "ia64" )
  539. {
  540. fout << "\t\t\t\tTargetEnvironment=\"2\"\n";
  541. }
  542. else
  543. {
  544. fout << "\t\t\t\tTargetEnvironment=\"1\"\n";
  545. }
  546. fout << "\t\t\t\tGenerateStublessProxies=\"TRUE\"\n";
  547. fout << "\t\t\t\tTypeLibraryName=\"$(InputName).tlb\"\n";
  548. fout << "\t\t\t\tOutputDirectory=\"$(IntDir)\"\n";
  549. fout << "\t\t\t\tHeaderFileName=\"$(InputName).h\"\n";
  550. fout << "\t\t\t\tDLLDataFileName=\"\"\n";
  551. fout << "\t\t\t\tInterfaceIdentifierFileName=\"$(InputName)_i.c\"\n";
  552. fout << "\t\t\t\tProxyFileName=\"$(InputName)_p.c\"/>\n";
  553. // end of <Tool Name=VCMIDLTool
  554. // If we are building a version 8 project file, add a flag telling the
  555. // manifest tool to use a workaround for FAT32 file systems, which can cause
  556. // an empty manifest to be embedded into the resulting executable.
  557. // See CMake bug #2617.
  558. if ( this->Version == 8 )
  559. {
  560. fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCManifestTool\"\n"
  561. << "\t\t\t\tUseFAT32Workaround=\"true\"\n"
  562. << "\t\t\t/>\n";
  563. }
  564. this->OutputTargetRules(fout, configName, target, libName);
  565. this->OutputBuildTool(fout, configName, target);
  566. fout << "\t\t</Configuration>\n";
  567. }
  568. //----------------------------------------------------------------------------
  569. std::string
  570. cmLocalVisualStudio7Generator
  571. ::GetBuildTypeLinkerFlags(std::string rootLinkerFlags, const char* configName)
  572. {
  573. std::string configTypeUpper = cmSystemTools::UpperCase(configName);
  574. std::string extraLinkOptionsBuildTypeDef =
  575. rootLinkerFlags + "_" + configTypeUpper;
  576. std::string extraLinkOptionsBuildType =
  577. this->Makefile->GetRequiredDefinition
  578. (extraLinkOptionsBuildTypeDef.c_str());
  579. return extraLinkOptionsBuildType;
  580. }
  581. void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout,
  582. const char* configName,
  583. cmTarget &target)
  584. {
  585. std::string temp;
  586. std::string extraLinkOptions;
  587. if(target.GetType() == cmTarget::EXECUTABLE)
  588. {
  589. extraLinkOptions =
  590. this->Makefile->GetRequiredDefinition("CMAKE_EXE_LINKER_FLAGS")
  591. + std::string(" ")
  592. + GetBuildTypeLinkerFlags("CMAKE_EXE_LINKER_FLAGS", configName);
  593. }
  594. if(target.GetType() == cmTarget::SHARED_LIBRARY)
  595. {
  596. extraLinkOptions =
  597. this->Makefile->GetRequiredDefinition("CMAKE_SHARED_LINKER_FLAGS")
  598. + std::string(" ")
  599. + GetBuildTypeLinkerFlags("CMAKE_SHARED_LINKER_FLAGS", configName);
  600. }
  601. if(target.GetType() == cmTarget::MODULE_LIBRARY)
  602. {
  603. extraLinkOptions =
  604. this->Makefile->GetRequiredDefinition("CMAKE_MODULE_LINKER_FLAGS")
  605. + std::string(" ")
  606. + GetBuildTypeLinkerFlags("CMAKE_MODULE_LINKER_FLAGS", configName);
  607. }
  608. const char* targetLinkFlags = target.GetProperty("LINK_FLAGS");
  609. if(targetLinkFlags)
  610. {
  611. extraLinkOptions += " ";
  612. extraLinkOptions += targetLinkFlags;
  613. }
  614. std::string configTypeUpper = cmSystemTools::UpperCase(configName);
  615. std::string linkFlagsConfig = "LINK_FLAGS_";
  616. linkFlagsConfig += configTypeUpper;
  617. targetLinkFlags = target.GetProperty(linkFlagsConfig.c_str());
  618. if(targetLinkFlags)
  619. {
  620. extraLinkOptions += " ";
  621. extraLinkOptions += targetLinkFlags;
  622. }
  623. Options linkOptions(Options::Linker);
  624. linkOptions.Parse(extraLinkOptions.c_str());
  625. switch(target.GetType())
  626. {
  627. case cmTarget::STATIC_LIBRARY:
  628. {
  629. std::string targetNameFull = target.GetFullName(configName);
  630. std::string libpath = target.GetDirectory(configName);
  631. libpath += "/";
  632. libpath += targetNameFull;
  633. fout << "\t\t\t<Tool\n"
  634. << "\t\t\t\tName=\"VCLibrarianTool\"\n";
  635. if(const char* libflags = target.GetProperty("STATIC_LIBRARY_FLAGS"))
  636. {
  637. fout << "\t\t\t\tAdditionalOptions=\"" << libflags << "\"\n";
  638. }
  639. fout << "\t\t\t\tOutputFile=\""
  640. << this->ConvertToXMLOutputPathSingle(libpath.c_str()) << "\"/>\n";
  641. break;
  642. }
  643. case cmTarget::SHARED_LIBRARY:
  644. case cmTarget::MODULE_LIBRARY:
  645. {
  646. std::string targetName;
  647. std::string targetNameSO;
  648. std::string targetNameFull;
  649. std::string targetNameImport;
  650. std::string targetNamePDB;
  651. target.GetLibraryNames(targetName, targetNameSO, targetNameFull,
  652. targetNameImport, targetNamePDB, configName);
  653. // Compute the link library and directory information.
  654. std::vector<cmStdString> linkLibs;
  655. std::vector<cmStdString> linkDirs;
  656. this->ComputeLinkInformation(target, configName, linkLibs, linkDirs);
  657. // Get the language to use for linking.
  658. const char* linkLanguage =
  659. target.GetLinkerLanguage(this->GetGlobalGenerator());
  660. if(!linkLanguage)
  661. {
  662. cmSystemTools::Error
  663. ("CMake can not determine linker language for target:",
  664. target.GetName());
  665. return;
  666. }
  667. // Compute the variable name to lookup standard libraries for this
  668. // language.
  669. std::string standardLibsVar = "CMAKE_";
  670. standardLibsVar += linkLanguage;
  671. standardLibsVar += "_STANDARD_LIBRARIES";
  672. fout << "\t\t\t<Tool\n"
  673. << "\t\t\t\tName=\"VCLinkerTool\"\n";
  674. linkOptions.OutputAdditionalOptions(fout, "\t\t\t\t", "\n");
  675. // Use the NOINHERIT macro to avoid getting VS project default
  676. // libraries which may be set by the user to something bad.
  677. fout << "\t\t\t\tAdditionalDependencies=\"$(NOINHERIT) "
  678. << this->Makefile->GetSafeDefinition(standardLibsVar.c_str())
  679. << " ";
  680. this->OutputLibraries(fout, linkLibs);
  681. fout << "\"\n";
  682. temp = target.GetDirectory(configName);
  683. temp += "/";
  684. temp += targetNameFull;
  685. fout << "\t\t\t\tOutputFile=\""
  686. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  687. this->WriteTargetVersionAttribute(fout, target);
  688. linkOptions.OutputFlagMap(fout, "\t\t\t\t");
  689. fout << "\t\t\t\tAdditionalLibraryDirectories=\"";
  690. this->OutputLibraryDirectories(fout, linkDirs);
  691. fout << "\"\n";
  692. this->OutputModuleDefinitionFile(fout, target);
  693. temp = target.GetDirectory(configName);
  694. temp += "/";
  695. temp += targetNamePDB;
  696. fout << "\t\t\t\tProgramDataBaseFile=\"" <<
  697. this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  698. if(strcmp(configName, "Debug") == 0
  699. || strcmp(configName, "RelWithDebInfo") == 0)
  700. {
  701. fout << "\t\t\t\tGenerateDebugInformation=\"TRUE\"\n";
  702. }
  703. std::string stackVar = "CMAKE_";
  704. stackVar += linkLanguage;
  705. stackVar += "_STACK_SIZE";
  706. const char* stackVal = this->Makefile->GetDefinition(stackVar.c_str());
  707. if(stackVal)
  708. {
  709. fout << "\t\t\t\tStackReserveSize=\"" << stackVal << "\"\n";
  710. }
  711. temp = target.GetDirectory(configName, true);
  712. temp += "/";
  713. temp += targetNameImport;
  714. fout << "\t\t\t\tImportLibrary=\""
  715. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"/>\n";
  716. }
  717. break;
  718. case cmTarget::EXECUTABLE:
  719. {
  720. std::string targetName;
  721. std::string targetNameFull;
  722. std::string targetNameImport;
  723. std::string targetNamePDB;
  724. target.GetExecutableNames(targetName, targetNameFull,
  725. targetNameImport, targetNamePDB, configName);
  726. // Compute the link library and directory information.
  727. std::vector<cmStdString> linkLibs;
  728. std::vector<cmStdString> linkDirs;
  729. this->ComputeLinkInformation(target, configName, linkLibs, linkDirs);
  730. // Get the language to use for linking.
  731. const char* linkLanguage =
  732. target.GetLinkerLanguage(this->GetGlobalGenerator());
  733. if(!linkLanguage)
  734. {
  735. cmSystemTools::Error
  736. ("CMake can not determine linker language for target:",
  737. target.GetName());
  738. return;
  739. }
  740. // Compute the variable name to lookup standard libraries for this
  741. // language.
  742. std::string standardLibsVar = "CMAKE_";
  743. standardLibsVar += linkLanguage;
  744. standardLibsVar += "_STANDARD_LIBRARIES";
  745. fout << "\t\t\t<Tool\n"
  746. << "\t\t\t\tName=\"VCLinkerTool\"\n";
  747. linkOptions.OutputAdditionalOptions(fout, "\t\t\t\t", "\n");
  748. // Use the NOINHERIT macro to avoid getting VS project default
  749. // libraries which may be set by the user to something bad.
  750. fout << "\t\t\t\tAdditionalDependencies=\"$(NOINHERIT) "
  751. << this->Makefile->GetSafeDefinition(standardLibsVar.c_str())
  752. << " ";
  753. this->OutputLibraries(fout, linkLibs);
  754. fout << "\"\n";
  755. temp = target.GetDirectory(configName);
  756. temp += "/";
  757. temp += targetNameFull;
  758. fout << "\t\t\t\tOutputFile=\""
  759. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
  760. this->WriteTargetVersionAttribute(fout, target);
  761. linkOptions.OutputFlagMap(fout, "\t\t\t\t");
  762. fout << "\t\t\t\tAdditionalLibraryDirectories=\"";
  763. this->OutputLibraryDirectories(fout, linkDirs);
  764. fout << "\"\n";
  765. fout << "\t\t\t\tProgramDataBaseFile=\""
  766. << target.GetDirectory(configName) << "/" << targetNamePDB
  767. << "\"\n";
  768. if(strcmp(configName, "Debug") == 0
  769. || strcmp(configName, "RelWithDebInfo") == 0)
  770. {
  771. fout << "\t\t\t\tGenerateDebugInformation=\"TRUE\"\n";
  772. }
  773. if ( target.GetPropertyAsBool("WIN32_EXECUTABLE") )
  774. {
  775. fout << "\t\t\t\tSubSystem=\"2\"\n";
  776. }
  777. else
  778. {
  779. fout << "\t\t\t\tSubSystem=\"1\"\n";
  780. }
  781. std::string stackVar = "CMAKE_";
  782. stackVar += linkLanguage;
  783. stackVar += "_STACK_SIZE";
  784. const char* stackVal = this->Makefile->GetDefinition(stackVar.c_str());
  785. if(stackVal)
  786. {
  787. fout << "\t\t\t\tStackReserveSize=\"" << stackVal << "\"";
  788. }
  789. temp = target.GetDirectory(configName, true);
  790. temp += "/";
  791. temp += targetNameImport;
  792. fout << "\t\t\t\tImportLibrary=\""
  793. << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"/>\n";
  794. break;
  795. }
  796. case cmTarget::UTILITY:
  797. case cmTarget::GLOBAL_TARGET:
  798. break;
  799. }
  800. }
  801. //----------------------------------------------------------------------------
  802. void
  803. cmLocalVisualStudio7Generator
  804. ::WriteTargetVersionAttribute(std::ostream& fout, cmTarget& target)
  805. {
  806. int major;
  807. int minor;
  808. target.GetTargetVersion(major, minor);
  809. fout << "\t\t\t\tVersion=\"" << major << "." << minor << "\"\n";
  810. }
  811. void cmLocalVisualStudio7Generator
  812. ::OutputModuleDefinitionFile(std::ostream& fout,
  813. cmTarget &target)
  814. {
  815. std::vector<cmSourceFile*> const& classes = target.GetSourceFiles();
  816. for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
  817. i != classes.end(); i++)
  818. {
  819. cmSourceFile* sf = *i;
  820. if(cmSystemTools::UpperCase(sf->GetExtension()) == "DEF")
  821. {
  822. fout << "\t\t\t\tModuleDefinitionFile=\""
  823. << this->ConvertToXMLOutputPath(sf->GetFullPath().c_str())
  824. << "\"\n";
  825. return;
  826. }
  827. }
  828. }
  829. //----------------------------------------------------------------------------
  830. void
  831. cmLocalVisualStudio7Generator
  832. ::OutputLibraries(std::ostream& fout,
  833. std::vector<cmStdString> const& libs)
  834. {
  835. for(std::vector<cmStdString>::const_iterator l = libs.begin();
  836. l != libs.end(); ++l)
  837. {
  838. fout << this->ConvertToXMLOutputPath(l->c_str()) << " ";
  839. }
  840. }
  841. //----------------------------------------------------------------------------
  842. void
  843. cmLocalVisualStudio7Generator
  844. ::OutputLibraryDirectories(std::ostream& fout,
  845. std::vector<cmStdString> const& dirs)
  846. {
  847. const char* comma = "";
  848. for(std::vector<cmStdString>::const_iterator d = dirs.begin();
  849. d != dirs.end(); ++d)
  850. {
  851. // Remove any trailing slash and skip empty paths.
  852. std::string dir = *d;
  853. if(dir[dir.size()-1] == '/')
  854. {
  855. dir = dir.substr(0, dir.size()-1);
  856. }
  857. if(dir.empty())
  858. {
  859. continue;
  860. }
  861. // Switch to a relative path specification if it is shorter.
  862. if(cmSystemTools::FileIsFullPath(dir.c_str()))
  863. {
  864. std::string rel = this->Convert(dir.c_str(), START_OUTPUT, UNCHANGED);
  865. if(rel.size() < dir.size())
  866. {
  867. dir = rel;
  868. }
  869. }
  870. // First search a configuration-specific subdirectory and then the
  871. // original directory.
  872. fout << comma << this->ConvertToXMLOutputPath((dir+"/$(OutDir)").c_str())
  873. << "," << this->ConvertToXMLOutputPath(dir.c_str());
  874. comma = ",";
  875. }
  876. }
  877. void cmLocalVisualStudio7Generator::WriteVCProjFile(std::ostream& fout,
  878. const char *libName,
  879. cmTarget &target)
  880. {
  881. // get the configurations
  882. std::vector<std::string> *configs =
  883. static_cast<cmGlobalVisualStudio7Generator *>
  884. (this->GlobalGenerator)->GetConfigurations();
  885. // trace the visual studio dependencies
  886. std::string name = libName;
  887. name += ".vcproj.cmake";
  888. // We may be modifying the source groups temporarily, so make a copy.
  889. std::vector<cmSourceGroup> sourceGroups = this->Makefile->GetSourceGroups();
  890. // get the classes from the source lists then add them to the groups
  891. std::vector<cmSourceFile*>const & classes = target.GetSourceFiles();
  892. for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
  893. i != classes.end(); i++)
  894. {
  895. // Add the file to the list of sources.
  896. std::string source = (*i)->GetFullPath();
  897. if(cmSystemTools::UpperCase((*i)->GetExtension()) == "DEF")
  898. {
  899. this->ModuleDefinitionFile = (*i)->GetFullPath();
  900. }
  901. cmSourceGroup& sourceGroup =
  902. this->Makefile->FindSourceGroup(source.c_str(), sourceGroups);
  903. sourceGroup.AssignSource(*i);
  904. }
  905. // Compute which sources need unique object computation.
  906. this->ComputeObjectNameRequirements(sourceGroups);
  907. // open the project
  908. this->WriteProjectStart(fout, libName, target, sourceGroups);
  909. // write the configuration information
  910. this->WriteConfigurations(fout, libName, target);
  911. fout << "\t<Files>\n";
  912. // Loop through every source group.
  913. for(unsigned int i = 0; i < sourceGroups.size(); ++i)
  914. {
  915. cmSourceGroup sg = sourceGroups[i];
  916. this->WriteGroup(&sg, target, fout, libName, configs);
  917. }
  918. //}
  919. fout << "\t</Files>\n";
  920. // Write the VCProj file's footer.
  921. this->WriteVCProjFooter(fout);
  922. }
  923. void cmLocalVisualStudio7Generator
  924. ::WriteGroup(const cmSourceGroup *sg, cmTarget target,
  925. std::ostream &fout, const char *libName,
  926. std::vector<std::string> *configs)
  927. {
  928. const std::vector<const cmSourceFile *> &sourceFiles =
  929. sg->GetSourceFiles();
  930. // If the group is empty, don't write it at all.
  931. if(sourceFiles.empty() && sg->GetGroupChildren().empty())
  932. {
  933. return;
  934. }
  935. // If the group has a name, write the header.
  936. std::string name = sg->GetName();
  937. if(name != "")
  938. {
  939. this->WriteVCProjBeginGroup(fout, name.c_str(), "");
  940. }
  941. // Compute the maximum length of a configuration name.
  942. std::string::size_type config_len_max = 0;
  943. for(std::vector<std::string>::iterator i = configs->begin();
  944. i != configs->end(); ++i)
  945. {
  946. if(i->size() > config_len_max)
  947. {
  948. config_len_max = i->size();
  949. }
  950. }
  951. // Compute the maximum length of the full path to the intermediate
  952. // files directory for any configuration. This is used to construct
  953. // object file names that do not produce paths that are too long.
  954. std::string::size_type dir_len = 0;
  955. dir_len += strlen(this->Makefile->GetCurrentOutputDirectory());
  956. dir_len += 1;
  957. dir_len += this->GetTargetDirectory(target).size();
  958. dir_len += 1;
  959. dir_len += config_len_max;
  960. dir_len += 1;
  961. // Loop through each source in the source group.
  962. std::string objectName;
  963. for(std::vector<const cmSourceFile *>::const_iterator sf =
  964. sourceFiles.begin(); sf != sourceFiles.end(); ++sf)
  965. {
  966. std::string source = (*sf)->GetFullPath();
  967. const cmCustomCommand *command = (*sf)->GetCustomCommand();
  968. std::string compileFlags;
  969. std::string additionalDeps;
  970. if(this->NeedObjectName.find(*sf) != this->NeedObjectName.end())
  971. {
  972. objectName = this->GetObjectFileNameWithoutTarget(*(*sf), dir_len);
  973. }
  974. else
  975. {
  976. objectName = "";
  977. }
  978. // Add per-source flags.
  979. const char* cflags = (*sf)->GetProperty("COMPILE_FLAGS");
  980. if(cflags)
  981. {
  982. compileFlags += " ";
  983. compileFlags += cflags;
  984. }
  985. const char* lang =
  986. this->GlobalGenerator->GetLanguageFromExtension
  987. ((*sf)->GetExtension().c_str());
  988. const char* sourceLang = this->GetSourceFileLanguage(*(*sf));
  989. const char* linkLanguage = target.GetLinkerLanguage
  990. (this->GetGlobalGenerator());
  991. bool needForceLang = false;
  992. // source file does not match its extension language
  993. if(lang && sourceLang && strcmp(lang, sourceLang) != 0)
  994. {
  995. needForceLang = true;
  996. lang = sourceLang;
  997. }
  998. // If lang is set, the compiler will generate code automatically.
  999. // If HEADER_FILE_ONLY is set, we must suppress this generation in
  1000. // the project file
  1001. bool excludedFromBuild =
  1002. (lang && (*sf)->GetPropertyAsBool("HEADER_FILE_ONLY"));
  1003. // if the source file does not match the linker language
  1004. // then force c or c++
  1005. if(needForceLang || (linkLanguage && lang
  1006. && strcmp(lang, linkLanguage) != 0))
  1007. {
  1008. if(strcmp(lang, "CXX") == 0)
  1009. {
  1010. // force a C++ file type
  1011. compileFlags += " /TP ";
  1012. }
  1013. else if(strcmp(lang, "C") == 0)
  1014. {
  1015. // force to c
  1016. compileFlags += " /TC ";
  1017. }
  1018. }
  1019. // Check for extra object-file dependencies.
  1020. const char* deps = (*sf)->GetProperty("OBJECT_DEPENDS");
  1021. if(deps)
  1022. {
  1023. std::vector<std::string> depends;
  1024. cmSystemTools::ExpandListArgument(deps, depends);
  1025. if(!depends.empty())
  1026. {
  1027. std::vector<std::string>::iterator i = depends.begin();
  1028. additionalDeps = this->ConvertToXMLOutputPath(i->c_str());
  1029. for(++i;i != depends.end(); ++i)
  1030. {
  1031. additionalDeps += ";";
  1032. additionalDeps += this->ConvertToXMLOutputPath(i->c_str());
  1033. }
  1034. }
  1035. }
  1036. if (source != libName || target.GetType() == cmTarget::UTILITY ||
  1037. target.GetType() == cmTarget::GLOBAL_TARGET )
  1038. {
  1039. fout << "\t\t\t<File\n";
  1040. std::string d = this->ConvertToXMLOutputPathSingle(source.c_str());
  1041. // Tell MS-Dev what the source is. If the compiler knows how to
  1042. // build it, then it will.
  1043. fout << "\t\t\t\tRelativePath=\"" << d << "\">\n";
  1044. if (command)
  1045. {
  1046. const char* flags = compileFlags.size() ? compileFlags.c_str(): 0;
  1047. this->WriteCustomRule(fout, source.c_str(), *command, flags);
  1048. }
  1049. else if(compileFlags.size() || additionalDeps.length()
  1050. || objectName.size() || excludedFromBuild)
  1051. {
  1052. const char* aCompilerTool = "VCCLCompilerTool";
  1053. std::string ext = (*sf)->GetExtension();
  1054. ext = cmSystemTools::LowerCase(ext);
  1055. if(ext == "idl")
  1056. {
  1057. aCompilerTool = "VCMIDLTool";
  1058. }
  1059. if(ext == "rc")
  1060. {
  1061. aCompilerTool = "VCResourceCompilerTool";
  1062. }
  1063. if(ext == "def")
  1064. {
  1065. aCompilerTool = "VCCustomBuildTool";
  1066. }
  1067. for(std::vector<std::string>::iterator i = configs->begin();
  1068. i != configs->end(); ++i)
  1069. {
  1070. fout << "\t\t\t\t<FileConfiguration\n"
  1071. << "\t\t\t\t\tName=\"" << *i
  1072. << "|" << this->PlatformName << "\"";
  1073. if(excludedFromBuild)
  1074. {
  1075. fout << " ExcludedFromBuild=\"true\"";
  1076. }
  1077. fout << ">\n";
  1078. fout << "\t\t\t\t\t<Tool\n"
  1079. << "\t\t\t\t\tName=\"" << aCompilerTool << "\"\n";
  1080. if(!compileFlags.empty())
  1081. {
  1082. Options fileOptions(Options::Compiler, this->ExtraFlagTable);
  1083. fileOptions.Parse(compileFlags.c_str());
  1084. fileOptions.OutputAdditionalOptions(fout, "\t\t\t\t\t", "\n");
  1085. fileOptions.OutputFlagMap(fout, "\t\t\t\t\t");
  1086. fileOptions.OutputPreprocessorDefinitions(fout,
  1087. "\t\t\t\t\t", "\n");
  1088. }
  1089. if(additionalDeps.length())
  1090. {
  1091. fout << "\t\t\t\t\tAdditionalDependencies=\""
  1092. << additionalDeps.c_str() << "\"\n";
  1093. }
  1094. if(objectName.size())
  1095. {
  1096. fout << "\t\t\t\t\tObjectFile=\"$(IntDir)/"
  1097. << objectName.c_str() << "\"\n";
  1098. }
  1099. fout << "\t\t\t\t\t/>\n"
  1100. << "\t\t\t\t</FileConfiguration>\n";
  1101. }
  1102. }
  1103. fout << "\t\t\t</File>\n";
  1104. }
  1105. }
  1106. std::vector<cmSourceGroup> children = sg->GetGroupChildren();
  1107. for(unsigned int i=0;i<children.size();++i)
  1108. {
  1109. this->WriteGroup(&children[i], target, fout, libName, configs);
  1110. }
  1111. // If the group has a name, write the footer.
  1112. if(name != "")
  1113. {
  1114. this->WriteVCProjEndGroup(fout);
  1115. }
  1116. }
  1117. void cmLocalVisualStudio7Generator::
  1118. WriteCustomRule(std::ostream& fout,
  1119. const char* source,
  1120. const cmCustomCommand& command,
  1121. const char* compileFlags)
  1122. {
  1123. std::string comment = this->ConstructComment(command);
  1124. // Write the rule for each configuration.
  1125. std::vector<std::string>::iterator i;
  1126. std::vector<std::string> *configs =
  1127. static_cast<cmGlobalVisualStudio7Generator *>
  1128. (this->GlobalGenerator)->GetConfigurations();
  1129. for(i = configs->begin(); i != configs->end(); ++i)
  1130. {
  1131. fout << "\t\t\t\t<FileConfiguration\n";
  1132. fout << "\t\t\t\t\tName=\"" << *i << "|" << this->PlatformName << "\">\n";
  1133. if(compileFlags)
  1134. {
  1135. fout << "\t\t\t\t\t<Tool\n"
  1136. << "\t\t\t\t\tName=\"VCCLCompilerTool\"\n"
  1137. << "\t\t\t\t\tAdditionalOptions=\""
  1138. << this->EscapeForXML(compileFlags) << "\"/>\n";
  1139. }
  1140. std::string script =
  1141. this->ConstructScript(command.GetCommandLines(),
  1142. command.GetWorkingDirectory(),
  1143. i->c_str(),
  1144. command.GetEscapeOldStyle(),
  1145. command.GetEscapeAllowMakeVars());
  1146. fout << "\t\t\t\t\t<Tool\n"
  1147. << "\t\t\t\t\tName=\"VCCustomBuildTool\"\n"
  1148. << "\t\t\t\t\tDescription=\""
  1149. << this->EscapeForXML(comment.c_str()) << "\"\n"
  1150. << "\t\t\t\t\tCommandLine=\""
  1151. << this->EscapeForXML(script.c_str()) << "\"\n"
  1152. << "\t\t\t\t\tAdditionalDependencies=\"";
  1153. if(command.GetDepends().empty())
  1154. {
  1155. // There are no real dependencies. Produce an artificial one to
  1156. // make sure the rule runs reliably.
  1157. if(!cmSystemTools::FileExists(source))
  1158. {
  1159. std::ofstream depout(source);
  1160. depout << "Artificial dependency for a custom command.\n";
  1161. }
  1162. fout << this->ConvertToXMLOutputPath(source);
  1163. }
  1164. else
  1165. {
  1166. // Write out the dependencies for the rule.
  1167. for(std::vector<std::string>::const_iterator d =
  1168. command.GetDepends().begin();
  1169. d != command.GetDepends().end();
  1170. ++d)
  1171. {
  1172. // Get the real name of the dependency in case it is a CMake target.
  1173. std::string dep = this->GetRealDependency(d->c_str(), i->c_str());
  1174. fout << this->ConvertToXMLOutputPath(dep.c_str())
  1175. << ";";
  1176. }
  1177. }
  1178. fout << "\"\n";
  1179. fout << "\t\t\t\t\tOutputs=\"";
  1180. if(command.GetOutputs().empty())
  1181. {
  1182. fout << source << "_force";
  1183. }
  1184. else
  1185. {
  1186. // Write a rule for the output generated by this command.
  1187. const char* sep = "";
  1188. for(std::vector<std::string>::const_iterator o =
  1189. 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. }