[CMake] Multiple targets

Ghyslain Leclerc ghleclerc at gmail.com
Mon Jun 22 15:36:20 EDT 2015


Hello,

We have a modular in-house library that we use for our software.  Let’s call it lib_x.  Let’s call a few of the modules (we have 7 I think) mod_y, mod_z, mod_u and mod_v.  Let’s say I have two applications that use all of this and call them app_1 and app_2.

The way I have setup our CMake builds is that I first find out what modules of lib_x the applications app_1 and app_2 depend on.  Then I build a single library lib_x which include the selected modules and finally, I build each app independently and link against the single library.

For instance, let’s say app_1 depends on mod_y and mod_z and app_2 depends on mod_y, mod_z and mod_u.  Then, I would build lib_x with everything for modules y, z and u (excluding module v) and build app_1 and app_2 linking against lib_x

Might not be explained properly (my apologies), willing to answer any questions on that.

I am looking into changing/modernizing our build system.  From what I understand, instead of building everything into a single library, I could build separate libraries, export them as targets and link against them.  (Pretty sure I could have done that before, but just coming around to do it.)

Am I wrong ?  Am I completely missing the point ?  If I am not and it is a reasonable approach, is there a place where a tutorial is available ?  I am trying really hard to read the documentation on export command and targets and such, but I am having a real hard time when trying to actually implement anything concrete.

I first attempted to do this:
include_directories( "${LIB_ROOT_DIR}/include" )
add_library( general ${GENERAL_SRCS}
                     ${GENERAL_HDRS}
                     ${LIB_ROOT_DIR}/include/hdqrt/always_inline.h
                     ${LIB_ROOT_DIR}/include/hdqrt/debug.h
                     ${LIB_ROOT_DIR}/include/hdqrt/Error.h
                     ${LIB_ROOT_DIR}/include/hdqrt/warn_stop.h
                     ${LIB_ROOT_DIR}/include/hdqrt/warn_restart.h
            )
set_property( TARGET general PROPERTY CXX_STANDARD 14 )
export( TARGETS general FILE general.cmake )

but then, the general.cmake file is nowhere to be found.  And if I test in another (parent) CMakeLists.txt to see if the target is defined, it is not.

Sorry if this is a silly question.  Trying to figure this out.

Thanks in advance.
Ghyslain
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20150622/4bc6e063/attachment.html>


More information about the CMake mailing list