From d2bab3232d6a093b40fd26830c7d1c5a5ac58c1a Mon Sep 17 00:00:00 2001 From: ZtRXR Date: Fri, 28 Jun 2024 14:57:41 +0800 Subject: [PATCH] update --- .gitignore | 2 ++ CMakeLists.txt | 7 +++++++ make.py | 13 +++++++++++++ src/main.cpp | 17 +++++++++++++++++ 4 files changed, 39 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 make.py create mode 100644 src/main.cpp diff --git a/.gitignore b/.gitignore index e257658..0934ef9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +build +.vscode # ---> C++ # Prerequisites *.d diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..b8ca093 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 3.15) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) +project(test_pybind11 VERSION 1.0 DESCRIPTION "a default project" LANGUAGES CXX) +file(GLOB_RECURSE SRC src/*.cpp) +find_package(Python 3.12.3 COMPONENTS Interpreter Development REQUIRED) +find_package(pybind11 CONFIG REQUIRED) +pybind11_add_module(${PROJECT_NAME} ${SRC}) diff --git a/make.py b/make.py new file mode 100644 index 0000000..6fa97a6 --- /dev/null +++ b/make.py @@ -0,0 +1,13 @@ +from pymake import * + + +( + cmake("3.15") + .set(cmake_export_compile_commands, on) + .project("test_pybind11") + .file("SRC",glob_recurse,"src/*.cpp") + .just_add("""find_package(Python 3.12.3 COMPONENTS Interpreter Development REQUIRED)""") + .just_add("find_package(pybind11 CONFIG REQUIRED)") + .pybind11_add_module(var(project_name),var("SRC")) + .write() +) \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..3062176 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,17 @@ +#include +#include + +int add(int i, int j) { + return i + j; +} + +std::vector sort_num(std::vector array){ + std::sort(array.begin(),array.end()); + return array; +} + +PYBIND11_MODULE(test_pybind11, m) { + m.doc() = "pybind11 example plugin"; // optional module docstring + m.def("sort_num",&sort_num,"A function to sort INT numbers"); + m.def("add", &add, "A function that adds two numbers"); +} \ No newline at end of file