cmGlobalVisualStudio7Generator.cxx 26 KB

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