Skip to content

Commit

Permalink
Also support creating relocatable pkgconfig
Browse files Browse the repository at this point in the history
Using the pgk-config derived variable `pcfiledir` provides an option
to create a package which the user can install to a location of their
choosing. The prefix is determined at runtime from where the pkgconfig
file is found.

Signed-off-by: Eero Aaltonen <[email protected]>
  • Loading branch information
eaaltonen committed Aug 17, 2023
1 parent 400e6dd commit 9eba999
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ include(GNUInstallDirs)
option(WITH_TESTS "Build tests." OFF)
option(WITH_EXAMPLE "Build example." OFF)
option(USE_BOOST_REGEX "Replace std::regex with Boost.Regex" OFF)
option(PKGCONFIG_RELOCATABLE "Create a pkgconfig file with relocatable path" OFF)

#============================================================================
# Internal compiler options
Expand Down Expand Up @@ -105,6 +106,11 @@ write_basic_package_version_file("${PROJECT_BINARY_DIR}/docopt-config-version.cm
install(FILES docopt-config.cmake ${PROJECT_BINARY_DIR}/docopt-config-version.cmake DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/docopt")
install(EXPORT ${export_name} DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/docopt")

if(PKGCONFIG_RELOCATABLE)
set(PKGCONFIG_PREFIX "\${pcfiledir}/../..")
else()
set(PKGCONFIG_PREFIX "${CMAKE_INSTALL_PREFIX}")
endif()
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/docopt.pc.in ${CMAKE_CURRENT_BINARY_DIR}/docopt.pc @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/docopt.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)

Expand Down
5 changes: 3 additions & 2 deletions docopt.pc.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
libdir=@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@
includedir=@CMAKE_INSTALL_PREFIX@/include/docopt
prefix=@PKGCONFIG_PREFIX@
libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
includedir=${prefix}/include/docopt

Name: docopt.cpp
Description: C++11 port of docopt
Expand Down

0 comments on commit 9eba999

Please sign in to comment.