# SPDX-FileCopyrightText: 2026 Elizabeth Kiara Regina Ashford
# SPDX-License-Identifier: 0BSD

cmake_minimum_required(VERSION 3.15)
project(ccobs VERSION 0.1.0 LANGUAGES C)

option(BUILD_SHARED_LIBS "Build ccobs as a shared library" OFF)

function(ccobs_enable_warnings target)
    if(MSVC)
        target_compile_options(${target} PRIVATE /W4)
    else()
        target_compile_options(${target} PRIVATE -Wall -Wextra -Wpedantic)
    endif()
endfunction()

add_library(ccobs src/cobs.c)
target_include_directories(ccobs
    PUBLIC
        $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
        $<INSTALL_INTERFACE:include>)
target_compile_features(ccobs PUBLIC c_std_11)
set_target_properties(ccobs PROPERTIES
    C_EXTENSIONS OFF
    VERSION ${PROJECT_VERSION}
    SOVERSION ${PROJECT_VERSION_MAJOR})
if(BUILD_SHARED_LIBS)
    target_compile_definitions(ccobs
        PUBLIC CCOBS_SHARED
        PRIVATE CCOBS_BUILDING_LIBRARY)
endif()
ccobs_enable_warnings(ccobs)

include(CTest)
if(BUILD_TESTING)
    add_executable(ccobs_test tests/test_cobs.c)
    target_link_libraries(ccobs_test PRIVATE ccobs)
    target_compile_features(ccobs_test PRIVATE c_std_11)
    set_target_properties(ccobs_test PROPERTIES C_EXTENSIONS OFF)
    ccobs_enable_warnings(ccobs_test)
    add_test(NAME ccobs_test COMMAND ccobs_test)
endif()
