cmLocalVisualStudio7Generator.cxx 57 KB

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