premake / premake-core

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

Premake alternative to the CMake interface library #2153

Open learn-more opened 1 year ago

learn-more commented 1 year ago

Is there a Premake alternative to the CMake concept of an 'interface' library?

An 'interface' library has the following properties when linking against it:

The main advantage I see with this is that we don't have to pollute the preprocessor macro's / include / link paths for all projects, just for the projects that need it.

Given this pseudo premake5.lua file:

project "gsl"
    kind "Interface"
    includedirs { "gsl/include" }
    defines { "HAS_GSL" }

project "example_1"
    kind "ConsoleApp"
    files { "main.cpp" }
    links { "gsl" }

project "example_2"
    kind "ConsoleApp"
    files { "main.cpp" }

This would mean that example_1 has the folder gsl/include added to the include paths, and the define HAS_GSL set.

Jarod42 commented 1 year ago

Related to https://github.com/premake/premake-core/issues/1346

As premake uses Lua, you might still create Lua functions:

function useGsl()
    externalincludedirs { "gsl/include" }
    defines { "HAS_GSL" }
end

and then

project "example_1"
    kind "ConsoleApp"
    files { "main.cpp" }
    useGsl()

project "example_2"
    kind "ConsoleApp"
    files { "main.cpp" }
learn-more commented 1 year ago

That works, until you move the function to other directories, because the relative paths will be relative to where the function is used, instead of where the function is defined.

nickclark2016 commented 1 year ago

This isn't something that's on the roadmap for v5 currently (we would gladly accept PRs for something like this, though). What I personally do is use a table and just reference that in the scripts.

learn-more commented 1 year ago

This isn't something that's on the roadmap for v5 currently (we would gladly accept PRs for something like this, though). What I personally do is use a table and just reference that in the scripts.

Do you happen to have an example for this?

SirNate0 commented 1 month ago

In Meson these are called dependencies, which I think is a much better name. I think there may be some slight differences with CMake interface libraries, though I think they do everything listed above.