cmake_minimum_required(VERSION 4.0)

project(autoopt)

set(CMAKE_CXX_STANDARD 23)

add_compile_options(-Wall -Werror -Wpedantic)

find_package(Eigen3 REQUIRED)

find_package(Python 3.13 COMPONENTS Interpreter Development.Module REQUIRED)

execute_process(
  COMMAND "${Python_EXECUTABLE}" -m nanobind --cmake_dir
  OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE nanobind_ROOT)
find_package(nanobind CONFIG REQUIRED)

file(GLOB_RECURSE SOURCES src/*.cpp)

add_library(autoopt STATIC ${SOURCES})
target_include_directories(autoopt PUBLIC include)
target_link_libraries(autoopt PUBLIC Eigen3::Eigen)

install(DIRECTORY include/autoopt DESTINATION include)

nanobind_add_module(slopefit NOMINSIZE pysrc/module.cpp)
target_link_libraries(slopefit PRIVATE autoopt)
install(TARGETS slopefit DESTINATION lib/python3.13/site-packages)

# add tests if gtest is found
find_library(GTestPackage gtest QUIET)
if(GTestPackage)
  enable_testing()
  add_subdirectory(tests)
endif()

