diff --git a/CMakeLists.txt b/CMakeLists.txt index 465d57a..4815d51 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.12) +cmake_minimum_required(VERSION 3.18) set(VERSION_MAJOR 0) set(VERSION_MINOR 3) @@ -9,11 +9,12 @@ project(telemetry VERSION ${VERSION}) include(cmake/build_type.cmake) include(cmake/installation.cmake) +include(cmake/dependencies.cmake) -option(TELEMETRY_BUILD_SHARED "Build shared library" ON) -option(TELEMETRY_PACKAGE_BUILDER "Enable RPM package builder (make rpm)" ON) -option(TELEMETRY_INSTALL_TARGETS "Generate the install target" ON) -option(TELEMETRY_ENABLE_TESTS "Build Unit tests (make test)" OFF) +option(TELEMETRY_BUILD_SHARED "Build shared library" ON) +option(TELEMETRY_PACKAGE_BUILDER "Enable RPM package builder (make rpm)" ON) +option(TELEMETRY_INSTALL_TARGETS "Generate the install target" ON) +option(TELEMETRY_ENABLE_TESTS "Build Unit tests (make test)" OFF) option(TELEMETRY_ENABLE_DOC_DOXYGEN "Enable build of code documentation" OFF) set(CMAKE_CXX_STANDARD 17) @@ -21,19 +22,10 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS ON) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wall -Wextra") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wall -Wextra -Wunused -Wconversion -Wsign-conversion") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -Werror") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -ggdb3") -# This option ensures that standard include header paths are explicitly added -# to the generated compile_commands.json file. -# clang-tidy doesn't seem to find standard include headers otherwise. -if (CMAKE_EXPORT_COMPILE_COMMANDS) - set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES}) -endif() - -include(cmake/dependencies.cmake) - if (TELEMETRY_ENABLE_TESTS) include(cmake/googletest.cmake) include(GoogleTest) diff --git a/cmake/googletest.cmake b/cmake/googletest.cmake index 0f2aa4f..b9ca222 100644 --- a/cmake/googletest.cmake +++ b/cmake/googletest.cmake @@ -12,4 +12,10 @@ FetchContent_Declare( GIT_REPOSITORY https://github.com/google/googletest.git GIT_TAG v1.14.0 ) + +# Library does not compile with -Wsign-conversion that we use in builds +string(REPLACE "-Wsign-conversion " " " CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ") +string(REPLACE "-Wsign-conversion " " " CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ") +string(REPLACE "-Wsign-conversion " " " CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ") + FetchContent_MakeAvailable(googletest) diff --git a/src/appFs/appFs.cpp b/src/appFs/appFs.cpp index ecc1927..740cc9c 100644 --- a/src/appFs/appFs.cpp +++ b/src/appFs/appFs.cpp @@ -32,7 +32,8 @@ static off_t getMaxFileSize(const std::shared_ptr& file) } constexpr double requiredBlockEmptyCapacityMultiplier = 0.5; - constexpr size_t requiredCapacity = blockSize * requiredBlockEmptyCapacityMultiplier; + constexpr auto requiredCapacity = static_cast( + static_cast(blockSize) * requiredBlockEmptyCapacityMultiplier); const size_t contentSize = fileContentToString(file).size(); const size_t blockSizeMultiplier = (contentSize + requiredCapacity) / blockSize + 1; @@ -217,12 +218,14 @@ static int readFile( cacheBuffer = fileContentToString(file); } - if (static_cast(offset) >= cacheBuffer.size()) { + const auto uOffset = static_cast(offset); + + if (uOffset >= cacheBuffer.size()) { return 0; } - const size_t length = std::min(size, cacheBuffer.size() - offset); - std::memcpy(buffer, cacheBuffer.c_str() + offset, length); + const size_t length = std::min(size, cacheBuffer.size() - uOffset); + std::memcpy(buffer, cacheBuffer.c_str() + uOffset, length); return static_cast(length); }