[CMake] create pc pkgconfig file when installing

Hendrik Sattler post at hendrik-sattler.de
Mon Jan 28 12:47:05 EST 2008


Quoting Christophe Alexandre <christophe.alexandre at lip6.fr>:
> How can I dynamically create a tool.pc pkgconfig file for my tool while
> installing it.
> I need to set a variable to the install destination : prefix=@DEST_DIR@
> and in my CMakeLists.txt, I use : set(DEST_DIR "$ENV{DESTDIR}")
> and then a CONFIGURE_FILE directive.
>
> My problem is that the tool.pc file is created when I run make without
> DEST and is not replaced when I run make DEST=foo
>
> Is there a proper way to generate the .pc file each time I install my tool.

To use CONFIGURE_FILE, you have to know the final destination at the  
time of the cmake call.
Usually, you do know before building where the thing goes to. So you can use
   cmake -DCMAKE_INSTALL_PREFIX /some/dir
and feed DEST_DIR from ${CMAKE_INSTALL_PREFIX} instead of an  
environment variable.
You can still use DESTDIR (_no_ underscore) at "make install" time to  
drop the files to some dir as if that was the system base but that  
won't change the pkgconfig file (and for that use-case that's perfect).

On Windows, you usually do not know where the final destination is.  
However, according to pkgconfig documentation, pkgconfig solves that  
for itself by modifying 'prefix' at pkgconfig run-time.

HS




More information about the CMake mailing list