# SPDX-License-Identifier: AGPL-3.0-or-later
# Copyright (C) 2026  Complement Alimentaire
#
# This file is part of simdpunk.
#
# simdpunk is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# simdpunk is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with simdpunk.  If not, see <https://www.gnu.org/licenses/>.

# The Python package's one compiled piece: `_simdpunk.so`, the C ABI `simdpunk/__init__.py` loads with ctypes.

cmake_minimum_required(VERSION 3.20)
project(simdpunk_python LANGUAGES CXX)

# OFF BEFORE THE add_subdirectory: the library registers its tests by default even as a
# subproject, and a wheel build has neither Catch2 nor any use for them.
set(SIMDPUNK_TESTS OFF CACHE BOOL "" FORCE)
set(SIMDPUNK_EXAMPLES OFF CACHE BOOL "" FORCE)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/.. simdpunk)

# A plain shared object, not a CPython extension: nothing here includes Python.h, so one build
# serves every Python version (the wheel is tagged py3-none-<platform>).
# No -march: every ISA arm reaches its instructions through its own target attribute and is chosen at run time.
add_library(_simdpunk MODULE simdpunk_c.cpp)
target_link_libraries(_simdpunk PRIVATE simdpunk)
set_target_properties(_simdpunk PROPERTIES PREFIX "" SUFFIX ".so" CXX_EXTENSIONS ON)

find_package(OpenMP)
if(OpenMP_CXX_FOUND)
  target_link_libraries(_simdpunk PRIVATE OpenMP::OpenMP_CXX)
endif()

install(TARGETS _simdpunk LIBRARY DESTINATION simdpunk)
