cmGlobalVisualStudio7Generator.cxx 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735
  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 "windows.h" // this must be first to define GetCurrentDirectory
  4. #include "cmGlobalVisualStudio7Generator.h"
  5. #include "cmGeneratedFileStream.h"
  6. #include "cmGeneratorTarget.h"
  7. #include "cmLocalVisualStudio7Generator.h"
  8. #include "cmMakefile.h"
  9. #include "cmState.h"
  10. #include "cmUuid.h"
  11. #include "cmake.h"
  12. #include <cmsys/Encoding.hxx>
  13. #include <assert.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. if (platformName.empty()) {
  44. this->DefaultPlatformName = "Win32";
  45. } else {
  46. this->DefaultPlatformName = platformName;
  47. }
  48. this->ExtraFlagTable = cmVS7ExtraFlagTable;
  49. this->Version = VS7;
  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. if (this->Version == VS71 && !this->CMakeInstance->GetIsInTryCompile()) {
  266. const char* cmakeWarnVS71 =
  267. this->CMakeInstance->GetState()->GetCacheEntryValue("CMAKE_WARN_VS71");
  268. if (!cmakeWarnVS71 || !cmSystemTools::IsOff(cmakeWarnVS71)) {
  269. this->CMakeInstance->IssueMessage(
  270. cmake::WARNING,
  271. "The \"Visual Studio 7 .NET 2003\" generator is deprecated "
  272. "and will be removed in a future version of CMake."
  273. "\n"
  274. "Add CMAKE_WARN_VS71=OFF to the cache to disable this warning.");
  275. }
  276. }
  277. }
  278. void cmGlobalVisualStudio7Generator::OutputSLNFile(
  279. cmLocalGenerator* root, std::vector<cmLocalGenerator*>& generators)
  280. {
  281. if (generators.empty()) {
  282. return;
  283. }
  284. this->CurrentProject = root->GetProjectName();
  285. std::string fname = root->GetCurrentBinaryDirectory();
  286. fname += "/";
  287. fname += root->GetProjectName();
  288. fname += ".sln";
  289. cmGeneratedFileStream fout(fname.c_str());
  290. fout.SetCopyIfDifferent(true);
  291. if (!fout) {
  292. return;
  293. }
  294. this->WriteSLNFile(fout, root, generators);
  295. if (fout.Close()) {
  296. this->FileReplacedDuringGenerate(fname);
  297. }
  298. }
  299. // output the SLN file
  300. void cmGlobalVisualStudio7Generator::OutputSLNFile()
  301. {
  302. std::map<std::string, std::vector<cmLocalGenerator*> >::iterator it;
  303. for (it = this->ProjectMap.begin(); it != this->ProjectMap.end(); ++it) {
  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 (OrderedTargetDependSet::const_iterator tt = projectTargets.begin();
  314. tt != projectTargets.end(); ++tt) {
  315. cmGeneratorTarget const* target = *tt;
  316. if (target->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
  317. continue;
  318. }
  319. const char* expath = target->GetProperty("EXTERNAL_MSPROJECT");
  320. if (expath) {
  321. std::set<std::string> allConfigurations(configs.begin(), configs.end());
  322. const char* mapping = target->GetProperty("VS_PLATFORM_MAPPING");
  323. this->WriteProjectConfigurations(
  324. fout, target->GetName().c_str(), target->GetType(), configs,
  325. allConfigurations, mapping ? mapping : "");
  326. } else {
  327. const std::set<std::string>& configsPartOfDefaultBuild =
  328. this->IsPartOfDefaultBuild(configs, projectTargets, target);
  329. const char* vcprojName = target->GetProperty("GENERATOR_FILE_NAME");
  330. if (vcprojName) {
  331. this->WriteProjectConfigurations(fout, vcprojName, target->GetType(),
  332. configs, configsPartOfDefaultBuild);
  333. }
  334. }
  335. }
  336. }
  337. void cmGlobalVisualStudio7Generator::WriteTargetsToSolution(
  338. std::ostream& fout, cmLocalGenerator* root,
  339. OrderedTargetDependSet const& projectTargets)
  340. {
  341. VisualStudioFolders.clear();
  342. std::string rootBinaryDir = root->GetCurrentBinaryDirectory();
  343. for (OrderedTargetDependSet::const_iterator tt = projectTargets.begin();
  344. tt != projectTargets.end(); ++tt) {
  345. cmGeneratorTarget const* target = *tt;
  346. if (target->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
  347. continue;
  348. }
  349. bool written = false;
  350. // handle external vc project files
  351. const char* expath = target->GetProperty("EXTERNAL_MSPROJECT");
  352. if (expath) {
  353. std::string project = target->GetName();
  354. std::string location = expath;
  355. this->WriteExternalProject(fout, project.c_str(), location.c_str(),
  356. target->GetProperty("VS_PROJECT_TYPE"),
  357. target->GetUtilities());
  358. written = true;
  359. } else {
  360. const char* vcprojName = target->GetProperty("GENERATOR_FILE_NAME");
  361. if (vcprojName) {
  362. cmLocalGenerator* lg = target->GetLocalGenerator();
  363. std::string dir = lg->GetCurrentBinaryDirectory();
  364. dir = root->ConvertToRelativePath(rootBinaryDir, dir.c_str());
  365. if (dir == ".") {
  366. dir = ""; // msbuild cannot handle ".\" prefix
  367. }
  368. this->WriteProject(fout, vcprojName, dir.c_str(), target);
  369. written = true;
  370. }
  371. }
  372. // Create "solution folder" information from FOLDER target property
  373. //
  374. if (written && this->UseFolderProperty()) {
  375. const std::string targetFolder = target->GetEffectiveFolderName();
  376. if (!targetFolder.empty()) {
  377. std::vector<cmsys::String> tokens =
  378. cmSystemTools::SplitString(targetFolder, '/', false);
  379. std::string cumulativePath = "";
  380. for (std::vector<cmsys::String>::iterator iter = tokens.begin();
  381. iter != tokens.end(); ++iter) {
  382. if (!iter->size()) {
  383. continue;
  384. }
  385. if (cumulativePath.empty()) {
  386. cumulativePath = "CMAKE_FOLDER_GUID_" + *iter;
  387. } else {
  388. VisualStudioFolders[cumulativePath].insert(cumulativePath + "/" +
  389. *iter);
  390. cumulativePath = cumulativePath + "/" + *iter;
  391. }
  392. }
  393. if (!cumulativePath.empty()) {
  394. VisualStudioFolders[cumulativePath].insert(target->GetName());
  395. }
  396. }
  397. }
  398. }
  399. }
  400. void cmGlobalVisualStudio7Generator::WriteTargetDepends(
  401. std::ostream& fout, OrderedTargetDependSet const& projectTargets)
  402. {
  403. for (OrderedTargetDependSet::const_iterator tt = projectTargets.begin();
  404. tt != projectTargets.end(); ++tt) {
  405. cmGeneratorTarget const* target = *tt;
  406. if (target->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
  407. continue;
  408. }
  409. const char* vcprojName = target->GetProperty("GENERATOR_FILE_NAME");
  410. if (vcprojName) {
  411. std::string dir =
  412. target->GetLocalGenerator()->GetCurrentSourceDirectory();
  413. this->WriteProjectDepends(fout, vcprojName, dir.c_str(), target);
  414. }
  415. }
  416. }
  417. void cmGlobalVisualStudio7Generator::WriteFolders(std::ostream& fout)
  418. {
  419. const char* prefix = "CMAKE_FOLDER_GUID_";
  420. const std::string::size_type skip_prefix = strlen(prefix);
  421. std::string guidProjectTypeFolder = "2150E333-8FDC-42A3-9474-1A3956D46DE8";
  422. for (std::map<std::string, std::set<std::string> >::iterator iter =
  423. VisualStudioFolders.begin();
  424. iter != VisualStudioFolders.end(); ++iter) {
  425. std::string fullName = iter->first;
  426. std::string guid = this->GetGUID(fullName.c_str());
  427. std::replace(fullName.begin(), fullName.end(), '/', '\\');
  428. if (cmSystemTools::StringStartsWith(fullName.c_str(), prefix)) {
  429. fullName = fullName.substr(skip_prefix);
  430. }
  431. std::string nameOnly = cmSystemTools::GetFilenameName(fullName);
  432. fout << "Project(\"{" << guidProjectTypeFolder << "}\") = \"" << nameOnly
  433. << "\", \"" << fullName << "\", \"{" << guid << "}\"\nEndProject\n";
  434. }
  435. }
  436. void cmGlobalVisualStudio7Generator::WriteFoldersContent(std::ostream& fout)
  437. {
  438. for (std::map<std::string, std::set<std::string> >::iterator iter =
  439. VisualStudioFolders.begin();
  440. iter != VisualStudioFolders.end(); ++iter) {
  441. std::string key(iter->first);
  442. std::string guidParent(this->GetGUID(key.c_str()));
  443. for (std::set<std::string>::iterator it = iter->second.begin();
  444. it != iter->second.end(); ++it) {
  445. std::string value(*it);
  446. std::string guid(this->GetGUID(value.c_str()));
  447. fout << "\t\t{" << guid << "} = {" << guidParent << "}\n";
  448. }
  449. }
  450. }
  451. std::string cmGlobalVisualStudio7Generator::ConvertToSolutionPath(
  452. const char* path)
  453. {
  454. // Convert to backslashes. Do not use ConvertToOutputPath because
  455. // we will add quoting ourselves, and we know these projects always
  456. // use windows slashes.
  457. std::string d = path;
  458. std::string::size_type pos = 0;
  459. while ((pos = d.find('/', pos)) != d.npos) {
  460. d[pos++] = '\\';
  461. }
  462. return d;
  463. }
  464. void cmGlobalVisualStudio7Generator::WriteSLNGlobalSections(
  465. std::ostream& fout, cmLocalGenerator* root)
  466. {
  467. bool extensibilityGlobalsOverridden = false;
  468. bool extensibilityAddInsOverridden = false;
  469. const std::vector<std::string> propKeys =
  470. root->GetMakefile()->GetPropertyKeys();
  471. for (std::vector<std::string>::const_iterator it = propKeys.begin();
  472. it != propKeys.end(); ++it) {
  473. if (it->find("VS_GLOBAL_SECTION_") == 0) {
  474. std::string sectionType;
  475. std::string name = it->substr(18);
  476. if (name.find("PRE_") == 0) {
  477. name = name.substr(4);
  478. sectionType = "preSolution";
  479. } else if (name.find("POST_") == 0) {
  480. name = name.substr(5);
  481. sectionType = "postSolution";
  482. } else
  483. continue;
  484. if (!name.empty()) {
  485. if (name == "ExtensibilityGlobals" && sectionType == "postSolution")
  486. extensibilityGlobalsOverridden = true;
  487. else if (name == "ExtensibilityAddIns" &&
  488. sectionType == "postSolution")
  489. extensibilityAddInsOverridden = true;
  490. fout << "\tGlobalSection(" << name << ") = " << sectionType << "\n";
  491. std::vector<std::string> keyValuePairs;
  492. cmSystemTools::ExpandListArgument(
  493. root->GetMakefile()->GetProperty(it->c_str()), keyValuePairs);
  494. for (std::vector<std::string>::const_iterator itPair =
  495. keyValuePairs.begin();
  496. itPair != keyValuePairs.end(); ++itPair) {
  497. const std::string::size_type posEqual = itPair->find('=');
  498. if (posEqual != std::string::npos) {
  499. const std::string key =
  500. cmSystemTools::TrimWhitespace(itPair->substr(0, posEqual));
  501. const std::string value =
  502. cmSystemTools::TrimWhitespace(itPair->substr(posEqual + 1));
  503. fout << "\t\t" << key << " = " << value << "\n";
  504. }
  505. }
  506. fout << "\tEndGlobalSection\n";
  507. }
  508. }
  509. }
  510. if (!extensibilityGlobalsOverridden)
  511. fout << "\tGlobalSection(ExtensibilityGlobals) = postSolution\n"
  512. << "\tEndGlobalSection\n";
  513. if (!extensibilityAddInsOverridden)
  514. fout << "\tGlobalSection(ExtensibilityAddIns) = postSolution\n"
  515. << "\tEndGlobalSection\n";
  516. }
  517. // Standard end of dsw file
  518. void cmGlobalVisualStudio7Generator::WriteSLNFooter(std::ostream& fout)
  519. {
  520. fout << "EndGlobal\n";
  521. }
  522. std::string cmGlobalVisualStudio7Generator::WriteUtilityDepend(
  523. cmGeneratorTarget const* target)
  524. {
  525. std::vector<std::string> configs;
  526. target->Target->GetMakefile()->GetConfigurations(configs);
  527. std::string pname = target->GetName();
  528. pname += "_UTILITY";
  529. std::string fname = target->GetLocalGenerator()->GetCurrentBinaryDirectory();
  530. fname += "/";
  531. fname += pname;
  532. fname += ".vcproj";
  533. cmGeneratedFileStream fout(fname.c_str());
  534. fout.SetCopyIfDifferent(true);
  535. std::string guid = this->GetGUID(pname.c_str());
  536. /* clang-format off */
  537. fout <<
  538. "<?xml version=\"1.0\" encoding = \""
  539. << this->Encoding() << "\"?>\n"
  540. "<VisualStudioProject\n"
  541. "\tProjectType=\"Visual C++\"\n"
  542. "\tVersion=\"" << this->GetIDEVersion() << "0\"\n"
  543. "\tName=\"" << pname << "\"\n"
  544. "\tProjectGUID=\"{" << guid << "}\"\n"
  545. "\tKeyword=\"Win32Proj\">\n"
  546. "\t<Platforms><Platform Name=\"Win32\"/></Platforms>\n"
  547. "\t<Configurations>\n"
  548. ;
  549. /* clang-format on */
  550. for (std::vector<std::string>::iterator i = configs.begin();
  551. i != configs.end(); ++i) {
  552. /* clang-format off */
  553. fout <<
  554. "\t\t<Configuration\n"
  555. "\t\t\tName=\"" << *i << "|Win32\"\n"
  556. "\t\t\tOutputDirectory=\"" << *i << "\"\n"
  557. "\t\t\tIntermediateDirectory=\"" << pname << ".dir\\" << *i << "\"\n"
  558. "\t\t\tConfigurationType=\"10\"\n"
  559. "\t\t\tUseOfMFC=\"0\"\n"
  560. "\t\t\tATLMinimizesCRunTimeLibraryUsage=\"FALSE\"\n"
  561. "\t\t\tCharacterSet=\"2\">\n"
  562. "\t\t</Configuration>\n"
  563. ;
  564. /* clang-format on */
  565. }
  566. /* clang-format off */
  567. fout <<
  568. "\t</Configurations>\n"
  569. "\t<Files></Files>\n"
  570. "\t<Globals></Globals>\n"
  571. "</VisualStudioProject>\n"
  572. ;
  573. /* clang-format on */
  574. if (fout.Close()) {
  575. this->FileReplacedDuringGenerate(fname);
  576. }
  577. return pname;
  578. }
  579. std::string cmGlobalVisualStudio7Generator::GetGUID(std::string const& name)
  580. {
  581. std::string const& guidStoreName = name + "_GUID_CMAKE";
  582. if (const char* storedGUID =
  583. this->CMakeInstance->GetCacheDefinition(guidStoreName.c_str())) {
  584. return std::string(storedGUID);
  585. }
  586. // Compute a GUID that is deterministic but unique to the build tree.
  587. std::string input = this->CMakeInstance->GetState()->GetBinaryDirectory();
  588. input += "|";
  589. input += name;
  590. cmUuid uuidGenerator;
  591. std::vector<unsigned char> uuidNamespace;
  592. uuidGenerator.StringToBinary("ee30c4be-5192-4fb0-b335-722a2dffe760",
  593. uuidNamespace);
  594. std::string guid = uuidGenerator.FromMd5(uuidNamespace, input);
  595. return cmSystemTools::UpperCase(guid);
  596. }
  597. void cmGlobalVisualStudio7Generator::AppendDirectoryForConfig(
  598. const std::string& prefix, const std::string& config,
  599. const std::string& suffix, std::string& dir)
  600. {
  601. if (!config.empty()) {
  602. dir += prefix;
  603. dir += config;
  604. dir += suffix;
  605. }
  606. }
  607. std::set<std::string> cmGlobalVisualStudio7Generator::IsPartOfDefaultBuild(
  608. std::vector<std::string> const& configs,
  609. OrderedTargetDependSet const& projectTargets,
  610. cmGeneratorTarget const* target)
  611. {
  612. std::set<std::string> activeConfigs;
  613. // if it is a utilitiy target then only make it part of the
  614. // default build if another target depends on it
  615. int type = target->GetType();
  616. if (type == cmStateEnums::GLOBAL_TARGET) {
  617. // check if INSTALL target is part of default build
  618. if (target->GetName() == "INSTALL") {
  619. // inspect CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD properties
  620. for (std::vector<std::string>::const_iterator i = configs.begin();
  621. i != configs.end(); ++i) {
  622. const char* propertyValue =
  623. target->Target->GetMakefile()->GetDefinition(
  624. "CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD");
  625. cmGeneratorExpression ge;
  626. CM_AUTO_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. return activeConfigs;
  635. }
  636. if (type == cmStateEnums::UTILITY &&
  637. !this->IsDependedOn(projectTargets, target)) {
  638. return activeConfigs;
  639. }
  640. // inspect EXCLUDE_FROM_DEFAULT_BUILD[_<CONFIG>] properties
  641. for (std::vector<std::string>::const_iterator i = configs.begin();
  642. i != configs.end(); ++i) {
  643. const char* propertyValue =
  644. target->GetFeature("EXCLUDE_FROM_DEFAULT_BUILD", i->c_str());
  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 (OrderedTargetDependSet::const_iterator l = projectTargets.begin();
  655. l != projectTargets.end(); ++l) {
  656. TargetDependSet const& tgtdeps = this->GetTargetDirectDepends(*l);
  657. if (tgtdeps.count(gtIn)) {
  658. return true;
  659. }
  660. }
  661. return false;
  662. }
  663. std::string cmGlobalVisualStudio7Generator::Encoding()
  664. {
  665. return "UTF-8";
  666. }