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