cmGlobalVisualStudio7Generator.cxx 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729
  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. int /*jobs*/, 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. #if defined(CMAKE_BUILD_WITH_CMAKE)
  231. Json::Value cmGlobalVisualStudio7Generator::GetJson() const
  232. {
  233. Json::Value generator = this->cmGlobalVisualStudioGenerator::GetJson();
  234. generator["platform"] = this->GetPlatformName();
  235. return generator;
  236. }
  237. #endif
  238. std::string const& cmGlobalVisualStudio7Generator::GetPlatformName() const
  239. {
  240. if (!this->GeneratorPlatform.empty()) {
  241. return this->GeneratorPlatform;
  242. }
  243. return this->DefaultPlatformName;
  244. }
  245. bool cmGlobalVisualStudio7Generator::SetSystemName(std::string const& s,
  246. cmMakefile* mf)
  247. {
  248. mf->AddDefinition("CMAKE_VS_INTEL_Fortran_PROJECT_VERSION",
  249. this->GetIntelProjectVersion());
  250. return this->cmGlobalVisualStudioGenerator::SetSystemName(s, mf);
  251. }
  252. bool cmGlobalVisualStudio7Generator::SetGeneratorPlatform(std::string const& p,
  253. cmMakefile* mf)
  254. {
  255. if (this->GetPlatformName() == "x64") {
  256. mf->AddDefinition("CMAKE_FORCE_WIN64", "TRUE");
  257. } else if (this->GetPlatformName() == "Itanium") {
  258. mf->AddDefinition("CMAKE_FORCE_IA64", "TRUE");
  259. }
  260. mf->AddDefinition("CMAKE_VS_PLATFORM_NAME", this->GetPlatformName().c_str());
  261. return this->cmGlobalVisualStudioGenerator::SetGeneratorPlatform(p, mf);
  262. }
  263. void cmGlobalVisualStudio7Generator::Generate()
  264. {
  265. // first do the superclass method
  266. this->cmGlobalVisualStudioGenerator::Generate();
  267. // Now write out the DSW
  268. this->OutputSLNFile();
  269. // If any solution or project files changed during the generation,
  270. // tell Visual Studio to reload them...
  271. if (!cmSystemTools::GetErrorOccuredFlag()) {
  272. this->CallVisualStudioMacro(MacroReload);
  273. }
  274. }
  275. void cmGlobalVisualStudio7Generator::OutputSLNFile(
  276. cmLocalGenerator* root, std::vector<cmLocalGenerator*>& generators)
  277. {
  278. if (generators.empty()) {
  279. return;
  280. }
  281. this->CurrentProject = root->GetProjectName();
  282. std::string fname = root->GetCurrentBinaryDirectory();
  283. fname += "/";
  284. fname += root->GetProjectName();
  285. fname += ".sln";
  286. cmGeneratedFileStream fout(fname.c_str());
  287. fout.SetCopyIfDifferent(true);
  288. if (!fout) {
  289. return;
  290. }
  291. this->WriteSLNFile(fout, root, generators);
  292. if (fout.Close()) {
  293. this->FileReplacedDuringGenerate(fname);
  294. }
  295. }
  296. // output the SLN file
  297. void cmGlobalVisualStudio7Generator::OutputSLNFile()
  298. {
  299. for (auto& it : this->ProjectMap) {
  300. this->OutputSLNFile(it.second[0], it.second);
  301. }
  302. }
  303. void cmGlobalVisualStudio7Generator::WriteTargetConfigurations(
  304. std::ostream& fout, std::vector<std::string> const& configs,
  305. OrderedTargetDependSet const& projectTargets)
  306. {
  307. // loop over again and write out configurations for each target
  308. // in the solution
  309. for (cmGeneratorTarget const* target : projectTargets) {
  310. if (target->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
  311. continue;
  312. }
  313. const char* expath = target->GetProperty("EXTERNAL_MSPROJECT");
  314. if (expath) {
  315. std::set<std::string> allConfigurations(configs.begin(), configs.end());
  316. const char* mapping = target->GetProperty("VS_PLATFORM_MAPPING");
  317. this->WriteProjectConfigurations(fout, target->GetName().c_str(),
  318. *target, configs, allConfigurations,
  319. mapping ? mapping : "");
  320. } else {
  321. const std::set<std::string>& configsPartOfDefaultBuild =
  322. this->IsPartOfDefaultBuild(configs, projectTargets, target);
  323. const char* vcprojName = target->GetProperty("GENERATOR_FILE_NAME");
  324. if (vcprojName) {
  325. this->WriteProjectConfigurations(fout, vcprojName, *target, configs,
  326. configsPartOfDefaultBuild);
  327. }
  328. }
  329. }
  330. }
  331. void cmGlobalVisualStudio7Generator::WriteTargetsToSolution(
  332. std::ostream& fout, cmLocalGenerator* root,
  333. OrderedTargetDependSet const& projectTargets)
  334. {
  335. VisualStudioFolders.clear();
  336. std::string rootBinaryDir = root->GetCurrentBinaryDirectory();
  337. for (cmGeneratorTarget const* target : projectTargets) {
  338. if (target->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
  339. continue;
  340. }
  341. bool written = false;
  342. // handle external vc project files
  343. const char* expath = target->GetProperty("EXTERNAL_MSPROJECT");
  344. if (expath) {
  345. std::string project = target->GetName();
  346. std::string location = expath;
  347. this->WriteExternalProject(fout, project.c_str(), location.c_str(),
  348. target->GetProperty("VS_PROJECT_TYPE"),
  349. target->GetUtilities());
  350. written = true;
  351. } else {
  352. const char* vcprojName = target->GetProperty("GENERATOR_FILE_NAME");
  353. if (vcprojName) {
  354. cmLocalGenerator* lg = target->GetLocalGenerator();
  355. std::string dir = lg->GetCurrentBinaryDirectory();
  356. dir = root->ConvertToRelativePath(rootBinaryDir, dir.c_str());
  357. if (dir == ".") {
  358. dir.clear(); // msbuild cannot handle ".\" prefix
  359. }
  360. this->WriteProject(fout, vcprojName, dir.c_str(), target);
  361. written = true;
  362. }
  363. }
  364. // Create "solution folder" information from FOLDER target property
  365. //
  366. if (written && this->UseFolderProperty()) {
  367. const std::string targetFolder = target->GetEffectiveFolderName();
  368. if (!targetFolder.empty()) {
  369. std::vector<std::string> tokens =
  370. cmSystemTools::SplitString(targetFolder, '/', false);
  371. std::string cumulativePath;
  372. for (std::string const& iter : tokens) {
  373. if (!iter.size()) {
  374. continue;
  375. }
  376. if (cumulativePath.empty()) {
  377. cumulativePath = "CMAKE_FOLDER_GUID_" + iter;
  378. } else {
  379. VisualStudioFolders[cumulativePath].insert(cumulativePath + "/" +
  380. iter);
  381. cumulativePath = cumulativePath + "/" + iter;
  382. }
  383. }
  384. if (!cumulativePath.empty()) {
  385. VisualStudioFolders[cumulativePath].insert(target->GetName());
  386. }
  387. }
  388. }
  389. }
  390. }
  391. void cmGlobalVisualStudio7Generator::WriteTargetDepends(
  392. std::ostream& fout, OrderedTargetDependSet const& projectTargets)
  393. {
  394. for (cmGeneratorTarget const* target : projectTargets) {
  395. if (target->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
  396. continue;
  397. }
  398. const char* vcprojName = target->GetProperty("GENERATOR_FILE_NAME");
  399. if (vcprojName) {
  400. std::string dir =
  401. target->GetLocalGenerator()->GetCurrentSourceDirectory();
  402. this->WriteProjectDepends(fout, vcprojName, dir.c_str(), target);
  403. }
  404. }
  405. }
  406. void cmGlobalVisualStudio7Generator::WriteFolders(std::ostream& fout)
  407. {
  408. const char* prefix = "CMAKE_FOLDER_GUID_";
  409. const std::string::size_type skip_prefix = strlen(prefix);
  410. std::string guidProjectTypeFolder = "2150E333-8FDC-42A3-9474-1A3956D46DE8";
  411. for (auto const& iter : VisualStudioFolders) {
  412. std::string fullName = iter.first;
  413. std::string guid = this->GetGUID(fullName);
  414. std::replace(fullName.begin(), fullName.end(), '/', '\\');
  415. if (cmSystemTools::StringStartsWith(fullName.c_str(), prefix)) {
  416. fullName = fullName.substr(skip_prefix);
  417. }
  418. std::string nameOnly = cmSystemTools::GetFilenameName(fullName);
  419. fout << "Project(\"{" << guidProjectTypeFolder << "}\") = \"" << nameOnly
  420. << "\", \"" << fullName << "\", \"{" << guid << "}\"\nEndProject\n";
  421. }
  422. }
  423. void cmGlobalVisualStudio7Generator::WriteFoldersContent(std::ostream& fout)
  424. {
  425. for (auto const& iter : VisualStudioFolders) {
  426. std::string key(iter.first);
  427. std::string guidParent(this->GetGUID(key));
  428. for (std::string const& it : iter.second) {
  429. std::string value(it);
  430. std::string guid(this->GetGUID(value));
  431. fout << "\t\t{" << guid << "} = {" << guidParent << "}\n";
  432. }
  433. }
  434. }
  435. std::string cmGlobalVisualStudio7Generator::ConvertToSolutionPath(
  436. const char* path)
  437. {
  438. // Convert to backslashes. Do not use ConvertToOutputPath because
  439. // we will add quoting ourselves, and we know these projects always
  440. // use windows slashes.
  441. std::string d = path;
  442. std::string::size_type pos = 0;
  443. while ((pos = d.find('/', pos)) != d.npos) {
  444. d[pos++] = '\\';
  445. }
  446. return d;
  447. }
  448. void cmGlobalVisualStudio7Generator::WriteSLNGlobalSections(
  449. std::ostream& fout, cmLocalGenerator* root)
  450. {
  451. std::string const guid = this->GetGUID(root->GetProjectName() + ".sln");
  452. bool extensibilityGlobalsOverridden = false;
  453. bool extensibilityAddInsOverridden = false;
  454. const std::vector<std::string> propKeys =
  455. root->GetMakefile()->GetPropertyKeys();
  456. for (std::string const& it : propKeys) {
  457. if (it.find("VS_GLOBAL_SECTION_") == 0) {
  458. std::string sectionType;
  459. std::string name = it.substr(18);
  460. if (name.find("PRE_") == 0) {
  461. name = name.substr(4);
  462. sectionType = "preSolution";
  463. } else if (name.find("POST_") == 0) {
  464. name = name.substr(5);
  465. sectionType = "postSolution";
  466. } else
  467. continue;
  468. if (!name.empty()) {
  469. bool addGuid = false;
  470. if (name == "ExtensibilityGlobals" && sectionType == "postSolution") {
  471. addGuid = true;
  472. extensibilityGlobalsOverridden = true;
  473. } else if (name == "ExtensibilityAddIns" &&
  474. sectionType == "postSolution") {
  475. extensibilityAddInsOverridden = true;
  476. }
  477. fout << "\tGlobalSection(" << name << ") = " << sectionType << "\n";
  478. std::vector<std::string> keyValuePairs;
  479. cmSystemTools::ExpandListArgument(root->GetMakefile()->GetProperty(it),
  480. keyValuePairs);
  481. for (std::string const& itPair : keyValuePairs) {
  482. const std::string::size_type posEqual = itPair.find('=');
  483. if (posEqual != std::string::npos) {
  484. const std::string key =
  485. cmSystemTools::TrimWhitespace(itPair.substr(0, posEqual));
  486. const std::string value =
  487. cmSystemTools::TrimWhitespace(itPair.substr(posEqual + 1));
  488. fout << "\t\t" << key << " = " << value << "\n";
  489. if (key == "SolutionGuid") {
  490. addGuid = false;
  491. }
  492. }
  493. }
  494. if (addGuid) {
  495. fout << "\t\tSolutionGuid = {" << guid << "}\n";
  496. }
  497. fout << "\tEndGlobalSection\n";
  498. }
  499. }
  500. }
  501. if (!extensibilityGlobalsOverridden) {
  502. fout << "\tGlobalSection(ExtensibilityGlobals) = postSolution\n"
  503. << "\t\tSolutionGuid = {" << guid << "}\n"
  504. << "\tEndGlobalSection\n";
  505. }
  506. if (!extensibilityAddInsOverridden)
  507. fout << "\tGlobalSection(ExtensibilityAddIns) = postSolution\n"
  508. << "\tEndGlobalSection\n";
  509. }
  510. // Standard end of dsw file
  511. void cmGlobalVisualStudio7Generator::WriteSLNFooter(std::ostream& fout)
  512. {
  513. fout << "EndGlobal\n";
  514. }
  515. std::string cmGlobalVisualStudio7Generator::WriteUtilityDepend(
  516. cmGeneratorTarget const* target)
  517. {
  518. std::vector<std::string> configs;
  519. target->Target->GetMakefile()->GetConfigurations(configs);
  520. std::string pname = target->GetName();
  521. pname += "_UTILITY";
  522. std::string fname = target->GetLocalGenerator()->GetCurrentBinaryDirectory();
  523. fname += "/";
  524. fname += pname;
  525. fname += ".vcproj";
  526. cmGeneratedFileStream fout(fname.c_str());
  527. fout.SetCopyIfDifferent(true);
  528. std::string guid = this->GetGUID(pname.c_str());
  529. /* clang-format off */
  530. fout <<
  531. "<?xml version=\"1.0\" encoding = \""
  532. << this->Encoding() << "\"?>\n"
  533. "<VisualStudioProject\n"
  534. "\tProjectType=\"Visual C++\"\n"
  535. "\tVersion=\"" << this->GetIDEVersion() << "0\"\n"
  536. "\tName=\"" << pname << "\"\n"
  537. "\tProjectGUID=\"{" << guid << "}\"\n"
  538. "\tKeyword=\"Win32Proj\">\n"
  539. "\t<Platforms><Platform Name=\"Win32\"/></Platforms>\n"
  540. "\t<Configurations>\n"
  541. ;
  542. /* clang-format on */
  543. for (std::string const& i : configs) {
  544. /* clang-format off */
  545. fout <<
  546. "\t\t<Configuration\n"
  547. "\t\t\tName=\"" << i << "|Win32\"\n"
  548. "\t\t\tOutputDirectory=\"" << i << "\"\n"
  549. "\t\t\tIntermediateDirectory=\"" << pname << ".dir\\" << i << "\"\n"
  550. "\t\t\tConfigurationType=\"10\"\n"
  551. "\t\t\tUseOfMFC=\"0\"\n"
  552. "\t\t\tATLMinimizesCRunTimeLibraryUsage=\"FALSE\"\n"
  553. "\t\t\tCharacterSet=\"2\">\n"
  554. "\t\t</Configuration>\n"
  555. ;
  556. /* clang-format on */
  557. }
  558. /* clang-format off */
  559. fout <<
  560. "\t</Configurations>\n"
  561. "\t<Files></Files>\n"
  562. "\t<Globals></Globals>\n"
  563. "</VisualStudioProject>\n"
  564. ;
  565. /* clang-format on */
  566. if (fout.Close()) {
  567. this->FileReplacedDuringGenerate(fname);
  568. }
  569. return pname;
  570. }
  571. std::string cmGlobalVisualStudio7Generator::GetGUID(std::string const& name)
  572. {
  573. std::string const& guidStoreName = name + "_GUID_CMAKE";
  574. if (const char* storedGUID =
  575. this->CMakeInstance->GetCacheDefinition(guidStoreName.c_str())) {
  576. return std::string(storedGUID);
  577. }
  578. // Compute a GUID that is deterministic but unique to the build tree.
  579. std::string input = this->CMakeInstance->GetState()->GetBinaryDirectory();
  580. input += "|";
  581. input += name;
  582. cmUuid uuidGenerator;
  583. std::vector<unsigned char> uuidNamespace;
  584. uuidGenerator.StringToBinary("ee30c4be-5192-4fb0-b335-722a2dffe760",
  585. uuidNamespace);
  586. std::string guid = uuidGenerator.FromMd5(uuidNamespace, input);
  587. return cmSystemTools::UpperCase(guid);
  588. }
  589. void cmGlobalVisualStudio7Generator::AppendDirectoryForConfig(
  590. const std::string& prefix, const std::string& config,
  591. const std::string& suffix, std::string& dir)
  592. {
  593. if (!config.empty()) {
  594. dir += prefix;
  595. dir += config;
  596. dir += suffix;
  597. }
  598. }
  599. std::set<std::string> cmGlobalVisualStudio7Generator::IsPartOfDefaultBuild(
  600. std::vector<std::string> const& configs,
  601. OrderedTargetDependSet const& projectTargets,
  602. cmGeneratorTarget const* target)
  603. {
  604. std::set<std::string> activeConfigs;
  605. // if it is a utilitiy target then only make it part of the
  606. // default build if another target depends on it
  607. int type = target->GetType();
  608. if (type == cmStateEnums::GLOBAL_TARGET) {
  609. std::vector<std::string> targetNames;
  610. targetNames.push_back("INSTALL");
  611. targetNames.push_back("PACKAGE");
  612. for (std::string const& t : targetNames) {
  613. // check if target <t> is part of default build
  614. if (target->GetName() == t) {
  615. const std::string propertyName =
  616. "CMAKE_VS_INCLUDE_" + t + "_TO_DEFAULT_BUILD";
  617. // inspect CMAKE_VS_INCLUDE_<t>_TO_DEFAULT_BUILD properties
  618. for (std::string const& i : configs) {
  619. const char* propertyValue =
  620. target->Target->GetMakefile()->GetDefinition(propertyName);
  621. cmGeneratorExpression ge;
  622. std::unique_ptr<cmCompiledGeneratorExpression> cge =
  623. ge.Parse(propertyValue);
  624. if (cmSystemTools::IsOn(
  625. cge->Evaluate(target->GetLocalGenerator(), i))) {
  626. activeConfigs.insert(i);
  627. }
  628. }
  629. }
  630. }
  631. return activeConfigs;
  632. }
  633. if (type == cmStateEnums::UTILITY &&
  634. !this->IsDependedOn(projectTargets, target)) {
  635. return activeConfigs;
  636. }
  637. // inspect EXCLUDE_FROM_DEFAULT_BUILD[_<CONFIG>] properties
  638. for (std::string const& i : configs) {
  639. const char* propertyValue =
  640. target->GetFeature("EXCLUDE_FROM_DEFAULT_BUILD", i);
  641. if (cmSystemTools::IsOff(propertyValue)) {
  642. activeConfigs.insert(i);
  643. }
  644. }
  645. return activeConfigs;
  646. }
  647. bool cmGlobalVisualStudio7Generator::IsDependedOn(
  648. OrderedTargetDependSet const& projectTargets, cmGeneratorTarget const* gtIn)
  649. {
  650. for (cmTargetDepend const& l : projectTargets) {
  651. TargetDependSet const& tgtdeps = this->GetTargetDirectDepends(l);
  652. if (tgtdeps.count(gtIn)) {
  653. return true;
  654. }
  655. }
  656. return false;
  657. }
  658. std::string cmGlobalVisualStudio7Generator::Encoding()
  659. {
  660. return "UTF-8";
  661. }