From bc01f2f981264446d095c1daad1451947bdc13a9 Mon Sep 17 00:00:00 2001 From: ruslan-ilesik Date: Sun, 4 Aug 2024 13:20:08 +0200 Subject: [PATCH] removed autconfig and adjusted dpp for formatters without it --- .gitignore | 1 - CMakeLists.txt | 51 +------------------------------------ include/dpp/autoconfig.h.in | 27 -------------------- include/dpp/snowflake.h | 7 +++-- library/CMakeLists.txt | 6 ++++- src/unittest/test.cpp | 4 +-- 6 files changed, 11 insertions(+), 85 deletions(-) delete mode 100644 include/dpp/autoconfig.h.in diff --git a/.gitignore b/.gitignore index 20a8eef932..bbf269173b 100644 --- a/.gitignore +++ b/.gitignore @@ -12,7 +12,6 @@ buildtools/composer.phar src/build cmake-build-debug docpages/example_code/build -*autoconfig.h # tests test diff --git a/CMakeLists.txt b/CMakeLists.txt index 2a67f21717..f2e7a58f2d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) @@ -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 - #include - - struct MyType { - int value; - std::string str() const { return std::to_string(value); } - }; - - template <> - struct std::formatter : std::formatter { - 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 -) diff --git a/include/dpp/autoconfig.h.in b/include/dpp/autoconfig.h.in deleted file mode 100644 index fd53c66bfe..0000000000 --- a/include/dpp/autoconfig.h.in +++ /dev/null @@ -1,27 +0,0 @@ -/************************************************************************************ - * - * D++, A Lightweight C++ library for Discord - * - * SPDX-License-Identifier: Apache-2.0 - * Copyright 2021 Craig Edwards and D++ contributors - * (https://github.com/brainboxdotcc/DPP/graphs/contributors) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ************************************************************************************/ - -#pragma once - -#if __cplusplus >= 202002L // c++20 or higher -#cmakedefine DPP_HAS_FORMAT -#endif diff --git a/include/dpp/snowflake.h b/include/dpp/snowflake.h index e6679b04d0..109f16a53a 100644 --- a/include/dpp/snowflake.h +++ b/include/dpp/snowflake.h @@ -23,11 +23,10 @@ #include #include #include -#include #include #include -#ifdef DPP_HAS_FORMAT +#ifdef DPP_FORMATTERS #include #endif @@ -287,7 +286,7 @@ struct std::hash } }; -#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 @@ -305,4 +304,4 @@ struct std::formatter return std::format_to(ctx.out(), "{}", snowflake.str()); } }; -#endif //DPP_HAS_FORMAT +#endif //DPP_FORMATTERS diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index e0eac6632c..00b2a8b651 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -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/*") @@ -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) diff --git a/src/unittest/test.cpp b/src/unittest/test.cpp index 33dddc3d1c..1af1301003 100644 --- a/src/unittest/test.cpp +++ b/src/unittest/test.cpp @@ -381,7 +381,7 @@ 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" && @@ -389,7 +389,7 @@ Markdown lol \\|\\|spoiler\\|\\| \\~\\~strikethrough\\~\\~ \\`small \\*code\\* b ); #else set_status(SNOWFLAKE_STD_FORMAT,ts_skipped); - #endif // DPP_HAS_FORMAT + #endif // DPP_FORMATTERS }; { // test dpp::json_interface