cmGlobalVisualStudio7Generator.cxx 24 KB

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