Aucune description

CMakeLists.txt 10.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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 CMAKE_INSTALL_LIBDIR if not defined
  15. include(GNUInstallDirs)
  16. set (LIB_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}" CACHE PATH "Installation path for libraries")
  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.6.2-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 (BUILDPYTHON3 "Use python3 for building/installing/testing" OFF)
  43. option (BUILDSWIGNODE "Build swig node modules." ON)
  44. option (BUILDEXAMPLES "Build C++ example binaries" OFF)
  45. option (BUILDJAVAEXAMPLES "Build java example jars" OFF)
  46. option (BUILDSWIGJAVA "Build swig java modules" OFF)
  47. option (IPK "Generate IPK using CPack" OFF)
  48. option (RPM "Generate RPM using CPack" OFF)
  49. option (BUILDTESTS "Generate check-ups for upm" ON)
  50. option (ENABLECXX11 "Enable C++11 standards support" ON)
  51. # Find swig
  52. if (BUILDSWIG)
  53. if (BUILDSWIGNODE)
  54. find_package (SWIG 3.0.5 REQUIRED)
  55. else ()
  56. find_package (SWIG REQUIRED)
  57. endif ()
  58. if (SWIG_FOUND)
  59. include (${SWIG_USE_FILE})
  60. endif ()
  61. endif ()
  62. # Detect arch
  63. include (TargetArch)
  64. target_architecture (DETECTED_ARCH)
  65. message( INFO " - Target arch is ${DETECTED_ARCH}")
  66. # enable c++11 standards support
  67. if (ENABLECXX11)
  68. include(CheckCXXCompilerFlag)
  69. if (CMAKE_VERSION VERSION_LESS "3.1")
  70. CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
  71. CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
  72. if (COMPILER_SUPPORTS_CXX11)
  73. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
  74. elseif (COMPILER_SUPPORTS_CXX0X)
  75. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
  76. else()
  77. message(WARNING "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please update your C++ compiler.")
  78. endif()
  79. else()
  80. # 3.1+ uses this generic method to enable c++11
  81. set (CMAKE_CXX_STANDARD 11)
  82. endif()
  83. else()
  84. message(WARNING "Some modules require C++11 support, and may not build without it.")
  85. endif()
  86. if (BUILDDOC)
  87. # Add a target to generate API documentation with Doxygen
  88. find_package (Doxygen)
  89. if (DOXYGEN_FOUND)
  90. configure_file (${CMAKE_CURRENT_SOURCE_DIR}/doxy/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
  91. if (BUILDSWIGJAVA)
  92. configure_file (${CMAKE_CURRENT_SOURCE_DIR}/doxy/Doxyfile.java.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile-java @ONLY)
  93. endif()
  94. file(GLOB PNG_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/docs docs/icons/*.png)
  95. foreach(PNG_FILE ${PNG_FILES})
  96. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/docs/${PNG_FILE} ${CMAKE_CURRENT_BINARY_DIR}/html/docs/${PNG_FILE} COPYONLY)
  97. endforeach()
  98. add_custom_target (doc
  99. ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
  100. COMMAND tar -czf html/xml.tar.gz -C xml .
  101. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
  102. COMMENT "Generating API documentation with Doxygen" VERBATIM
  103. )
  104. endif (DOXYGEN_FOUND)
  105. # Check if Sphinx is installed and add target to generate API documentation
  106. find_package (Sphinx)
  107. if(SPHINX_FOUND AND BUILDSWIG AND BUILDSWIGPYTHON)
  108. # Python required for Sphinx build
  109. find_package (PythonLibs ${PYTHONBUILD_VERSION} REQUIRED)
  110. string (REPLACE "." ";" PYTHON_VERSION_LIST ${PYTHONLIBS_VERSION_STRING})
  111. list (GET PYTHON_VERSION_LIST 0 PYTHON_VERSION_MAJOR)
  112. list (GET PYTHON_VERSION_LIST 1 PYTHON_VERSION_MINOR)
  113. configure_file (${CMAKE_CURRENT_SOURCE_DIR}/doxy/conf.py.in ${CMAKE_CURRENT_BINARY_DIR}/pydoc/conf.py @ONLY)
  114. configure_file (${CMAKE_CURRENT_SOURCE_DIR}/doxy/index.rst ${CMAKE_CURRENT_BINARY_DIR}/pydoc/index.rst COPYONLY)
  115. add_custom_target (pydoc ALL
  116. COMMAND rm -r -f ${CMAKE_BINARY_DIR}/pyupm && mkdir -p ${CMAKE_BINARY_DIR}/pyupm
  117. COMMAND find ${CMAKE_BINARY_DIR}/src -name "_pyupm_*.so" -exec cp {} ${CMAKE_BINARY_DIR}/pyupm \;
  118. COMMAND find ${CMAKE_BINARY_DIR}/src -name "pyupm_*.py" -exec cp {} ${CMAKE_BINARY_DIR}/pyupm \;
  119. COMMAND ${SPHINX_API_EXECUTABLE} -f -o pydoc ${CMAKE_BINARY_DIR}/pyupm
  120. # TODO: use a separate cmake FILE module for string replacement instead
  121. COMMAND ${SPHINX_EXECUTABLE} -b html pydoc html/python
  122. COMMAND sed -i.bak s|\">pyupm_|\">|g html/python/index.html html/python/modules.html
  123. COMMAND sed -i.bak s|[[:space:]][mM]odule</a>|</a>|g html/python/index.html html/python/modules.html
  124. DEPENDS doc
  125. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
  126. COMMENT "Generating API documentation with Sphinx" VERBATIM
  127. )
  128. endif ()
  129. # Check if Yuidoc is installed and add target for API documentation
  130. find_package(Yuidoc)
  131. if(YUIDOC_FOUND AND BUILDSWIGNODE)
  132. # Node required for Yuidoc documentation
  133. find_package(Node)
  134. file(GLOB_RECURSE JSDOC_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/doxy/node doxy/node/*)
  135. foreach(JSDOC_FILE ${JSDOC_FILES})
  136. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/doxy/node/${JSDOC_FILE} ${CMAKE_CURRENT_BINARY_DIR}/${JSDOC_FILE} COPYONLY)
  137. endforeach()
  138. add_custom_target(jsdoc ALL
  139. COMMAND ${NODEJS_EXECUTABLE} docgen -m upm -i xml -t ${CMAKE_CURRENT_SOURCE_DIR}/src -g ../../
  140. COMMAND ${YUIDOC_EXECUTABLE} -C --no-sort --helpers generators/yuidoc/helper.js --themedir generators/yuidoc/tmpl -o html/node jsdoc/yuidoc/upm
  141. COMMAND ${NODEJS_EXECUTABLE} tolower -i html/node
  142. DEPENDS doc
  143. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
  144. COMMENT "Generating API documentation with Yuidoc" VERBATIM
  145. )
  146. endif()
  147. endif()
  148. if (IPK)
  149. # Get target package arch from Yocto ADT sysroot if set or host OS, mapping to Ubuntu name if necessary
  150. if (DEFINED ENV{OECORE_TARGET_SYSROOT})
  151. GET_FILENAME_COMPONENT (DETECTED_SYSROOT $ENV{OECORE_TARGET_SYSROOT} NAME)
  152. string (REGEX REPLACE "-poky-linux" "" TARGET_ARCH "${DETECTED_SYSROOT}")
  153. else ()
  154. # Debian uses amd64 to denote x86_64
  155. if (DETECTED_ARCH STREQUAL "x86_64")
  156. set (TARGET_ARCH "amd64")
  157. else ()
  158. set (TARGET_ARCH ${DETECTED_ARCH})
  159. endif ()
  160. endif ()
  161. message (INFO " - Package arch is ${TARGET_ARCH}")
  162. set(CPACK_GENERATOR "DEB")
  163. set(OPKG_ARCH ${TARGET_ARCH})
  164. set(CPACK_BINARY_DIR ${CMAKE_BINARY_DIR})
  165. set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Intel IoT-Devkit") #required
  166. set(upm_PACKAGE_ON_TAG ".")
  167. if ("${VERSION_COMMIT}" STREQUAL "")
  168. set(upm_PACKAGE_ON_TAG "")
  169. endif()
  170. set(CPACK_PACKAGE_VERSION
  171. "${upm_VERSION_MAJOR}.${upm_VERSION_MINOR}.${upm_VERSION_PATCH}${upm_PACKAGE_ON_TAG}${VERSION_COMMIT}")
  172. set(CPACK_PACKAGE_NAME "upm")
  173. set(CPACK_DEBIAN_PACKAGE_SECTION "libs")
  174. set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE ${TARGET_ARCH})
  175. set(CPACK_SYSTEM_NAME ${TARGET_ARCH})
  176. set(CPACK_DEBIAN_PACKAGE_DEPENDS "mraa (>= ${MRAA_VERSION})")
  177. set(CPACK_DEBIAN_PACKAGE_PROVIDES "upm-dev, upm-dbg, upm-doc")
  178. set(CPACK_DEBIAN_PACKAGE_REPLACES ${CPACK_DEBIAN_PACKAGE_PROVIDES})
  179. set(CPACK_DEBIAN_PACKAGE_CONFLICTS ${CPACK_DEBIAN_PACKAGE_PROVIDES})
  180. set(WDIR "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}")
  181. include (CPack)
  182. endif()
  183. if (RPM)
  184. message (INFO " - RPM packaging enabled for ${DETECTED_ARCH}")
  185. set(CPACK_PACKAGE_VERSION ${VERSION})
  186. set(CPACK_GENERATOR "RPM")
  187. set(CPACK_PACKAGE_NAME "upm")
  188. set(upm_PACKAGE_ON_TAG ".")
  189. if ("${VERSION_COMMIT}" STREQUAL "")
  190. set(upm_PACKAGE_ON_TAG "")
  191. endif()
  192. set(CPACK_PACKAGE_VERSION
  193. "${upm_VERSION_MAJOR}.${upm_VERSION_MINOR}.${upm_VERSION_PATCH}${upm_PACKAGE_ON_TAG}${VERSION_COMMIT}")
  194. set(CPACK_PACKAGE_CONTACT "Intel IoT-Devkit")
  195. set(CPACK_PACKAGE_VENDOR "Intel IoT-Devkit")
  196. set(CPACK_RPM_PACKAGE_REQUIRES "mraa >= ${MRAA_VERSION}")
  197. set(CPACK_RPM_PACKAGE_PROVIDES "${CPACK_PACKAGE_NAME}-devel")
  198. set(CPACK_RPM_PACKAGE_LICENSE "MIT")
  199. EXECUTE_PROCESS(COMMAND rpm --showrc
  200. COMMAND grep -E "dist[[:space:]]*\\."
  201. COMMAND sed -e "s/^.*dist\\s*\\.//"
  202. COMMAND tr \\n \\t
  203. COMMAND sed -e s/\\t//
  204. OUTPUT_VARIABLE DIST_TAG)
  205. set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}.${DIST_TAG}.${DETECTED_ARCH}")
  206. include(CPack)
  207. endif()
  208. add_subdirectory (src)
  209. if(BUILDEXAMPLES)
  210. add_subdirectory (examples/c++)
  211. endif()
  212. if(BUILDJAVAEXAMPLES)
  213. add_subdirectory (examples/java)
  214. endif()
  215. if (BUILDSWIGPYTHON OR BUILDTESTS)
  216. if (BUILDPYTHON3)
  217. set (PYTHONBUILD_VERSION 3)
  218. else ()
  219. set (PYTHONBUILD_VERSION 2.7)
  220. endif ()
  221. endif ()
  222. if (BUILDTESTS)
  223. find_package (PythonInterp ${PYTHONBUILD_VERSION} REQUIRED)
  224. enable_testing ()
  225. add_subdirectory (tests)
  226. endif()