Skip to content

Commit

Permalink
implement python module using nanobind
Browse files Browse the repository at this point in the history
  • Loading branch information
foolnotion committed May 29, 2024
1 parent 3563285 commit 0389294
Show file tree
Hide file tree
Showing 3 changed files with 649 additions and 2 deletions.
15 changes: 13 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ if (NOT VSTAT_NAMESPACE)
endif()
message(STATUS "vstat namespace defined as '${VSTAT_NAMESPACE}'")

# ---- Python module ----

if(vstat_BUILD_PYTHON)
find_package(Python COMPONENTS Interpreter Development REQUIRED)
find_package(nanobind REQUIRED)
set(VSTAT_PYTHON_SITELIB "${CMAKE_INSTALL_LIBDIR}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}/site-packages/")

nanobind_add_module(vstat_python ${PROJECT_SOURCE_DIR}/src/vstat.cpp)
target_link_libraries(vstat_python PRIVATE vstat::vstat)
set_target_properties(vstat_python PROPERTIES OUTPUT_NAME "vstat")
endif()

# ---- Install rules ----

if(NOT CMAKE_SKIP_INSTALL_RULES)
Expand All @@ -59,5 +71,4 @@ elseif(NOT PROJECT_IS_TOP_LEVEL)
"Developer mode is intended for developers of vstat"
)
endif()

include(cmake/dev-mode.cmake)
include(cmake/dev-mode.cmake)
8 changes: 8 additions & 0 deletions cmake/install-rules.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ install(
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)

if (vstat_BUILD_PYTHON AND Python_FOUND)
install(
TARGETS vstat_python
EXPORT vstatTargets
LIBRARY DESTINATION "${VSTAT_PYTHON_SITELIB}"
)
endif()

write_basic_package_version_file(
"${package}ConfigVersion.cmake"
COMPATIBILITY SameMajorVersion
Expand Down
Loading

0 comments on commit 0389294

Please sign in to comment.