Skip to content
Open
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
44 changes: 44 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: CI

on:
push:
branches: [ main, master, develop ]
pull_request:
branches: [ main, master, develop ]

jobs:
build-and-test:
runs-on: ubuntu-latest

strategy:
matrix:
compiler: [gcc, clang]

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install build dependencies
run: |
sudo apt-get update
sudo apt-get install -y cmake build-essential

- name: Build in debug mode
run: |
./build.sh debug

- name: Compile project
run: |
cd build_debug
make

- name: Run tests
run: |
cd build_debug
make test

- name: Run cross-platform tests
run: |
cd test/cross-platform-testing
./advanced-tests.sh
./test-missing-headers.sh
72 changes: 50 additions & 22 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,53 +1,81 @@
cmake_minimum_required(VERSION 2.8.11)
cmake_minimum_required(VERSION 3.5)
project(logger C)

set(CMAKE_C_FLAGS "-Wall -std=c89")
set(CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG")
set(CMAKE_C_FLAGS_DEBUG "-g")
include(GNUInstallDirs)

# Build options
option(BUILD_TESTS "Build all of own tests" OFF)
option(BUILD_EXAMPLES "Build example programs" OFF)
option(BUILD_DOCS "Build doxygen documentation" OFF)
option(BUILD_SHARED "Build shared library" OFF)
option(ENABLE_THREADING "Enable thread safety" ON)
option(WARNINGS_AS_ERRORS "Treat all warnings as errors" OFF)

# Set default build type to Release
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build." FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()

option(build_tests "Build all of own tests" OFF)
option(build_examples "Build example programs" OFF)
option(build_docs "Build doxygen documentation" OFF)
# Cross-platform feature detection
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/PlatformChecks.cmake)

# Compiler flags
set(CMAKE_C_FLAGS "-Wall -Wextra -std=c99")
if(WARNINGS_AS_ERRORS)
message(STATUS "WARNINGS_AS_ERRORS=ON: Treating warnings as errors")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
endif()
set(CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG")
set(CMAKE_C_FLAGS_DEBUG "-g -O0")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g -DNDEBUG")
set(CMAKE_C_FLAGS_MINSIZEREL "-Os -DNDEBUG")

### Library
set(source_files
set(logger_sources
src/logger.c
src/logger.h
src/logger_platform.c
src/logger_platform.h
src/loggerconf.c
src/loggerconf.h
include/logger_config.h
)
# shared and static libraries
add_library(${PROJECT_NAME} SHARED ${source_files})
add_library(${PROJECT_NAME}_static STATIC ${source_files})
set_target_properties(${PROJECT_NAME}_static PROPERTIES OUTPUT_NAME ${PROJECT_NAME})
if(BUILD_SHARED)
add_library(${PROJECT_NAME} SHARED ${logger_sources})
else()
add_library(${PROJECT_NAME} STATIC ${logger_sources})
endif()

# Export the include directory
target_include_directories(
${PROJECT_NAME} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
target_include_directories(
${PROJECT_NAME}_static PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)

### Install
install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
install(TARGETS ${PROJECT_NAME}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
file(GLOB header_files src/*.h)
install(FILES ${header_files} DESTINATION ${CMAKE_INSTALL_PREFIX}/include)
install(FILES ${header_files} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

### Document
if(build_docs)
if(BUILD_DOCS)
add_custom_target(doc COMMAND "doxygen" "${PROJECT_SOURCE_DIR}/doc/Doxyfile")
endif()

### Test
if(build_tests)
if(BUILD_TESTS)
enable_testing()
add_subdirectory(test)
endif()

### Example
if(build_examples)
if(BUILD_EXAMPLES)
add_subdirectory(example)
endif()
Loading