cmGlobalVisualStudio7Generator.cxx 25 KB

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