No Description

CMakeLists.txt 8.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. cmake_minimum_required (VERSION 2.8.11)
  2. project (upm)
  3. if ("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
  4. message("WARNING: building into sources dir can be risky, prefer other directory")
  5. endif ()
  6. find_package (Threads REQUIRED)
  7. find_package (PkgConfig REQUIRED)
  8. # Force a libmraa search and minimum required version every time a config is generated
  9. unset(MRAA_FOUND CACHE)
  10. pkg_check_modules (MRAA REQUIRED mraa>=0.9.1)
  11. message (INFO " found mraa version: ${MRAA_VERSION}")
  12. # Appends the cmake/modules path to MAKE_MODULE_PATH variable.
  13. set (CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_PATH})
  14. set (LIB_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}" CACHE PATH "Installation path for libraries")
  15. # Set CMAKE_LIB_INSTALL_DIR if not defined
  16. include(GNUInstallDirs)
  17. # Make a version file containing the current version from git.
  18. include (GetGitRevisionDescription)
  19. git_describe (VERSION "--tags")
  20. if ("x_${VERSION}" STREQUAL "x_GIT-NOTFOUND" OR "x_${VERSION}" STREQUAL "x_-128-NOTFOUND")
  21. message (WARNING " - Install git to compile a production UPM!")
  22. set (VERSION "v0.5.1-dirty")
  23. endif ()
  24. message (INFO " - UPM Version ${VERSION}")
  25. # Parse the version information into pieces.
  26. string (REGEX REPLACE "^v([0-9]+)\\..*" "\\1" VERSION_MAJOR "${VERSION}")
  27. string (REGEX REPLACE "^v[0-9]+\\.([0-9]+).*" "\\1" VERSION_MINOR "${VERSION}")
  28. string (REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" VERSION_PATCH "${VERSION}")
  29. string (REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.[0-9]+\\-([0-9]+).*" "\\1" VERSION_COMMIT "${VERSION}")
  30. string (REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.[0-9]+-[0-9]+\\-(.*)" "\\1" VERSION_SHA1 "${VERSION}")
  31. if ("${VERSION_COMMIT}" MATCHES "^v.*")
  32. set (VERSION_COMMIT "")
  33. endif()
  34. set (upm_VERSION_MAJOR ${VERSION_MAJOR})
  35. set (upm_VERSION_MINOR ${VERSION_MINOR})
  36. set (upm_VERSION_PATCH ${VERSION_PATCH})
  37. set (upm_VERSION_STRING ${upm_VERSION_MAJOR}.${upm_VERSION_MINOR}.${upm_VERSION_PATCH})
  38. set (CMAKE_SWIG_FLAGS "")
  39. option (BUILDDOC "Build all doc." OFF)
  40. option (BUILDSWIG "Build swig modules." ON)
  41. option (BUILDSWIGPYTHON "Build swig python modules." ON)
  42. option (BUILDSWIGNODE "Build swig node modules." ON)
  43. option (BUILDEXAMPLES "Build C++ example binaries" OFF)
  44. option (BUILDJAVAEXAMPLES "Build java example jars" OFF)
  45. option (BUILDSWIGJAVA "Build swig java modules" OFF)
  46. option (IPK "Generate IPK using CPack" OFF)
  47. option (RPM "Generate RPM using CPack" OFF)
  48. option (BUILDTESTS "Generate check-ups for upm" ON)
  49. # Find swig
  50. if (BUILDSWIG)
  51. if (BUILDSWIGNODE)
  52. find_package (SWIG 3.0.5 REQUIRED)
  53. else ()
  54. find_package (SWIG REQUIRED)
  55. endif ()
  56. if (SWIG_FOUND)
  57. include (${SWIG_USE_FILE})
  58. endif ()
  59. endif ()
  60. # Detect arch
  61. include (TargetArch)
  62. target_architecture (DETECTED_ARCH)
  63. message( INFO " - Target arch is ${DETECTED_ARCH}")
  64. if (BUILDDOC)
  65. # Add a target to generate API documentation with Doxygen
  66. find_package (Doxygen)
  67. if (DOXYGEN_FOUND)
  68. configure_file (${CMAKE_CURRENT_SOURCE_DIR}/doxy/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
  69. if (BUILDSWIGJAVA)
  70. configure_file (${CMAKE_CURRENT_SOURCE_DIR}/doxy/Doxyfile.java.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile-java @ONLY)
  71. endif()
  72. file(GLOB PNG_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/docs docs/icons/*.png)
  73. foreach(PNG_FILE ${PNG_FILES})
  74. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/docs/${PNG_FILE} ${CMAKE_CURRENT_BINARY_DIR}/html/docs/${PNG_FILE} COPYONLY)
  75. endforeach()
  76. add_custom_target (doc
  77. ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
  78. COMMAND tar -czf html/xml.tar.gz -C xml .
  79. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
  80. COMMENT "Generating API documentation with Doxygen" VERBATIM
  81. )
  82. endif (DOXYGEN_FOUND)
  83. # Check if Sphinx is installed and add target to generate API documentation
  84. find_package (Sphinx)
  85. if(SPHINX_FOUND AND BUILDSWIG AND BUILDSWIGPYTHON)
  86. # Python required for Sphinx build
  87. find_package (PythonLibs)
  88. string (REPLACE "." ";" PYTHON_VERSION_LIST ${PYTHONLIBS_VERSION_STRING})
  89. list (GET PYTHON_VERSION_LIST 0 PYTHON_VERSION_MAJOR)
  90. list (GET PYTHON_VERSION_LIST 1 PYTHON_VERSION_MINOR)
  91. set (SITE_PACKAGES ${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_DIR}/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/site-packages)
  92. configure_file (${CMAKE_CURRENT_SOURCE_DIR}/doxy/conf.py.in ${CMAKE_CURRENT_BINARY_DIR}/pydoc/conf.py @ONLY)
  93. configure_file (${CMAKE_CURRENT_SOURCE_DIR}/doxy/index.rst ${CMAKE_CURRENT_BINARY_DIR}/pydoc/index.rst COPYONLY)
  94. add_custom_target (pydoc ALL
  95. COMMAND rm -r -f ${CMAKE_BINARY_DIR}/pyupm && mkdir -p ${CMAKE_BINARY_DIR}/pyupm
  96. COMMAND find ${CMAKE_BINARY_DIR}/src -name "_pyupm_*.so" -exec cp {} ${CMAKE_BINARY_DIR}/pyupm \;
  97. COMMAND find ${CMAKE_BINARY_DIR}/src -name "pyupm_*.py" -exec cp {} ${CMAKE_BINARY_DIR}/pyupm \;
  98. COMMAND ${SPHINX_API_EXECUTABLE} -f -o pydoc ${CMAKE_BINARY_DIR}/pyupm
  99. # TODO: use a separate cmake FILE module for string replacement instead
  100. COMMAND ${SPHINX_EXECUTABLE} -b html pydoc html/python
  101. COMMAND sed -i.bak s|\">pyupm_|\">|g html/python/index.html html/python/modules.html
  102. COMMAND sed -i.bak s|[[:space:]][mM]odule</a>|</a>|g html/python/index.html html/python/modules.html
  103. DEPENDS doc
  104. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
  105. COMMENT "Generating API documentation with Sphinx" VERBATIM
  106. )
  107. endif ()
  108. # Check if Yuidoc is installed and add target for API documentation
  109. find_package(Yuidoc)
  110. if(YUIDOC_FOUND AND BUILDSWIGNODE)
  111. # Node required for Yuidoc documentation
  112. find_package(Node)
  113. file(GLOB_RECURSE JSDOC_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/doxy/node doxy/node/*)
  114. foreach(JSDOC_FILE ${JSDOC_FILES})
  115. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/doxy/node/${JSDOC_FILE} ${CMAKE_CURRENT_BINARY_DIR}/${JSDOC_FILE} COPYONLY)
  116. endforeach()
  117. add_custom_target(jsdoc ALL
  118. COMMAND ${NODE_EXECUTABLE} docgen -m upm -i xml -t ${CMAKE_CURRENT_SOURCE_DIR}/src -g ../../
  119. COMMAND ${YUIDOC_EXECUTABLE} -C --no-sort --helpers generators/yuidoc/helper.js --themedir generators/yuidoc/tmpl -o html/node jsdoc/yuidoc/upm
  120. COMMAND ${NODE_EXECUTABLE} tolower -i html/node
  121. DEPENDS doc
  122. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
  123. COMMENT "Generating API documentation with Yuidoc" VERBATIM
  124. )
  125. endif()
  126. endif()
  127. if (IPK)
  128. # Get target package arch from Yocto ADT sysroot if set or host OS, mapping to Ubuntu name if necessary
  129. if (DEFINED ENV{OECORE_TARGET_SYSROOT})
  130. GET_FILENAME_COMPONENT (DETECTED_SYSROOT $ENV{OECORE_TARGET_SYSROOT} NAME)
  131. string (REGEX REPLACE "-poky-linux" "" TARGET_ARCH "${DETECTED_SYSROOT}")
  132. else ()
  133. # Debian uses amd64 to denote x86_64
  134. if (DETECTED_ARCH STREQUAL "x86_64")
  135. set (TARGET_ARCH "amd64")
  136. else ()
  137. set (TARGET_ARCH ${DETECTED_ARCH})
  138. endif ()
  139. endif ()
  140. message (INFO " - Package arch is ${TARGET_ARCH}")
  141. set(CPACK_GENERATOR "DEB" "TGZ")
  142. set(OPKG_ARCH ${TARGET_ARCH})
  143. set(CPACK_BINARY_DIR ${CMAKE_BINARY_DIR})
  144. set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Intel IoT-Devkit") #required
  145. set(upm_PACKAGE_ON_TAG ".")
  146. if ("${VERSION_COMMIT}" STREQUAL "")
  147. set(upm_PACKAGE_ON_TAG "")
  148. endif()
  149. set(CPACK_PACKAGE_VERSION
  150. "${upm_VERSION_MAJOR}.${upm_VERSION_MINOR}.${upm_VERSION_PATCH}${upm_PACKAGE_ON_TAG}${VERSION_COMMIT}")
  151. set(CPACK_PACKAGE_NAME "upm")
  152. set(CPACK_DEBIAN_PACKAGE_SECTION "libs")
  153. set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE ${TARGET_ARCH})
  154. set(CPACK_SYSTEM_NAME ${TARGET_ARCH})
  155. set(CPACK_DEBIAN_PACKAGE_DEPENDS "mraa (>= ${MRAA_VERSION})")
  156. set(CPACK_DEBIAN_PACKAGE_PROVIDES "upm-dev, upm-dbg, upm-doc")
  157. set(CPACK_DEBIAN_PACKAGE_REPLACES ${CPACK_DEBIAN_PACKAGE_PROVIDES})
  158. set(CPACK_DEBIAN_PACKAGE_CONFLICTS ${CPACK_DEBIAN_PACKAGE_PROVIDES})
  159. set(WDIR "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}")
  160. include (CPack)
  161. endif()
  162. if (RPM)
  163. message (INFO " - RPM packaging enabled for ${DETECTED_ARCH}")
  164. set(CPACK_PACKAGE_VERSION ${VERSION})
  165. set(CPACK_GENERATOR "RPM")
  166. set(CPACK_PACKAGE_NAME "upm")
  167. set(CPACK_PACKAGE_VERSION
  168. "${upm_VERSION_MAJOR}.${upm_VERSION_MINOR}.${upm_VERSION_PATCH}.${upm_PACKAGE_ON_TAG}${VERSION_COMMIT}")
  169. set(CPACK_PACKAGE_CONTACT "Intel IoT-Devkit")
  170. set(CPACK_PACKAGE_VENDOR "Intel IoT-Devkit")
  171. set(CPACK_RPM_PACKAGE_REQUIRES "mraa >= ${MRAA_VERSION}")
  172. set(CPACK_RPM_PACKAGE_PROVIDES "${CPACK_PACKAGE_NAME}-devel")
  173. EXECUTE_PROCESS(COMMAND rpm --showrc
  174. COMMAND grep -E "dist[[:space:]]*\\."
  175. COMMAND sed -e "s/^.*dist\\s*\\.//"
  176. COMMAND tr \\n \\t
  177. COMMAND sed -e s/\\t//
  178. OUTPUT_VARIABLE DIST_TAG)
  179. set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}.${DIST_TAG}.${DETECTED_ARCH}")
  180. include(CPack)
  181. endif()
  182. add_subdirectory (src)
  183. if(BUILDEXAMPLES)
  184. add_subdirectory (examples/c++)
  185. endif()
  186. if(BUILDJAVAEXAMPLES)
  187. add_subdirectory (examples/java)
  188. endif()
  189. if(BUILDTESTS)
  190. find_package (PythonInterp REQUIRED)
  191. if (${PYTHONINTERP_FOUND})
  192. enable_testing ()
  193. add_subdirectory (tests)
  194. endif ()
  195. endif()