-
Notifications
You must be signed in to change notification settings - Fork 7.3k
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
Enable support for C++23 in esp-idf (IDFGH-9684) #11025
Conversation
I tried putting the following statements in my CMakeLists.txt:
But esp-idf keeps appending a This has to be changed in idf itself. |
@0xFEEDC0DE64 Thanks for the suggestion! We are considering this PR but we first need to run tests on it and make sure that it won't affect anyone else. |
Can we make it a sdkconfig instead so you dont have to do testing? With defaults set to cpp20 |
@0xFEEDC0DE64 To set a custom value of C++ standard for your component (without having to change the default value used for other components) you can use idf_component_register(
SRCS main.cpp
)
set_property(TARGET ${COMPONENT_LIB} PROPERTY CXX_STANDARD 23) Then the component library will be compiled with an additional I've tried to compile the following example main.cpp file with the above CMakeLists.txt and it worked as expected: #include <expected>
using std::expected;
extern "C" void app_main(void)
{
} (Not saying that we won't update the default C++ language standard to C++23; just giving you a suggestion how to solve this problem without having to patch IDF or having to wait for us to do this update.) |
sha=a96f5bd5b098feb0e3ac39180bd8b19183f80907 |
@igrr we just rebased to the latest esp-idf again, and the compiler is called again with -std=gnu++23 and -std=gnu++20. which results in compiler errors. We are setting the c++ version with
in the topmost CMakeLists.txt and I added your set_property() to each component in our firmware project
But still I have to patch build.cmake in esp-idf to finally make it work. What has been merged here? |
Maybe COMPONENT_LIB has to be replaced with COMPONENT_TARGET ? |
I think build.cmake has been updated in a96f5bd already. Could you please verify you have this commit in your fork? |
Yes we have that commit, but for some reason the if branch for clang was needed to patch to get it to compile again. I dont understand why this happens. |
@0xFEEDC0DE64 Sorry for this. We tried to fix an incompatibility with our version of clang, but the code was faulty. We'll take a look ASAP. |
@0xFEEDC0DE64 Meanwhile, could you try the following in your component's CMakeLists.txt?
When I use this, the standard is set twice
I can then compile C++23 code (which fails compiling without setting the option in the component's CMakeLists.txt). |
std::expected, std::to_underlying, modules and concepts were missing in the esp-idf and this change enables all of them.