[CMake] Using objects in different targets

Michael Hertling mhertling at online.de
Thu May 20 07:33:01 EDT 2010


On 05/20/2010 01:04 PM, "Christoph Rüdiger" wrote:
> Hi!
> 
> I'm new to cmake and couldn't find a solution for my problem:
> 
> I've a directory src containing the complete source code of the program and
> another directory called test containing the source code for the unit tests.
> In the top level directory is a CMakeLists.txt that points to the subdirectories containing each an own CMakeLists.txt for building the program or the unit tests.
> 
> Now I want to use the already build object files from the src directory one time for linking the program and one time for linking to the unit tests.
> 
> My current way is building a static library in the src directory and link the unit tests against this library. But the sources would be compiled twice: One time for the static library and one time for the program itself.

Link the program against the static library, too, while removing
the latter's source files from the program's ADD_EXECUTABLE().

Regards,

Michael


More information about the CMake mailing list