cmGlobalVisualStudio7Generator.cxx 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036
  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 "cmake.h"
  17. #include <cmsys/Encoding.hxx>
  18. cmGlobalVisualStudio7Generator::cmGlobalVisualStudio7Generator(
  19. const char* platformName)
  20. {
  21. this->IntelProjectVersion = 0;
  22. this->DevEnvCommandInitialized = false;
  23. if (!platformName)
  24. {
  25. platformName = "Win32";
  26. }
  27. this->PlatformName = platformName;
  28. }
  29. cmGlobalVisualStudio7Generator::~cmGlobalVisualStudio7Generator()
  30. {
  31. free(this->IntelProjectVersion);
  32. }
  33. // Package GUID of Intel Visual Fortran plugin to VS IDE
  34. #define CM_INTEL_PLUGIN_GUID "{B68A201D-CB9B-47AF-A52F-7EEC72E217E4}"
  35. const char* cmGlobalVisualStudio7Generator::GetIntelProjectVersion()
  36. {
  37. if(!this->IntelProjectVersion)
  38. {
  39. // Compute the version of the Intel plugin to the VS IDE.
  40. // If the key does not exist then use a default guess.
  41. std::string intelVersion;
  42. std::string vskey = this->GetRegistryBase();
  43. vskey += "\\Packages\\" CM_INTEL_PLUGIN_GUID ";ProductVersion";
  44. cmSystemTools::ReadRegistryValue(vskey.c_str(), intelVersion,
  45. cmSystemTools::KeyWOW64_32);
  46. unsigned int intelVersionNumber = ~0u;
  47. sscanf(intelVersion.c_str(), "%u", &intelVersionNumber);
  48. if(intelVersionNumber >= 11)
  49. {
  50. // Default to latest known project file version.
  51. intelVersion = "11.0";
  52. }
  53. else if(intelVersionNumber == 10)
  54. {
  55. // Version 10.x actually uses 9.10 in project files!
  56. intelVersion = "9.10";
  57. }
  58. else
  59. {
  60. // Version <= 9: use ProductVersion from registry.
  61. }
  62. this->IntelProjectVersion = strdup(intelVersion.c_str());
  63. }
  64. return this->IntelProjectVersion;
  65. }
  66. void cmGlobalVisualStudio7Generator
  67. ::EnableLanguage(std::vector<std::string>const & lang,
  68. cmMakefile *mf, bool optional)
  69. {
  70. mf->AddDefinition("CMAKE_GENERATOR_RC", "rc");
  71. mf->AddDefinition("CMAKE_GENERATOR_NO_COMPILER_ENV", "1");
  72. this->AddPlatformDefinitions(mf);
  73. if(!mf->GetDefinition("CMAKE_CONFIGURATION_TYPES"))
  74. {
  75. mf->AddCacheDefinition(
  76. "CMAKE_CONFIGURATION_TYPES",
  77. "Debug;Release;MinSizeRel;RelWithDebInfo",
  78. "Semicolon separated list of supported configuration types, "
  79. "only supports Debug, Release, MinSizeRel, and RelWithDebInfo, "
  80. "anything else will be ignored.",
  81. cmCacheManager::STRING);
  82. }
  83. // Create list of configurations requested by user's cache, if any.
  84. this->cmGlobalGenerator::EnableLanguage(lang, mf, optional);
  85. this->GenerateConfigurations(mf);
  86. // if this environment variable is set, then copy it to
  87. // a static cache entry. It will be used by
  88. // cmLocalGenerator::ConstructScript, to add an extra PATH
  89. // to all custom commands. This is because the VS IDE
  90. // does not use the environment it is run in, and this allows
  91. // for running commands and using dll's that the IDE environment
  92. // does not know about.
  93. const char* extraPath = cmSystemTools::GetEnv("CMAKE_MSVCIDE_RUN_PATH");
  94. if(extraPath)
  95. {
  96. mf->AddCacheDefinition
  97. ("CMAKE_MSVCIDE_RUN_PATH", extraPath,
  98. "Saved environment variable CMAKE_MSVCIDE_RUN_PATH",
  99. cmCacheManager::STATIC);
  100. }
  101. }
  102. //----------------------------------------------------------------------------
  103. void cmGlobalVisualStudio7Generator::FindMakeProgram(cmMakefile* mf)
  104. {
  105. this->cmGlobalVisualStudioGenerator::FindMakeProgram(mf);
  106. mf->AddDefinition("CMAKE_VS_DEVENV_COMMAND",
  107. this->GetDevEnvCommand().c_str());
  108. }
  109. //----------------------------------------------------------------------------
  110. std::string const& cmGlobalVisualStudio7Generator::GetDevEnvCommand()
  111. {
  112. if(!this->DevEnvCommandInitialized)
  113. {
  114. this->DevEnvCommandInitialized = true;
  115. this->DevEnvCommand = this->FindDevEnvCommand();
  116. }
  117. return this->DevEnvCommand;
  118. }
  119. //----------------------------------------------------------------------------
  120. std::string cmGlobalVisualStudio7Generator::FindDevEnvCommand()
  121. {
  122. std::string vscmd;
  123. std::string vskey = this->GetRegistryBase() + ";InstallDir";
  124. if(cmSystemTools::ReadRegistryValue(vskey.c_str(), vscmd,
  125. cmSystemTools::KeyWOW64_32))
  126. {
  127. cmSystemTools::ConvertToUnixSlashes(vscmd);
  128. vscmd += "/";
  129. }
  130. vscmd += "devenv.com";
  131. return vscmd;
  132. }
  133. //----------------------------------------------------------------------------
  134. const char* cmGlobalVisualStudio7Generator::ExternalProjectType(
  135. const char* location)
  136. {
  137. std::string extension = cmSystemTools::GetFilenameLastExtension(location);
  138. if (extension == ".vbproj")
  139. {
  140. return "F184B08F-C81C-45F6-A57F-5ABD9991F28F";
  141. }
  142. else if (extension == ".csproj")
  143. {
  144. return "FAE04EC0-301F-11D3-BF4B-00C04F79EFBC";
  145. }
  146. else if (extension == ".fsproj")
  147. {
  148. return "F2A71F9B-5D33-465A-A702-920D77279786";
  149. }
  150. else if (extension == ".vdproj")
  151. {
  152. return "54435603-DBB4-11D2-8724-00A0C9A8B90C";
  153. }
  154. else if (extension == ".dbproj")
  155. {
  156. return "C8D11400-126E-41CD-887F-60BD40844F9E";
  157. }
  158. else if (extension == ".wixproj")
  159. {
  160. return "930C7802-8A8C-48F9-8165-68863BCCD9DD";
  161. }
  162. else if (extension == ".pyproj")
  163. {
  164. return "888888A0-9F3D-457C-B088-3A5042F75D52";
  165. }
  166. return "8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942";
  167. }
  168. //----------------------------------------------------------------------------
  169. void cmGlobalVisualStudio7Generator::GenerateBuildCommand(
  170. std::vector<std::string>& makeCommand,
  171. const char* makeProgram,
  172. const std::string& projectName,
  173. const std::string& /*projectDir*/,
  174. const std::string& targetName,
  175. const std::string& config,
  176. bool /*fast*/,
  177. std::vector<std::string> const& makeOptions)
  178. {
  179. // Select the caller- or user-preferred make program, else devenv.
  180. std::string makeProgramSelected =
  181. this->SelectMakeProgram(makeProgram, this->GetDevEnvCommand());
  182. // Ignore the above preference if it is msbuild.
  183. // Assume any other value is either a devenv or
  184. // command-line compatible with devenv.
  185. std::string makeProgramLower = makeProgramSelected;
  186. cmSystemTools::LowerCase(makeProgramLower);
  187. if(makeProgramLower.find("msbuild") != std::string::npos)
  188. {
  189. makeProgramSelected = this->GetDevEnvCommand();
  190. }
  191. makeCommand.push_back(makeProgramSelected);
  192. makeCommand.push_back(std::string(projectName) + ".sln");
  193. std::string realTarget = targetName;
  194. bool clean = false;
  195. if ( realTarget == "clean" )
  196. {
  197. clean = true;
  198. realTarget = "ALL_BUILD";
  199. }
  200. if(clean)
  201. {
  202. makeCommand.push_back("/clean");
  203. }
  204. else
  205. {
  206. makeCommand.push_back("/build");
  207. }
  208. if(!config.empty())
  209. {
  210. makeCommand.push_back(config);
  211. }
  212. else
  213. {
  214. makeCommand.push_back("Debug");
  215. }
  216. makeCommand.push_back("/project");
  217. if (!realTarget.empty())
  218. {
  219. makeCommand.push_back(realTarget);
  220. }
  221. else
  222. {
  223. makeCommand.push_back("ALL_BUILD");
  224. }
  225. makeCommand.insert(makeCommand.end(),
  226. makeOptions.begin(), makeOptions.end());
  227. }
  228. ///! Create a local generator appropriate to this Global Generator
  229. cmLocalGenerator *cmGlobalVisualStudio7Generator::CreateLocalGenerator()
  230. {
  231. cmLocalVisualStudio7Generator *lg =
  232. new cmLocalVisualStudio7Generator(cmLocalVisualStudioGenerator::VS7);
  233. lg->SetExtraFlagTable(this->GetExtraFlagTableVS7());
  234. lg->SetGlobalGenerator(this);
  235. return lg;
  236. }
  237. //----------------------------------------------------------------------------
  238. void cmGlobalVisualStudio7Generator::AddPlatformDefinitions(cmMakefile* mf)
  239. {
  240. cmGlobalVisualStudioGenerator::AddPlatformDefinitions(mf);
  241. mf->AddDefinition("CMAKE_VS_PLATFORM_NAME", this->GetPlatformName());
  242. mf->AddDefinition("CMAKE_VS_INTEL_Fortran_PROJECT_VERSION",
  243. this->GetIntelProjectVersion());
  244. }
  245. void cmGlobalVisualStudio7Generator::GenerateConfigurations(cmMakefile* mf)
  246. {
  247. // process the configurations
  248. const char* ct
  249. = this->CMakeInstance->GetCacheDefinition("CMAKE_CONFIGURATION_TYPES");
  250. if ( ct )
  251. {
  252. std::vector<std::string> argsOut;
  253. cmSystemTools::ExpandListArgument(ct, argsOut);
  254. for(std::vector<std::string>::iterator i = argsOut.begin();
  255. i != argsOut.end(); ++i)
  256. {
  257. if(std::find(this->Configurations.begin(),
  258. this->Configurations.end(),
  259. *i) == this->Configurations.end())
  260. {
  261. this->Configurations.push_back(*i);
  262. }
  263. }
  264. }
  265. // default to at least Debug and Release
  266. if(this->Configurations.size() == 0)
  267. {
  268. this->Configurations.push_back("Debug");
  269. this->Configurations.push_back("Release");
  270. }
  271. // Reset the entry to have a semi-colon separated list.
  272. std::string configs = this->Configurations[0];
  273. for(unsigned int i=1; i < this->Configurations.size(); ++i)
  274. {
  275. configs += ";";
  276. configs += this->Configurations[i];
  277. }
  278. mf->AddCacheDefinition(
  279. "CMAKE_CONFIGURATION_TYPES",
  280. configs.c_str(),
  281. "Semicolon separated list of supported configuration types, "
  282. "only supports Debug, Release, MinSizeRel, and RelWithDebInfo, "
  283. "anything else will be ignored.",
  284. cmCacheManager::STRING);
  285. }
  286. void cmGlobalVisualStudio7Generator::Generate()
  287. {
  288. // first do the superclass method
  289. this->cmGlobalVisualStudioGenerator::Generate();
  290. // Now write out the DSW
  291. this->OutputSLNFile();
  292. // If any solution or project files changed during the generation,
  293. // tell Visual Studio to reload them...
  294. if(!cmSystemTools::GetErrorOccuredFlag())
  295. {
  296. this->CallVisualStudioMacro(MacroReload);
  297. }
  298. }
  299. void cmGlobalVisualStudio7Generator
  300. ::OutputSLNFile(cmLocalGenerator* root,
  301. std::vector<cmLocalGenerator*>& generators)
  302. {
  303. if(generators.size() == 0)
  304. {
  305. return;
  306. }
  307. this->CurrentProject = root->GetMakefile()->GetProjectName();
  308. std::string fname = root->GetMakefile()->GetStartOutputDirectory();
  309. fname += "/";
  310. fname += root->GetMakefile()->GetProjectName();
  311. fname += ".sln";
  312. cmGeneratedFileStream fout(fname.c_str());
  313. fout.SetCopyIfDifferent(true);
  314. if(!fout)
  315. {
  316. return;
  317. }
  318. this->WriteSLNFile(fout, root, generators);
  319. if (fout.Close())
  320. {
  321. this->FileReplacedDuringGenerate(fname);
  322. }
  323. }
  324. // output the SLN file
  325. void cmGlobalVisualStudio7Generator::OutputSLNFile()
  326. {
  327. std::map<std::string, std::vector<cmLocalGenerator*> >::iterator it;
  328. for(it = this->ProjectMap.begin(); it!= this->ProjectMap.end(); ++it)
  329. {
  330. this->OutputSLNFile(it->second[0], it->second);
  331. }
  332. }
  333. void cmGlobalVisualStudio7Generator::WriteTargetConfigurations(
  334. std::ostream& fout,
  335. cmLocalGenerator* root,
  336. OrderedTargetDependSet const& projectTargets)
  337. {
  338. // loop over again and write out configurations for each target
  339. // in the solution
  340. for(OrderedTargetDependSet::const_iterator tt =
  341. projectTargets.begin(); tt != projectTargets.end(); ++tt)
  342. {
  343. cmTarget const* target = *tt;
  344. if(target->GetType() == cmTarget::INTERFACE_LIBRARY)
  345. {
  346. continue;
  347. }
  348. const char* expath = target->GetProperty("EXTERNAL_MSPROJECT");
  349. if(expath)
  350. {
  351. std::set<std::string> allConfigurations(this->Configurations.begin(),
  352. this->Configurations.end());
  353. this->WriteProjectConfigurations(
  354. fout, target->GetName().c_str(), target->GetType(),
  355. allConfigurations, target->GetProperty("VS_PLATFORM_MAPPING"));
  356. }
  357. else
  358. {
  359. const std::set<std::string>& configsPartOfDefaultBuild =
  360. this->IsPartOfDefaultBuild(root->GetMakefile()->GetProjectName(),
  361. target);
  362. const char *vcprojName =
  363. target->GetProperty("GENERATOR_FILE_NAME");
  364. if (vcprojName)
  365. {
  366. this->WriteProjectConfigurations(fout, vcprojName, target->GetType(),
  367. configsPartOfDefaultBuild);
  368. }
  369. }
  370. }
  371. }
  372. void cmGlobalVisualStudio7Generator::WriteTargetsToSolution(
  373. std::ostream& fout,
  374. cmLocalGenerator* root,
  375. OrderedTargetDependSet const& projectTargets)
  376. {
  377. VisualStudioFolders.clear();
  378. for(OrderedTargetDependSet::const_iterator tt =
  379. projectTargets.begin(); tt != projectTargets.end(); ++tt)
  380. {
  381. cmTarget const* target = *tt;
  382. if(target->GetType() == cmTarget::INTERFACE_LIBRARY)
  383. {
  384. continue;
  385. }
  386. bool written = false;
  387. // handle external vc project files
  388. const char* expath = target->GetProperty("EXTERNAL_MSPROJECT");
  389. if(expath)
  390. {
  391. std::string project = target->GetName();
  392. std::string location = expath;
  393. this->WriteExternalProject(fout,
  394. project.c_str(),
  395. location.c_str(),
  396. target->GetProperty("VS_PROJECT_TYPE"),
  397. target->GetUtilities());
  398. written = true;
  399. }
  400. else
  401. {
  402. const char *vcprojName =
  403. target->GetProperty("GENERATOR_FILE_NAME");
  404. if(vcprojName)
  405. {
  406. cmMakefile* tmf = target->GetMakefile();
  407. std::string dir = tmf->GetStartOutputDirectory();
  408. dir = root->Convert(dir.c_str(),
  409. cmLocalGenerator::START_OUTPUT);
  410. if(dir == ".")
  411. {
  412. dir = ""; // msbuild cannot handle ".\" prefix
  413. }
  414. this->WriteProject(fout, vcprojName, dir.c_str(),
  415. *target);
  416. written = true;
  417. }
  418. }
  419. // Create "solution folder" information from FOLDER target property
  420. //
  421. if (written && this->UseFolderProperty())
  422. {
  423. const char *targetFolder = target->GetProperty("FOLDER");
  424. if (targetFolder)
  425. {
  426. std::vector<cmsys::String> tokens =
  427. cmSystemTools::SplitString(targetFolder, '/', false);
  428. std::string cumulativePath = "";
  429. for(std::vector<cmsys::String>::iterator iter = tokens.begin();
  430. iter != tokens.end(); ++iter)
  431. {
  432. if(!iter->size())
  433. {
  434. continue;
  435. }
  436. if (cumulativePath.empty())
  437. {
  438. cumulativePath = "CMAKE_FOLDER_GUID_" + *iter;
  439. }
  440. else
  441. {
  442. VisualStudioFolders[cumulativePath].insert(
  443. cumulativePath + "/" + *iter);
  444. cumulativePath = cumulativePath + "/" + *iter;
  445. }
  446. this->CreateGUID(cumulativePath.c_str());
  447. }
  448. if (!cumulativePath.empty())
  449. {
  450. VisualStudioFolders[cumulativePath].insert(target->GetName());
  451. }
  452. }
  453. }
  454. }
  455. }
  456. void cmGlobalVisualStudio7Generator::WriteTargetDepends(
  457. std::ostream& fout,
  458. OrderedTargetDependSet const& projectTargets
  459. )
  460. {
  461. for(OrderedTargetDependSet::const_iterator tt =
  462. projectTargets.begin(); tt != projectTargets.end(); ++tt)
  463. {
  464. cmTarget const* target = *tt;
  465. if(target->GetType() == cmTarget::INTERFACE_LIBRARY)
  466. {
  467. continue;
  468. }
  469. cmMakefile* mf = target->GetMakefile();
  470. const char *vcprojName =
  471. target->GetProperty("GENERATOR_FILE_NAME");
  472. if (vcprojName)
  473. {
  474. std::string dir = mf->GetStartDirectory();
  475. this->WriteProjectDepends(fout, vcprojName,
  476. dir.c_str(), *target);
  477. }
  478. }
  479. }
  480. //----------------------------------------------------------------------------
  481. // Write a SLN file to the stream
  482. void cmGlobalVisualStudio7Generator
  483. ::WriteSLNFile(std::ostream& fout,
  484. cmLocalGenerator* root,
  485. std::vector<cmLocalGenerator*>& generators)
  486. {
  487. // Write out the header for a SLN file
  488. this->WriteSLNHeader(fout);
  489. // Collect all targets under this root generator and the transitive
  490. // closure of their dependencies.
  491. TargetDependSet projectTargets;
  492. TargetDependSet originalTargets;
  493. this->GetTargetSets(projectTargets, originalTargets, root, generators);
  494. OrderedTargetDependSet orderedProjectTargets(projectTargets);
  495. this->WriteTargetsToSolution(fout, root, orderedProjectTargets);
  496. bool useFolderProperty = this->UseFolderProperty();
  497. if (useFolderProperty)
  498. {
  499. this->WriteFolders(fout);
  500. }
  501. // Write out the configurations information for the solution
  502. fout << "Global\n"
  503. << "\tGlobalSection(SolutionConfiguration) = preSolution\n";
  504. int c = 0;
  505. for(std::vector<std::string>::iterator i = this->Configurations.begin();
  506. i != this->Configurations.end(); ++i)
  507. {
  508. fout << "\t\tConfigName." << c << " = " << *i << "\n";
  509. c++;
  510. }
  511. fout << "\tEndGlobalSection\n";
  512. // Write out project(target) depends
  513. fout << "\tGlobalSection(ProjectDependencies) = postSolution\n";
  514. this->WriteTargetDepends(fout, orderedProjectTargets);
  515. fout << "\tEndGlobalSection\n";
  516. if (useFolderProperty)
  517. {
  518. // Write out project folders
  519. fout << "\tGlobalSection(NestedProjects) = preSolution\n";
  520. this->WriteFoldersContent(fout);
  521. fout << "\tEndGlobalSection\n";
  522. }
  523. // Write out the configurations for all the targets in the project
  524. fout << "\tGlobalSection(ProjectConfiguration) = postSolution\n";
  525. this->WriteTargetConfigurations(fout, root, orderedProjectTargets);
  526. fout << "\tEndGlobalSection\n";
  527. // Write out global sections
  528. this->WriteSLNGlobalSections(fout, root);
  529. // Write the footer for the SLN file
  530. this->WriteSLNFooter(fout);
  531. }
  532. //----------------------------------------------------------------------------
  533. void cmGlobalVisualStudio7Generator::WriteFolders(std::ostream& fout)
  534. {
  535. const char *prefix = "CMAKE_FOLDER_GUID_";
  536. const std::string::size_type skip_prefix = strlen(prefix);
  537. std::string guidProjectTypeFolder = "2150E333-8FDC-42A3-9474-1A3956D46DE8";
  538. for(std::map<std::string,std::set<std::string> >::iterator iter =
  539. VisualStudioFolders.begin(); iter != VisualStudioFolders.end(); ++iter)
  540. {
  541. std::string fullName = iter->first;
  542. std::string guid = this->GetGUID(fullName.c_str());
  543. cmSystemTools::ReplaceString(fullName, "/", "\\");
  544. if (cmSystemTools::StringStartsWith(fullName.c_str(), prefix))
  545. {
  546. fullName = fullName.substr(skip_prefix);
  547. }
  548. std::string nameOnly = cmSystemTools::GetFilenameName(fullName);
  549. fout << "Project(\"{" <<
  550. guidProjectTypeFolder << "}\") = \"" <<
  551. nameOnly << "\", \"" <<
  552. fullName << "\", \"{" <<
  553. guid <<
  554. "}\"\nEndProject\n";
  555. }
  556. }
  557. //----------------------------------------------------------------------------
  558. void cmGlobalVisualStudio7Generator::WriteFoldersContent(std::ostream& fout)
  559. {
  560. for(std::map<std::string,std::set<std::string> >::iterator iter =
  561. VisualStudioFolders.begin(); iter != VisualStudioFolders.end(); ++iter)
  562. {
  563. std::string key(iter->first);
  564. std::string guidParent(this->GetGUID(key.c_str()));
  565. for(std::set<std::string>::iterator it = iter->second.begin();
  566. it != iter->second.end(); ++it)
  567. {
  568. std::string value(*it);
  569. std::string guid(this->GetGUID(value.c_str()));
  570. fout << "\t\t{" << guid << "} = {" << guidParent << "}\n";
  571. }
  572. }
  573. }
  574. //----------------------------------------------------------------------------
  575. std::string
  576. cmGlobalVisualStudio7Generator::ConvertToSolutionPath(const char* path)
  577. {
  578. // Convert to backslashes. Do not use ConvertToOutputPath because
  579. // we will add quoting ourselves, and we know these projects always
  580. // use windows slashes.
  581. std::string d = path;
  582. std::string::size_type pos = 0;
  583. while((pos = d.find('/', pos)) != d.npos)
  584. {
  585. d[pos++] = '\\';
  586. }
  587. return d;
  588. }
  589. // Write a dsp file into the SLN file,
  590. // Note, that dependencies from executables to
  591. // the libraries it uses are also done here
  592. void cmGlobalVisualStudio7Generator::WriteProject(std::ostream& fout,
  593. const std::string& dspname,
  594. const char* dir, cmTarget const& target)
  595. {
  596. // check to see if this is a fortran build
  597. const char* ext = ".vcproj";
  598. const char* project =
  599. "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"";
  600. if(this->TargetIsFortranOnly(target))
  601. {
  602. ext = ".vfproj";
  603. project = "Project(\"{6989167D-11E4-40FE-8C1A-2192A86A7E90}\") = \"";
  604. }
  605. fout << project
  606. << dspname << "\", \""
  607. << this->ConvertToSolutionPath(dir) << (dir[0]? "\\":"")
  608. << dspname << ext << "\", \"{"
  609. << this->GetGUID(dspname) << "}\"\nEndProject\n";
  610. UtilityDependsMap::iterator ui = this->UtilityDepends.find(&target);
  611. if(ui != this->UtilityDepends.end())
  612. {
  613. const char* uname = ui->second.c_str();
  614. fout << "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \""
  615. << uname << "\", \""
  616. << this->ConvertToSolutionPath(dir) << (dir[0]? "\\":"")
  617. << uname << ".vcproj" << "\", \"{"
  618. << this->GetGUID(uname) << "}\"\n"
  619. << "EndProject\n";
  620. }
  621. }
  622. // Write a dsp file into the SLN file,
  623. // Note, that dependencies from executables to
  624. // the libraries it uses are also done here
  625. void
  626. cmGlobalVisualStudio7Generator
  627. ::WriteProjectDepends(std::ostream& fout,
  628. const std::string& dspname,
  629. const char*, cmTarget const& target)
  630. {
  631. int depcount = 0;
  632. std::string dspguid = this->GetGUID(dspname);
  633. VSDependSet const& depends = this->VSTargetDepends[&target];
  634. for(VSDependSet::const_iterator di = depends.begin();
  635. di != depends.end(); ++di)
  636. {
  637. const char* name = di->c_str();
  638. std::string guid = this->GetGUID(name);
  639. if(guid.size() == 0)
  640. {
  641. std::string m = "Target: ";
  642. m += target.GetName();
  643. m += " depends on unknown target: ";
  644. m += name;
  645. cmSystemTools::Error(m.c_str());
  646. }
  647. fout << "\t\t{" << dspguid << "}." << depcount << " = {" << guid << "}\n";
  648. depcount++;
  649. }
  650. UtilityDependsMap::iterator ui = this->UtilityDepends.find(&target);
  651. if(ui != this->UtilityDepends.end())
  652. {
  653. const char* uname = ui->second.c_str();
  654. fout << "\t\t{" << this->GetGUID(uname) << "}.0 = {" << dspguid << "}\n";
  655. }
  656. }
  657. // Write a dsp file into the SLN file, Note, that dependencies from
  658. // executables to the libraries it uses are also done here
  659. void cmGlobalVisualStudio7Generator
  660. ::WriteProjectConfigurations(
  661. std::ostream& fout, const std::string& name, cmTarget::TargetType,
  662. const std::set<std::string>& configsPartOfDefaultBuild,
  663. const char* platformMapping)
  664. {
  665. const char* platformName =
  666. platformMapping ? platformMapping : this->GetPlatformName();
  667. std::string guid = this->GetGUID(name);
  668. for(std::vector<std::string>::iterator i = this->Configurations.begin();
  669. i != this->Configurations.end(); ++i)
  670. {
  671. fout << "\t\t{" << guid << "}." << *i
  672. << ".ActiveCfg = " << *i << "|" << platformName << "\n";
  673. std::set<std::string>::const_iterator
  674. ci = configsPartOfDefaultBuild.find(*i);
  675. if(!(ci == configsPartOfDefaultBuild.end()))
  676. {
  677. fout << "\t\t{" << guid << "}." << *i
  678. << ".Build.0 = " << *i << "|" << platformName << "\n";
  679. }
  680. }
  681. }
  682. // Write a dsp file into the SLN file,
  683. // Note, that dependencies from executables to
  684. // the libraries it uses are also done here
  685. void cmGlobalVisualStudio7Generator::WriteExternalProject(std::ostream& fout,
  686. const std::string& name,
  687. const char* location,
  688. const char* typeGuid,
  689. const std::set<std::string>&)
  690. {
  691. std::string d = cmSystemTools::ConvertToOutputPath(location);
  692. fout << "Project("
  693. << "\"{"
  694. << (typeGuid ? typeGuid : this->ExternalProjectType(location))
  695. << "}\") = \""
  696. << name << "\", \""
  697. << this->ConvertToSolutionPath(location) << "\", \"{"
  698. << this->GetGUID(name)
  699. << "}\"\n";
  700. fout << "EndProject\n";
  701. }
  702. void cmGlobalVisualStudio7Generator
  703. ::WriteSLNGlobalSections(std::ostream& fout,
  704. cmLocalGenerator* root)
  705. {
  706. bool extensibilityGlobalsOverridden = false;
  707. bool extensibilityAddInsOverridden = false;
  708. const cmPropertyMap& props = root->GetMakefile()->GetProperties();
  709. for(cmPropertyMap::const_iterator itProp = props.begin();
  710. itProp != props.end(); ++itProp)
  711. {
  712. if(itProp->first.find("VS_GLOBAL_SECTION_") == 0)
  713. {
  714. std::string sectionType;
  715. std::string name = itProp->first.substr(18);
  716. if(name.find("PRE_") == 0)
  717. {
  718. name = name.substr(4);
  719. sectionType = "preSolution";
  720. }
  721. else if(name.find("POST_") == 0)
  722. {
  723. name = name.substr(5);
  724. sectionType = "postSolution";
  725. }
  726. else
  727. continue;
  728. if(!name.empty())
  729. {
  730. if(name == "ExtensibilityGlobals" && sectionType == "postSolution")
  731. extensibilityGlobalsOverridden = true;
  732. else if(name == "ExtensibilityAddIns" && sectionType == "postSolution")
  733. extensibilityAddInsOverridden = true;
  734. fout << "\tGlobalSection(" << name << ") = " << sectionType << "\n";
  735. std::vector<std::string> keyValuePairs;
  736. cmSystemTools::ExpandListArgument(itProp->second.GetValue(),
  737. keyValuePairs);
  738. for(std::vector<std::string>::const_iterator itPair =
  739. keyValuePairs.begin(); itPair != keyValuePairs.end(); ++itPair)
  740. {
  741. const std::string::size_type posEqual = itPair->find('=');
  742. if(posEqual != std::string::npos)
  743. {
  744. const std::string key =
  745. cmSystemTools::TrimWhitespace(itPair->substr(0, posEqual));
  746. const std::string value =
  747. cmSystemTools::TrimWhitespace(itPair->substr(posEqual + 1));
  748. fout << "\t\t" << key << " = " << value << "\n";
  749. }
  750. }
  751. fout << "\tEndGlobalSection\n";
  752. }
  753. }
  754. }
  755. if(!extensibilityGlobalsOverridden)
  756. fout << "\tGlobalSection(ExtensibilityGlobals) = postSolution\n"
  757. << "\tEndGlobalSection\n";
  758. if(!extensibilityAddInsOverridden)
  759. fout << "\tGlobalSection(ExtensibilityAddIns) = postSolution\n"
  760. << "\tEndGlobalSection\n";
  761. }
  762. // Standard end of dsw file
  763. void cmGlobalVisualStudio7Generator::WriteSLNFooter(std::ostream& fout)
  764. {
  765. fout << "EndGlobal\n";
  766. }
  767. // ouput standard header for dsw file
  768. void cmGlobalVisualStudio7Generator::WriteSLNHeader(std::ostream& fout)
  769. {
  770. fout << "Microsoft Visual Studio Solution File, Format Version 7.00\n";
  771. }
  772. //----------------------------------------------------------------------------
  773. std::string
  774. cmGlobalVisualStudio7Generator::WriteUtilityDepend(cmTarget const* target)
  775. {
  776. std::string pname = target->GetName();
  777. pname += "_UTILITY";
  778. std::string fname = target->GetMakefile()->GetStartOutputDirectory();
  779. fname += "/";
  780. fname += pname;
  781. fname += ".vcproj";
  782. cmGeneratedFileStream fout(fname.c_str());
  783. fout.SetCopyIfDifferent(true);
  784. this->CreateGUID(pname.c_str());
  785. std::string guid = this->GetGUID(pname.c_str());
  786. fout <<
  787. "<?xml version=\"1.0\" encoding = \"Windows-1252\"?>\n"
  788. "<VisualStudioProject\n"
  789. "\tProjectType=\"Visual C++\"\n"
  790. "\tVersion=\"" << this->GetIDEVersion() << "0\"\n"
  791. "\tName=\"" << pname << "\"\n"
  792. "\tProjectGUID=\"{" << guid << "}\"\n"
  793. "\tKeyword=\"Win32Proj\">\n"
  794. "\t<Platforms><Platform Name=\"Win32\"/></Platforms>\n"
  795. "\t<Configurations>\n"
  796. ;
  797. for(std::vector<std::string>::iterator i = this->Configurations.begin();
  798. i != this->Configurations.end(); ++i)
  799. {
  800. fout <<
  801. "\t\t<Configuration\n"
  802. "\t\t\tName=\"" << *i << "|Win32\"\n"
  803. "\t\t\tOutputDirectory=\"" << *i << "\"\n"
  804. "\t\t\tIntermediateDirectory=\"" << pname << ".dir\\" << *i << "\"\n"
  805. "\t\t\tConfigurationType=\"10\"\n"
  806. "\t\t\tUseOfMFC=\"0\"\n"
  807. "\t\t\tATLMinimizesCRunTimeLibraryUsage=\"FALSE\"\n"
  808. "\t\t\tCharacterSet=\"2\">\n"
  809. "\t\t</Configuration>\n"
  810. ;
  811. }
  812. fout <<
  813. "\t</Configurations>\n"
  814. "\t<Files></Files>\n"
  815. "\t<Globals></Globals>\n"
  816. "</VisualStudioProject>\n"
  817. ;
  818. if(fout.Close())
  819. {
  820. this->FileReplacedDuringGenerate(fname);
  821. }
  822. return pname;
  823. }
  824. std::string cmGlobalVisualStudio7Generator::GetGUID(const std::string& name)
  825. {
  826. std::string guidStoreName = name;
  827. guidStoreName += "_GUID_CMAKE";
  828. const char* storedGUID =
  829. this->CMakeInstance->GetCacheDefinition(guidStoreName.c_str());
  830. if(storedGUID)
  831. {
  832. return std::string(storedGUID);
  833. }
  834. cmSystemTools::Error("Unknown Target referenced : ",
  835. name.c_str());
  836. return "";
  837. }
  838. void cmGlobalVisualStudio7Generator::CreateGUID(const std::string& name)
  839. {
  840. std::string guidStoreName = name;
  841. guidStoreName += "_GUID_CMAKE";
  842. if(this->CMakeInstance->GetCacheDefinition(guidStoreName.c_str()))
  843. {
  844. return;
  845. }
  846. std::string ret;
  847. UUID uid;
  848. unsigned short *uidstr;
  849. UuidCreate(&uid);
  850. UuidToStringW(&uid,&uidstr);
  851. ret = cmsys::Encoding::ToNarrow(reinterpret_cast<wchar_t*>(uidstr));
  852. RpcStringFreeW(&uidstr);
  853. ret = cmSystemTools::UpperCase(ret);
  854. this->CMakeInstance->AddCacheEntry(guidStoreName.c_str(),
  855. ret.c_str(), "Stored GUID",
  856. cmCacheManager::INTERNAL);
  857. }
  858. std::vector<std::string> *cmGlobalVisualStudio7Generator::GetConfigurations()
  859. {
  860. return &this->Configurations;
  861. };
  862. //----------------------------------------------------------------------------
  863. void cmGlobalVisualStudio7Generator
  864. ::GetDocumentation(cmDocumentationEntry& entry)
  865. {
  866. entry.Name = cmGlobalVisualStudio7Generator::GetActualName();
  867. entry.Brief = "Generates Visual Studio .NET 2002 project files.";
  868. }
  869. //----------------------------------------------------------------------------
  870. void
  871. cmGlobalVisualStudio7Generator
  872. ::AppendDirectoryForConfig(const std::string& prefix,
  873. const std::string& config,
  874. const std::string& suffix,
  875. std::string& dir)
  876. {
  877. if(!config.empty())
  878. {
  879. dir += prefix;
  880. dir += config;
  881. dir += suffix;
  882. }
  883. }
  884. std::set<std::string>
  885. cmGlobalVisualStudio7Generator::IsPartOfDefaultBuild(
  886. const std::string& project,
  887. cmTarget const* target)
  888. {
  889. std::set<std::string> activeConfigs;
  890. // if it is a utilitiy target then only make it part of the
  891. // default build if another target depends on it
  892. int type = target->GetType();
  893. if (type == cmTarget::GLOBAL_TARGET)
  894. {
  895. return activeConfigs;
  896. }
  897. if(type == cmTarget::UTILITY && !this->IsDependedOn(project, target))
  898. {
  899. return activeConfigs;
  900. }
  901. // inspect EXCLUDE_FROM_DEFAULT_BUILD[_<CONFIG>] properties
  902. for(std::vector<std::string>::iterator i = this->Configurations.begin();
  903. i != this->Configurations.end(); ++i)
  904. {
  905. const char* propertyValue =
  906. target->GetFeature("EXCLUDE_FROM_DEFAULT_BUILD", i->c_str());
  907. if(cmSystemTools::IsOff(propertyValue))
  908. {
  909. activeConfigs.insert(*i);
  910. }
  911. }
  912. return activeConfigs;
  913. }
  914. //----------------------------------------------------------------------------
  915. static cmVS7FlagTable cmVS7ExtraFlagTable[] =
  916. {
  917. // Precompiled header and related options. Note that the
  918. // UsePrecompiledHeader entries are marked as "Continue" so that the
  919. // corresponding PrecompiledHeaderThrough entry can be found.
  920. {"UsePrecompiledHeader", "YX", "Automatically Generate", "2",
  921. cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue},
  922. {"PrecompiledHeaderThrough", "YX", "Precompiled Header Name", "",
  923. cmVS7FlagTable::UserValueRequired},
  924. {"UsePrecompiledHeader", "Yu", "Use Precompiled Header", "3",
  925. cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue},
  926. {"PrecompiledHeaderThrough", "Yu", "Precompiled Header Name", "",
  927. cmVS7FlagTable::UserValueRequired},
  928. {"WholeProgramOptimization", "LTCG", "WholeProgramOptimization", "TRUE", 0},
  929. // Exception handling mode. If no entries match, it will be FALSE.
  930. {"ExceptionHandling", "GX", "enable c++ exceptions", "TRUE", 0},
  931. {"ExceptionHandling", "EHsc", "enable c++ exceptions", "TRUE", 0},
  932. // The EHa option does not have an IDE setting. Let it go to false,
  933. // and have EHa passed on the command line by leaving out the table
  934. // entry.
  935. {0,0,0,0,0}
  936. };
  937. cmIDEFlagTable const* cmGlobalVisualStudio7Generator::GetExtraFlagTableVS7()
  938. {
  939. return cmVS7ExtraFlagTable;
  940. }