cmGlobalVisualStudio7Generator.cxx 24 KB

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