Home | History | Annotate | Download | only in libmraa
      1 cmake_minimum_required (VERSION 2.8)
      2 project (mraa C)
      3 
      4 FIND_PACKAGE (Threads REQUIRED)
      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 set (LIB_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}" CACHE PATH "Installation path for libraries")
      9 
     10 # Set CMAKE_LIB_INSTALL_DIR if not defined
     11 include(GNUInstallDirs)
     12 
     13 # By default, build shared object libraries on linux
     14 if (UNIX AND NOT APPLE)
     15   if (NOT DEFINED BUILD_SHARED_LIBS)
     16     set(BUILD_SHARED_LIBS ON)
     17   endif()
     18 endif()
     19 
     20 # Appends the cmake/modules path to MAKE_MODULE_PATH variable.
     21 set (CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_PATH})
     22 
     23 # Make a version file containing the current version from git.
     24 include (GetGitRevisionDescription)
     25 git_describe (VERSION "--tags")
     26 if ("x_${VERSION}" STREQUAL "x_GIT-NOTFOUND" OR "x_${VERSION}" STREQUAL "x_HEAD-HASH-NOTFOUND" OR "x_${VERSION}" STREQUAL "x_-128-NOTFOUND")
     27   message (WARNING " - Install git to compile a production libmraa!")
     28   set (VERSION "v0.9.0-dirty")
     29 endif ()
     30 
     31 message (INFO " - libmraa Version ${VERSION}")
     32 
     33 #parse the version information into pieces.
     34 string (REGEX REPLACE "^v([0-9]+)\\..*" "\\1" VERSION_MAJOR "${VERSION}")
     35 string (REGEX REPLACE "^v[0-9]+\\.([0-9]+).*" "\\1" VERSION_MINOR "${VERSION}")
     36 string (REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" VERSION_PATCH "${VERSION}")
     37 string (REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.[0-9]+\\-([0-9]+).*" "\\1" VERSION_COMMIT "${VERSION}")
     38 string (REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.[0-9]+-[0-9]+\\-(.*)" "\\1" VERSION_SHA1 "${VERSION}")
     39 set (VERSION_SHORT "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
     40 
     41 if ("${VERSION_COMMIT}" MATCHES "^v.*")
     42   set (VERSION_COMMIT "")
     43 endif()
     44 
     45 configure_file (${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/version.c.in
     46                 ${CMAKE_CURRENT_BINARY_DIR}/src/version.c)
     47 
     48 # this is the library version, independant of git revision
     49 set (mraa_VERSION_MAJOR ${VERSION_MAJOR})
     50 set (mraa_VERSION_MINOR ${VERSION_MINOR})
     51 set (mraa_VERSION_PATCH ${VERSION_PATCH})
     52 set (mraa_VERSION_STRING ${mraa_VERSION_MAJOR}.${mraa_VERSION_MINOR}.${mraa_VERSION_PATCH})
     53 
     54 set (CMAKE_SWIG_FLAGS "")
     55 
     56 find_path (SYSTEM_USR_DIR "stdlib.h")
     57 include_directories (${SYSTEM_USR_DIR})
     58 
     59 option (BUILDDOC "Build all doc." OFF)
     60 option (BUILDSWIG "Build swig modules." ON)
     61 option (BUILDSWIGPYTHON "Build swig python modules." ON)
     62 option (BUILDSWIGNODE "Build swig node modules." ON)
     63 option (BUILDSWIGJAVA "Build Java API." OFF)
     64 option (USBPLAT "Detection USB platform." OFF)
     65 option (FTDI4222 "Build with FTDI FT4222 subplatform support." OFF)
     66 option (IPK "Generate IPK using CPack" OFF)
     67 option (RPM "Generate RPM using CPack" OFF)
     68 option (BUILDPYTHON3 "Use python3 for building/installing/testing" OFF)
     69 option (ENABLEEXAMPLES "Disable building of examples" ON)
     70 option (INSTALLGPIOTOOL "Install gpio tool" OFF)
     71 option (BUILDARCH "Override architecture to build for - override" OFF)
     72 option (BUILDTESTS "Override the addition of tests" ON)
     73 
     74 set (MRAAPLATFORMFORCE "" CACHE STRING "ALL")
     75 
     76 if (NOT BUILDSWIG)
     77   set (BUILDSWIGPYTHON OFF)
     78   set (BUILDSWIGNODE OFF)
     79   set (BUILDSWIGJAVA OFF)
     80 endif()
     81 
     82 if (NOT BUILDARCH)
     83   include (TargetArch)
     84   target_architecture (DETECTED_ARCH)
     85   message( INFO " - Target arch is ${DETECTED_ARCH}")
     86 else ()
     87   set (DETECTED_ARCH ${BUILDARCH})
     88   message( INFO " - Override arch is ${DETECTED_ARCH}")
     89 endif()
     90 
     91 if (DETECTED_ARCH STREQUAL "i586" OR DETECTED_ARCH STREQUAL "x86_64"
     92     OR DETECTED_ARCH STREQUAL "i386")
     93   set (X86PLAT ON)
     94 elseif (DETECTED_ARCH MATCHES "arm.*")
     95   set (ARMPLAT ON)
     96 else ()
     97   message(FATAL_ERROR "Only x86 and arm platforms currently supported")
     98 endif()
     99 
    100 if (BUILDSWIGPYTHON OR BUILDTESTS)
    101   if (BUILDPYTHON3)
    102     set (PYTHONBUILD_VERSION 3)
    103   else ()
    104     set (PYTHONBUILD_VERSION 2.7)
    105   endif ()
    106   find_package (PythonInterp ${PYTHONBUILD_VERSION} REQUIRED)
    107 endif ()
    108 
    109 if (BUILDDOC)
    110   # add a target to generate API documentation with Doxygen
    111   find_package (Doxygen)
    112   if (DOXYGEN_FOUND)
    113     configure_file (${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
    114     if (BUILDSWIGJAVA)
    115       configure_file (${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.java.in ${CMAKE_CURRENT_BINARY_DIR}/src/java/Doxyfile @ONLY)
    116     endif ()
    117     add_custom_target (doc
    118       ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
    119       WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
    120       COMMENT "Generating API documentation with Doxygen" VERBATIM
    121     )
    122   endif (DOXYGEN_FOUND)
    123 endif ()
    124 
    125 if (IPK)
    126   # Get target package arch from Yocto ADT sysroot if set or host OS, mapping to Ubuntu name if necessary
    127   if (DEFINED ENV{OECORE_TARGET_SYSROOT})
    128     GET_FILENAME_COMPONENT (DETECTED_SYSROOT $ENV{OECORE_TARGET_SYSROOT} NAME)
    129     string (REGEX REPLACE "-poky-linux" "" TARGET_ARCH "${DETECTED_SYSROOT}")
    130   else ()
    131     # debian uses amd64 to denote x86_64
    132     if (DETECTED_ARCH STREQUAL "x86_64")
    133       set (TARGET_ARCH "amd64")
    134     else ()
    135       set (TARGET_ARCH ${DETECTED_ARCH})
    136     endif ()
    137   endif ()
    138   message (INFO " - Package arch is ${TARGET_ARCH}")
    139 
    140   set(CPACK_GENERATOR "DEB" "TGZ")
    141   set(OPKG_ARCH ${TARGET_ARCH})
    142   set(CPACK_BINARY_DIR ${CMAKE_BINARY_DIR})
    143   set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Intel IoT-Devkit") #required
    144   set(mraa_PACKAGE_ON_TAG ".")
    145   if ("${VERSION_COMMIT}" STREQUAL "")
    146     set(mraa_PACKAGE_ON_TAG "")
    147   endif()
    148   set(CPACK_PACKAGE_VERSION 
    149       "${mraa_VERSION_MAJOR}.${mraa_VERSION_MINOR}.${mraa_VERSION_PATCH}${mraa_PACKAGE_ON_TAG}${VERSION_COMMIT}")
    150   set(CPACK_PACKAGE_NAME "mraa")
    151   set(CPACK_DEBIAN_PACKAGE_SECTION "libs")
    152   set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE ${TARGET_ARCH})
    153   set(CPACK_SYSTEM_NAME ${TARGET_ARCH})
    154   set(CPACK_DEBIAN_PACKAGE_PROVIDES "mraa-dev, mraa-dbg, mraa-doc")
    155   set(CPACK_DEBIAN_PACKAGE_REPLACES "${CPACK_DEBIAN_PACKAGE_PROVIDES}, libmraa, libmraa-dev, libmraa-doc")
    156   set(CPACK_DEBIAN_PACKAGE_CONFLICTS ${CPACK_DEBIAN_PACKAGE_PROVIDES})
    157   set(WDIR "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}")
    158   include (CPack)
    159 endif()
    160 
    161 if (RPM)
    162   message (INFO " - Enabled RPM packaging for ${DETECTED_ARCH}")
    163   set(CMAKE_INSTALL_PREFIX "/usr")
    164   set(CPACK_PACKAGE_VERSION ${VERSION})
    165   set(CPACK_GENERATOR "RPM")
    166   set(CPACK_PACKAGE_NAME "libmraa${mraa_VERSION_MAJOR}")
    167   set(CPACK_PACKAGE_RELEASE 1)
    168   set(CPACK_PACKAGE_VERSION
    169       "${mraa_VERSION_MAJOR}.${mraa_VERSION_MINOR}.${mraa_VERSION_PATCH}${mraa_PACKAGE_ON_TAG}${VERSION_COMMIT}")
    170   set(CPACK_PACKAGE_CONTACT "Intel IoT-Devkit")
    171   set(CPACK_PACKAGE_VENDOR "Intel IoT-Devkit")
    172   set(CPACK_RPM_PACKAGE_PROVIDES "${CPACK_PACKAGE_NAME}-devel")
    173   # Get distro tag (e.g. 'fc20') by parsing output of rpm --showrc
    174   EXECUTE_PROCESS(
    175     COMMAND rpm --showrc
    176     COMMAND grep -w dist
    177     COMMAND sed -e "s/\\t./ /"
    178     COMMAND awk "{printf \"%s\", \$NF}"
    179     OUTPUT_VARIABLE DIST_TAG
    180   )
    181   set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CPACK_PACKAGE_RELEASE}.${DIST_TAG}.${DETECTED_ARCH}")
    182   include(CPack)
    183 endif()
    184 
    185 add_subdirectory (src)
    186 if (ENABLEEXAMPLES)
    187   add_subdirectory (examples)
    188 endif ()
    189 
    190 if (BUILDTESTS)
    191   if (${PYTHONINTERP_FOUND})
    192     enable_testing ()
    193     add_subdirectory (tests)
    194   endif ()
    195 endif ()
    196