Commit b1dd53a2 authored by Johan Ström's avatar Johan Ström

Fix detection of i2c

On Fedora we have linux/i2c-dev.h, but it does not hold i2c_smbus_ definitions, so do not try to use it just
because it exists.
parent 3231129d
......@@ -15,7 +15,7 @@ include(cmake/AgoFileHelpers.cmake)
find_package(PythonNaive)
# FreeBSD have some differences in building, mainly
# FreeBSD have some differences in building, mainly
# that non-base libs/includes are located in /usr/local.
IF (CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
set (FREEBSD YES)
......@@ -151,17 +151,8 @@ ELSE()
set(BUILD_TESTS_DEFAULT OFF)
ENDIF()
# Different linux distributions places i2c-dev.h at different locations
# For example, debian uses linux/i2c-dev.h, but Fedora 27 uses i2c-tools/i2c-dev.h
# Since it seems wrong to include /usr/include/linux as -I, this detects the location
# and sets a HAVE_ def instead which the code then can use to include the wanted one.
check_include_files("linux/i2c-dev.h" HAVE_LINUX_I2C_DEV_H)
check_include_files("i2c-tools/i2c-dev.h" HAVE_I2CTOOLS_I2C_DEV_H)
check_include_files("xlocale.h" HAVE_XLOCALE_H)
set (ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${LIBDIR}")
set (LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${LIBDIR}")
set (RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${BINDIR}")
......@@ -175,21 +166,13 @@ else()
set (IN_SOURCE_BUILD FALSE)
endif()
# configure a header file to pass some of the CMake settings
# to the source code
configure_file (
"${PROJECT_SOURCE_DIR}/build_config.h.in"
"${PROJECT_BINARY_DIR}/build_config.h"
@ONLY
)
# Shared for all
install(DIRECTORY DESTINATION ${BINDIR})
# add sub directories
OPTION(BUILD_SHARED "Build the agoclient shared library" ON)
if (BUILD_SHARED)
add_subdirectory (shared)
add_subdirectory (shared)
endif()
OPTION(BUILD_TESTS "Build the unittests" ${BUILD_TESTS_DEFAULT})
......@@ -201,26 +184,35 @@ endif()
OPTION(BUILD_CORE "Build the CORE" ON)
if (BUILD_CORE)
add_subdirectory (core)
add_subdirectory (core)
install (FILES data/inventory.sql data/datalogger.sql DESTINATION ${DATADIR})
endif()
OPTION(BUILD_GATEWAYS "Build the gateways" ON)
if (BUILD_GATEWAYS)
add_subdirectory (gateways)
add_subdirectory (gateways)
endif()
OPTION(BUILD_DEVICES "Build the devices" ON)
if (BUILD_DEVICES)
add_subdirectory (devices)
add_subdirectory (devices)
endif()
OPTION(BUILD_CONF "Build the configs" ON)
if (BUILD_CONF)
add_subdirectory (conf)
add_subdirectory (conf)
endif()
OPTION(BUILD_SCRIPTS "Build the scripts" ON)
if (BUILD_SCRIPTS)
add_subdirectory (scripts)
endif()
# configure a header file to pass some of the CMake settings
# to the source code
configure_file (
"${PROJECT_SOURCE_DIR}/build_config.h.in"
"${PROJECT_BINARY_DIR}/build_config.h"
@ONLY
)
......@@ -2,8 +2,9 @@
#define AGOCONTROL_VERSION @AGOCONTROL_VERSION@
#cmakedefine HAVE_LINUX_I2C_DEV_H @HAVE_LINUX_I2C_DEV_H@
#cmakedefine HAVE_I2CTOOLS_I2C_DEV_H @HAVE_I2CTOOLS_I2C_DEV_H@
#cmakedefine HAVE_I2C_SMBUS_VIA_I2C_TOOLS @HAVE_I2C_SMBUS_VIA_I2C_TOOLS@
#cmakedefine HAVE_I2C_SMBUS_VIA_LINUX_I2C_DEV @HAVE_I2C_SMBUS_VIA_LINUX_I2C_DEV@
#cmakedefine HAVE_XLOCALE_H @HAVE_XLOCALE_H@
#endif
\ No newline at end of file
# Different linux distributions places i2c-dev.h at different locations, with different contents.
# For example on debian i2c_smbus_write_i2c_block_data is provided by linux/i2c-dev.h, but Fedora 27 uses i2c-tools/i2c-dev.h
# even if it has linux/i2c-dev.h.
# This tries to figure out which file to include.
include (CheckSymbolExists)
check_symbol_exists(i2c_smbus_write_i2c_block_data i2c-tools/i2c-dev.h HAVE_I2C_SMBUS_VIA_I2C_TOOLS)
check_symbol_exists(i2c_smbus_write_i2c_block_data linux/i2c-dev.h HAVE_I2C_SMBUS_VIA_LINUX_I2C_DEV)
if(HAVE_I2C_SMBUS_VIA_I2C_TOOLS)
message(STATUS "i2c_smbus_write_i2c_block_data available through i2c-tools/i2c-dev.h")
set(HAVE_I2C_SMBUS 1)
elseif(HAVE_I2C_SMBUS_VIA_LINUX_I2C_DEV)
message(STATUS "i2c_smbus_write_i2c_block_data available through linux/i2c-dev.h")
set(HAVE_I2C_SMBUS 1)
else()
message(STATUS "i2c_smbus_write_i2c_block_data not available, consider installing package providing i2c-tools")
set(HAVE_I2C_SMBUS 0)
endif()
......@@ -54,38 +54,42 @@ set (AGODEVICES
agoping
)
FIND_PACKAGE(OpenCV)
find_package(OpenCV)
IF (NOT OpenCV_FOUND)
list(REMOVE_ITEM AGODEVICES NVR)
MESSAGE(STATUS "OpenCV not found, NOT building NVR device")
ENDIF (NOT OpenCV_FOUND)
FIND_PACKAGE(OpenZWave)
find_package(OpenZWave)
IF (NOT OpenZWave_FOUND)
list(REMOVE_ITEM AGODEVICES zwave)
MESSAGE(STATUS "OpenZWave not found, NOT building zwave device")
ENDIF ()
FIND_PACKAGE(EibClient)
find_package(EibClient)
IF (NOT EibClient_FOUND)
list(REMOVE_ITEM AGODEVICES knx)
MESSAGE(STATUS "eibclient not found, NOT building knx device")
ENDIF ()
find_package(PkgConfig)
pkg_check_modules(OpenLighting libola)
IF (NOT OpenLighting_FOUND)
list(REMOVE_ITEM AGODEVICES agodmx)
MESSAGE(STATUS "OpenLighting (ola) not found, NOT building agodmx device")
ENDIF ()
if(NOT FREEBSD)
find_package(LinuxI2C)
endif()
if(NOT HAVE_I2C_SMBUS)
list(REMOVE_ITEM AGODEVICES i2c blinkm)
endif()
IF (FREEBSD)
# These does not build on FreeBSD currently
list(REMOVE_ITEM AGODEVICES
blinkm # linux/i2c-dev.h
firmata # S_IRUSR
i2c # linux/i2c-dev.h
PLCBUS # TCIFLUSH / TCIOFLUSH
MySensors # TCIFLUSH / TCIOFLUSH
zmcam # error: member access into incomplete type 'struct sockaddr_in'
......
......@@ -7,15 +7,7 @@
#include <sys/ioctl.h>
#include "build_config.h"
#if HAVE_LINUX_I2C_DEV_H
#include <linux/i2c-dev.h>
#elif HAVE_I2CTOOLS_I2C_DEV_H
#include <i2c-tools/i2c-dev.h>
#else
#error "i2c-dev.h not found"
#endif
#include "../i2c_include.h"
#include "agoapp.h"
......
......@@ -37,13 +37,7 @@ Circuit detail:
#include <stdlib.h>
#include <unistd.h>
#if HAVE_LINUX_I2C_DEV_H
#include <linux/i2c-dev.h>
#elif HAVE_I2CTOOLS_I2C_DEV_H
#include <i2c-tools/i2c-dev.h>
#else
#error "i2c-dev.h not found"
#endif
#include "../i2c_include.h"
#include <sys/ioctl.h>
......
......@@ -7,14 +7,7 @@
#include <sys/ioctl.h>
#include "build_config.h"
#if HAVE_LINUX_I2C_DEV_H
#include <linux/i2c-dev.h>
#elif HAVE_I2CTOOLS_I2C_DEV_H
#include <i2c-tools/i2c-dev.h>
#else
#error "i2c-dev.h not found"
#endif
#include "../i2c_include.h"
#include "agoapp.h"
......
#ifndef AGOCONTROL_I2C_INCLUDE_H
#define AGOCONTROL_I2C_INCLUDE_H
/* This file interacts with cmake/Modules/FindLinuxI2C.cmake
* and can be included to pick the proper header to use for accessing i2c_smbus_*
*/
#include "build_config.h"
#if HAVE_I2C_SMBUS_VIA_I2C_TOOLS
#include <i2c-tools/i2c-dev.h>
#elif HAVE_I2C_SMBUS_VIA_LINUX_I2C_DEV
#include <linux/i2c-dev.h>
#else
#error "i2c-dev.h not found"
#endif
#endif //AGOCONTROL_I2C_INCLUDE_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment