[CMake] List all binaries associated with a target.

Roman Bolshakov roolebo at gmail.com
Mon Mar 16 14:11:32 EDT 2015


> I'm not totally sure install() does exactly what I need.
> My use case is that I need to debug each executable in an installed-like
> context (with data), which imply that each time it is compiled it should be installed too.
> Actually 2 and 3 are the same, I just put the files in a specific place in the
> build directory so that it looks like installed, but I do this when the binary is
> built so that it's always up to date while debugging.
> Now, I use post-build command (add_custom_command) to do this indeed
> but I didn't find a way yet to trigger install() a specific binary on post-build yet,
> but I suppose I just missed it so far.


If one source tree has a few separate binaries, I'd just use
install(TARGET) with COMPONENT specified. Even if you have a library
which is shared between the set of separate components you can specify
its installation for a few components using foreach loop:
foreach(COMP A B C)
  install(
    TARGET common-lib
    DESTINATION lib
    COMPONENT ${COMP}
  )
endforeach()

Then you can invoke top-level cmake_install.cmake to install a subset
of your project:
DESTDIR=/destination/install/path cmake -DCOMPONENT=A -P cmake_install.cmake

Also note, that if your project is shipped as one bundle on a platform
which supports RPATH you don't need to do any actions as you can run
any executable in build tree without any additional actions using
add_test command. ctest can drive test execution in the build tree.


More information about the CMake mailing list