Skip to content

Commit 4b1bd44

Browse files
wdouglassbaylesj
andauthored
Create a jsoncppConfig.cmake file, even if building under meson (open-source-parsers#1486)
* Create a jsoncppConfig.cmake file, even if building under meson * Hardcode many fewer things in the meson-generated cmake files * use join_paths for constructing paths in the output Config.cmake --------- Co-authored-by: Jordan Bayles <[email protected]>
1 parent f459022 commit 4b1bd44

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

jsoncppConfig.cmake.meson.in

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@PACKAGE_INIT@
2+
3+
@MESON_SHARED_TARGET@
4+
@MESON_STATIC_TARGET@
5+
6+
include ( "${CMAKE_CURRENT_LIST_DIR}/jsoncpp-namespaced-targets.cmake" )
7+
8+
check_required_components(JsonCpp)

meson.build

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ project(
1515
'cpp_std=c++11',
1616
'warning_level=1'],
1717
license : 'Public Domain',
18-
meson_version : '>= 0.49.0')
18+
meson_version : '>= 0.54.0')
1919

2020

2121
jsoncpp_headers = files([
@@ -62,6 +62,43 @@ import('pkgconfig').generate(
6262
filebase : 'jsoncpp',
6363
description : 'A C++ library for interacting with JSON')
6464

65+
cmakeconf = configuration_data()
66+
cmakeconf.set('MESON_LIB_DIR', get_option('libdir'))
67+
cmakeconf.set('MESON_INCLUDE_DIR', get_option('includedir'))
68+
69+
fs = import('fs')
70+
if get_option('default_library') == 'shared'
71+
shared_name = fs.name(jsoncpp_lib.full_path())
72+
endif
73+
if get_option('default_library') == 'static'
74+
static_name = fs.name(jsoncpp_lib.full_path())
75+
endif
76+
if get_option('default_library') == 'both'
77+
shared_name = fs.name(jsoncpp_lib.get_shared_lib().full_path())
78+
static_name = fs.name(jsoncpp_lib.get_static_lib().full_path())
79+
endif
80+
81+
if get_option('default_library') == 'shared' or get_option('default_library') == 'both'
82+
cmakeconf.set('MESON_SHARED_TARGET', '''
83+
add_library(jsoncpp_lib IMPORTED SHARED)
84+
set_target_properties(jsoncpp_lib PROPERTIES
85+
IMPORTED_LOCATION "''' + join_paths('${PACKAGE_PREFIX_DIR}', get_option('libdir'), shared_name) + '''"
86+
INTERFACE_INCLUDE_DIRECTORIES "''' + join_paths('${PACKAGE_PREFIX_DIR}', get_option('includedir')) + '")')
87+
endif
88+
if get_option('default_library') == 'static' or get_option('default_library') == 'both'
89+
cmakeconf.set('MESON_STATIC_TARGET', '''
90+
add_library(jsoncpp_static IMPORTED STATIC)
91+
set_target_properties(jsoncpp_static PROPERTIES
92+
IMPORTED_LOCATION "''' + join_paths('${PACKAGE_PREFIX_DIR}', get_option('libdir'), static_name) + '''"
93+
INTERFACE_INCLUDE_DIRECTORIES "''' + join_paths('${PACKAGE_PREFIX_DIR}', get_option('includedir')) + '")')
94+
endif
95+
96+
import('cmake').configure_package_config_file(
97+
name: 'jsoncpp',
98+
input: 'jsoncppConfig.cmake.meson.in',
99+
configuration: cmakeconf)
100+
install_data('jsoncpp-namespaced-targets.cmake', install_dir : join_paths(get_option('libdir'), 'cmake', jsoncpp_lib.name()))
101+
65102
# for libraries bundling jsoncpp
66103
jsoncpp_dep = declare_dependency(
67104
include_directories : jsoncpp_include_directories,

0 commit comments

Comments
 (0)