[CMake] Specifying individual install locations at CPack time

Sean Anderson seanga2 at gmail.com
Fri Mar 9 01:14:55 EST 2018


Hi,

I'm creating a small library (https://github.com/Forty-Bot/appdir) using
CMake, and I would like to package it with CPack. I build a shared
library, and some html documentation. In addition to that, I need to
ship the headers, the README, and the license. If I were to make an
archive by hand, it would look like

libappdir.so
appdir.h
README.md
COPYING.LESSER
doc/
	index.html
	...

However, when running `make install`, these files go in different
locations (using GNUInstallDirs for the variables):

${CMAKE_INSTALL_LIBDIR}/
	libappdir.so
${CMAKE_INSTALL_INCLUDEDIR}/
	appdir.h
${CMAKE_INSTALL_DOCDIR}/
	README.md
	COPYING.LESSER
	html/
		index.html
		...

Of course, on Debian systems, `COPYING.LESSER` should be omitted, and a
`copyright` file should be written referencing the copy of the LGPL in
`/usr/share/common-licenses`, and this assumes some sort of posix-y
system. On windows, I don't think it makes sense to support an install
target because there is no standard location for dlls. On darwin, I have
no idea what the standard is, but it's likely not what works for linux.
Lastly, I'd like to generate reasonable output for DEB and RPM, as well
as one of the macos installers.

Clearly the default CPack behaviour will not work here. Currently, I use
a variable `CREATE_ARCHIVE` to switch between install layout behaviour,
but it seems like there should be some sort of way to do this without
reconfiguring; after all, the only difference is where everything gets
copied. I looked into using `CPACK_INSTALLED_DIRECTORIES`, but I want to
control individual files, and I'd end up having to simulate an install
step in order to get the correct directories. I also considered
`CPACK_INSTALL_SCRIPT`, but it looked like I'd just end up writing my
own `cmake_install.cmake`s. And of course, all of these solutions would
need to use `CPACK_PROJECT_CONFIG_FILE` to detect what sort of build we
were doing, which as far as I can tell corresponds to
`CPACK_INCLUDE_TOPLEVEL_DIRECTORY`.

This seems like a rather common use-case, and I'm surprised that I
couldn't find any obvious solution for it. Am I missing something here?
Installing everything twice and using components to select between
configurations could work, but it would mess up invocations of `make
install`. Additionally, my current solution doesn't address the
installation of `copyright` for Debian (Somehow we need to detect
whether we're on debian or whether we're build a deb).

The GNUInstallDirs script seems to only be valid for posix-y systems. Is
there some equivalent for discovering where to install things on (say)
Darwin?

I've been digging around for a few days, and there doesn't seem to be
any prior work in this area (not to mention the paucity of
documentation). Thanks in advance for any tips.

	--Sean

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 618 bytes
Desc: OpenPGP digital signature
URL: <https://cmake.org/pipermail/cmake/attachments/20180309/ad8976d3/attachment.sig>


More information about the CMake mailing list