1
0

cmGlobalVisualStudio7Generator.cxx 26 KB

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