cmake_minimum_required(VERSION 3.15...3.27)

project(
  ${SKBUILD_PROJECT_NAME}
  VERSION ${SKBUILD_PROJECT_VERSION}
  LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

add_library(methods STATIC
  src/common.cpp
  src/mes_add1.cpp
  src/mes_utils.cpp
  src/expanding_approvals.cpp
  src/single_transferable_vote.cpp
  src/solid_coalition_refinement.cpp)
set_target_properties(methods PROPERTIES POSITION_INDEPENDENT_CODE ON)

add_library(metrics STATIC
  src/metrics/solved_instance.cpp
  src/metrics/exclusion_ratio.cpp
  src/metrics/ejr_plus.cpp)
set_target_properties(metrics PROPERTIES POSITION_INDEPENDENT_CODE ON)
# no fused multiply-add: python rounds every * and +, parity is bit-exact
target_compile_options(metrics PRIVATE
  $<IF:$<CXX_COMPILER_ID:MSVC>,/fp:precise,-ffp-contract=off>)

find_package(Python REQUIRED COMPONENTS Interpreter Development.Module)
find_package(pybind11 CONFIG REQUIRED)

include_directories(${pybind11_INCLUDE_DIRS})

python_add_library(muoblpbindings MODULE src/binder.cpp WITH_SOABI)
target_link_libraries(muoblpbindings PRIVATE pybind11::headers)
target_link_libraries(muoblpbindings PRIVATE methods)
target_link_libraries(muoblpbindings PRIVATE metrics)

target_compile_definitions(muoblpbindings PRIVATE VERSION_INFO=${PROJECT_VERSION})

install(TARGETS muoblpbindings DESTINATION muoblpbindings)
