From eae0a053f5155b9826d3f96508c66e66a8867051 Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 16 Sep 2025 14:22:37 -0400 Subject: [PATCH] VS: Default Intel Fortran projects to ifx in VS 18 and above Intel oneAPI distributions no longer include the `ifort` compiler, but its Visual Studio Integration defaults to `ifort` if `ifx` is not explicitly specified in the `.vfproj` file. We cannot change the default Fortran compiler in VS 17 and older, but since the VS 18 generator is new, we can establish `ifx` as its default. This establishes working defaults on new versions of VS and oneAPI while retaining existing behavior on older versions. Issue: #26415 --- Help/variable/CMAKE_VS_PLATFORM_TOOLSET_FORTRAN.rst | 9 ++++++++- Source/cmGlobalVisualStudio10Generator.cxx | 9 +++++++++ Source/cmGlobalVisualStudio10Generator.h | 6 ++---- Source/cmGlobalVisualStudioVersionedGenerator.cxx | 3 +++ 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/Help/variable/CMAKE_VS_PLATFORM_TOOLSET_FORTRAN.rst b/Help/variable/CMAKE_VS_PLATFORM_TOOLSET_FORTRAN.rst index c7e414835f..afad4b2465 100644 --- a/Help/variable/CMAKE_VS_PLATFORM_TOOLSET_FORTRAN.rst +++ b/Help/variable/CMAKE_VS_PLATFORM_TOOLSET_FORTRAN.rst @@ -9,4 +9,11 @@ Fortran compiler to be used by Visual Studio projects. that have the required Visual Studio Integration feature installed. The compiler may be specified by a field in :variable:`CMAKE_GENERATOR_TOOLSET` of the form ``fortran=...``. CMake provides the selected Fortran compiler in this -variable. The value may be empty if the field was not specified. +variable. + +If the field was not specified, the default depends on the generator: + +* On :generator:`Visual Studio 18 2026` and above, the default is ``ifx``. + +* On older :ref:`Visual Studio Generators`, the default is empty, which the + Intel Visual Studio Integration interprets as equivalent to ``ifort``. diff --git a/Source/cmGlobalVisualStudio10Generator.cxx b/Source/cmGlobalVisualStudio10Generator.cxx index cb447aac83..c3b9fe8f69 100644 --- a/Source/cmGlobalVisualStudio10Generator.cxx +++ b/Source/cmGlobalVisualStudio10Generator.cxx @@ -797,6 +797,15 @@ std::string const& cmGlobalVisualStudio10Generator:: return this->GeneratorToolsetCudaVSIntegrationSubdir; } +cm::optional +cmGlobalVisualStudio10Generator::GetPlatformToolsetFortran() const +{ + if (this->GeneratorToolsetFortran) { + return this->GeneratorToolsetFortran; + } + return this->DefaultToolsetFortran; +} + cmGlobalVisualStudio10Generator::AuxToolset cmGlobalVisualStudio10Generator::FindAuxToolset(std::string&, std::string&) const diff --git a/Source/cmGlobalVisualStudio10Generator.h b/Source/cmGlobalVisualStudio10Generator.h index 5248b4da9d..486060f3cb 100644 --- a/Source/cmGlobalVisualStudio10Generator.h +++ b/Source/cmGlobalVisualStudio10Generator.h @@ -94,10 +94,7 @@ public: std::string const& GetPlatformToolsetCudaVSIntegrationSubdirString() const; /** The fortran toolset name. */ - cm::optional GetPlatformToolsetFortran() const override - { - return this->GeneratorToolsetFortran; - } + cm::optional GetPlatformToolsetFortran() const override; /** Return whether we need to use No/Debug instead of false/true for GenerateDebugInformation. */ @@ -234,6 +231,7 @@ protected: std::string GeneratorToolsetCudaNvccSubdir; std::string GeneratorToolsetCudaVSIntegrationSubdir; cm::optional GeneratorToolsetFortran; + cm::optional DefaultToolsetFortran; std::string DefaultPlatformToolset; std::string DefaultPlatformToolsetHostArchitecture; std::string DefaultAndroidToolset; diff --git a/Source/cmGlobalVisualStudioVersionedGenerator.cxx b/Source/cmGlobalVisualStudioVersionedGenerator.cxx index 238475782a..bc13358602 100644 --- a/Source/cmGlobalVisualStudioVersionedGenerator.cxx +++ b/Source/cmGlobalVisualStudioVersionedGenerator.cxx @@ -513,6 +513,9 @@ cmGlobalVisualStudioVersionedGenerator::cmGlobalVisualStudioVersionedGenerator( // Use a version installed by VS 2022 without a separate component. this->DefaultTargetFrameworkVersion = "v4.7.2"; } + if (this->Version >= cmGlobalVisualStudioGenerator::VSVersion::VS18) { + this->DefaultToolsetFortran = "ifx"; + } } bool cmGlobalVisualStudioVersionedGenerator::MatchesGeneratorName(