Skip to content

Commit 5be07bd

Browse files
authored
Fix generation of pkg-config file with absolute includedir/libdir. (#1199)
1 parent bf0cfa5 commit 5be07bd

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828

2929
# CMake-generated files:
3030
CMakeFiles/
31-
*.cmake
3231
/pkg-config/jsoncpp.pc
3332
jsoncpp_lib_static.dir/
3433

CMakeLists.txt

+7
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ if(NOT DEFINED CMAKE_BUILD_TYPE AND NOT DEFINED CMAKE_CONFIGURATION_TYPES)
4949
"Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel Coverage.")
5050
endif()
5151

52+
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
53+
5254
# ---------------------------------------------------------------------------
5355
# use ccache if found, has to be done before project()
5456
# ---------------------------------------------------------------------------
@@ -148,6 +150,11 @@ if(JSONCPP_WITH_WARNING_AS_ERROR)
148150
endif()
149151

150152
if(JSONCPP_WITH_PKGCONFIG_SUPPORT)
153+
include(JoinPaths)
154+
155+
join_paths(libdir_for_pc_file "\${exec_prefix}" "${CMAKE_INSTALL_LIBDIR}")
156+
join_paths(includedir_for_pc_file "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}")
157+
151158
configure_file(
152159
"pkg-config/jsoncpp.pc.in"
153160
"pkg-config/jsoncpp.pc"

cmake/JoinPaths.cmake

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# This module provides a function for joining paths
2+
# known from most languages
3+
#
4+
# SPDX-License-Identifier: (MIT OR CC0-1.0)
5+
# Copyright 2020 Jan Tojnar
6+
# https://github.com/jtojnar/cmake-snips
7+
#
8+
# Modelled after Python’s os.path.join
9+
# https://docs.python.org/3.7/library/os.path.html#os.path.join
10+
# Windows not supported
11+
function(join_paths joined_path first_path_segment)
12+
set(temp_path "${first_path_segment}")
13+
foreach(current_segment IN LISTS ARGN)
14+
if(NOT ("${current_segment}" STREQUAL ""))
15+
if(IS_ABSOLUTE "${current_segment}")
16+
set(temp_path "${current_segment}")
17+
else()
18+
set(temp_path "${temp_path}/${current_segment}")
19+
endif()
20+
endif()
21+
endforeach()
22+
set(${joined_path} "${temp_path}" PARENT_SCOPE)
23+
endfunction()

pkg-config/jsoncpp.pc.in

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
prefix=@CMAKE_INSTALL_PREFIX@
22
exec_prefix=@CMAKE_INSTALL_PREFIX@
3-
libdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@
4-
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
3+
libdir=@libdir_for_pc_file@
4+
includedir=@includedir_for_pc_file@
55

66
Name: jsoncpp
77
Description: A C++ library for interacting with JSON

0 commit comments

Comments
 (0)