diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index 1478bc32..ec39f3e8 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -3,27 +3,58 @@ name: CMake on: [push, pull_request] jobs: - build: - runs-on: ubuntu-latest - + build_and_test: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest] + COMPILER: [gcc, clang] + LIBMBUS_SANITIZE_MEMORY: ["ON", "OFF"] + steps: + - name: setup (linux) + if: startsWith(matrix.os, 'ubuntu') && startsWith(matrix.COMPILER, 'clang') + run: | + sudo apt install clang + - uses: actions/checkout@v2 - name: build examples and tests - run: rm -rf build || true && mkdir build && cd build && cmake .. -DLIBMBUS_BUILD_EXAMPLES=ON -DLIBMBUS_BUILD_TESTS=ON -DLIBMBUS_ENABLE_COVERAGE=ON && cmake --build . -j && cd .. + run: | + if [[ ${{matrix.COMPILER}} == *"clang"* ]]; then + export CC=clang + export CXX=clang++ + fi + rm -rf build || true + mkdir build + cd build + cmake .. \ + -DLIBMBUS_BUILD_EXAMPLES=ON \ + -DLIBMBUS_BUILD_TESTS=ON \ + -DLIBMBUS_ENABLE_COVERAGE=ON \ + -DLIBMBUS_SANITIZE_MEMORY=${{matrix.LIBMBUS_SANITIZE_MEMORY}} + cmake --build . -j + cd .. - name: generate test frames run: ./test/generate-xml.sh test/test-frames - name: install and run gcovr + if: startsWith(matrix.COMPILER, 'gcc') run: sudo pip install gcovr && gcovr build/. - debian: + debian_package: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: build debian package - run: rm -rf build || true && mkdir build && cd build && cmake .. -DLIBMBUS_PACKAGE_DEB=ON && cpack .. && sudo dpkg -i *.deb && ls /usr/lib + run: | + rm -rf build || true + mkdir build + cd build + cmake .. \ + -DLIBMBUS_PACKAGE_DEB=ON + cpack .. && sudo dpkg -i *.deb && ls /usr/lib doc: runs-on: ubuntu-latest @@ -34,5 +65,11 @@ jobs: run: sudo apt install -y doxygen - name: build doxygen documentation - run: rm -rf build || true && mkdir build && cd build && cmake .. -DLIBMBUS_BUILD_DOCS=ON && cmake --build . --target doc + run: | + rm -rf build || true + mkdir build + cd build + cmake .. \ + -DLIBMBUS_BUILD_DOCS=ON + cmake --build . --target doc diff --git a/CMakeLists.txt b/CMakeLists.txt index c35713f1..0c389875 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,6 +23,7 @@ option(LIBMBUS_PACKAGE_DEB "build debian package" OFF) option(LIBMBUS_PACKAGE_RPM "build rpm package" OFF) option(LIBMBUS_BUILD_DOCS "build documentation" OFF) option(BUILD_SHARED_LIBS "build shared lib" ON) +option(LIBMBUS_SANITIZE_MEMORY "sanitize memory" OFF) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) @@ -72,6 +73,20 @@ if(LIBMBUS_ENABLE_COVERAGE) endif() endif() +if(LIBMBUS_SANITIZE_MEMORY) + if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + message(STATUS "Sanitizing memory...") + set(CMAKE_BUILD_TYPE DEBUG) + set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=memory -g") + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=memory -g") + set(CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=memory ") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=memory") + set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -fsanitize=memory") + else() + message(STATUS "LIBMBUS_SANITIZE_MEMORY only available with clang...") + endif() +endif() + include(CheckIncludeFile) check_include_file(dlfcn.h HAVE_DLFCN_H)