Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCHv2 1/1] package/cjson: add a patch to allow cross-compilation with sysroot.
@ 2025-04-28  9:12 Guillaume Chaye
  2026-02-04 14:47 ` Thomas Petazzoni via buildroot
  0 siblings, 1 reply; 2+ messages in thread
From: Guillaume Chaye @ 2025-04-28  9:12 UTC (permalink / raw)
  To: buildroot; +Cc: Guillaume GC. Chaye, Thomas Petazzoni

From: "Guillaume GC. Chaye" <guillaume.chaye@zeetim.com>

The current generated cJSONConfig.cmake holds hard coded path of libraries and makes it impossible to use in SDKs.
Use CMakePackageConfigHelpers and @PACKAGE_INIT@ to make them suit for real environment dynamically.

Signed-off-by: Guillaume Chaye <guillaume.chaye@zeetim.com>
---
 ...nfigHelpers-to-generate-config.cmake.patch | 191 ++++++++++++++++++
 1 file changed, 191 insertions(+)
 create mode 100644 package/cjson/0001-Use-CMakePackageConfigHelpers-to-generate-config.cmake.patch

diff --git a/package/cjson/0001-Use-CMakePackageConfigHelpers-to-generate-config.cmake.patch b/package/cjson/0001-Use-CMakePackageConfigHelpers-to-generate-config.cmake.patch
new file mode 100644
index 0000000000..04248afbd9
--- /dev/null
+++ b/package/cjson/0001-Use-CMakePackageConfigHelpers-to-generate-config.cmake.patch
@@ -0,0 +1,191 @@
+From 2b0a994b5832439cf704147c5b485b9a4c7fbc24 Mon Sep 17 00:00:00 2001
+From: Charles Chan <charles@zeerd.com>
+Date: Fri, 22 Dec 2023 11:14:36 +0800
+Subject: [PATCH] Use CMakePackageConfigHelpers to generate config.cmake
+Signed-off-by: Charles Chan <charles@zeerd.com>
+Upstream: https://github.com/DaveGamble/cJSON/pull/812/commits/2b0a994b5832439cf704147c5b485b9a4c7fbc24
+
+---
+ CMakeLists.txt                                | 72 ++++++++++---------
+ .../{cJSONConfig.cmake.in => Config.cmake.in} | 15 ++--
+ library_config/cJSONConfigVersion.cmake.in    | 11 ---
+ 3 files changed, 48 insertions(+), 50 deletions(-)
+ rename library_config/{cJSONConfig.cmake.in => Config.cmake.in} (57%)
+ delete mode 100644 library_config/cJSONConfigVersion.cmake.in
+
+diff --git a/CMakeLists.txt b/CMakeLists.txt
+index f23ec631..fe10d6fe 100644
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -142,25 +142,25 @@ endif()
+ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/library_config/libcjson.pc.in"
+     "${CMAKE_CURRENT_BINARY_DIR}/libcjson.pc" @ONLY)
+ 
+-install(FILES cJSON.h DESTINATION "${CMAKE_INSTALL_FULL_INCLUDEDIR}/cjson")
+-install (FILES "${CMAKE_CURRENT_BINARY_DIR}/libcjson.pc" DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/pkgconfig")
++install(FILES cJSON.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/cjson")
++install (FILES "${CMAKE_CURRENT_BINARY_DIR}/libcjson.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
+ install(TARGETS "${CJSON_LIB}"
+-    EXPORT "${CJSON_LIB}"
+-    ARCHIVE DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}"
+-    LIBRARY DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}"
+-    RUNTIME DESTINATION "${CMAKE_INSTALL_FULL_BINDIR}"
+-    INCLUDES DESTINATION "${CMAKE_INSTALL_FULL_INCLUDEDIR}"
++    EXPORT "${CJSON_LIB}-targets"
++    ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
++    LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
++    RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
++    INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
+ )
+ if (BUILD_SHARED_AND_STATIC_LIBS)
+     install(TARGETS "${CJSON_LIB}-static"
+-    EXPORT "${CJSON_LIB}" 
+-    ARCHIVE DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}"
+-    INCLUDES DESTINATION "${CMAKE_INSTALL_FULL_INCLUDEDIR}"
++    EXPORT "${CJSON_LIB}-targets"
++    ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
++    INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
+ )
+ endif()
+ if(ENABLE_TARGET_EXPORT)
+     # export library information for CMake projects
+-    install(EXPORT "${CJSON_LIB}" DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/cmake/cJSON")
++    install(EXPORT "${CJSON_LIB}-targets" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/cJSON")
+ endif()
+ 
+ if(ENABLE_CJSON_VERSION_SO)
+@@ -194,24 +194,24 @@ if(ENABLE_CJSON_UTILS)
+         "${CMAKE_CURRENT_BINARY_DIR}/libcjson_utils.pc" @ONLY)
+ 
+     install(TARGETS "${CJSON_UTILS_LIB}"
+-        EXPORT "${CJSON_UTILS_LIB}"
+-        ARCHIVE DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}"
+-        LIBRARY DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}"
+-        RUNTIME DESTINATION "${CMAKE_INSTALL_FULL_BINDIR}"
+-        INCLUDES DESTINATION "${CMAKE_INSTALL_FULL_INCLUDEDIR}"
++        EXPORT "${CJSON_UTILS_LIB}-targets"
++        ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
++        LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
++        RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
++        INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
+     )
+     if (BUILD_SHARED_AND_STATIC_LIBS)
+-        install(TARGETS "${CJSON_UTILS_LIB}-static" 
+-        EXPORT "${CJSON_UTILS_LIB}" 
+-        ARCHIVE DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}"
+-        INCLUDES DESTINATION "${CMAKE_INSTALL_FULL_INCLUDEDIR}"
++        install(TARGETS "${CJSON_UTILS_LIB}-static"
++        EXPORT "${CJSON_UTILS_LIB}-targets"
++        ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
++        INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
+         )
+     endif()
+-    install(FILES cJSON_Utils.h DESTINATION "${CMAKE_INSTALL_FULL_INCLUDEDIR}/cjson")
+-    install (FILES "${CMAKE_CURRENT_BINARY_DIR}/libcjson_utils.pc" DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/pkgconfig")
++    install(FILES cJSON_Utils.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/cjson")
++    install (FILES "${CMAKE_CURRENT_BINARY_DIR}/libcjson_utils.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
+     if(ENABLE_TARGET_EXPORT)
+-      # export library information for CMake projects
+-      install(EXPORT "${CJSON_UTILS_LIB}" DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/cmake/cJSON")
++        # export library information for CMake projects
++        install(EXPORT "${CJSON_UTILS_LIB}-targets" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/cJSON")
+     endif()
+ 
+     if(ENABLE_CJSON_VERSION_SO)
+@@ -223,18 +223,22 @@ if(ENABLE_CJSON_UTILS)
+ endif()
+ 
+ # create the other package config files
+-configure_file(
+-    "${CMAKE_CURRENT_SOURCE_DIR}/library_config/cJSONConfig.cmake.in"
+-    ${PROJECT_BINARY_DIR}/cJSONConfig.cmake @ONLY)
+-configure_file(
+-    "${CMAKE_CURRENT_SOURCE_DIR}/library_config/cJSONConfigVersion.cmake.in"
+-    ${PROJECT_BINARY_DIR}/cJSONConfigVersion.cmake @ONLY)
+-
+ if(ENABLE_TARGET_EXPORT)
+-    # Install package config files
+-    install(FILES ${PROJECT_BINARY_DIR}/cJSONConfig.cmake
++    include(CMakePackageConfigHelpers)
++    write_basic_package_version_file(
+         ${PROJECT_BINARY_DIR}/cJSONConfigVersion.cmake
+-        DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/cmake/cJSON")
++        VERSION ${NCHL_VERSION}
++        COMPATIBILITY AnyNewerVersion)
++
++    configure_package_config_file(
++        "${PROJECT_SOURCE_DIR}/library_config/Config.cmake.in"
++        "${PROJECT_BINARY_DIR}/cJSONConfig.cmake"
++        INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/cJSON"
++        )
++    install(FILES
++            ${PROJECT_BINARY_DIR}/cJSONConfigVersion.cmake
++            ${PROJECT_BINARY_DIR}/cJSONConfig.cmake
++        DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/cJSON")
+ endif()
+ 
+ option(ENABLE_CJSON_TEST "Enable building cJSON test" ON)
+diff --git a/library_config/cJSONConfig.cmake.in b/library_config/Config.cmake.in
+similarity index 57%
+rename from library_config/cJSONConfig.cmake.in
+rename to library_config/Config.cmake.in
+index 909f7a9a..2784b7ab 100644
+--- a/library_config/cJSONConfig.cmake.in
++++ b/library_config/Config.cmake.in
+@@ -1,9 +1,12 @@
++@PACKAGE_INIT@
++include(CMakeFindDependencyMacro)
++
+ # Whether the utils lib was build.
+ set(CJSON_UTILS_FOUND @ENABLE_CJSON_UTILS@)
+ 
+ # The include directories used by cJSON
+-set(CJSON_INCLUDE_DIRS "@CMAKE_INSTALL_FULL_INCLUDEDIR@")
+-set(CJSON_INCLUDE_DIR "@CMAKE_INSTALL_FULL_INCLUDEDIR@")
++set(CJSON_INCLUDE_DIRS "${PACKAGE_PREFIX_DIR}/@CMAKE_INSTALL_INCLUDEDIR@")
++set(CJSON_INCLUDE_DIR "${PACKAGE_PREFIX_DIR}/@CMAKE_INSTALL_INCLUDEDIR@")
+ 
+ get_filename_component(_dir "${CMAKE_CURRENT_LIST_FILE}" PATH)
+ 
+@@ -11,19 +14,21 @@ get_filename_component(_dir "${CMAKE_CURRENT_LIST_FILE}" PATH)
+ set(CJSON_LIBRARY "@CJSON_LIB@")
+ if(@ENABLE_TARGET_EXPORT@)
+   # Include the target
+-  include("${_dir}/cjson.cmake")
++    include("${CMAKE_CURRENT_LIST_DIR}/cjson-targets.cmake")
+ endif()
+ 
+ if(CJSON_UTILS_FOUND)
+   # The cJSON utils library
+-  set(CJSON_UTILS_LIBRARY @CJSON_UTILS_LIB@)
++  set(CJSON_UTILS_LIBRARY "@CJSON_UTILS_LIB@")
+   # All cJSON libraries
+   set(CJSON_LIBRARIES "@CJSON_UTILS_LIB@" "@CJSON_LIB@")
+   if(@ENABLE_TARGET_EXPORT@)
+     # Include the target
+-    include("${_dir}/cjson_utils.cmake")
++    include("${CMAKE_CURRENT_LIST_DIR}/cjson_utils-targets.cmake")
+   endif()
+ else()
+   # All cJSON libraries
+   set(CJSON_LIBRARIES "@CJSON_LIB@")
+ endif()
++
++check_required_components("@CMAKE_PROJECT_NAME@")
+diff --git a/library_config/cJSONConfigVersion.cmake.in b/library_config/cJSONConfigVersion.cmake.in
+deleted file mode 100644
+index 22ffec0f..00000000
+--- a/library_config/cJSONConfigVersion.cmake.in
++++ /dev/null
+@@ -1,11 +0,0 @@
+-set(PACKAGE_VERSION "@PROJECT_VERSION@")
+-
+-# Check whether the requested PACKAGE_FIND_VERSION is compatible
+-if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}")
+-  set(PACKAGE_VERSION_COMPATIBLE FALSE)
+-else()
+-  set(PACKAGE_VERSION_COMPATIBLE TRUE)
+-  if ("${PACKAGE_VERSION}" VERSION_EQUAL "${PACKAGE_FIND_VERSION}")
+-    set(PACKAGE_VERSION_EXACT TRUE)
+-  endif()
+-endif()
-- 
2.39.5

_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [Buildroot] [PATCHv2 1/1] package/cjson: add a patch to allow cross-compilation with sysroot.
  2025-04-28  9:12 [Buildroot] [PATCHv2 1/1] package/cjson: add a patch to allow cross-compilation with sysroot Guillaume Chaye
@ 2026-02-04 14:47 ` Thomas Petazzoni via buildroot
  0 siblings, 0 replies; 2+ messages in thread
From: Thomas Petazzoni via buildroot @ 2026-02-04 14:47 UTC (permalink / raw)
  To: Guillaume Chaye; +Cc: buildroot

Hello Guillaume,

Sorry for the long delay in getting back to you.

On Mon, Apr 28, 2025 at 05:12:48AM -0400, Guillaume Chaye wrote:
> From: "Guillaume GC. Chaye" <guillaume.chaye@zeetim.com>
> 
> The current generated cJSONConfig.cmake holds hard coded path of libraries and makes it impossible to use in SDKs.

Could you provide some more details here? Indeed, normally hardcoded
paths in text files are properly replaced by our relocate-sdk.sh
scripts. Are you sure we're talking about hardcoded paths, or paths
that are just invalid in the first place? I did a build of cjson
without your patch, and saw some /usr/include in
cJSONConfig.cmake. Are these the problemtic paths?

> Use CMakePackageConfigHelpers and @PACKAGE_INIT@ to make them suit for real environment dynamically.

The problem with your proposal is that the upstream submission was
made over 2 years ago, has received no interest/feedback from
upstream, but makes some fairly substantial changes to CMakeLists.txt
that would make updating to later versions cJSON quite a lot more
difficult.

Could you push further the topic upstream, so that we have something
that is accepted upstream, and that we can safely backport in
Buildroot?

Thanks a lot,

Thomas
-- 
Thomas Petazzoni, co-owner and CEO, Bootlin
Embedded Linux and Kernel engineering and training
https://bootlin.com
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-02-04 14:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-28  9:12 [Buildroot] [PATCHv2 1/1] package/cjson: add a patch to allow cross-compilation with sysroot Guillaume Chaye
2026-02-04 14:47 ` Thomas Petazzoni via buildroot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox