Closed catb0t closed 6 years ago
So…a bunch of stuff here. To respond to the original subject of generating multiple projects: we recommend using a Lua function to generate the projects to your specifications, as you did. This is the simplest, most flexible solution. I'm not convinced that this feature should be added to premake-core, but you can always roll it up as an add-on module, and if it gets enough traction we can consider it.
As for the table merging, etc…you really should be using the premake.field APIs to merge those collections, rather than peeking under the hood of the field tables.
I'm going to mark this as closed, since I think I've answered the original question (write a Lua function that meets your needs). But feel free to reopen if you have more questions, or open a different issue for follow up questions on developing modules, using the field APIs, etc.
thanks for your response!
is premake.field*
documented? I can't find it searching on the wiki, and there's no "field" in the Project API page.
Not currently. See src/base/field.lua
, and field.merge()
in particular.
this is not a bug, but something I have wondered and wanted since I found Premake.
I have the project structure
I want to make:
src/example.cpp
->bin/{config}/example
aConsoleApp
src/raw/X.cpp
->X.o
a project which can be linked againstsrc/test/test_*.cpp
->bin/{config}/test_vaddr
one executable made from all test filesbin/{config}/libvirt_addr.a
, astaticlib
.a
fileTo this end, my
premake5.lua
saysthis is okay, unfortunately though if I want to change something in each of the small projects like
attrs
ctypes
etc, I must manually change many lines. (also, because my filenames are long, then I must remember thatattributes
shortens toattrs
and so on.)it would be good if I could list in bulk some file pattern and have Premake generate projects for each file matching the pattern. GNU Makefiles already have this in a concise way so that it is easy to do what I want, but I want to use Premake because GNU Make is a headache.
to this end, I have written the following
premake5.lua
with the same effect as the above.table.reverse
is not in Premake (I will create a pull request for this useful thing), but I am only using it to hack around a problem with Premake'stable.merge
. we will come upon this later.the first loop finds all the
.cpp
files insrc/raw
. it generates a project by the name of the each file and gives it thefiles
of its own singular source file.note that the explicit index in the second argument of
table.merge(tbl, { [N] = value })
is a hack to get around the useless behaviour of Premake'stable.merge
to overwrite array elements with the same index. (HereN
must be strictly larger than any index already intbl
).the contents of
base_links
and their indicies are printed for exposition's sake.the project
example
linksbase_links
, which now consists of all the projects made fromsrc/raw/*.cpp
andvirt_addr
.the project
virt_addr
(project(main_project)
) does not link against itself, but links the rest of thestaticlib
projects thus far (inproj_names
).the project
test
consists of all the.cpp
files insrc/test/
.again, to add the testing library, we need the
table.merge(tbl, { [N] = value })
hack to preventcriterion
overwriting or being overwritten in merge.by its nature
libcriterion
must be listed before all or most other libraries, but it is almost impossible to simply and concisely insert to the beginning of a table. I could have listedcriterion
when initialisingproj_names
but then every other project would be linked againstlibcriterion
which is not a very good thing.criterion
was just merged intobase_links
, so it is at the end. therefore an easy solution is to reverse the table of project names.test_links
is printed so that it is easy to see the effect of thetable.merge
hack.test
is linked againsttest_links
, and we're done.Instead of that composition of hacks, I would like to write:
what do you think? there are many codebases I would convert from GNU Makefile to Premake, except that Premake is missing this bulk-object / bulk-project generation.
the practical application of this demonstration is found at catb0t/virtual-addressing/premake5.lua