mirror of
https://github.com/eclipse/upm.git
synced 2025-07-01 09:21:12 +03:00
python: Build both python2 and python3 modules
Updated UPM cmake to build both python2/3 modules if the necessary python libs are available. * Removed BUILDPYTHON3 cmake option in favor of building both versions * Added cmake module to find both python2 and python3 * Added macro which can be called from per-sensor cmake files to add dependency libraries via target_link_libraries as well as swig_link_libraries (for java, nodejs, and python) * Python2 is required for python documentation builds * Cleanup of python usage throughout UPM cmakelists. * Make find_package for Node required. Removed check for NODE_FOUND (which should have been NODEJS_FOUND) in favor of REQUIRED. * The cxx and .py wrapper files get generated in python2/3 (instead of the same directory). It appears these files are identical, however since the targets can be built in parallel it's safer to split them out. * Updated all cmake dependencies related to building documentation. * Removed unused classname from cmake files Signed-off-by: Noel Eck <noel.eck@intel.com>
This commit is contained in:
127
CMakeLists.txt
127
CMakeLists.txt
@ -8,7 +8,6 @@ option (BUILDFTI "Build Funtion Table Interface (FTI) in C sensor libraries" OFF
|
||||
option (BUILDSWIGPYTHON "Build swig python modules" ON)
|
||||
option (BUILDSWIGNODE "Build swig node modules" ON)
|
||||
option (BUILDSWIGJAVA "Build swig java modules" OFF)
|
||||
option (BUILDPYTHON3 "Use python3 for building/installing/testing" OFF)
|
||||
option (BUILDEXAMPLES "Build C/C++ example binaries" OFF)
|
||||
option (BUILDJAVAEXAMPLES "Build java example jars" OFF)
|
||||
option (IPK "Generate IPK using CPack" OFF)
|
||||
@ -44,12 +43,38 @@ pkg_check_modules (OPENZWAVE libopenzwave)
|
||||
# Find JPEG
|
||||
find_package (JPEG)
|
||||
|
||||
# Find nodejs
|
||||
if (BUILDSWIGNODE)
|
||||
find_package (Node REQUIRED)
|
||||
endif (BUILDSWIGNODE)
|
||||
|
||||
# Find swig if any wrapper is enabled
|
||||
if (BUILDSWIGPYTHON OR BUILDSWIGNODE OR BUILDSWIGJAVA)
|
||||
find_package (SWIG 3.0.5 REQUIRED)
|
||||
include (${SWIG_USE_FILE})
|
||||
endif ()
|
||||
|
||||
# Python is required for swig generated python and for UPM tests
|
||||
# UPM build can generated modules for both python2 AND python3
|
||||
# OpenCV python detect will attempt to find python2/3
|
||||
if (BUILDSWIGPYTHON OR BUILDTESTS)
|
||||
include (cmake/modules/OpenCVDetectPython.cmake)
|
||||
endif (BUILDSWIGPYTHON OR BUILDTESTS)
|
||||
|
||||
# Which versions of python were found?
|
||||
if (PYTHON2LIBS_FOUND AND BUILDSWIGPYTHON)
|
||||
message(STATUS "Building python2 modules with python-${PYTHON2LIBS_VERSION_STRING}")
|
||||
endif (PYTHON2LIBS_FOUND AND BUILDSWIGPYTHON)
|
||||
if (PYTHON3LIBS_FOUND AND BUILDSWIGPYTHON)
|
||||
message(STATUS "Building python3 modules with python-${PYTHON3LIBS_VERSION_STRING}")
|
||||
endif (PYTHON3LIBS_FOUND AND BUILDSWIGPYTHON)
|
||||
|
||||
# Python2 is currently required for python documentation
|
||||
if (BUILDSWIGPYTHON AND BUILDDOC AND NOT PYTHON2INTERP_FOUND)
|
||||
message(FATAL_ERROR "Failed to find python2 interpreter which is required "
|
||||
"to build python documentation.")
|
||||
endif (BUILDSWIGPYTHON AND BUILDDOC AND NOT PYTHON2INTERP_FOUND)
|
||||
|
||||
# Set CMAKE_INSTALL_LIBDIR if not defined
|
||||
include(GNUInstallDirs)
|
||||
set (LIB_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}" CACHE PATH "Installation path for libraries")
|
||||
@ -111,33 +136,59 @@ else()
|
||||
message(WARNING "Some modules require C++11 support, and may not build without it.")
|
||||
endif()
|
||||
|
||||
# The doc target depends on each sensor target
|
||||
#
|
||||
# doc
|
||||
# ├──> libupm_sensor0
|
||||
# ├──> libupm_sensor1
|
||||
# ├──> libupm_sensor2
|
||||
# └──> libupm_sensor_n
|
||||
#
|
||||
# The pydoc target builds documentation with sphinx via inspection by loading
|
||||
# each python module. Those modules must include the CXX documentation via
|
||||
# a monolithic swig file generated by doxy2swig
|
||||
#
|
||||
# pydoc
|
||||
# └──> _pyupm_sensor0_python2
|
||||
# ├──────> libupm_sensor0
|
||||
# └──────> doxy2swig
|
||||
#
|
||||
# The doxy2swig target is dependent upon the doc target IF BUILDDOC=ON,
|
||||
# otherwise doxy2swig uses an empty file. Doxy2swig also depends on each
|
||||
# sensor target
|
||||
#
|
||||
# doxy2swig
|
||||
# ├──> BUILDDOC=ON───> doc
|
||||
# └──> libupm_sensor0
|
||||
#
|
||||
# The jsdoc target builds js documentation via yuidoc and only requires
|
||||
# the doc target
|
||||
#
|
||||
# jsdoc ─> doc
|
||||
#
|
||||
if (BUILDDOC)
|
||||
# Add a target to generate API documentation with Doxygen
|
||||
find_package (Doxygen)
|
||||
if (DOXYGEN_FOUND)
|
||||
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/doxy/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
|
||||
if (BUILDSWIGJAVA)
|
||||
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/doxy/Doxyfile.java.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile-java @ONLY)
|
||||
endif()
|
||||
file(GLOB PNG_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/docs docs/icons/*.png)
|
||||
foreach(PNG_FILE ${PNG_FILES})
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/docs/${PNG_FILE} ${CMAKE_CURRENT_BINARY_DIR}/html/docs/${PNG_FILE} COPYONLY)
|
||||
endforeach()
|
||||
add_custom_target (doc
|
||||
${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
|
||||
COMMAND tar -czf html/xml.tar.gz -C xml .
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||
COMMENT "Generating API documentation with Doxygen" VERBATIM
|
||||
)
|
||||
endif (DOXYGEN_FOUND)
|
||||
# Check if Sphinx is installed and add target to generate API documentation
|
||||
find_package (Sphinx)
|
||||
if(SPHINX_FOUND AND BUILDSWIGPYTHON)
|
||||
# Python required for Sphinx build
|
||||
find_package (PythonLibs ${PYTHONBUILD_VERSION} REQUIRED)
|
||||
string (REPLACE "." ";" PYTHON_VERSION_LIST ${PYTHONLIBS_VERSION_STRING})
|
||||
list (GET PYTHON_VERSION_LIST 0 PYTHON_VERSION_MAJOR)
|
||||
list (GET PYTHON_VERSION_LIST 1 PYTHON_VERSION_MINOR)
|
||||
find_package (Doxygen REQUIRED)
|
||||
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/doxy/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
|
||||
if (BUILDSWIGJAVA)
|
||||
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/doxy/Doxyfile.java.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile-java @ONLY)
|
||||
endif()
|
||||
file(GLOB PNG_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/docs docs/icons/*.png)
|
||||
foreach(PNG_FILE ${PNG_FILES})
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/docs/${PNG_FILE} ${CMAKE_CURRENT_BINARY_DIR}/html/docs/${PNG_FILE} COPYONLY)
|
||||
endforeach()
|
||||
add_custom_target (doc
|
||||
${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
|
||||
COMMAND tar -czf html/xml.tar.gz -C xml .
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||
COMMENT "Generating API documentation with Doxygen" VERBATIM
|
||||
)
|
||||
|
||||
# Check if Sphinx is installed and add target to generate API documentationa
|
||||
# Currently, the per-module documentation for python is generated from the
|
||||
# python2 modules.
|
||||
if(BUILDSWIGPYTHON)
|
||||
find_package (Sphinx REQUIRED)
|
||||
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/doxy/conf.py.in ${CMAKE_CURRENT_BINARY_DIR}/pydoc/conf.py @ONLY)
|
||||
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/doxy/index.rst ${CMAKE_CURRENT_BINARY_DIR}/pydoc/index.rst COPYONLY)
|
||||
add_custom_target (pydoc ALL
|
||||
@ -153,12 +204,11 @@ if (BUILDDOC)
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||
COMMENT "Generating API documentation with Sphinx" VERBATIM
|
||||
)
|
||||
endif ()
|
||||
endif(BUILDSWIGPYTHON)
|
||||
|
||||
# Check if Yuidoc is installed and add target for API documentation
|
||||
find_package(Yuidoc)
|
||||
if(YUIDOC_FOUND AND BUILDSWIGNODE)
|
||||
# Node required for Yuidoc documentation
|
||||
find_package(Node)
|
||||
if(BUILDSWIGNODE)
|
||||
find_package(Yuidoc REQUIRED)
|
||||
file(GLOB_RECURSE JSDOC_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/doxy/node doxy/node/*)
|
||||
foreach(JSDOC_FILE ${JSDOC_FILES})
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/doxy/node/${JSDOC_FILE} ${CMAKE_CURRENT_BINARY_DIR}/${JSDOC_FILE} COPYONLY)
|
||||
@ -171,11 +221,10 @@ if (BUILDDOC)
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||
COMMENT "Generating API documentation with Yuidoc" VERBATIM
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
endif(BUILDSWIGNODE)
|
||||
endif (BUILDDOC)
|
||||
|
||||
if (IPK)
|
||||
|
||||
# Get target package arch from Yocto ADT sysroot if set or host OS, mapping to Ubuntu name if necessary
|
||||
if (DEFINED ENV{OECORE_TARGET_SYSROOT})
|
||||
GET_FILENAME_COMPONENT (DETECTED_SYSROOT $ENV{OECORE_TARGET_SYSROOT} NAME)
|
||||
@ -238,14 +287,6 @@ if (RPM)
|
||||
include(CPack)
|
||||
endif()
|
||||
|
||||
if (BUILDSWIGPYTHON OR BUILDTESTS)
|
||||
if (BUILDPYTHON3)
|
||||
set (PYTHONBUILD_VERSION 3)
|
||||
else ()
|
||||
set (PYTHONBUILD_VERSION 2.7)
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
# UPM common headers
|
||||
set (UPM_COMMON_HEADER_DIRS
|
||||
${CMAKE_HOME_DIRECTORY}/include
|
||||
@ -263,8 +304,8 @@ if(BUILDJAVAEXAMPLES)
|
||||
add_subdirectory (examples/java)
|
||||
endif()
|
||||
|
||||
# Python interp is previously found if BUILDTESTS=ON
|
||||
if (BUILDTESTS)
|
||||
find_package (PythonInterp ${PYTHONBUILD_VERSION} REQUIRED)
|
||||
enable_testing ()
|
||||
add_subdirectory (tests)
|
||||
endif()
|
||||
|
Reference in New Issue
Block a user