Skip to content

Commit

Permalink
removed autconfig and adjusted dpp for formatters without it
Browse files Browse the repository at this point in the history
  • Loading branch information
ruslan-ilesik committed Aug 4, 2024
1 parent d21fa02 commit bc01f2f
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 85 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ buildtools/composer.phar
src/build
cmake-build-debug
docpages/example_code/build
*autoconfig.h

# tests
test
Expand Down
51 changes: 1 addition & 50 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ option(DPP_INSTALL "Generate the install target" ON)
option(DPP_BUILD_TEST "Build the test program" ON)
option(DPP_NO_VCPKG "No VCPKG" OFF)
option(DPP_CORO "Experimental support for C++20 coroutines" OFF)
option(DPP_FORMATTERS "Support for C++20 formatters" OFF)
option(DPP_USE_EXTERNAL_JSON "Use an external installation of nlohmann::json" OFF)
option(DPP_USE_PCH "Use precompiled headers to speed up compilation" OFF)
option(AVX_TYPE "Force AVX type for speeding up audio mixing" OFF)
Expand Down Expand Up @@ -115,53 +116,3 @@ else()
# that made no sense, it seems they may have changed their parsing rules somehow.
message("-- Using bundled nlohmann::json")
endif()

if(CMAKE_CXX_STANDARD GREATER_EQUAL 20 OR DPP_CORO)
include(CheckCXXSourceCompiles)
unset(HAS_FORMAT CACHE)
set(temp_flags "${CMAKE_REQUIRED_FLAGS}")
if (MSVC)
set(CMAKE_REQUIRED_FLAGS "/std:c++20")
else ()
set(CMAKE_REQUIRED_FLAGS "-std=c++20")
endif ()
check_cxx_source_compiles(
"
#include <format>
#include <string>
struct MyType {
int value;
std::string str() const { return std::to_string(value); }
};
template <>
struct std::formatter<MyType> : std::formatter<std::string> {
auto format(const MyType& item, std::format_context& ctx) const -> decltype(ctx.out()) {
return std::format_to(ctx.out(), \"{}\", item.str());
}
};
int main() {
MyType my{42};
auto s = std::format(\"{}\", my);
return 0;
}
"
HAS_FORMAT

)
set(CMAKE_REQUIRED_FLAGS ${temp_flags})
if(HAS_FORMAT)
message("-- INFO: Found std::format support")
set(DPP_HAS_FORMAT 1)
else ()
message("-- INFO: std::format support not found")
endif()
endif ()

configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/include/dpp/autoconfig.h.in
${CMAKE_CURRENT_SOURCE_DIR}/include/dpp/autoconfig.h
@ONLY
)
27 changes: 0 additions & 27 deletions include/dpp/autoconfig.h.in

This file was deleted.

7 changes: 3 additions & 4 deletions include/dpp/snowflake.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@
#include <dpp/export.h>
#include <dpp/json_fwd.h>
#include <dpp/exception.h>
#include <dpp/autoconfig.h>
#include <cstdint>
#include <type_traits>

#ifdef DPP_HAS_FORMAT
#ifdef DPP_FORMATTERS
#include <format>
#endif

Expand Down Expand Up @@ -287,7 +286,7 @@ struct std::hash<dpp::snowflake>
}
};

#ifdef DPP_HAS_FORMAT
#ifdef DPP_FORMATTERS
/*
* @brief implementation of formater for dpp::snowflake for std::format support
* https://en.cppreference.com/w/cpp/utility/format/formatter
Expand All @@ -305,4 +304,4 @@ struct std::formatter<dpp::snowflake>
return std::format_to(ctx.out(), "{}", snowflake.str());
}
};
#endif //DPP_HAS_FORMAT
#endif //DPP_FORMATTERS
6 changes: 5 additions & 1 deletion library/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,10 @@ if(DPP_CORO)
COMMAND php buildtools/make_struct.php "\\Dpp\\Generator\\CoroGenerator")
endif()

if(DPP_FORMATTERS)
target_compile_definitions(dpp PUBLIC DPP_FORMATTERS)
endif()

if (DPP_BUILD_TEST)
enable_testing(${CMAKE_CURRENT_SOURCE_DIR}/..)
file(GLOB testnamelist "${CMAKE_CURRENT_SOURCE_DIR}/../src/*")
Expand All @@ -351,7 +355,7 @@ if (DPP_BUILD_TEST)
set (testsrc "")
file(GLOB testsrc "${modules_dir}/${testname}/*.cpp")
add_executable(${testname} ${testsrc})
if (DPP_CORO)
if (DPP_CORO OR DPP_FORMATTERS)
target_compile_features(${testname} PRIVATE cxx_std_20)
else()
target_compile_features(${testname} PRIVATE cxx_std_17)
Expand Down
4 changes: 2 additions & 2 deletions src/unittest/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,15 +381,15 @@ Markdown lol \\|\\|spoiler\\|\\| \\~\\~strikethrough\\~\\~ \\`small \\*code\\* b

{ // test snowflake: std::format support

#ifdef DPP_HAS_FORMAT
#ifdef DPP_FORMATTERS
set_test(SNOWFLAKE_STD_FORMAT,
std::format("{}",dpp::snowflake{}) == "0" &&
std::format("{}",dpp::snowflake{12345}) == "12345" &&
std::format("{} hello {}", dpp::snowflake{12345}, dpp::snowflake{54321}) == "12345 hello 54321"
);
#else
set_status(SNOWFLAKE_STD_FORMAT,ts_skipped);
#endif // DPP_HAS_FORMAT
#endif // DPP_FORMATTERS
};

{ // test dpp::json_interface
Expand Down

0 comments on commit bc01f2f

Please sign in to comment.