cmake_minimum_required(VERSION 3.14)

project(cenet CXX)

option(CENET_BUILD_TESTS "Compile cenet tests" OFF)
option(CENET_BUILD_EXAMPLES "Compile cenet examples" ON)

option(TULIP_DISABLE_SIMD "Disable SIMD backend for tulip" OFF)

file(GLOB_RECURSE TULIP_HEADERS CONFIGURE_DEPENDS "include/tulip/*.hpp")
add_library(tulip INTERFACE ${TULIP_HEADERS})
target_include_directories(tulip INTERFACE include)
target_compile_features(tulip INTERFACE cxx_std_17)
add_library(cenet::tulip ALIAS tulip)

if(TULIP_DISABLE_SIMD)
  target_compile_definitions(tulip INTERFACE TULIP_DISABLE_SIMD)
endif()

file(GLOB_RECURSE CENET_HEADERS CONFIGURE_DEPENDS "include/cenet/*.hpp")
add_library(cenet INTERFACE ${CENET_HEADERS})
target_link_libraries(cenet INTERFACE tulip)
target_include_directories(cenet INTERFACE include)
target_compile_features(cenet INTERFACE cxx_std_17)
add_library(cenet::cenet ALIAS cenet)

if(CENET_BUILD_EXAMPLES)
  add_executable(xor example/xor.cpp)
  target_link_libraries(xor PRIVATE cenet)

  add_executable(mnist example/mnist.cpp)
  target_link_libraries(mnist PRIVATE cenet)

  add_executable(tokenizer example/tokenizer.cpp)
  target_link_libraries(tokenizer PRIVATE cenet)

  add_executable(gpt example/gpt.cpp)
  target_link_libraries(gpt PRIVATE cenet)
endif()

if(CENET_BUILD_TESTS)
  include(FetchContent)
  FetchContent_Declare(
    googletest
    URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
  )
  set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
  FetchContent_MakeAvailable(googletest)

  enable_testing()

  add_executable(math_test test/tensor.cpp)
  target_link_libraries(math_test GTest::gtest_main cenet)

  include(GoogleTest)
  gtest_discover_tests(math_test)
endif()
