cmake_minimum_required(VERSION 3.11)

set(CMAKE_C_STANDARD 11)

project(
  refcount
  VERSION 1.0
  LANGUAGES C)

include(FetchContent)
FetchContent_Declare(
  ht
  GIT_REPOSITORY https://git.zander.im/Zander671/ht.git
  GIT_TAG 9a1b271cfdc8ab203f9d6aa6a83cc4523de422be)

FetchContent_MakeAvailable(ht)

if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
  include(CTest)
endif()

add_compile_options(-fsanitize=address,leak,undefined)
add_link_options(-fsanitize=address,leak,undefined)

add_library(refcount src/allocator.c src/list.c src/refcount.c)
target_link_libraries(refcount PUBLIC ht)
target_include_directories(refcount PUBLIC include/)
target_compile_options(refcount PRIVATE -Wall -Wpedantic)

if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING)
  add_subdirectory(test/)
endif()
