diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..c3887693 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,108 @@ +cmake_minimum_required(VERSION 2.8) +project(ebusd) + +file(STRINGS "VERSION" VERSION) +set(PACKAGE ${CMAKE_PROJECT_NAME}) +set(PACKAGE_NAME ${CMAKE_PROJECT_NAME}) +set(PACKAGE_TARNAME ${CMAKE_PROJECT_NAME}) +set(PACKAGE_VERSION ${VERSION}) +set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}") +set(PACKAGE_BUGREPORT "ebusd@ebusd.eu") +set(PACKAGE_URL "ebusd@ebusd.eu") +set(PACKAGE_PIDFILE "${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/run/${PACKAGE}.pid") +set(PACKAGE_LOGFILE "${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/log/${PACKAGE}.log") +set(PACKAGE_CONFIGPATH "${CMAKE_INSTALL_FULL_SYSCONFDIR}/${PACKAGE}") +execute_process(COMMAND sed -e "s/^\\([0-9]*\\.[0-9]*\\).*/\\1/" -e "s/\\.\\([0-9]\\)\$/0\\1/" -e "s/\\.//" VERSION + OUTPUT_VARIABLE SCAN_VERSION) +execute_process(COMMAND git describe --always + OUTPUT_VARIABLE REVISION + OUTPUT_STRIP_TRAILING_WHITESPACE) +if(NOT REVISION) + execute_process(COMMAND date +p%Y%m%d + OUTPUT_VARIABLE REVISION + OUTPUT_STRIP_TRAILING_WHITESPACE) +endif(NOT REVISION) + +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_INSTALL_PREFIX "/") +include(GNUInstallDirs) +include(CheckFunctionExists) +include(CheckCXXSourceRuns) +include(CheckIncludeFile) + +add_compile_options(-fpic -Wall -Wextra) + +check_include_file(arpa/inet.h HAVE_ARPA_INET_H) +check_include_file(dirent.h HAVE_DIRENT_H) +check_include_file(fcntl.h HAVE_FCNTL_H) +check_include_file(netdb.h HAVE_NETDB_H) +check_include_file(poll.h HAVE_POLL_H) +check_include_file(pthread.h HAVE_PTHREAD_H) +check_include_file(sys/ioctl.h HAVE_SYS_IOCTL_H) +check_include_file(sys/select.h HAVE_SYS_SELECT_H) +check_include_file(sys/time.h HAVE_SYS_TIME_H) +check_include_file(time.h HAVE_TIME_H) +check_include_file(termios.h HAVE_TERMIOS_H) + +check_function_exists(pthread_setname_np HAVE_PTHREAD_SETNAME_NP) +find_library(RTLIB rt) + +check_function_exists(pselect HAVE_PSELECT) +check_function_exists(ppoll HAVE_PPOLL) + +option(coverage "enable code coverage tracking." OFF) +if(NOT coverage STREQUAL OFF) + add_compile_options(-coverage -O0) + message(STATUS "coverage enabled") +endif(NOT coverage STREQUAL OFF) +option(contrib "disable inclusion of contributed sources." ON) +if(contrib STREQUAL ON) + set(HAVE_CONTRIB ON) + message(STATUS "contrib enabled") +endif(contrib STREQUAL ON) +find_library(HAVE_MQTT mosquitto) +if(HAVE_MQTT) + option(mqtt "disable support for MQTT handling." ON) + if(mqtt STREQUAL ON) + message(STATUS "MQTT enabled") + else(mqtt STREQUAL ON) + unset(HAVE_MQTT) + endif(mqtt STREQUAL ON) +endif(HAVE_MQTT) + +check_cxx_source_runs(" +#include +int main() { + union { + uint32_t i; + float f; + } test; + test.f = 0.15; + return test.i == 0x3e19999a ? 0 : 1; +} +" HAVE_DIRECT_FLOAT_FORMAT) +if(NOT HAVE_DIRECT_FLOAT_FORMAT) + check_cxx_source_runs(" +#include +int main() { + union { + uint32_t i; + float f; + } test; + test.f = 0.15; + return test.i == 0x9a99193e ? 0 : 1; +} + " HAVE_DIRECT_FLOAT_FORMAT_REV) + if(HAVE_DIRECT_FLOAT_FORMAT_REV) + set(HAVE_DIRECT_FLOAT_FORMAT 2) + endif(HAVE_DIRECT_FLOAT_FORMAT_REV) +endif(NOT HAVE_DIRECT_FLOAT_FORMAT) + +add_definitions(-DHAVE_CONFIG_H -DSYSCONFDIR="${CMAKE_INSTALL_FULL_SYSCONFDIR}" -DLOCALSTATEDIR="${CMAKE_INSTALL_FULL_LOCALSTATEDIR}") +configure_file(config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h) +include_directories(${CMAKE_CURRENT_BINARY_DIR}) + +add_subdirectory(src/ebusd) +add_subdirectory(src/lib/utils) +add_subdirectory(src/lib/ebus) +add_subdirectory(src/tools) diff --git a/src/ebusd/CMakeLists.txt b/src/ebusd/CMakeLists.txt new file mode 100644 index 00000000..0247cd90 --- /dev/null +++ b/src/ebusd/CMakeLists.txt @@ -0,0 +1,29 @@ +add_compile_options(-Wconversion -Wno-unused-parameter) + +set(ebusd_SOURCES + bushandler.cpp + bushandler.h + datahandler.h + datahandler.cpp + network.cpp + network.h + mainloop.cpp + mainloop.h + main.h + main.cpp +) + +if(HAVE_MQTT) + set(ebusd_SOURCES ${ebusd_SOURCES} mqtthandler.cpp mqtthandler.h) + set(ebusd_LIBS ${ebusd_LIBS} mosquitto) +endif(HAVE_MQTT) + +if(HAVE_CONTRIB) + set(ebusd_LIBS ${ebusd_LIBS} ebuscontrib) +endif(HAVE_CONTRIB) + +include_directories(../lib/ebus) +include_directories(../lib/utils) + +add_executable(ebusd ${ebusd_SOURCES}) +target_link_libraries(ebusd utils ebus pthread rt ${ebusd_LIBS}) diff --git a/src/lib/ebus/CMakeLists.txt b/src/lib/ebus/CMakeLists.txt new file mode 100644 index 00000000..18d14ac8 --- /dev/null +++ b/src/lib/ebus/CMakeLists.txt @@ -0,0 +1,23 @@ +add_compile_options(-Wconversion -Wno-unused-parameter) + +set(libebus_a_SOURCES + result.cpp + result.h + symbol.cpp + symbol.h + filereader.h + datatype.cpp + datatype.h + data.cpp + data.h + device.cpp + device.h + message.cpp + message.h +) + +if(HAVE_CONTRIB) + add_subdirectory(contrib) +endif(HAVE_CONTRIB) + +add_library(ebus ${libebus_a_SOURCES}) diff --git a/src/lib/ebus/contrib/CMakeLists.txt b/src/lib/ebus/contrib/CMakeLists.txt new file mode 100644 index 00000000..ac442716 --- /dev/null +++ b/src/lib/ebus/contrib/CMakeLists.txt @@ -0,0 +1,12 @@ +add_compile_options(-Wno-unused-parameter) + +set(libebuscontrib_a_SOURCES + contrib.cpp + contrib.h + tem.cpp + tem.h +) + +include_directories(..) + +add_library(ebuscontrib ${libebuscontrib_a_SOURCES}) diff --git a/src/lib/utils/CMakeLists.txt b/src/lib/utils/CMakeLists.txt new file mode 100644 index 00000000..1113e273 --- /dev/null +++ b/src/lib/utils/CMakeLists.txt @@ -0,0 +1,18 @@ +add_compile_options(-Wconversion) + +set(libutils_a_SOURCES + log.cpp + log.h + tcpsocket.cpp + tcpsocket.h + thread.cpp + thread.h + clock.cpp + clock.h + queue.h + notify.h + rotatefile.cpp + rotatefile.h +) + +add_library(utils ${libutils_a_SOURCES}) diff --git a/src/tools/CMakeLists.txt b/src/tools/CMakeLists.txt new file mode 100644 index 00000000..7dbbabd9 --- /dev/null +++ b/src/tools/CMakeLists.txt @@ -0,0 +1,14 @@ +set(ebusctl_SOURCES ebusctl.cpp) +set(ebusfeed_SOURCES ebusfeed.cpp) + +if(HAVE_CONTRIB) + set(ebusfeed_LIBS ${ebusfeed_LIBS} ebuscontrib) +endif(HAVE_CONTRIB) + +include_directories(../lib/ebus) +include_directories(../lib/utils) + +add_executable(ebusctl ${ebusctl_SOURCES}) +add_executable(ebusfeed ${ebusfeed_SOURCES}) +target_link_libraries(ebusctl utils ebus ${ebusctl_LIBS}) +target_link_libraries(ebusfeed ebus ${ebusfeed_LIBS})