Switch completely to CMake for linux build, update Readme
This commit is contained in:
parent
6c5e517838
commit
e508c4e28d
3 changed files with 34 additions and 82 deletions
|
@ -1,5 +1,5 @@
|
||||||
cmake_minimum_required(VERSION 3.0)
|
cmake_minimum_required(VERSION 3.0)
|
||||||
project(LIBMQTT LANGUAGES C)
|
project(LIBMQTT)
|
||||||
|
|
||||||
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMakeModules)
|
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMakeModules)
|
||||||
|
|
||||||
|
|
|
@ -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
|
|
38
Readme.md
38
Readme.md
|
@ -30,12 +30,29 @@ And no, I will not do an Arduino port.
|
||||||
|
|
||||||
### Building on Linux
|
### Building on Linux
|
||||||
|
|
||||||
|
Requirements:
|
||||||
|
|
||||||
|
- CMake
|
||||||
|
- GCC
|
||||||
|
|
||||||
|
|
||||||
1. Checkout the repo
|
1. Checkout the repo
|
||||||
2. Run make:
|
2. Run cmake:
|
||||||
```bash
|
```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
|
### Testing on Linux
|
||||||
|
|
||||||
|
@ -47,13 +64,24 @@ Requirements:
|
||||||
#### Running the tests:
|
#### Running the tests:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
make -f Makefile.linux test
|
cd build
|
||||||
|
make check
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Building a coverage report
|
#### Building a coverage report
|
||||||
|
|
||||||
|
**Attention:** Only works in `DEBUG` mode, switch like this:
|
||||||
|
|
||||||
```bash
|
```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.
|
Be aware to create the coverage report the tests must run, so you'll need the MQTT broker.
|
||||||
|
|
Loading…
Reference in a new issue