Ingen beskrivning

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