Hello,
The MCUXpresso VSCode extension is not a pure CMake project. It is driven by CMake + NXP SDK + specific templates, but a lot of the build details are encapsulated in the CMake module provided by NXP. As a result, the project's CMakeLists.txt file is not the core file that tells everything, and may not take effect after you edit it.
If you need to add uCUnit, you can refer below steps:
1. Create a new test_runner.c including unit test
2.Using #ifdef to switch test code or normal code
// main.c
#ifdef RUN_TESTS
extern void run_tests(void);
int main(void) {
run_tests();
while (1); //
}
#else
int main(void) {
//
}
#endif
3. Add -DRUN_TESTS in cmake flag
The build configurations(debug/release) in MCUXpresso IDE - Vscode is from CMakePresets.json-->flags.cmake
If you need to add a new build configuration, create a new Presets in CMakePresets.json, using CMAKE_BUILD_TYPE="utest" to replace CMAKE_BUILD_TYPE="debug".
Then add your build preset in flags.cmake.
SET(CMAKE_C_FLAGS_UTEST " \
${CMAKE_C_FLAGS_DEBUG} \
-DDEBUG \
-DRUN_TESTS \
-DCPU_MIMX8ML8DVNLZ \
-DCPU_MIMX8ML8DVNLZ_cm7 \
-DPRINTF_FLOAT_ENABLE=0 \
-DSCANF_FLOAT_ENABLE=0 \
-DPRINTF_ADVANCED_ENABLE=0 \
-DSCANF_ADVANCED_ENABLE=0 \
-DMCUXPRESSO_SDK \
-DSERIAL_PORT_TYPE_UART=1 \
-g \
-O0 \
-mcpu=cortex-m7 \
-Wall \
-Wno-address-of-packed-member \
-mthumb \
-MMD \
-MP \
-fno-common \
-ffunction-sections \
-fdata-sections \
-fno-builtin \
-mapcs \
-std=gnu99 \
${FPU} \
${DEBUG_CONSOLE_CONFIG} \
")
4. Switch Build Configurations in MCUXpresso IDE - Vscode.
Best Regards,
Zhiming