Skip to content

Commit

Permalink
First small example for nanobind module.
Browse files Browse the repository at this point in the history
  • Loading branch information
KerstinKeller committed Mar 12, 2024
1 parent b8a22c5 commit ff9a33e
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,6 @@
[submodule "thirdparty/udpcap"]
path = thirdparty/udpcap/udpcap
url = https://github.com/eclipse-ecal/udpcap.git
[submodule "thirdparty/nanobind/nanobind"]
path = thirdparty/nanobind/nanobind
url = https://github.com/wjakob/nanobind.git
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ option(ECAL_THIRDPARTY_BUILD_CMAKE_FUNCTIONS "Build CMakeFunctions with eCAL"
option(ECAL_THIRDPARTY_BUILD_FINEFTP "Build fineFTP with eCAL" ON)
option(ECAL_THIRDPARTY_BUILD_FTXUI "Build ftxui with eCAL" ON)
option(ECAL_THIRDPARTY_BUILD_GTEST "Build gtest with eCAL" OFF)
if (BUILD_PY_BINDING)
option(ECAL_THIRDPARTY_BUILD_NANOBIND "Build nanobind with eCAL" ON)
endif()
option(ECAL_THIRDPARTY_BUILD_RECYCLE "Build steinwurf::recylce with eCAL" ON)
option(ECAL_THIRDPARTY_BUILD_SPDLOG "Build spdlog with eCAL" ON)
option(ECAL_THIRDPARTY_BUILD_SIMPLEINI "Build simpleini with eCAL" ON)
Expand Down Expand Up @@ -223,6 +226,7 @@ set(possible_subprojects
GTest
HDF5
#libssh2
nanobind
Protobuf
qwt
recycle
Expand Down
7 changes: 7 additions & 0 deletions doc/rst/license/thirdparty_licenses.rst
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,13 @@ They are used by Eclipse eCAL, but not associated to it in any way.
- - |fa-file-alt| Copy in repository: :file:`/cpack/innosetup/modpath.iss`
- |fa-windows| Binary distributions for Windows (Installer only)

* - `nanobind <https://github.com/wjakob/nanobind>`_
- :ref:`bsd_3`
- 2022, Wenzel Jakob
- - |fa-github| Git submodule ``/tirdparty/nanobind``
- |fa-windows| Binary distributions for Windows
- |fa-ubuntu| Binary distributions for Linux

* - `npcap <https://nmap.org/npcap/>`_
- :ref:`npcap_license`
- 2013-2021 by Insecure.Com LLC
Expand Down
1 change: 1 addition & 0 deletions lang/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ else()
endif()

add_subdirectory(core)
add_subdirectory(nanobind_core)
if(HAS_HDF5)
add_subdirectory(ecalhdf5)
endif()
28 changes: 28 additions & 0 deletions lang/python/nanobind_core/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Try to import all Python components potentially needed by nanobind
find_package(Python
REQUIRED COMPONENTS Interpreter Development.Module
OPTIONAL_COMPONENTS Development.SABIModule)

# Import nanobind through CMake's find_package mechanism
find_package(nanobind CONFIG REQUIRED)

# We are now ready to compile the actual extension module
nanobind_add_module(
# Name of the extension
nanobind_core

# Target the stable ABI for Python 3.12+, which reduces
# the number of binary wheels that must be built. This
# does nothing on older Python versions
STABLE_ABI

# Source code goes here
main.cpp
)

# Install directive for scikit-build-core
install(TARGETS nanobind_core LIBRARY DESTINATION nanobind_core)

if(WIN32)
set_property(TARGET nanobind_core PROPERTY FOLDER lang/python/core)
endif()
5 changes: 5 additions & 0 deletions lang/python/nanobind_core/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include <nanobind/nanobind.h>

NB_MODULE(nanobind_core, m) {
m.def("hello", []() { return "Hello world!"; });
}
1 change: 1 addition & 0 deletions thirdparty/nanobind/Modules/Findnanobind.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
set(nanobind_FOUND TRUE)
10 changes: 10 additions & 0 deletions thirdparty/nanobind/build-nanobind.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
message(STATUS "building nanobind")

if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.25.0")
add_subdirectory(thirdparty/nanobind/nanobind EXCLUDE_FROM_ALL SYSTEM)
else ()
add_subdirectory(thirdparty/nanobind/nanobind EXCLUDE_FROM_ALL)
endif ()


list(PREPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/Modules)
1 change: 1 addition & 0 deletions thirdparty/nanobind/nanobind
Submodule nanobind added at df8996

0 comments on commit ff9a33e

Please sign in to comment.