Commit cb6dd354 authored by Patrik Huber's avatar Patrik Huber

Added infrastructure to generate Python bindings

- Added a flag GENERATE_PYTHON_BINDINGS to CMake which enables the use of pybind11
- `create-python-bindings` generates bindings for PcaModel
- pybind11 is added as a submodule; needs to be cloned with `git submodule update --init`
- Increased cmake_minimum_required to 2.8.12 for pybind11
parent 43dcb3d4
project(eos) project(eos)
cmake_minimum_required(VERSION 2.8.10) cmake_minimum_required(VERSION 2.8.12)
set(eos_VERSION_MAJOR 0) set(eos_VERSION_MAJOR 0)
set(eos_VERSION_MINOR 7) set(eos_VERSION_MINOR 7)
set(eos_VERSION_PATCH 1) set(eos_VERSION_PATCH 1)
...@@ -58,6 +58,8 @@ option(BUILD_UTILS "Build utility applications." OFF) ...@@ -58,6 +58,8 @@ option(BUILD_UTILS "Build utility applications." OFF)
message(STATUS "BUILD_UTILS: ${BUILD_UTILS}") message(STATUS "BUILD_UTILS: ${BUILD_UTILS}")
option(BUILD_DOCUMENTATION "Build the library documentation." OFF) option(BUILD_DOCUMENTATION "Build the library documentation." OFF)
message(STATUS "BUILD_DOCUMENTATION: ${BUILD_DOCUMENTATION}") message(STATUS "BUILD_DOCUMENTATION: ${BUILD_DOCUMENTATION}")
option(GENERATE_PYTHON_BINDINGS "Build python bindings. Needs BUILD_UTILS enabled too." OFF)
message(STATUS "GENERATE_PYTHON_BINDINGS: ${GENERATE_PYTHON_BINDINGS}")
# Build a CPack driven installer package: # Build a CPack driven installer package:
include(InstallRequiredSystemLibraries) # This module will include any runtime libraries that are needed by the project for the current platform include(InstallRequiredSystemLibraries) # This module will include any runtime libraries that are needed by the project for the current platform
...@@ -140,6 +142,13 @@ source_group(fitting\\detail include/eos/fitting/detail/*) ...@@ -140,6 +142,13 @@ source_group(fitting\\detail include/eos/fitting/detail/*)
source_group(render include/eos/render/*) source_group(render include/eos/render/*)
source_group(render\\detail include/eos/render/detail/*) source_group(render\\detail include/eos/render/detail/*)
# Generate python bindings using pybind11:
if(GENERATE_PYTHON_BINDINGS)
set(PYBIND11_PATH "${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/pybind11")
add_subdirectory(${PYBIND11_PATH})
# If this fails, the repo has probably not been cloned with submodules. Run: git submodule update --init
endif()
# The install target: # The install target:
install(DIRECTORY ${CMAKE_SOURCE_DIR}/include/ DESTINATION include) # our library headers install(DIRECTORY ${CMAKE_SOURCE_DIR}/include/ DESTINATION include) # our library headers
install(DIRECTORY ${CMAKE_SOURCE_DIR}/share/ DESTINATION share) # the model and metadata install(DIRECTORY ${CMAKE_SOURCE_DIR}/share/ DESTINATION share) # the model and metadata
......
...@@ -25,3 +25,4 @@ ...@@ -25,3 +25,4 @@
set(BUILD_EXAMPLES ON CACHE BOOL "Build the example applications." FORCE) set(BUILD_EXAMPLES ON CACHE BOOL "Build the example applications." FORCE)
set(BUILD_UTILS OFF CACHE BOOL "Build utility applications." FORCE) set(BUILD_UTILS OFF CACHE BOOL "Build utility applications." FORCE)
set(BUILD_DOCUMENTATION OFF CACHE BOOL "Build the library documentation." FORCE) set(BUILD_DOCUMENTATION OFF CACHE BOOL "Build the library documentation." FORCE)
set(GENERATE_PYTHON_BINDINGS OFF CACHE BOOL "Build python bindings. Needs BUILD_UTILS enabled too." FORCE)
project(utils) project(utils)
cmake_minimum_required(VERSION 2.8.10) cmake_minimum_required(VERSION 2.8.12)
# The utils need a few additional dependencies (e.g. boost filesystem and OpenCV highgui): # The utils need a few additional dependencies (e.g. boost filesystem and OpenCV highgui):
...@@ -41,6 +41,13 @@ target_link_libraries(scm-to-cereal ${OpenCV_LIBS} ${Boost_LIBRARIES}) ...@@ -41,6 +41,13 @@ target_link_libraries(scm-to-cereal ${OpenCV_LIBS} ${Boost_LIBRARIES})
# Store a json file as cereal .bin: # Store a json file as cereal .bin:
add_executable(json-to-cereal-binary json-to-cereal-binary.cpp) add_executable(json-to-cereal-binary json-to-cereal-binary.cpp)
target_link_libraries(json-to-cereal-binary ${OpenCV_LIBS} ${Boost_LIBRARIES}) target_link_libraries(json-to-cereal-binary ${OpenCV_LIBS} ${Boost_LIBRARIES})
# Generate python bindings using pybind11:
if(GENERATE_PYTHON_BINDINGS)
pybind11_add_module(eos_py create-python-bindings.cpp)
target_link_libraries(eos_py PRIVATE ${OpenCV_LIBS} ${Boost_LIBRARIES})
install(TARGETS eos_py DESTINATION bin)
endif()
# install target: # install target:
install(TARGETS scm-to-cereal DESTINATION bin) install(TARGETS scm-to-cereal DESTINATION bin)
install(TARGETS json-to-cereal-binary DESTINATION bin) install(TARGETS json-to-cereal-binary DESTINATION bin)
/*
* eos - A 3D Morphable Model fitting library written in modern C++11/14.
*
* File: utils/create-python-bindings.cpp
*
* Copyright 2016 Patrik Huber
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "eos/morphablemodel/PcaModel.hpp"
#include "pybind11/pybind11.h"
namespace py = pybind11;
/**
* Create python bindings for the eos library using pybind11.
*/
PYBIND11_PLUGIN(eos_py) {
py::module m("eos_py", "Python bindings to the 3D Morphable Face Model fitting library");
py::class_<eos::morphablemodel::PcaModel>(m, "PcaModel")
.def(py::init<>())
.def("get_mean_at_point", &eos::morphablemodel::PcaModel::get_mean_at_point);
return m.ptr();
};
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment