cmake_minimum_required(VERSION 3.11) # FetchContent

project(keycode)

enable_language(CXX)
set(CMAKE_CXX_STANDARD 20)

include(FetchContent)
include("cmake/Check-from_chars.cmake")

set (LIBS fmt)

if (NOT DEFINED OPTCON_LOCAL_BUILD)
    FetchContent_Declare(
        fmt
        GIT_REPOSITORY https://github.com/fmtlib/fmt
        GIT_TAG 407c905e45ad75fc29bf0f9bb7c5c2fd3475976f # 12.1.0
        SYSTEM
    )

    FetchContent_MakeAvailable(fmt)
endif()

if (NOT FROM_CHARS_WORKS)
    FetchContent_Declare(
        fast_float
        GIT_REPOSITORY https://github.com/fastfloat/fast_float
        GIT_TAG 77cc847c842c49e7e3477c1e95da2b6540166d66 # 8.0.0
        SYSTEM
    )

    FetchContent_MakeAvailable(fast_float)

    list(APPEND LIBS fast_float)
    add_definitions(-DUSE_FAST_FLOAT)
endif()

if (MSVC)
    # https://learn.microsoft.com/en-us/cpp/build/reference/compiler-option-warning-level?view=msvc-170
    add_compile_options(/Wall)
else()
    add_compile_options(-Wall -Wextra -Wpedantic)
endif()

add_library(keycode STATIC
    src/array.cpp
    src/array_utils.cpp
    src/keycode.c
)

target_link_libraries(keycode ${LIBS})

target_include_directories(keycode
    PUBLIC src
)

add_executable(keycode_test
    src/test.c
)

target_link_libraries(keycode_test
    keycode
)
