diff --git a/CMakeLists.txt b/CMakeLists.txt index 52e45fcf9..6f1338b87 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.4.1) -project(kompute VERSION 0.3.0) +project(kompute VERSION 0.4.2) set(CMAKE_CXX_STANDARD 14) @@ -13,6 +13,7 @@ option(KOMPUTE_OPT_BUILD_SHADERS "Enable if you want to re-build all shader file option(KOMPUTE_OPT_BUILD_SINGLE_HEADER "Enable if you want to build the single header file" 0) option(KOMPUTE_OPT_INSTALL "Enable if you want to enable installation" 0) # Build options +option(KOMPUTE_OPT_BUILD_PYTHON "Enable if you want to build python bindings" 0) option(KOMPUTE_OPT_ENABLE_SPDLOG "Extra compile flags for Kompute, see docs for full list" 0) option(KOMPUTE_OPT_REPO_SUBMODULE_BUILD, "Use the submodule repos instead of external package manager" 0) option(KOMPUTE_OPT_ANDOID_BUILD "Enable android compilation flags required" 0) @@ -43,12 +44,16 @@ endfunction() add_subdirectory(src) +if(KOMPUTE_OPT_BUILD_TESTS) + add_subdirectory(test) +endif() + if(KOMPUTE_OPT_BUILD_DOCS) set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/config" ${CMAKE_MODULE_PATH}) add_subdirectory(docs) endif() -if(KOMPUTE_OPT_BUILD_TESTS) - add_subdirectory(test) +if(KOMPUTE_OPT_BUILD_PYTHON) + add_subdirectory(python) endif() diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 31449ec1c..f0b4949ac 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -1,5 +1,4 @@ -cmake_minimum_required(VERSION 2.8.12) -project(cmake_example) add_subdirectory(pybind11) pybind11_add_module(cmake_example src/main.cpp) + diff --git a/python/src/main.cpp b/python/src/main.cpp index 86ab58210..1330bab19 100644 --- a/python/src/main.cpp +++ b/python/src/main.cpp @@ -1,36 +1,9 @@ #include - -int add(int i, int j) { - return i + j; -} +#include "kompute/Kompute.hpp" namespace py = pybind11; PYBIND11_MODULE(cmake_example, m) { - m.doc() = R"pbdoc( - Pybind11 example plugin - ----------------------- - - .. currentmodule:: cmake_example - - .. autosummary:: - :toctree: _generate - - add - subtract - )pbdoc"; - - m.def("add", &add, R"pbdoc( - Add two numbers - - Some other explanation about the add function. - )pbdoc"); - - m.def("subtract", [](int i, int j) { return i - j; }, R"pbdoc( - Subtract two numbers - - Some other explanation about the subtract function. - )pbdoc"); #ifdef VERSION_INFO m.attr("__version__") = VERSION_INFO; diff --git a/python/setup.py b/setup.py similarity index 95% rename from python/setup.py rename to setup.py index bd30b12b7..07d769b5b 100644 --- a/python/setup.py +++ b/setup.py @@ -38,6 +38,8 @@ class CMakeBuild(build_ext): extdir += os.path.sep cmake_args = ['-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + extdir, + '-DKOMPUTE_OPT_BUILD_PYTHON=1', + '-DKOMPUTE_OPT_BUILD_SINGLE_HEADER=1', '-DPYTHON_EXECUTABLE=' + sys.executable] cfg = 'Debug' if self.debug else 'Release' @@ -57,6 +59,7 @@ class CMakeBuild(build_ext): self.distribution.get_version()) if not os.path.exists(self.build_temp): os.makedirs(self.build_temp) + subprocess.check_call(['cmake', ext.sourcedir] + cmake_args, cwd=self.build_temp, env=env) subprocess.check_call(['cmake', '--build', '.'] + build_args, cwd=self.build_temp)