Skip to content

Commit

Permalink
Merge pull request #20 from CESNET/cmake-improvments
Browse files Browse the repository at this point in the history
Cmake improvements
  • Loading branch information
SiskaPavel authored Oct 4, 2024
2 parents 5511961 + c074b4b commit 4741a69
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
22 changes: 7 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.12)
cmake_minimum_required(VERSION 3.18)

set(VERSION_MAJOR 0)
set(VERSION_MINOR 3)
Expand All @@ -9,31 +9,23 @@ 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)
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)
Expand Down
6 changes: 6 additions & 0 deletions cmake/googletest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
11 changes: 7 additions & 4 deletions src/appFs/appFs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ static off_t getMaxFileSize(const std::shared_ptr<File>& file)
}

constexpr double requiredBlockEmptyCapacityMultiplier = 0.5;
constexpr size_t requiredCapacity = blockSize * requiredBlockEmptyCapacityMultiplier;
constexpr auto requiredCapacity = static_cast<size_t>(
static_cast<double>(blockSize) * requiredBlockEmptyCapacityMultiplier);

const size_t contentSize = fileContentToString(file).size();
const size_t blockSizeMultiplier = (contentSize + requiredCapacity) / blockSize + 1;
Expand Down Expand Up @@ -217,12 +218,14 @@ static int readFile(
cacheBuffer = fileContentToString(file);
}

if (static_cast<size_t>(offset) >= cacheBuffer.size()) {
const auto uOffset = static_cast<size_t>(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<int>(length);
}
Expand Down

0 comments on commit 4741a69

Please sign in to comment.