cmGlobalVisualStudio7Generator.cxx 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072
  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 *
  259. cmGlobalVisualStudio7Generator::CreateLocalGenerator(cmLocalGenerator* parent,
  260. cmState::Snapshot snapshot)
  261. {
  262. cmLocalVisualStudio7Generator *lg =
  263. new cmLocalVisualStudio7Generator(this, parent, snapshot);
  264. return lg;
  265. }
  266. //----------------------------------------------------------------------------
  267. std::string const& cmGlobalVisualStudio7Generator::GetPlatformName() const
  268. {
  269. if(!this->GeneratorPlatform.empty())
  270. {
  271. return this->GeneratorPlatform;
  272. }
  273. return this->DefaultPlatformName;
  274. }
  275. //----------------------------------------------------------------------------
  276. bool cmGlobalVisualStudio7Generator::SetSystemName(std::string const& s,
  277. cmMakefile* mf)
  278. {
  279. mf->AddDefinition("CMAKE_VS_INTEL_Fortran_PROJECT_VERSION",
  280. this->GetIntelProjectVersion());
  281. return this->cmGlobalVisualStudioGenerator::SetSystemName(s, mf);
  282. }
  283. //----------------------------------------------------------------------------
  284. bool cmGlobalVisualStudio7Generator::SetGeneratorPlatform(std::string const& p,
  285. cmMakefile* mf)
  286. {
  287. if(this->GetPlatformName() == "x64")
  288. {
  289. mf->AddDefinition("CMAKE_FORCE_WIN64", "TRUE");
  290. }
  291. else if(this->GetPlatformName() == "Itanium")
  292. {
  293. mf->AddDefinition("CMAKE_FORCE_IA64", "TRUE");
  294. }
  295. mf->AddDefinition("CMAKE_VS_PLATFORM_NAME", this->GetPlatformName().c_str());
  296. return this->cmGlobalVisualStudioGenerator::SetGeneratorPlatform(p, mf);
  297. }
  298. void cmGlobalVisualStudio7Generator::Generate()
  299. {
  300. // first do the superclass method
  301. this->cmGlobalVisualStudioGenerator::Generate();
  302. // Now write out the DSW
  303. this->OutputSLNFile();
  304. // If any solution or project files changed during the generation,
  305. // tell Visual Studio to reload them...
  306. if(!cmSystemTools::GetErrorOccuredFlag())
  307. {
  308. this->CallVisualStudioMacro(MacroReload);
  309. }
  310. if (!this->CMakeInstance->GetIsInTryCompile() &&
  311. this->GetName() == "Visual Studio 7")
  312. {
  313. const char* cmakeWarnVS70 =
  314. this->CMakeInstance->GetState()->GetCacheEntryValue("CMAKE_WARN_VS70");
  315. if (!cmakeWarnVS70 || !cmSystemTools::IsOff(cmakeWarnVS70))
  316. {
  317. this->CMakeInstance->IssueMessage(
  318. cmake::WARNING,
  319. "The \"Visual Studio 7\" generator is deprecated "
  320. "and will be removed in a future version of CMake."
  321. "\n"
  322. "Add CMAKE_WARN_VS70=OFF to the cache to disable this warning."
  323. );
  324. }
  325. }
  326. }
  327. void cmGlobalVisualStudio7Generator
  328. ::OutputSLNFile(cmLocalGenerator* root,
  329. std::vector<cmLocalGenerator*>& generators)
  330. {
  331. if(generators.empty())
  332. {
  333. return;
  334. }
  335. this->CurrentProject = root->GetMakefile()->GetProjectName();
  336. std::string fname = root->GetMakefile()->GetCurrentBinaryDirectory();
  337. fname += "/";
  338. fname += root->GetMakefile()->GetProjectName();
  339. fname += ".sln";
  340. cmGeneratedFileStream fout(fname.c_str());
  341. fout.SetCopyIfDifferent(true);
  342. if(!fout)
  343. {
  344. return;
  345. }
  346. this->WriteSLNFile(fout, root, generators);
  347. if (fout.Close())
  348. {
  349. this->FileReplacedDuringGenerate(fname);
  350. }
  351. }
  352. // output the SLN file
  353. void cmGlobalVisualStudio7Generator::OutputSLNFile()
  354. {
  355. std::map<std::string, std::vector<cmLocalGenerator*> >::iterator it;
  356. for(it = this->ProjectMap.begin(); it!= this->ProjectMap.end(); ++it)
  357. {
  358. this->OutputSLNFile(it->second[0], it->second);
  359. }
  360. }
  361. void cmGlobalVisualStudio7Generator::WriteTargetConfigurations(
  362. std::ostream& fout,
  363. std::vector<std::string> const& configs,
  364. OrderedTargetDependSet const& projectTargets)
  365. {
  366. // loop over again and write out configurations for each target
  367. // in the solution
  368. for(OrderedTargetDependSet::const_iterator tt =
  369. projectTargets.begin(); tt != projectTargets.end(); ++tt)
  370. {
  371. cmTarget const* target = (*tt)->Target;
  372. if(target->GetType() == cmTarget::INTERFACE_LIBRARY)
  373. {
  374. continue;
  375. }
  376. const char* expath = target->GetProperty("EXTERNAL_MSPROJECT");
  377. if(expath)
  378. {
  379. std::set<std::string> allConfigurations(configs.begin(), configs.end());
  380. const char* mapping = target->GetProperty("VS_PLATFORM_MAPPING");
  381. this->WriteProjectConfigurations(
  382. fout, target->GetName().c_str(), target->GetType(),
  383. configs, allConfigurations, mapping ? mapping : "");
  384. }
  385. else
  386. {
  387. const std::set<std::string>& configsPartOfDefaultBuild =
  388. this->IsPartOfDefaultBuild(configs, projectTargets, target);
  389. const char *vcprojName =
  390. target->GetProperty("GENERATOR_FILE_NAME");
  391. if (vcprojName)
  392. {
  393. this->WriteProjectConfigurations(fout, vcprojName, target->GetType(),
  394. configs, configsPartOfDefaultBuild);
  395. }
  396. }
  397. }
  398. }
  399. void cmGlobalVisualStudio7Generator::WriteTargetsToSolution(
  400. std::ostream& fout,
  401. cmLocalGenerator* root,
  402. OrderedTargetDependSet const& projectTargets)
  403. {
  404. VisualStudioFolders.clear();
  405. for(OrderedTargetDependSet::const_iterator tt =
  406. projectTargets.begin(); tt != projectTargets.end(); ++tt)
  407. {
  408. cmTarget const* target = (*tt)->Target;
  409. if(target->GetType() == cmTarget::INTERFACE_LIBRARY)
  410. {
  411. continue;
  412. }
  413. bool written = false;
  414. // handle external vc project files
  415. const char* expath = target->GetProperty("EXTERNAL_MSPROJECT");
  416. if(expath)
  417. {
  418. std::string project = target->GetName();
  419. std::string location = expath;
  420. this->WriteExternalProject(fout,
  421. project.c_str(),
  422. location.c_str(),
  423. target->GetProperty("VS_PROJECT_TYPE"),
  424. target->GetUtilities());
  425. written = true;
  426. }
  427. else
  428. {
  429. const char *vcprojName =
  430. target->GetProperty("GENERATOR_FILE_NAME");
  431. if(vcprojName)
  432. {
  433. cmMakefile* tmf = target->GetMakefile();
  434. std::string dir = tmf->GetCurrentBinaryDirectory();
  435. dir = root->Convert(dir.c_str(),
  436. cmLocalGenerator::START_OUTPUT);
  437. if(dir == ".")
  438. {
  439. dir = ""; // msbuild cannot handle ".\" prefix
  440. }
  441. this->WriteProject(fout, vcprojName, dir.c_str(),
  442. *target);
  443. written = true;
  444. }
  445. }
  446. // Create "solution folder" information from FOLDER target property
  447. //
  448. if (written && this->UseFolderProperty())
  449. {
  450. const char *targetFolder = target->GetProperty("FOLDER");
  451. if (targetFolder)
  452. {
  453. std::vector<cmsys::String> tokens =
  454. cmSystemTools::SplitString(targetFolder, '/', false);
  455. std::string cumulativePath = "";
  456. for(std::vector<cmsys::String>::iterator iter = tokens.begin();
  457. iter != tokens.end(); ++iter)
  458. {
  459. if(!iter->size())
  460. {
  461. continue;
  462. }
  463. if (cumulativePath.empty())
  464. {
  465. cumulativePath = "CMAKE_FOLDER_GUID_" + *iter;
  466. }
  467. else
  468. {
  469. VisualStudioFolders[cumulativePath].insert(
  470. cumulativePath + "/" + *iter);
  471. cumulativePath = cumulativePath + "/" + *iter;
  472. }
  473. }
  474. if (!cumulativePath.empty())
  475. {
  476. VisualStudioFolders[cumulativePath].insert(target->GetName());
  477. }
  478. }
  479. }
  480. }
  481. }
  482. void cmGlobalVisualStudio7Generator::WriteTargetDepends(
  483. std::ostream& fout,
  484. OrderedTargetDependSet const& projectTargets
  485. )
  486. {
  487. for(OrderedTargetDependSet::const_iterator tt =
  488. projectTargets.begin(); tt != projectTargets.end(); ++tt)
  489. {
  490. cmTarget const* target = (*tt)->Target;
  491. if(target->GetType() == cmTarget::INTERFACE_LIBRARY)
  492. {
  493. continue;
  494. }
  495. cmMakefile* mf = target->GetMakefile();
  496. const char *vcprojName =
  497. target->GetProperty("GENERATOR_FILE_NAME");
  498. if (vcprojName)
  499. {
  500. std::string dir = mf->GetCurrentSourceDirectory();
  501. this->WriteProjectDepends(fout, vcprojName,
  502. dir.c_str(), *target);
  503. }
  504. }
  505. }
  506. //----------------------------------------------------------------------------
  507. // Write a SLN file to the stream
  508. void cmGlobalVisualStudio7Generator
  509. ::WriteSLNFile(std::ostream& fout,
  510. cmLocalGenerator* root,
  511. std::vector<cmLocalGenerator*>& generators)
  512. {
  513. std::vector<std::string> configs;
  514. root->GetMakefile()->GetConfigurations(configs);
  515. // Write out the header for a SLN file
  516. this->WriteSLNHeader(fout);
  517. // Collect all targets under this root generator and the transitive
  518. // closure of their dependencies.
  519. TargetDependSet projectTargets;
  520. TargetDependSet originalTargets;
  521. this->GetTargetSets(projectTargets, originalTargets, root, generators);
  522. OrderedTargetDependSet orderedProjectTargets(projectTargets);
  523. this->WriteTargetsToSolution(fout, root, orderedProjectTargets);
  524. bool useFolderProperty = this->UseFolderProperty();
  525. if (useFolderProperty)
  526. {
  527. this->WriteFolders(fout);
  528. }
  529. // Write out the configurations information for the solution
  530. fout << "Global\n"
  531. << "\tGlobalSection(SolutionConfiguration) = preSolution\n";
  532. int c = 0;
  533. for(std::vector<std::string>::iterator i = configs.begin();
  534. i != configs.end(); ++i)
  535. {
  536. fout << "\t\tConfigName." << c << " = " << *i << "\n";
  537. c++;
  538. }
  539. fout << "\tEndGlobalSection\n";
  540. // Write out project(target) depends
  541. fout << "\tGlobalSection(ProjectDependencies) = postSolution\n";
  542. this->WriteTargetDepends(fout, orderedProjectTargets);
  543. fout << "\tEndGlobalSection\n";
  544. if (useFolderProperty)
  545. {
  546. // Write out project folders
  547. fout << "\tGlobalSection(NestedProjects) = preSolution\n";
  548. this->WriteFoldersContent(fout);
  549. fout << "\tEndGlobalSection\n";
  550. }
  551. // Write out the configurations for all the targets in the project
  552. fout << "\tGlobalSection(ProjectConfiguration) = postSolution\n";
  553. this->WriteTargetConfigurations(fout, configs, orderedProjectTargets);
  554. fout << "\tEndGlobalSection\n";
  555. // Write out global sections
  556. this->WriteSLNGlobalSections(fout, root);
  557. // Write the footer for the SLN file
  558. this->WriteSLNFooter(fout);
  559. }
  560. //----------------------------------------------------------------------------
  561. void cmGlobalVisualStudio7Generator::WriteFolders(std::ostream& fout)
  562. {
  563. const char *prefix = "CMAKE_FOLDER_GUID_";
  564. const std::string::size_type skip_prefix = strlen(prefix);
  565. std::string guidProjectTypeFolder = "2150E333-8FDC-42A3-9474-1A3956D46DE8";
  566. for(std::map<std::string,std::set<std::string> >::iterator iter =
  567. VisualStudioFolders.begin(); iter != VisualStudioFolders.end(); ++iter)
  568. {
  569. std::string fullName = iter->first;
  570. std::string guid = this->GetGUID(fullName.c_str());
  571. cmSystemTools::ReplaceString(fullName, "/", "\\");
  572. if (cmSystemTools::StringStartsWith(fullName.c_str(), prefix))
  573. {
  574. fullName = fullName.substr(skip_prefix);
  575. }
  576. std::string nameOnly = cmSystemTools::GetFilenameName(fullName);
  577. fout << "Project(\"{" <<
  578. guidProjectTypeFolder << "}\") = \"" <<
  579. nameOnly << "\", \"" <<
  580. fullName << "\", \"{" <<
  581. guid <<
  582. "}\"\nEndProject\n";
  583. }
  584. }
  585. //----------------------------------------------------------------------------
  586. void cmGlobalVisualStudio7Generator::WriteFoldersContent(std::ostream& fout)
  587. {
  588. for(std::map<std::string,std::set<std::string> >::iterator iter =
  589. VisualStudioFolders.begin(); iter != VisualStudioFolders.end(); ++iter)
  590. {
  591. std::string key(iter->first);
  592. std::string guidParent(this->GetGUID(key.c_str()));
  593. for(std::set<std::string>::iterator it = iter->second.begin();
  594. it != iter->second.end(); ++it)
  595. {
  596. std::string value(*it);
  597. std::string guid(this->GetGUID(value.c_str()));
  598. fout << "\t\t{" << guid << "} = {" << guidParent << "}\n";
  599. }
  600. }
  601. }
  602. //----------------------------------------------------------------------------
  603. std::string
  604. cmGlobalVisualStudio7Generator::ConvertToSolutionPath(const char* path)
  605. {
  606. // Convert to backslashes. Do not use ConvertToOutputPath because
  607. // we will add quoting ourselves, and we know these projects always
  608. // use windows slashes.
  609. std::string d = path;
  610. std::string::size_type pos = 0;
  611. while((pos = d.find('/', pos)) != d.npos)
  612. {
  613. d[pos++] = '\\';
  614. }
  615. return d;
  616. }
  617. // Write a dsp file into the SLN file,
  618. // Note, that dependencies from executables to
  619. // the libraries it uses are also done here
  620. void cmGlobalVisualStudio7Generator::WriteProject(std::ostream& fout,
  621. const std::string& dspname,
  622. const char* dir, cmTarget const& target)
  623. {
  624. // check to see if this is a fortran build
  625. const char* ext = ".vcproj";
  626. const char* project =
  627. "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"";
  628. if(this->TargetIsFortranOnly(target))
  629. {
  630. ext = ".vfproj";
  631. project = "Project(\"{6989167D-11E4-40FE-8C1A-2192A86A7E90}\") = \"";
  632. }
  633. fout << project
  634. << dspname << "\", \""
  635. << this->ConvertToSolutionPath(dir) << (dir[0]? "\\":"")
  636. << dspname << ext << "\", \"{"
  637. << this->GetGUID(dspname) << "}\"\nEndProject\n";
  638. UtilityDependsMap::iterator ui = this->UtilityDepends.find(&target);
  639. if(ui != this->UtilityDepends.end())
  640. {
  641. const char* uname = ui->second.c_str();
  642. fout << "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \""
  643. << uname << "\", \""
  644. << this->ConvertToSolutionPath(dir) << (dir[0]? "\\":"")
  645. << uname << ".vcproj" << "\", \"{"
  646. << this->GetGUID(uname) << "}\"\n"
  647. << "EndProject\n";
  648. }
  649. }
  650. // Write a dsp file into the SLN file,
  651. // Note, that dependencies from executables to
  652. // the libraries it uses are also done here
  653. void
  654. cmGlobalVisualStudio7Generator
  655. ::WriteProjectDepends(std::ostream& fout,
  656. const std::string& dspname,
  657. const char*, cmTarget const& target)
  658. {
  659. int depcount = 0;
  660. std::string dspguid = this->GetGUID(dspname);
  661. VSDependSet const& depends = this->VSTargetDepends[&target];
  662. for(VSDependSet::const_iterator di = depends.begin();
  663. di != depends.end(); ++di)
  664. {
  665. const char* name = di->c_str();
  666. std::string guid = this->GetGUID(name);
  667. if(guid.empty())
  668. {
  669. std::string m = "Target: ";
  670. m += target.GetName();
  671. m += " depends on unknown target: ";
  672. m += name;
  673. cmSystemTools::Error(m.c_str());
  674. }
  675. fout << "\t\t{" << dspguid << "}." << depcount << " = {" << guid << "}\n";
  676. depcount++;
  677. }
  678. UtilityDependsMap::iterator ui = this->UtilityDepends.find(&target);
  679. if(ui != this->UtilityDepends.end())
  680. {
  681. const char* uname = ui->second.c_str();
  682. fout << "\t\t{" << this->GetGUID(uname) << "}.0 = {" << dspguid << "}\n";
  683. }
  684. }
  685. // Write a dsp file into the SLN file, Note, that dependencies from
  686. // executables to the libraries it uses are also done here
  687. void cmGlobalVisualStudio7Generator
  688. ::WriteProjectConfigurations(
  689. std::ostream& fout, const std::string& name, cmTarget::TargetType,
  690. std::vector<std::string> const& configs,
  691. const std::set<std::string>& configsPartOfDefaultBuild,
  692. const std::string& platformMapping)
  693. {
  694. const std::string& platformName =
  695. !platformMapping.empty() ? platformMapping : this->GetPlatformName();
  696. std::string guid = this->GetGUID(name);
  697. for(std::vector<std::string>::const_iterator i = configs.begin();
  698. i != configs.end(); ++i)
  699. {
  700. fout << "\t\t{" << guid << "}." << *i
  701. << ".ActiveCfg = " << *i << "|" << platformName << "\n";
  702. std::set<std::string>::const_iterator
  703. ci = configsPartOfDefaultBuild.find(*i);
  704. if(!(ci == configsPartOfDefaultBuild.end()))
  705. {
  706. fout << "\t\t{" << guid << "}." << *i
  707. << ".Build.0 = " << *i << "|" << platformName << "\n";
  708. }
  709. }
  710. }
  711. // Write a dsp file into the SLN file,
  712. // Note, that dependencies from executables to
  713. // the libraries it uses are also done here
  714. void cmGlobalVisualStudio7Generator::WriteExternalProject(std::ostream& fout,
  715. const std::string& name,
  716. const char* location,
  717. const char* typeGuid,
  718. const std::set<std::string>&)
  719. {
  720. fout << "Project("
  721. << "\"{"
  722. << (typeGuid ? typeGuid : this->ExternalProjectType(location))
  723. << "}\") = \""
  724. << name << "\", \""
  725. << this->ConvertToSolutionPath(location) << "\", \"{"
  726. << this->GetGUID(name)
  727. << "}\"\n";
  728. fout << "EndProject\n";
  729. }
  730. void cmGlobalVisualStudio7Generator
  731. ::WriteSLNGlobalSections(std::ostream& fout,
  732. cmLocalGenerator* root)
  733. {
  734. bool extensibilityGlobalsOverridden = false;
  735. bool extensibilityAddInsOverridden = false;
  736. const std::vector<std::string> propKeys =
  737. root->GetMakefile()->GetPropertyKeys();
  738. for(std::vector<std::string>::const_iterator it = propKeys.begin();
  739. it != propKeys.end(); ++it)
  740. {
  741. if(it->find("VS_GLOBAL_SECTION_") == 0)
  742. {
  743. std::string sectionType;
  744. std::string name = it->substr(18);
  745. if(name.find("PRE_") == 0)
  746. {
  747. name = name.substr(4);
  748. sectionType = "preSolution";
  749. }
  750. else if(name.find("POST_") == 0)
  751. {
  752. name = name.substr(5);
  753. sectionType = "postSolution";
  754. }
  755. else
  756. continue;
  757. if(!name.empty())
  758. {
  759. if(name == "ExtensibilityGlobals" && sectionType == "postSolution")
  760. extensibilityGlobalsOverridden = true;
  761. else if(name == "ExtensibilityAddIns" && sectionType == "postSolution")
  762. extensibilityAddInsOverridden = true;
  763. fout << "\tGlobalSection(" << name << ") = " << sectionType << "\n";
  764. std::vector<std::string> keyValuePairs;
  765. cmSystemTools::ExpandListArgument(
  766. root->GetMakefile()->GetProperty(it->c_str()),
  767. keyValuePairs);
  768. for(std::vector<std::string>::const_iterator itPair =
  769. keyValuePairs.begin(); itPair != keyValuePairs.end(); ++itPair)
  770. {
  771. const std::string::size_type posEqual = itPair->find('=');
  772. if(posEqual != std::string::npos)
  773. {
  774. const std::string key =
  775. cmSystemTools::TrimWhitespace(itPair->substr(0, posEqual));
  776. const std::string value =
  777. cmSystemTools::TrimWhitespace(itPair->substr(posEqual + 1));
  778. fout << "\t\t" << key << " = " << value << "\n";
  779. }
  780. }
  781. fout << "\tEndGlobalSection\n";
  782. }
  783. }
  784. }
  785. if(!extensibilityGlobalsOverridden)
  786. fout << "\tGlobalSection(ExtensibilityGlobals) = postSolution\n"
  787. << "\tEndGlobalSection\n";
  788. if(!extensibilityAddInsOverridden)
  789. fout << "\tGlobalSection(ExtensibilityAddIns) = postSolution\n"
  790. << "\tEndGlobalSection\n";
  791. }
  792. // Standard end of dsw file
  793. void cmGlobalVisualStudio7Generator::WriteSLNFooter(std::ostream& fout)
  794. {
  795. fout << "EndGlobal\n";
  796. }
  797. // ouput standard header for dsw file
  798. void cmGlobalVisualStudio7Generator::WriteSLNHeader(std::ostream& fout)
  799. {
  800. fout << "Microsoft Visual Studio Solution File, Format Version 7.00\n";
  801. }
  802. //----------------------------------------------------------------------------
  803. std::string
  804. cmGlobalVisualStudio7Generator::WriteUtilityDepend(cmTarget const* target)
  805. {
  806. std::vector<std::string> configs;
  807. target->GetMakefile()->GetConfigurations(configs);
  808. std::string pname = target->GetName();
  809. pname += "_UTILITY";
  810. std::string fname = target->GetMakefile()->GetCurrentBinaryDirectory();
  811. fname += "/";
  812. fname += pname;
  813. fname += ".vcproj";
  814. cmGeneratedFileStream fout(fname.c_str());
  815. fout.SetCopyIfDifferent(true);
  816. std::string guid = this->GetGUID(pname.c_str());
  817. fout <<
  818. "<?xml version=\"1.0\" encoding = \""
  819. << this->Encoding() << "\"?>\n"
  820. "<VisualStudioProject\n"
  821. "\tProjectType=\"Visual C++\"\n"
  822. "\tVersion=\"" << this->GetIDEVersion() << "0\"\n"
  823. "\tName=\"" << pname << "\"\n"
  824. "\tProjectGUID=\"{" << guid << "}\"\n"
  825. "\tKeyword=\"Win32Proj\">\n"
  826. "\t<Platforms><Platform Name=\"Win32\"/></Platforms>\n"
  827. "\t<Configurations>\n"
  828. ;
  829. for(std::vector<std::string>::iterator i = configs.begin();
  830. i != configs.end(); ++i)
  831. {
  832. fout <<
  833. "\t\t<Configuration\n"
  834. "\t\t\tName=\"" << *i << "|Win32\"\n"
  835. "\t\t\tOutputDirectory=\"" << *i << "\"\n"
  836. "\t\t\tIntermediateDirectory=\"" << pname << ".dir\\" << *i << "\"\n"
  837. "\t\t\tConfigurationType=\"10\"\n"
  838. "\t\t\tUseOfMFC=\"0\"\n"
  839. "\t\t\tATLMinimizesCRunTimeLibraryUsage=\"FALSE\"\n"
  840. "\t\t\tCharacterSet=\"2\">\n"
  841. "\t\t</Configuration>\n"
  842. ;
  843. }
  844. fout <<
  845. "\t</Configurations>\n"
  846. "\t<Files></Files>\n"
  847. "\t<Globals></Globals>\n"
  848. "</VisualStudioProject>\n"
  849. ;
  850. if(fout.Close())
  851. {
  852. this->FileReplacedDuringGenerate(fname);
  853. }
  854. return pname;
  855. }
  856. //----------------------------------------------------------------------------
  857. std::string cmGlobalVisualStudio7Generator::GetGUID(std::string const& name)
  858. {
  859. std::string const& guidStoreName = name + "_GUID_CMAKE";
  860. if (const char* storedGUID =
  861. this->CMakeInstance->GetCacheDefinition(guidStoreName.c_str()))
  862. {
  863. return std::string(storedGUID);
  864. }
  865. // Compute a GUID that is deterministic but unique to the build tree.
  866. std::string input = this->CMakeInstance->GetState()->GetBinaryDirectory();
  867. input += "|";
  868. input += name;
  869. cmUuid uuidGenerator;
  870. std::vector<unsigned char> uuidNamespace;
  871. uuidGenerator.StringToBinary(
  872. "ee30c4be-5192-4fb0-b335-722a2dffe760", uuidNamespace);
  873. std::string guid = uuidGenerator.FromMd5(uuidNamespace, input);
  874. return cmSystemTools::UpperCase(guid);
  875. }
  876. //----------------------------------------------------------------------------
  877. void cmGlobalVisualStudio7Generator
  878. ::GetDocumentation(cmDocumentationEntry& entry)
  879. {
  880. entry.Name = cmGlobalVisualStudio7Generator::GetActualName();
  881. entry.Brief = "Deprecated. Generates Visual Studio .NET 2002 project files.";
  882. }
  883. //----------------------------------------------------------------------------
  884. void
  885. cmGlobalVisualStudio7Generator
  886. ::AppendDirectoryForConfig(const std::string& prefix,
  887. const std::string& config,
  888. const std::string& suffix,
  889. std::string& dir)
  890. {
  891. if(!config.empty())
  892. {
  893. dir += prefix;
  894. dir += config;
  895. dir += suffix;
  896. }
  897. }
  898. std::set<std::string>
  899. cmGlobalVisualStudio7Generator::IsPartOfDefaultBuild(
  900. std::vector<std::string> const& configs,
  901. OrderedTargetDependSet const& projectTargets, cmTarget const* target)
  902. {
  903. std::set<std::string> activeConfigs;
  904. // if it is a utilitiy target then only make it part of the
  905. // default build if another target depends on it
  906. int type = target->GetType();
  907. if (type == cmTarget::GLOBAL_TARGET)
  908. {
  909. // check if INSTALL target is part of default build
  910. if(target->GetName() == "INSTALL")
  911. {
  912. // inspect CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD properties
  913. for(std::vector<std::string>::const_iterator i = configs.begin();
  914. i != configs.end(); ++i)
  915. {
  916. const char* propertyValue = target->GetMakefile()
  917. ->GetDefinition("CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD");
  918. cmGeneratorExpression ge;
  919. cmsys::auto_ptr<cmCompiledGeneratorExpression>
  920. cge = ge.Parse(propertyValue);
  921. if(cmSystemTools::IsOn(cge->Evaluate(target->GetMakefile(), *i)))
  922. {
  923. activeConfigs.insert(*i);
  924. }
  925. }
  926. }
  927. return activeConfigs;
  928. }
  929. if(type == cmTarget::UTILITY && !this->IsDependedOn(projectTargets, target))
  930. {
  931. return activeConfigs;
  932. }
  933. cmGeneratorTarget* gt = this->GetGeneratorTarget(target);
  934. // inspect EXCLUDE_FROM_DEFAULT_BUILD[_<CONFIG>] properties
  935. for(std::vector<std::string>::const_iterator i = configs.begin();
  936. i != configs.end(); ++i)
  937. {
  938. const char* propertyValue =
  939. gt->GetFeature("EXCLUDE_FROM_DEFAULT_BUILD", i->c_str());
  940. if(cmSystemTools::IsOff(propertyValue))
  941. {
  942. activeConfigs.insert(*i);
  943. }
  944. }
  945. return activeConfigs;
  946. }
  947. bool
  948. cmGlobalVisualStudio7Generator
  949. ::IsDependedOn(OrderedTargetDependSet const& projectTargets,
  950. cmTarget const* targetIn)
  951. {
  952. cmGeneratorTarget* gtIn = this->GetGeneratorTarget(targetIn);
  953. for (OrderedTargetDependSet::const_iterator l = projectTargets.begin();
  954. l != projectTargets.end(); ++l)
  955. {
  956. TargetDependSet const& tgtdeps = this->GetTargetDirectDepends(*l);
  957. if(tgtdeps.count(gtIn))
  958. {
  959. return true;
  960. }
  961. }
  962. return false;
  963. }
  964. std::string cmGlobalVisualStudio7Generator::Encoding()
  965. {
  966. std::ostringstream encoding;
  967. #ifdef CMAKE_ENCODING_UTF8
  968. encoding << "UTF-8";
  969. #else
  970. encoding << "Windows-1252";
  971. #endif
  972. return encoding.str();
  973. }