From 0ca73850160338be71efe146cb66becbe8d12bc5 Mon Sep 17 00:00:00 2001 From: Woodrow Douglass Date: Tue, 2 May 2023 09:00:38 -0400 Subject: [PATCH 1/3] Create a jsoncppConfig.cmake file, even if building under meson --- jsoncppConfig.cmake.meson.in | 6 ++++++ meson.build | 7 +++++++ 2 files changed, 13 insertions(+) create mode 100644 jsoncppConfig.cmake.meson.in diff --git a/jsoncppConfig.cmake.meson.in b/jsoncppConfig.cmake.meson.in new file mode 100644 index 000000000..6120a6eca --- /dev/null +++ b/jsoncppConfig.cmake.meson.in @@ -0,0 +1,6 @@ +@PACKAGE_INIT@ + +add_library(jsoncpp_lib IMPORTED SHARED) +set_target_properties(jsoncpp_lib PROPERTIES + IMPORTED_LOCATION "${PACKAGE_PREFIX_DIR}/lib/libjsoncpp.so" + INTERFACE_INCLUDE_DIRECTORIES "${PACKAGE_PREFIX_DIR}/include") diff --git a/meson.build b/meson.build index f68db30dd..89b3b961d 100644 --- a/meson.build +++ b/meson.build @@ -62,6 +62,13 @@ import('pkgconfig').generate( filebase : 'jsoncpp', description : 'A C++ library for interacting with JSON') +cmakeconf = configuration_data() + +import('cmake').configure_package_config_file( + name: 'jsoncpp', + input: 'jsoncppConfig.cmake.meson.in', + configuration: cmakeconf) + # for libraries bundling jsoncpp jsoncpp_dep = declare_dependency( include_directories : jsoncpp_include_directories, From 1e41177de69d583f339722aaf344a1b9d419d34d Mon Sep 17 00:00:00 2001 From: Woodrow Douglass Date: Thu, 11 May 2023 10:09:56 -0400 Subject: [PATCH 2/3] Hardcode many fewer things in the meson-generated cmake files --- jsoncppConfig.cmake.meson.in | 10 ++++++---- meson.build | 32 +++++++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/jsoncppConfig.cmake.meson.in b/jsoncppConfig.cmake.meson.in index 6120a6eca..0f4866d6d 100644 --- a/jsoncppConfig.cmake.meson.in +++ b/jsoncppConfig.cmake.meson.in @@ -1,6 +1,8 @@ @PACKAGE_INIT@ -add_library(jsoncpp_lib IMPORTED SHARED) -set_target_properties(jsoncpp_lib PROPERTIES - IMPORTED_LOCATION "${PACKAGE_PREFIX_DIR}/lib/libjsoncpp.so" - INTERFACE_INCLUDE_DIRECTORIES "${PACKAGE_PREFIX_DIR}/include") +@MESON_SHARED_TARGET@ +@MESON_STATIC_TARGET@ + +include ( "${CMAKE_CURRENT_LIST_DIR}/jsoncpp-namespaced-targets.cmake" ) + +check_required_components(JsonCpp) diff --git a/meson.build b/meson.build index 89b3b961d..ab78d2b4c 100644 --- a/meson.build +++ b/meson.build @@ -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([ @@ -63,11 +63,41 @@ import('pkgconfig').generate( 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 "${PACKAGE_PREFIX_DIR}/''' + get_option('libdir') + '/' + shared_name + '''" + INTERFACE_INCLUDE_DIRECTORIES "${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 "${PACKAGE_PREFIX_DIR}/''' + get_option('libdir') + '/' + static_name + '''" + INTERFACE_INCLUDE_DIRECTORIES "${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 : get_option('libdir') + '/cmake/' + jsoncpp_lib.name()) # for libraries bundling jsoncpp jsoncpp_dep = declare_dependency( From 010540bd2d4846fdd3e6bdef9f5f77a0a29c83f2 Mon Sep 17 00:00:00 2001 From: Woodrow Douglass Date: Fri, 12 May 2023 11:44:24 -0400 Subject: [PATCH 3/3] use join_paths for constructing paths in the output Config.cmake --- meson.build | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/meson.build b/meson.build index ab78d2b4c..be93a3c87 100644 --- a/meson.build +++ b/meson.build @@ -82,22 +82,22 @@ if get_option('default_library') == 'shared' or get_option('default_library') == cmakeconf.set('MESON_SHARED_TARGET', ''' add_library(jsoncpp_lib IMPORTED SHARED) set_target_properties(jsoncpp_lib PROPERTIES - IMPORTED_LOCATION "${PACKAGE_PREFIX_DIR}/''' + get_option('libdir') + '/' + shared_name + '''" - INTERFACE_INCLUDE_DIRECTORIES "${PACKAGE_PREFIX_DIR}/''' + get_option('includedir') + '")') + 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 "${PACKAGE_PREFIX_DIR}/''' + get_option('libdir') + '/' + static_name + '''" - INTERFACE_INCLUDE_DIRECTORIES "${PACKAGE_PREFIX_DIR}/''' + get_option('includedir') + '")') + 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 : get_option('libdir') + '/cmake/' + jsoncpp_lib.name()) +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(