From a8d4b43039a6b998610b977503c1f8e678751ee8 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 29 Jun 2025 18:21:20 +1200 Subject: [PATCH] docs: Update 3 files --- README.md | 17 +++++++++++++++++ build-base/Dockerfile.dropshell-build-base | 16 ++++++++++++++++ tests/cprdemo/CMakeLists.txt | 18 ++++-------------- 3 files changed, 37 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index d9f9027..3f6a1ec 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,23 @@ Two HTTP client approaches are available: } ``` + To use CPR in your CMakeLists.txt with proper static linking: + ```cmake + find_package(nlohmann_json REQUIRED) + + # CPR static linking setup + add_library(cpr::cpr_static STATIC IMPORTED) + set_target_properties(cpr::cpr_static PROPERTIES + IMPORTED_LOCATION "/usr/local/lib/libcpr.a" + INTERFACE_INCLUDE_DIRECTORIES "/usr/local/include" + INTERFACE_LINK_LIBRARIES "/usr/local/lib/libcurl.a;/usr/local/lib64/libssl.a;/usr/local/lib64/libcrypto.a;/usr/lib/libz.a;/usr/lib/libzstd.a;lzma;dl" + ) + + target_link_libraries(${PROJECT_NAME} PRIVATE + nlohmann_json::nlohmann_json + cpr::cpr_static) + ``` + ## Quick Start ### Building the Base Image diff --git a/build-base/Dockerfile.dropshell-build-base b/build-base/Dockerfile.dropshell-build-base index 4d46e31..55fd89d 100644 --- a/build-base/Dockerfile.dropshell-build-base +++ b/build-base/Dockerfile.dropshell-build-base @@ -183,6 +183,22 @@ RUN curl -LO https://github.com/libcpr/cpr/archive/refs/tags/${CPR_VERSION}.tar. make install && \ cd / && rm -rf /tmp/cpr-${CPR_VERSION} /tmp/${CPR_VERSION}.tar.gz +# Fix CPR CMake config to provide a static-only target +RUN cat > /usr/local/lib/cmake/cpr/cprConfig-static.cmake << 'EOF' +# Static-only CPR configuration that avoids CURL dependency issues + +# Create the static CPR target +add_library(cpr::cpr_static STATIC IMPORTED) +set_target_properties(cpr::cpr_static PROPERTIES + IMPORTED_LOCATION "${CMAKE_CURRENT_LIST_DIR}/../../../lib/libcpr.a" + INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_LIST_DIR}/../../../include" + INTERFACE_LINK_LIBRARIES "/usr/local/lib/libcurl.a;/usr/local/lib64/libssl.a;/usr/local/lib64/libcrypto.a;/usr/lib/libz.a;/usr/lib/libzstd.a;lzma;dl" +) + +# Provide an alias for convenience +add_library(cpr::static ALIAS cpr::cpr_static) +EOF + ARG MARIADB_CONNECTOR_VERSION=3.4.5 WORKDIR /tmp diff --git a/tests/cprdemo/CMakeLists.txt b/tests/cprdemo/CMakeLists.txt index 1f20648..dd9aec7 100644 --- a/tests/cprdemo/CMakeLists.txt +++ b/tests/cprdemo/CMakeLists.txt @@ -35,27 +35,17 @@ target_include_directories(${PROJECT_NAME} PRIVATE src) # Find packages -find_package(OpenSSL REQUIRED) find_package(nlohmann_json REQUIRED) -find_package(PkgConfig REQUIRED) -# Use pkg-config for libcurl since CMake config isn't available -pkg_check_modules(CURL REQUIRED libcurl) - -# Create a static-only CPR target to avoid dynamic linking issues +# CPR static linking setup add_library(cpr::cpr_static STATIC IMPORTED) set_target_properties(cpr::cpr_static PROPERTIES IMPORTED_LOCATION "/usr/local/lib/libcpr.a" INTERFACE_INCLUDE_DIRECTORIES "/usr/local/include" + INTERFACE_LINK_LIBRARIES "/usr/local/lib/libcurl.a;/usr/local/lib64/libssl.a;/usr/local/lib64/libcrypto.a;/usr/lib/libz.a;/usr/lib/libzstd.a;lzma;dl" ) -# Link libraries with explicit static linking +# Link libraries target_link_libraries(${PROJECT_NAME} PRIVATE nlohmann_json::nlohmann_json - cpr::cpr_static - /usr/local/lib/libcurl.a - /usr/local/lib64/libssl.a - /usr/local/lib64/libcrypto.a - /usr/lib/libz.a - /usr/lib/libzstd.a - lzma dl) \ No newline at end of file + cpr::cpr_static) \ No newline at end of file