cmGlobalVisualStudio7Generator.cxx 24 KB

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