]> granicus.if.org Git - zziplib/commit
build: Produce correct pc file with absolute libdir
authorJan Tojnar <jtojnar@gmail.com>
Mon, 13 Apr 2020 14:16:11 +0000 (16:16 +0200)
committerJan Tojnar <jtojnar@gmail.com>
Mon, 13 Apr 2020 14:16:11 +0000 (16:16 +0200)
commit892dea3b82208654cc9f57ffc4ef555d0d934cf5
treeb98ac7af727e87eccae0c47e4f8f69131b982709
parente82dc78a1ca427c4ad45a76565bb6604376c3bc8
build: Produce correct pc file with absolute libdir

The CMAKE_INSTALL_INCLUDEDIR and CMAKE_INSTALL_LIBDIR variables
can be absolute paths so simply appending them to \${prefix}
might not work.

Unfortunately, CMake does not have simple function for joining paths [1]
so I had to write my own suboptimal one.

It somewhat handles the following cases

- prefix absolute + libdir relative
- prefix absolute + libdir absolute but not under prefix

but for

- prefix absolute + libdir absolute & under prefix

we would want to strip the prefix and make the libdir relative
so we can make it relative to the pkg-config variables.

Basically, we want the equivalent of the following Python function:

import os.path
from pathlib import PurePath

if os.path.isabs(libdir) and os.path.commonpath([libdir, prefix]) == str(PurePath(prefix)):
    # Convert path to be relative to prefix
    skip = len(prefix) + 1
    libdir = libdir[skip:]

return os.path.join('${prefix}', libdir)

This would be non-trivial to replicate in CMake scripts as far as I can tell.

[1]: https://gitlab.kitware.com/cmake/cmake/issues/19568
CMakeScripts/JoinPaths.cmake [new file with mode: 0644]
zzip/CMakeLists.txt
zzipwrap/CMakeLists.txt