cmGlobalVisualStudio7Generator.cxx 25 KB

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