[CMake] installation paths and generated source files

Andreas Pakulat apaku at gmx.de
Mon Aug 19 14:10:18 EDT 2013


Hi,

On Mon, Aug 19, 2013 at 6:23 PM, Magnus Hagdorn <magnus.hagdorn at ed.ac.uk>wrote:

> Hi there,
> I have the following problem with cmake:
>
> I would like to set the installation path for plugins to be
> ${LIB_INSTALL_DIR}/${PROJECT_**NAME}. As I understand it, the
> LIB_INSTALL_DIR is relative to CMAKE_INSTALL_PREFIX if it is not an
> absolute path. Installation works fine for both cases when LIB_INSTALL_DIR
> is absolute and when it is relative. So far so good.
>
> Now, my problem is that I would like to generate a header file containing
> the installation path for my plugins so the program can find them.  My
> header input file contains
>
> #define PLUGIN_DIR "${PLUGIN_INSTALL_DIR}"
>
> which works if LIB_INSTALL_DIR is absolute but it doesn't work if it is a
> relative path in which case I'd need
>
> #define PLUGIN_DIR "${CMAKE_INSTALL_PREFIX}/${**PLUGIN_INSTALL_DIR}"
>
> which presumably won't work on windows systems anyway because of the unix
> dir separator. what's the best way of solving this issue?
>

I'd solve this inside cmake and setup a custom cmake variable which is then
used in the h.cmake-file for configure_file.

However note that doing this makes your application non-relocatable, i.e.
its not possible to move it around anymore. So you may want to reconsider
this and merely store a relative path as plugin-dir in the header and then
absolutify this during the runtime of the program based on the location of
the binary or something like that. Makes handling the
plugin-install-dir-is-absolute case a bit more work since you need to
determine the location.

Andreas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20130819/77f00227/attachment.htm>


More information about the CMake mailing list