I'm trying to setup a project that would consist of two executables: the actual application app
and a test application test
(i.e. executable that runs unit tests).
Obviously, test
depends on functions/classes defined in app
, meaning that correct build order has to be ensured. What is more however, app
has a few external dependencies of its own, e.g. boost, which makes test
transitively dependent on them as well.
What is the most idiomatic way of resolving these dependencies?
Two approaches I tried are:
- Make an intermediate
app_lib
library target, consisting of all source files exceptmain.cpp
, then link both executables against it (target_link_libraries(test PRIVATE app_lib)
). - Set
ENABLE_EXPORTS
property onapp
target, allowingtest
to link against it directly (target_link_libraries(test PRIVATE app)
).
While both of these approaches work, they both seem quite hacky. The latter feels a tad better but if I understand it correctly, it was originally meant to enable plugin development, hence the "hacky" feeling.
To reiterate - what would be the correct way of setting up such project? Are these two the only possible solutions or there is another, better one?