cmGlobalVisualStudio7Generator.cxx 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  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->IntelProjectVersion = 0;
  43. this->DevEnvCommandInitialized = false;
  44. this->MasmEnabled = false;
  45. this->NasmEnabled = false;
  46. this->ExtraFlagTable = cmVS7ExtraFlagTable;
  47. }
  48. cmGlobalVisualStudio7Generator::~cmGlobalVisualStudio7Generator()
  49. {
  50. free(this->IntelProjectVersion);
  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 char* cmGlobalVisualStudio7Generator::GetIntelProjectVersion()
  55. {
  56. if (!this->IntelProjectVersion) {
  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.c_str(), 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 = strdup(intelVersion.c_str());
  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->cmGlobalGenerator::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",
  114. this->GetDevEnvCommand().c_str());
  115. return true;
  116. }
  117. std::string const& cmGlobalVisualStudio7Generator::GetDevEnvCommand()
  118. {
  119. if (!this->DevEnvCommandInitialized) {
  120. this->DevEnvCommandInitialized = true;
  121. this->DevEnvCommand = this->FindDevEnvCommand();
  122. }
  123. return this->DevEnvCommand;
  124. }
  125. std::string cmGlobalVisualStudio7Generator::FindDevEnvCommand()
  126. {
  127. std::string vscmd;
  128. std::string vskey;
  129. // Search in standard location.
  130. vskey = this->GetRegistryBase() + ";InstallDir";
  131. if (cmSystemTools::ReadRegistryValue(vskey.c_str(), vscmd,
  132. cmSystemTools::KeyWOW64_32)) {
  133. cmSystemTools::ConvertToUnixSlashes(vscmd);
  134. vscmd += "/devenv.com";
  135. if (cmSystemTools::FileExists(vscmd, true)) {
  136. return vscmd;
  137. }
  138. }
  139. // Search where VS15Preview places it.
  140. vskey = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\SxS\\VS7;";
  141. vskey += this->GetIDEVersion();
  142. if (cmSystemTools::ReadRegistryValue(vskey.c_str(), vscmd,
  143. cmSystemTools::KeyWOW64_32)) {
  144. cmSystemTools::ConvertToUnixSlashes(vscmd);
  145. vscmd += "/Common7/IDE/devenv.com";
  146. if (cmSystemTools::FileExists(vscmd, true)) {
  147. return vscmd;
  148. }
  149. }
  150. vscmd = "devenv.com";
  151. return vscmd;
  152. }
  153. const char* cmGlobalVisualStudio7Generator::ExternalProjectType(
  154. const char* location)
  155. {
  156. std::string extension = cmSystemTools::GetFilenameLastExtension(location);
  157. if (extension == ".vbproj") {
  158. return "F184B08F-C81C-45F6-A57F-5ABD9991F28F";
  159. } else if (extension == ".csproj") {
  160. return "FAE04EC0-301F-11D3-BF4B-00C04F79EFBC";
  161. } else if (extension == ".fsproj") {
  162. return "F2A71F9B-5D33-465A-A702-920D77279786";
  163. } else if (extension == ".vdproj") {
  164. return "54435603-DBB4-11D2-8724-00A0C9A8B90C";
  165. } else if (extension == ".dbproj") {
  166. return "C8D11400-126E-41CD-887F-60BD40844F9E";
  167. } else if (extension == ".wixproj") {
  168. return "930C7802-8A8C-48F9-8165-68863BCCD9DD";
  169. } else if (extension == ".pyproj") {
  170. return "888888A0-9F3D-457C-B088-3A5042F75D52";
  171. }
  172. return "8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942";
  173. }
  174. std::vector<cmGlobalGenerator::GeneratedMakeCommand>
  175. cmGlobalVisualStudio7Generator::GenerateBuildCommand(
  176. const std::string& makeProgram, const std::string& projectName,
  177. const std::string& /*projectDir*/,
  178. std::vector<std::string> const& targetNames, const std::string& config,
  179. bool /*fast*/, int /*jobs*/, bool /*verbose*/,
  180. std::vector<std::string> const& makeOptions)
  181. {
  182. // Select the caller- or user-preferred make program, else devenv.
  183. std::string makeProgramSelected =
  184. this->SelectMakeProgram(makeProgram, this->GetDevEnvCommand());
  185. // Ignore the above preference if it is msbuild.
  186. // Assume any other value is either a devenv or
  187. // command-line compatible with devenv.
  188. std::string makeProgramLower = makeProgramSelected;
  189. cmSystemTools::LowerCase(makeProgramLower);
  190. if (makeProgramLower.find("msbuild") != std::string::npos) {
  191. makeProgramSelected = this->GetDevEnvCommand();
  192. }
  193. // Workaround to convince VCExpress.exe to produce output.
  194. const bool requiresOutputForward =
  195. (makeProgramLower.find("vcexpress") != std::string::npos);
  196. std::vector<GeneratedMakeCommand> makeCommands;
  197. std::vector<std::string> realTargetNames = targetNames;
  198. if (targetNames.empty() ||
  199. ((targetNames.size() == 1) && targetNames.front().empty())) {
  200. realTargetNames = { "ALL_BUILD" };
  201. }
  202. for (const auto& tname : realTargetNames) {
  203. std::string realTarget;
  204. if (!tname.empty()) {
  205. realTarget = tname;
  206. } else {
  207. continue;
  208. }
  209. bool clean = false;
  210. if (realTarget == "clean") {
  211. clean = true;
  212. realTarget = "ALL_BUILD";
  213. }
  214. GeneratedMakeCommand makeCommand;
  215. makeCommand.RequiresOutputForward = requiresOutputForward;
  216. makeCommand.Add(makeProgramSelected);
  217. makeCommand.Add(std::string(projectName) + ".sln");
  218. makeCommand.Add((clean ? "/clean" : "/build"));
  219. makeCommand.Add((config.empty() ? "Debug" : config));
  220. makeCommand.Add("/project");
  221. makeCommand.Add(realTarget);
  222. makeCommand.Add(makeOptions.begin(), makeOptions.end());
  223. makeCommands.emplace_back(std::move(makeCommand));
  224. }
  225. return makeCommands;
  226. }
  227. ///! Create a local generator appropriate to this Global Generator
  228. cmLocalGenerator* cmGlobalVisualStudio7Generator::CreateLocalGenerator(
  229. cmMakefile* mf)
  230. {
  231. cmLocalVisualStudio7Generator* lg =
  232. new cmLocalVisualStudio7Generator(this, mf);
  233. return lg;
  234. }
  235. #if defined(CMAKE_BUILD_WITH_CMAKE)
  236. Json::Value cmGlobalVisualStudio7Generator::GetJson() const
  237. {
  238. Json::Value generator = this->cmGlobalVisualStudioGenerator::GetJson();
  239. generator["platform"] = this->GetPlatformName();
  240. return generator;
  241. }
  242. #endif
  243. bool cmGlobalVisualStudio7Generator::SetSystemName(std::string const& s,
  244. cmMakefile* mf)
  245. {
  246. mf->AddDefinition("CMAKE_VS_INTEL_Fortran_PROJECT_VERSION",
  247. this->GetIntelProjectVersion());
  248. return this->cmGlobalVisualStudioGenerator::SetSystemName(s, mf);
  249. }
  250. void cmGlobalVisualStudio7Generator::Generate()
  251. {
  252. // first do the superclass method
  253. this->cmGlobalVisualStudioGenerator::Generate();
  254. // Now write out the DSW
  255. this->OutputSLNFile();
  256. // If any solution or project files changed during the generation,
  257. // tell Visual Studio to reload them...
  258. if (!cmSystemTools::GetErrorOccuredFlag()) {
  259. this->CallVisualStudioMacro(MacroReload);
  260. }
  261. }
  262. void cmGlobalVisualStudio7Generator::OutputSLNFile(
  263. cmLocalGenerator* root, std::vector<cmLocalGenerator*>& generators)
  264. {
  265. if (generators.empty()) {
  266. return;
  267. }
  268. this->CurrentProject = root->GetProjectName();
  269. std::string fname = root->GetCurrentBinaryDirectory();
  270. fname += "/";
  271. fname += root->GetProjectName();
  272. fname += ".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. const char* prefix = "CMAKE_FOLDER_GUID_";
  396. const std::string::size_type skip_prefix = strlen(prefix);
  397. std::string guidProjectTypeFolder = "2150E333-8FDC-42A3-9474-1A3956D46DE8";
  398. for (auto const& iter : VisualStudioFolders) {
  399. std::string fullName = iter.first;
  400. std::string guid = this->GetGUID(fullName);
  401. std::replace(fullName.begin(), fullName.end(), '/', '\\');
  402. if (cmSystemTools::StringStartsWith(fullName.c_str(), prefix)) {
  403. fullName = fullName.substr(skip_prefix);
  404. }
  405. std::string nameOnly = cmSystemTools::GetFilenameName(fullName);
  406. fout << "Project(\"{" << guidProjectTypeFolder << "}\") = \"" << nameOnly
  407. << "\", \"" << fullName << "\", \"{" << guid << "}\"\nEndProject\n";
  408. }
  409. }
  410. void cmGlobalVisualStudio7Generator::WriteFoldersContent(std::ostream& fout)
  411. {
  412. for (auto const& iter : VisualStudioFolders) {
  413. std::string key(iter.first);
  414. std::string guidParent(this->GetGUID(key));
  415. for (std::string const& it : iter.second) {
  416. std::string value(it);
  417. std::string guid(this->GetGUID(value));
  418. fout << "\t\t{" << guid << "} = {" << guidParent << "}\n";
  419. }
  420. }
  421. }
  422. std::string cmGlobalVisualStudio7Generator::ConvertToSolutionPath(
  423. const char* path)
  424. {
  425. // Convert to backslashes. Do not use ConvertToOutputPath because
  426. // we will add quoting ourselves, and we know these projects always
  427. // use windows slashes.
  428. std::string d = path;
  429. std::string::size_type pos = 0;
  430. while ((pos = d.find('/', pos)) != d.npos) {
  431. d[pos++] = '\\';
  432. }
  433. return d;
  434. }
  435. void cmGlobalVisualStudio7Generator::WriteSLNGlobalSections(
  436. std::ostream& fout, cmLocalGenerator* root)
  437. {
  438. std::string const guid = this->GetGUID(root->GetProjectName() + ".sln");
  439. bool extensibilityGlobalsOverridden = false;
  440. bool extensibilityAddInsOverridden = false;
  441. const std::vector<std::string> propKeys =
  442. root->GetMakefile()->GetPropertyKeys();
  443. for (std::string const& it : propKeys) {
  444. if (it.find("VS_GLOBAL_SECTION_") == 0) {
  445. std::string sectionType;
  446. std::string name = it.substr(18);
  447. if (name.find("PRE_") == 0) {
  448. name = name.substr(4);
  449. sectionType = "preSolution";
  450. } else if (name.find("POST_") == 0) {
  451. name = name.substr(5);
  452. sectionType = "postSolution";
  453. } else
  454. continue;
  455. if (!name.empty()) {
  456. bool addGuid = false;
  457. if (name == "ExtensibilityGlobals" && sectionType == "postSolution") {
  458. addGuid = true;
  459. extensibilityGlobalsOverridden = true;
  460. } else if (name == "ExtensibilityAddIns" &&
  461. sectionType == "postSolution") {
  462. extensibilityAddInsOverridden = true;
  463. }
  464. fout << "\tGlobalSection(" << name << ") = " << sectionType << "\n";
  465. std::vector<std::string> keyValuePairs;
  466. cmSystemTools::ExpandListArgument(root->GetMakefile()->GetProperty(it),
  467. keyValuePairs);
  468. for (std::string const& itPair : keyValuePairs) {
  469. const std::string::size_type posEqual = itPair.find('=');
  470. if (posEqual != std::string::npos) {
  471. const std::string key =
  472. cmSystemTools::TrimWhitespace(itPair.substr(0, posEqual));
  473. const std::string value =
  474. cmSystemTools::TrimWhitespace(itPair.substr(posEqual + 1));
  475. fout << "\t\t" << key << " = " << value << "\n";
  476. if (key == "SolutionGuid") {
  477. addGuid = false;
  478. }
  479. }
  480. }
  481. if (addGuid) {
  482. fout << "\t\tSolutionGuid = {" << guid << "}\n";
  483. }
  484. fout << "\tEndGlobalSection\n";
  485. }
  486. }
  487. }
  488. if (!extensibilityGlobalsOverridden) {
  489. fout << "\tGlobalSection(ExtensibilityGlobals) = postSolution\n"
  490. << "\t\tSolutionGuid = {" << guid << "}\n"
  491. << "\tEndGlobalSection\n";
  492. }
  493. if (!extensibilityAddInsOverridden)
  494. fout << "\tGlobalSection(ExtensibilityAddIns) = postSolution\n"
  495. << "\tEndGlobalSection\n";
  496. }
  497. // Standard end of dsw file
  498. void cmGlobalVisualStudio7Generator::WriteSLNFooter(std::ostream& fout)
  499. {
  500. fout << "EndGlobal\n";
  501. }
  502. std::string cmGlobalVisualStudio7Generator::WriteUtilityDepend(
  503. cmGeneratorTarget const* target)
  504. {
  505. std::vector<std::string> configs;
  506. target->Target->GetMakefile()->GetConfigurations(configs);
  507. std::string pname = target->GetName();
  508. pname += "_UTILITY";
  509. std::string fname = target->GetLocalGenerator()->GetCurrentBinaryDirectory();
  510. fname += "/";
  511. fname += pname;
  512. fname += ".vcproj";
  513. cmGeneratedFileStream fout(fname.c_str());
  514. fout.SetCopyIfDifferent(true);
  515. std::string guid = this->GetGUID(pname.c_str());
  516. /* clang-format off */
  517. fout <<
  518. "<?xml version=\"1.0\" encoding = \""
  519. << this->Encoding() << "\"?>\n"
  520. "<VisualStudioProject\n"
  521. "\tProjectType=\"Visual C++\"\n"
  522. "\tVersion=\"" << this->GetIDEVersion() << "0\"\n"
  523. "\tName=\"" << pname << "\"\n"
  524. "\tProjectGUID=\"{" << guid << "}\"\n"
  525. "\tKeyword=\"Win32Proj\">\n"
  526. "\t<Platforms><Platform Name=\"Win32\"/></Platforms>\n"
  527. "\t<Configurations>\n"
  528. ;
  529. /* clang-format on */
  530. for (std::string const& i : configs) {
  531. /* clang-format off */
  532. fout <<
  533. "\t\t<Configuration\n"
  534. "\t\t\tName=\"" << i << "|Win32\"\n"
  535. "\t\t\tOutputDirectory=\"" << i << "\"\n"
  536. "\t\t\tIntermediateDirectory=\"" << pname << ".dir\\" << i << "\"\n"
  537. "\t\t\tConfigurationType=\"10\"\n"
  538. "\t\t\tUseOfMFC=\"0\"\n"
  539. "\t\t\tATLMinimizesCRunTimeLibraryUsage=\"FALSE\"\n"
  540. "\t\t\tCharacterSet=\"2\">\n"
  541. "\t\t</Configuration>\n"
  542. ;
  543. /* clang-format on */
  544. }
  545. /* clang-format off */
  546. fout <<
  547. "\t</Configurations>\n"
  548. "\t<Files></Files>\n"
  549. "\t<Globals></Globals>\n"
  550. "</VisualStudioProject>\n"
  551. ;
  552. /* clang-format on */
  553. if (fout.Close()) {
  554. this->FileReplacedDuringGenerate(fname);
  555. }
  556. return pname;
  557. }
  558. std::string cmGlobalVisualStudio7Generator::GetGUID(std::string const& name)
  559. {
  560. std::string const& guidStoreName = name + "_GUID_CMAKE";
  561. if (const char* storedGUID =
  562. this->CMakeInstance->GetCacheDefinition(guidStoreName.c_str())) {
  563. return std::string(storedGUID);
  564. }
  565. // Compute a GUID that is deterministic but unique to the build tree.
  566. std::string input = this->CMakeInstance->GetState()->GetBinaryDirectory();
  567. input += "|";
  568. input += name;
  569. cmUuid uuidGenerator;
  570. std::vector<unsigned char> uuidNamespace;
  571. uuidGenerator.StringToBinary("ee30c4be-5192-4fb0-b335-722a2dffe760",
  572. uuidNamespace);
  573. std::string guid = uuidGenerator.FromMd5(uuidNamespace, input);
  574. return cmSystemTools::UpperCase(guid);
  575. }
  576. void cmGlobalVisualStudio7Generator::AppendDirectoryForConfig(
  577. const std::string& prefix, const std::string& config,
  578. const std::string& suffix, std::string& dir)
  579. {
  580. if (!config.empty()) {
  581. dir += prefix;
  582. dir += config;
  583. dir += suffix;
  584. }
  585. }
  586. std::set<std::string> cmGlobalVisualStudio7Generator::IsPartOfDefaultBuild(
  587. std::vector<std::string> const& configs,
  588. OrderedTargetDependSet const& projectTargets,
  589. cmGeneratorTarget const* target)
  590. {
  591. std::set<std::string> activeConfigs;
  592. // if it is a utilitiy target then only make it part of the
  593. // default build if another target depends on it
  594. int type = target->GetType();
  595. if (type == cmStateEnums::GLOBAL_TARGET) {
  596. std::vector<std::string> targetNames;
  597. targetNames.push_back("INSTALL");
  598. targetNames.push_back("PACKAGE");
  599. for (std::string const& t : targetNames) {
  600. // check if target <t> is part of default build
  601. if (target->GetName() == t) {
  602. const std::string propertyName =
  603. "CMAKE_VS_INCLUDE_" + t + "_TO_DEFAULT_BUILD";
  604. // inspect CMAKE_VS_INCLUDE_<t>_TO_DEFAULT_BUILD properties
  605. for (std::string const& i : configs) {
  606. const char* propertyValue =
  607. target->Target->GetMakefile()->GetDefinition(propertyName);
  608. cmGeneratorExpression ge;
  609. std::unique_ptr<cmCompiledGeneratorExpression> cge =
  610. ge.Parse(propertyValue);
  611. if (cmSystemTools::IsOn(
  612. cge->Evaluate(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 (cmSystemTools::IsOff(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. }