cmGlobalVisualStudio7Generator.cxx 25 KB

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