Explorar o código

Merge topic 'vs-per-config-sources'

55a0bebdd3 VS: Add support for per-config sources
bcaecf6bcd Teach check for single-language targets to consider all configurations
324988a6b1 cmGeneratorTarget: Add GetAllConfigCompileLanguages method
fd2c9fac10 cmGeneratorTarget: Return non-const sources from GetAllConfigSources

Acked-by: Kitware Robot <[email protected]>
Merge-request: !3882
Brad King %!s(int64=6) %!d(string=hai) anos
pai
achega
50afd147f8

+ 5 - 0
Help/release/dev/vs-per-config-sources.rst

@@ -0,0 +1,5 @@
+vs-per-config-sources
+---------------------
+
+* :ref:`Visual Studio Generators` learned to support per-config sources.
+  Previously only :ref:`Command-Line Build Tool Generators` supported them.

+ 14 - 2
Source/cmGeneratorTarget.cxx

@@ -1670,6 +1670,19 @@ void cmGeneratorTarget::ComputeAllConfigSources() const
   }
 }
 
+std::set<std::string> cmGeneratorTarget::GetAllConfigCompileLanguages() const
+{
+  std::set<std::string> languages;
+  std::vector<AllConfigSource> const& sources = this->GetAllConfigSources();
+  for (AllConfigSource const& si : sources) {
+    std::string const& lang = si.Source->GetOrDetermineLanguage();
+    if (!lang.empty()) {
+      languages.emplace(lang);
+    }
+  }
+  return languages;
+}
+
 std::string cmGeneratorTarget::GetCompilePDBName(
   const std::string& config) const
 {
@@ -6343,8 +6356,7 @@ bool cmGeneratorTarget::IsCSharpOnly() const
       this->GetType() != cmStateEnums::EXECUTABLE) {
     return false;
   }
-  std::set<std::string> languages;
-  this->GetLanguages(languages, "");
+  std::set<std::string> languages = this->GetAllConfigCompileLanguages();
   // Consider an explicit linker language property, but *not* the
   // computed linker language that may depend on linked targets.
   const char* linkLang = this->GetProperty("LINKER_LANGUAGE");

+ 5 - 1
Source/cmGeneratorTarget.h

@@ -123,7 +123,7 @@ public:
 
   struct AllConfigSource
   {
-    cmSourceFile const* Source;
+    cmSourceFile* Source;
     cmGeneratorTarget::SourceKind Kind;
     std::vector<size_t> Configs;
   };
@@ -132,6 +132,10 @@ public:
       per-source configurations assigned.  */
   std::vector<AllConfigSource> const& GetAllConfigSources() const;
 
+  /** Get all languages used to compile sources in any configuration.
+      This excludes the languages of objects from object libraries.  */
+  std::set<std::string> GetAllConfigCompileLanguages() const;
+
   void GetObjectSources(std::vector<cmSourceFile const*>&,
                         const std::string& config) const;
   const std::string& GetObjectName(cmSourceFile const* file);

+ 1 - 11
Source/cmGlobalVisualStudioGenerator.cxx

@@ -799,19 +799,9 @@ void RegisterVisualStudioMacros(const std::string& macrosFile,
 bool cmGlobalVisualStudioGenerator::TargetIsFortranOnly(
   cmGeneratorTarget const* gt)
 {
-  // check to see if this is a fortran build
-  {
-    // Issue diagnostic if the source files depend on the config.
-    std::vector<cmSourceFile*> sources;
-    if (!gt->GetConfigCommonSourceFiles(sources)) {
-      return false;
-    }
-  }
-
   // If there's only one source language, Fortran has to be used
   // in order for the sources to compile.
-  std::set<std::string> languages;
-  gt->GetLanguages(languages, "");
+  std::set<std::string> languages = gt->GetAllConfigCompileLanguages();
   // Consider an explicit linker language property, but *not* the
   // computed linker language that may depend on linked targets.
   // This allows the project to control the language choice in

+ 1 - 1
Source/cmLocalVisualStudio7Generator.cxx

@@ -1329,7 +1329,7 @@ void cmLocalVisualStudio7Generator::WriteVCProjFile(std::ostream& fout,
   // Add CMakeLists.txt file with rule to re-run CMake for user convenience.
   if (target->GetType() != cmStateEnums::GLOBAL_TARGET &&
       target->GetName() != CMAKE_CHECK_BUILD_SYSTEM_TARGET) {
-    if (cmSourceFile const* sf = this->CreateVCProjBuildRule()) {
+    if (cmSourceFile* sf = this->CreateVCProjBuildRule()) {
       cmGeneratorTarget::AllConfigSource acs;
       acs.Source = sf;
       acs.Kind = cmGeneratorTarget::SourceKindCustomCommand;

+ 6 - 2
Tests/CMakeLists.txt

@@ -451,8 +451,12 @@ if(BUILD_TESTING)
   ADD_TEST_MACRO(StagingPrefix StagingPrefix)
   ADD_TEST_MACRO(ImportedSameName ImportedSameName)
   ADD_TEST_MACRO(InterfaceLibrary InterfaceLibrary)
-  if(NOT _isMultiConfig)
-    set(ConfigSources_BUILD_OPTIONS -DCMAKE_BUILD_TYPE=$<CONFIGURATION>)
+  if(NOT CMAKE_GENERATOR STREQUAL "Xcode")
+    if(_isMultiConfig)
+      set(ConfigSources_CTEST_OPTIONS --build-config $<CONFIGURATION>)
+    else()
+      set(ConfigSources_BUILD_OPTIONS -DCMAKE_BUILD_TYPE=$<CONFIGURATION>)
+    endif()
     ADD_TEST_MACRO(ConfigSources ConfigSources)
   endif()
   ADD_TEST_MACRO(SourcesProperty SourcesProperty)

+ 1 - 1
Tests/RunCMake/TargetSources/RunCMakeTest.cmake

@@ -1,6 +1,6 @@
 include(RunCMake)
 
-if(RunCMake_GENERATOR MATCHES "Visual Studio|Xcode")
+if(RunCMake_GENERATOR STREQUAL "Xcode")
   run_cmake(ConfigNotAllowed)
 endif()