mirror of
https://github.com/espressif/esp-idf.git
synced 2025-11-18 10:31:09 +00:00
refactor(linux): Unified libbsd handling
* Users can now use libbsd string.h and sys/cdefs.h functionality (e.g., strlcpy, containerof) on Linux by just including string.h or sys/cdefs.h. In other words, the includes are the same on the Linux target as well as on chips targets (ESP32, etc.). * libbsd linking is done by the linux component (belongs to common components) now instead of handling it separately in each component
This commit is contained in:
@@ -14,3 +14,12 @@ endif()
|
||||
idf_component_register(INCLUDE_DIRS ${includes}
|
||||
REQUIRED_IDF_TARGETS linux
|
||||
SRCS ${srcs})
|
||||
|
||||
if(${IDF_TARGET} STREQUAL "linux")
|
||||
find_library(LIB_BSD bsd)
|
||||
if(LIB_BSD)
|
||||
target_link_libraries(${COMPONENT_LIB} PRIVATE ${LIB_BSD})
|
||||
elseif(NOT CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
|
||||
message(WARNING "Missing LIBBSD library. Install libbsd-dev package and/or check linker directories.")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
@@ -1,10 +1,16 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
* NOTE: This file is deprecated and will be removed in the future.
|
||||
* Use include sys/cdefs.h instead, it will also include
|
||||
* the corresponding libbsd header. TODO: IDF-9391
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
15
components/linux/linux_include/string.h
Normal file
15
components/linux/linux_include/string.h
Normal file
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/*
|
||||
* This header file also includes the additional libbsd string.h with functions such as strlcpy(),
|
||||
* which are present in the ESP-IDF toolchain and on MacOS, but not on Linux.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <bsd/string.h>
|
||||
#include_next <string.h>
|
||||
22
components/linux/linux_include/sys/cdefs.h
Normal file
22
components/linux/linux_include/sys/cdefs.h
Normal file
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/*
|
||||
* This header file adds the libbsd defines of header cdefs.h.
|
||||
* It also defines __uintptr_t which is still used by older libbsd versions (< 0.11.3)
|
||||
* but not (or not guaranteed to be) defined on Linux.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
// We need a define. We can't typedef here since, depending on the include order,
|
||||
// uintptr_t may not be defined yet.
|
||||
#define __uintptr_t uintptr_t
|
||||
|
||||
#include_next <sys/cdefs.h>
|
||||
#include <bsd/sys/cdefs.h>
|
||||
Reference in New Issue
Block a user