1 cmake_minimum_required (VERSION 2.8)
4 FIND_PACKAGE (Threads REQUIRED)
6 set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -fno-omit-frame-pointer")
7 set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Wall")
8 set (LIB_INSTALL_DIR "lib${LIB_SUFFIX}" CACHE PATH "Installation path for libraries")
10 # Set CMAKE_LIB_INSTALL_DIR if not defined
11 include(GNUInstallDirs)
13 # Appends the cmake/modules path to MAKE_MODULE_PATH variable.
14 set (CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_PATH})
16 # Make a version file containing the current version from git.
17 include (GetGitRevisionDescription)
18 git_describe (VERSION "--tags")
19 if ("x_${VERSION}" STREQUAL "x_GIT-NOTFOUND" OR "x_${VERSION}" STREQUAL "x_HEAD-HASH-NOTFOUND")
20 message (WARNING " - Install git to compile a production libmraa!")
21 set (VERSION "v0.7.2-dirty")
24 message (INFO " - libmraa Version ${VERSION}")
26 #parse the version information into pieces.
27 string (REGEX REPLACE "^v([0-9]+)\\..*" "\\1" VERSION_MAJOR "${VERSION}")
28 string (REGEX REPLACE "^v[0-9]+\\.([0-9]+).*" "\\1" VERSION_MINOR "${VERSION}")
29 string (REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" VERSION_PATCH "${VERSION}")
30 string (REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.[0-9]+\\-([0-9]+).*" "\\1" VERSION_COMMIT "${VERSION}")
31 string (REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.[0-9]+-[0-9]+\\-(.*)" "\\1" VERSION_SHA1 "${VERSION}")
32 set (VERSION_SHORT "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
34 if ("${VERSION_COMMIT}" MATCHES "^v.*")
35 set (VERSION_COMMIT "")
38 configure_file (${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/version.c.in
39 ${CMAKE_CURRENT_BINARY_DIR}/src/version.c)
41 # this is the library version, independant of git revision
42 set (mraa_VERSION_MAJOR ${VERSION_MAJOR})
43 set (mraa_VERSION_MINOR ${VERSION_MINOR})
44 set (mraa_VERSION_PATCH ${VERSION_PATCH})
45 set (mraa_VERSION_STRING ${mraa_VERSION_MAJOR}.${mraa_VERSION_MINOR}.${mraa_VERSION_PATCH})
47 set (CMAKE_SWIG_FLAGS "")
49 find_path (SYSTEM_USR_DIR "stdlib.h")
50 include_directories (${SYSTEM_USR_DIR})
52 option (BUILDDOC "Build all doc." OFF)
53 option (BUILDSWIG "Build swig modules." ON)
54 option (BUILDSWIGPYTHON "Build swig python modules." ON)
55 option (BUILDSWIGNODE "Build swig node modules." ON)
56 option (BUILDSWIGJAVA "Build Java API." OFF)
57 option (IPK "Generate IPK using CPack" OFF)
58 option (RPM "Generate RPM using CPack" OFF)
59 option (BUILDPYTHON3 "Use python3 for building/installing" OFF)
60 option (INSTALLGPIOTOOL "Install gpio tool" OFF)
61 option (BUILDARCH "Override architecture to build for - override" OFF)
62 option (TESTS "Override the addition of tests" ON)
65 set (BUILDSWIGPYTHON OFF)
66 set (BUILDSWIGNODE OFF)
67 set (BUILDSWIGJAVA OFF)
72 target_architecture (DETECTED_ARCH)
73 message( INFO " - Target arch is ${DETECTED_ARCH}")
75 set (DETECTED_ARCH ${BUILDARCH})
76 message( INFO " - Override arch is ${DETECTED_ARCH}")
79 if (DETECTED_ARCH STREQUAL "i586" OR DETECTED_ARCH STREQUAL "x86_64"
80 OR DETECTED_ARCH STREQUAL "i386")
82 elseif (DETECTED_ARCH MATCHES "arm.*")
85 message(FATAL_ERROR "Only x86 and arm platforms currently supported")
90 set (PYTHONBUILD_VERSION 3)
92 set (PYTHONBUILD_VERSION 2.7)
94 find_package (PythonInterp ${PYTHONBUILD_VERSION} REQUIRED)
96 if (${PYTHONINTERP_FOUND})
98 add_subdirectory (tests)
104 # add a target to generate API documentation with Doxygen
105 find_package (Doxygen)
107 configure_file (${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
108 add_custom_target (doc
109 ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
110 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
111 COMMENT "Generating API documentation with Doxygen" VERBATIM
113 endif (DOXYGEN_FOUND)
117 # Get target package arch from Yocto ADT sysroot if set or host OS, mapping to Ubuntu name if necessary
118 if (DEFINED ENV{OECORE_TARGET_SYSROOT})
119 GET_FILENAME_COMPONENT (DETECTED_SYSROOT $ENV{OECORE_TARGET_SYSROOT} NAME)
120 string (REGEX REPLACE "-poky-linux" "" TARGET_ARCH "${DETECTED_SYSROOT}")
122 # debian uses amd64 to denote x86_64
123 if (DETECTED_ARCH STREQUAL "x86_64")
124 set (TARGET_ARCH "amd64")
126 set (TARGET_ARCH ${DETECTED_ARCH})
129 message (INFO " - Package arch is ${TARGET_ARCH}")
131 set(CPACK_GENERATOR "DEB" "TGZ")
132 set(OPKG_ARCH ${TARGET_ARCH})
133 set(CPACK_BINARY_DIR ${CMAKE_BINARY_DIR})
134 set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Intel IoT-Devkit") #required
135 set(mraa_PACKAGE_ON_TAG ".")
136 if ("${VERSION_COMMIT}" STREQUAL "")
137 set(mraa_PACKAGE_ON_TAG "")
139 set(CPACK_PACKAGE_VERSION
140 "${mraa_VERSION_MAJOR}.${mraa_VERSION_MINOR}.${mraa_VERSION_PATCH}${mraa_PACKAGE_ON_TAG}${VERSION_COMMIT}")
141 set(CPACK_PACKAGE_NAME "libmraa${mraa_VERSION_MAJOR}")
142 set(CPACK_DEBIAN_PACKAGE_SECTION "libs")
143 set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE ${TARGET_ARCH})
144 set(CPACK_SYSTEM_NAME ${TARGET_ARCH})
145 set(CPACK_DEBIAN_PACKAGE_PROVIDES "libmraa-dev, libmraa-dbg, libmraa-doc")
146 set(CPACK_DEBIAN_PACKAGE_REPLACES ${CPACK_DEBIAN_PACKAGE_PROVIDES})
147 set(CPACK_DEBIAN_PACKAGE_CONFLICTS ${CPACK_DEBIAN_PACKAGE_PROVIDES})
148 set(WDIR "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}")
153 message (INFO " - Enabled RPM packaging for ${DETECTED_ARCH}")
154 set(CPACK_PACKAGE_VERSION ${VERSION})
155 set(CPACK_GENERATOR "RPM")
156 set(CPACK_PACKAGE_NAME "libmraa${mraa_VERSION_MAJOR}")
157 set(CPACK_PACKAGE_RELEASE 1)
158 set(CPACK_PACKAGE_VERSION
159 "${mraa_VERSION_MAJOR}.${mraa_VERSION_MINOR}.${mraa_VERSION_PATCH}${mraa_PACKAGE_ON_TAG}${VERSION_COMMIT}")
160 set(CPACK_PACKAGE_CONTACT "Intel IoT-Devkit")
161 set(CPACK_PACKAGE_VENDOR "Intel IoT-Devkit")
162 set(CPACK_RPM_PACKAGE_PROVIDES "${CPACK_PACKAGE_NAME}-devel")
163 EXECUTE_PROCESS(COMMAND rpm --showrc
164 COMMAND grep -E "dist[[:space:]]*\\."
165 COMMAND sed -e "s/^.*dist\\s*\\.//"
167 COMMAND sed -e s/\\t//
168 OUTPUT_VARIABLE DIST_TAG)
169 set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CPACK_PACKAGE_RELEASE}.${DIST_TAG}.${DETECTED_ARCH}")
173 add_subdirectory (src)
174 add_subdirectory (examples)