cmGlobalVisualStudio7Generator.cxx 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "windows.h" // this must be first to define GetCurrentDirectory
  11. #include "cmGlobalVisualStudio7Generator.h"
  12. #include "cmGeneratedFileStream.h"
  13. #include "cmLocalVisualStudio7Generator.h"
  14. #include "cmMakefile.h"
  15. #include "cmUuid.h"
  16. #include "cmake.h"
  17. #include <cmsys/Encoding.hxx>
  18. #include <assert.h>
  19. static cmVS7FlagTable cmVS7ExtraFlagTable[] = {
  20. // Precompiled header and related options. Note that the
  21. // UsePrecompiledHeader entries are marked as "Continue" so that the
  22. // corresponding PrecompiledHeaderThrough entry can be found.
  23. { "UsePrecompiledHeader", "YX", "Automatically Generate", "2",
  24. cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue },
  25. { "PrecompiledHeaderThrough", "YX", "Precompiled Header Name", "",
  26. cmVS7FlagTable::UserValueRequired },
  27. { "UsePrecompiledHeader", "Yu", "Use Precompiled Header", "3",
  28. cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue },
  29. { "PrecompiledHeaderThrough", "Yu", "Precompiled Header Name", "",
  30. cmVS7FlagTable::UserValueRequired },
  31. { "WholeProgramOptimization", "LTCG", "WholeProgramOptimization", "true",
  32. 0 },
  33. // Exception handling mode. If no entries match, it will be FALSE.
  34. { "ExceptionHandling", "GX", "enable c++ exceptions", "true", 0 },
  35. { "ExceptionHandling", "EHsc", "enable c++ exceptions", "true", 0 },
  36. // The EHa option does not have an IDE setting. Let it go to false,
  37. // and have EHa passed on the command line by leaving out the table
  38. // entry.
  39. { 0, 0, 0, 0, 0 }
  40. };
  41. cmGlobalVisualStudio7Generator::cmGlobalVisualStudio7Generator(
  42. cmake* cm, const std::string& platformName)
  43. : cmGlobalVisualStudioGenerator(cm)
  44. {
  45. this->IntelProjectVersion = 0;
  46. this->DevEnvCommandInitialized = false;
  47. this->MasmEnabled = false;
  48. if (platformName.empty()) {
  49. this->DefaultPlatformName = "Win32";
  50. } else {
  51. this->DefaultPlatformName = platformName;
  52. }
  53. this->ExtraFlagTable = cmVS7ExtraFlagTable;
  54. this->Version = VS7;
  55. }
  56. cmGlobalVisualStudio7Generator::~cmGlobalVisualStudio7Generator()
  57. {
  58. free(this->IntelProjectVersion);
  59. }
  60. // Package GUID of Intel Visual Fortran plugin to VS IDE
  61. #define CM_INTEL_PLUGIN_GUID "{B68A201D-CB9B-47AF-A52F-7EEC72E217E4}"
  62. const char* cmGlobalVisualStudio7Generator::GetIntelProjectVersion()
  63. {
  64. if (!this->IntelProjectVersion) {
  65. // Compute the version of the Intel plugin to the VS IDE.
  66. // If the key does not exist then use a default guess.
  67. std::string intelVersion;
  68. std::string vskey = this->GetRegistryBase();
  69. vskey += "\\Packages\\" CM_INTEL_PLUGIN_GUID ";ProductVersion";
  70. cmSystemTools::ReadRegistryValue(vskey.c_str(), intelVersion,
  71. cmSystemTools::KeyWOW64_32);
  72. unsigned int intelVersionNumber = ~0u;
  73. sscanf(intelVersion.c_str(), "%u", &intelVersionNumber);
  74. if (intelVersionNumber >= 11) {
  75. // Default to latest known project file version.
  76. intelVersion = "11.0";
  77. } else if (intelVersionNumber == 10) {
  78. // Version 10.x actually uses 9.10 in project files!
  79. intelVersion = "9.10";
  80. } else {
  81. // Version <= 9: use ProductVersion from registry.
  82. }
  83. this->IntelProjectVersion = strdup(intelVersion.c_str());
  84. }
  85. return this->IntelProjectVersion;
  86. }
  87. void cmGlobalVisualStudio7Generator::EnableLanguage(
  88. std::vector<std::string> const& lang, cmMakefile* mf, bool optional)
  89. {
  90. mf->AddDefinition("CMAKE_GENERATOR_RC", "rc");
  91. mf->AddDefinition("CMAKE_GENERATOR_NO_COMPILER_ENV", "1");
  92. if (!mf->GetDefinition("CMAKE_CONFIGURATION_TYPES")) {
  93. mf->AddCacheDefinition(
  94. "CMAKE_CONFIGURATION_TYPES", "Debug;Release;MinSizeRel;RelWithDebInfo",
  95. "Semicolon separated list of supported configuration types, "
  96. "only supports Debug, Release, MinSizeRel, and RelWithDebInfo, "
  97. "anything else will be ignored.",
  98. cmState::STRING);
  99. }
  100. // Create list of configurations requested by user's cache, if any.
  101. this->cmGlobalGenerator::EnableLanguage(lang, mf, optional);
  102. // if this environment variable is set, then copy it to
  103. // a static cache entry. It will be used by
  104. // cmLocalGenerator::ConstructScript, to add an extra PATH
  105. // to all custom commands. This is because the VS IDE
  106. // does not use the environment it is run in, and this allows
  107. // for running commands and using dll's that the IDE environment
  108. // does not know about.
  109. const char* extraPath = cmSystemTools::GetEnv("CMAKE_MSVCIDE_RUN_PATH");
  110. if (extraPath) {
  111. mf->AddCacheDefinition("CMAKE_MSVCIDE_RUN_PATH", extraPath,
  112. "Saved environment variable CMAKE_MSVCIDE_RUN_PATH",
  113. cmState::STATIC);
  114. }
  115. }
  116. void cmGlobalVisualStudio7Generator::FindMakeProgram(cmMakefile* mf)
  117. {
  118. this->cmGlobalVisualStudioGenerator::FindMakeProgram(mf);
  119. mf->AddDefinition("CMAKE_VS_DEVENV_COMMAND",
  120. this->GetDevEnvCommand().c_str());
  121. }
  122. std::string const& cmGlobalVisualStudio7Generator::GetDevEnvCommand()
  123. {
  124. if (!this->DevEnvCommandInitialized) {
  125. this->DevEnvCommandInitialized = true;
  126. this->DevEnvCommand = this->FindDevEnvCommand();
  127. }
  128. return this->DevEnvCommand;
  129. }
  130. std::string cmGlobalVisualStudio7Generator::FindDevEnvCommand()
  131. {
  132. std::string vscmd;
  133. std::string vskey = this->GetRegistryBase() + ";InstallDir";
  134. if (cmSystemTools::ReadRegistryValue(vskey.c_str(), vscmd,
  135. cmSystemTools::KeyWOW64_32)) {
  136. cmSystemTools::ConvertToUnixSlashes(vscmd);
  137. vscmd += "/";
  138. }
  139. vscmd += "devenv.com";
  140. return vscmd;
  141. }
  142. const char* cmGlobalVisualStudio7Generator::ExternalProjectType(
  143. const char* location)
  144. {
  145. std::string extension = cmSystemTools::GetFilenameLastExtension(location);
  146. if (extension == ".vbproj") {
  147. return "F184B08F-C81C-45F6-A57F-5ABD9991F28F";
  148. } else if (extension == ".csproj") {
  149. return "FAE04EC0-301F-11D3-BF4B-00C04F79EFBC";
  150. } else if (extension == ".fsproj") {
  151. return "F2A71F9B-5D33-465A-A702-920D77279786";
  152. } else if (extension == ".vdproj") {
  153. return "54435603-DBB4-11D2-8724-00A0C9A8B90C";
  154. } else if (extension == ".dbproj") {
  155. return "C8D11400-126E-41CD-887F-60BD40844F9E";
  156. } else if (extension == ".wixproj") {
  157. return "930C7802-8A8C-48F9-8165-68863BCCD9DD";
  158. } else if (extension == ".pyproj") {
  159. return "888888A0-9F3D-457C-B088-3A5042F75D52";
  160. }
  161. return "8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942";
  162. }
  163. void cmGlobalVisualStudio7Generator::GenerateBuildCommand(
  164. std::vector<std::string>& makeCommand, const std::string& makeProgram,
  165. const std::string& projectName, const std::string& /*projectDir*/,
  166. const std::string& targetName, const std::string& config, bool /*fast*/,
  167. bool /*verbose*/, std::vector<std::string> const& makeOptions)
  168. {
  169. // Select the caller- or user-preferred make program, else devenv.
  170. std::string makeProgramSelected =
  171. this->SelectMakeProgram(makeProgram, this->GetDevEnvCommand());
  172. // Ignore the above preference if it is msbuild.
  173. // Assume any other value is either a devenv or
  174. // command-line compatible with devenv.
  175. std::string makeProgramLower = makeProgramSelected;
  176. cmSystemTools::LowerCase(makeProgramLower);
  177. if (makeProgramLower.find("msbuild") != std::string::npos) {
  178. makeProgramSelected = this->GetDevEnvCommand();
  179. }
  180. makeCommand.push_back(makeProgramSelected);
  181. makeCommand.push_back(std::string(projectName) + ".sln");
  182. std::string realTarget = targetName;
  183. bool clean = false;
  184. if (realTarget == "clean") {
  185. clean = true;
  186. realTarget = "ALL_BUILD";
  187. }
  188. if (clean) {
  189. makeCommand.push_back("/clean");
  190. } else {
  191. makeCommand.push_back("/build");
  192. }
  193. if (!config.empty()) {
  194. makeCommand.push_back(config);
  195. } else {
  196. makeCommand.push_back("Debug");
  197. }
  198. makeCommand.push_back("/project");
  199. if (!realTarget.empty()) {
  200. makeCommand.push_back(realTarget);
  201. } else {
  202. makeCommand.push_back("ALL_BUILD");
  203. }
  204. makeCommand.insert(makeCommand.end(), makeOptions.begin(),
  205. makeOptions.end());
  206. }
  207. ///! Create a local generator appropriate to this Global Generator
  208. cmLocalGenerator* cmGlobalVisualStudio7Generator::CreateLocalGenerator(
  209. cmMakefile* mf)
  210. {
  211. cmLocalVisualStudio7Generator* lg =
  212. new cmLocalVisualStudio7Generator(this, mf);
  213. return lg;
  214. }
  215. std::string const& cmGlobalVisualStudio7Generator::GetPlatformName() const
  216. {
  217. if (!this->GeneratorPlatform.empty()) {
  218. return this->GeneratorPlatform;
  219. }
  220. return this->DefaultPlatformName;
  221. }
  222. bool cmGlobalVisualStudio7Generator::SetSystemName(std::string const& s,
  223. cmMakefile* mf)
  224. {
  225. mf->AddDefinition("CMAKE_VS_INTEL_Fortran_PROJECT_VERSION",
  226. this->GetIntelProjectVersion());
  227. return this->cmGlobalVisualStudioGenerator::SetSystemName(s, mf);
  228. }
  229. bool cmGlobalVisualStudio7Generator::SetGeneratorPlatform(std::string const& p,
  230. cmMakefile* mf)
  231. {
  232. if (this->GetPlatformName() == "x64") {
  233. mf->AddDefinition("CMAKE_FORCE_WIN64", "TRUE");
  234. } else if (this->GetPlatformName() == "Itanium") {
  235. mf->AddDefinition("CMAKE_FORCE_IA64", "TRUE");
  236. }
  237. mf->AddDefinition("CMAKE_VS_PLATFORM_NAME", this->GetPlatformName().c_str());
  238. return this->cmGlobalVisualStudioGenerator::SetGeneratorPlatform(p, mf);
  239. }
  240. void cmGlobalVisualStudio7Generator::Generate()
  241. {
  242. // first do the superclass method
  243. this->cmGlobalVisualStudioGenerator::Generate();
  244. // Now write out the DSW
  245. this->OutputSLNFile();
  246. // If any solution or project files changed during the generation,
  247. // tell Visual Studio to reload them...
  248. if (!cmSystemTools::GetErrorOccuredFlag()) {
  249. this->CallVisualStudioMacro(MacroReload);
  250. }
  251. if (this->Version == VS71 && !this->CMakeInstance->GetIsInTryCompile()) {
  252. const char* cmakeWarnVS71 =
  253. this->CMakeInstance->GetState()->GetCacheEntryValue("CMAKE_WARN_VS71");
  254. if (!cmakeWarnVS71 || !cmSystemTools::IsOff(cmakeWarnVS71)) {
  255. this->CMakeInstance->IssueMessage(
  256. cmake::WARNING,
  257. "The \"Visual Studio 7 .NET 2003\" generator is deprecated "
  258. "and will be removed in a future version of CMake."
  259. "\n"
  260. "Add CMAKE_WARN_VS71=OFF to the cache to disable this warning.");
  261. }
  262. }
  263. }
  264. void cmGlobalVisualStudio7Generator::OutputSLNFile(
  265. cmLocalGenerator* root, std::vector<cmLocalGenerator*>& generators)
  266. {
  267. if (generators.empty()) {
  268. return;
  269. }
  270. this->CurrentProject = root->GetProjectName();
  271. std::string fname = root->GetCurrentBinaryDirectory();
  272. fname += "/";
  273. fname += root->GetProjectName();
  274. fname += ".sln";
  275. cmGeneratedFileStream fout(fname.c_str());
  276. fout.SetCopyIfDifferent(true);
  277. if (!fout) {
  278. return;
  279. }
  280. this->WriteSLNFile(fout, root, generators);
  281. if (fout.Close()) {
  282. this->FileReplacedDuringGenerate(fname);
  283. }
  284. }
  285. // output the SLN file
  286. void cmGlobalVisualStudio7Generator::OutputSLNFile()
  287. {
  288. std::map<std::string, std::vector<cmLocalGenerator*> >::iterator it;
  289. for (it = this->ProjectMap.begin(); it != this->ProjectMap.end(); ++it) {
  290. this->OutputSLNFile(it->second[0], it->second);
  291. }
  292. }
  293. void cmGlobalVisualStudio7Generator::WriteTargetConfigurations(
  294. std::ostream& fout, std::vector<std::string> const& configs,
  295. OrderedTargetDependSet const& projectTargets)
  296. {
  297. // loop over again and write out configurations for each target
  298. // in the solution
  299. for (OrderedTargetDependSet::const_iterator tt = projectTargets.begin();
  300. tt != projectTargets.end(); ++tt) {
  301. cmGeneratorTarget const* target = *tt;
  302. if (target->GetType() == cmState::INTERFACE_LIBRARY) {
  303. continue;
  304. }
  305. const char* expath = target->GetProperty("EXTERNAL_MSPROJECT");
  306. if (expath) {
  307. std::set<std::string> allConfigurations(configs.begin(), configs.end());
  308. const char* mapping = target->GetProperty("VS_PLATFORM_MAPPING");
  309. this->WriteProjectConfigurations(
  310. fout, target->GetName().c_str(), target->GetType(), configs,
  311. allConfigurations, mapping ? mapping : "");
  312. } else {
  313. const std::set<std::string>& configsPartOfDefaultBuild =
  314. this->IsPartOfDefaultBuild(configs, projectTargets, target);
  315. const char* vcprojName = target->GetProperty("GENERATOR_FILE_NAME");
  316. if (vcprojName) {
  317. this->WriteProjectConfigurations(fout, vcprojName, target->GetType(),
  318. configs, configsPartOfDefaultBuild);
  319. }
  320. }
  321. }
  322. }
  323. void cmGlobalVisualStudio7Generator::WriteTargetsToSolution(
  324. std::ostream& fout, cmLocalGenerator* root,
  325. OrderedTargetDependSet const& projectTargets)
  326. {
  327. VisualStudioFolders.clear();
  328. for (OrderedTargetDependSet::const_iterator tt = projectTargets.begin();
  329. tt != projectTargets.end(); ++tt) {
  330. cmGeneratorTarget const* target = *tt;
  331. if (target->GetType() == cmState::INTERFACE_LIBRARY) {
  332. continue;
  333. }
  334. bool written = false;
  335. // handle external vc project files
  336. const char* expath = target->GetProperty("EXTERNAL_MSPROJECT");
  337. if (expath) {
  338. std::string project = target->GetName();
  339. std::string location = expath;
  340. this->WriteExternalProject(fout, project.c_str(), location.c_str(),
  341. target->GetProperty("VS_PROJECT_TYPE"),
  342. target->GetUtilities());
  343. written = true;
  344. } else {
  345. const char* vcprojName = target->GetProperty("GENERATOR_FILE_NAME");
  346. if (vcprojName) {
  347. cmLocalGenerator* lg = target->GetLocalGenerator();
  348. std::string dir = lg->GetCurrentBinaryDirectory();
  349. dir = root->Convert(dir.c_str(), cmOutputConverter::START_OUTPUT);
  350. if (dir == ".") {
  351. dir = ""; // msbuild cannot handle ".\" prefix
  352. }
  353. this->WriteProject(fout, vcprojName, dir.c_str(), target);
  354. written = true;
  355. }
  356. }
  357. // Create "solution folder" information from FOLDER target property
  358. //
  359. if (written && this->UseFolderProperty()) {
  360. const char* targetFolder = target->GetProperty("FOLDER");
  361. if (targetFolder) {
  362. std::vector<cmsys::String> tokens =
  363. cmSystemTools::SplitString(targetFolder, '/', false);
  364. std::string cumulativePath = "";
  365. for (std::vector<cmsys::String>::iterator iter = tokens.begin();
  366. iter != tokens.end(); ++iter) {
  367. if (!iter->size()) {
  368. continue;
  369. }
  370. if (cumulativePath.empty()) {
  371. cumulativePath = "CMAKE_FOLDER_GUID_" + *iter;
  372. } else {
  373. VisualStudioFolders[cumulativePath].insert(cumulativePath + "/" +
  374. *iter);
  375. cumulativePath = cumulativePath + "/" + *iter;
  376. }
  377. }
  378. if (!cumulativePath.empty()) {
  379. VisualStudioFolders[cumulativePath].insert(target->GetName());
  380. }
  381. }
  382. }
  383. }
  384. }
  385. void cmGlobalVisualStudio7Generator::WriteTargetDepends(
  386. std::ostream& fout, OrderedTargetDependSet const& projectTargets)
  387. {
  388. for (OrderedTargetDependSet::const_iterator tt = projectTargets.begin();
  389. tt != projectTargets.end(); ++tt) {
  390. cmGeneratorTarget const* target = *tt;
  391. if (target->GetType() == cmState::INTERFACE_LIBRARY) {
  392. continue;
  393. }
  394. const char* vcprojName = target->GetProperty("GENERATOR_FILE_NAME");
  395. if (vcprojName) {
  396. std::string dir =
  397. target->GetLocalGenerator()->GetCurrentSourceDirectory();
  398. this->WriteProjectDepends(fout, vcprojName, dir.c_str(), target);
  399. }
  400. }
  401. }
  402. void cmGlobalVisualStudio7Generator::WriteFolders(std::ostream& fout)
  403. {
  404. const char* prefix = "CMAKE_FOLDER_GUID_";
  405. const std::string::size_type skip_prefix = strlen(prefix);
  406. std::string guidProjectTypeFolder = "2150E333-8FDC-42A3-9474-1A3956D46DE8";
  407. for (std::map<std::string, std::set<std::string> >::iterator iter =
  408. VisualStudioFolders.begin();
  409. iter != VisualStudioFolders.end(); ++iter) {
  410. std::string fullName = iter->first;
  411. std::string guid = this->GetGUID(fullName.c_str());
  412. std::replace(fullName.begin(), fullName.end(), '/', '\\');
  413. if (cmSystemTools::StringStartsWith(fullName.c_str(), prefix)) {
  414. fullName = fullName.substr(skip_prefix);
  415. }
  416. std::string nameOnly = cmSystemTools::GetFilenameName(fullName);
  417. fout << "Project(\"{" << guidProjectTypeFolder << "}\") = \"" << nameOnly
  418. << "\", \"" << fullName << "\", \"{" << guid << "}\"\nEndProject\n";
  419. }
  420. }
  421. void cmGlobalVisualStudio7Generator::WriteFoldersContent(std::ostream& fout)
  422. {
  423. for (std::map<std::string, std::set<std::string> >::iterator iter =
  424. VisualStudioFolders.begin();
  425. iter != VisualStudioFolders.end(); ++iter) {
  426. std::string key(iter->first);
  427. std::string guidParent(this->GetGUID(key.c_str()));
  428. for (std::set<std::string>::iterator it = iter->second.begin();
  429. it != iter->second.end(); ++it) {
  430. std::string value(*it);
  431. std::string guid(this->GetGUID(value.c_str()));
  432. fout << "\t\t{" << guid << "} = {" << guidParent << "}\n";
  433. }
  434. }
  435. }
  436. std::string cmGlobalVisualStudio7Generator::ConvertToSolutionPath(
  437. const char* path)
  438. {
  439. // Convert to backslashes. Do not use ConvertToOutputPath because
  440. // we will add quoting ourselves, and we know these projects always
  441. // use windows slashes.
  442. std::string d = path;
  443. std::string::size_type pos = 0;
  444. while ((pos = d.find('/', pos)) != d.npos) {
  445. d[pos++] = '\\';
  446. }
  447. return d;
  448. }
  449. void cmGlobalVisualStudio7Generator::WriteSLNGlobalSections(
  450. std::ostream& fout, cmLocalGenerator* root)
  451. {
  452. bool extensibilityGlobalsOverridden = false;
  453. bool extensibilityAddInsOverridden = false;
  454. const std::vector<std::string> propKeys =
  455. root->GetMakefile()->GetPropertyKeys();
  456. for (std::vector<std::string>::const_iterator it = propKeys.begin();
  457. it != propKeys.end(); ++it) {
  458. if (it->find("VS_GLOBAL_SECTION_") == 0) {
  459. std::string sectionType;
  460. std::string name = it->substr(18);
  461. if (name.find("PRE_") == 0) {
  462. name = name.substr(4);
  463. sectionType = "preSolution";
  464. } else if (name.find("POST_") == 0) {
  465. name = name.substr(5);
  466. sectionType = "postSolution";
  467. } else
  468. continue;
  469. if (!name.empty()) {
  470. if (name == "ExtensibilityGlobals" && sectionType == "postSolution")
  471. extensibilityGlobalsOverridden = true;
  472. else if (name == "ExtensibilityAddIns" &&
  473. sectionType == "postSolution")
  474. extensibilityAddInsOverridden = true;
  475. fout << "\tGlobalSection(" << name << ") = " << sectionType << "\n";
  476. std::vector<std::string> keyValuePairs;
  477. cmSystemTools::ExpandListArgument(
  478. root->GetMakefile()->GetProperty(it->c_str()), keyValuePairs);
  479. for (std::vector<std::string>::const_iterator itPair =
  480. keyValuePairs.begin();
  481. itPair != keyValuePairs.end(); ++itPair) {
  482. const std::string::size_type posEqual = itPair->find('=');
  483. if (posEqual != std::string::npos) {
  484. const std::string key =
  485. cmSystemTools::TrimWhitespace(itPair->substr(0, posEqual));
  486. const std::string value =
  487. cmSystemTools::TrimWhitespace(itPair->substr(posEqual + 1));
  488. fout << "\t\t" << key << " = " << value << "\n";
  489. }
  490. }
  491. fout << "\tEndGlobalSection\n";
  492. }
  493. }
  494. }
  495. if (!extensibilityGlobalsOverridden)
  496. fout << "\tGlobalSection(ExtensibilityGlobals) = postSolution\n"
  497. << "\tEndGlobalSection\n";
  498. if (!extensibilityAddInsOverridden)
  499. fout << "\tGlobalSection(ExtensibilityAddIns) = postSolution\n"
  500. << "\tEndGlobalSection\n";
  501. }
  502. // Standard end of dsw file
  503. void cmGlobalVisualStudio7Generator::WriteSLNFooter(std::ostream& fout)
  504. {
  505. fout << "EndGlobal\n";
  506. }
  507. std::string cmGlobalVisualStudio7Generator::WriteUtilityDepend(
  508. cmGeneratorTarget const* target)
  509. {
  510. std::vector<std::string> configs;
  511. target->Target->GetMakefile()->GetConfigurations(configs);
  512. std::string pname = target->GetName();
  513. pname += "_UTILITY";
  514. std::string fname = target->GetLocalGenerator()->GetCurrentBinaryDirectory();
  515. fname += "/";
  516. fname += pname;
  517. fname += ".vcproj";
  518. cmGeneratedFileStream fout(fname.c_str());
  519. fout.SetCopyIfDifferent(true);
  520. std::string guid = this->GetGUID(pname.c_str());
  521. /* clang-format off */
  522. fout <<
  523. "<?xml version=\"1.0\" encoding = \""
  524. << this->Encoding() << "\"?>\n"
  525. "<VisualStudioProject\n"
  526. "\tProjectType=\"Visual C++\"\n"
  527. "\tVersion=\"" << this->GetIDEVersion() << "0\"\n"
  528. "\tName=\"" << pname << "\"\n"
  529. "\tProjectGUID=\"{" << guid << "}\"\n"
  530. "\tKeyword=\"Win32Proj\">\n"
  531. "\t<Platforms><Platform Name=\"Win32\"/></Platforms>\n"
  532. "\t<Configurations>\n"
  533. ;
  534. /* clang-format on */
  535. for (std::vector<std::string>::iterator i = configs.begin();
  536. i != configs.end(); ++i) {
  537. /* clang-format off */
  538. fout <<
  539. "\t\t<Configuration\n"
  540. "\t\t\tName=\"" << *i << "|Win32\"\n"
  541. "\t\t\tOutputDirectory=\"" << *i << "\"\n"
  542. "\t\t\tIntermediateDirectory=\"" << pname << ".dir\\" << *i << "\"\n"
  543. "\t\t\tConfigurationType=\"10\"\n"
  544. "\t\t\tUseOfMFC=\"0\"\n"
  545. "\t\t\tATLMinimizesCRunTimeLibraryUsage=\"FALSE\"\n"
  546. "\t\t\tCharacterSet=\"2\">\n"
  547. "\t\t</Configuration>\n"
  548. ;
  549. /* clang-format on */
  550. }
  551. /* clang-format off */
  552. fout <<
  553. "\t</Configurations>\n"
  554. "\t<Files></Files>\n"
  555. "\t<Globals></Globals>\n"
  556. "</VisualStudioProject>\n"
  557. ;
  558. /* clang-format on */
  559. if (fout.Close()) {
  560. this->FileReplacedDuringGenerate(fname);
  561. }
  562. return pname;
  563. }
  564. std::string cmGlobalVisualStudio7Generator::GetGUID(std::string const& name)
  565. {
  566. std::string const& guidStoreName = name + "_GUID_CMAKE";
  567. if (const char* storedGUID =
  568. this->CMakeInstance->GetCacheDefinition(guidStoreName.c_str())) {
  569. return std::string(storedGUID);
  570. }
  571. // Compute a GUID that is deterministic but unique to the build tree.
  572. std::string input = this->CMakeInstance->GetState()->GetBinaryDirectory();
  573. input += "|";
  574. input += name;
  575. cmUuid uuidGenerator;
  576. std::vector<unsigned char> uuidNamespace;
  577. uuidGenerator.StringToBinary("ee30c4be-5192-4fb0-b335-722a2dffe760",
  578. uuidNamespace);
  579. std::string guid = uuidGenerator.FromMd5(uuidNamespace, input);
  580. return cmSystemTools::UpperCase(guid);
  581. }
  582. void cmGlobalVisualStudio7Generator::AppendDirectoryForConfig(
  583. const std::string& prefix, const std::string& config,
  584. const std::string& suffix, std::string& dir)
  585. {
  586. if (!config.empty()) {
  587. dir += prefix;
  588. dir += config;
  589. dir += suffix;
  590. }
  591. }
  592. std::set<std::string> cmGlobalVisualStudio7Generator::IsPartOfDefaultBuild(
  593. std::vector<std::string> const& configs,
  594. OrderedTargetDependSet const& projectTargets,
  595. cmGeneratorTarget const* target)
  596. {
  597. std::set<std::string> activeConfigs;
  598. // if it is a utilitiy target then only make it part of the
  599. // default build if another target depends on it
  600. int type = target->GetType();
  601. if (type == cmState::GLOBAL_TARGET) {
  602. // check if INSTALL target is part of default build
  603. if (target->GetName() == "INSTALL") {
  604. // inspect CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD properties
  605. for (std::vector<std::string>::const_iterator i = configs.begin();
  606. i != configs.end(); ++i) {
  607. const char* propertyValue =
  608. target->Target->GetMakefile()->GetDefinition(
  609. "CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD");
  610. cmGeneratorExpression ge;
  611. CM_AUTO_PTR<cmCompiledGeneratorExpression> cge =
  612. ge.Parse(propertyValue);
  613. if (cmSystemTools::IsOn(
  614. cge->Evaluate(target->GetLocalGenerator(), *i))) {
  615. activeConfigs.insert(*i);
  616. }
  617. }
  618. }
  619. return activeConfigs;
  620. }
  621. if (type == cmState::UTILITY &&
  622. !this->IsDependedOn(projectTargets, target)) {
  623. return activeConfigs;
  624. }
  625. // inspect EXCLUDE_FROM_DEFAULT_BUILD[_<CONFIG>] properties
  626. for (std::vector<std::string>::const_iterator i = configs.begin();
  627. i != configs.end(); ++i) {
  628. const char* propertyValue =
  629. target->GetFeature("EXCLUDE_FROM_DEFAULT_BUILD", i->c_str());
  630. if (cmSystemTools::IsOff(propertyValue)) {
  631. activeConfigs.insert(*i);
  632. }
  633. }
  634. return activeConfigs;
  635. }
  636. bool cmGlobalVisualStudio7Generator::IsDependedOn(
  637. OrderedTargetDependSet const& projectTargets, cmGeneratorTarget const* gtIn)
  638. {
  639. for (OrderedTargetDependSet::const_iterator l = projectTargets.begin();
  640. l != projectTargets.end(); ++l) {
  641. TargetDependSet const& tgtdeps = this->GetTargetDirectDepends(*l);
  642. if (tgtdeps.count(gtIn)) {
  643. return true;
  644. }
  645. }
  646. return false;
  647. }
  648. std::string cmGlobalVisualStudio7Generator::Encoding()
  649. {
  650. std::ostringstream encoding;
  651. #ifdef CMAKE_ENCODING_UTF8
  652. encoding << "UTF-8";
  653. #else
  654. encoding << "Windows-1252";
  655. #endif
  656. return encoding.str();
  657. }