Skip to content

Commit 9eba999

Browse files
committed
Also support creating relocatable pkgconfig
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]>
1 parent 400e6dd commit 9eba999

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

CMakeLists.txt

+6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ include(GNUInstallDirs)
99
option(WITH_TESTS "Build tests." OFF)
1010
option(WITH_EXAMPLE "Build example." OFF)
1111
option(USE_BOOST_REGEX "Replace std::regex with Boost.Regex" OFF)
12+
option(PKGCONFIG_RELOCATABLE "Create a pkgconfig file with relocatable path" OFF)
1213

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

109+
if(PKGCONFIG_RELOCATABLE)
110+
set(PKGCONFIG_PREFIX "\${pcfiledir}/../..")
111+
else()
112+
set(PKGCONFIG_PREFIX "${CMAKE_INSTALL_PREFIX}")
113+
endif()
108114
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/docopt.pc.in ${CMAKE_CURRENT_BINARY_DIR}/docopt.pc @ONLY)
109115
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/docopt.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
110116

docopt.pc.in

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
libdir=@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@
2-
includedir=@CMAKE_INSTALL_PREFIX@/include/docopt
1+
prefix=@PKGCONFIG_PREFIX@
2+
libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
3+
includedir=${prefix}/include/docopt
34

45
Name: docopt.cpp
56
Description: C++11 port of docopt

0 commit comments

Comments
 (0)