From fd2c9fac101ec6d341db5b30e9d1eba64fa23116 Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 2 Oct 2019 13:48:37 -0400 Subject: cmGeneratorTarget: Return non-const sources from GetAllConfigSources We need a non-const pointer to `cmSourceFile` instances in order to call `GetOrDetermineLanguage` on them. --- Source/cmGeneratorTarget.h | 2 +- Source/cmLocalVisualStudio7Generator.cxx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index 1f824b1..c2811b2 100644 --- a/Source/cmGeneratorTarget.h +++ b/Source/cmGeneratorTarget.h @@ -123,7 +123,7 @@ public: struct AllConfigSource { - cmSourceFile const* Source; + cmSourceFile* Source; cmGeneratorTarget::SourceKind Kind; std::vector Configs; }; diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx index ff1eaec..fd346df 100644 --- a/Source/cmLocalVisualStudio7Generator.cxx +++ b/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; -- cgit v0.12 From 324988a6b101f29d148badc32b44964aedae1163 Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 2 Oct 2019 13:57:12 -0400 Subject: cmGeneratorTarget: Add GetAllConfigCompileLanguages method Return all languages needed to compile sources in the target in any configuration. --- Source/cmGeneratorTarget.cxx | 13 +++++++++++++ Source/cmGeneratorTarget.h | 4 ++++ 2 files changed, 17 insertions(+) diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 949d9d9..0cc70c7 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -1670,6 +1670,19 @@ void cmGeneratorTarget::ComputeAllConfigSources() const } } +std::set cmGeneratorTarget::GetAllConfigCompileLanguages() const +{ + std::set languages; + std::vector 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 { diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index c2811b2..4623513 100644 --- a/Source/cmGeneratorTarget.h +++ b/Source/cmGeneratorTarget.h @@ -132,6 +132,10 @@ public: per-source configurations assigned. */ std::vector const& GetAllConfigSources() const; + /** Get all languages used to compile sources in any configuration. + This excludes the languages of objects from object libraries. */ + std::set GetAllConfigCompileLanguages() const; + void GetObjectSources(std::vector&, const std::string& config) const; const std::string& GetObjectName(cmSourceFile const* file); -- cgit v0.12 From bcaecf6bcddfaec2b586bff870650a4a66b0ccc3 Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 4 Oct 2019 10:42:03 -0400 Subject: Teach check for single-language targets to consider all configurations --- Source/cmGeneratorTarget.cxx | 3 +-- Source/cmGlobalVisualStudioGenerator.cxx | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 0cc70c7..d5e58b0 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -6356,8 +6356,7 @@ bool cmGeneratorTarget::IsCSharpOnly() const this->GetType() != cmStateEnums::EXECUTABLE) { return false; } - std::set languages; - this->GetLanguages(languages, ""); + std::set 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"); diff --git a/Source/cmGlobalVisualStudioGenerator.cxx b/Source/cmGlobalVisualStudioGenerator.cxx index ed0cba7..6569e5e 100644 --- a/Source/cmGlobalVisualStudioGenerator.cxx +++ b/Source/cmGlobalVisualStudioGenerator.cxx @@ -810,8 +810,7 @@ bool cmGlobalVisualStudioGenerator::TargetIsFortranOnly( // If there's only one source language, Fortran has to be used // in order for the sources to compile. - std::set languages; - gt->GetLanguages(languages, ""); + std::set 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 -- cgit v0.12 From 55a0bebdd3d253f81bd89782702d481ac81110b3 Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 2 Oct 2019 13:59:15 -0400 Subject: VS: Add support for per-config sources Since commit 97cc29c766 (VS: Teach generators how to mark per-config source files, 2017-04-10, v3.9.0-rc1~268^2~2) the VS generators have known how to generate per-config sources. We've now converted most other code paths to support per-config sources, so drop the check that disallows it. This leaves only per-config support for precompiled headers and unity build transformations, but those are optional features that can be addressed later. Fixes: #18233 Issue: #19789 --- Help/release/dev/vs-per-config-sources.rst | 5 +++++ Source/cmGlobalVisualStudioGenerator.cxx | 9 --------- Tests/CMakeLists.txt | 8 ++++++-- Tests/RunCMake/TargetSources/RunCMakeTest.cmake | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) create mode 100644 Help/release/dev/vs-per-config-sources.rst diff --git a/Help/release/dev/vs-per-config-sources.rst b/Help/release/dev/vs-per-config-sources.rst new file mode 100644 index 0000000..bf7572b --- /dev/null +++ b/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. diff --git a/Source/cmGlobalVisualStudioGenerator.cxx b/Source/cmGlobalVisualStudioGenerator.cxx index 6569e5e..5412407 100644 --- a/Source/cmGlobalVisualStudioGenerator.cxx +++ b/Source/cmGlobalVisualStudioGenerator.cxx @@ -799,15 +799,6 @@ 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 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 languages = gt->GetAllConfigCompileLanguages(); diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index b29638b..185401f 100644 --- a/Tests/CMakeLists.txt +++ b/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=$) + if(NOT CMAKE_GENERATOR STREQUAL "Xcode") + if(_isMultiConfig) + set(ConfigSources_CTEST_OPTIONS --build-config $) + else() + set(ConfigSources_BUILD_OPTIONS -DCMAKE_BUILD_TYPE=$) + endif() ADD_TEST_MACRO(ConfigSources ConfigSources) endif() ADD_TEST_MACRO(SourcesProperty SourcesProperty) diff --git a/Tests/RunCMake/TargetSources/RunCMakeTest.cmake b/Tests/RunCMake/TargetSources/RunCMakeTest.cmake index bee8c4e..0d462ba 100644 --- a/Tests/RunCMake/TargetSources/RunCMakeTest.cmake +++ b/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() -- cgit v0.12