premake-core icon indicating copy to clipboard operation
premake-core copied to clipboard

Premake alternative to the CMake interface library

Open learn-more opened this issue 8 months ago • 4 comments

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

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

  • It adds whatever libraries are defined inside this 'interface' library (not the main advantage)
  • It adds whatever preprocessor macro's / conditions are set
  • It adds include paths
  • It adds link paths
  • .. probably more?

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.

learn-more avatar Oct 26 '23 20:10 learn-more

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" }

Jarod42 avatar Oct 27 '23 13:10 Jarod42

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.

learn-more avatar Oct 30 '23 19:10 learn-more

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.

nickclark2016 avatar Oct 31 '23 05:10 nickclark2016

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?

learn-more avatar Nov 02 '23 10:11 learn-more