Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
134 commits
Select commit Hold shift + click to select a range
11f8b71
Remove unused code files
riccardodebenedictis Jan 28, 2024
cf1624e
Add constexpr function for infinity value
riccardodebenedictis Jan 28, 2024
178f5bb
Fix bug in login functionality
riccardodebenedictis Jan 28, 2024
93bd2e5
Add logging level configuration
riccardodebenedictis Jan 28, 2024
9a239d0
Added CI
riccardodebenedictis Jan 28, 2024
ad8e617
Update CMakeLists.txt to use CXX language and add cxx_std_17 feature …
riccardodebenedictis Jan 28, 2024
d6ba1a0
Update minimum required CMake version to 3.5.0
riccardodebenedictis Jan 28, 2024
288d4cd
Add linear expression
riccardodebenedictis Feb 2, 2024
2025409
Add lin and tableau classes for linear algebra operations
riccardodebenedictis Feb 2, 2024
e1db2c5
Refactor tableau class to support pivot operation
riccardodebenedictis Feb 2, 2024
40159a3
Update variable types in CMakeLists.txt
riccardodebenedictis Feb 2, 2024
79baeae
Fix return type in tableau::new_var() function
riccardodebenedictis Feb 2, 2024
32d5a3b
Fix assertion error in tableau pivot function
riccardodebenedictis Feb 6, 2024
af41ee0
Add debug flag for undefined behavior sanitizer
riccardodebenedictis Feb 10, 2024
878d05b
Add coverage report generation and upload
riccardodebenedictis Feb 10, 2024
7c8e0af
Add dependency installation step for lcov
riccardodebenedictis Feb 10, 2024
76377ff
Add CMake configuration for Debug build type with coverage
riccardodebenedictis Feb 10, 2024
7553d67
Refactor CMake workflow to install lcov only for Debug builds on Ubuntu
riccardodebenedictis Feb 10, 2024
103f64f
Add [[nodiscard]] attribute to functions in integer.hpp, tableau.hpp,…
riccardodebenedictis Feb 26, 2024
adc4493
Fix function visibility and friend declarations
riccardodebenedictis Feb 26, 2024
8a7b36b
Fix formatting of integer type message
riccardodebenedictis Mar 2, 2024
a8d0814
Add test for literals
riccardodebenedictis Mar 3, 2024
3e2ff77
Update lit.hpp and lin.hpp with constexpr functions
riccardodebenedictis Mar 9, 2024
f7649a8
Refactor lin class implementation
riccardodebenedictis Mar 9, 2024
758016c
Add inf_rational class and epsilon constant
riccardodebenedictis Mar 11, 2024
b7e7377
Update logging levels and remove variable from linear expression
riccardodebenedictis Mar 11, 2024
9d43f5a
Update actions/checkout to v4
riccardodebenedictis Mar 11, 2024
f5c4d84
Refactor build command in cmake.yml
riccardodebenedictis Mar 25, 2024
b4a9c36
Add test with coverage and test without coverage jobs in CMake workflow
riccardodebenedictis Mar 25, 2024
3e2ca38
Update build command to include build type configuration
riccardodebenedictis Mar 25, 2024
d4db8c8
Update variable assignment in tableau.cpp
riccardodebenedictis Mar 25, 2024
df099c9
Update test conditions in cmake.yml
riccardodebenedictis Mar 25, 2024
05a4a2e
Update coverage report generation condition
riccardodebenedictis Mar 25, 2024
3c96816
Add lcov installation for macOS
riccardodebenedictis Mar 25, 2024
b95072a
Add code coverage support for Clang compiler
riccardodebenedictis Mar 25, 2024
952e2b1
Refactor CMakeLists.txt to use 'utils' as library name
riccardodebenedictis Mar 25, 2024
e3d3d82
Fix coverage generation for Ubuntu
riccardodebenedictis Mar 25, 2024
db89718
Update logging levels in CMakeLists.txt and logging.hpp
riccardodebenedictis Mar 27, 2024
f307b10
Add is_integer function to inf_rational class
riccardodebenedictis Mar 27, 2024
5882315
Add lcov and valgrind to dependencies for Debug build on Ubuntu
riccardodebenedictis Mar 28, 2024
86fd1ab
Update test step in CMake workflow
riccardodebenedictis Mar 28, 2024
2c95e86
Update CMake configuration based on build type
riccardodebenedictis Mar 28, 2024
0c0b211
Add [[nodiscard]] attribute to member functions
riccardodebenedictis Mar 28, 2024
bf87d0d
Add pair.hpp to the repository
riccardodebenedictis Apr 9, 2024
e616b67
Refactor pair.hpp to use const reference in operator< overload
riccardodebenedictis Apr 9, 2024
56972c7
Remove pair.hpp from the repository
riccardodebenedictis Apr 9, 2024
33b7871
Add zero constant to inf_rational class
riccardodebenedictis Apr 11, 2024
c3d41a1
Add comparison operators for INTEGER_TYPE and rational in rational.hp…
riccardodebenedictis Apr 12, 2024
24b8cbc
Add base64 encoding utility function
riccardodebenedictis Apr 20, 2024
76565fe
Add crypto_tests to CMakeLists.txt
riccardodebenedictis Apr 21, 2024
887109d
Update CMake workflow to install dependencies on Ubuntu
riccardodebenedictis Apr 21, 2024
76b687a
Add timer.cpp to utils library
riccardodebenedictis Apr 22, 2024
d79cb81
Fix formatting issue in timer.cpp
riccardodebenedictis Apr 22, 2024
e666c7a
Update integer type in integer.hpp and CMakeLists.txt
riccardodebenedictis Apr 22, 2024
4938e50
Add Codecov coverage reporting to CMake workflow
riccardodebenedictis May 14, 2024
5c823e5
Add badges for build status and code coverage
riccardodebenedictis May 14, 2024
837aecd
Add include for cstdint in test_crypto.cpp
riccardodebenedictis May 16, 2024
ed58e60
Add new utilities and update timer class
riccardodebenedictis Oct 19, 2024
b168b38
Refactor loss function to calculate Mean Squared Error (MSE)
riccardodebenedictis Oct 19, 2024
96c1453
Refactor loss function to calculate Mean Squared Error (MSE) and Mean…
riccardodebenedictis Oct 19, 2024
f207d68
Refactor differentiable class to include virtual functions for functi…
riccardodebenedictis Oct 23, 2024
eaf3ddd
Refactor loss functions to return double instead of template type
riccardodebenedictis Oct 23, 2024
9478632
Refactor test_loss to use std::vector instead of raw pointers for bet…
riccardodebenedictis Oct 31, 2024
e2220f6
Add matrix utility functions and corresponding tests for matrix multi…
riccardodebenedictis Nov 4, 2024
e7ee03d
Refactor variable type from VARIABLE_TYPE to std::size_t across multi…
riccardodebenedictis Nov 11, 2024
01bb5be
Refactor variable type from std::size_t to var for improved readabili…
riccardodebenedictis Nov 11, 2024
e088f59
Refactor timer start method to use store instead of exchange for impr…
riccardodebenedictis Nov 20, 2024
1a86028
Refactor to use emplace_back for improved performance and clarity in …
riccardodebenedictis Dec 14, 2024
16b8ef8
Add -fsanitize=undefined flag for improved debugging in CMake configu…
riccardodebenedictis Dec 31, 2024
4599d22
Enhance CMake configuration with address sanitizer for improved memor…
riccardodebenedictis Dec 31, 2024
3581f68
Update CMake configuration to link with AddressSanitizer for enhanced…
riccardodebenedictis Dec 31, 2024
68c6bf3
Add coverage support for tests in CMake configuration
riccardodebenedictis Dec 31, 2024
7776f7d
Update CMake configuration to ensure utils library is linked for test…
riccardodebenedictis Dec 31, 2024
121447a
Refactor CMake configuration to remove AddressSanitizer flags and str…
riccardodebenedictis Dec 31, 2024
8bb4edd
Refactor CMake configuration to centralize sanitizer setup and stream…
riccardodebenedictis Jan 15, 2025
06faeeb
Update CMake configuration to use PROJECT_SOURCE_DIR for module path
riccardodebenedictis Jan 15, 2025
e5e1586
Enhance sanitizer setup in CMake to include AddressSanitizer flags fo…
riccardodebenedictis Jan 15, 2025
3a26208
Refactor sha1 constructor to accept std::string_view for improved per…
riccardodebenedictis Jan 15, 2025
87a0359
Refactor sanitizer setup in CMake to improve error handling and enabl…
riccardodebenedictis Jan 17, 2025
3a58ce0
Enhance GitHub Actions workflow for CMake to support multiple sanitiz…
riccardodebenedictis Jan 17, 2025
fe0bd7a
Refactor GitHub Actions workflow and sanitizer setup in CMake for imp…
riccardodebenedictis Jan 17, 2025
8907d7f
Refactor GitHub Actions workflow and sanitizer setup in CMake for imp…
riccardodebenedictis Jan 17, 2025
890a5dc
Add compile definitions to disable vector and string annotations for …
riccardodebenedictis Jan 17, 2025
ce42ae5
Fix target name in Address Sanitizer setup to correctly apply compile…
riccardodebenedictis Jan 17, 2025
51d2bc7
Add error message for missing MSVC environment when using Address San…
riccardodebenedictis Jan 17, 2025
9d58623
Update MSVC sanitizer setup to improve compile options and error mess…
riccardodebenedictis Jan 17, 2025
ec9708e
Update CMake configuration and SHA1 digest function for improved clar…
riccardodebenedictis Jan 17, 2025
4bf3ca3
Refactor sanitizer setup to improve clarity and ensure proper depende…
riccardodebenedictis Jan 17, 2025
5a85f89
Remove unnecessary status messages and compiler flag outputs from san…
riccardodebenedictis Jan 17, 2025
04719b0
Change target_compile_options and target_link_options to PUBLIC for b…
riccardodebenedictis Jan 17, 2025
991c56f
Fix typo in CMake configuration for UBSAN enablement in GitHub Action…
riccardodebenedictis Jan 17, 2025
7c7a299
Change target_compile_options and target_link_options to PRIVATE for …
riccardodebenedictis Jan 17, 2025
3bbd8b8
Add integer class for enhanced integer representation and operations
riccardodebenedictis Jan 23, 2025
22991ef
Add arithmetic and comparison operators to integer class for enhanced…
riccardodebenedictis Jan 23, 2025
5a5f8ce
Add unique and shared pointer implementations with corresponding tests
riccardodebenedictis Jan 25, 2025
4c6d3d1
Enhance unique and shared pointer implementations with move semantics…
riccardodebenedictis Jan 25, 2025
f98852e
Delete copy assignment operator from unique pointer to prevent copying
riccardodebenedictis Jan 25, 2025
ef97b35
Add copy constructor to shared pointer for shared ownership
riccardodebenedictis Jan 25, 2025
82a6b79
Add equality operator to ref_wrapper for comparison functionality
riccardodebenedictis Jan 27, 2025
60c9c49
Refactor unique and shared pointer constructors to simplify template …
riccardodebenedictis Jan 27, 2025
1d833f5
Implement dynamic_cast in s_ptr_cast for safer type conversion
riccardodebenedictis Jan 27, 2025
1e5ddc6
Add copy and move assignment operators to shared pointer and implemen…
riccardodebenedictis Jan 27, 2025
c77a0fa
Add utility functions for lbool and implement to_string for integer c…
riccardodebenedictis Jan 29, 2025
507feff
Add assertions to integer operators for handling indeterminate forms
riccardodebenedictis Jan 29, 2025
ff961d5
Refactor shared pointer constructor and assignment operators to simpl…
riccardodebenedictis Jan 31, 2025
6c39826
Add noexcept specifier to integer constructors for improved safety an…
riccardodebenedictis Feb 4, 2025
0cf2846
Add noexcept swap function to unique pointer for exception safety
riccardodebenedictis Feb 7, 2025
df8588a
Add floor and ceil functions for rational numbers with tests
riccardodebenedictis Feb 7, 2025
7881246
Add [[nodiscard]] specifier to rational operators for improved safety
riccardodebenedictis Feb 8, 2025
00b4b76
Add [[nodiscard]] specifier to floor and ceil functions for improved …
riccardodebenedictis Feb 8, 2025
9871f72
Add Floyd-Warshall algorithm implementation with tests
riccardodebenedictis Feb 10, 2025
b66441e
Fix assignment operator checks in unique and shared pointer implement…
riccardodebenedictis Feb 13, 2025
807d05d
Add noexcept specifier to move constructors in unique and shared poin…
riccardodebenedictis Feb 21, 2025
76277cf
Use dynamic_cast in shared pointer copy constructor for safer type co…
riccardodebenedictis Apr 1, 2025
d2fac4e
Replace dynamic_cast with static_cast in shared pointer copy construc…
riccardodebenedictis Apr 1, 2025
03bbc3e
Add crypto module with SHA-1, SHA-256, and Base64 encoding/decoding f…
riccardodebenedictis Apr 14, 2025
8dba1c0
Refactor test addition for crypto_tests to be conditional on BUILD_CR…
riccardodebenedictis Apr 14, 2025
5992f5d
Remove SHA-1, SHA-256, and Base64 functions from crypto module; add s…
riccardodebenedictis Apr 14, 2025
bbd9276
Remove BUILD_CRYPTO matrix strategy from CMake workflows for simplifi…
riccardodebenedictis Apr 14, 2025
f208317
Add [[nodiscard]] attribute to base64_encode function for better warn…
riccardodebenedictis May 14, 2025
757a30a
Update CMake installation command to use --formula option for consist…
riccardodebenedictis Jul 8, 2025
a13fb2a
Add base64url encoding and RS256 signing functions; enhance password …
riccardodebenedictis Jul 10, 2025
498c943
Remove redundant dependency installation steps from CMake workflows
riccardodebenedictis Sep 4, 2025
4462481
Add dependency installation steps for lcov and valgrind in CMake work…
riccardodebenedictis Sep 4, 2025
ba0c4e7
Rename test step for clarity in CMake workflow
riccardodebenedictis Sep 4, 2025
842c593
Implement to_string functions for inf_rational, rational, and lin typ…
riccardodebenedictis Sep 17, 2025
6d2b323
Add to_string function for integer type; enhance string representation
riccardodebenedictis Sep 17, 2025
c6f690b
Refactor constructors in inf_rational, integer, lin, rational, and li…
riccardodebenedictis Oct 2, 2025
55f7155
Refactor tests to replace utils::rational::zero and utils::rational::…
riccardodebenedictis Oct 2, 2025
f44b6f6
Refactor lit class: move friend function declarations outside the cla…
riccardodebenedictis Oct 23, 2025
1bd406a
Refactor sha1 class: rename variable for clarity in process_bytes fun…
riccardodebenedictis Oct 27, 2025
4656806
Refactor inf_rational class: move friend function definitions outside…
riccardodebenedictis Oct 31, 2025
e4aeb7c
Refactor inf_rational and rational classes: move friend function decl…
riccardodebenedictis Oct 31, 2025
d3cc24f
Refactor rational class: move operator overloads to header for improv…
riccardodebenedictis Nov 7, 2025
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
151 changes: 151 additions & 0 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
name: CMake

on: [push, pull_request]

jobs:
ubuntu-address-undefined-coverage:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y lcov

- name: Configure CMake
run: cmake -B build -DCMAKE_BUILD_TYPE=Debug -DENABLE_ASAN=ON -DENABLE_UBSAN=ON -DENABLE_COV=ON

- name: Build
run: cmake --build build --config Debug

- name: Test with address sanitizer, undefined behavior sanitizer and coverage
working-directory: build
run: ctest -C Debug --rerun-failed --output-on-failure -T Test -T Coverage

- name: Make coverage report
run: |
lcov --capture --directory build --output-file coverage.info
lcov --remove coverage.info '/usr/*' --output-file coverage.info
lcov --list coverage.info

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4.0.1
with:
token: ${{ secrets.CODECOV_TOKEN }}

ubuntu-memcheck:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y valgrind

- name: Configure CMake
run: cmake -B build -DCMAKE_BUILD_TYPE=Debug

- name: Build
run: cmake --build build --config Debug

- name: Test with memory checker
working-directory: build
run: ctest -C Debug --rerun-failed --output-on-failure -T Test -T MemCheck

windows-debug:
runs-on: windows-latest

steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Configure CMake
run: cmake -B build -DCMAKE_BUILD_TYPE=Debug

- name: Build
run: cmake --build build --config Debug

- name: Test
working-directory: build
run: ctest -C Debug --rerun-failed --output-on-failure -T Test

macos-address-undefined:
runs-on: macos-latest

steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Configure CMake
run: cmake -B build -DCMAKE_BUILD_TYPE=Debug -DENABLE_ASAN=ON -DENABLE_UBSAN=ON

- name: Build
run: cmake --build build --config Debug

- name: Test with address sanitizer and undefined behavior sanitizer
working-directory: build
run: ctest -C Debug --rerun-failed --output-on-failure -T Test

ubuntu-release:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Configure CMake
run: cmake -B build -DCMAKE_BUILD_TYPE=Release

- name: Build
run: cmake --build build --config Release

- name: Test
working-directory: build
run: ctest -C Release --rerun-failed --output-on-failure -T Test

windows-release:
runs-on: windows-latest

steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Configure CMake
run: cmake -B build -DCMAKE_BUILD_TYPE=Release

- name: Build
run: cmake --build build --config Release

- name: Test
working-directory: build
run: ctest -C Release --rerun-failed --output-on-failure -T Test

macos-release:
runs-on: macos-latest

steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Configure CMake
run: cmake -B build -DCMAKE_BUILD_TYPE=Release

- name: Build
run: cmake --build build --config Release

- name: Test
working-directory: build
run: ctest -C Release --rerun-failed --output-on-failure -T Test
114 changes: 48 additions & 66 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,83 +1,65 @@
cmake_minimum_required(VERSION 3.0.0)
project(utils VERSION 0.1.0)
cmake_minimum_required(VERSION 3.21)
project(utils VERSION 0.2.0 LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=undefined")

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

include(GenerateExportHeader)
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/Modules")
include(Sanitizers)

include(CTest)
enable_testing()

set(INTEGER_TYPES "int" "long" "long long")
set(INTEGER_TYPE "long" CACHE STRING "Integer type")
set_property(CACHE INTEGER_TYPE PROPERTY STRINGS ${INTEGER_TYPES})

option(VERBOSE_LOG "Makes log more verbose" OFF)
option(ADD_COVERAGE "Add coverage" OFF)
set(INT_TYPES "int" "long" "long long")
set(INT_TYPE "long" CACHE STRING "Integer type")
set_property(CACHE INT_TYPE PROPERTY STRINGS ${INT_TYPES})
list(FIND INT_TYPES ${INT_TYPE} INT_TYPE_INDEX)
if(${INT_TYPE_INDEX} EQUAL -1)
message(FATAL_ERROR "Invalid integer type: ${INT_TYPE}")
endif()

file(GLOB UTILS_SOURCES src/*.cpp)
file(GLOB UTILS_HEADERS include/*.h)
set(LOGGING_LEVELS "TRACE" "DEBUG" "INFO" "WARN" "ERROR" "FATAL")
set(LOGGING_LEVEL "INFO" CACHE STRING "Logging level")
set_property(CACHE LOGGING_LEVEL PROPERTY STRINGS ${LOGGING_LEVELS})
list(FIND LOGGING_LEVELS ${LOGGING_LEVEL} LOGGING_LEVEL_INDEX)
if(${LOGGING_LEVEL_INDEX} EQUAL -1)
message(FATAL_ERROR "Invalid logging level: ${LOGGING_LEVEL}")
endif()

add_library(${PROJECT_NAME} SHARED ${UTILS_SOURCES})
GENERATE_EXPORT_HEADER(${PROJECT_NAME})
target_include_directories(${PROJECT_NAME} PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>/include $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>)
option(BUILD_CRYPTO "Build crypto" OFF)

message(STATUS "Integer type: ${INTEGER_TYPE}")
if(INTEGER_TYPE STREQUAL "int")
target_compile_definitions(${PROJECT_NAME} PUBLIC INTEGER_TYPE_INT)
elseif(INTEGER_TYPE STREQUAL "long")
target_compile_definitions(${PROJECT_NAME} PUBLIC INTEGER_TYPE_LONG)
elseif(INTEGER_TYPE STREQUAL "long long")
target_compile_definitions(${PROJECT_NAME} PUBLIC INTEGER_TYPE_LONG_LONG)
else()
message(FATAL_ERROR "INTEGER_TYPE must be one of ${INTEGER_TYPES}")
if(LOGGING_LEVEL STREQUAL "TRACE")
set(LOG_LEVEL 6)
elseif(LOGGING_LEVEL STREQUAL "DEBUG")
set(LOG_LEVEL 5)
elseif(LOGGING_LEVEL STREQUAL "INFO")
set(LOG_LEVEL 4)
elseif(LOGGING_LEVEL STREQUAL "WARN")
set(LOG_LEVEL 3)
elseif(LOGGING_LEVEL STREQUAL "ERROR")
set(LOG_LEVEL 2)
elseif(LOGGING_LEVEL STREQUAL "FATAL")
set(LOG_LEVEL 1)
endif()

if(BUILD_TESTING)
add_subdirectory(tests)
endif()
message(STATUS "Integer type: ${INT_TYPE}")
message(STATUS "Logging level: ${LOGGING_LEVEL}")

message(STATUS "Verbose log: ${VERBOSE_LOG}")
if(VERBOSE_LOG)
target_compile_definitions(${PROJECT_NAME} PUBLIC VERBOSE_LOG)
endif()
add_library(utils src/integer.cpp src/rational.cpp src/inf_rational.cpp src/lin.cpp src/tableau.cpp src/timer.cpp)
target_compile_features(utils PUBLIC cxx_std_17)
target_include_directories(utils PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>)
target_compile_definitions(utils PUBLIC INT_TYPE=${INT_TYPE} LOGGING_LEVEL=${LOG_LEVEL})
setup_sanitizers(utils)

message(STATUS "Build crypto: ${BUILD_CRYPTO}")
if(BUILD_CRYPTO)
find_package(OpenSSL REQUIRED)

if(MSVC)
target_compile_options(${PROJECT_NAME} PRIVATE /W4)
else()
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -Wpedantic)
if (ADD_COVERAGE)
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_options(${PROJECT_NAME} PRIVATE --coverage)
target_link_libraries(${PROJECT_NAME} PUBLIC gcov)
endif()
endif()
target_sources(utils PRIVATE src/crypto.cpp)
target_link_libraries(utils PUBLIC OpenSSL::Crypto)
endif()

install(
TARGETS ${PROJECT_NAME}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
install(
FILES ${UTILS_HEADERS} ${CMAKE_CURRENT_BINARY_DIR}/utils_export.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}
)
configure_package_config_file(src/${PROJECT_NAME}Config.cmake.in ${PROJECT_NAME}Config.cmake INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} PATH_VARS CMAKE_INSTALL_INCLUDEDIR)
write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake VERSION 1.0.0 COMPATIBILITY SameMajorVersion)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
)
if(BUILD_TESTING)
add_subdirectory(tests)
endif()

set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_NAME utils)
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
# Utils

![Build Status](https://github.com/ratioSolver/Utils/actions/workflows/cmake.yml/badge.svg)
[![codecov](https://codecov.io/gh/ratioSolver/Utils/branch/master/graph/badge.svg)](https://codecov.io/gh/ratioSolver/Utils)

This repository contains the source code for a library of utility functions for the C++ programming language.
Currently implemented utilities are:
- Logging macros, including logging capabilities for some containers
- Cartesian product of containers
- Combinations of given size from a container
- Propositional literals
- Rationals
- Infinitesimal rationals
- Memory management utilities (e.g. `c_ptr`, `u_ptr`, etc.)
- Base64 encoding and decoding
- SHA1 hashing
89 changes: 89 additions & 0 deletions cmake/Modules/Sanitizers.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Sanitizers.cmake
# A CMake module to simplify sanitizer setup.

function(setup_sanitizers target)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_options(${target} PRIVATE -Wall -Wextra -Wpedantic)

if (ENABLE_MSAN)
message(FATAL_ERROR "Memory sanitizer is not supported with GCC")
endif()

set(SANITIZERS "")

if (ENABLE_ASAN)
list(APPEND SANITIZERS "address")
endif()

if (ENABLE_UBSAN)
list(APPEND SANITIZERS "undefined")
endif()

list(JOIN SANITIZERS "," LIST_OF_SANITIZERS)

if ("${LIST_OF_SANITIZERS}" STREQUAL "")
message(STATUS "No sanitizers for ${target}")
else()
message(STATUS "Sanitizers enabled for ${target}: ${LIST_OF_SANITIZERS}")
target_compile_options(${target} PRIVATE -fsanitize=${LIST_OF_SANITIZERS})
target_link_options(${target} PRIVATE -fsanitize=${LIST_OF_SANITIZERS})
endif()

if (ENABLE_COV)
message(STATUS "Code coverage enabled for ${target}")
target_compile_options(${target} PRIVATE --coverage)
target_link_libraries(${target} PRIVATE --coverage)
endif()
elseif(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang")
target_compile_options(${target} PRIVATE -Wall -Wextra -Wpedantic)

set(SANITIZERS "")

if (ENABLE_ASAN)
list(APPEND SANITIZERS "address")
endif()

if (ENABLE_MSAN)
list(APPEND SANITIZERS "memory")
endif()

if (ENABLE_UBSAN)
list(APPEND SANITIZERS "undefined")
endif()

list(JOIN SANITIZERS "," LIST_OF_SANITIZERS)

if ("${LIST_OF_SANITIZERS}" STREQUAL "")
message(STATUS "No sanitizers for ${target}")
else()
message(STATUS "Sanitizers enabled for ${target}: ${LIST_OF_SANITIZERS}")
target_compile_options(${target} PRIVATE -fsanitize=${LIST_OF_SANITIZERS})
target_link_options(${target} PRIVATE -fsanitize=${LIST_OF_SANITIZERS})
endif()
elseif(MSVC)
target_compile_options(${target} PRIVATE /W4 /Zi /INCREMENTAL:NO)

if (ENABLE_MSAN)
message(FATAL_ERROR "Memory sanitizer is not supported with MSVC")
endif()

if (ENABLE_UBSAN)
message(FATAL_ERROR "Undefined behavior sanitizer is not supported with MSVC")
endif()

if (NOT ENABLE_ASAN)
message(STATUS "No sanitizers for ${target}")
else()
message(STATUS "Address sanitizer enabled for ${target}")
string(FIND "$ENV{PATH}" "$ENV{VSINSTALLDIR}" index_of_vs_install_dir)
if("${index_of_vs_install_dir}" STREQUAL "-1")
message(FATAL_ERROR "Visual Studio environment not found")
endif()
target_compile_options(${target} PRIVATE /fsanitize=address)
target_compile_definitions(${target} PRIVATE _DISABLE_VECTOR_ANNOTATION _DISABLE_STRING_ANNOTATION)
target_link_options(${target} PRIVATE /INCREMENTAL:NO)
endif()
else()
message(FATAL_ERROR "Unsupported compiler")
endif()
endfunction()
Loading