Skip to content
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

CMake build system + msys2 windows binaries CI (fixes #6) #38

Merged
merged 8 commits into from
Feb 14, 2022
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
31 changes: 24 additions & 7 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
Expand All @@ -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/[email protected]
with:
name: coverage
path: coverage/
name: omemo_coverage_shared_${{ matrix.BUILD_SHARED_LIBS }}
path: build/coverage*.html
if-no-files-found: error
78 changes: 78 additions & 0 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Copyright (c) 2022 Sebastian Pipping <[email protected]>
# 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/[email protected]

- 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/[email protected]
with:
name: omemo_win32bin_shared_${{ matrix.BUILD_SHARED_LIBS }}
path: |
build/*.a
build/*.dll
build/*.exe
if-no-files-found: error
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
204 changes: 204 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
# Copyright (c) 2022 Sebastian Pipping <[email protected]>
# 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 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>)

if(OMEMO_INSTALL)
file(GLOB _OMEMO_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/src/libomemo*.h)
target_include_directories(omemo PUBLIC $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/libomemo>)
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()
Loading