Skip to content

Commit

Permalink
Add check for cxx standard, add VISP_EXPORT macro in front of generat…
Browse files Browse the repository at this point in the history
…ed code
  • Loading branch information
SamFlt committed Feb 13, 2024
1 parent e660431 commit e5af3cc
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 23 deletions.
13 changes: 10 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,14 @@ if(PYTHON3_VERSION_STRING VERSION_LESS ${PYTHON3_MINIMUM_VERSION_PYTHON_BINDINGS
else()
set(PYTHON3_NOT_OK_FOR_BINDINGS FALSE)
endif()
if(VISP_CXX_STANDARD LESS VISP_CXX_STANDARD_17)
set(CXX_STANDARD_NOT_OK_FOR_BINDINGS TRUE)
message(STATUS "Required C++ standard is C++17, but you have ${VISP_CXX_STANDARD}")
else()
set(CXX_STANDARD_NOT_OK_FOR_BINDINGS FALSE)
endif()



# Forbid system Python
if(DEFINED ENV{VIRTUAL_ENV} OR DEFINED ENV{CONDA_PREFIX})
Expand Down Expand Up @@ -493,7 +501,7 @@ VP_OPTION(BUILD_ANDROID_EXAMPLES "" "" "Build examples for Android platform"
VP_OPTION(INSTALL_ANDROID_EXAMPLES "" "" "Install Android examples" "" OFF IF ANDROID )

# Build python bindings as an option
VP_OPTION(BUILD_PYTHON_BINDINGS "" "" "Build Python bindings" "" ON IF (PYTHON3INTERP_FOUND AND USE_PYBIND11 AND NOT CMAKE_NOT_OK_FOR_BINDINGS AND NOT VISP_PYTHON_IS_SYSTEM_WIDE AND NOT PYTHON3_NOT_OK_FOR_BINDINGS) )
VP_OPTION(BUILD_PYTHON_BINDINGS "" "" "Build Python bindings" "" ON IF (PYTHON3INTERP_FOUND AND USE_PYBIND11 AND NOT CMAKE_NOT_OK_FOR_BINDINGS AND NOT VISP_PYTHON_IS_SYSTEM_WIDE AND NOT PYTHON3_NOT_OK_FOR_BINDINGS AND NOT CXX_STANDARD_NOT_OK_FOR_BINDINGS) )
VP_OPTION(BUILD_PYTHON_BINDINGS_DOC "" "" "Build the documentation for the Python bindings" "" ON IF BUILD_PYTHON_BINDINGS )


Expand Down Expand Up @@ -1655,8 +1663,7 @@ else()
status(" Python in Virtual environment or conda:" VISP_PYTHON_IS_SYSTEM_WIDE THEN "failed" ELSE "ok")
status(" Pybind11 found:" USE_PYBIND11 THEN "ok" ELSE "failed")
status(" CMake > ${CMAKE_MINIMUM_VERSION_PYTHON_BINDINGS}:" CMAKE_NOT_OK_FOR_BINDINGS THEN "failed (${CMAKE_VERSION})" ELSE "ok (${CMAKE_VERSION})")


status(" C++ standard > ${VISP_CXX_STANDARD_17}:" CXX_STANDARD_NOT_OK_FOR_BINDINGS THEN "failed (${VISP_CXX_STANDARD})" ELSE "ok (${VISP_CXX_STANDARD})")

endif()

Expand Down
4 changes: 2 additions & 2 deletions modules/python/bindings/include/blob.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <pybind11/numpy.h>

#include <visp3/core/vpConfig.h>
#include <visp3/blob/vpDot2.h>
#include <optional>

namespace py = pybind11;

void bindings_vpDot2(py::class_<vpDot2, vpTracker> &pyDot2)
VISP_EXPORT void bindings_vpDot2(py::class_<vpDot2, vpTracker> &pyDot2)
{
pyDot2.def_static("defineDots", [](std::vector<vpDot2> &dots,
const std::string &dotFile,
Expand Down
15 changes: 8 additions & 7 deletions modules/python/bindings/include/core/arrays.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include <pybind11/stl.h>
#include <pybind11/numpy.h>

#include <visp3/core/vpConfig.h>
#include <visp3/core/vpArray2D.h>
#include <visp3/core/vpColVector.h>
#include <visp3/core/vpHomogeneousMatrix.h>
Expand Down Expand Up @@ -173,7 +174,7 @@ const char *numpy_fn_doc_nonwritable = R"doc(
)doc";

template<typename T>
void bindings_vpArray2D(py::class_<vpArray2D<T>> &pyArray2D)
VISP_EXPORT void bindings_vpArray2D(py::class_<vpArray2D<T>> &pyArray2D)
{
pyArray2D.def_buffer(&get_buffer_info<T, vpArray2D>);

Expand All @@ -197,7 +198,7 @@ Construct a 2D ViSP array by **copying** a 2D numpy array.
define_get_item_2d_array<py::class_<vpArray2D<T>>, vpArray2D<T>, T>(pyArray2D);
}

void bindings_vpMatrix(py::class_<vpMatrix, vpArray2D<double>> &pyMatrix)
VISP_EXPORT void bindings_vpMatrix(py::class_<vpMatrix, vpArray2D<double>> &pyMatrix)
{
pyMatrix.def_buffer(&get_buffer_info<vpMatrix>);

Expand All @@ -222,7 +223,7 @@ Construct a matrix by **copying** a 2D numpy array.
}


void bindings_vpRotationMatrix(py::class_<vpRotationMatrix, vpArray2D<double>> &pyRotationMatrix)
VISP_EXPORT void bindings_vpRotationMatrix(py::class_<vpRotationMatrix, vpArray2D<double>> &pyRotationMatrix)
{

pyRotationMatrix.def_buffer(&get_buffer_info<vpRotationMatrix>);
Expand All @@ -249,7 +250,7 @@ If it is not a rotation matrix, an exception will be raised.
define_get_item_2d_array<py::class_<vpRotationMatrix, vpArray2D<double>>, vpRotationMatrix, double>(pyRotationMatrix);
}

void bindings_vpHomogeneousMatrix(py::class_<vpHomogeneousMatrix, vpArray2D<double>> &pyHomogeneousMatrix)
VISP_EXPORT void bindings_vpHomogeneousMatrix(py::class_<vpHomogeneousMatrix, vpArray2D<double>> &pyHomogeneousMatrix)
{
pyHomogeneousMatrix.def_buffer(get_buffer_info<vpHomogeneousMatrix>);
pyHomogeneousMatrix.def("numpy", [](vpHomogeneousMatrix &self) -> np_array_cf<double> {
Expand Down Expand Up @@ -278,7 +279,7 @@ If it is not a homogeneous matrix, an exception will be raised.



void bindings_vpTranslationVector(py::class_<vpTranslationVector, vpArray2D<double>> &pyTranslationVector)
VISP_EXPORT void bindings_vpTranslationVector(py::class_<vpTranslationVector, vpArray2D<double>> &pyTranslationVector)
{
pyTranslationVector.def_buffer(&get_buffer_info<vpTranslationVector>);

Expand All @@ -303,7 +304,7 @@ Construct a Translation vector by **copying** a 1D numpy array of size 3.
}


void bindings_vpColVector(py::class_<vpColVector, vpArray2D<double>> &pyColVector)
VISP_EXPORT void bindings_vpColVector(py::class_<vpColVector, vpArray2D<double>> &pyColVector)
{
pyColVector.def_buffer(&get_buffer_info<vpColVector>);

Expand All @@ -327,7 +328,7 @@ Construct a column vector by **copying** a 1D numpy array.

}

void bindings_vpRowVector(py::class_<vpRowVector, vpArray2D<double>> &pyRowVector)
VISP_EXPORT void bindings_vpRowVector(py::class_<vpRowVector, vpArray2D<double>> &pyRowVector)
{
pyRowVector.def_buffer(&get_buffer_info<vpRowVector>);
pyRowVector.def("numpy", [](vpRowVector &self) -> np_array_cf<double> {
Expand Down
4 changes: 2 additions & 2 deletions modules/python/bindings/include/core/image_conversions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <pybind11/numpy.h>

#include <visp3/core/vpConfig.h>
#include <visp3/core/vpImageConvert.h>

namespace
Expand Down Expand Up @@ -177,7 +177,7 @@ unsigned size411(unsigned h, unsigned w)



void bindings_vpImageConvert(py::class_<vpImageConvert> &pyImageConvert)
VISP_EXPORT void bindings_vpImageConvert(py::class_<vpImageConvert> &pyImageConvert)
{
// Simple conversions where the size input is a single argument
{
Expand Down
8 changes: 4 additions & 4 deletions modules/python/bindings/include/core/images.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

#ifndef VISP_PYTHON_CORE_IMAGES_HPP
#define VISP_PYTHON_CORE_IMAGES_HPP

#include <visp3/core/vpConfig.h>
#include <visp3/core/vpImage.h>
#include <visp3/core/vpRGBf.h>
#include <pybind11/pybind11.h>
Expand Down Expand Up @@ -97,7 +97,7 @@ void define_get_item_2d_image(py::class_<vpImage<T>> &pyClass)
* vpImage
*/
template<typename T>
typename std::enable_if<std::is_fundamental<T>::value, void>::type
VISP_EXPORT typename std::enable_if<std::is_fundamental<T>::value, void>::type
bindings_vpImage(py::class_<vpImage<T>> &pyImage)
{
pyImage.def_buffer([](vpImage<T> &image) -> py::buffer_info {
Expand Down Expand Up @@ -137,7 +137,7 @@ Construct an image by **copying** a 2D numpy array.
}

template<typename T>
typename std::enable_if<std::is_same<vpRGBa, T>::value, void>::type
VISP_EXPORT typename std::enable_if<std::is_same<vpRGBa, T>::value, void>::type
bindings_vpImage(py::class_<vpImage<T>> &pyImage)
{
using NpRep = unsigned char;
Expand Down Expand Up @@ -181,7 +181,7 @@ where the 4 denotes the red, green, blue and alpha components of the image.

}
template<typename T>
typename std::enable_if<std::is_same<vpRGBf, T>::value, void>::type
VISP_EXPORT typename std::enable_if<std::is_same<vpRGBf, T>::value, void>::type
bindings_vpImage(py::class_<vpImage<T>> &pyImage)
{
using NpRep = float;
Expand Down
4 changes: 2 additions & 2 deletions modules/python/bindings/include/core/pixel_meter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

#include "core/utils.hpp"

void bindings_vpPixelMeterConversion(py::class_<vpPixelMeterConversion> &pyPM)
VISP_EXPORT void bindings_vpPixelMeterConversion(py::class_<vpPixelMeterConversion> &pyPM)
{
pyPM.def_static("convertPoints", [](const vpCameraParameters &cam, const py::array_t<double> &us, const py::array_t<double> &vs) {
py::buffer_info bufu = us.request(), bufv = vs.request();
Expand Down Expand Up @@ -106,7 +106,7 @@ Example usage:
)doc", py::arg("cam"), py::arg("us"), py::arg("vs"));
}

void bindings_vpMeterPixelConversion(py::class_<vpMeterPixelConversion> &pyMP)
VISP_EXPORT void bindings_vpMeterPixelConversion(py::class_<vpMeterPixelConversion> &pyMP)
{
pyMP.def_static("convertPoints", [](const vpCameraParameters &cam, const py::array_t<double> &xs, const py::array_t<double> &ys) {
py::buffer_info bufx = xs.request(), bufy = ys.request();
Expand Down
3 changes: 2 additions & 1 deletion modules/python/bindings/include/mbt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <pybind11/numpy.h>
#include <visp3/core/vpConfig.h>
#include <visp3/mbt/vpMbGenericTracker.h>

namespace py = pybind11;

void bindings_vpMbGenericTracker(py::class_<vpMbGenericTracker, vpMbTracker> &pyMbGenericTracker)
VISP_EXPORT void bindings_vpMbGenericTracker(py::class_<vpMbGenericTracker, vpMbTracker> &pyMbGenericTracker)
{
pyMbGenericTracker.def("track", [](vpMbGenericTracker &self, std::map<std::string, const vpImage<unsigned char> *> &mapOfImages,
std::map<std::string, py::array_t<double, py::array::c_style>> &mapOfPointClouds) {
Expand Down
3 changes: 2 additions & 1 deletion modules/python/generator/visp_python_bindgen/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def main_str(submodule_fn_declarations, submodule_fn_calls):
'''
return f'''
//#define PYBIND11_DETAILED_ERROR_MESSAGES
#include <visp3/core/vpConfig.h>
#include <pybind11/pybind11.h>
namespace py = pybind11;
{submodule_fn_declarations}
Expand Down Expand Up @@ -142,7 +143,7 @@ def generate_module(generate_path: Path, config_path: Path) -> None:
submodule_fn_calls = []
for submodule in submodules:
name = submodule.generation_function_name()
submodule_fn_declarations.append(f'void {name}(py::module_&);')
submodule_fn_declarations.append(f'VISP_EXPORT void {name}(py::module_&);')
submodule_fn_calls.append(f'{name}(m);')

submodule_fn_declarations = '\n'.join(submodule_fn_declarations)
Expand Down
2 changes: 1 addition & 1 deletion modules/python/generator/visp_python_bindgen/submodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def generate(self) -> None:
namespace py = pybind11;
void {self.generation_function_name()}(py::module_ &m) {{
VISP_EXPORT void {self.generation_function_name()}(py::module_ &m) {{
py::options options;
options.disable_enum_members_docstring();
Expand Down

0 comments on commit e5af3cc

Please sign in to comment.