diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..2d48ef028571f082604202ac4a4813d837e489b8 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,88 @@ +cmake_minimum_required(VERSION 3.15) + +project( + EvalHyd-Python + LANGUAGES CXX C + VERSION 0.0.1 + DESCRIPTION "Python bindings for evalhyd utility" +) + +add_library( + evalhyd-python MODULE + ${CMAKE_CURRENT_SOURCE_DIR}/src/evalhyd-python.cpp +) + +# ------------------------------------------------------------------------------ +# dependencies and build +# ------------------------------------------------------------------------------ + +if(SKBUILD) + find_package(PythonExtensions REQUIRED) + find_package(NumPy REQUIRED) + python_extension_module(evalhyd-python) +else() + find_package(Python COMPONENTS Interpreter Development NumPy REQUIRED) + target_link_libraries(evalhyd-python Python::NumPy) + # use only header if numpy target links to libpython + #target_include_directories(evalhyd-python SYSTEM PRIVATE "${Python_NumPy_INCLUDE_DIRS}") +endif() + +find_package(xtensor REQUIRED) +message(STATUS "Found xtensor: ${xtensor_INCLUDE_DIRS}/xtensor") + +find_package(xtensor-python REQUIRED) +message(STATUS "Found xtensor-python: ${xtensor-python_INCLUDE_DIRS}/xtensor-python") + +find_package(pybind11 REQUIRED) +message(STATUS "Found pybind11: ${pybind11_INCLUDE_DIRS}/pybind11") + +if(DEFINED EVALHYD_SRC) + set(EVALHYD_BUILD_TEST OFF CACHE BOOL "configure and compile tests") + add_subdirectory(${EVALHYD_SRC} deps/evalhyd) +else() + find_package(EvalHyd REQUIRED) +endif() + +target_link_libraries( + evalhyd-python + EvalHyd::evalhyd + xtensor-python + pybind11::module + pybind11::lto + pybind11::windows_extras +) + +set_target_properties( + evalhyd-python PROPERTIES + OUTPUT_NAME evalhyd +) + +pybind11_extension(evalhyd-python) +if(NOT MSVC AND NOT ${CMAKE_BUILD_TYPE} MATCHES Debug|RelWithDebInfo) + # Strip unnecessary sections of the binary on Linux/macOS + pybind11_strip(evalhyd-python) +endif() + +set_target_properties( + evalhyd-python PROPERTIES + CXX_VISIBILITY_PRESET "hidden" + CUDA_VISIBILITY_PRESET "hidden" +) + +# add include directories +target_include_directories( + evalhyd-python + PUBLIC + ${NUMPY_INCLUDE_DIRS} +) + +# ------------------------------------------------------------------------------ +# installation +# ------------------------------------------------------------------------------ + +if(SKBUILD) + install( + TARGETS evalhyd-python + DESTINATION evalhyd-python + ) +endif() diff --git a/pyproject.toml b/pyproject.toml index fd3ad8a0e0588c2bd9c545812d1848eb30f5993c..fbc35a1bba84828279cfa3dd10d09ee62c774f92 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,7 +2,10 @@ requires = [ "setuptools>=42", "wheel", + "scikit-build", + "cmake", "pybind11>=2.8.0", + "ninja", "numpy>1.16", ]