LFortran now recognized by CMake

I don’t think this has been mentioned elsewhere, see the release notes for CMake 3.31 Lfortran is now supported in CMake! :smiley:

16 Likes

Yes. Please report all bugs. This is a new feature and some things might break.

2 Likes

This is great to hear, fantastic!

2 Likes

How to use it?

I tried lfortran-0.63.0\examples\project1 on Win 10 with cmake 4.3.2.

The readme.md says:

To compile with LFortran:

    FC=lfortran cmake .

Have to changed to:

cmake FC=lfortran .

The error is:

D:\00masterLib\lfortran-0.63.0\examples\project1>cmake FC=lfortran .
-- Selecting Windows SDK version 10.0.26100.0 to target Windows 10.0.19045.
-- The Fortran compiler identification is IntelLLVM 2025.1.0 with MSVC-like command-line
CMake Error at CMakeLists.txt:3 (project):
  The CMAKE_Fortran_COMPILER:

    lfortran

  is not a full path and was not found in the PATH.  Perhaps the extension is
  missing?

I have Intel Fortran on my pc. It found IntelLLVM first, then says lfortran not found. In that folder, I do can start lfortran. My lfortran.exe is at D:\00masterLib\lfortran-0.63.0\inst\bin\lfortran.exe and it is in the PATH.

Thanks for help

Cean

I don’t know how to fix it. I don’t have time right now to debug it myself, but if somebody can help with setting up cmake+lfortran on Windows, that would be highly appreciated. It works on linux/macOS.

I uploaded my lfortran_0.63.0.exe to my google drive. 20.54MB

https://drive.google.com/file/d/11GRJIIPredV8lLlsPljtQHL0FDObDxM6/view?usp=drivesdk

After unzip, all under an inst folder. Need to set the inst/bin into Windows 10’s PATH.

If lfortran asks some Dlls to run, upzip these into the bin folder. 9.49MB.

https://drive.google.com/file/d/1NWAF8EqfsKtw8uyMTnPC2eQMtaeyPrE8/view?usp=drivesdk

Because lfortran needs VS’s link to generate exe file, you must have VS installed and run lfortran inside the X64 native terminal.

Hope that will help.

it might be a CMake for windows thing? Can you use the WSL?

Not really want to use wsl.

What file and where cmake look for lFortran? Never tried to figure out how the find package works.

you can use cmake --debug-find ../ to see what it is looking for

Put full path worked.

cmake -DCMAKE_Fortran_COMPILER="D:/bjbin/lfortran/bin/lfortran.exe" .
3 Likes

This generates sln file. When loaded in VS, it is actually build by Intel Fortran on my computer.

I should add the -G “Unix Makefiles”. Then it generates makefile file and then can be build by lfortran.

Disable my Intel Fortran first, then no need for full path of lfortran.