Cmake Cannot Find my Fortran Compiler

I am trying to compile the NJOY 2016 program from Los Alamos National Laboratory on Windows Professional v10. It comes with its own CMakeLists.txt and searches for the Fortran compiler because it is designed to run on a variety of systems. I am using CMake v3.31.3. The build process needs both Python and a Fortran compiler. It finds Python with no problem. It cannot find my GNU Fortran compiler. My path is as follows:
PATH=C:\Program Files\Python313\Scripts;C:\Program Files\Python313;C:\Program Files\Microsoft MPI\Bin;
C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;
C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\dotnet;C:\Program Files (x86)\dotnet;
C:\Program Files\gs\gs10.04.0\bin;C:\Program Files\CMake\bin;C:\Program Files\NVIDIA Corporation\NVIDIA app\NvDLISR;
C:\Program Files (x86)\Simply Fortran 3\mingw-w64\bin;C:\Program Files (x86)\Simply Fortran 3\mingw-w64\x86_64-w64-mingw32\lib32;
C:\Program Files (x86)\Simply Fortran 3\mingw-w64\x86_64-w64-mingw32\lib;
C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit;
C:\Program Files (x86)\Windows Kits\10\Microsoft Application Virtualization\Sequencer;
C:\Program Files\Git\cmd;C:\Users\Jeff\AppData\Local\Microsoft\WindowsApps;

I also have Visual Studio 2022 but it is not in the path. I use Git to successfully clone the source code from Los Alamos into D:_Nuclear\LANL\NJOY\NJOY2016\NJOY2016>. I then make a build directory and cd into it. I execute the following command:
D:_Nuclear\LANL\NJOY\NJOY2016\NJOY2016\build>cmake -DCMAKE_BUILD_TYPE=Release -Dstatic_libraries=ON -Dstatic_njoy=ON -DCMAKE_EXE_LINKER_FLAGS=-static …/
The responses are:
– Building for: Visual Studio 17 2022
– Found Python3: C:/Program Files/Python313/python.exe (found suitable version “3.13.2”, minimum required is “3.5”) found components: Interpreter
– Selecting Windows SDK version 10.0.22621.0 to target Windows 10.0.19045.
– The Fortran compiler identification is unknown
CMake Error at CMakeLists.txt:8 (project):
No CMAKE_Fortran_COMPILER could be found.

– Configuring incomplete, errors occurred!
Cmake locates the Visual Studio 2022 installation but it has no Fortran compiler. Los Alamos advised me to add the following command to my Cmake command line:
-DCMAKE_Fortran_COMPILER=/my/path/to/fortran/compiler.exe, which for me is:
-DCMAKE_Fortran_COMPILER=“C:\Program Files (x86)\Simply Fortran 3\mingw-w64\bin\gfortran.exe”
But this does not help. I have tried the path with and without double quotes and single quotes with no success.
I am guessing that the problem has something to do with the blanks in the path, but I don’t think I can change the installation path for the Simply Fortran package.

Can anyone advise?

The GNU fortran compiler won’t work with MSVC. There is a way to use it but you would need to modify the CMake code for the project to use https://cmake.org/cmake/help/latest/module/CMakeAddFortranSubdirectory.html. Alternatively, you can install the IntelOneAPI fortran compiler and use that as a compatible fortran compiler with MSVC. You might also want to try using the ninja generator for CMake. But make sure you run from a shell that is setup with cl and ifort in the PATH.

Thank you for your suggestion. I understand that the GNU Fortran compiler will not normally work with MSVC, but thhis particular software has no C routines in the code. I hope eventually to get the Intel compiler installed but right now I just need to get CMake to find the GNU Fortran compiler and ignore MSVC. I am puzzled that CMake finds the MSVC compiler even though it is not in the path but cannot find the GNU Fortran compiler when it is in the path.

Because you use the wrong generator! Visual Studio is the default generator on Windows but only supports certain toolsets.

Of you want to use gfortran, you MUST NOT use the visual studio generator!

Thank you for the information. I will search the documentation for how to specify a GNU generator. Eventually I hope to install Intel Fortran to work in conjunction with Visual Studio but that is a project in itself.