cmGlobalVisualStudio7Generator.cxx 24 KB

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