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 "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",
  112. this->GetDevEnvCommand().c_str());
  113. return true;
  114. }
  115. std::string const& cmGlobalVisualStudio7Generator::GetDevEnvCommand()
  116. {
  117. if (!this->DevEnvCommandInitialized) {
  118. this->DevEnvCommandInitialized = true;
  119. this->DevEnvCommand = this->FindDevEnvCommand();
  120. }
  121. return this->DevEnvCommand;
  122. }
  123. std::string cmGlobalVisualStudio7Generator::FindDevEnvCommand()
  124. {
  125. std::string vscmd;
  126. std::string vskey;
  127. // Search in standard location.
  128. vskey = this->GetRegistryBase() + ";InstallDir";
  129. if (cmSystemTools::ReadRegistryValue(vskey.c_str(), vscmd,
  130. cmSystemTools::KeyWOW64_32)) {
  131. cmSystemTools::ConvertToUnixSlashes(vscmd);
  132. vscmd += "/devenv.com";
  133. if (cmSystemTools::FileExists(vscmd, true)) {
  134. return vscmd;
  135. }
  136. }
  137. // Search where VS15Preview places it.
  138. vskey = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\SxS\\VS7;";
  139. vskey += this->GetIDEVersion();
  140. if (cmSystemTools::ReadRegistryValue(vskey.c_str(), vscmd,
  141. cmSystemTools::KeyWOW64_32)) {
  142. cmSystemTools::ConvertToUnixSlashes(vscmd);
  143. vscmd += "/Common7/IDE/devenv.com";
  144. if (cmSystemTools::FileExists(vscmd, true)) {
  145. return vscmd;
  146. }
  147. }
  148. vscmd = "devenv.com";
  149. return vscmd;
  150. }
  151. const char* cmGlobalVisualStudio7Generator::ExternalProjectType(
  152. const char* location)
  153. {
  154. std::string extension = cmSystemTools::GetFilenameLastExtension(location);
  155. if (extension == ".vbproj") {
  156. return "F184B08F-C81C-45F6-A57F-5ABD9991F28F";
  157. } else if (extension == ".csproj") {
  158. return "FAE04EC0-301F-11D3-BF4B-00C04F79EFBC";
  159. } else if (extension == ".fsproj") {
  160. return "F2A71F9B-5D33-465A-A702-920D77279786";
  161. } else if (extension == ".vdproj") {
  162. return "54435603-DBB4-11D2-8724-00A0C9A8B90C";
  163. } else if (extension == ".dbproj") {
  164. return "C8D11400-126E-41CD-887F-60BD40844F9E";
  165. } else if (extension == ".wixproj") {
  166. return "930C7802-8A8C-48F9-8165-68863BCCD9DD";
  167. } else if (extension == ".pyproj") {
  168. return "888888A0-9F3D-457C-B088-3A5042F75D52";
  169. }
  170. return "8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942";
  171. }
  172. std::vector<cmGlobalGenerator::GeneratedMakeCommand>
  173. cmGlobalVisualStudio7Generator::GenerateBuildCommand(
  174. const std::string& makeProgram, const std::string& projectName,
  175. const std::string& /*projectDir*/,
  176. std::vector<std::string> const& targetNames, const std::string& config,
  177. bool /*fast*/, int /*jobs*/, bool /*verbose*/,
  178. std::vector<std::string> const& makeOptions)
  179. {
  180. // Select the caller- or user-preferred make program, else devenv.
  181. std::string makeProgramSelected =
  182. this->SelectMakeProgram(makeProgram, this->GetDevEnvCommand());
  183. // Ignore the above preference if it is msbuild.
  184. // Assume any other value is either a devenv or
  185. // command-line compatible with devenv.
  186. std::string makeProgramLower = makeProgramSelected;
  187. cmSystemTools::LowerCase(makeProgramLower);
  188. if (makeProgramLower.find("msbuild") != std::string::npos) {
  189. makeProgramSelected = this->GetDevEnvCommand();
  190. }
  191. // Workaround to convince VCExpress.exe to produce output.
  192. const bool requiresOutputForward =
  193. (makeProgramLower.find("vcexpress") != std::string::npos);
  194. std::vector<GeneratedMakeCommand> makeCommands;
  195. std::vector<std::string> realTargetNames = targetNames;
  196. if (targetNames.empty() ||
  197. ((targetNames.size() == 1) && targetNames.front().empty())) {
  198. realTargetNames = { "ALL_BUILD" };
  199. }
  200. for (const auto& tname : realTargetNames) {
  201. std::string realTarget;
  202. if (!tname.empty()) {
  203. realTarget = tname;
  204. } else {
  205. continue;
  206. }
  207. bool clean = false;
  208. if (realTarget == "clean") {
  209. clean = true;
  210. realTarget = "ALL_BUILD";
  211. }
  212. GeneratedMakeCommand makeCommand;
  213. makeCommand.RequiresOutputForward = requiresOutputForward;
  214. makeCommand.Add(makeProgramSelected);
  215. makeCommand.Add(projectName + ".sln");
  216. makeCommand.Add((clean ? "/clean" : "/build"));
  217. makeCommand.Add((config.empty() ? "Debug" : config));
  218. makeCommand.Add("/project");
  219. makeCommand.Add(realTarget);
  220. makeCommand.Add(makeOptions.begin(), makeOptions.end());
  221. makeCommands.emplace_back(std::move(makeCommand));
  222. }
  223. return makeCommands;
  224. }
  225. //! Create a local generator appropriate to this Global Generator
  226. cmLocalGenerator* cmGlobalVisualStudio7Generator::CreateLocalGenerator(
  227. cmMakefile* mf)
  228. {
  229. cmLocalVisualStudio7Generator* lg =
  230. new cmLocalVisualStudio7Generator(this, mf);
  231. return lg;
  232. }
  233. #if defined(CMAKE_BUILD_WITH_CMAKE)
  234. Json::Value cmGlobalVisualStudio7Generator::GetJson() const
  235. {
  236. Json::Value generator = this->cmGlobalVisualStudioGenerator::GetJson();
  237. generator["platform"] = this->GetPlatformName();
  238. return generator;
  239. }
  240. #endif
  241. bool cmGlobalVisualStudio7Generator::SetSystemName(std::string const& s,
  242. cmMakefile* mf)
  243. {
  244. mf->AddDefinition("CMAKE_VS_INTEL_Fortran_PROJECT_VERSION",
  245. this->GetIntelProjectVersion().c_str());
  246. return this->cmGlobalVisualStudioGenerator::SetSystemName(s, mf);
  247. }
  248. void cmGlobalVisualStudio7Generator::Generate()
  249. {
  250. // first do the superclass method
  251. this->cmGlobalVisualStudioGenerator::Generate();
  252. // Now write out the DSW
  253. this->OutputSLNFile();
  254. // If any solution or project files changed during the generation,
  255. // tell Visual Studio to reload them...
  256. if (!cmSystemTools::GetErrorOccuredFlag()) {
  257. this->CallVisualStudioMacro(MacroReload);
  258. }
  259. }
  260. void cmGlobalVisualStudio7Generator::OutputSLNFile(
  261. cmLocalGenerator* root, std::vector<cmLocalGenerator*>& generators)
  262. {
  263. if (generators.empty()) {
  264. return;
  265. }
  266. this->CurrentProject = root->GetProjectName();
  267. std::string fname = root->GetCurrentBinaryDirectory();
  268. fname += "/";
  269. fname += root->GetProjectName();
  270. fname += ".sln";
  271. cmGeneratedFileStream fout(fname.c_str());
  272. fout.SetCopyIfDifferent(true);
  273. if (!fout) {
  274. return;
  275. }
  276. this->WriteSLNFile(fout, root, generators);
  277. if (fout.Close()) {
  278. this->FileReplacedDuringGenerate(fname);
  279. }
  280. }
  281. // output the SLN file
  282. void cmGlobalVisualStudio7Generator::OutputSLNFile()
  283. {
  284. for (auto& it : this->ProjectMap) {
  285. this->OutputSLNFile(it.second[0], it.second);
  286. }
  287. }
  288. void cmGlobalVisualStudio7Generator::WriteTargetConfigurations(
  289. std::ostream& fout, std::vector<std::string> const& configs,
  290. OrderedTargetDependSet const& projectTargets)
  291. {
  292. // loop over again and write out configurations for each target
  293. // in the solution
  294. for (cmGeneratorTarget const* target : projectTargets) {
  295. if (target->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
  296. continue;
  297. }
  298. const char* expath = target->GetProperty("EXTERNAL_MSPROJECT");
  299. if (expath) {
  300. std::set<std::string> allConfigurations(configs.begin(), configs.end());
  301. const char* mapping = target->GetProperty("VS_PLATFORM_MAPPING");
  302. this->WriteProjectConfigurations(fout, target->GetName().c_str(),
  303. *target, configs, allConfigurations,
  304. mapping ? mapping : "");
  305. } else {
  306. const std::set<std::string>& configsPartOfDefaultBuild =
  307. this->IsPartOfDefaultBuild(configs, projectTargets, target);
  308. const char* vcprojName = target->GetProperty("GENERATOR_FILE_NAME");
  309. if (vcprojName) {
  310. this->WriteProjectConfigurations(fout, vcprojName, *target, configs,
  311. configsPartOfDefaultBuild);
  312. }
  313. }
  314. }
  315. }
  316. void cmGlobalVisualStudio7Generator::WriteTargetsToSolution(
  317. std::ostream& fout, cmLocalGenerator* root,
  318. OrderedTargetDependSet const& projectTargets)
  319. {
  320. VisualStudioFolders.clear();
  321. std::string rootBinaryDir = root->GetCurrentBinaryDirectory();
  322. for (cmGeneratorTarget const* target : projectTargets) {
  323. if (target->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
  324. continue;
  325. }
  326. bool written = false;
  327. // handle external vc project files
  328. const char* expath = target->GetProperty("EXTERNAL_MSPROJECT");
  329. if (expath) {
  330. std::string project = target->GetName();
  331. std::string location = expath;
  332. this->WriteExternalProject(fout, project.c_str(), location.c_str(),
  333. target->GetProperty("VS_PROJECT_TYPE"),
  334. target->GetUtilities());
  335. written = true;
  336. } else {
  337. const char* vcprojName = target->GetProperty("GENERATOR_FILE_NAME");
  338. if (vcprojName) {
  339. cmLocalGenerator* lg = target->GetLocalGenerator();
  340. std::string dir = lg->GetCurrentBinaryDirectory();
  341. dir = root->MaybeConvertToRelativePath(rootBinaryDir, dir.c_str());
  342. if (dir == ".") {
  343. dir.clear(); // msbuild cannot handle ".\" prefix
  344. }
  345. this->WriteProject(fout, vcprojName, dir.c_str(), target);
  346. written = true;
  347. }
  348. }
  349. // Create "solution folder" information from FOLDER target property
  350. //
  351. if (written && this->UseFolderProperty()) {
  352. const std::string targetFolder = target->GetEffectiveFolderName();
  353. if (!targetFolder.empty()) {
  354. std::vector<std::string> tokens =
  355. cmSystemTools::SplitString(targetFolder, '/', false);
  356. std::string cumulativePath;
  357. for (std::string const& iter : tokens) {
  358. if (!iter.size()) {
  359. continue;
  360. }
  361. if (cumulativePath.empty()) {
  362. cumulativePath = "CMAKE_FOLDER_GUID_" + iter;
  363. } else {
  364. VisualStudioFolders[cumulativePath].insert(cumulativePath + "/" +
  365. iter);
  366. cumulativePath = cumulativePath + "/" + iter;
  367. }
  368. }
  369. if (!cumulativePath.empty()) {
  370. VisualStudioFolders[cumulativePath].insert(target->GetName());
  371. }
  372. }
  373. }
  374. }
  375. }
  376. void cmGlobalVisualStudio7Generator::WriteTargetDepends(
  377. std::ostream& fout, OrderedTargetDependSet const& projectTargets)
  378. {
  379. for (cmGeneratorTarget const* target : projectTargets) {
  380. if (target->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
  381. continue;
  382. }
  383. const char* vcprojName = target->GetProperty("GENERATOR_FILE_NAME");
  384. if (vcprojName) {
  385. std::string dir =
  386. target->GetLocalGenerator()->GetCurrentSourceDirectory();
  387. this->WriteProjectDepends(fout, vcprojName, dir.c_str(), target);
  388. }
  389. }
  390. }
  391. void cmGlobalVisualStudio7Generator::WriteFolders(std::ostream& fout)
  392. {
  393. const char* prefix = "CMAKE_FOLDER_GUID_";
  394. const std::string::size_type skip_prefix = strlen(prefix);
  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 (cmSystemTools::StringStartsWith(fullName.c_str(), prefix)) {
  401. fullName = fullName.substr(skip_prefix);
  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. cmSystemTools::TrimWhitespace(itPair.substr(0, posEqual));
  471. const std::string value =
  472. cmSystemTools::TrimWhitespace(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. }