mirror of
https://github.com/espressif/esp-idf.git
synced 2026-06-04 20:26:38 +03:00
For the Linux target, we currently attempt to fallback to older C/CXX lagnuage standards in the __build_set_lang_version() function. The language standard support is checked using CMake's language-specific functions, such as check_c_compiler_flag(). These functions require the language to be enabled[1] in CMake beforehand, which is done by calling project() or by enabling the languages later with enable_language(). At present, we use enable_language() to enable C and CXX languages in CMake, allowing us to set the standard early, before invoking project(). However, newer CMake versions (>3.29) issue a warning[2] if enable_language() is called before project(), as noted in CMP0165[3]. It should generally be acceptable to call __build_set_lang_version() after __project(), but doing so would alter the behavior of the COMPILE_OPTIONS also for non-Linux targets. Currently, users can add to COMPILE_OPTIONS even before calling project() in the project's CMakeLists.txt and the options will be in the desired order. In other words, appending to COMPILE_OPTIONS can occur either before or after calling project() in the project's CMakeLists.txt, with the outcome remaining consistent. This means the user's settings will appear later and take priority. However, if __build_set_lang_version() is called after __project(), the user's COMPILE_OPTIONS settings would be overridden if set before calling project(). Our documentation[4] explicitly states that COMPILE_OPTIONS and similar properties should be modified using idf_build_set_property() after calling project() to prevent default values from overwriting them. Even with this guidance, some existing components that modify COMPILE_OPTIONS before invoking project() might be impacted by this change. Therefore, separate the language standard settings for non-Linux and Linux targets. For non-Linux targets, these settings are applied in __build_set_default_build_specifications(), maintaining the current behavior. For the Linux target, the language standard is set with __linux_build_set_lang_version() after calling __project(), ensuring the languages are already enabled in CMake and no warning is issued. Since the Linux target is still in preview, this approach should be acceptable, especially with the existing documentation[4]. Closes https://github.com/espressif/esp-idf/issues/15488 [1] https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html#languages [2] https://gitlab.kitware.com/cmake/cmake/-/merge_requests/9396 [3] https://cmake.org/cmake/help/latest/policy/CMP0165.html#policy:CMP0165 [4] https://docs.espressif.com/projects/esp-idf/en/v5.4/esp32/api-guides/ build-system.html#overriding-default-build-specifications Signed-off-by: Frantisek Hrbata <frantisek.hrbata@espressif.com>