[CMake] library dependcies and add_library(OBJECT)

avorop at mail.ru avorop at mail.ru
Mon Nov 17 07:29:30 EST 2014


Hello!

I'm playing with add_library(OBJECT) operation. Everything works nice
but then I have one "library" that uses some external library. An
attempt to add target_link_libraries here results in failure, because I
don't build and library, only object files. But now comes the problem,
how do I notify target that uses my "library" that it should include
additional external library as dependency? Of course in the simplest
case I can provide target_link_libraries for the executable, but I'd
prefer to keep this setting in the CMakeLists.txt for the library.

In hope to clarify the above, suppose that we have project with
sources located in directories A, B and C. The final executable is built
using objects from these directories. In each of directories I place
CMakeLists.txt containing "add_library(X OBJECT x.c y.c)". Then in
CMakeLists.txt for the executable I put line "add_executable(my_prog
$<TARGET_OBJECTS:A> $<TARGET_OBJECTS:B> $<TARGET_OBJECTS:C>)"
Now, suppose files in B use external library libssl. What should I add
to B/CMakeLists.txt to successfully build my executable?

--
Andrei Voropaev



More information about the CMake mailing list