From 73bcc302089e5680c82256c95c231bc7a9a5707f Mon Sep 17 00:00:00 2001 From: Farid Zakaria Date: Mon, 27 Oct 2025 10:56:59 -0700 Subject: [PATCH 1/4] Add support for pkg-config --- CMakeLists.txt | 29 ++++++++++++++++++++++++++++- json.cpp.pc.in | 8 ++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 json.cpp.pc.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 98a6419..8b4fbc9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,8 @@ cmake_minimum_required(VERSION 3.15) -project(jtjson) +project(jtjson + LANGUAGES CXX + VERSION 0.1.0 + DESCRIPTION "JSON for Classic C++") option(JSON_CPP_BUILD_TESTS "Enable building tests" ON) option(DOUBLE_CONVERSION_VENDORED "Use vendored double-conversion library" ON) @@ -59,6 +62,23 @@ enable_testing() ) endif() +function(prefix_rel_path var_name install_dir) + if(IS_ABSOLUTE "${install_dir}") + set(${var_name} "${install_dir}" PARENT_SCOPE) + else() + set(${var_name} "\${prefix}/${install_dir}" PARENT_SCOPE) + endif() +endfunction() + +# Generate pkg-config file +prefix_rel_path(PKG_CONFIG_LIBDIR "${CMAKE_INSTALL_LIBDIR}") +prefix_rel_path(PKG_CONFIG_INCLUDEDIR "${CMAKE_INSTALL_INCLUDEDIR}") +configure_file( + "json.cpp.pc.in" + "json.cpp.pc" + @ONLY + ) + include(GNUInstallDirs) install(TARGETS json ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} @@ -66,3 +86,10 @@ install(TARGETS json RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ) + +# pkg-config +# * /lib/pkgconfig/double-conversion.pc +install( + FILES "${CMAKE_CURRENT_BINARY_DIR}/double-conversion.pc" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig" +) \ No newline at end of file diff --git a/json.cpp.pc.in b/json.cpp.pc.in new file mode 100644 index 0000000..f4054e2 --- /dev/null +++ b/json.cpp.pc.in @@ -0,0 +1,8 @@ +prefix=@CMAKE_INSTALL_PREFIX@ +libdir=@PKG_CONFIG_LIBDIR@ +includedir=@PKG_CONFIG_INCLUDEDIR@ + +Name: json.cpp +Description: @CMAKE_PROJECT_DESCRIPTION@ +Libs: -L${libdir} -ljson +Cflags: -I${includedir} \ No newline at end of file From 8e4d636e7c89a2fc899ee563b5ad1b2aa2861814 Mon Sep 17 00:00:00 2001 From: Farid Zakaria Date: Mon, 27 Oct 2025 10:59:04 -0700 Subject: [PATCH 2/4] Add requires for double-conversion --- CMakeLists.txt | 4 ++-- json.cpp.pc.in | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8b4fbc9..7f879cd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -88,8 +88,8 @@ install(TARGETS json ) # pkg-config -# * /lib/pkgconfig/double-conversion.pc +# * /lib/pkgconfig/json.cpp.pc install( - FILES "${CMAKE_CURRENT_BINARY_DIR}/double-conversion.pc" + FILES "${CMAKE_CURRENT_BINARY_DIR}/json.cpp.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig" ) \ No newline at end of file diff --git a/json.cpp.pc.in b/json.cpp.pc.in index f4054e2..6c1c2c9 100644 --- a/json.cpp.pc.in +++ b/json.cpp.pc.in @@ -5,4 +5,5 @@ includedir=@PKG_CONFIG_INCLUDEDIR@ Name: json.cpp Description: @CMAKE_PROJECT_DESCRIPTION@ Libs: -L${libdir} -ljson -Cflags: -I${includedir} \ No newline at end of file +Cflags: -I${includedir} +Requires.private: double-conversion \ No newline at end of file From 0a11e5c9e27d5edad72d28ec0d3214265bf8f009 Mon Sep 17 00:00:00 2001 From: Farid Zakaria Date: Mon, 27 Oct 2025 11:03:09 -0700 Subject: [PATCH 3/4] Add version --- json.cpp.pc.in | 1 + 1 file changed, 1 insertion(+) diff --git a/json.cpp.pc.in b/json.cpp.pc.in index 6c1c2c9..3ca1610 100644 --- a/json.cpp.pc.in +++ b/json.cpp.pc.in @@ -4,6 +4,7 @@ includedir=@PKG_CONFIG_INCLUDEDIR@ Name: json.cpp Description: @CMAKE_PROJECT_DESCRIPTION@ +Version: @PROJECT_VERSION@ Libs: -L${libdir} -ljson Cflags: -I${includedir} Requires.private: double-conversion \ No newline at end of file From 2df1cbfce5a1e3595a007fde3e89a114dbe65189 Mon Sep 17 00:00:00 2001 From: Farid Zakaria Date: Mon, 27 Oct 2025 11:09:41 -0700 Subject: [PATCH 4/4] Add new line after files --- CMakeLists.txt | 2 +- json.cpp.pc.in | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7f879cd..5f2fcdc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -92,4 +92,4 @@ install(TARGETS json install( FILES "${CMAKE_CURRENT_BINARY_DIR}/json.cpp.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig" -) \ No newline at end of file +) diff --git a/json.cpp.pc.in b/json.cpp.pc.in index 3ca1610..8d8ccf1 100644 --- a/json.cpp.pc.in +++ b/json.cpp.pc.in @@ -7,4 +7,4 @@ Description: @CMAKE_PROJECT_DESCRIPTION@ Version: @PROJECT_VERSION@ Libs: -L${libdir} -ljson Cflags: -I${includedir} -Requires.private: double-conversion \ No newline at end of file +Requires.private: double-conversion