test: Update 5 files
All checks were successful
dropshell-build multiarch / build (linux/amd64) (push) Successful in 7m39s
dropshell-build multiarch / build (linux/arm64) (push) Successful in 16m19s
dropshell-build multiarch / create-manifest (push) Successful in 15s

This commit is contained in:
Your Name
2025-06-29 15:33:50 +12:00
parent ec15d87376
commit ea0ad2daa5
10 changed files with 269 additions and 19 deletions

View File

@ -0,0 +1,63 @@
cmake_minimum_required(VERSION 3.16)
# Project setup
if(NOT DEFINED PROJECT_NAME)
message(FATAL_ERROR "PROJECT_NAME is not defined. Pass it via -DPROJECT_NAME=<name>")
endif()
string(TIMESTAMP PROJECT_VERSION "%Y.%m%d.%H%M")
project(${PROJECT_NAME} VERSION ${PROJECT_VERSION} LANGUAGES CXX)
# Build configuration
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXE_LINKER_FLAGS "-static")
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
set(BUILD_SHARED_LIBS OFF)
set(CMAKE_PREFIX_PATH /usr/local)
# Create executable
file(GLOB_RECURSE SOURCES "src/*.cpp")
add_executable(${PROJECT_NAME} ${SOURCES})
# Configure version.hpp
configure_file("src/version.hpp.in" "src/autogen/version.hpp" @ONLY)
# Pre-build script
add_custom_target(run_prebuild_script ALL
COMMAND bash ${CMAKE_CURRENT_SOURCE_DIR}/cmake_prebuild.sh
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
add_dependencies(${PROJECT_NAME} run_prebuild_script)
# Include directories
target_include_directories(${PROJECT_NAME} PRIVATE
${CMAKE_CURRENT_BINARY_DIR}/src/autogen
src)
# Find packages
find_package(OpenSSL REQUIRED)
find_package(PkgConfig REQUIRED)
find_package(nlohmann_json REQUIRED)
# Find CURL manually since we built it without CMake targets
find_library(CURL_LIBRARY NAMES curl libcurl PATHS /usr/local/lib NO_DEFAULT_PATH)
find_path(CURL_INCLUDE_DIR NAMES curl/curl.h PATHS /usr/local/include NO_DEFAULT_PATH)
# Create CURL target if not found
if(NOT TARGET CURL::libcurl)
add_library(CURL::libcurl STATIC IMPORTED)
set_target_properties(CURL::libcurl PROPERTIES
IMPORTED_LOCATION ${CURL_LIBRARY}
INTERFACE_INCLUDE_DIRECTORIES ${CURL_INCLUDE_DIR}
INTERFACE_LINK_LIBRARIES "/usr/lib/libz.a;/usr/lib/libzstd.a"
)
endif()
# Find CPR after CURL target is available
find_package(cpr REQUIRED)
# Link libraries
target_link_libraries(${PROJECT_NAME} PRIVATE
nlohmann_json::nlohmann_json
cpr::cpr
lzma dl)

View File

@ -0,0 +1,8 @@
#!/bin/bash
echo "CPR Demo Pre-build Script"
echo "========================="
echo "Build time: $(date)"
echo "Working directory: $(pwd)"
echo "CMAKE args: $@"
echo "CPR Demo ready for build"

View File

@ -0,0 +1,13 @@
#pragma once
#include <iostream>
#include <stdexcept>
#define ASSERT(condition, message) \
do { \
if (!(condition)) { \
std::cerr << "Assertion failed: " << message << std::endl; \
std::cerr << "File: " << __FILE__ << ", Line: " << __LINE__ << std::endl; \
throw std::runtime_error(message); \
} \
} while (false)

View File

@ -0,0 +1,33 @@
#include <iostream>
#include <nlohmann/json.hpp>
#include <cpr/cpr.h>
#include "version.hpp"
#include "assert.hpp"
void crashy() {
ASSERT(false, "SUCCESS!");
}
int main() {
std::cout << "cprdemo version: " << cprdemo::VERSION << std::endl;
std::cout << std::endl;
std::cout << "Retrieving IP address using CPR..." << std::endl;
// Use CPR to make HTTP GET request
cpr::Response r = cpr::Get(cpr::Url{"https://ipinfo.io/ip"});
ASSERT(r.status_code == 200, "Failed to get IP");
nlohmann::json j;
j["ip"] = r.text;
j["status"] = r.status_code;
std::cout << j.dump(4) << std::endl;
std::cout << "Done" << std::endl;
crashy();
return 0;
}

View File

@ -0,0 +1,5 @@
#pragma once
namespace @PROJECT_NAME@ {
constexpr const char* VERSION = "@PROJECT_VERSION@";
}