From d432689f646b681c9253465a4a8be3f3271a68b5 Mon Sep 17 00:00:00 2001 From: Peter O'Hanley Date: Fri, 2 Nov 2018 12:46:35 -0500 Subject: [PATCH] Converted build system to cmake, removed redundant file --- .gitignore | 6 ++++ CMakeLists.txt | 35 ++++++++++++++++++++++ Makefile | 48 ------------------------------ src/binary_semaphore.c | 4 +-- src/config.h | 3 -- src/crc16.c | 4 ++- src/crc16.h | 7 ++--- src/spi_chunks.cpp | 4 +-- src/spi_chunks.h | 8 ++++- src/spi_proto.c | 11 +++---- src/spi_proto.h | 4 +-- src/spi_proto_util.c | 5 ++-- test/spi_proto_tests.c | 4 +-- test/test_chunks.c | 3 +- test/test_longer_random_messages.c | 3 +- test/test_resync.c | 3 +- 16 files changed, 70 insertions(+), 82 deletions(-) create mode 100644 CMakeLists.txt delete mode 100644 Makefile delete mode 100644 src/config.h diff --git a/.gitignore b/.gitignore index 1c4d7b7..373c734 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,9 @@ *.a tmtags* +#CMake +CMakeFiles +CMakeCache.txt +Makefile +cmake_install.cmake + diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..2cba901 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,35 @@ +SET(CFLAGS -Wall -Wextra -Wno-missing-braces -Wno-unused-variable -Wno-unused-parameter) + +set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) + +project(spi_proto) + +add_library(spiproto STATIC src/spi_proto.c src/crc16.c src/spi_chunks.cpp) + +add_executable(resync_test test/test_resync.c test/test_util.c) +target_link_libraries(resync_test spiproto) +target_include_directories(resync_test PUBLIC src/ PUBLIC test/) + +add_executable(spi_test test/spi_proto_tests.c test/test_util.c src/spi_proto_util.c) +target_link_libraries(spi_test spiproto) +target_include_directories(spi_test PUBLIC src/ PUBLIC test/) + +add_executable(test_longer_random_messages test/test_longer_random_messages.c test/test_util.c) +target_link_libraries(test_longer_random_messages spiproto) +target_include_directories(test_longer_random_messages PUBLIC src/ PUBLIC test/) + +add_executable(chunk_test test/test_chunks.c test/test_util.c src/spi_proto_util.c) +target_link_libraries(chunk_test spiproto) +target_include_directories(chunk_test PUBLIC src/ PUBLIC test/) + +#TODO can only run on linux +#click-test: test/click-test.cpp libspiproto.a spi_chunks.o test/test_util.o spi_proto_util.o +# #g++ $(CFLAGS) -o click-test test/click-test.cpp -std=c++14 -pthread spi_chunks.o test/test_util.o spi_proto_util.o -L. -lspiproto -I. -Isrc +# g++ test/click-test.cpp src/spi_proto_master.cpp src/spi_chunks.cpp -std=c++14 -pthread -x c src/binary_semaphore.c -x c src/spi_proto.c -I. -Isrc/ -x c src/crc16.c -x c src/spi_remote_host.c -o click-test -g + +#TODO can only run on linux +#blip-test: test/blip-test.cpp libspiproto.a spi_chunks.o test/test_util.o spi_proto_util.o +# #g++ $(CFLAGS) -o blip-test test/blip-test.cpp -std=c++14 -pthread spi_chunks.o test/test_util.o spi_proto_util.o -L. -lspiproto -I. -Isrc +# g++ test/blip-test.cpp src/spi_proto_master_datagram.cpp src/spi_chunks.cpp -std=c++14 -pthread -x c src/binary_semaphore.c -x c src/spi_proto.c -I. -Isrc/ -x c src/crc16.c -x c src/spi_remote_host.c -o blip-test -g diff --git a/Makefile b/Makefile deleted file mode 100644 index fe35905..0000000 --- a/Makefile +++ /dev/null @@ -1,48 +0,0 @@ -CFLAGS=-Wall -Wextra -Wno-missing-braces -Wno-unused-variable -Wno-unused-parameter - -all : spi_test msg_test chunk_test resync_test spi_proto.o spi_chunks.o click-test blip-test - -spi_test: test/spi_proto_tests.c libspiproto.a test/test_util.o spi_proto_util.o - gcc $(CFLAGS) -o spi_test test/spi_proto_tests.c test/test_util.o crc16.o spi_proto_util.o -L. -lspiproto -I. -Isrc - -msg_test: test/test_longer_random_messages.c libspiproto.a test/test_util.o spi_proto_util.o - gcc $(CFLAGS) -o msg_test test/test_longer_random_messages.c test/test_util.o spi_proto_util.o -L. -lspiproto -I. -Isrc - -chunk_test: test/test_chunks.c libspiproto.a spi_chunks.o test/test_util.o spi_proto_util.o - gcc $(CFLAGS) -o chunk_test test/test_chunks.c spi_chunks.o test/test_util.o spi_proto_util.o -L. -lspiproto -I. -Isrc - -resync_test: test/test_resync.c libspiproto.a spi_chunks.o test/test_util.o spi_proto_util.o - gcc $(CFLAGS) -o resync_test test/test_resync.c spi_chunks.o test/test_util.o spi_proto_util.o -L. -lspiproto -I. -Isrc - -spi_proto.o: src/spi_proto.c src/spi_proto.h - gcc $(CFLAGS) -c src/spi_proto.c -std=c99 -Isrc - -spi_proto_util.o: src/spi_proto_util.c src/spi_proto_util.h - gcc $(CFLAGS) -c src/spi_proto_util.c -std=c99 -Isrc - -spi_chunks.o: src/spi_chunks.cpp src/spi_chunks.h - gcc $(CFLAGS) -c -x c src/spi_chunks.cpp -std=c99 - -crc16.o: src/crc16.c - gcc $(CFLAGS) -c src/crc16.c - -test/test_util.o: test/test_util.c - gcc $(CFLAGS) -c test/test_util.c -o test/test_util.o - -clean: - rm -f spi_test msg_test chunk_test resync_test spi_proto.o spi_chunks.o crc16.o test/test_util.o libspiproto.a binary_semaphore.o spi_proto_util.o spi_remote.o - rm -f click-test blip-test - -libspiproto.a: spi_proto.o crc16.o - ar rc libspiproto.a spi_proto.o crc16.o - ranlib libspiproto.a - -click-test: test/click-test.cpp libspiproto.a spi_chunks.o test/test_util.o spi_proto_util.o - #g++ $(CFLAGS) -o click-test test/click-test.cpp -std=c++14 -pthread spi_chunks.o test/test_util.o spi_proto_util.o -L. -lspiproto -I. -Isrc - g++ test/click-test.cpp src/spi_proto_master.cpp src/spi_chunks.cpp -std=c++14 -pthread -x c src/binary_semaphore.c -x c src/spi_proto.c -I. -Isrc/ -x c src/crc16.c -x c src/spi_remote_host.c -o click-test -g - - -blip-test: test/blip-test.cpp libspiproto.a spi_chunks.o test/test_util.o spi_proto_util.o - #g++ $(CFLAGS) -o blip-test test/blip-test.cpp -std=c++14 -pthread spi_chunks.o test/test_util.o spi_proto_util.o -L. -lspiproto -I. -Isrc - g++ test/blip-test.cpp src/spi_proto_master_datagram.cpp src/spi_chunks.cpp -std=c++14 -pthread -x c src/binary_semaphore.c -x c src/spi_proto.c -I. -Isrc/ -x c src/crc16.c -x c src/spi_remote_host.c -o blip-test -g - diff --git a/src/binary_semaphore.c b/src/binary_semaphore.c index d9c8cfd..bdeaf95 100644 --- a/src/binary_semaphore.c +++ b/src/binary_semaphore.c @@ -1,6 +1,6 @@ #include #include "binary_semaphore.h" -#ifdef CPP +#ifdef __cplusplus extern "C" { #endif void bisem_post(struct binary_semaphore *p) @@ -37,6 +37,6 @@ bisem_destroy(struct binary_semaphore *p) pthread_cond_destroy(&p->cvar); pthread_mutex_destroy(&p->mutex); } -#ifdef CPP +#ifdef __cplusplus } // extern #endif diff --git a/src/config.h b/src/config.h deleted file mode 100644 index 486825d..0000000 --- a/src/config.h +++ /dev/null @@ -1,3 +0,0 @@ -#include -typedef uint16_t uint_16; -typedef uint8_t uint_8; diff --git a/src/crc16.c b/src/crc16.c index c78435d..c5e52d1 100644 --- a/src/crc16.c +++ b/src/crc16.c @@ -11,7 +11,9 @@ /* ======================================================================== */ -#include "config.h" +#include +typedef uint16_t uint_16; +typedef uint8_t uint_8; #include "crc16.h" /* ======================================================================== */ diff --git a/src/crc16.h b/src/crc16.h index aeb93a9..fc33ad0 100644 --- a/src/crc16.h +++ b/src/crc16.h @@ -13,11 +13,10 @@ #ifndef CRC_16_H_ #define CRC_16_H_ 1 - /* ======================================================================== */ /* CRC16_TBL -- Lookup table used for the CRC-16 code. */ /* ======================================================================== */ -extern const uint_16 crc16_tbl[256]; +extern const uint16_t crc16_tbl[256]; /* ======================================================================== */ /* CRC16_UPDATE -- Updates a 16-bit CRC using the lookup table above. */ @@ -26,7 +25,7 @@ extern const uint_16 crc16_tbl[256]; /* */ /* All-caps version is a macro for stuff that can use it. */ /* ======================================================================== */ -uint_16 crc16_update(uint_16 crc, uint_8 data); +uint16_t crc16_update(uint16_t crc, uint8_t data); #define CRC16_UPDATE(crc, d) (((crc) << 8) ^ crc16_tbl[((crc) >> 8) ^ (d)]) /* ======================================================================== */ @@ -34,7 +33,7 @@ uint_16 crc16_update(uint_16 crc, uint_8 data); /* Note: The 16-bit CRC is set up as a left-shifting */ /* CRC with no inversions. */ /* ======================================================================== */ -uint_16 crc16_block(uint_16 crc, uint_8 *data, int len); +uint16_t crc16_block(uint16_t crc, uint8_t *data, int len); #endif /* ======================================================================== */ diff --git a/src/spi_chunks.cpp b/src/spi_chunks.cpp index 327445d..1f7d2d0 100644 --- a/src/spi_chunks.cpp +++ b/src/spi_chunks.cpp @@ -8,7 +8,7 @@ #include "spi_chunks.h" //#include "spi_chunks_slave.h" -#ifdef CPP +#ifdef __cplusplus extern "C" { #endif @@ -67,6 +67,6 @@ spi_msg_chunks(uint8_t *buf, size_t len, int (*chunk_handler)(uint8_t *b, size_t return 0; } -#ifdef CPP +#ifdef __cplusplus } #endif diff --git a/src/spi_chunks.h b/src/spi_chunks.h index 27578cb..b51a68b 100644 --- a/src/spi_chunks.h +++ b/src/spi_chunks.h @@ -1,4 +1,7 @@ - +#pragma once +#ifdef __cplusplus +extern "C" { +#endif struct waiting_chunk { uint8_t buf[SPI_MSG_PAYLOAD_LEN]; //buf[0] is len @@ -13,3 +16,6 @@ spi_msg_chunks(uint8_t *buf, size_t len, int (*chunk_handler)(uint8_t *b, size_t int chunk_packer(struct waiting_chunk *chunks, size_t numchunk, uint8_t *buf, size_t len); +#ifdef __cplusplus +} +#endif diff --git a/src/spi_proto.c b/src/spi_proto.c index f8ffd85..37e427f 100644 --- a/src/spi_proto.c +++ b/src/spi_proto.c @@ -4,21 +4,18 @@ #include #endif -#ifdef CPP +#ifdef __cplusplus extern "C" { #endif -#include "config.h" #include "crc16.h" -#ifdef CPP +#ifdef __cplusplus } #endif #include "spi_proto.h" -//TODO this was made CPP to fix a linker error, instead determine what was causing the cross-language linking to fail and fix that so this can be pure C - //update the protocol state with a message. Doesn't do any processing of the message itselves -#ifdef CPP +#ifdef __cplusplus extern "C" { #endif void @@ -276,6 +273,6 @@ spi_msg_crc(struct spi_packet *p) //p->crc = crc_res; return crc_res; } -#ifdef CPP +#ifdef __cplusplus } // extern C #endif diff --git a/src/spi_proto.h b/src/spi_proto.h index bc8b210..4b9c7f7 100644 --- a/src/spi_proto.h +++ b/src/spi_proto.h @@ -4,7 +4,7 @@ #define SPI_REPEAT_RESYNC_THRESH 10 -#ifdef CPP +#ifdef __cplusplus extern "C" { #endif @@ -90,6 +90,6 @@ spi_proto_send_msg(struct spi_state *s, void *buf, size_t n); uint16_t spi_msg_crc(struct spi_packet *p); -#ifdef CPP +#ifdef __cplusplus } // extern C #endif diff --git a/src/spi_proto_util.c b/src/spi_proto_util.c index 23d154a..325c011 100644 --- a/src/spi_proto_util.c +++ b/src/spi_proto_util.c @@ -2,12 +2,11 @@ #include #include -#ifdef CPP +#ifdef __cplusplus extern "C" { #endif -#include "config.h" #include "crc16.h" -#ifdef CPP +#ifdef __cplusplus } #endif diff --git a/test/spi_proto_tests.c b/test/spi_proto_tests.c index b3304c9..36a8cd0 100644 --- a/test/spi_proto_tests.c +++ b/test/spi_proto_tests.c @@ -7,10 +7,8 @@ #include "spi_proto.h" #include "spi_proto_util.h" -#include "config.h" #include "crc16.h" - -#include "test/test_util.h" +#include "test_util.h" //SPI protocol testing void diff --git a/test/test_chunks.c b/test/test_chunks.c index 3daaae3..0db9380 100644 --- a/test/test_chunks.c +++ b/test/test_chunks.c @@ -8,11 +8,10 @@ #include "spi_proto.h" #include "spi_proto_util.h" -#include "config.h" #include "crc16.h" #include "spi_chunks.h" -#include "test/test_util.h" +#include "test_util.h" #define BIG_ROUNDS 5 diff --git a/test/test_longer_random_messages.c b/test/test_longer_random_messages.c index c32fdd4..5520f62 100644 --- a/test/test_longer_random_messages.c +++ b/test/test_longer_random_messages.c @@ -7,9 +7,8 @@ #include "spi_proto.h" #include "spi_proto_util.h" -#include "config.h" #include "crc16.h" -#include "test/test_util.h" +#include "test_util.h" //SPI protocol testing diff --git a/test/test_resync.c b/test/test_resync.c index 2ec8808..92abaf5 100644 --- a/test/test_resync.c +++ b/test/test_resync.c @@ -7,9 +7,8 @@ #include "spi_proto.h" #include "spi_proto_util.h" -#include "config.h" #include "crc16.h" -#include "test/test_util.h" +#include "test_util.h" //SPI protocol testing //test resynchronization