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.5-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 (USBPLAT "Detection USB platform." ON)
58 option (FTDID2XX "Build with FTDI D2xx subplatform support." OFF)
59 option (IPK "Generate IPK using CPack" OFF)
60 option (RPM "Generate RPM using CPack" OFF)
61 option (BUILDPYTHON3 "Use python3 for building/installing" OFF)
62 option (ENABLEEXAMPLES "Disable building of examples" ON)
63 option (INSTALLGPIOTOOL "Install gpio tool" OFF)
64 option (BUILDARCH "Override architecture to build for - override" OFF)
65 option (TESTS "Override the addition of tests" ON)
68 set (BUILDSWIGPYTHON OFF)
69 set (BUILDSWIGNODE OFF)
70 set (BUILDSWIGJAVA OFF)
75 target_architecture (DETECTED_ARCH)
76 message( INFO " - Target arch is ${DETECTED_ARCH}")
78 set (DETECTED_ARCH ${BUILDARCH})
79 message( INFO " - Override arch is ${DETECTED_ARCH}")
82 if (DETECTED_ARCH STREQUAL "i586" OR DETECTED_ARCH STREQUAL "x86_64"
83 OR DETECTED_ARCH STREQUAL "i386")
85 elseif (DETECTED_ARCH MATCHES "arm.*")
88 message(FATAL_ERROR "Only x86 and arm platforms currently supported")
93 set (PYTHONBUILD_VERSION 3)
95 set (PYTHONBUILD_VERSION 2.7)
97 find_package (PythonInterp ${PYTHONBUILD_VERSION} REQUIRED)
99 if (${PYTHONINTERP_FOUND})
101 add_subdirectory (tests)
107 # add a target to generate API documentation with Doxygen
108 find_package (Doxygen)
110 configure_file (${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
111 add_custom_target (doc
112 ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
113 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
114 COMMENT "Generating API documentation with Doxygen" VERBATIM
116 endif (DOXYGEN_FOUND)
120 # Get target package arch from Yocto ADT sysroot if set or host OS, mapping to Ubuntu name if necessary
121 if (DEFINED ENV{OECORE_TARGET_SYSROOT})
122 GET_FILENAME_COMPONENT (DETECTED_SYSROOT $ENV{OECORE_TARGET_SYSROOT} NAME)
123 string (REGEX REPLACE "-poky-linux" "" TARGET_ARCH "${DETECTED_SYSROOT}")
125 # debian uses amd64 to denote x86_64
126 if (DETECTED_ARCH STREQUAL "x86_64")
127 set (TARGET_ARCH "amd64")
129 set (TARGET_ARCH ${DETECTED_ARCH})
132 message (INFO " - Package arch is ${TARGET_ARCH}")
134 set(CPACK_GENERATOR "DEB" "TGZ")
135 set(OPKG_ARCH ${TARGET_ARCH})
136 set(CPACK_BINARY_DIR ${CMAKE_BINARY_DIR})
137 set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Intel IoT-Devkit") #required
138 set(mraa_PACKAGE_ON_TAG ".")
139 if ("${VERSION_COMMIT}" STREQUAL "")
140 set(mraa_PACKAGE_ON_TAG "")
142 set(CPACK_PACKAGE_VERSION
143 "${mraa_VERSION_MAJOR}.${mraa_VERSION_MINOR}.${mraa_VERSION_PATCH}${mraa_PACKAGE_ON_TAG}${VERSION_COMMIT}")
144 set(CPACK_PACKAGE_NAME "mraa")
145 set(CPACK_DEBIAN_PACKAGE_SECTION "libs")
146 set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE ${TARGET_ARCH})
147 set(CPACK_SYSTEM_NAME ${TARGET_ARCH})
148 set(CPACK_DEBIAN_PACKAGE_PROVIDES "mraa-dev, mraa-dbg, mraa-doc")
149 set(CPACK_DEBIAN_PACKAGE_REPLACES "${CPACK_DEBIAN_PACKAGE_PROVIDES}, libmraa, libmraa-dev, libmraa-doc")
150 set(CPACK_DEBIAN_PACKAGE_CONFLICTS ${CPACK_DEBIAN_PACKAGE_PROVIDES})
151 set(WDIR "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}")
156 message (INFO " - Enabled RPM packaging for ${DETECTED_ARCH}")
157 set(CPACK_PACKAGE_VERSION ${VERSION})
158 set(CPACK_GENERATOR "RPM")
159 set(CPACK_PACKAGE_NAME "libmraa${mraa_VERSION_MAJOR}")
160 set(CPACK_PACKAGE_RELEASE 1)
161 set(CPACK_PACKAGE_VERSION
162 "${mraa_VERSION_MAJOR}.${mraa_VERSION_MINOR}.${mraa_VERSION_PATCH}${mraa_PACKAGE_ON_TAG}${VERSION_COMMIT}")
163 set(CPACK_PACKAGE_CONTACT "Intel IoT-Devkit")
164 set(CPACK_PACKAGE_VENDOR "Intel IoT-Devkit")
165 set(CPACK_RPM_PACKAGE_PROVIDES "${CPACK_PACKAGE_NAME}-devel")
166 EXECUTE_PROCESS(COMMAND rpm --showrc
167 COMMAND grep -E "dist[[:space:]]*\\."
168 COMMAND sed -e "s/^.*dist\\s*\\.//"
170 COMMAND sed -e s/\\t//
171 OUTPUT_VARIABLE DIST_TAG)
172 set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CPACK_PACKAGE_RELEASE}.${DIST_TAG}.${DETECTED_ARCH}")
176 add_subdirectory (src)
178 add_subdirectory (examples)