[CMake] Linking unit tests

Marcus yhadin002 at sneakemail.com
Wed Dec 12 14:32:54 EST 2007


Hi,

I'm trying to build a collection of libraries, each with a
set of unit tests.  In CMakeLists.txt, I use `add_library` to create the 
main target and `add_executable` to generate a test runner for each 
library.  Then I use `target_link_libraries` to link each test runner to 
it's corresponding library.

The problem with this solution is that I can only test the interfaces 
that are exported from the library.  I really want to be able to test 
all of the units, including internal classes.  But how can I do this 
with CMake?

In the past (when I was using SCons) I compiled the source files into 
object files, and then linked the same object files into both the test 
executable and the shared library.  Is it possible to do this with CMake?

Many thanks,
Marcus



More information about the CMake mailing list