Revert "CMakeLists.txt: add DEBUG define when doing a debug build"
[contrib/mraa.git] / CMakeLists.txt
1 cmake_minimum_required (VERSION 2.8)
2 project (mraa)
3
4 FIND_PACKAGE (Threads)
5
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
9 # Appends the cmake/modules path to MAKE_MODULE_PATH variable.
10 set (CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_PATH})
11
12 # Make a version file containing the current version from git.
13 include (GetGitRevisionDescription)
14 git_describe (VERSION "--tags")
15 if ("x_${VERSION}" STREQUAL "x_GIT-NOTFOUND")
16   message (WARNING " - Install git to compile a production libmraa!")
17   set (VERSION "v0.5.0-dirty")
18 endif ()
19
20 message (INFO " - libmraa Version ${VERSION}")
21
22 #parse the version information into pieces.
23 string (REGEX REPLACE "^v([0-9]+)\\..*" "\\1" VERSION_MAJOR "${VERSION}")
24 string (REGEX REPLACE "^v[0-9]+\\.([0-9]+).*" "\\1" VERSION_MINOR "${VERSION}")
25 string (REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" VERSION_PATCH "${VERSION}")
26 string (REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.[0-9]+\\-([0-9]+).*" "\\1" VERSION_COMMIT "${VERSION}")
27 string (REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.[0-9]+-[0-9]+\\-(.*)" "\\1" VERSION_SHA1 "${VERSION}")
28 set (VERSION_SHORT "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
29
30 if ("${VERSION_COMMIT}" MATCHES "^v.*")
31   set (VERSION_COMMIT "")
32 endif()
33
34 configure_file (${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/version.c.in
35                 ${CMAKE_CURRENT_BINARY_DIR}/src/version.c)
36
37 # this is the library version, independant of git revision
38 set (mraa_VERSION_MAJOR ${VERSION_MAJOR})
39 set (mraa_VERSION_MINOR ${VERSION_MINOR})
40 set (mraa_VERSION_PATCH ${VERSION_PATCH})
41 set (mraa_VERSION_STRING ${mraa_VERSION_MAJOR}.${mraa_VERSION_MINOR}.${mraa_VERSION_PATCH})
42
43 set (CMAKE_SWIG_FLAGS "")
44
45 find_path (SYSTEM_USR_DIR "stdlib.h")
46 include_directories (${SYSTEM_USR_DIR})
47
48 option (GTEST "Build all gtests." OFF)
49 option (BUILDDOC "Build all doc." OFF)
50 option (BUILDSWIG "Build swig modules." ON)
51 option (BUILDSWIGPYTHON "Build swig python modules." ON)
52 option (BUILDSWIGNODE "Build swig node modules." ON)
53 option (IPK "Generate IPK using CPack" OFF)
54
55 if (GTEST)
56   enable_testing ()
57   add_subdirectory (tests)
58 endif ()
59
60 if (BUILDDOC)
61   # add a target to generate API documentation with Doxygen
62   find_package (Doxygen)
63   if (DOXYGEN_FOUND)
64     configure_file (${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
65     add_custom_target (doc
66       ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
67       WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
68       COMMENT "Generating API documentation with Doxygen" VERBATIM
69     )
70   endif (DOXYGEN_FOUND)
71 endif ()
72
73 if (IPK)
74   include (TargetArch)
75   target_architecture (DETECTED_ARCH)
76   message( INFO " - Target arch is ${DETECTED_ARCH}")
77
78   set(CPACK_GENERATOR "DEB" "TGZ")
79   set(OPKG_ARCH ${DETECTED_ARCH})
80   set(CPACK_BINARY_DIR ${CMAKE_BINARY_DIR})
81   set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Intel IoT-Devkit") #required
82   set(mraa_PACKAGE_ON_TAG ".")
83   if ("${VERSION_COMMIT}" STREQUAL "")
84     set(mraa_PACKAGE_ON_TAG "")
85   endif()
86   set(CPACK_PACKAGE_VERSION 
87       "${mraa_VERSION_MAJOR}.${mraa_VERSION_MINOR}.${mraa_VERSION_PATCH}${mraa_PACKAGE_ON_TAG}${VERSION_COMMIT}")
88   set(CPACK_PACKAGE_NAME "libmraa${mraa_VERSION_MAJOR}")
89   set(CPACK_DEBIAN_PACKAGE_SECTION "libs")
90   set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE ${DETECTED_ARCH})
91   set(CPACK_SYSTEM_NAME ${DETECTED_ARCH})
92   set(CPACK_DEBIAN_PACKAGE_PROVIDES "libmraa-dev, libmraa-dbg, libmraa-doc, libmaa-dev, libmaa-dbg, libmaa-doc, libmaa0")
93   set(CPACK_DEBIAN_PACKAGE_REPLACES ${CPACK_DEBIAN_PACKAGE_PROVIDES})
94   set(CPACK_DEBIAN_PACKAGE_CONFLICTS ${CPACK_DEBIAN_PACKAGE_PROVIDES})
95   set(WDIR "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}")
96   include (CPack)
97 endif()
98
99 add_subdirectory (src)
100 add_subdirectory (examples)