cmLocalVisualStudioGenerator.cxx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmLocalVisualStudioGenerator.h"
  14. #include "cmMakefile.h"
  15. #include "cmSourceFile.h"
  16. #include "cmSystemTools.h"
  17. //----------------------------------------------------------------------------
  18. cmLocalVisualStudioGenerator::cmLocalVisualStudioGenerator()
  19. {
  20. }
  21. //----------------------------------------------------------------------------
  22. cmLocalVisualStudioGenerator::~cmLocalVisualStudioGenerator()
  23. {
  24. }
  25. //----------------------------------------------------------------------------
  26. bool cmLocalVisualStudioGenerator::SourceFileCompiles(const cmSourceFile* sf)
  27. {
  28. // Identify the language of the source file.
  29. if(const char* lang = this->GetSourceFileLanguage(*sf))
  30. {
  31. // Check whether this source will actually be compiled.
  32. return (!sf->GetCustomCommand() &&
  33. !sf->GetPropertyAsBool("HEADER_FILE_ONLY") &&
  34. !sf->GetPropertyAsBool("EXTERNAL_OBJECT"));
  35. }
  36. else
  37. {
  38. // Unknown source file language. Assume it will not be compiled.
  39. return false;
  40. }
  41. }
  42. //----------------------------------------------------------------------------
  43. void cmLocalVisualStudioGenerator::ComputeObjectNameRequirements
  44. (std::vector<cmSourceGroup> const& sourceGroups)
  45. {
  46. // Clear the current set of requirements.
  47. this->NeedObjectName.clear();
  48. // Count the number of object files with each name. Note that
  49. // windows file names are not case sensitive.
  50. std::map<cmStdString, int> objectNameCounts;
  51. for(unsigned int i = 0; i < sourceGroups.size(); ++i)
  52. {
  53. cmSourceGroup sg = sourceGroups[i];
  54. std::vector<const cmSourceFile*> const& srcs = sg.GetSourceFiles();
  55. for(std::vector<const cmSourceFile*>::const_iterator s = srcs.begin();
  56. s != srcs.end(); ++s)
  57. {
  58. const cmSourceFile* sf = *s;
  59. if(this->SourceFileCompiles(sf))
  60. {
  61. std::string objectName =
  62. cmSystemTools::LowerCase(
  63. cmSystemTools::GetFilenameWithoutLastExtension(
  64. sf->GetFullPath().c_str()));
  65. objectName += ".obj";
  66. objectNameCounts[objectName] += 1;
  67. }
  68. }
  69. }
  70. // For all source files producing duplicate names we need unique
  71. // object name computation.
  72. for(unsigned int i = 0; i < sourceGroups.size(); ++i)
  73. {
  74. cmSourceGroup sg = sourceGroups[i];
  75. std::vector<const cmSourceFile*> const& srcs = sg.GetSourceFiles();
  76. for(std::vector<const cmSourceFile*>::const_iterator s = srcs.begin();
  77. s != srcs.end(); ++s)
  78. {
  79. const cmSourceFile* sf = *s;
  80. if(this->SourceFileCompiles(sf))
  81. {
  82. std::string objectName =
  83. cmSystemTools::LowerCase(
  84. cmSystemTools::GetFilenameWithoutLastExtension(
  85. sf->GetFullPath().c_str()));
  86. objectName += ".obj";
  87. if(objectNameCounts[objectName] > 1)
  88. {
  89. this->NeedObjectName.insert(sf);
  90. }
  91. }
  92. }
  93. }
  94. }