cmGlobalVisualStudio7Generator.cxx 24 KB

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