mirror of
https://github.com/eclipse/upm.git
synced 2025-03-15 04:57:30 +03:00

The DetectPython cmake script now outputs a default python executable. Updated other cmake scripts to use this concept. Used default where python2/3 will work, use explicit PYTHON2/3_EXECUTABLE where an explicit version is needed. Also, fail if python is required and NO version of python was found. Signed-off-by: Noel Eck <noel.eck@intel.com>
328 lines
13 KiB
CMake
328 lines
13 KiB
CMake
cmake_minimum_required (VERSION 2.8.11)
|
|
project (upm)
|
|
|
|
# Before going any further, define build options
|
|
option (BUILDDOC "Build all doc" OFF)
|
|
option (BUILDCPP "Build CPP sensor libraries" ON)
|
|
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 (BUILDEXAMPLES "Build C/C++ example binaries" OFF)
|
|
option (BUILDJAVAEXAMPLES "Build java example jars" OFF)
|
|
option (IPK "Generate IPK using CPack" OFF)
|
|
option (RPM "Generate RPM using CPack" OFF)
|
|
option (BUILDTESTS "Generate check-ups for upm" ON)
|
|
option (ENABLECXX11 "Enable C++11 standards support" ON)
|
|
|
|
# Warn if building in source root
|
|
if ("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
|
|
message (WARNING "Building into sources dir can be risky, prefer other directory")
|
|
endif ()
|
|
|
|
# Appends the cmake/modules path to MAKE_MODULE_PATH variable.
|
|
set (CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_PATH})
|
|
|
|
find_package (Threads REQUIRED)
|
|
find_package (PkgConfig REQUIRED)
|
|
|
|
# Force a libmraa search and minimum required version every time a config is generated
|
|
unset(MRAA_FOUND CACHE)
|
|
set(MRAA_MINIMUM 1.1.1)
|
|
pkg_check_modules (MRAA REQUIRED mraa>=${MRAA_MINIMUM})
|
|
|
|
# Check for BACNET
|
|
pkg_check_modules (BACNET libbacnet)
|
|
|
|
# Check for MODBUS
|
|
pkg_check_modules (MODBUS libmodbus>=3.1.2)
|
|
|
|
# Check for OPENZWAVE
|
|
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.
|
|
# The UPM build can generated modules for both python2 AND python3
|
|
# with the corresponding PYTHONLIBS. Currently, BUILDTESTS has a
|
|
# hard dependency on the PYTHON2INTERP.
|
|
# OpenCV python detect will attempt to find python2/3
|
|
if (BUILDSWIGPYTHON OR BUILDTESTS)
|
|
include (cmake/modules/OpenCVDetectPython.cmake)
|
|
|
|
# Fail if building tests but no python interpreter was found
|
|
if (BUILDTESTS AND NOT PYTHON2INTERP_FOUND)
|
|
message(FATAL_ERROR "BUILDTESTS=ON requires the python2 interpreter")
|
|
endif (BUILDTESTS AND NOT PYTHON2INTERP_FOUND)
|
|
|
|
# Fail if no LIBS were found
|
|
if (NOT PYTHON2LIBS_FOUND AND NOT PYTHON3LIBS_FOUND)
|
|
message(FATAL_ERROR "At least one python lib is required")
|
|
endif (NOT PYTHON2LIBS_FOUND AND NOT PYTHON3LIBS_FOUND)
|
|
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")
|
|
|
|
# Make a version file containing the current version from git.
|
|
include (GetGitRevisionDescription)
|
|
git_describe (VERSION "--tags")
|
|
if ("x_${VERSION}" STREQUAL "x_GIT-NOTFOUND" OR "x_${VERSION}" STREQUAL "x_-128-NOTFOUND")
|
|
message (WARNING "Install git to compile a production UPM!")
|
|
set (VERSION "v0.8.0-dirty")
|
|
endif ()
|
|
|
|
message (STATUS "UPM Version ${VERSION}")
|
|
|
|
# Parse the version information into pieces.
|
|
string (REGEX REPLACE "^v([0-9]+)\\..*" "\\1" VERSION_MAJOR "${VERSION}")
|
|
string (REGEX REPLACE "^v[0-9]+\\.([0-9]+).*" "\\1" VERSION_MINOR "${VERSION}")
|
|
string (REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" VERSION_PATCH "${VERSION}")
|
|
string (REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.[0-9]+\\-([0-9]+).*" "\\1" VERSION_COMMIT "${VERSION}")
|
|
string (REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.[0-9]+-[0-9]+\\-(.*)" "\\1" VERSION_SHA1 "${VERSION}")
|
|
|
|
if ("${VERSION_COMMIT}" MATCHES "^v.*")
|
|
set (VERSION_COMMIT "")
|
|
endif()
|
|
|
|
set (upm_VERSION_MAJOR ${VERSION_MAJOR})
|
|
set (upm_VERSION_MINOR ${VERSION_MINOR})
|
|
set (upm_VERSION_PATCH ${VERSION_PATCH})
|
|
set (upm_VERSION_STRING ${upm_VERSION_MAJOR}.${upm_VERSION_MINOR}.${upm_VERSION_PATCH})
|
|
|
|
# Detect arch
|
|
include (TargetArch)
|
|
target_architecture (DETECTED_ARCH)
|
|
message (STATUS "Target arch is ${DETECTED_ARCH}")
|
|
|
|
#-march=native for ARM when not defined/forced
|
|
if (DETECTED_ARCH MATCHES "arm.*" AND NOT CMAKE_CXX_FLAGS MATCHES "-march")
|
|
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
|
|
endif()
|
|
|
|
# enable c++11 standards support
|
|
if (ENABLECXX11)
|
|
include(CheckCXXCompilerFlag)
|
|
if (CMAKE_VERSION VERSION_LESS "3.1")
|
|
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
|
|
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
|
|
if (COMPILER_SUPPORTS_CXX11)
|
|
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
|
elseif (COMPILER_SUPPORTS_CXX0X)
|
|
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
|
|
else()
|
|
message(WARNING "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please update your C++ compiler.")
|
|
endif()
|
|
else()
|
|
# 3.1+ uses this generic method to enable c++11
|
|
set (CMAKE_CXX_STANDARD 11)
|
|
endif()
|
|
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 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
|
|
COMMAND rm -r -f ${CMAKE_BINARY_DIR}/pyupm && mkdir -p ${CMAKE_BINARY_DIR}/pyupm
|
|
COMMAND find ${CMAKE_BINARY_DIR}/src -name "_pyupm_*.so" -exec cp {} ${CMAKE_BINARY_DIR}/pyupm \;
|
|
COMMAND find ${CMAKE_BINARY_DIR}/src -name "pyupm_*.py" -exec cp {} ${CMAKE_BINARY_DIR}/pyupm \;
|
|
COMMAND ${SPHINX_API_EXECUTABLE} -f -o pydoc ${CMAKE_BINARY_DIR}/pyupm
|
|
# TODO: use a separate cmake FILE module for string replacement instead
|
|
COMMAND ${SPHINX_EXECUTABLE} -b html pydoc html/python
|
|
COMMAND sed -i.bak s|\">pyupm_|\">|g html/python/index.html html/python/modules.html
|
|
COMMAND sed -i.bak s|[[:space:]][mM]odule</a>|</a>|g html/python/index.html html/python/modules.html
|
|
DEPENDS doc
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
|
COMMENT "Generating API documentation with Sphinx" VERBATIM
|
|
)
|
|
endif(BUILDSWIGPYTHON)
|
|
|
|
# Check if Yuidoc is installed and add target for API documentation
|
|
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)
|
|
endforeach()
|
|
add_custom_target(jsdoc ALL
|
|
COMMAND ${NODEJS_EXECUTABLE} docgen -m upm -i xml -t ${CMAKE_CURRENT_SOURCE_DIR}/src -g ../../
|
|
COMMAND ${YUIDOC_EXECUTABLE} -C --no-sort --helpers generators/yuidoc/helper.js --themedir generators/yuidoc/tmpl -o html/node jsdoc/yuidoc/upm
|
|
COMMAND ${NODEJS_EXECUTABLE} tolower -i html/node
|
|
DEPENDS doc
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
|
COMMENT "Generating API documentation with Yuidoc" VERBATIM
|
|
)
|
|
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)
|
|
string (REGEX REPLACE "-poky-linux" "" TARGET_ARCH "${DETECTED_SYSROOT}")
|
|
else ()
|
|
# Debian uses amd64 to denote x86_64
|
|
if (DETECTED_ARCH STREQUAL "x86_64")
|
|
set (TARGET_ARCH "amd64")
|
|
else ()
|
|
set (TARGET_ARCH ${DETECTED_ARCH})
|
|
endif ()
|
|
endif ()
|
|
message (STATUS "Package arch is ${TARGET_ARCH}")
|
|
|
|
set(CPACK_GENERATOR "DEB")
|
|
set(OPKG_ARCH ${TARGET_ARCH})
|
|
set(CPACK_BINARY_DIR ${CMAKE_BINARY_DIR})
|
|
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Intel IoT-Devkit") #required
|
|
set(upm_PACKAGE_ON_TAG ".")
|
|
if ("${VERSION_COMMIT}" STREQUAL "")
|
|
set(upm_PACKAGE_ON_TAG "")
|
|
endif()
|
|
set(CPACK_PACKAGE_VERSION
|
|
"${upm_VERSION_MAJOR}.${upm_VERSION_MINOR}.${upm_VERSION_PATCH}${upm_PACKAGE_ON_TAG}${VERSION_COMMIT}")
|
|
set(CPACK_PACKAGE_NAME "upm")
|
|
set(CPACK_DEBIAN_PACKAGE_SECTION "libs")
|
|
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE ${TARGET_ARCH})
|
|
set(CPACK_SYSTEM_NAME ${TARGET_ARCH})
|
|
set(CPACK_DEBIAN_PACKAGE_DEPENDS "mraa (>= ${MRAA_VERSION})")
|
|
set(CPACK_DEBIAN_PACKAGE_PROVIDES "upm-dev, upm-dbg, upm-doc")
|
|
set(CPACK_DEBIAN_PACKAGE_REPLACES ${CPACK_DEBIAN_PACKAGE_PROVIDES})
|
|
set(CPACK_DEBIAN_PACKAGE_CONFLICTS ${CPACK_DEBIAN_PACKAGE_PROVIDES})
|
|
set(WDIR "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}")
|
|
include (CPack)
|
|
endif()
|
|
|
|
if (RPM)
|
|
message (STATUS "RPM packaging enabled for ${DETECTED_ARCH}")
|
|
set(CPACK_PACKAGE_VERSION ${VERSION})
|
|
set(CPACK_GENERATOR "RPM")
|
|
set(CPACK_PACKAGE_NAME "upm")
|
|
set(upm_PACKAGE_ON_TAG ".")
|
|
if ("${VERSION_COMMIT}" STREQUAL "")
|
|
set(upm_PACKAGE_ON_TAG "")
|
|
endif()
|
|
set(CPACK_PACKAGE_VERSION
|
|
"${upm_VERSION_MAJOR}.${upm_VERSION_MINOR}.${upm_VERSION_PATCH}${upm_PACKAGE_ON_TAG}${VERSION_COMMIT}")
|
|
set(CPACK_PACKAGE_CONTACT "Intel IoT-Devkit")
|
|
set(CPACK_PACKAGE_VENDOR "Intel IoT-Devkit")
|
|
set(CPACK_RPM_PACKAGE_REQUIRES "mraa >= ${MRAA_VERSION}")
|
|
set(CPACK_RPM_PACKAGE_PROVIDES "${CPACK_PACKAGE_NAME}-devel")
|
|
set(CPACK_RPM_PACKAGE_LICENSE "MIT")
|
|
EXECUTE_PROCESS(COMMAND rpm --showrc
|
|
COMMAND grep -E "dist[[:space:]]*\\."
|
|
COMMAND sed -e "s/^.*dist\\s*\\.//"
|
|
COMMAND tr \\n \\t
|
|
COMMAND sed -e s/\\t//
|
|
OUTPUT_VARIABLE DIST_TAG)
|
|
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}.${DIST_TAG}.${DETECTED_ARCH}")
|
|
include(CPack)
|
|
endif()
|
|
|
|
# UPM common headers
|
|
set (UPM_COMMON_HEADER_DIRS
|
|
${CMAKE_HOME_DIRECTORY}/include
|
|
${CMAKE_HOME_DIRECTORY}/include/fti)
|
|
|
|
add_subdirectory (src)
|
|
if(BUILDEXAMPLES)
|
|
add_subdirectory (examples/c)
|
|
if(BUILDCPP)
|
|
add_subdirectory (examples/c++)
|
|
endif(BUILDCPP)
|
|
endif()
|
|
|
|
if(BUILDJAVAEXAMPLES)
|
|
add_subdirectory (examples/java)
|
|
endif()
|
|
|
|
# Python interp is previously found if BUILDTESTS=ON
|
|
if (BUILDTESTS)
|
|
enable_testing ()
|
|
add_subdirectory (tests)
|
|
endif()
|
|
|
|
# Install C headers
|
|
install(DIRECTORY include/ DESTINATION include/upm
|
|
FILES_MATCHING PATTERN "*.h")
|