Modifications to compile with Python3, lest version of cmake and last
version of swig (2026-04-23) Modifications qui seront validées : modifié : CMakeLists.txt modifié : cmake/modules/OpenCVDetectPython.cmake modifié : src/java/CMakeLists.txt modifié : src/javascript/CMakeLists.txt modifié : src/python/python3/CMakeLists.txt
This commit is contained in:
@@ -1,6 +1,10 @@
|
|||||||
cmake_minimum_required (VERSION 3.22)
|
#cmake_minimum_required (VERSION 3.22)
|
||||||
|
cmake_minimum_required (VERSION 3.5)
|
||||||
project (mraa C)
|
project (mraa C)
|
||||||
|
|
||||||
|
cmake_policy(SET CMP0177 NEW)
|
||||||
|
#cmake_policy(SET CMP0148 NEW)
|
||||||
|
|
||||||
FIND_PACKAGE (Threads REQUIRED)
|
FIND_PACKAGE (Threads REQUIRED)
|
||||||
|
|
||||||
set (CMAKE_C_STANDARD 99)
|
set (CMAKE_C_STANDARD 99)
|
||||||
@@ -74,27 +78,28 @@ if (BUILDCPP)
|
|||||||
endif ()
|
endif ()
|
||||||
endforeach ()
|
endforeach ()
|
||||||
|
|
||||||
# This function adds the c++11 flag to a c++ target (if supported)
|
# This function adds the c++20 flag to a c++ target (if supported)
|
||||||
function(use_cxx_11 targetname)
|
function(use_cxx_20 targetname)
|
||||||
include(CheckCXXCompilerFlag)
|
include(CheckCXXCompilerFlag)
|
||||||
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
|
CHECK_CXX_COMPILER_FLAG("-std=c++20" COMPILER_SUPPORTS_CXX20)
|
||||||
if (COMPILER_SUPPORTS_CXX11)
|
if (COMPILER_SUPPORTS_CXX20)
|
||||||
set_target_properties(${targetname} PROPERTIES COMPILE_FLAGS "-std=c++11")
|
set_target_properties(${targetname} PROPERTIES COMPILE_FLAGS "-std=c++20")
|
||||||
|
message(STATUS "INFO Use std=c++20")
|
||||||
else()
|
else()
|
||||||
message(FATAL_ERROR "Target '${targetname}' requires c++11 which is not supported by this compiler")
|
message(FATAL_ERROR "Target '${targetname}' requires c++20 which is not supported by this compiler")
|
||||||
endif()
|
endif()
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
# This function adds the c++17 flag to a c++ target (if supported)
|
# # This function adds the c++17 flag to a c++ target (if supported)
|
||||||
function(use_cxx_17 targetname)
|
# function(use_cxx_17 targetname)
|
||||||
include(CheckCXXCompilerFlag)
|
# include(CheckCXXCompilerFlag)
|
||||||
CHECK_CXX_COMPILER_FLAG("-std=c++17" COMPILER_SUPPORTS_CXX17)
|
# CHECK_CXX_COMPILER_FLAG("-std=c++17" COMPILER_SUPPORTS_CXX17)
|
||||||
if (COMPILER_SUPPORTS_CXX17)
|
# if (COMPILER_SUPPORTS_CXX17)
|
||||||
set_target_properties(${targetname} PROPERTIES COMPILE_FLAGS "-std=c++17")
|
# set_target_properties(${targetname} PROPERTIES COMPILE_FLAGS "-std=c++17")
|
||||||
else()
|
# else()
|
||||||
message(FATAL_ERROR "Target '${targetname}' requires c++17 which is not supported by this compiler")
|
# message(FATAL_ERROR "Target '${targetname}' requires c++17 which is not supported by this compiler")
|
||||||
endif()
|
# endif()
|
||||||
endfunction()
|
# endfunction()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Set CMAKE_INSTALL_LIBDIR if not defined
|
# Set CMAKE_INSTALL_LIBDIR if not defined
|
||||||
@@ -158,17 +163,17 @@ option (BUILDDOC "Build all doc." OFF)
|
|||||||
option (BUILDSWIG "Build swig modules." ON)
|
option (BUILDSWIG "Build swig modules." ON)
|
||||||
option (BUILDSWIGPYTHON "Build swig python modules." ON)
|
option (BUILDSWIGPYTHON "Build swig python modules." ON)
|
||||||
option (BUILDSWIGNODE "Build swig node modules." OFF)
|
option (BUILDSWIGNODE "Build swig node modules." OFF)
|
||||||
option (BUILDSWIGJAVA "Build Java API." OFF)
|
option (BUILDSWIGJAVA "Build Java API." ON)
|
||||||
option (USBPLAT "Detection USB platform." OFF)
|
option (USBPLAT "Detection USB platform." OFF)
|
||||||
option (FIRMATA "Add Firmata support to mraa." OFF)
|
option (FIRMATA "Add Firmata support to mraa." OFF)
|
||||||
option (ONEWIRE "Add Onewire support to mraa." ON)
|
option (ONEWIRE "Add Onewire support to mraa." ON)
|
||||||
option (JSONPLAT "Add Platform loading via a json file." ON)
|
option (JSONPLAT "Add Platform loading via a json file." ON)
|
||||||
option (IMRAA "Add Imraa support to mraa." OFF)
|
option (IMRAA "Add Imraa support to mraa." OFF)
|
||||||
option (FTDI4222 "Build with FTDI FT4222 subplatform support." OFF)
|
option (FTDI4222 "Build with FTDI FT4222 subplatform support." OFF)
|
||||||
option (ENABLEEXAMPLES "Enable building of examples" ON)
|
option (ENABLEEXAMPLES "Enable building of examples" OFF)
|
||||||
option (INSTALLTOOLS "Install all tools" ON)
|
option (INSTALLTOOLS "Install all tools" ON)
|
||||||
option (BUILDTESTS "Override the addition of tests" ON)
|
option (BUILDTESTS "Override the addition of tests" ON)
|
||||||
option (USEPYTHON3TESTS "Force tests to run with python3" OFF)
|
option (USEPYTHON3TESTS "Force tests to run with python3" ON)
|
||||||
|
|
||||||
set (BUILDARCH "" CACHE STRING "Override architecture to build for")
|
set (BUILDARCH "" CACHE STRING "Override architecture to build for")
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,3 @@
|
|||||||
# From OpenCV Project
|
|
||||||
# SPDX-License-Identifier: BSD-3-Clause
|
|
||||||
#
|
|
||||||
# Find specified Python version
|
# Find specified Python version
|
||||||
# Arguments:
|
# Arguments:
|
||||||
# preferred_version (value): Version to check for first
|
# preferred_version (value): Version to check for first
|
||||||
@@ -22,36 +19,38 @@
|
|||||||
# include_dir (variable): Output of found Python include dir
|
# include_dir (variable): Output of found Python include dir
|
||||||
# include_dir2 (variable): Output of found Python include dir2
|
# include_dir2 (variable): Output of found Python include dir2
|
||||||
# packages_path (variable): Output of found Python packages path
|
# packages_path (variable): Output of found Python packages path
|
||||||
|
|
||||||
function(find_python preferred_version min_version library_env include_dir_env
|
function(find_python preferred_version min_version library_env include_dir_env
|
||||||
found executable version_string version_major version_minor
|
found executable version_string version_major version_minor
|
||||||
libs_found libs_version_string libraries library debug_libraries
|
libs_found libs_version_string libraries library debug_libraries
|
||||||
debug_library include_path include_dir include_dir2 packages_path)
|
debug_library include_path include_dir include_dir2 packages_path)
|
||||||
|
|
||||||
if(NOT ${found})
|
if(NOT ${found})
|
||||||
if(${executable})
|
if(${executable})
|
||||||
set(PYTHON_EXECUTABLE "${${executable}}")
|
set(Python3_EXECUTABLE "${${executable}}")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
find_package(PythonInterp "${preferred_version}")
|
find_package(Python3 "${preferred_version}" COMPONENTS Interpreter Development)
|
||||||
if(NOT PYTHONINTERP_FOUND)
|
if(NOT Python3_FOUND)
|
||||||
find_package(PythonInterp "${min_version}")
|
find_package(Python3 "${min_version}")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(PYTHONINTERP_FOUND)
|
if(Python3_FOUND)
|
||||||
# Copy outputs
|
# Copy outputs
|
||||||
set(_found ${PYTHONINTERP_FOUND})
|
set(_found ${Python3_FOUND})
|
||||||
set(_executable ${PYTHON_EXECUTABLE})
|
set(_executable ${Python3_EXECUTABLE})
|
||||||
set(_version_string ${PYTHON_VERSION_STRING})
|
set(_version_string ${ython3_VERSION})
|
||||||
set(_version_major ${PYTHON_VERSION_MAJOR})
|
set(_version_major ${Python3_VERSION_MAJOR})
|
||||||
set(_version_minor ${PYTHON_VERSION_MINOR})
|
set(_version_minor ${Python3_VERSION_MINOR})
|
||||||
set(_version_patch ${PYTHON_VERSION_PATCH})
|
set(_version_patch ${Python3_VERSION_PATCH})
|
||||||
|
|
||||||
# Clear find_host_package side effects
|
# Clear find_host_package side effects
|
||||||
unset(PYTHONINTERP_FOUND)
|
unset(Python3_FOUND)
|
||||||
unset(PYTHON_EXECUTABLE CACHE)
|
unset(Python3_EXECUTABLE CACHE)
|
||||||
unset(PYTHON_VERSION_STRING)
|
unset(Python3_VERSION_STRING)
|
||||||
unset(PYTHON_VERSION_MAJOR)
|
unset(Python3_VERSION_MAJOR)
|
||||||
unset(PYTHON_VERSION_MINOR)
|
unset(Python3_VERSION_MINOR)
|
||||||
unset(PYTHON_VERSION_PATCH)
|
unset(Python3_VERSION_PATCH)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(_found)
|
if(_found)
|
||||||
@@ -61,42 +60,42 @@ if(NOT ${found})
|
|||||||
# not using _version_string here, because it might not conform to the CMake version format
|
# not using _version_string here, because it might not conform to the CMake version format
|
||||||
if(CMAKE_CROSSCOMPILING)
|
if(CMAKE_CROSSCOMPILING)
|
||||||
# builder version can differ from target, matching base version (e.g. 2.7)
|
# builder version can differ from target, matching base version (e.g. 2.7)
|
||||||
find_package(PythonLibs "${_version_major_minor}")
|
find_package(Python "${_version_major_minor}" COMPONENTS Interpreter Development)
|
||||||
else()
|
else()
|
||||||
find_package(PythonLibs "${_version_major_minor}.${_version_patch}" EXACT)
|
find_package(Python "${_version_major_minor}.${_version_patch}" EXACT COMPONENTS Interpreter Development)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(PYTHONLIBS_FOUND)
|
if(Python_FOUND)
|
||||||
# Copy outputs
|
# Copy outputs
|
||||||
set(_libs_found ${PYTHONLIBS_FOUND})
|
set(_libs_found ${Python_Development_FOUND})
|
||||||
set(_libraries ${PYTHON_LIBRARIES})
|
set(_libraries ${Python_LIBRARIES})
|
||||||
set(_include_path ${PYTHON_INCLUDE_PATH})
|
set(_include_path ${Python_INCLUDE_DIR})
|
||||||
set(_include_dirs ${PYTHON_INCLUDE_DIRS})
|
set(_include_dirs ${Python_INCLUDE_DIRS})
|
||||||
set(_debug_libraries ${PYTHON_DEBUG_LIBRARIES})
|
set(_debug_libraries ${Python_LIBRARIES})
|
||||||
set(_libs_version_string ${PYTHONLIBS_VERSION_STRING})
|
set(_libs_version_string ${Python_VERSION})
|
||||||
set(_debug_library ${PYTHON_DEBUG_LIBRARY})
|
set(_debug_library ${Python_LIBRARY})
|
||||||
set(_library ${PYTHON_LIBRARY})
|
set(_library ${Python_LIBRARY})
|
||||||
set(_library_debug ${PYTHON_LIBRARY_DEBUG})
|
set(_library_debug ${Python_LIBRARY})
|
||||||
set(_library_release ${PYTHON_LIBRARY_RELEASE})
|
set(_library_release ${Python_LIBRARY})
|
||||||
set(_include_dir ${PYTHON_INCLUDE_DIR})
|
set(_include_dir ${Python_INCLUDE_DIR})
|
||||||
set(_include_dir2 ${PYTHON_INCLUDE_DIR2})
|
set(_include_dir2 ${Python_INCLUDE_DIR2})
|
||||||
|
|
||||||
# Clear find_package side effects
|
# Clear find_package side effects
|
||||||
unset(PYTHONLIBS_FOUND)
|
unset(Python_Development_FOUND)
|
||||||
unset(PYTHON_LIBRARIES)
|
unset(Python_LIBRARIES)
|
||||||
unset(PYTHON_INCLUDE_PATH)
|
unset(Python_INCLUDE_DIR)
|
||||||
unset(PYTHON_INCLUDE_DIRS)
|
unset(Python_INCLUDE_DIRS)
|
||||||
unset(PYTHON_DEBUG_LIBRARIES)
|
unset(Python_LIBRARIES)
|
||||||
unset(PYTHONLIBS_VERSION_STRING)
|
unset(Python_VERSION)
|
||||||
unset(PYTHON_DEBUG_LIBRARY CACHE)
|
unset(Python_LIBRARY CACHE)
|
||||||
unset(PYTHON_LIBRARY)
|
unset(Python_LIBRARY)
|
||||||
unset(PYTHON_LIBRARY_DEBUG)
|
unset(Python_LIBRARY_DEBUG)
|
||||||
unset(PYTHON_LIBRARY_RELEASE)
|
unset(Python_LIBRARY_RELEASE)
|
||||||
unset(PYTHON_LIBRARY CACHE)
|
unset(Python_LIBRARY CACHE)
|
||||||
unset(PYTHON_LIBRARY_DEBUG CACHE)
|
unset(Python_LIBRARY CACHE)
|
||||||
unset(PYTHON_LIBRARY_RELEASE CACHE)
|
unset(Python_LIBRARY CACHE)
|
||||||
unset(PYTHON_INCLUDE_DIR CACHE)
|
unset(Python_INCLUDE_DIR CACHE)
|
||||||
unset(PYTHON_INCLUDE_DIR2 CACHE)
|
unset(Python_INCLUDE_DIR2 CACHE)
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
@@ -138,26 +137,26 @@ endfunction(find_python)
|
|||||||
set(MIN_VER_PYTHON2 2.7)
|
set(MIN_VER_PYTHON2 2.7)
|
||||||
set(MIN_VER_PYTHON3 3.2)
|
set(MIN_VER_PYTHON3 3.2)
|
||||||
|
|
||||||
find_python(2.7 "${MIN_VER_PYTHON2}" PYTHON2_LIBRARY PYTHON2_INCLUDE_DIR
|
#find_python(2.7 "${MIN_VER_PYTHON2}" PYTHON2_LIBRARY PYTHON2_INCLUDE_DIR
|
||||||
PYTHON2INTERP_FOUND PYTHON2_EXECUTABLE PYTHON2_VERSION_STRING
|
# Python3_FOUND PYTHON2_EXECUTABLE PYTHON2_VERSION_STRING
|
||||||
PYTHON2_VERSION_MAJOR PYTHON2_VERSION_MINOR PYTHON2LIBS_FOUND
|
# PYTHON2_VERSION_MAJOR PYTHON2_VERSION_MINOR PYTHON2LIBS_FOUND
|
||||||
PYTHON2LIBS_VERSION_STRING PYTHON2_LIBRARIES PYTHON2_LIBRARY
|
# PYTHON2LIBS_VERSION_STRING PYTHON2_LIBRARIES PYTHON2_LIBRARY
|
||||||
PYTHON2_DEBUG_LIBRARIES PYTHON2_LIBRARY_DEBUG PYTHON2_INCLUDE_PATH
|
# PYTHON2_DEBUG_LIBRARIES PYTHON2_LIBRARY_DEBUG PYTHON2_INCLUDE_PATH
|
||||||
PYTHON2_INCLUDE_DIR PYTHON2_INCLUDE_DIR2 PYTHON2_PACKAGES_PATH)
|
# PYTHON2_INCLUDE_DIR PYTHON2_INCLUDE_DIR2 PYTHON2_PACKAGES_PATH)
|
||||||
|
|
||||||
find_python(3 "${MIN_VER_PYTHON3}" PYTHON3_LIBRARY PYTHON3_INCLUDE_DIR
|
find_python(3 "${MIN_VER_PYTHON3}" Python_LIBRARY Python_INCLUDE_DIR
|
||||||
PYTHON3INTERP_FOUND PYTHON3_EXECUTABLE PYTHON3_VERSION_STRING
|
Python3_FOUND Python3_EXECUTABLE Python3_VERSION
|
||||||
PYTHON3_VERSION_MAJOR PYTHON3_VERSION_MINOR PYTHON3LIBS_FOUND
|
Python3_VERSION_MAJOR Python3_VERSION_MINOR PYTHON3LIBS_FOUND
|
||||||
PYTHON3LIBS_VERSION_STRING PYTHON3_LIBRARIES PYTHON3_LIBRARY
|
Python_VERSION Python_LIBRARIES Python_LIBRARY
|
||||||
PYTHON3_DEBUG_LIBRARIES PYTHON3_LIBRARY_DEBUG PYTHON3_INCLUDE_PATH
|
PYTHON3_DEBUG_LIBRARIES PYTHON3_LIBRARY_DEBUG Python_INCLUDE_DIR
|
||||||
PYTHON3_INCLUDE_DIR PYTHON3_INCLUDE_DIR2 PYTHON3_PACKAGES_PATH)
|
Python_INCLUDE_DIR Python_INCLUDE_DIR2 PYTHON3_PACKAGES_PATH)
|
||||||
|
|
||||||
if(PYTHON_DEFAULT_EXECUTABLE)
|
if(PYTHON_DEFAULT_EXECUTABLE)
|
||||||
set(PYTHON_DEFAULT_AVAILABLE "TRUE")
|
set(PYTHON_DEFAULT_AVAILABLE "TRUE")
|
||||||
elseif(PYTHON3INTERP_FOUND) # Use Python 3 as default Python interpreter
|
elseif(Python3_FOUND) # Use Python 2 as default Python interpreter
|
||||||
set(PYTHON_DEFAULT_AVAILABLE "TRUE")
|
|
||||||
set(PYTHON_DEFAULT_EXECUTABLE "${PYTHON3_EXECUTABLE}")
|
|
||||||
elseif(PYTHON2INTERP_FOUND) # Use Python 2 as fallback Python interpreter (if there is no Python 3)
|
|
||||||
set(PYTHON_DEFAULT_AVAILABLE "TRUE")
|
set(PYTHON_DEFAULT_AVAILABLE "TRUE")
|
||||||
set(PYTHON_DEFAULT_EXECUTABLE "${PYTHON2_EXECUTABLE}")
|
set(PYTHON_DEFAULT_EXECUTABLE "${PYTHON2_EXECUTABLE}")
|
||||||
|
elseif(Python3_FOUND) # Use Python 2 as fallback Python interpreter (if there is no Python 2)
|
||||||
|
set(PYTHON_DEFAULT_AVAILABLE "TRUE")
|
||||||
|
set(PYTHON_DEFAULT_EXECUTABLE "${Python3_EXECUTABLE}")
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
@@ -38,7 +38,8 @@ if (CMAKE_VERSION VERSION_LESS "3.8")
|
|||||||
else ()
|
else ()
|
||||||
swig_add_library (mraajava LANGUAGE java SOURCES mraajava.i mraajni.c)
|
swig_add_library (mraajava LANGUAGE java SOURCES mraajava.i mraajni.c)
|
||||||
endif ()
|
endif ()
|
||||||
swig_link_libraries (mraajava ${JAVA_LIBRARIES} mraa)
|
#swig_link_libraries (mraajava ${JAVA_LIBRARIES} mraa)
|
||||||
|
target_link_libraries (mraajava ${JAVA_LIBRARIES} mraa)
|
||||||
|
|
||||||
add_custom_command (TARGET mraajava
|
add_custom_command (TARGET mraajava
|
||||||
POST_BUILD
|
POST_BUILD
|
||||||
|
|||||||
@@ -26,7 +26,8 @@ if (CMAKE_VERSION VERSION_LESS "3.8")
|
|||||||
else ()
|
else ()
|
||||||
swig_add_library (mraajs LANGUAGE javascript SOURCES mraajs.i)
|
swig_add_library (mraajs LANGUAGE javascript SOURCES mraajs.i)
|
||||||
endif ()
|
endif ()
|
||||||
swig_link_libraries (mraajs mraa)
|
#swig_link_libraries (mraajs mraa)
|
||||||
|
target_link_libraries (mraajs mraa)
|
||||||
|
|
||||||
set_target_properties (mraajs PROPERTIES
|
set_target_properties (mraajs PROPERTIES
|
||||||
COMPILE_FLAGS " -DBUILDING_NODE_EXTENSION -DSWIGJAVASCRIPT=${SWIG_FOUND}"
|
COMPILE_FLAGS " -DBUILDING_NODE_EXTENSION -DSWIGJAVASCRIPT=${SWIG_FOUND}"
|
||||||
|
|||||||
@@ -8,12 +8,13 @@ if (CMAKE_VERSION VERSION_LESS "3.8")
|
|||||||
else ()
|
else ()
|
||||||
swig_add_library (python3-mraa LANGUAGE python SOURCES mraa3.i ../mraapy.c)
|
swig_add_library (python3-mraa LANGUAGE python SOURCES mraa3.i ../mraapy.c)
|
||||||
endif ()
|
endif ()
|
||||||
swig_link_libraries (python3-mraa ${PYTHON3_LIBRARIES} mraa)
|
#swig_link_libraries (python3-mraa ${PYTHON3_LIBRARIES} mraa)
|
||||||
|
target_link_libraries (python3-mraa ${Python3_LIBRARIES} mraa)
|
||||||
|
|
||||||
target_include_directories(${SWIG_MODULE_python3-mraa_REAL_NAME}
|
target_include_directories(${SWIG_MODULE_python3-mraa_REAL_NAME}
|
||||||
PUBLIC
|
PUBLIC
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/../.."
|
"${CMAKE_CURRENT_SOURCE_DIR}/../.."
|
||||||
"${PYTHON3_INCLUDE_DIR}"
|
"${Python3_INCLUDE_DIR}"
|
||||||
)
|
)
|
||||||
|
|
||||||
if (DOXYGEN_FOUND AND PYTHON3_EXECUTABLE)
|
if (DOXYGEN_FOUND AND PYTHON3_EXECUTABLE)
|
||||||
|
|||||||
Reference in New Issue
Block a user