Skip to content

Commit

Permalink
cmake: make the .pc file relocatable
Browse files Browse the repository at this point in the history
Instead of writing absolute file paths for exec_prefix, libdir and
includedir make them all relative to prefix. This makes the .pc
file match the autotools generated one and allows changing all paths
via prefix.

Before:

prefix=C:/test
exec_prefix=C:/test
libdir=C:/test/lib
includedir=C:/test/include

After:

prefix=C:/test
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include

While CMAKE_INSTALL_LIBDIR and CMAKE_INSTALL_INCLUDEDIR are by default
relative paths, cmake allows users to override them with absolute ones,
so in case they are absolute write them as is into the .pc file and
not relative to the prefix.
  • Loading branch information
lazka committed Jul 24, 2023
1 parent 7273ec1 commit 37aa094
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -429,9 +429,17 @@ set(abs_top_srcdir "${CMAKE_CURRENT_SOURCE_DIR}")
set(abs_top_builddir "${CMAKE_CURRENT_BINARY_DIR}")
# libnghttp2.pc (pkg-config file)
set(prefix "${CMAKE_INSTALL_PREFIX}")
set(exec_prefix "${CMAKE_INSTALL_PREFIX}")
set(libdir "${CMAKE_INSTALL_FULL_LIBDIR}")
set(includedir "${CMAKE_INSTALL_FULL_INCLUDEDIR}")
set(exec_prefix "\${prefix}")
if(IS_ABSOLUTE ${CMAKE_INSTALL_LIBDIR})
set(libdir "${CMAKE_INSTALL_LIBDIR}")
else()
set(libdir "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}")
endif()
if(IS_ABSOLUTE ${CMAKE_INSTALL_INCLUDEDIR})
set(includedir "${CMAKE_INSTALL_INCLUDEDIR}")
else()
set(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
endif()
set(VERSION "${PACKAGE_VERSION}")
# For init scripts and systemd service file (in contrib/)
set(bindir "${CMAKE_INSTALL_FULL_BINDIR}")
Expand Down

0 comments on commit 37aa094

Please sign in to comment.