cmLocalVisualStudioGenerator.cxx 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. this->WindowsShell = true;
  21. }
  22. //----------------------------------------------------------------------------
  23. cmLocalVisualStudioGenerator::~cmLocalVisualStudioGenerator()
  24. {
  25. }
  26. //----------------------------------------------------------------------------
  27. bool cmLocalVisualStudioGenerator::SourceFileCompiles(const cmSourceFile* sf)
  28. {
  29. // Identify the language of the source file.
  30. if(const char* lang = this->GetSourceFileLanguage(*sf))
  31. {
  32. // Check whether this source will actually be compiled.
  33. return (!sf->GetCustomCommand() &&
  34. !sf->GetPropertyAsBool("HEADER_FILE_ONLY") &&
  35. !sf->GetPropertyAsBool("EXTERNAL_OBJECT"));
  36. }
  37. else
  38. {
  39. // Unknown source file language. Assume it will not be compiled.
  40. return false;
  41. }
  42. }
  43. //----------------------------------------------------------------------------
  44. void cmLocalVisualStudioGenerator::ComputeObjectNameRequirements
  45. (std::vector<cmSourceGroup> const& sourceGroups)
  46. {
  47. // Clear the current set of requirements.
  48. this->NeedObjectName.clear();
  49. // Count the number of object files with each name. Note that
  50. // windows file names are not case sensitive.
  51. std::map<cmStdString, int> objectNameCounts;
  52. for(unsigned int i = 0; i < sourceGroups.size(); ++i)
  53. {
  54. cmSourceGroup sg = sourceGroups[i];
  55. std::vector<const cmSourceFile*> const& srcs = sg.GetSourceFiles();
  56. for(std::vector<const cmSourceFile*>::const_iterator s = srcs.begin();
  57. s != srcs.end(); ++s)
  58. {
  59. const cmSourceFile* sf = *s;
  60. if(this->SourceFileCompiles(sf))
  61. {
  62. std::string objectName =
  63. cmSystemTools::LowerCase(
  64. cmSystemTools::GetFilenameWithoutLastExtension(
  65. sf->GetFullPath().c_str()));
  66. objectName += ".obj";
  67. objectNameCounts[objectName] += 1;
  68. }
  69. }
  70. }
  71. // For all source files producing duplicate names we need unique
  72. // object name computation.
  73. for(unsigned int i = 0; i < sourceGroups.size(); ++i)
  74. {
  75. cmSourceGroup sg = sourceGroups[i];
  76. std::vector<const cmSourceFile*> const& srcs = sg.GetSourceFiles();
  77. for(std::vector<const cmSourceFile*>::const_iterator s = srcs.begin();
  78. s != srcs.end(); ++s)
  79. {
  80. const cmSourceFile* sf = *s;
  81. if(this->SourceFileCompiles(sf))
  82. {
  83. std::string objectName =
  84. cmSystemTools::LowerCase(
  85. cmSystemTools::GetFilenameWithoutLastExtension(
  86. sf->GetFullPath().c_str()));
  87. objectName += ".obj";
  88. if(objectNameCounts[objectName] > 1)
  89. {
  90. this->NeedObjectName.insert(sf);
  91. }
  92. }
  93. }
  94. }
  95. }
  96. //----------------------------------------------------------------------------
  97. std::string
  98. cmLocalVisualStudioGenerator
  99. ::ConstructScript(const cmCustomCommandLines& commandLines,
  100. const char* workingDirectory,
  101. const char* newline)
  102. {
  103. // Store the script in a string.
  104. std::string script;
  105. if(workingDirectory)
  106. {
  107. script += "cd ";
  108. script += this->Convert(workingDirectory, START_OUTPUT, SHELL);
  109. script += newline;
  110. }
  111. // for visual studio IDE add extra stuff to the PATH
  112. // if CMAKE_MSVCIDE_RUN_PATH is set.
  113. if(this->Makefile->GetDefinition("MSVC_IDE"))
  114. {
  115. const char* extraPath =
  116. this->Makefile->GetDefinition("CMAKE_MSVCIDE_RUN_PATH");
  117. if(extraPath)
  118. {
  119. script += "set PATH=";
  120. script += extraPath;
  121. script += ";%PATH%";
  122. script += newline;
  123. }
  124. }
  125. // Write each command on a single line.
  126. for(cmCustomCommandLines::const_iterator cl = commandLines.begin();
  127. cl != commandLines.end(); ++cl)
  128. {
  129. // Start with the command name.
  130. const cmCustomCommandLine& commandLine = *cl;
  131. script += this->Convert(commandLine[0].c_str(),START_OUTPUT,SHELL);
  132. // Add the arguments.
  133. for(unsigned int j=1;j < commandLine.size(); ++j)
  134. {
  135. script += " ";
  136. script += this->EscapeForShell(commandLine[j].c_str());
  137. }
  138. // End the line.
  139. script += newline;
  140. }
  141. return script;
  142. }