# clawdforge — C SDK # # MIT License # # Copyright (c) 2026 clawdforge contributors # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. cmake_minimum_required(VERSION 3.16) project(clawdforge VERSION 0.1.0 DESCRIPTION "C SDK for the clawdforge HTTP service" LANGUAGES C) option(CLAWDFORGE_BUILD_TESTS "Build the test suite" ON) option(CLAWDFORGE_BUILD_EXAMPLES "Build example programs" ON) option(CLAWDFORGE_ASAN "Build with AddressSanitizer" OFF) set(CMAKE_C_STANDARD 11) set(CMAKE_C_STANDARD_REQUIRED ON) set(CMAKE_C_EXTENSIONS OFF) include(GNUInstallDirs) # ---------------------------------------------------------------------------- # Dependencies # ---------------------------------------------------------------------------- find_package(CURL REQUIRED) # Common warning flags. Tests bump to -Werror. set(CF_WARN_FLAGS -Wall -Wextra -Wpedantic) if(CLAWDFORGE_ASAN) list(APPEND CF_WARN_FLAGS -fsanitize=address -fno-omit-frame-pointer -g) endif() # ---------------------------------------------------------------------------- # Sources # ---------------------------------------------------------------------------- set(CF_SOURCES src/client.c src/http.c src/json.c src/cjson/cJSON.c) # ---------------------------------------------------------------------------- # Static library # ---------------------------------------------------------------------------- add_library(clawdforge_static STATIC ${CF_SOURCES}) set_target_properties(clawdforge_static PROPERTIES OUTPUT_NAME clawdforge POSITION_INDEPENDENT_CODE ON) target_include_directories(clawdforge_static PUBLIC $ $ PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}/src/cjson) target_link_libraries(clawdforge_static PUBLIC CURL::libcurl) target_compile_options(clawdforge_static PRIVATE ${CF_WARN_FLAGS}) target_compile_definitions(clawdforge_static PRIVATE CLAWDFORGE_BUILDING_LIB) if(CLAWDFORGE_ASAN) target_link_options(clawdforge_static PUBLIC -fsanitize=address) endif() # ---------------------------------------------------------------------------- # Shared library # ---------------------------------------------------------------------------- add_library(clawdforge_shared SHARED ${CF_SOURCES}) set_target_properties(clawdforge_shared PROPERTIES OUTPUT_NAME clawdforge VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR} POSITION_INDEPENDENT_CODE ON C_VISIBILITY_PRESET hidden) target_include_directories(clawdforge_shared PUBLIC $ $ PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}/src/cjson) target_link_libraries(clawdforge_shared PUBLIC CURL::libcurl) target_compile_options(clawdforge_shared PRIVATE ${CF_WARN_FLAGS}) target_compile_definitions(clawdforge_shared PRIVATE CLAWDFORGE_BUILDING_LIB) if(CLAWDFORGE_ASAN) target_link_options(clawdforge_shared PUBLIC -fsanitize=address) endif() # Convenience alias used by examples + tests. add_library(clawdforge::clawdforge ALIAS clawdforge_static) # ---------------------------------------------------------------------------- # Install + pkg-config # ---------------------------------------------------------------------------- install(TARGETS clawdforge_static clawdforge_shared EXPORT clawdforgeTargets ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) install(FILES include/clawdforge.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) configure_file(pkgconfig/clawdforge.pc.in ${CMAKE_CURRENT_BINARY_DIR}/clawdforge.pc @ONLY) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/clawdforge.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) # ---------------------------------------------------------------------------- # Examples # ---------------------------------------------------------------------------- if(CLAWDFORGE_BUILD_EXAMPLES) add_executable(clawdforge_example_basic examples/basic.c) target_link_libraries(clawdforge_example_basic PRIVATE clawdforge_static) target_compile_options(clawdforge_example_basic PRIVATE ${CF_WARN_FLAGS}) endif() # ---------------------------------------------------------------------------- # Tests # ---------------------------------------------------------------------------- if(CLAWDFORGE_BUILD_TESTS) enable_testing() add_executable(clawdforge_tests tests/test_client.c) target_link_libraries(clawdforge_tests PRIVATE clawdforge_static) target_include_directories(clawdforge_tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/cjson) target_compile_options(clawdforge_tests PRIVATE ${CF_WARN_FLAGS} -Werror) add_test(NAME clawdforge_tests COMMAND clawdforge_tests) set_tests_properties(clawdforge_tests PROPERTIES TIMEOUT 60) endif()