Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Switch to modern C++ version #161

Closed
wants to merge 3 commits into from
Closed
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
19 changes: 1 addition & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ project(zswap-cli
LANGUAGES CXX
)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# ======================================================
Expand Down Expand Up @@ -53,7 +53,6 @@ include(FetchContent)
include(cmake/FindPandoc.cmake)
include(cmake/FindKernelHeaders.cmake)
include(cmake/FindGlibcHeaders.cmake)
include(cmake/FindFileSystem.cmake)

# ======================================================
# ================== Boost detection ===================
Expand Down Expand Up @@ -87,12 +86,6 @@ if (BUILD_DOC)
set(DOXYGEN_USE_MDFILE_AS_MAINPAGE "README.md")
endif()

# ======================================================
# ================= fmtlib detection ===================
# ======================================================

find_package(fmt 6.1.2 REQUIRED)

# ======================================================
# ================= semver detection ===================
# ======================================================
Expand Down Expand Up @@ -161,7 +154,6 @@ target_include_directories(${LIB_NAME} PUBLIC
)

target_link_libraries(${LIB_NAME} PUBLIC
fmt::fmt
semver::semver
)

Expand Down Expand Up @@ -189,18 +181,9 @@ target_include_directories(${APP_NAME} PRIVATE

target_link_libraries(${APP_NAME} PRIVATE
${LIB_NAME}
fmt::fmt
Boost::program_options
)

if (FILESYSTEM_REQUIRE_LINKAGE)
target_link_libraries(${APP_NAME} PRIVATE stdc++fs)
endif()

if(FILESYSTEM_REQUIRE_EXPERIMENTAL)
target_compile_definitions(${APP_NAME} PRIVATE FILESYSTEM_LEGACY)
endif()

install(TARGETS ${APP_NAME} DESTINATION ${CMAKE_INSTALL_SBINDIR})

# ======================================================
Expand Down
53 changes: 0 additions & 53 deletions cmake/FindFileSystem.cmake

This file was deleted.

1 change: 0 additions & 1 deletion docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ You need the following versions:
* Clang: 7.0+;
* CMake: 3.14+;
* Boost: 1.65.0+;
* fmt: 6.1.2+;
* semver: 0.3.0+ (optional);
* doxygen (for building documentation);
* pandoc (for generating manpage).
Expand Down
23 changes: 8 additions & 15 deletions src/app/application/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,13 @@
*/

#include <iostream>
#include <filesystem>
#include <format>
#include <fstream>
#include <memory>
#include <stdexcept>

#ifndef FILESYSTEM_LEGACY
#include <filesystem>
namespace fs = std::filesystem;
#else
#include <experimental/filesystem>
namespace fs = std::experimental::filesystem;
#endif

#include <boost/program_options.hpp>
#include <fmt/format.h>

#include "appconstants/appconstants.hpp"
#include "application/application.hpp"
Expand All @@ -29,14 +22,14 @@ namespace fs = std::experimental::filesystem;

void Application::PrintDebugInfo()
{
if (!fs::exists(ZSwapDebug::GetModulePath()))
if (!std::filesystem::exists(ZSwapDebug::GetModulePath()))
{
std::cout << "ZSwap is not running or access to debug is denied." << std::endl;
return;
}

std::unique_ptr<ZSwapDebug> ZSwapDebugger = std::make_unique<ZSwapDebug>();
std::cout << fmt::format("Duplicate entries count: {0}.\n"
std::cout << std::format("Duplicate entries count: {0}.\n"
"Pool limit hit: {1}.\n"
"Pool total size: {2}.\n"
"Reject allocation failures: {3}.\n"
Expand All @@ -62,7 +55,7 @@ void Application::PrintDebugInfo()

void Application::PrintSettings()
{
std::cout << fmt::format("ZSwap enabled: {0}.\n"
std::cout << std::format("ZSwap enabled: {0}.\n"
"Same filled pages enabled: {1}.\n"
"Maximum pool percentage: {2}.\n"
"Compression algorithm: {3}.\n"
Expand Down Expand Up @@ -101,7 +94,7 @@ void Application::PrintSummary()
const float SwapUsedPercent = static_cast<float>(ZSwapDebugger -> GetStoredPages() * CWrappers::GetSCPageSize()) / static_cast<float>(SysInfo -> GetTotalSwap() - SysInfo -> GetFreeSwap()) * 100.f;
const float CompressionRatio = StoredPagesMB / PoolSizeMB;

std::cout << fmt::format("Pool: {0:.2f} MiB ({1:.1f}% of MemTotal).\n"
std::cout << std::format("Pool: {0:.2f} MiB ({1:.1f}% of MemTotal).\n"
"Stored: {2:.2f} MiB ({3:.1f}% of SwapUsed).\n"
"Compression ratio: {4:.2f}.",
PoolSizeMB,
Expand Down Expand Up @@ -154,7 +147,7 @@ int Application::PrintHelp()

int Application::PrintVersion()
{
std::cout << fmt::format("{0} project version: {1}.",
std::cout << std::format("{0} project version: {1}.",
AppConstants::ProductNameInternal,
AppConstants::ProductVersion)
<< std::endl;
Expand Down Expand Up @@ -201,7 +194,7 @@ int Application::ExecuteConfig(const std::string& ConfigFile)
("zswap.shrinker_enabled", boost::program_options::value<std::string>(), "Enable or disable pool shrinking based on memory pressure.")
;

if (!fs::exists(ConfigFile)) throw std::invalid_argument("Configuration file does not exist!");
if (!std::filesystem::exists(ConfigFile)) throw std::invalid_argument("Configuration file does not exist!");
std::ifstream ConfigFileFs(ConfigFile);
boost::program_options::store(boost::program_options::parse_config_file(ConfigFileFs, *ConfigOptions), *Config);
Config -> notify();
Expand Down
4 changes: 2 additions & 2 deletions src/lib/zswapobject/zswapobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
*/

#include <iostream>
#include <format>
#include <fstream>
#include <stdexcept>
#include <string>
#include <regex>

#include <fmt/format.h>
#include <semver.hpp>

#include "ksysversion/ksysversion.hpp"
Expand All @@ -35,7 +35,7 @@ bool ZSwapObject::CheckKernelVersion(const std::string& RequiredKernelVersion)

void ZSwapObject::WriteLogEntry(const std::string& Name, const std::string& NewValue, const std::string& OldValue)
{
std::cout << fmt::format("Writing a new value \"{1}\" to the \"{0}\" variable. The old value was: \"{2}\".", Name, NewValue, OldValue) << std::endl;
std::cout << std::format("Writing a new value \"{1}\" to the \"{0}\" variable. The old value was: \"{2}\".", Name, NewValue, OldValue) << std::endl;
}

void ZSwapObject::WriteZSwapValue(const std::string& Name, const std::string& Value)
Expand Down
Loading