diff --git a/CMakeLists.txt b/CMakeLists.txt index 025203badf..85f4547080 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,7 +24,7 @@ option(RUN_LDCONFIG "Run ldconfig after installation" ON) 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_CORO "Experimental support for C++20 coroutines" ON) 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,3 +115,43 @@ else() # that made no sense, it seems they may have changed their parsing rules somehow. message("-- Using bundled nlohmann::json") endif() + +if ("cxx_std_20" IN_LIST CMAKE_CXX_COMPILE_FEATURES) + include(CheckCXXSourceCompiles) + unset(HAS_FORMAT CACHE) + set(temp_flags "${CMAKE_REQUIRED_FLAGS}") + set(CMAKE_REQUIRED_FLAGS "-std=c++20") + 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") + target_compile_definitions(dpp PUBLIC DPP_HAS_FORMAT) + else () + message("-- INFO: std::format support not found") + endif() +endif () \ No newline at end of file diff --git a/include/dpp/snowflake.h b/include/dpp/snowflake.h index 1142d00459..e55d8b3f2b 100644 --- a/include/dpp/snowflake.h +++ b/include/dpp/snowflake.h @@ -26,19 +26,11 @@ #include #include -#if __cplusplus >= 202002L -//fix for https://github.com/llvm/llvm-project/issues/77773 and -// apple support on clang 14 https://developer.apple.com/xcode/cpp/ -#if (defined(__cpp_lib_format) || \ - (defined(__clang__) && __clang_major__ >= 14 && !defined(__APPLE__) && __has_include())) || ( defined(__GNUC__) && __GNUC__ >= 13) - -#define DPP_HAS_FORMAT - +#ifdef DPP_HAS_FORMAT #include - -#endif #endif + /** * @brief The main namespace for D++ functions. classes and types */