@@ -272,71 +272,82 @@ if(NOT IOS)
272
272
# Make sure to refresh the python interpreter every time we rerun cmake
273
273
# If we don't do this, we may use an old or invalid python when installing the bindings
274
274
# 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 ()
275
306
307
+ # --- Python Bindings requirements ---
308
+ VP_OPTION(USE_PYBIND11 pybind11 QUIET "Include pybind11 to create Python bindings" "" ON )
276
309
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} )
297
314
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
+ " )
298
319
else ()
299
320
set (CMAKE_NOT_OK_FOR_BINDINGS FALSE )
300
321
endif ()
301
322
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 )
304
331
endif ()
305
332
333
+ # Forbid system Python
306
334
if (DEFINED ENV{VIRTUAL_ENV} OR DEFINED ENV{CONDA_PREFIX})
307
335
set (_pip_args)
308
336
set (VISP_PYTHON_IS_SYSTEM_WIDE FALSE )
309
337
else ()
310
338
# First solution: raise an error when cmake will call pip install
311
339
# 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 ()
319
349
endif ()
320
350
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}")
340
351
# ---
341
352
342
353
@@ -482,7 +493,7 @@ VP_OPTION(BUILD_ANDROID_EXAMPLES "" "" "Build examples for Android platform"
482
493
VP_OPTION(INSTALL_ANDROID_EXAMPLES "" "" "Install Android examples" "" OFF IF ANDROID )
483
494
484
495
# 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 ) )
486
497
VP_OPTION(BUILD_PYTHON_BINDINGS_DOC "" "" "Build the documentation for the Python bindings" "" ON IF BUILD_PYTHON_BINDINGS )
487
498
488
499
@@ -1583,8 +1594,18 @@ if(BUILD_PYTHON_BINDINGS)
1583
1594
status (" Package version:" "${VISP_PYTHON_PACKAGE_VERSION} " )
1584
1595
status (" Wrapped modules:" "${VISP_PYTHON_BOUND_MODULES} " )
1585
1596
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
+
1586
1606
endif ()
1587
1607
1608
+
1588
1609
# ============================ Options ===========================
1589
1610
status ("" )
1590
1611
status (" Build options: " )
0 commit comments