diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ee76d5..efa6ad8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,11 @@ # ChangeLog -## v0.2.1 - 2025-04-29 +## v0.2.1 - 2025-05-30 ### Enhancements: * feat(memory): add C++ global memory allocation +* feat(repo): support compile on PC ## v0.2.0 - 2025-02-07 diff --git a/CMakeLists.txt b/CMakeLists.txt index e415ab7..86ee7c4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,10 +2,16 @@ set(SRC_DIR ./src) file(GLOB_RECURSE SRCS_C ${SRC_DIR}/*.c) file(GLOB_RECURSE SRCS_CPP ${SRC_DIR}/*.cpp) -idf_component_register( - SRCS ${SRCS_C} ${SRCS_CPP} - INCLUDE_DIRS ${SRC_DIR} -) +if(ESP_PLATFORM) + idf_component_register( + SRCS ${SRCS_C} ${SRCS_CPP} + INCLUDE_DIRS ${SRC_DIR} + ) +else() + set(COMPONENT_LIB esp-lib-utils) + add_library(${COMPONENT_LIB} STATIC ${SRCS_C} ${SRCS_CPP}) + target_include_directories(${COMPONENT_LIB} PUBLIC ${SRC_DIR}) +endif() target_compile_options(${COMPONENT_LIB} PUBLIC @@ -13,3 +19,7 @@ target_compile_options(${COMPONENT_LIB} PRIVATE $<$:-std=gnu++20> ) + +if(NOT ESP_PLATFORM) + target_compile_definitions(${COMPONENT_LIB} PUBLIC ESP_UTILS_KCONFIG_IGNORE) +endif() diff --git a/src/check/esp_utils_check.h b/src/check/esp_utils_check.h index 86f9325..4580b93 100644 --- a/src/check/esp_utils_check.h +++ b/src/check/esp_utils_check.h @@ -3,7 +3,9 @@ * * SPDX-License-Identifier: Apache-2.0 */ +#if defined(ESP_PLATFORM) #include "esp_err.h" +#endif #include "esp_utils_conf_internal.h" #include "log/esp_utils_log.h" @@ -91,6 +93,7 @@ } \ } while(0) +#if defined(ESP_PLATFORM) /** * @brief Check if the value is not `ESP_OK`; if not, return the specified value. * @@ -132,6 +135,7 @@ return; \ } \ } while(0) +#endif // ESP_PLATFORM /** * The `try {} catch {}` block is only available in C++ and `CONFIG_COMPILER_CXX_EXCEPTIONS = 1` @@ -281,6 +285,7 @@ } \ } while(0) +#if defined(ESP_PLATFORM) /** * @brief Check if the value is not `ESP_OK`; if not, log an error and return the specified value. * @@ -327,6 +332,7 @@ return; \ } \ } while(0) +#endif // ESP_PLATFORM /** * The `try {} catch {}` block is only available in C++ and `CONFIG_COMPILER_CXX_EXCEPTIONS = 1` @@ -408,6 +414,7 @@ } while (0) #define ESP_UTILS_CHECK_FALSE_EXIT(x, ...) assert(x) +#if defined(ESP_PLATFORM) #define ESP_UTILS_CHECK_ERROR_RETURN(x, ...) assert((x) == ESP_OK) #define ESP_UTILS_CHECK_ERROR_GOTO(x, goto_tag, ...) do { \ assert((x) == ESP_OK); \ @@ -417,6 +424,7 @@ } \ } while (0) #define ESP_UTILS_CHECK_ERROR_EXIT(x, ...) assert((x) == ESP_OK) +#endif // ESP_PLATFORM /** * The `try {} catch {}` block is only available in C++ and `CONFIG_COMPILER_CXX_EXCEPTIONS = 1` diff --git a/src/esp_utils_types.h b/src/esp_utils_types.h index 4eb5aca..1ebbf84 100644 --- a/src/esp_utils_types.h +++ b/src/esp_utils_types.h @@ -6,8 +6,6 @@ #pragma once -#include "sdkconfig.h" - /** * @brief Macros for check handle method */ diff --git a/src/memory/allocation/esp_utils_mem_esp.h b/src/memory/allocation/esp_utils_mem_esp.h index b1634c0..adc8041 100644 --- a/src/memory/allocation/esp_utils_mem_esp.h +++ b/src/memory/allocation/esp_utils_mem_esp.h @@ -5,6 +5,8 @@ */ #pragma once +#if defined(ESP_PLATFORM) + #include "esp_heap_caps.h" #if ESP_UTILS_MEM_ALLOC_ESP_CAPS == ESP_UTILS_MEM_ALLOC_ESP_CAPS_DEFAULT @@ -23,3 +25,5 @@ #define MALLOC(x) heap_caps_aligned_alloc(ESP_UTILS_MEM_ALLOC_ESP_ALIGN, x, MEM_CAPS) #define FREE(x) heap_caps_free(x) + +#endif // ESP_PLATFORM diff --git a/src/memory/esp_utils_mem.c b/src/memory/esp_utils_mem.c index 6d76272..0f0735b 100644 --- a/src/memory/esp_utils_mem.c +++ b/src/memory/esp_utils_mem.c @@ -3,6 +3,8 @@ * * SPDX-License-Identifier: Apache-2.0 */ +#if defined(ESP_PLATFORM) + #include "esp_heap_caps.h" #include "check/esp_utils_check.h" #include "log/esp_utils_log.h" @@ -32,3 +34,5 @@ bool esp_utils_mem_print_info(void) return true; } + +#endif // ESP_PLATFORM diff --git a/src/memory/esp_utils_mem.h b/src/memory/esp_utils_mem.h index c4a4295..e5ea74f 100644 --- a/src/memory/esp_utils_mem.h +++ b/src/memory/esp_utils_mem.h @@ -7,7 +7,6 @@ #include #include -#include "sdkconfig.h" #include "esp_utils_mem_general.h" #include "esp_utils_mem_cxx_global.h" #ifdef __cplusplus @@ -16,6 +15,8 @@ extern "C" { #endif +#if defined(ESP_PLATFORM) + /** * @brief Print memory information to the console * @@ -27,6 +28,8 @@ extern "C" { */ bool esp_utils_mem_print_info(void); +#endif // ESP_PLATFORM + #ifdef __cplusplus } #endif diff --git a/src/memory/esp_utils_mem_cxx_general.hpp b/src/memory/esp_utils_mem_cxx_general.hpp index 2852bff..6b89485 100644 --- a/src/memory/esp_utils_mem_cxx_general.hpp +++ b/src/memory/esp_utils_mem_cxx_general.hpp @@ -9,7 +9,7 @@ #include #include #include -#include "sdkconfig.h" +#include "esp_utils_conf_internal.h" #include "esp_utils_mem_general.h" namespace esp_utils { @@ -34,7 +34,7 @@ struct GeneralMemoryAllocator { return nullptr; } void *ptr = esp_utils_mem_gen_malloc(n * sizeof(T)); -#if CONFIG_COMPILER_CXX_EXCEPTIONS +#if !defined(ESP_PLATFORM) || CONFIG_COMPILER_CXX_EXCEPTIONS if (ptr == nullptr) { throw std::bad_alloc(); } diff --git a/src/memory/esp_utils_mem_cxx_global.cpp b/src/memory/esp_utils_mem_cxx_global.cpp index b17c8cf..72dadf1 100644 --- a/src/memory/esp_utils_mem_cxx_global.cpp +++ b/src/memory/esp_utils_mem_cxx_global.cpp @@ -31,7 +31,7 @@ void *operator new (std::size_t size) } ptr = MALLOC(size); -#if CONFIG_COMPILER_CXX_EXCEPTIONS +#if !defined(ESP_PLATFORM) || CONFIG_COMPILER_CXX_EXCEPTIONS if (!ptr) { throw std::bad_alloc(); } @@ -51,7 +51,7 @@ void *operator new[](std::size_t size) } ptr = MALLOC(size); -#if CONFIG_COMPILER_CXX_EXCEPTIONS +#if !defined(ESP_PLATFORM) || CONFIG_COMPILER_CXX_EXCEPTIONS if (!ptr) { throw std::bad_alloc(); } diff --git a/src/memory/esp_utils_mem_cxx_global.h b/src/memory/esp_utils_mem_cxx_global.h index 971c5e1..aa96952 100644 --- a/src/memory/esp_utils_mem_cxx_global.h +++ b/src/memory/esp_utils_mem_cxx_global.h @@ -5,6 +5,7 @@ */ #pragma once +#include #include "esp_utils_conf_internal.h" #if ESP_UTILS_CONF_MEM_ENABLE_CXX_GLOB_ALLOC