cmake_minimum_required(VERSION 3.21)
project(regolith VERSION 0.0.1 LANGUAGES C)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

option(REGOLITH_BUILD_TESTS "Build tests" ON)
option(REGOLITH_BUILD_SDL3 "Build the SDL3 backend" ON)

add_subdirectory(third_party)

add_library(regolith
  src/context.c
  src/layout_clay.c
  src/text_stb.c
  src/lua_module.c
)
add_library(regolith::regolith ALIAS regolith)

target_include_directories(regolith
  PUBLIC  ${PROJECT_SOURCE_DIR}/include
  PRIVATE ${PROJECT_SOURCE_DIR}/src
)
target_link_libraries(regolith PUBLIC lua PRIVATE clay stb)
target_compile_definitions(regolith PRIVATE RG_BUILD)
target_compile_options(regolith PRIVATE
  $<$<NOT:$<C_COMPILER_ID:MSVC>>:-Wall -Wextra -Wpedantic>)
set_target_properties(regolith PROPERTIES
  C_STANDARD 99
  C_EXTENSIONS OFF
  C_VISIBILITY_PRESET hidden
)

if(REGOLITH_BUILD_SDL3 AND NOT EMSCRIPTEN)
  find_package(SDL3 REQUIRED CONFIG)
endif()

if(REGOLITH_BUILD_TESTS)
  enable_testing()
  add_subdirectory(tests)
endif()
