diff --git a/CMakeLists.txt b/CMakeLists.txt index b244d97..06e424c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.0) -project(LIBMQTT LANGUAGES C) +project(LIBMQTT) set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMakeModules) diff --git a/Makefile.linux b/Makefile.linux deleted file mode 100644 index c8aba7d..0000000 --- a/Makefile.linux +++ /dev/null @@ -1,76 +0,0 @@ -SRCS=src/mqtt.c src/packet.c src/protocol.c src/state_queue.c src/subscriptions.c platform/linux.c -OBJS=$(SRCS:%.c=%.o) -DEBUG_OBJS=$(SRCS:%.c=%.do) -COVERAGE_FILES=$(SRCS:%.c=%.gcno) $(SRCS:%.c=%.gcda) - -TARGET=libmqtt.a -DEBUG_TARGET=libmqtt-debug.a - -MAJOR_VERSION=0 -MINOR_VERSION=1 - -PLATFORM_FLAGS= - -AR=ar -CC=gcc -EXTRA_CFLAGS= -CFLAGS=-g -Os -Wall -pthread -I./platform -I./src $(EXTRA_CFLAGS) $(PLATFORM_FLAGS) -COVERAGE_FLAGS=-fprofile-arcs -ftest-coverage -DEBUG_FLAGS=-DDEBUG=1 $(COVERAGE_FLAGS) - -all: $(TARGET) $(DEBUG_TARGET) - -test: - $(MAKE) EXTRA_CFLAGS="-DMQTT_SERVER=1 -DMQTT_CLIENT=1" clean all - $(MAKE) -C tests - $(MAKE) clean - -coverage: - $(MAKE) EXTRA_CFLAGS="-DMQTT_SERVER=1 -DMQTT_CLIENT=1" clean all - $(MAKE) DEBUG_FLAGS= -C tests clean all - lcov --capture --directory . --output-file lcov.info - rm -rf coverage - mkdir -p coverage - genhtml -o coverage lcov.info - -dist: $(TARGET) - mkdir -p dist/include - mkdir -p dist/lib - cp libmqtt.a dist/lib - cp src/mqtt.h dist/include - (cd dist && tar czvf ../libmqtt-$(MAJOR_VERSION).$(MINOR_VERSION).tar.gz .) - -src/mqtt.h: src/mqtt.h.in - sed \ - -e 's/@LIBMQTT_VERSION_MAJOR@/'$(MAJOR_VERSION)'/' \ - -e 's/@LIBMQTT_VERSION_MINOR@/'$(MINOR_VERSION)'/' \ - -e 's/@LIBMQTT_BUILD_DATE@/"'`date +%Y-%m-%d_%H-%M-%S`'"/' \ - src/mqtt.h.in >src/mqtt.h - - -$(TARGET): $(OBJS) - $(AR) -cr $(TARGET) $(OBJS) - -$(DEBUG_TARGET): $(DEBUG_OBJS) - $(AR) -cr $(DEBUG_TARGET) $(DEBUG_OBJS) - -%.do: %.c src/mqtt.h - $(CC) $(CFLAGS) $(DEBUG_FLAGS) -o $@ -c $< - -%.o: %.c src/mqtt.h - $(CC) $(CFLAGS) -o $@ -c $< - -mqtt.o: mqtt.h - -clean: - $(MAKE) -C tests clean - rm -f $(TARGET) $(DEBUG_TARGET) - rm -f $(OBJS) $(DEBUG_OBJS) - rm -f $(COVERAGE_FILES) - rm -f *.gcov - rm -rf docs/ - rm -rf coverage/ - rm -rf dist/ - rm -f libmqtt-$(MAJOR_VERSION).$(MINOR_VERSION).tar.gz - -.PHONY: coverage test src/mqtt.h diff --git a/Readme.md b/Readme.md index 4518682..7914381 100644 --- a/Readme.md +++ b/Readme.md @@ -30,12 +30,29 @@ And no, I will not do an Arduino port. ### Building on Linux +Requirements: + +- CMake +- GCC + + 1. Checkout the repo -2. Run make: +2. Run cmake: ```bash -make -f Makefile.linux +mkdir build +cd build +cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX:PATH=/ .. ``` -3. Grab `libmqtt.a` or `libmqtt-debug.a` and `src/mqtt.h` and add that into your project. +3. Build the library +```bash +cd build +make all +``` +4. Install/Make a Distribution (Only works in `RELEASE` mode) +```bash +make DESTDIR=/path/to/put/it install +``` +The dynamic and static libs will be placed in the `lib/` sub-dir of that folder and the include in `include/mqtt/mqtt.h` ### Testing on Linux @@ -47,13 +64,24 @@ Requirements: #### Running the tests: ```bash -make -f Makefile.linux test +cd build +make check ``` #### Building a coverage report +**Attention:** Only works in `DEBUG` mode, switch like this: + ```bash -make -f Makefile.linux coverage +cd build +cmake -DCMAKE_BUILD_TYPE=Debug .. +``` + +Building the report: + +```bash +cd build +make coverage ``` Be aware to create the coverage report the tests must run, so you'll need the MQTT broker.