Skip to content

Build #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 36 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,33 +1,51 @@
cmake_minimum_required(VERSION 2.8.9)
cmake_minimum_required(VERSION 3.0)

project (MQTTAGENT C)
project(mqtt-tools
VERSION 0.1.0
LANGUAGES C)

file(GLOB headers "${CMAKE_CURRENT_SOURCE_DIR}/*.h")
#
# NOTE This project uses semantic versioning as described at
#
# https://semver.org/
#
# As long as all components (libraries, agents, helper) are in the
# same Git repository, all have to share the same version numbers,
# because those can not be distinguished with different tags.
#

set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)

# These libraries are noted here for later use
# Additional CMake modules
include(GNUInstallDirs) # cmake 2.8.5

# Options
option(BUILD_SHARED_LIBS
"Global flag to cause add_library to create shared libraries if on."
OFF
)

# Requirements (commented libraries noted here for later use)
find_library(CONFIG_LIBRARY NAMES config)
#find_library(PTHREAD_LIBRARY NAMES pthread)
#find_library(POPT_LIBRARY NAMES popt)
find_library(MOSQUITTO_LIBRARY NAMES mosquitto)

# Headers
configure_file(
mqtta-build.h.in
mqtta-build.h
@ONLY
)
include_directories(
"${CMAKE_CURRENT_BINARY_DIR}"
)
add_subdirectory(include/mqtt-tools)

# Libraries
add_subdirectory(lib)

# Agents
add_subdirectory(agents)

add_executable(mqtt-clock
mqtt-clock.c
mosqagent.c
mosqhelper.c
# Install CMake targets
install(EXPORT ${PROJECT_NAME}-targets
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
)

target_link_libraries(mqtt-clock ${CONFIG_LIBRARY})
# For later
#target_link_libraries(mqtt-clock ${POPT_LIBRARY})
#target_link_libraries(mqtt-clock ${PTHREAD_LIBRARY})
target_link_libraries(mqtt-clock ${MOSQUITTO_LIBRARY})
16 changes: 16 additions & 0 deletions agents/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
include_directories(
"${PROJECT_SOURCE_DIR}/include"
"${PROJECT_BINARY_DIR}/include"
)

# mqtt-clock
add_executable(mqtt-clock
mqtt-clock.c
)
target_link_libraries(mqtt-clock
mosqhelper
mqtta
)
install(TARGETS mqtt-clock
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
)
4 changes: 2 additions & 2 deletions mqtt-clock.c → agents/mqtt-clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
#include <time.h>
#include <sys/time.h>

#include "mosqagent.h"
#include "mosqhelper.h"
#include <mqtt-tools/mqtta.h>
#include <mqtt-tools/mosqhelper.h>

#define WITH_SYSLOG
#ifdef WITH_SYSLOG
Expand Down
File renamed without changes.
11 changes: 11 additions & 0 deletions include/mqtt-tools/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
configure_file(
mqtta-build.h.in
mqtta-build.h
@ONLY
)

install(FILES
mqtta.h
mosqhelper.h
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/mqtt-tools"
)
File renamed without changes.
File renamed without changes.
File renamed without changes.
42 changes: 42 additions & 0 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
include_directories(
"${PROJECT_SOURCE_DIR}/include/mqtt-tools"
"${PROJECT_BINARY_DIR}/include/mqtt-tools"
)

# mosqhelper
add_library(mosqhelper
mosqhelper.c
)
set_target_properties(mosqhelper PROPERTIES
OUTPUT_NAME mosqhelper
SOVERSION ${PROJECT_VERSION_MAJOR}
VERSION ${PROJECT_VERSION}
)
target_link_libraries(mosqhelper
"${MOSQUITTO_LIBRARY}"
)
install(TARGETS mosqhelper
EXPORT ${PROJECT_NAME}-targets
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
)

# mqtta
add_library(mqtta
mqtta.c
)
set_target_properties(mqtta PROPERTIES
OUTPUT_NAME mqtta
SOVERSION ${PROJECT_VERSION_MAJOR}
VERSION ${PROJECT_VERSION}
)
target_link_libraries(mqtta
mosqhelper
"${CONFIG_LIBRARY}"
"${MOSQUITTO_LIBRARY}"
)
install(TARGETS mqtta
EXPORT ${PROJECT_NAME}-targets
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
)
2 changes: 2 additions & 0 deletions mosqhelper.c → lib/mosqhelper.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include <syslog.h>
#include <unistd.h>

#include <mosquitto.h>

int mqtt_init(const char* clientname,
struct mosquitto **mosq,
void *mqtt_obj)
Expand Down
2 changes: 1 addition & 1 deletion mosqagent.c → lib/mqtta.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: MIT
*/

#include "mosqagent.h"
#include "mqtta.h"

#include <errno.h>
#include <stddef.h>
Expand Down