premake-core
premake-core copied to clipboard
Premake alternative to the CMake interface library
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.
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" }
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.
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.
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?