From 1e2b1238c6a03c941e81a422b7cebe5f3dd795fd Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Fri, 10 Sep 2021 18:56:25 +0200 Subject: [PATCH] cbor: add a workaround for -ffreestanding being passed to clang Toolchain CMake files for clang currently pass -ffreestanding option to prevent clang from picking the wrong copy of stdint.h. This is a temporary hack until we fix clang distributions to not include the GCC version of stdint.h. This hack, however, results in setting __STDC_HOSTED__=0, which is being checked by cbor header files, making some required functions unavailable as a result. Undefine __STDC_HOSTED__ as a workaround. This flag is only passed when compiling cbor itself. --- components/cbor/CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/components/cbor/CMakeLists.txt b/components/cbor/CMakeLists.txt index 7f12fbe9c9..f213c22733 100644 --- a/components/cbor/CMakeLists.txt +++ b/components/cbor/CMakeLists.txt @@ -13,3 +13,8 @@ idf_component_register(SRCS "tinycbor/src/cborencoder_close_container_checked.c" # for open_memstream.c set_source_files_properties(tinycbor/src/open_memstream.c PROPERTIES COMPILE_DEFINITIONS "__linux__") + +# workaround for the fact that we are passing -ffreestanding to Clang +if(CMAKE_C_COMPILER_ID MATCHES "Clang") + target_compile_options(${COMPONENT_LIB} PRIVATE "-U __STDC_HOSTED__") +endif()