cmGlobalVisualStudio7Generator.cxx 31 KB

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