premake / premake-core

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

Can you instruct premake to link to the binaries of another module rather than rebuilding? #1455

Closed Makogan closed 4 years ago

Makogan commented 4 years ago

First of all I love premake, it's the best build system I have used so far.

I currently have a project that has:

Because I am lazy in all 3 modules I have more or less the following

   files {"./Src/**.hpp", "./Src/**.cpp"}
    removefiles {"./**test*" }
    removefiles {"./**benchmarks*" }

This makes it such that both the benchmark and test modules rebuild 100% of the object files in the directory, which is slow. I was wondering if there is a mechanism I can use to to tell both modules to use the generated object files of the parent object instead of rebuilding.

Thanks in advance.

samsinsane commented 4 years ago

It sounds like what you want is a static lib?

Makogan commented 4 years ago

Not quite, when gcc creates an executable it also creates all the intermediary object files. Which with premake are under Generated/obj/Debug (for example).

In my current configuration the benchmarks module will generate an almost identical directory under Generated/Benchmarks/Debug where the only difference is the main object file.

I want to try to configure premake to not regenerate any of the object files already in Generated/obj/Debug and instead link against them when generating the benchmarks executable.

starkos commented 4 years ago

If you're intent on taking that approach, you could try setting an explicit objdir for each configuration, with a leading "!" to prevent Premake from trying to make it unique. Untested but perhaps like…

objdir '!obj/%{cfg.shortname}'

Otherwise, the cleanest way to get what you're after is to split out a static library project as @samsinsane suggested.

Marking this one closed as answered, but feel free to continue the conversation if you still have questions.

Makogan commented 4 years ago

@starkos This seems perfect for my use case (tried it and it works). Thank you. I see the utility of the static lib approach but for now this is a better solution. Thank you.