Skip to content

Commit 789f29e

Browse files
committed
Fix generation of pkg-config file with absolute includedir/libdir.
1 parent c8453d3 commit 789f29e

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
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

Lines changed: 7 additions & 0 deletions
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
# ---------------------------------------------------------------------------
@@ -146,6 +148,11 @@ if(JSONCPP_WITH_WARNING_AS_ERROR)
146148
endif()
147149

148150
if(JSONCPP_WITH_PKGCONFIG_SUPPORT)
151+
include(JoinPaths)
152+
153+
join_paths(libdir_for_pc_file "\${exec_prefix}" "${CMAKE_INSTALL_LIBDIR}")
154+
join_paths(includedir_for_pc_file "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}")
155+
149156
configure_file(
150157
"pkg-config/jsoncpp.pc.in"
151158
"pkg-config/jsoncpp.pc"

cmake/JoinPaths.cmake

Lines changed: 23 additions & 0 deletions
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

Lines changed: 2 additions & 2 deletions
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)