[CMake] Installing generated files

Alejandro Martinez Ruiz alex at flawedcode.org
Thu Mar 6 15:47:07 EST 2014


Hi list,

I have a problem trying to properly install my project with CMake.

My project has a dependency on an external project, which I
conveniently download, build and install using the ExternalProject
module. What I have at this point is the following:

1) This external project produces a set of shared and static
libraries, along with related symlinks (on Unix), which I do not know
their exact names in advance, but only a pattern.

2) The shared libraries from the external project need to be installed
along with my project's binaries in the final destination, either in
the same directory or in a known rpath (ie, $ORIGIN/../lib). I don't
want to point ExternalProject's INSTALL option to the final
destination of my project, since this external project installs a ton
of extra stuff that is not needed, so I point it to a controlled
directory within my project's build tree. I guess I could actually
skip the install step altogether and link directly to the libraries
within their own build tree.

3) My project's binaries depend on the external shared libraries and I
can successfully link them against these external libraries by
declaring the libraries as IMPORTED and setting the IMPORTED_LOCATION
and IMPORTED_IMPLIB properties on them to one of the known symlinks
(ie. libfoo.so, which points to something like libfoo.so.0.2.4).

The problem arises when I try to install the shared libraries produced
by the external project. I want to include not only the files that the
binaries are actually linked to, but also all the symlinks. Since
those files do not exist at configure time, cmake errors out on
FILE(GLOB ...) and INSTALL(FILES ...) commands.

I have been able to install just the imported library to a directory
under the install prefix by using:

INSTALL(CODE "FILE(INSTALL ${SHARED_LIB_LOCATION} DESTINATION
${CMAKE_INSTALL_PREFIX}/lib")

But even if I could do that for the entire set of generated files, the
problem is that (some?) package generators completely ignore files
installed this way. This is the case with NSIS, which seems to require
a file to be installed using INSTALL() to actually include it in the
final package... but using INSTALL(CODE "INSTALL(FILES ...)") does not
work.

So basically, my question is how to properly install files which are
generated during build time (ie. external project's shared libraries
and related files) but without knowing in advance the exact name of
the files that I want to install, so that the end result will be OK
when installed manually and also picked up correctly by NSIS and
others.

Thanks,
  Alex


More information about the CMake mailing list