cmGlobalVisualStudio7Generator.cxx 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "windows.h" // this must be first to define GetCurrentDirectory
  11. #include "cmGlobalVisualStudio7Generator.h"
  12. #include "cmGeneratedFileStream.h"
  13. #include "cmLocalVisualStudio7Generator.h"
  14. #include "cmMakefile.h"
  15. #include "cmake.h"
  16. cmGlobalVisualStudio7Generator::cmGlobalVisualStudio7Generator()
  17. {
  18. this->FindMakeProgramFile = "CMakeVS7FindMake.cmake";
  19. }
  20. void cmGlobalVisualStudio7Generator
  21. ::EnableLanguage(std::vector<std::string>const & lang,
  22. cmMakefile *mf, bool optional)
  23. {
  24. mf->AddDefinition("CMAKE_GENERATOR_CC", "cl");
  25. mf->AddDefinition("CMAKE_GENERATOR_CXX", "cl");
  26. mf->AddDefinition("CMAKE_GENERATOR_RC", "rc");
  27. mf->AddDefinition("CMAKE_GENERATOR_NO_COMPILER_ENV", "1");
  28. mf->AddDefinition("CMAKE_GENERATOR_FC", "ifort");
  29. this->AddPlatformDefinitions(mf);
  30. // Create list of configurations requested by user's cache, if any.
  31. this->cmGlobalGenerator::EnableLanguage(lang, mf, optional);
  32. this->GenerateConfigurations(mf);
  33. // if this environment variable is set, then copy it to
  34. // a static cache entry. It will be used by
  35. // cmLocalGenerator::ConstructScript, to add an extra PATH
  36. // to all custom commands. This is because the VS IDE
  37. // does not use the environment it is run in, and this allows
  38. // for running commands and using dll's that the IDE environment
  39. // does not know about.
  40. const char* extraPath = cmSystemTools::GetEnv("CMAKE_MSVCIDE_RUN_PATH");
  41. if(extraPath)
  42. {
  43. mf->AddCacheDefinition
  44. ("CMAKE_MSVCIDE_RUN_PATH", extraPath,
  45. "Saved environment variable CMAKE_MSVCIDE_RUN_PATH",
  46. cmCacheManager::STATIC);
  47. }
  48. }
  49. void cmGlobalVisualStudio7Generator::AddPlatformDefinitions(cmMakefile* mf)
  50. {
  51. mf->AddDefinition("MSVC70", "1");
  52. mf->AddDefinition("MSVC_C_ARCHITECTURE_ID", "X86");
  53. mf->AddDefinition("MSVC_CXX_ARCHITECTURE_ID", "X86");
  54. }
  55. std::string cmGlobalVisualStudio7Generator
  56. ::GenerateBuildCommand(const char* makeProgram,
  57. const char *projectName,
  58. const char* additionalOptions, const char *targetName,
  59. const char* config, bool ignoreErrors, bool)
  60. {
  61. // Ingoring errors is not implemented in visual studio 6
  62. (void) ignoreErrors;
  63. // now build the test
  64. std::string makeCommand =
  65. cmSystemTools::ConvertToOutputPath(makeProgram);
  66. std::string lowerCaseCommand = makeCommand;
  67. cmSystemTools::LowerCase(lowerCaseCommand);
  68. // if there are spaces in the makeCommand, assume a full path
  69. // and convert it to a path with no spaces in it as the
  70. // RunSingleCommand does not like spaces
  71. #if defined(_WIN32) && !defined(__CYGWIN__)
  72. if(makeCommand.find(' ') != std::string::npos)
  73. {
  74. cmSystemTools::GetShortPath(makeCommand.c_str(), makeCommand);
  75. }
  76. #endif
  77. makeCommand += " ";
  78. makeCommand += projectName;
  79. makeCommand += ".sln ";
  80. bool clean = false;
  81. if ( targetName && strcmp(targetName, "clean") == 0 )
  82. {
  83. clean = true;
  84. targetName = "ALL_BUILD";
  85. }
  86. if(clean)
  87. {
  88. makeCommand += "/clean ";
  89. }
  90. else
  91. {
  92. makeCommand += "/build ";
  93. }
  94. if(config && strlen(config))
  95. {
  96. makeCommand += config;
  97. }
  98. else
  99. {
  100. makeCommand += "Debug";
  101. }
  102. makeCommand += " /project ";
  103. if (targetName && strlen(targetName))
  104. {
  105. makeCommand += targetName;
  106. }
  107. else
  108. {
  109. makeCommand += "ALL_BUILD";
  110. }
  111. if ( additionalOptions )
  112. {
  113. makeCommand += " ";
  114. makeCommand += additionalOptions;
  115. }
  116. return makeCommand;
  117. }
  118. ///! Create a local generator appropriate to this Global Generator
  119. cmLocalGenerator *cmGlobalVisualStudio7Generator::CreateLocalGenerator()
  120. {
  121. cmLocalVisualStudio7Generator *lg =
  122. new cmLocalVisualStudio7Generator(cmLocalVisualStudioGenerator::VS7);
  123. lg->SetExtraFlagTable(this->GetExtraFlagTableVS7());
  124. lg->SetGlobalGenerator(this);
  125. return lg;
  126. }
  127. void cmGlobalVisualStudio7Generator::GenerateConfigurations(cmMakefile* mf)
  128. {
  129. // process the configurations
  130. const char* ct
  131. = this->CMakeInstance->GetCacheDefinition("CMAKE_CONFIGURATION_TYPES");
  132. if ( ct )
  133. {
  134. std::vector<std::string> argsOut;
  135. cmSystemTools::ExpandListArgument(ct, argsOut);
  136. for(std::vector<std::string>::iterator i = argsOut.begin();
  137. i != argsOut.end(); ++i)
  138. {
  139. if(std::find(this->Configurations.begin(),
  140. this->Configurations.end(),
  141. *i) == this->Configurations.end())
  142. {
  143. this->Configurations.push_back(*i);
  144. }
  145. }
  146. }
  147. // default to at least Debug and Release
  148. if(this->Configurations.size() == 0)
  149. {
  150. this->Configurations.push_back("Debug");
  151. this->Configurations.push_back("Release");
  152. }
  153. // Reset the entry to have a semi-colon separated list.
  154. std::string configs = this->Configurations[0];
  155. for(unsigned int i=1; i < this->Configurations.size(); ++i)
  156. {
  157. configs += ";";
  158. configs += this->Configurations[i];
  159. }
  160. mf->AddCacheDefinition(
  161. "CMAKE_CONFIGURATION_TYPES",
  162. configs.c_str(),
  163. "Semicolon separated list of supported configuration types, "
  164. "only supports Debug, Release, MinSizeRel, and RelWithDebInfo, "
  165. "anything else will be ignored.",
  166. cmCacheManager::STRING);
  167. }
  168. void cmGlobalVisualStudio7Generator::Generate()
  169. {
  170. // first do the superclass method
  171. this->cmGlobalVisualStudioGenerator::Generate();
  172. // Now write out the DSW
  173. this->OutputSLNFile();
  174. // If any solution or project files changed during the generation,
  175. // tell Visual Studio to reload them...
  176. if(!cmSystemTools::GetErrorOccuredFlag())
  177. {
  178. this->CallVisualStudioMacro(MacroReload);
  179. }
  180. }
  181. void cmGlobalVisualStudio7Generator
  182. ::OutputSLNFile(cmLocalGenerator* root,
  183. std::vector<cmLocalGenerator*>& generators)
  184. {
  185. if(generators.size() == 0)
  186. {
  187. return;
  188. }
  189. this->CurrentProject = root->GetMakefile()->GetProjectName();
  190. std::string fname = root->GetMakefile()->GetStartOutputDirectory();
  191. fname += "/";
  192. fname += root->GetMakefile()->GetProjectName();
  193. fname += ".sln";
  194. cmGeneratedFileStream fout(fname.c_str());
  195. fout.SetCopyIfDifferent(true);
  196. if(!fout)
  197. {
  198. return;
  199. }
  200. this->WriteSLNFile(fout, root, generators);
  201. if (fout.Close())
  202. {
  203. this->FileReplacedDuringGenerate(fname);
  204. }
  205. }
  206. // output the SLN file
  207. void cmGlobalVisualStudio7Generator::OutputSLNFile()
  208. {
  209. std::map<cmStdString, std::vector<cmLocalGenerator*> >::iterator it;
  210. for(it = this->ProjectMap.begin(); it!= this->ProjectMap.end(); ++it)
  211. {
  212. this->OutputSLNFile(it->second[0], it->second);
  213. }
  214. }
  215. void cmGlobalVisualStudio7Generator::WriteTargetConfigurations(
  216. std::ostream& fout,
  217. cmLocalGenerator* root,
  218. OrderedTargetDependSet const& projectTargets)
  219. {
  220. // loop over again and write out configurations for each target
  221. // in the solution
  222. for(OrderedTargetDependSet::const_iterator tt =
  223. projectTargets.begin(); tt != projectTargets.end(); ++tt)
  224. {
  225. cmTarget* target = *tt;
  226. const char* expath = target->GetProperty("EXTERNAL_MSPROJECT");
  227. if(expath)
  228. {
  229. this->WriteProjectConfigurations(
  230. fout, target->GetName(),
  231. true, target->GetProperty("VS_PLATFORM_MAPPING"));
  232. }
  233. else
  234. {
  235. bool partOfDefaultBuild = this->IsPartOfDefaultBuild(
  236. root->GetMakefile()->GetProjectName(), target);
  237. const char *vcprojName =
  238. target->GetProperty("GENERATOR_FILE_NAME");
  239. if (vcprojName)
  240. {
  241. this->WriteProjectConfigurations(fout, vcprojName,
  242. partOfDefaultBuild);
  243. }
  244. }
  245. }
  246. }
  247. void cmGlobalVisualStudio7Generator::WriteTargetsToSolution(
  248. std::ostream& fout,
  249. cmLocalGenerator* root,
  250. OrderedTargetDependSet const& projectTargets)
  251. {
  252. for(OrderedTargetDependSet::const_iterator tt =
  253. projectTargets.begin(); tt != projectTargets.end(); ++tt)
  254. {
  255. cmTarget* target = *tt;
  256. bool written = false;
  257. // handle external vc project files
  258. const char* expath = target->GetProperty("EXTERNAL_MSPROJECT");
  259. if(expath)
  260. {
  261. std::string project = target->GetName();
  262. std::string location = expath;
  263. this->WriteExternalProject(fout,
  264. project.c_str(),
  265. location.c_str(),
  266. target->GetProperty("VS_PROJECT_TYPE"),
  267. target->GetUtilities());
  268. written = true;
  269. }
  270. else
  271. {
  272. const char *vcprojName =
  273. target->GetProperty("GENERATOR_FILE_NAME");
  274. if(vcprojName)
  275. {
  276. cmMakefile* tmf = target->GetMakefile();
  277. std::string dir = tmf->GetStartOutputDirectory();
  278. dir = root->Convert(dir.c_str(),
  279. cmLocalGenerator::START_OUTPUT);
  280. if(dir == ".")
  281. {
  282. dir = ""; // msbuild cannot handle ".\" prefix
  283. }
  284. this->WriteProject(fout, vcprojName, dir.c_str(),
  285. *target);
  286. written = true;
  287. }
  288. }
  289. // Create "solution folder" information from FOLDER target property
  290. //
  291. if (written && this->UseFolderProperty())
  292. {
  293. const char *targetFolder = target->GetProperty("FOLDER");
  294. if (targetFolder)
  295. {
  296. std::vector<cmsys::String> tokens =
  297. cmSystemTools::SplitString(targetFolder, '/', false);
  298. std::string cumulativePath = "";
  299. for(std::vector<cmsys::String>::iterator iter = tokens.begin();
  300. iter != tokens.end(); ++iter)
  301. {
  302. if(!iter->size())
  303. {
  304. continue;
  305. }
  306. if (cumulativePath.empty())
  307. {
  308. cumulativePath = "CMAKE_FOLDER_GUID_" + *iter;
  309. }
  310. else
  311. {
  312. VisualStudioFolders[cumulativePath].insert(
  313. cumulativePath + "/" + *iter);
  314. cumulativePath = cumulativePath + "/" + *iter;
  315. }
  316. this->CreateGUID(cumulativePath.c_str());
  317. }
  318. if (!cumulativePath.empty())
  319. {
  320. VisualStudioFolders[cumulativePath].insert(target->GetName());
  321. }
  322. }
  323. }
  324. }
  325. }
  326. void cmGlobalVisualStudio7Generator::WriteTargetDepends(
  327. std::ostream& fout,
  328. OrderedTargetDependSet const& projectTargets
  329. )
  330. {
  331. for(OrderedTargetDependSet::const_iterator tt =
  332. projectTargets.begin(); tt != projectTargets.end(); ++tt)
  333. {
  334. cmTarget* target = *tt;
  335. cmMakefile* mf = target->GetMakefile();
  336. const char *vcprojName =
  337. target->GetProperty("GENERATOR_FILE_NAME");
  338. if (vcprojName)
  339. {
  340. std::string dir = mf->GetStartDirectory();
  341. this->WriteProjectDepends(fout, vcprojName,
  342. dir.c_str(), *target);
  343. }
  344. }
  345. }
  346. //----------------------------------------------------------------------------
  347. // Write a SLN file to the stream
  348. void cmGlobalVisualStudio7Generator
  349. ::WriteSLNFile(std::ostream& fout,
  350. cmLocalGenerator* root,
  351. std::vector<cmLocalGenerator*>& generators)
  352. {
  353. // Write out the header for a SLN file
  354. this->WriteSLNHeader(fout);
  355. // Collect all targets under this root generator and the transitive
  356. // closure of their dependencies.
  357. TargetDependSet projectTargets;
  358. TargetDependSet originalTargets;
  359. this->GetTargetSets(projectTargets, originalTargets, root, generators);
  360. OrderedTargetDependSet orderedProjectTargets(projectTargets);
  361. this->WriteTargetsToSolution(fout, root, orderedProjectTargets);
  362. bool useFolderProperty = this->UseFolderProperty();
  363. if (useFolderProperty)
  364. {
  365. this->WriteFolders(fout);
  366. }
  367. // Write out the configurations information for the solution
  368. fout << "Global\n"
  369. << "\tGlobalSection(SolutionConfiguration) = preSolution\n";
  370. int c = 0;
  371. for(std::vector<std::string>::iterator i = this->Configurations.begin();
  372. i != this->Configurations.end(); ++i)
  373. {
  374. fout << "\t\tConfigName." << c << " = " << *i << "\n";
  375. c++;
  376. }
  377. fout << "\tEndGlobalSection\n";
  378. // Write out project(target) depends
  379. fout << "\tGlobalSection(ProjectDependencies) = postSolution\n";
  380. this->WriteTargetDepends(fout, orderedProjectTargets);
  381. fout << "\tEndGlobalSection\n";
  382. if (useFolderProperty)
  383. {
  384. // Write out project folders
  385. fout << "\tGlobalSection(NestedProjects) = preSolution\n";
  386. this->WriteFoldersContent(fout);
  387. fout << "\tEndGlobalSection\n";
  388. }
  389. // Write out the configurations for all the targets in the project
  390. fout << "\tGlobalSection(ProjectConfiguration) = postSolution\n";
  391. this->WriteTargetConfigurations(fout, root, orderedProjectTargets);
  392. fout << "\tEndGlobalSection\n";
  393. // Write the footer for the SLN file
  394. this->WriteSLNFooter(fout);
  395. }
  396. //----------------------------------------------------------------------------
  397. void cmGlobalVisualStudio7Generator::WriteFolders(std::ostream& fout)
  398. {
  399. const char *prefix = "CMAKE_FOLDER_GUID_";
  400. const std::string::size_type skip_prefix = strlen(prefix);
  401. std::string guidProjectTypeFolder = "2150E333-8FDC-42A3-9474-1A3956D46DE8";
  402. for(std::map<std::string,std::set<std::string> >::iterator iter =
  403. VisualStudioFolders.begin(); iter != VisualStudioFolders.end(); ++iter)
  404. {
  405. std::string fullName = iter->first;
  406. std::string guid = this->GetGUID(fullName.c_str());
  407. cmSystemTools::ReplaceString(fullName, "/", "\\");
  408. if (cmSystemTools::StringStartsWith(fullName.c_str(), prefix))
  409. {
  410. fullName = fullName.substr(skip_prefix);
  411. }
  412. std::string nameOnly = cmSystemTools::GetFilenameName(fullName);
  413. fout << "Project(\"{" <<
  414. guidProjectTypeFolder << "}\") = \"" <<
  415. nameOnly << "\", \"" <<
  416. fullName << "\", \"{" <<
  417. guid <<
  418. "}\"\nEndProject\n";
  419. }
  420. }
  421. //----------------------------------------------------------------------------
  422. void cmGlobalVisualStudio7Generator::WriteFoldersContent(std::ostream& fout)
  423. {
  424. for(std::map<std::string,std::set<std::string> >::iterator iter =
  425. VisualStudioFolders.begin(); iter != VisualStudioFolders.end(); ++iter)
  426. {
  427. std::string key(iter->first);
  428. std::string guidParent(this->GetGUID(key.c_str()));
  429. for(std::set<std::string>::iterator it = iter->second.begin();
  430. it != iter->second.end(); ++it)
  431. {
  432. std::string value(*it);
  433. std::string guid(this->GetGUID(value.c_str()));
  434. fout << "\t\t{" << guid << "} = {" << guidParent << "}\n";
  435. }
  436. }
  437. }
  438. //----------------------------------------------------------------------------
  439. std::string
  440. cmGlobalVisualStudio7Generator::ConvertToSolutionPath(const char* path)
  441. {
  442. // Convert to backslashes. Do not use ConvertToOutputPath because
  443. // we will add quoting ourselves, and we know these projects always
  444. // use windows slashes.
  445. std::string d = path;
  446. std::string::size_type pos = 0;
  447. while((pos = d.find('/', pos)) != d.npos)
  448. {
  449. d[pos++] = '\\';
  450. }
  451. return d;
  452. }
  453. // Write a dsp file into the SLN file,
  454. // Note, that dependencies from executables to
  455. // the libraries it uses are also done here
  456. void cmGlobalVisualStudio7Generator::WriteProject(std::ostream& fout,
  457. const char* dspname,
  458. const char* dir, cmTarget& target)
  459. {
  460. // check to see if this is a fortran build
  461. const char* ext = ".vcproj";
  462. const char* project =
  463. "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"";
  464. if(this->TargetIsFortranOnly(target))
  465. {
  466. ext = ".vfproj";
  467. project = "Project(\"{6989167D-11E4-40FE-8C1A-2192A86A7E90}\") = \"";
  468. }
  469. fout << project
  470. << dspname << "\", \""
  471. << this->ConvertToSolutionPath(dir) << (dir[0]? "\\":"")
  472. << dspname << ext << "\", \"{"
  473. << this->GetGUID(dspname) << "}\"\nEndProject\n";
  474. UtilityDependsMap::iterator ui = this->UtilityDepends.find(&target);
  475. if(ui != this->UtilityDepends.end())
  476. {
  477. const char* uname = ui->second.c_str();
  478. fout << "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \""
  479. << uname << "\", \""
  480. << this->ConvertToSolutionPath(dir) << (dir[0]? "\\":"")
  481. << uname << ".vcproj" << "\", \"{"
  482. << this->GetGUID(uname) << "}\"\n"
  483. << "EndProject\n";
  484. }
  485. }
  486. // Write a dsp file into the SLN file,
  487. // Note, that dependencies from executables to
  488. // the libraries it uses are also done here
  489. void
  490. cmGlobalVisualStudio7Generator
  491. ::WriteProjectDepends(std::ostream& fout,
  492. const char* dspname,
  493. const char*, cmTarget& target)
  494. {
  495. int depcount = 0;
  496. std::string dspguid = this->GetGUID(dspname);
  497. VSDependSet const& depends = this->VSTargetDepends[&target];
  498. for(VSDependSet::const_iterator di = depends.begin();
  499. di != depends.end(); ++di)
  500. {
  501. const char* name = di->c_str();
  502. std::string guid = this->GetGUID(name);
  503. if(guid.size() == 0)
  504. {
  505. std::string m = "Target: ";
  506. m += target.GetName();
  507. m += " depends on unknown target: ";
  508. m += name;
  509. cmSystemTools::Error(m.c_str());
  510. }
  511. fout << "\t\t{" << dspguid << "}." << depcount << " = {" << guid << "}\n";
  512. depcount++;
  513. }
  514. UtilityDependsMap::iterator ui = this->UtilityDepends.find(&target);
  515. if(ui != this->UtilityDepends.end())
  516. {
  517. const char* uname = ui->second.c_str();
  518. fout << "\t\t{" << this->GetGUID(uname) << "}.0 = {" << dspguid << "}\n";
  519. }
  520. }
  521. // Write a dsp file into the SLN file, Note, that dependencies from
  522. // executables to the libraries it uses are also done here
  523. void cmGlobalVisualStudio7Generator
  524. ::WriteProjectConfigurations(std::ostream& fout, const char* name,
  525. bool partOfDefaultBuild,
  526. const char* platformMapping)
  527. {
  528. std::string guid = this->GetGUID(name);
  529. for(std::vector<std::string>::iterator i = this->Configurations.begin();
  530. i != this->Configurations.end(); ++i)
  531. {
  532. fout << "\t\t{" << guid << "}." << *i
  533. << ".ActiveCfg = " << *i << "|"
  534. << (platformMapping ? platformMapping : "Win32") << "\n";
  535. if(partOfDefaultBuild)
  536. {
  537. fout << "\t\t{" << guid << "}." << *i
  538. << ".Build.0 = " << *i << "|"
  539. << (platformMapping ? platformMapping : "Win32") << "\n";
  540. }
  541. }
  542. }
  543. // Write a dsp file into the SLN file,
  544. // Note, that dependencies from executables to
  545. // the libraries it uses are also done here
  546. void cmGlobalVisualStudio7Generator::WriteExternalProject(std::ostream& fout,
  547. const char* name,
  548. const char* location,
  549. const char* typeGuid,
  550. const std::set<cmStdString>&)
  551. {
  552. std::string d = cmSystemTools::ConvertToOutputPath(location);
  553. fout << "Project("
  554. << "\"{"
  555. << (typeGuid ? typeGuid : "8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942")
  556. << "}\") = \""
  557. << name << "\", \""
  558. << this->ConvertToSolutionPath(location) << "\", \"{"
  559. << this->GetGUID(name)
  560. << "}\"\n";
  561. fout << "EndProject\n";
  562. }
  563. // Standard end of dsw file
  564. void cmGlobalVisualStudio7Generator::WriteSLNFooter(std::ostream& fout)
  565. {
  566. fout << "\tGlobalSection(ExtensibilityGlobals) = postSolution\n"
  567. << "\tEndGlobalSection\n"
  568. << "\tGlobalSection(ExtensibilityAddIns) = postSolution\n"
  569. << "\tEndGlobalSection\n"
  570. << "EndGlobal\n";
  571. }
  572. // ouput standard header for dsw file
  573. void cmGlobalVisualStudio7Generator::WriteSLNHeader(std::ostream& fout)
  574. {
  575. fout << "Microsoft Visual Studio Solution File, Format Version 7.00\n";
  576. }
  577. //----------------------------------------------------------------------------
  578. std::string
  579. cmGlobalVisualStudio7Generator::WriteUtilityDepend(cmTarget* target)
  580. {
  581. std::string pname = target->GetName();
  582. pname += "_UTILITY";
  583. std::string fname = target->GetMakefile()->GetStartOutputDirectory();
  584. fname += "/";
  585. fname += pname;
  586. fname += ".vcproj";
  587. cmGeneratedFileStream fout(fname.c_str());
  588. fout.SetCopyIfDifferent(true);
  589. this->CreateGUID(pname.c_str());
  590. std::string guid = this->GetGUID(pname.c_str());
  591. fout <<
  592. "<?xml version=\"1.0\" encoding = \"Windows-1252\"?>\n"
  593. "<VisualStudioProject\n"
  594. "\tProjectType=\"Visual C++\"\n"
  595. "\tVersion=\"" << this->GetIDEVersion() << "0\"\n"
  596. "\tName=\"" << pname << "\"\n"
  597. "\tProjectGUID=\"{" << guid << "}\"\n"
  598. "\tKeyword=\"Win32Proj\">\n"
  599. "\t<Platforms><Platform Name=\"Win32\"/></Platforms>\n"
  600. "\t<Configurations>\n"
  601. ;
  602. for(std::vector<std::string>::iterator i = this->Configurations.begin();
  603. i != this->Configurations.end(); ++i)
  604. {
  605. fout <<
  606. "\t\t<Configuration\n"
  607. "\t\t\tName=\"" << *i << "|Win32\"\n"
  608. "\t\t\tOutputDirectory=\"" << *i << "\"\n"
  609. "\t\t\tIntermediateDirectory=\"" << pname << ".dir\\" << *i << "\"\n"
  610. "\t\t\tConfigurationType=\"10\"\n"
  611. "\t\t\tUseOfMFC=\"0\"\n"
  612. "\t\t\tATLMinimizesCRunTimeLibraryUsage=\"FALSE\"\n"
  613. "\t\t\tCharacterSet=\"2\">\n"
  614. "\t\t</Configuration>\n"
  615. ;
  616. }
  617. fout <<
  618. "\t</Configurations>\n"
  619. "\t<Files></Files>\n"
  620. "\t<Globals></Globals>\n"
  621. "</VisualStudioProject>\n"
  622. ;
  623. if(fout.Close())
  624. {
  625. this->FileReplacedDuringGenerate(fname);
  626. }
  627. return pname;
  628. }
  629. std::string cmGlobalVisualStudio7Generator::GetGUID(const char* name)
  630. {
  631. std::string guidStoreName = name;
  632. guidStoreName += "_GUID_CMAKE";
  633. const char* storedGUID =
  634. this->CMakeInstance->GetCacheDefinition(guidStoreName.c_str());
  635. if(storedGUID)
  636. {
  637. return std::string(storedGUID);
  638. }
  639. cmSystemTools::Error("Unknown Target referenced : ",
  640. name);
  641. return "";
  642. }
  643. void cmGlobalVisualStudio7Generator::CreateGUID(const char* name)
  644. {
  645. std::string guidStoreName = name;
  646. guidStoreName += "_GUID_CMAKE";
  647. if(this->CMakeInstance->GetCacheDefinition(guidStoreName.c_str()))
  648. {
  649. return;
  650. }
  651. std::string ret;
  652. UUID uid;
  653. unsigned char *uidstr;
  654. UuidCreate(&uid);
  655. UuidToString(&uid,&uidstr);
  656. ret = reinterpret_cast<char*>(uidstr);
  657. RpcStringFree(&uidstr);
  658. ret = cmSystemTools::UpperCase(ret);
  659. this->CMakeInstance->AddCacheEntry(guidStoreName.c_str(),
  660. ret.c_str(), "Stored GUID",
  661. cmCacheManager::INTERNAL);
  662. }
  663. std::vector<std::string> *cmGlobalVisualStudio7Generator::GetConfigurations()
  664. {
  665. return &this->Configurations;
  666. };
  667. //----------------------------------------------------------------------------
  668. void cmGlobalVisualStudio7Generator
  669. ::GetDocumentation(cmDocumentationEntry& entry) const
  670. {
  671. entry.Name = this->GetName();
  672. entry.Brief = "Generates Visual Studio .NET 2002 project files.";
  673. entry.Full = "";
  674. }
  675. //----------------------------------------------------------------------------
  676. void
  677. cmGlobalVisualStudio7Generator
  678. ::AppendDirectoryForConfig(const char* prefix,
  679. const char* config,
  680. const char* suffix,
  681. std::string& dir)
  682. {
  683. if(config)
  684. {
  685. dir += prefix;
  686. dir += config;
  687. dir += suffix;
  688. }
  689. }
  690. bool cmGlobalVisualStudio7Generator::IsPartOfDefaultBuild(const char* project,
  691. cmTarget* target)
  692. {
  693. if(target->GetPropertyAsBool("EXCLUDE_FROM_DEFAULT_BUILD"))
  694. {
  695. return false;
  696. }
  697. // if it is a utilitiy target then only make it part of the
  698. // default build if another target depends on it
  699. int type = target->GetType();
  700. if (type == cmTarget::GLOBAL_TARGET)
  701. {
  702. return false;
  703. }
  704. if(type == cmTarget::UTILITY)
  705. {
  706. return this->IsDependedOn(project, target);
  707. }
  708. // default is to be part of the build
  709. return true;
  710. }
  711. //----------------------------------------------------------------------------
  712. static cmVS7FlagTable cmVS7ExtraFlagTable[] =
  713. {
  714. // Precompiled header and related options. Note that the
  715. // UsePrecompiledHeader entries are marked as "Continue" so that the
  716. // corresponding PrecompiledHeaderThrough entry can be found.
  717. {"UsePrecompiledHeader", "YX", "Automatically Generate", "2",
  718. cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue},
  719. {"PrecompiledHeaderThrough", "YX", "Precompiled Header Name", "",
  720. cmVS7FlagTable::UserValueRequired},
  721. {"UsePrecompiledHeader", "Yu", "Use Precompiled Header", "3",
  722. cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue},
  723. {"PrecompiledHeaderThrough", "Yu", "Precompiled Header Name", "",
  724. cmVS7FlagTable::UserValueRequired},
  725. {"WholeProgramOptimization", "LTCG", "WholeProgramOptimization", "TRUE", 0},
  726. // Exception handling mode. If no entries match, it will be FALSE.
  727. {"ExceptionHandling", "GX", "enable c++ exceptions", "TRUE", 0},
  728. {"ExceptionHandling", "EHsc", "enable c++ exceptions", "TRUE", 0},
  729. // The EHa option does not have an IDE setting. Let it go to false,
  730. // and have EHa passed on the command line by leaving out the table
  731. // entry.
  732. {0,0,0,0,0}
  733. };
  734. cmIDEFlagTable const* cmGlobalVisualStudio7Generator::GetExtraFlagTableVS7()
  735. {
  736. return cmVS7ExtraFlagTable;
  737. }