浏览代码

Used C++ to integrate with Cython

Adam Kelly 5 年之前
父节点
当前提交
a96845b0f2
共有 4 个文件被更改,包括 18 次插入8 次删除
  1. 1 1
      CMakeLists.txt
  2. 11 0
      src/library.cpp
  3. 1 5
      tangle/CMakeLists.txt
  4. 5 2
      tangle/_tangle.pyx

+ 1 - 1
CMakeLists.txt

@@ -1,7 +1,7 @@
 cmake_minimum_required(VERSION 3.9)
 project(tangle)
 
-# Source for the command line tool
+set(TANGLE_SRC_DIR "${PROJECT_SOURCE_DIR}/src")
 set(CLI_MAIN "${PROJECT_SOURCE_DIR}/extras/simulator_cli.cpp")
 
 if(SKBUILD) # Using Python

+ 11 - 0
src/library.cpp

@@ -0,0 +1,11 @@
+#include <iostream>
+
+namespace Tangle
+{
+
+void say_hello()
+{
+    std::cout << "Pretty Tangled Here" << std::endl;
+}
+
+} // namespace Tangle

+ 1 - 5
tangle/CMakeLists.txt

@@ -2,13 +2,9 @@ find_package(PythonExtensions REQUIRED)
 find_package(Cython REQUIRED)
 
 
-# add_library(_tangle MODULE _tangle.cpp)
-# python_extension_module(_tangle)
-# install(TARGETS _tangle LIBRARY DESTINATION tangle)
-
-# add_cython_target(${PROJECT_SOURCE_DIR}/tangle/_tangle.pyx)
 add_cython_target(_tangle.pyx CXX)
 add_library(_tangle MODULE ${_tangle})
+target_include_directories(_tangle PRIVATE ${TANGLE_SRC_DIR})
 python_extension_module(_tangle)
 
 install(TARGETS _tangle LIBRARY DESTINATION tangle)

+ 5 - 2
tangle/_tangle.pyx

@@ -1,2 +1,5 @@
-cpdef say_hi ():
-    print("Hello World")
+cdef extern from "library.cpp" namespace "Tangle":
+    cdef void say_hello()
+
+def say_hi():
+    return say_hello()