cmLocalVisualStudioGenerator.cxx 5.4 KB

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