From 033a249e5ecab7db3d21b25b377ed56c7c0c8b32 Mon Sep 17 00:00:00 2001 From: Sebastian Pipping Date: Sat, 29 Jan 2022 17:01:53 +0100 Subject: [PATCH 1/8] tests: Make tests use . rather than test/ for SQLite files --- test/test_storage.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_storage.c b/test/test_storage.c index c86cf89..d49504c 100644 --- a/test/test_storage.c +++ b/test/test_storage.c @@ -9,7 +9,7 @@ #include "../src/libomemo.c" #include "../src/libomemo_storage.c" -#define TEST_DB_PATH "test/test.sqlite" +#define TEST_DB_PATH "test.sqlite" int db_cleanup(void ** state) { (void) state; From d08933d1b5845debb12e1e6a48c100e7f24ced54 Mon Sep 17 00:00:00 2001 From: Sebastian Pipping Date: Sat, 29 Jan 2022 16:48:55 +0100 Subject: [PATCH 2/8] Add CMake build system (including a fixed pkg-config template) --- CMakeLists.txt | 204 ++++++++++++++++++++++++++++++++++++++++++++++ libomemo.pc.cmake | 13 +++ 2 files changed, 217 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 libomemo.pc.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..f472e2f --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,204 @@ +# Copyright (c) 2022 Sebastian Pipping +# Licensed under the GPL v2 or later + +cmake_minimum_required(VERSION 3.16.3) + +project(omemo + VERSION + 0.8.0 + # NOTE: Because this^^ version affects shared library filenames, + # it needs a major version bump to 1.0.0 already at + # the _first ever ABI break_ despite semver rule 4 + # (https://semver.org/#spec-item-4). + LANGUAGES + C +) + +include(FindPkgConfig) +include(GNUInstallDirs) + + +# +# Public configuration +# +option(BUILD_SHARED_LIBS "Build shared libraries (rather than static ones)" ON) +option(OMEMO_INSTALL "Install build artifacts" ON) +option(OMEMO_WITH_TESTS "Build test suite (depends on cmocka)" ON) +if(NOT _OMEMO_HELP) # hide from "cmake -DOMEMO_HELP=ON -LH ." output + option(_OMEMO_WARNINGS_AS_ERRORS "(Unofficial!) Turn warnings into errors" OFF) + option(_OMEMO_WITH_COVERAGE "(Unofficial!) Build with coverage" OFF) +endif() + +if(NOT BUILD_SHARED_LIBS) + # NOTE: If we don't enforce -fPIC for static(!) libraries, we may run into + # "[..] relocation R_X86_64_PC32 against symbol [..]" link errors + # in dependent projects trying to link a shared library based on + # our static library. + set(CMAKE_POSITION_INDEPENDENT_CODE ON) +endif() + + +# +# Global CPPFLAGS and CFLAGS +# +add_compile_definitions( + _XOPEN_SOURCE=700 + _DEFAULT_SOURCE +) +add_compile_options( + -std=c99 + -Wall + -Wextra + -Wpedantic + -Wstrict-overflow + -fno-strict-aliasing + -funsigned-char + -fno-builtin-memset +) + +if(_OMEMO_WARNINGS_AS_ERRORS) + add_compile_options(-Werror) +endif() + +if(_OMEMO_WITH_COVERAGE) + set(_OMEMO_COVERAGE_FLAGS -g -O0 --coverage) + add_compile_options(${_OMEMO_COVERAGE_FLAGS}) + link_libraries(${_OMEMO_COVERAGE_FLAGS}) +endif() + + +# +# Build dependencies +# +# NOTE: We cannot use "pkg_check_modules([..] IMPORTED_TARGET [..])" +# because we'd run into a (false positive) CMake error +# "contains relative path in its INTERFACE_INCLUDE_DIRECTORIES" +# when using "target_link_libraries([..] PkgConfig::[..])" with msys2. +if(OMEMO_WITH_TESTS) + pkg_check_modules(CMOCKA REQUIRED "cmocka") +endif() +pkg_check_modules(GLIB REQUIRED "glib-2.0") +pkg_check_modules(GCRYPT REQUIRED "libgcrypt") +pkg_check_modules(MXML REQUIRED "mxml") +pkg_check_modules(SQLITE REQUIRED "sqlite3") + + +# +# C library +# +file(GLOB _OMEMO_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/libomemo*.[ch]) +add_library(omemo ${_OMEMO_SOURCES}) +target_include_directories(omemo PUBLIC $) + +if(OMEMO_INSTALL) + file(GLOB _OMEMO_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/src/libomemo*.h) + target_include_directories(omemo PUBLIC $) + install(FILES ${_OMEMO_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/libomemo) + install(TARGETS omemo EXPORT omemo + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + ) +endif() + +if(NOT WIN32) + set_property(TARGET omemo PROPERTY VERSION ${PROJECT_VERSION}) + set_property(TARGET omemo PROPERTY SOVERSION ${PROJECT_VERSION_MAJOR}) + set_property(TARGET omemo PROPERTY NO_SONAME ${NO_SONAME}) +endif() + + +# +# pkg-config/pkgconf file +# +set(_OMEMO_PKGCONF_EXEC_PREFIX ${CMAKE_INSTALL_PREFIX}) +set(_OMEMO_PKGCONF_LIBDIR ${CMAKE_INSTALL_FULL_LIBDIR}) +set(_OMEMO_PKGCONF_INCLUDEDIR ${CMAKE_INSTALL_FULL_INCLUDEDIR}) +set(_OMEMO_PKGCONF_PREFIX ${CMAKE_INSTALL_PREFIX}) +string(REPLACE ${CMAKE_INSTALL_PREFIX} \${exec_prefix} _OMEMO_PKGCONF_LIBDIR ${_OMEMO_PKGCONF_LIBDIR}) +string(REPLACE ${CMAKE_INSTALL_PREFIX} \${prefix} _OMEMO_PKGCONF_EXEC_PREFIX ${_OMEMO_PKGCONF_EXEC_PREFIX}) +string(REPLACE ${CMAKE_INSTALL_PREFIX} \${prefix} _OMEMO_PKGCONF_INCLUDEDIR ${_OMEMO_PKGCONF_INCLUDEDIR}) + +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libomemo.pc.cmake ${CMAKE_CURRENT_BINARY_DIR}/libomemo.pc @ONLY) +set_target_properties(omemo PROPERTIES ADDITIONAL_CLEAN_FILES ${CMAKE_CURRENT_BINARY_DIR}/libomemo.pc) + +if(OMEMO_INSTALL) + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libomemo.pc + DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig + ) +endif() + + +# +# C test suite +# +if(OMEMO_WITH_TESTS) + set(_OMEMO_TEST_TARGETS test_crypto test_libomemo test_storage) + + enable_testing() + + foreach(_target ${_OMEMO_TEST_TARGETS}) + add_executable(${_target} ${CMAKE_CURRENT_SOURCE_DIR}/test/${_target}.c) + target_link_libraries(${_target} PRIVATE omemo) + add_test(NAME ${_target} COMMAND ${_target}) + + if(BUILD_SHARED_LIBS) + target_compile_options(${_target} PRIVATE ${CMOCKA_CFLAGS}) + target_link_libraries(${_target} PRIVATE ${CMOCKA_LIBRARIES}) + else() + target_compile_options(${_target} PRIVATE ${CMOCKA_STATIC_CFLAGS}) + target_link_libraries(${_target} PRIVATE ${CMOCKA_STATIC_LIBRARIES}) + endif() + endforeach() +endif() + + +# +# External build dependencies +# +foreach(_target omemo ${_OMEMO_TEST_TARGETS}) + if(BUILD_SHARED_LIBS) + # TODO: Tests should stop depending on gcrypt + # once the tests stop including libomemo's .c(!) files + target_compile_options(${_target} PRIVATE ${GCRYPT_CFLAGS}) + target_link_libraries(${_target} PRIVATE ${GCRYPT_LIBRARIES}) + + target_compile_options(${_target} PUBLIC ${GLIB_CFLAGS}) + target_link_libraries(${_target} PUBLIC ${GLIB_LIBRARIES}) + + # TODO: Tests should stop depending on mxml + # once the tests stop including libomemo's .c(!) files + target_compile_options(${_target} PRIVATE ${MXML_CFLAGS}) + target_link_libraries(${_target} PRIVATE ${MXML_LIBRARIES}) + + target_compile_options(${_target} PRIVATE ${SQLITE_CFLAGS}) + target_link_libraries(${_target} PRIVATE ${SQLITE_LIBRARIES}) + else() + # TODO: Tests should stop depending on gcrypt + # once the tests stop including libomemo's .c(!) files + target_compile_options(${_target} PRIVATE ${GCRYPT_STATIC_CFLAGS}) + target_link_libraries(${_target} PRIVATE ${GCRYPT_STATIC_LIBRARIES}) + + target_compile_options(${_target} PUBLIC ${GLIB_STATIC_CFLAGS}) + target_link_libraries(${_target} PUBLIC ${GLIB_STATIC_LIBRARIES}) + + # TODO: Tests should stop depending on mxml + # once the tests stop including libomemo's .c(!) files + target_compile_options(${_target} PRIVATE ${MXML_STATIC_CFLAGS}) + target_link_libraries(${_target} PRIVATE ${MXML_STATIC_LIBRARIES}) + + target_compile_options(${_target} PRIVATE ${SQLITE_STATIC_CFLAGS}) + target_link_libraries(${_target} PRIVATE ${SQLITE_STATIC_LIBRARIES}) + endif() +endforeach() + + +# +# Coverage reporting +# +if(_OMEMO_WITH_COVERAGE) + add_custom_target(coverage + COMMAND gcovr -r ${CMAKE_CURRENT_SOURCE_DIR} --html --html-details -o coverage.html + COMMAND gcovr -r ${CMAKE_CURRENT_SOURCE_DIR} -s + ) +endif() diff --git a/libomemo.pc.cmake b/libomemo.pc.cmake new file mode 100644 index 0000000..93cb3c4 --- /dev/null +++ b/libomemo.pc.cmake @@ -0,0 +1,13 @@ +prefix=@_OMEMO_PKGCONF_PREFIX@ +exec_prefix=@_OMEMO_PKGCONF_EXEC_PREFIX@ +libdir=@_OMEMO_PKGCONF_LIBDIR@ +includedir=@_OMEMO_PKGCONF_INCLUDEDIR@ + +Name: libomemo +Version: @PROJECT_VERSION@ +Description: OMEMO library for C +URL: https://github.com/gkdr/libomemo +Requires: glib-2.0 +Requires.private: libgcrypt mxml sqlite3 +Cflags: -I${includedir}/libomemo +Libs: -L${libdir} -lomemo From 6694aeb1905946d46fef2ecaa95159ddfb09e552 Mon Sep 17 00:00:00 2001 From: Sebastian Pipping Date: Sat, 29 Jan 2022 17:53:59 +0100 Subject: [PATCH 3/8] Actions: Migrate from Makefile to CMake and Ninja --- .github/workflows/linux.yml | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 1360635..c326c42 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -11,8 +11,12 @@ on: jobs: checks: - name: Build for Linux + name: Build for Linux (shared=${{ matrix.BUILD_SHARED_LIBS }}) runs-on: ubuntu-20.04 + strategy: + fail-fast: false + matrix: + BUILD_SHARED_LIBS: ['ON', 'OFF'] steps: - uses: actions/checkout@v2.4.0 @@ -27,26 +31,39 @@ jobs: libgcrypt20-dev \ libglib2.0-dev \ libmxml-dev \ - libsqlite3-dev + libsqlite3-dev \ + ninja-build + + - name: Configure + run: |- + set -x + cmake \ + -B build \ + -G Ninja \ + -DBUILD_SHARED_LIBS=${{ matrix.BUILD_SHARED_LIBS }} \ + -D_OMEMO_WITH_COVERAGE=ON - name: Build run: |- set -x - make -j $(nproc) all + ninja -v -C build all + cat build/libomemo.pc - name: Test run: |- - make coverage # includes tests + set -x + CTEST_OUTPUT_ON_FAILURE=1 ninja -C build test + ninja -C build coverage - name: Install run: |- set -x -o pipefail - make DESTDIR="${PWD}"/ROOT install + DESTDIR="${PWD}"/ROOT ninja -v -C build install find ROOT/ -not -type d | sort | xargs ls -l - name: Store coverage HTML report uses: actions/upload-artifact@v2.3.1 with: - name: coverage - path: coverage/ + name: omemo_coverage_shared_${{ matrix.BUILD_SHARED_LIBS }} + path: build/coverage*.html if-no-files-found: error From f2418f5143b6bd8b39941360a05746ee27a053e3 Mon Sep 17 00:00:00 2001 From: Sebastian Pipping Date: Sat, 29 Jan 2022 17:56:36 +0100 Subject: [PATCH 4/8] Actions: Build for Windows using msys2 --- .github/workflows/windows.yml | 78 +++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 .github/workflows/windows.yml diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml new file mode 100644 index 0000000..f8f026e --- /dev/null +++ b/.github/workflows/windows.yml @@ -0,0 +1,78 @@ +# Copyright (c) 2022 Sebastian Pipping +# Licensed under the GPL v2 or later + +name: Build for Windows + +on: + pull_request: + push: + schedule: + - cron: '0 2 * * 5' # Every Friday at 2am + +jobs: + checks: + name: Build for Windows (shared=${{ matrix.BUILD_SHARED_LIBS }}) + runs-on: windows-2019 + defaults: + run: + shell: msys2 {0} + strategy: + fail-fast: false + matrix: + BUILD_SHARED_LIBS: ['ON', 'OFF'] + steps: + + - uses: actions/checkout@v2.4.0 + + - name: Install build dependencies + uses: msys2/setup-msys2@v2 + with: + msystem: MINGW32 + install: | + cmake + mingw-w64-i686-cmocka + mingw-w64-i686-glib2 + mingw-w64-i686-libgcrypt + mingw-w64-i686-mxml + mingw-w64-i686-sqlite3 + mingw-w64-i686-toolchain + ninja + + - name: Configure + run: |- + set -x + cmake \ + -B build \ + -G Ninja \ + -DCMAKE_C_COMPILER=i686-w64-mingw32-gcc -DCMAKE_SYSTEM_NAME=Windows -DWIN32=ON -DMINGW=ON \ + -DBUILD_SHARED_LIBS=${{ matrix.BUILD_SHARED_LIBS }} \ + -D_OMEMO_WITH_COVERAGE=ON + + - name: Build + run: |- + set -x + ninja -v -C build all + cat build/libomemo.pc + + - name: Test + run: |- + set -x + CTEST_OUTPUT_ON_FAILURE=1 ninja -C build test + # Note: msys2 does not come with a package for gcovr, yet(?) + # ninja -C build coverage + + - name: Install + run: |- + set -x -o pipefail + DESTDIR="${PWD}"/ROOT ninja -v -C build install + find ROOT/ -not -type d | sort | xargs ls -l + + - name: Store Windows binaries + uses: actions/upload-artifact@v2.3.1 + with: + name: omemo_win32bin_shared_${{ matrix.BUILD_SHARED_LIBS }} + path: | + build/*.a + build/*.dll + build/*.exe + if-no-files-found: error From fdfbc7935d2b650e37eb0220ec0588df54bf1b12 Mon Sep 17 00:00:00 2001 From: Sebastian Pipping Date: Sat, 29 Jan 2022 18:21:20 +0100 Subject: [PATCH 5/8] Makefile: Drop --- Makefile | 150 ------------------------------------------------------- 1 file changed, 150 deletions(-) delete mode 100644 Makefile diff --git a/Makefile b/Makefile deleted file mode 100644 index 516af33..0000000 --- a/Makefile +++ /dev/null @@ -1,150 +0,0 @@ -### toolchain -# -CC ?= gcc -AR ?= ar -LIBTOOL ?= libtool -MKDIR = mkdir -MKDIR_P = mkdir -p - -ARCH = $(shell $(CC) -print-multiarch) -VER_MAJ = 0 -VERSION = 0.8.0 - -PKG_CONFIG ?= pkg-config -GLIB_CFLAGS ?= $(shell $(PKG_CONFIG) --cflags glib-2.0) -GLIB_LDFLAGS ?= $(shell $(PKG_CONFIG) --libs glib-2.0) - -SQLITE3_CFLAGS ?= $(shell $(PKG_CONFIG) --cflags sqlite3) -SQLITE3_LDFLAGS ?= $(shell $(PKG_CONFIG) --libs sqlite3) - -MXML_CFLAGS ?= $(shell $(PKG_CONFIG) --cflags mxml) -MXML_LDFLAGS ?= $(shell $(PKG_CONFIG) --libs mxml) - -LIBGCRYPT_CONFIG ?= libgcrypt-config -LIBGCRYPT_LDFLAGS ?= $(shell $(LIBGCRYPT_CONFIG) --libs) - -SDIR = src -BDIR = build -TDIR = test -LDIR = lib - -# according to https://sourceware.org/bugzilla/show_bug.cgi?id=17879 -# -fno-builtin-memset is enough to make gcc not optimize it away -FILES = - -PKGCFG_C=$(GLIB_CFLAGS) \ - $(MXML_CFLAGS) \ - $(SQLITE3_CFLAGS) \ - $(LIBGCRYPT_CFLAGS) - -PKGCFG_L=$(GLIB_LDFLAGS) \ - $(MXML_LDFLAGS) \ - $(SQLITE3_LDFLAGS) \ - $(LIBGCRYPT_LDFLAGS) - -CFLAGS += -std=c11 -Wall -Wextra -Wpedantic -Wstrict-overflow \ - -fno-strict-aliasing -funsigned-char \ - -fno-builtin-memset -g $(PKGCFG_C) -CPPFLAGS += -D_XOPEN_SOURCE=700 -D_DEFAULT_SOURCE -CFLAGS_CONVERSATIONS=$(CFLAGS) -COVFLAGS = --coverage -O0 -g $(CFLAGS) -LDFLAGS += -pthread -ldl -lm $(PKGCFG_L) -TESTFLAGS = -lcmocka $(LDFLAGS) - -all: $(BDIR)/libomemo-conversations.a shared - -$(BDIR): - $(MKDIR_P) $@ - -libomemo: $(SDIR)/libomemo.c libomemo_crypto libomemo_storage $(BDIR) - $(LIBTOOL) --mode=compile $(CC) -c $(SDIR)/$@.c $(CFLAGS) $(CPPFLAGS) -o $(BDIR)/$@.lo - $(LIBTOOL) --mode=link $(CC) -o $(BDIR)/$@.la $(BDIR)/$@.lo $(BDIR)/$@_crypto.lo $(BDIR)/$@_storage.lo - -libomemo-conversations: $(SDIR)/libomemo.c libomemo_crypto libomemo_storage $(BDIR) - $(LIBTOOL) --mode=compile $(CC) -c $(SDIR)/libomemo.c $(CFLAGS_CONVERSATIONS) -o $(BDIR)/libomemo.lo $(CPPFLAGS) - $(LIBTOOL) --mode=link $(CC) -o $(BDIR)/libomemo.la $(BDIR)/libomemo.lo $(BDIR)/libomemo_crypto.lo $(BDIR)/libomemo_storage.lo - -libomemo_crypto: $(SDIR)/libomemo_crypto.c build - $(LIBTOOL) --mode=compile $(CC) -c $(SDIR)/$@.c $(CFLAGS) $(CPPFLAGS) -o $(BDIR)/$@.lo - -libomemo_storage: $(SDIR)/libomemo_storage.c build - $(LIBTOOL) --mode=compile $(CC) -c $(SDIR)/$@.c $(CFLAGS) $(CPPFLAGS) -o $(BDIR)/$@.lo - -$(BDIR)/libomemo.o: $(BDIR) $(SDIR)/libomemo.c $(SDIR)/libomemo.h - $(CC) -c $(CFLAGS) $(CPPFLAGS) $(SDIR)/libomemo.c -o $@ - -$(BDIR)/libomemo-conversations.o: $(SDIR)/libomemo.c $(BDIR) - $(CC) -c $(SDIR)/libomemo.c $(CFLAGS_CONVERSATIONS) $(CPPFLAGS) -fPIC -o $@ - -$(BDIR)/libomemo_crypto.o: $(SDIR)/libomemo_crypto.c $(BDIR) - $(CC) -c $(SDIR)/libomemo_crypto.c $(CFLAGS) $(CPPFLAGS) -fPIC -o $@ - -$(BDIR)/libomemo_storage.o: $(SDIR)/libomemo_storage.c $(BDIR) - $(CC) -c $(SDIR)/libomemo_storage.c $(CFLAGS) $(CPPFLAGS) -fPIC -o $@ - -$(BDIR)/libomemo-conversations.a: $(BDIR)/libomemo-conversations.o $(BDIR)/libomemo_crypto.o $(BDIR)/libomemo_storage.o - $(AR) rcs $@ $^ - -$(BDIR)/libomemo.so: $(BDIR) - $(CC) -shared $(SDIR)/libomemo.c -Wl,-soname,libomemo.so.$(VER_MAJ) \ - $(SDIR)/libomemo_crypto.c $(SDIR)/libomemo_storage.c \ - $(LDFLAGS) $(CPPFLAGS) -fPIC -o $@ $(CFLAGS_CONVERSATIONS) - -$(BDIR)/libomemo.pc: $(BDIR) - echo 'prefix='$(PREFIX) > $@ - echo 'exec_prefix=$${prefix}' >> $@ - echo 'libdir=$${prefix}/lib/$(ARCH)' >> $@ - echo 'includedir=$${prefix}/include' >> $@ - echo 'Name: libomemo' >> $@ - echo 'Version: ${VERSION}' >> $@ - echo 'Description: OMEMO library for C' >> $@ - echo 'Requires.private: glib-2.0' >> $@ - echo 'Cflags: -I$${includedir}/libomemo' >> $@ - echo 'Libs: -L$${libdir} -lomemo' >> $@ - -shared: $(BDIR)/libomemo.so $(BDIR)/libomemo.pc - -install: $(BDIR) - install -d $(DESTDIR)/$(PREFIX)/lib/$(ARCH)/pkgconfig/ - install -m 644 $(BDIR)/libomemo-conversations.a $(DESTDIR)/$(PREFIX)/lib/$(ARCH)/libomemo.a - install -m 644 $(BDIR)/libomemo.so $(DESTDIR)/$(PREFIX)/lib/$(ARCH)/libomemo.so.$(VERSION) - ln -s libomemo.so.$(VERSION) $(DESTDIR)/$(PREFIX)/lib/$(ARCH)/libomemo.so.$(VER_MAJ) - ln -s libomemo.so.$(VERSION) $(DESTDIR)/$(PREFIX)/lib/$(ARCH)/libomemo.so - install -m 644 $(BDIR)/libomemo.pc $(DESTDIR)/$(PREFIX)/lib/$(ARCH)/pkgconfig/ - install -d $(DESTDIR)/$(PREFIX)/include/libomemo/ - install -m 644 $(SDIR)/libomemo_crypto.h $(DESTDIR)/$(PREFIX)/include/libomemo/ - install -m 644 $(SDIR)/libomemo_storage.h $(DESTDIR)/$(PREFIX)/include/libomemo/ - install -m 644 $(SDIR)/libomemo.h $(DESTDIR)/$(PREFIX)/include/libomemo/ - -.PHONY = test_libomemo.o -test_libomemo: $(TDIR)/test_libomemo.c $(SDIR)/libomemo.c - $(CC) $(COVFLAGS) $< $(FILES) -o $(TDIR)/$@.o $(TESTFLAGS) - -$(TDIR)/$@.o - find . -maxdepth 1 -iname 'test*.g*' -exec mv {} $(TDIR) \; - -.PHONY: test_crypto -test_crypto: $(TDIR)/test_crypto.c $(SDIR)/libomemo_crypto.c - $(CC) $(COVFLAGS) $< $(FILES) -o $(TDIR)/$@.o $(TESTFLAGS) - -$(TDIR)/$@.o - find . -maxdepth 1 -iname 'test*.g*' -exec mv {} $(TDIR) \; - -.PHONY: test_storage -test_storage: $(TDIR)/test_storage.c $(SDIR)/libomemo_storage.c - $(CC) $(COVFLAGS) $< $(FILES) -o $(TDIR)/$@.o $(TESTFLAGS) - -$(TDIR)/$@.o - find . -maxdepth 1 -iname 'test*.g*' -exec mv {} $(TDIR) \; - -.PHONY: test -test : test_libomemo test_crypto test_storage - -.PHONY: coverage -coverage: test - gcovr -r . --html --html-details -o $@.html - gcovr -r . -s - $(MKDIR_P) $@ - mv $@.* $@ - -.PHONY: clean -clean: - rm -rf build coverage - rm -f $(TDIR)/*.sqlite $(TDIR)/*.o $(TDIR)/*.gcno $(TDIR)/*.gcda From 7fa47dec15e3a424cc0c0adad0a05b6a18691074 Mon Sep 17 00:00:00 2001 From: Sebastian Pipping Date: Sat, 29 Jan 2022 18:25:57 +0100 Subject: [PATCH 6/8] README.md: Improve section on dependencies --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index efea313..1309a9a 100644 --- a/README.md +++ b/README.md @@ -8,14 +8,16 @@ It deals with devicelists and bundles as well as encrypting the payload, but doe However, you can use my [axc](https://github.com/gkdr/axc) lib for that and easily combine it with this one (or write all the libsignal client code yourself if that is better suited to your needs). ## Dependencies +* pkg-config (`pkg-config`) or pkgconf (`pkgconf`) * [Mini-XML](http://www.msweet.org/projects.php?Z3) (`libmxml-dev`) * gcrypt (`libgcrypt20-dev`) * glib (`libglib2.0-dev`) * SQLite (`libsqlite3-dev`) +* GNU make (`make`) Optional: -* For testing: [cmocka](https://cmocka.org/) (`make test`) -* For the coverage report: [gcovr](https://gcovr.com/) (`make coverage`) +* [cmocka](https://cmocka.org/) (`libcmocka-dev`) for testing (`make test`) +* [gcovr](http://gcovr.com/) (`gcovr`) for a coverage report (`make coverage`) I recommend to simply link it statically - the standard target is a is a static lib (containing PIC) which uses the _compatible_ namespace (i.e. not the one in the XEP). From 27d8be9bce22992c5e816c4a9607698cc024520e Mon Sep 17 00:00:00 2001 From: Sebastian Pipping Date: Sat, 29 Jan 2022 18:29:57 +0100 Subject: [PATCH 7/8] README.md: CMake-ify --- README.md | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1309a9a..ad86b03 100644 --- a/README.md +++ b/README.md @@ -8,18 +8,53 @@ It deals with devicelists and bundles as well as encrypting the payload, but doe However, you can use my [axc](https://github.com/gkdr/axc) lib for that and easily combine it with this one (or write all the libsignal client code yourself if that is better suited to your needs). ## Dependencies +* CMake (`cmake`) * pkg-config (`pkg-config`) or pkgconf (`pkgconf`) * [Mini-XML](http://www.msweet.org/projects.php?Z3) (`libmxml-dev`) * gcrypt (`libgcrypt20-dev`) * glib (`libglib2.0-dev`) * SQLite (`libsqlite3-dev`) -* GNU make (`make`) +* GNU make (`make`) or Ninja (`ninja-build`) Optional: * [cmocka](https://cmocka.org/) (`libcmocka-dev`) for testing (`make test`) * [gcovr](http://gcovr.com/) (`gcovr`) for a coverage report (`make coverage`) -I recommend to simply link it statically - the standard target is a is a static lib (containing PIC) which uses the _compatible_ namespace (i.e. not the one in the XEP). +## Installation +libomemo uses CMake as a build system. It can be used with either GNU make or Ninja. For example: + +``` +mkdir build +cd build + +cmake -G Ninja .. # for options see below + +ninja -v all +ninja -v test # potentially with CTEST_OUTPUT_ON_FAILURE=1 in the environment +ninja -v install +``` + +The following configuration options are supported: + +```console +# rm -f CMakeCache.txt ; cmake -D_OMEMO_HELP=ON -LH . | grep -B1 ':.*=' | sed 's,^--$,,' +// Build shared libraries (rather than static ones) +BUILD_SHARED_LIBS:BOOL=ON + +// Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel ... +CMAKE_BUILD_TYPE:STRING= + +// Install path prefix, prepended onto install directories. +CMAKE_INSTALL_PREFIX:PATH=/usr/local + +// Install build artifacts +OMEMO_INSTALL:BOOL=ON + +// Build test suite (depends on cmocka) +OMEMO_WITH_TESTS:BOOL=ON +``` + +They can be passed to CMake as `-D=`, e.g. `-DBUILD_SHARED_LIBS=OFF`. ## Usage Basically, there are three data types: messages, devicelists, and bundles. From 09f9e581cfba97d0a8bddf892eaf34111e90ad0e Mon Sep 17 00:00:00 2001 From: Sebastian Pipping Date: Sat, 29 Jan 2022 17:24:21 +0100 Subject: [PATCH 8/8] CHANGELOG.md: Document this pull request --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b384fef..c42bb3d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,9 +17,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added missing symlinks for the `.so` files. ([#34](https://github.com/gkdr/libomemo/pull/34)) (thanks, [@hartwork](https://github.com/hartwork)!) - Fix crossbuild using wrong multiarch triplet. ([#36](https://github.com/gkdr/libomemo/pull/36)) (thanks, [@fortysixandtwo](https://github.com/fortysixandtwo)!) - Flaky test `test_aes_gcm_encrypt_decrypt`. ([#39](https://github.com/gkdr/libomemo/issues/39)) (thanks, [@hartwork](https://github.com/hartwork)!) +- Fix default prefix to be `/usr/local` rather than `/` ([#38](https://github.com/gkdr/libomemo/pull/38)) (thanks, [@hartwork](https://github.com/hartwork)!) +- Fix filed `Requires.private` and `Requires` in auto-generated pkg-config file `libomemo.pc` ([#38](https://github.com/gkdr/libomemo/pull/38)) (thanks, [@hartwork](https://github.com/hartwork)!) + +### Changed +- Migrate build system from a Makefile to CMake ([#38](https://github.com/gkdr/libomemo/pull/38)) (thanks, [@hartwork](https://github.com/hartwork)!) ### Infrastructure - Cover Linux build by GitHub Actions CI ([#37](https://github.com/gkdr/libomemo/pull/37)) (thanks, [@hartwork](https://github.com/hartwork)!) +- Cover Windows build by GitHub Actions CI using msys2 ([#38](https://github.com/gkdr/libomemo/pull/38)) (thanks, [@hartwork](https://github.com/hartwork)!) ## [0.7.1] - 2021-01-31 ### Fixed