cmGlobalVisualStudio7Generator.cxx 24 KB

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