premake / premake-core

Premake
https://premake.github.io/
BSD 3-Clause "New" or "Revised" License
3.22k stars 620 forks source link

Adding a Visual Fortran Project in Visual Studio #1309

Closed TsarpDev closed 5 years ago

TsarpDev commented 5 years ago

Hello premake community, There are some mathematical libraries written in Fortran (Blas/Lapack etc.) and I'd like to combine them with C/C++ applications. Is it possible to hack my way around and create intel visual fortran projects with premake? The procedure to create a fortran project in Visual Studio is fairly easy; File/New/Project and I select Intel(R) Visual Fortran and then console application or library, the same as for a C/C++ project. Thank you in advance

samsinsane commented 5 years ago

Is it possible to hack my way around and create intel visual fortran projects with premake?

Definitely, you can look at the code in the modules folder for examples on generating project files; vstudio and android contain code to generate VS projects. There's also community modules that can show the same thing here. If you already have the projects themselves, you can also cheat a bit and just add support for using externalproject, but I don't recall off the top of my head what's required to do that.

The procedure to create a fortran project in Visual Studio is fairly easy; File/New/Project and I select Intel(R) Visual Fortran and then console application or library, the same as for a C/C++ project.

I wasn't able to follow along here, I assume that you need the Intel compiler for this? I'm not sure how many have that so you might be a bit on your own here?

TsarpDev commented 5 years ago

Thank you for you answer, I wanted to point out that the procedure in Visual Studio in order to create a fortran project is similar to a c/c++ (I thought that this might be helpful). Anyway my main problem is that there is no option for fortran language, as I can see from the wiki. Even if I create the project on my own, I cannot find a way to use externalproject command as it still requires a language to be defined.

samsinsane commented 5 years ago

Even if I create the project on my own, I cannot find a way to use externalproject command as it still requires a language to be defined.

That's fine, you can do something like this in your premake5.lua:

require "vstudio"
premake.api.addAllowed("language", "Fortran")
table.insert(premake.action.get("vs2019").valid_languages, "Fortran") -- Whatever action you're using
premake.override(premake.vstudio, "tool", function(oldfn, prj)
  if prj.language == "Fortran" then
    return "6989167D-11E4-40FE-8C1A-2192A86A7E90" -- From what I could find online, this is what is used for `.vfproj` files?
  end
  return oldfn(prj)
end)

If that UUID is wrong, just open the .sln and find a line for a Fortran project, and grab the first UUID on the line:

Project("{6989167D-11E4-40FE-8C1A-2192A86A7E90}") = "Example", "Exmaple.vfproj", "{97E4A8DA-C94F-459D-AD7B-58DC5A8810D1}"

It's been a while since I've added a new project type so I may have missed something. The D module has an example of adding in a new language and a new VS project type(.visualdproj).