Skip to content

Commit 849093e

Browse files
committed
Update Python retrieval for newer cmake versions, update eror message and status logging
1 parent 75deb42 commit 849093e

File tree

2 files changed

+107
-51
lines changed

2 files changed

+107
-51
lines changed

CMakeLists.txt

+70-49
Original file line numberDiff line numberDiff line change
@@ -272,71 +272,82 @@ if(NOT IOS)
272272
# Make sure to refresh the python interpreter every time we rerun cmake
273273
# If we don't do this, we may use an old or invalid python when installing the bindings
274274
# that was cached by a previous attempt at building
275+
if(CMAKE_VERSION VERSION_LESS "3.15.0")
276+
set(PYTHON3_CACHE_LIST
277+
PYTHON3INTERP_FOUND PYTHONINTERP_FOUND PYTHONLIBS_FOUND PYTHON_FOUND
278+
PYTHON3_EXECUTABLE PYTHON_EXECUTABLE
279+
)
280+
foreach (_variableName ${PYTHON3_CACHE_LIST})
281+
unset(${_variableName} CACHE)
282+
endforeach()
283+
include(cmake/VISPDetectPython.cmake)
284+
else()
285+
set(PYTHON3_CACHE_LIST
286+
Python3_FOUND Python3_EXECUTABLE Python3_Interpreter_FOUND Python3_LIBRARIES
287+
_Python3_EXECUTABLE _Python3_INCLUDE_DIR _Python3_INTERPRETER_PROPERTIES _Python3_LIBRARY_RELEASE
288+
)
289+
foreach (_variableName ${PYTHON3_CACHE_LIST})
290+
unset(${_variableName} CACHE)
291+
endforeach()
292+
# Find strategy
293+
set(Python3_FIND_REGISTRY LAST)
294+
set(Python3_FIND_VIRTUALENV FIRST)
295+
set(Python3_FIND_STRATEGY LOCATION)
296+
find_package (Python3 COMPONENTS Interpreter Development)
297+
298+
# Alias variables to be consistent with previous detection method
299+
set(PYTHON3_FOUND ${Python3_FOUND})
300+
set(PYTHON3_EXECUTABLE ${Python3_EXECUTABLE})
301+
set(PYTHON_DEFAULT_EXECUTABLE ${PYTHON3_EXECUTABLE})
302+
set(PYTHON3INTERP_FOUND ${Python3_Interpreter_FOUND})
303+
set(PYTHON3_VERSION_STRING ${Python3_VERSION})
304+
endif()
305+
endif()
275306

307+
# --- Python Bindings requirements ---
308+
VP_OPTION(USE_PYBIND11 pybind11 QUIET "Include pybind11 to create Python bindings" "" ON)
276309

277-
# # this avoids non-active conda from getting picked anyway on Windows
278-
# set(Python_FIND_REGISTRY LAST)
279-
# set(Python_FIND_VIRTUALENV FIRST)
280-
# set(Python_FIND_STRATEGY LOCATION)
281-
unset(PYTHON3INTERP_FOUND CACHE)
282-
unset(PYTHONINTERP_FOUND CACHE)
283-
unset(PYTHON3INTERP_FOUND)
284-
unset(PYTHONLIBS_FOUND CACHE)
285-
unset(PYTHONINTERP_FOUND)
286-
unset(PYTHON_FOUND CACHE)
287-
unset(PYTHON3_EXECUTABLE CACHE)
288-
unset(PYTHON_EXECUTABLE CACHE)
289-
unset(PYTHON3_EXECUTABLE)
290-
unset(PYTHON_EXECUTABLE)
291-
unset(VISP_PYTHON_IS_SYSTEM_WIDE CACHE)
292-
unset(VISP_PYTHON3_VERSION CACHE)
293-
include(cmake/VISPDetectPython.cmake)
294-
endif()
295-
296-
if(CMAKE_VERSION VERSION_LESS "3.19.0")
310+
# Minimum tool versions
311+
set(CMAKE_MINIMUM_VERSION_PYTHON_BINDINGS "3.19.0")
312+
set(PYTHON3_MINIMUM_VERSION_PYTHON_BINDINGS "3.7.0")
313+
if(CMAKE_VERSION VERSION_LESS ${CMAKE_MINIMUM_VERSION_PYTHON_BINDINGS})
297314
set(CMAKE_NOT_OK_FOR_BINDINGS TRUE)
315+
message(STATUS "Required CMake version for Python bindings is ${CMAKE_MINIMUM_VERSION_PYTHON_BINDINGS},
316+
but you have ${CMAKE_VERSION}.
317+
Python bindings generation will be deactivated.
318+
")
298319
else()
299320
set(CMAKE_NOT_OK_FOR_BINDINGS FALSE)
300321
endif()
301322

302-
if(CMAKE_NOT_OK_FOR_BINDINGS)
303-
status("CMake version required for Python bindings is 3.19.0, but you have ${CMAKE_VERSION}. Python bindings generation will be deactivated")
323+
if(PYTHON3_VERSION_STRING VERSION_LESS ${PYTHON3_MINIMUM_VERSION_PYTHON_BINDINGS})
324+
set(PYTHON3_NOT_OK_FOR_BINDINGS TRUE)
325+
message(STATUS "Required Python version for Python bindings is ${PYTHON3_MINIMUM_VERSION_PYTHON_BINDINGS},
326+
but you have ${PYTHON3_VERSION_STRING}.
327+
Python bindings generation will be deactivated.
328+
")
329+
else()
330+
set(PYTHON3_NOT_OK_FOR_BINDINGS FALSE)
304331
endif()
305332

333+
# Forbid system Python
306334
if(DEFINED ENV{VIRTUAL_ENV} OR DEFINED ENV{CONDA_PREFIX})
307335
set(_pip_args)
308336
set(VISP_PYTHON_IS_SYSTEM_WIDE FALSE)
309337
else()
310338
# First solution: raise an error when cmake will call pip install
311339
# set(_pip_args "--require-virtualenv") # If this is a system python, throw an error
312-
message(WARNING "\
313-
The python version that you are using (${PYTHON3_EXECUTABLE}) is the system interpreter.
314-
pip packages should not be installed system-wide!
315-
Python bindings targets will be deactivated!
316-
To reenable them, install conda or virtualenv, delete the CMakeCache file then rerun cmake when inside the virtual environment.
317-
")
318-
set(VISP_PYTHON_IS_SYSTEM_WIDE TRUE)
340+
if(PYTHON3_FOUND)
341+
message(STATUS "The python version that you are using (${PYTHON3_EXECUTABLE}) is the system interpreter.
342+
pip packages should not be installed system-wide!
343+
Python bindings targets will be deactivated!
344+
To reenable them, install conda or virtualenv,
345+
delete the CMakeCache file then rerun cmake when inside the virtual environment.
346+
")
347+
set(VISP_PYTHON_IS_SYSTEM_WIDE TRUE)
348+
endif()
319349
endif()
320350

321-
# --- Python Bindings requirements ---
322-
323-
# this avoids non-active conda from getting picked anyway on Windows
324-
#set(Python_FIND_REGISTRY LAST)
325-
# Use environment variable PATH to decide preference for Python
326-
#set(Python_FIND_VIRTUALENV FIRST)
327-
#set(Python_FIND_STRATEGY LOCATION)
328-
329-
#find_package(Python 3.7 COMPONENTS Interpreter Development) # TODO: use visp function to find python?
330-
#if(Python_FOUND)
331-
# set(VISP_PYTHON_BINDINGS_EXECUTABLE "${Python_EXECUTABLE}")
332-
#endif()
333-
#find_package(pybind11)
334-
VP_OPTION(USE_PYBIND11 pybind11 QUIET "Include pybind11 to create Python bindings" "" ON)
335-
336-
#if(pybind11_FOUND)
337-
# set(VISP_PYBIND11_DIR "${pybind11_DIR}")
338-
#endif()
339-
#message("${pybind11_FOUND}")
340351
# ---
341352

342353

@@ -482,7 +493,7 @@ VP_OPTION(BUILD_ANDROID_EXAMPLES "" "" "Build examples for Android platform"
482493
VP_OPTION(INSTALL_ANDROID_EXAMPLES "" "" "Install Android examples" "" OFF IF ANDROID )
483494

484495
# Build python bindings as an option
485-
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) )
496+
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) )
486497
VP_OPTION(BUILD_PYTHON_BINDINGS_DOC "" "" "Build the documentation for the Python bindings" "" ON IF BUILD_PYTHON_BINDINGS )
487498

488499

@@ -1583,8 +1594,18 @@ if(BUILD_PYTHON_BINDINGS)
15831594
status(" Package version:" "${VISP_PYTHON_PACKAGE_VERSION}")
15841595
status(" Wrapped modules:" "${VISP_PYTHON_BOUND_MODULES}")
15851596
status(" Generated input config:" "${VISP_PYTHON_GENERATED_CONFIG_FILE}")
1597+
else()
1598+
status(" Requirements: ")
1599+
status(" Python version > ${PYTHON3_MINIMUM_VERSION_PYTHON_BINDINGS}:" PYTHON3_FOUND AND NOT PYTHON3_NOT_OK_FOR_BINDINGS THEN "ok (ver ${PYTHON3_VERSION_STRING})" ELSE "python not found or too old (${PYTHON3_VERSION_STRING})")
1600+
status(" Python in Virtual environment or conda:" VISP_PYTHON_IS_SYSTEM_WIDE THEN "failed" ELSE "ok")
1601+
status(" Pybind11 found:" USE_PYBIND11 THEN "ok" ELSE "failed")
1602+
status(" CMake > ${CMAKE_MINIMUM_VERSION_PYTHON_BINDINGS}:" CMAKE_NOT_OK_FOR_BINDINGS THEN "failed (${CMAKE_VERSION})" ELSE "ok (${CMAKE_VERSION})")
1603+
1604+
1605+
15861606
endif()
15871607

1608+
15881609
# ============================ Options ===========================
15891610
status("")
15901611
status(" Build options: ")

modules/python/config/core.json

+37-2
Original file line numberDiff line numberDiff line change
@@ -735,11 +735,48 @@
735735
"param_is_input": [true,true,false,false],
736736
"param_is_output": [false,false,true,true]
737737
},
738+
{
739+
"static": true,
740+
"signature": "void convertEllipse(const vpCameraParameters&, const vpCircle&, vpImagePoint&, double&, double&, double&)",
741+
"use_default_param_policy": false,
742+
"param_is_input": [
743+
true, true, true, true, true, true
744+
],
745+
"param_is_output": [
746+
false, false, false, true, true, true
747+
]
748+
},
749+
{
750+
"static": true,
751+
"signature": "void convertEllipse(const vpCameraParameters&, double, double, double, double, double, vpImagePoint&, double&, double&, double&)",
752+
"use_default_param_policy": false,
753+
"param_is_input": [
754+
true, true, true, true, true, true, true, false, false, false
755+
],
756+
"param_is_output": [
757+
false, false, false, false, false, false, false, true, true, true
758+
]
759+
},
738760
{
739761
"static": true,
740762
"signature": "void convertEllipse(const cv::Mat&, const cv::Mat&, const vpImagePoint&, double, double, double, double&, double&, double&, double&, double&)",
741763
"ignore": true
742764
},
765+
{
766+
"static": true,
767+
"signature": "void convertEllipse(const cv::Mat&, double, double, double, double, double, vpImagePoint&, double&, double&, double&)",
768+
"ignore": true
769+
},
770+
{
771+
"static": true,
772+
"signature": "void convertEllipse(const cv::Mat&, const vpCircle&, vpImagePoint&, double&, double&, double&)",
773+
"ignore": true
774+
},
775+
{
776+
"static": true,
777+
"signature": "void convertEllipse(const cv::Mat&, const vpSphere&, vpImagePoint&, double&, double&, double&)",
778+
"ignore": true
779+
},
743780
{
744781
"static": true,
745782
"signature": "void convertLine(const cv::Mat&, const double&, const double&, double&, double&)",
@@ -768,7 +805,5 @@
768805
}
769806
]
770807
}
771-
772808
}
773-
774809
}

0 commit comments

Comments
 (0)