mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
Merge branch 'contrib/github_pr_11025' into 'master'
Enable support for C++23 in esp-idf (GitHub PR) Closes IDFGH-9684 See merge request espressif/esp-idf!23144
This commit is contained in:
commit
d82eb6942c
@ -32,7 +32,7 @@ extern "C" {
|
|||||||
* - MACRO_ARGS(__VA_ARGS__) if __VA_ARGS__ was not empty
|
* - MACRO_ARGS(__VA_ARGS__) if __VA_ARGS__ was not empty
|
||||||
* - MACRO_NO_ARGS() if __VA_ARGS__ was empty
|
* - MACRO_NO_ARGS() if __VA_ARGS__ was empty
|
||||||
*
|
*
|
||||||
* @note In the future, we want to switch to C++20. We also want to become compatible with clang. Hence, we provide two
|
* @note In the future, we want to become compatible with clang. Hence, we provide two
|
||||||
* versions of the following macros which are using variadic arguments. One is using the GNU extension ##__VA_ARGS__.
|
* versions of the following macros which are using variadic arguments. One is using the GNU extension ##__VA_ARGS__.
|
||||||
* The other is using the C++20 feature __VA_OPT__(,). This allows users to compile their code with standard C++20
|
* The other is using the C++20 feature __VA_OPT__(,). This allows users to compile their code with standard C++20
|
||||||
* enabled instead of the GNU extension. Below C++20, we haven't found any good alternative to using ##__VA_ARGS__.
|
* enabled instead of the GNU extension. Below C++20, we haven't found any good alternative to using ##__VA_ARGS__.
|
||||||
|
@ -288,7 +288,7 @@ void esp_log_writev(esp_log_level_t level, const char* tag, const char* format,
|
|||||||
/// Log at ``ESP_LOG_ERROR`` level. @see ``printf``,``ESP_LOGE``,``ESP_DRAM_LOGE``
|
/// Log at ``ESP_LOG_ERROR`` level. @see ``printf``,``ESP_LOGE``,``ESP_DRAM_LOGE``
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* In the future, we want to switch to C++20. We also want to become compatible with clang.
|
* In the future, we want to become compatible with clang.
|
||||||
* Hence, we provide two versions of the following macros which are using variadic arguments.
|
* Hence, we provide two versions of the following macros which are using variadic arguments.
|
||||||
* The first one is using the GNU extension \#\#__VA_ARGS__. The second one is using the C++20 feature __VA_OPT__(,).
|
* The first one is using the GNU extension \#\#__VA_ARGS__. The second one is using the C++20 feature __VA_OPT__(,).
|
||||||
* This allows users to compile their code with standard C++20 enabled instead of the GNU extension.
|
* This allows users to compile their code with standard C++20 enabled instead of the GNU extension.
|
||||||
|
@ -23,14 +23,14 @@ esp-idf-cxx Component
|
|||||||
C++ language standard
|
C++ language standard
|
||||||
---------------------
|
---------------------
|
||||||
|
|
||||||
By default, ESP-IDF compiles C++ code with C++20 language standard with GNU extensions (``-std=gnu++20``).
|
By default, ESP-IDF compiles C++ code with C++23 language standard with GNU extensions (``-std=gnu++23``).
|
||||||
|
|
||||||
To compile the source code of a certain component using a different language standard, set the desired compiler flag in the component CMakeLists.txt file:
|
To compile the source code of a certain component using a different language standard, set the desired compiler flag in the component CMakeLists.txt file:
|
||||||
|
|
||||||
.. code-block:: cmake
|
.. code-block:: cmake
|
||||||
|
|
||||||
idf_component_register( ... )
|
idf_component_register( ... )
|
||||||
target_compile_options(${COMPONENT_LIB} PRIVATE -std=gnu++2b)
|
target_compile_options(${COMPONENT_LIB} PRIVATE -std=gnu++11)
|
||||||
|
|
||||||
Use ``PUBLIC`` instead of ``PRIVATE`` if the public header files of the component also need to be compiled with the same language standard.
|
Use ``PUBLIC`` instead of ``PRIVATE`` if the public header files of the component also need to be compiled with the same language standard.
|
||||||
|
|
||||||
|
@ -129,7 +129,12 @@ function(__build_set_lang_version)
|
|||||||
# Use latest supported versions.
|
# Use latest supported versions.
|
||||||
# Please update docs/en/api-guides/cplusplus.rst when changing this.
|
# Please update docs/en/api-guides/cplusplus.rst when changing this.
|
||||||
set(c_std gnu17)
|
set(c_std gnu17)
|
||||||
set(cxx_std gnu++20)
|
if(NOT ${env_idf_toolchain} STREQUAL "clang")
|
||||||
|
set(cxx_std gnu++23)
|
||||||
|
else()
|
||||||
|
# TODO: IDF-7241 - remove the exception for clang
|
||||||
|
set(cxx_std gnu++20)
|
||||||
|
endif()
|
||||||
else()
|
else()
|
||||||
enable_language(C CXX)
|
enable_language(C CXX)
|
||||||
# Building for Linux target, fall back to an older version of the standard
|
# Building for Linux target, fall back to an older version of the standard
|
||||||
@ -149,7 +154,7 @@ function(__build_set_lang_version)
|
|||||||
"${preferred_c_versions}. Please upgrade the host compiler.")
|
"${preferred_c_versions}. Please upgrade the host compiler.")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(preferred_cxx_versions gnu++20 gnu++2a gnu++17 gnu++14)
|
set(preferred_cxx_versions gnu++23 gnu++20 gnu++2a gnu++17 gnu++14)
|
||||||
set(ver_found FALSE)
|
set(ver_found FALSE)
|
||||||
foreach(cxx_version ${preferred_cxx_versions})
|
foreach(cxx_version ${preferred_cxx_versions})
|
||||||
check_cxx_compiler_flag("-std=${cxx_version}" ver_${cxx_version}_supported)
|
check_cxx_compiler_flag("-std=${cxx_version}" ver_${cxx_version}_supported)
|
||||||
|
Loading…
Reference in New Issue
Block a user