暫無描述

CMakeLists.txt 8.5KB

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