<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]--><style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;
mso-fareast-language:EN-US;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:#954F72;
text-decoration:underline;}
p.msonormal0, li.msonormal0, div.msonormal0
{mso-style-name:msonormal;
mso-margin-top-alt:auto;
margin-right:0cm;
mso-margin-bottom-alt:auto;
margin-left:0cm;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
span.EmailStyle18
{mso-style-type:personal;
font-family:"Calibri",sans-serif;}
span.EmailStyle21
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-GB" link="#0563C1" vlink="#954F72">
<div class="WordSection1">
<p class="MsoNormal">Thank you KT; let’s see what they say. <o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Like in your case, I have a project structure where my Fortran library depends on various C libraries, and my C++ application depends on those same C libraries both indirectly (through the Fortran library) and directly. I’d like to be able
to use the MSVC versions of those C libraries (and as the interfaces are C, not C++, this ought to be straightforward). Currently, however, the only way I can get my Fortran code to compile is if I call it from the command line with the “MinGW Makefiles” generator,
in which case it uses MinGW versions for all the other libraries as well. <o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Warm regards,<o:p></o:p></p>
<p class="MsoNormal">Stephen. <o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span lang="EN-US" style="mso-fareast-language:EN-GB">From:</span></b><span lang="EN-US" style="mso-fareast-language:EN-GB"> Thompson, KT <kgt@lanl.gov>
<br>
<b>Sent:</b> 14 January 2019 04:06<br>
<b>To:</b> Stephen Morris <s-morris@n-eos.com>; cmake@cmake.org<br>
<b>Subject:</b> Re: How to specify gfortran in an MSVC project<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div id="divtagdefaultwrapper">
<p><span style="font-size:12.0pt;color:black">Hi Stephen,<o:p></o:p></span></p>
<p><span style="font-size:12.0pt;color:black"><o:p> </o:p></span></p>
<p><span style="font-size:12.0pt;color:black">I am also interested in Kitware's response to your question. I don't use Qt Creator, but I help maintain several projects that use Visual Studio and MinGW gfortran via the CMakeAddFortranSubdirectory feature.
This feature is somewhat limited and not really maintained (in my experience).<o:p></o:p></span></p>
<p><span style="font-size:12.0pt;color:black"><o:p> </o:p></span></p>
<p><span style="font-size:12.0pt;color:black">Background: In my case, I use a heavily modified version of CMakeAddFortranSubdirectory that supports Xcode builds in addition to MSVC. I also have dependencies of the form mycpp.exe -> myf90.lib -> mycpp.lib
-> msmpi.lib that standard CMakeAddFortranSubdirectory doesn't know how to deal with.<o:p></o:p></span></p>
<p><span style="font-size:12.0pt;color:black"><o:p> </o:p></span></p>
<p><span style="font-size:12.0pt;color:black">When I run the 'build' target via Visual Studio, the Fortran compiler is discovered by CMakeAddFortranSubdirectory only if gfortran.exe is in %PATH% (via find_program -- I believe that the default code only supports
the name 'gfortran.exe'.) You might need to add </span><span style="font-size:12.0pt;color:#212121">C:/Qt/Tools/mingw730_64/bin/ to your local path before running cmake for the project. I have found that CMakeAddFortranSubdirectory isn't flexible. You may
need modify it for your own needs. </span><span style="font-size:12.0pt;color:black"><o:p></o:p></span></p>
<p><span style="font-size:12.0pt;color:black"><o:p> </o:p></span></p>
<p><span style="font-size:12.0pt;color:#212121">-kt</span><span style="font-size:12.0pt;color:black"><o:p></o:p></span></p>
</div>
<div class="MsoNormal" align="center" style="text-align:center"><span style="mso-fareast-language:EN-GB">
<hr size="2" width="98%" align="center">
</span></div>
<div id="divRplyFwdMsg">
<p class="MsoNormal"><b><span style="color:black;mso-fareast-language:EN-GB">From:</span></b><span style="color:black;mso-fareast-language:EN-GB"> CMake <<a href="mailto:cmake-bounces@cmake.org">cmake-bounces@cmake.org</a>> on behalf of Stephen Morris <<a href="mailto:s-morris@n-eos.com">s-morris@n-eos.com</a>><br>
<b>Sent:</b> Sunday, January 13, 2019 6:14:33 PM<br>
<b>To:</b> <a href="mailto:cmake@cmake.org">cmake@cmake.org</a><br>
<b>Subject:</b> [CMake] How to specify gfortran in an MSVC project</span><span style="mso-fareast-language:EN-GB">
<o:p></o:p></span></p>
<div>
<p class="MsoNormal"><span style="mso-fareast-language:EN-GB"> <o:p></o:p></span></p>
</div>
</div>
<div>
<p class="MsoNormal">I would like to try to use 64-bit gfortran to compile a project in which the rest of the code is compiled with Visual C++ 2017. I’ve read the netlib article (<a href="http://www.netlib.org/lapack/lawnspdf/lawn270.pdf">http://www.netlib.org/lapack/lawnspdf/lawn270.pdf</a>)
but it doesn’t address my problem, which is how to help CMake select the right Fortran compiler. The CMakeLists.txt file is launched from within Qt Creator.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">My CMakeLists.txt file (which I’ve tested thoroughly using gfortran in Linux and MinGW gfortran on Windows) begins:<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"> cmake_minimum_required(VERSION 3.12)<o:p></o:p></p>
<p class="MsoNormal"> project(myProj LANGUAGES Fortran)<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">...and if I set Qt Creator to parse it with the MSVC compiler option selected, the output is:<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"> Starting to parse CMake project, using: "-DCMAKE_CXX_COMPILER:STRING=C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/HostX86/x64/cl.exe", "-DCMAKE_C_COMPILER:STRING=C:/Program Files (x86)/Microsoft
Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/HostX86/x64/cl.exe", "-DCMAKE_PREFIX_PATH:STRING=C:/Qt/5.9.7/msvc2017_64", "-DQT_QMAKE_EXECUTABLE:STRING=C:/Qt/5.9.7/msvc2017_64/bin/qmake.exe".<o:p></o:p></p>
<p class="MsoNormal"> The Fortran compiler identification is unknown<o:p></o:p></p>
<p class="MsoNormal"> CMake Error at CMakeLists.txt:2 (project):<o:p></o:p></p>
<p class="MsoNormal"> No CMAKE_Fortran_COMPILER could be found.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"> Tell CMake where to find the compiler by setting either the environment<o:p></o:p></p>
<p class="MsoNormal"> variable "FC" or the CMake cache entry CMAKE_Fortran_COMPILER to the full<o:p></o:p></p>
<p class="MsoNormal"> path to the compiler, or to the compiler name if it is in the PATH.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Fair enough; here’s my second attempt:<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"> cmake_minimum_required(VERSION 3.12)<o:p></o:p></p>
<p class="MsoNormal"> set(CMAKE_Fortran_COMPILER "C:/Qt/Tools/mingw730_64/bin/gfortran.exe")<o:p></o:p></p>
<p class="MsoNormal"> project(myProj LANGUAGES Fortran)<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">...and this gives me:<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"> Starting to parse CMake project, using: "-DCMAKE_CXX_COMPILER:STRING=C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/HostX86/x64/cl.exe", "-DCMAKE_C_COMPILER:STRING=C:/Program Files (x86)/Microsoft
Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/HostX86/x64/cl.exe", "-DCMAKE_PREFIX_PATH:STRING=C:/Qt/5.9.7/msvc2017_64", "-DQT_QMAKE_EXECUTABLE:STRING=C:/Qt/5.9.7/msvc2017_64/bin/qmake.exe".<o:p></o:p></p>
<p class="MsoNormal"> The Fortran compiler identification is unknown<o:p></o:p></p>
<p class="MsoNormal"> Check for working Fortran compiler: C:/Qt/Tools/mingw730_64/bin/gfortran.exe<o:p></o:p></p>
<p class="MsoNormal"> CMake Error: Error required internal CMake variable not set, cmake may not be built correctly.<o:p></o:p></p>
<p class="MsoNormal"> Missing variable is:<o:p></o:p></p>
<p class="MsoNormal"> CMAKE_Fortran_PREPROCESS_SOURCE<o:p></o:p></p>
<p class="MsoNormal"> CMake Error at C:/Program Files/CMake/share/cmake-3.12/Modules/CMakeTestFortranCompiler.cmake:30 (try_compile):<o:p></o:p></p>
<p class="MsoNormal"> Failed to generate test project build system.<o:p></o:p></p>
<p class="MsoNormal"> Call Stack (most recent call first):<o:p></o:p></p>
<p class="MsoNormal"> CMakeLists.txt:3 (project)<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">In place of the “set(CMAKE_Fortran_COMPILER...” line I’ve also tried<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal"> set($ENV{FC} "C:/Qt/Tools/mingw730_64/bin/gfortran.exe")<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">...which gave me the error message<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"> Could not find compiler set in environment variable FC:<o:p></o:p></p>
<p class="MsoNormal"> CMAKE_Fortran_COMPILER-NOTFOUND<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">..and<o:p></o:p></p>
<p class="MsoNormal"> set($ENV{FC} "C:/Qt/Tools/mingw730_64/bin")<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">... which gave me exactly the same error as I got in the first case.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">So what am I doing wrong here? <o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
</body>
</html>