[CMake] Multiple executables per project?

Andreas Pakulat apaku at gmx.de
Sun Oct 28 19:09:48 EDT 2012


Hi,

On Sun, Oct 28, 2012 at 10:09 PM, Rui Maciel <rui.maciel at gmail.com> wrote:
> I'm developing a software package which consists of a GUI application and a
> command line program.  Both programs share common libraries, and essentially
> they only differ in which UI components each program uses.
>
> I would like to use CMake to handle the build project of this package, but
> as I never used CMake to pull this off I don't even know if it is possible.
> So, does anyone have any experience using CMake to set a project with
> multiple executables sharing commong libraries?  If it is possible what's
> the best way to pull this off?

Having this is as simple as:

add_library( mysharedlib SHARED ${LIB_SRCS} )

add_executable( mycliapp ${CLI_SRCS} )
target_link_libraries( mycliapp mysharedlib )

add_executable( myguiapp ${CLI_SRCS})
target_link_libraries( myguiapp mysharedlib )

# This installs the library to CMAKE_INSTALL_PREFIX/lib and the
binaries to CMAKE_INSTALL_PREFIX/bin on *nix, see the cmake manual for
more details
install( TARGETS mysharedlib mycliapp myguiapp
           LIBRARY DESTINATION lib/
           RUNTIME DESTINATION bin/
         )

On Unix you might want to look into the RPATH options offered by
cmake, so your executables can easily find the shared library when its
installed in the users home directory or so, but under the same
base-directory.

Andreas


More information about the CMake mailing list