Skip to content

Commit 3d5534e

Browse files
committed
feat(repo): support compile on PC
1 parent b68e772 commit 3d5534e

10 files changed

+41
-12
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# ChangeLog
22

3-
## v0.2.1 - 2025-04-29
3+
## v0.2.1 - 2025-05-30
44

55
### Enhancements:
66

77
* feat(memory): add C++ global memory allocation
8+
* feat(repo): support compile on PC
89

910
## v0.2.0 - 2025-02-07
1011

CMakeLists.txt

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,24 @@ set(SRC_DIR ./src)
22
file(GLOB_RECURSE SRCS_C ${SRC_DIR}/*.c)
33
file(GLOB_RECURSE SRCS_CPP ${SRC_DIR}/*.cpp)
44

5-
idf_component_register(
6-
SRCS ${SRCS_C} ${SRCS_CPP}
7-
INCLUDE_DIRS ${SRC_DIR}
8-
)
5+
if(ESP_PLATFORM)
6+
idf_component_register(
7+
SRCS ${SRCS_C} ${SRCS_CPP}
8+
INCLUDE_DIRS ${SRC_DIR}
9+
)
10+
else()
11+
set(COMPONENT_LIB esp-lib-utils)
12+
add_library(${COMPONENT_LIB} STATIC ${SRCS_C} ${SRCS_CPP})
13+
target_include_directories(${COMPONENT_LIB} PUBLIC ${SRC_DIR})
14+
endif()
915

1016
target_compile_options(${COMPONENT_LIB}
1117
PUBLIC
1218
-Wno-missing-field-initializers
1319
PRIVATE
1420
$<$<COMPILE_LANGUAGE:CXX>:-std=gnu++20>
1521
)
22+
23+
if(NOT ESP_PLATFORM)
24+
target_compile_definitions(${COMPONENT_LIB} PUBLIC ESP_UTILS_KCONFIG_IGNORE)
25+
endif()

src/check/esp_utils_check.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
6+
#if defined(ESP_PLATFORM)
67
#include "esp_err.h"
8+
#endif
79
#include "esp_utils_conf_internal.h"
810
#include "log/esp_utils_log.h"
911

@@ -91,6 +93,7 @@
9193
} \
9294
} while(0)
9395

96+
#if defined(ESP_PLATFORM)
9497
/**
9598
* @brief Check if the value is not `ESP_OK`; if not, return the specified value.
9699
*
@@ -132,6 +135,7 @@
132135
return; \
133136
} \
134137
} while(0)
138+
#endif // ESP_PLATFORM
135139

136140
/**
137141
* The `try {} catch {}` block is only available in C++ and `CONFIG_COMPILER_CXX_EXCEPTIONS = 1`
@@ -281,6 +285,7 @@
281285
} \
282286
} while(0)
283287

288+
#if defined(ESP_PLATFORM)
284289
/**
285290
* @brief Check if the value is not `ESP_OK`; if not, log an error and return the specified value.
286291
*
@@ -327,6 +332,7 @@
327332
return; \
328333
} \
329334
} while(0)
335+
#endif // ESP_PLATFORM
330336

331337
/**
332338
* The `try {} catch {}` block is only available in C++ and `CONFIG_COMPILER_CXX_EXCEPTIONS = 1`
@@ -408,6 +414,7 @@
408414
} while (0)
409415
#define ESP_UTILS_CHECK_FALSE_EXIT(x, ...) assert(x)
410416

417+
#if defined(ESP_PLATFORM)
411418
#define ESP_UTILS_CHECK_ERROR_RETURN(x, ...) assert((x) == ESP_OK)
412419
#define ESP_UTILS_CHECK_ERROR_GOTO(x, goto_tag, ...) do { \
413420
assert((x) == ESP_OK); \
@@ -417,6 +424,7 @@
417424
} \
418425
} while (0)
419426
#define ESP_UTILS_CHECK_ERROR_EXIT(x, ...) assert((x) == ESP_OK)
427+
#endif // ESP_PLATFORM
420428

421429
/**
422430
* The `try {} catch {}` block is only available in C++ and `CONFIG_COMPILER_CXX_EXCEPTIONS = 1`

src/esp_utils_types.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
#pragma once
88

9-
#include "sdkconfig.h"
10-
119
/**
1210
* @brief Macros for check handle method
1311
*/

src/memory/allocation/esp_utils_mem_esp.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
#pragma once
77

8+
#if defined(ESP_PLATFORM)
9+
810
#include "esp_heap_caps.h"
911

1012
#if ESP_UTILS_MEM_ALLOC_ESP_CAPS == ESP_UTILS_MEM_ALLOC_ESP_CAPS_DEFAULT
@@ -23,3 +25,5 @@
2325

2426
#define MALLOC(x) heap_caps_aligned_alloc(ESP_UTILS_MEM_ALLOC_ESP_ALIGN, x, MEM_CAPS)
2527
#define FREE(x) heap_caps_free(x)
28+
29+
#endif // ESP_PLATFORM

src/memory/esp_utils_mem.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
6+
#if defined(ESP_PLATFORM)
7+
68
#include "esp_heap_caps.h"
79
#include "check/esp_utils_check.h"
810
#include "log/esp_utils_log.h"
@@ -32,3 +34,5 @@ bool esp_utils_mem_print_info(void)
3234

3335
return true;
3436
}
37+
38+
#endif // ESP_PLATFORM

src/memory/esp_utils_mem.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
#include <stdbool.h>
99
#include <stdlib.h>
10-
#include "sdkconfig.h"
1110
#include "esp_utils_mem_general.h"
1211
#include "esp_utils_mem_cxx_global.h"
1312
#ifdef __cplusplus
@@ -16,6 +15,8 @@
1615
extern "C" {
1716
#endif
1817

18+
#if defined(ESP_PLATFORM)
19+
1920
/**
2021
* @brief Print memory information to the console
2122
*
@@ -27,6 +28,8 @@ extern "C" {
2728
*/
2829
bool esp_utils_mem_print_info(void);
2930

31+
#endif // ESP_PLATFORM
32+
3033
#ifdef __cplusplus
3134
}
3235
#endif

src/memory/esp_utils_mem_cxx_general.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <map>
1010
#include <unordered_map>
1111
#include <vector>
12-
#include "sdkconfig.h"
12+
#include "esp_utils_conf_internal.h"
1313
#include "esp_utils_mem_general.h"
1414

1515
namespace esp_utils {
@@ -34,7 +34,7 @@ struct GeneralMemoryAllocator {
3434
return nullptr;
3535
}
3636
void *ptr = esp_utils_mem_gen_malloc(n * sizeof(T));
37-
#if CONFIG_COMPILER_CXX_EXCEPTIONS
37+
#if !defined(ESP_PLATFORM) || CONFIG_COMPILER_CXX_EXCEPTIONS
3838
if (ptr == nullptr) {
3939
throw std::bad_alloc();
4040
}

src/memory/esp_utils_mem_cxx_global.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ void *operator new (std::size_t size)
3131
}
3232

3333
ptr = MALLOC(size);
34-
#if CONFIG_COMPILER_CXX_EXCEPTIONS
34+
#if !defined(ESP_PLATFORM) || CONFIG_COMPILER_CXX_EXCEPTIONS
3535
if (!ptr) {
3636
throw std::bad_alloc();
3737
}
@@ -51,7 +51,7 @@ void *operator new[](std::size_t size)
5151
}
5252

5353
ptr = MALLOC(size);
54-
#if CONFIG_COMPILER_CXX_EXCEPTIONS
54+
#if !defined(ESP_PLATFORM) || CONFIG_COMPILER_CXX_EXCEPTIONS
5555
if (!ptr) {
5656
throw std::bad_alloc();
5757
}

src/memory/esp_utils_mem_cxx_global.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
#pragma once
77

8+
#include <stdbool.h>
89
#include "esp_utils_conf_internal.h"
910

1011
#if ESP_UTILS_CONF_MEM_ENABLE_CXX_GLOB_ALLOC

0 commit comments

Comments
 (0)