The problem is already at the "Check for working Fortran compiler" phase. As described in the issue above, CMake is trying to use gfortran for linking and passes incorrect options to it.

My understanding is that on Windows, one must use gfortran to build a dll, and then dynamically link it with MSVC, with the proper cmake options like `-DCMAKE_GNUtoMS=ON -DBUILD_SHARED_LIBS=ON`. However, this can only be done once the "Check for working Fortran compiler" phase passes.

How do I make CMake pass the "Check for working Fortran compiler" phase?

Re: cmake thinks mingw-64 gfortran on Windows is broken

On 03/09/2018 07:58 PM, Ondřej Čertík wrote:
> How do I make CMake pass the "Check for working Fortran compiler" phase?

The problem reported in issue 17810 is caused by trying to
enable C with MSVC and Fortran with GNU together at the same
time, e.g. `project(MyProj C Fortran)`. These tools cannot
be used together directly.

The purpose of cmake_add_fortran_subdirectory as described
in the blog post is to avoid enabling Fortran in the main
project. Instead Fortran is only enabled in a separate project
by itself, and the main project gets only C (and CXX).

If you want to use MSVC and Fortran together directly then you
need a Fortran compiler that works with the MSVC binutils. The
Intel Fortran compiler for Windows, a commercial tool, is one
option. There is also https://github.com/flang-compiler/flang,
which is currently maturing.

Alternatively you can use GNU from MinGW for all languages,
e.g. `CC=gcc CXX=g++ FC=gfortran cmake ../src`.