cmGlobalVisualStudio7Generator.cxx 25 KB

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