cmake_minimum_required(VERSION 3.28)

project(ds3231 LANGUAGES CXX)

# libavr comes from a local checkout (LIBAVR_ROOT cache/env variable) or,
# failing that, straight from the forge. The toolchain file also lives in
# that checkout — see CMakePresets.json.
include(FetchContent)
if(NOT LIBAVR_ROOT AND DEFINED ENV{LIBAVR_ROOT})
	set(LIBAVR_ROOT $ENV{LIBAVR_ROOT})
endif()
if(LIBAVR_ROOT)
	FetchContent_Declare(libavr SOURCE_DIR ${LIBAVR_ROOT})
else()
	FetchContent_Declare(libavr GIT_REPOSITORY git@git.blackmark.me:avr/libavr.git GIT_TAG main)
endif()
FetchContent_MakeAvailable(libavr)

add_library(ds3231 INTERFACE)
target_include_directories(ds3231 INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_link_libraries(ds3231 INTERFACE libavr)

if(PROJECT_IS_TOP_LEVEL)
	add_subdirectory(example)
endif()
