Skip to content

Commit

Permalink
Create a jsoncppConfig.cmake file, even if building under meson (open…
Browse files Browse the repository at this point in the history
…-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]>
  • Loading branch information
wdouglass and baylesj authored Sep 10, 2024
1 parent f459022 commit 4b1bd44
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
8 changes: 8 additions & 0 deletions jsoncppConfig.cmake.meson.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@PACKAGE_INIT@

@MESON_SHARED_TARGET@
@MESON_STATIC_TARGET@

include ( "${CMAKE_CURRENT_LIST_DIR}/jsoncpp-namespaced-targets.cmake" )

check_required_components(JsonCpp)
39 changes: 38 additions & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ project(
'cpp_std=c++11',
'warning_level=1'],
license : 'Public Domain',
meson_version : '>= 0.49.0')
meson_version : '>= 0.54.0')


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

cmakeconf = configuration_data()
cmakeconf.set('MESON_LIB_DIR', get_option('libdir'))
cmakeconf.set('MESON_INCLUDE_DIR', get_option('includedir'))

fs = import('fs')
if get_option('default_library') == 'shared'
shared_name = fs.name(jsoncpp_lib.full_path())
endif
if get_option('default_library') == 'static'
static_name = fs.name(jsoncpp_lib.full_path())
endif
if get_option('default_library') == 'both'
shared_name = fs.name(jsoncpp_lib.get_shared_lib().full_path())
static_name = fs.name(jsoncpp_lib.get_static_lib().full_path())
endif

if get_option('default_library') == 'shared' or get_option('default_library') == 'both'
cmakeconf.set('MESON_SHARED_TARGET', '''
add_library(jsoncpp_lib IMPORTED SHARED)
set_target_properties(jsoncpp_lib PROPERTIES
IMPORTED_LOCATION "''' + join_paths('${PACKAGE_PREFIX_DIR}', get_option('libdir'), shared_name) + '''"
INTERFACE_INCLUDE_DIRECTORIES "''' + join_paths('${PACKAGE_PREFIX_DIR}', get_option('includedir')) + '")')
endif
if get_option('default_library') == 'static' or get_option('default_library') == 'both'
cmakeconf.set('MESON_STATIC_TARGET', '''
add_library(jsoncpp_static IMPORTED STATIC)
set_target_properties(jsoncpp_static PROPERTIES
IMPORTED_LOCATION "''' + join_paths('${PACKAGE_PREFIX_DIR}', get_option('libdir'), static_name) + '''"
INTERFACE_INCLUDE_DIRECTORIES "''' + join_paths('${PACKAGE_PREFIX_DIR}', get_option('includedir')) + '")')
endif

import('cmake').configure_package_config_file(
name: 'jsoncpp',
input: 'jsoncppConfig.cmake.meson.in',
configuration: cmakeconf)
install_data('jsoncpp-namespaced-targets.cmake', install_dir : join_paths(get_option('libdir'), 'cmake', jsoncpp_lib.name()))

# for libraries bundling jsoncpp
jsoncpp_dep = declare_dependency(
include_directories : jsoncpp_include_directories,
Expand Down

0 comments on commit 4b1bd44

Please sign in to comment.