I made my project, which I created with STM32 cubeIDE, compilable with Cmake, but I had problems with googletest integration.
The file structure of the entire project is as follows;
I created the project and test folders as two different cmake projects. I don't have any problems compiling the project, but I could not establish a healthy connection between the test and the project. Because when compiling the test I get an error.
When I add the source and header files related to the Project to the CmakeList.txt in the test, I get an error in the project's variables and type definitions.
The cmake commands I used in the test file directory are as follows;
$cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_TOOLCHAIN_FILE=<path_to_Project/cmake/gcc-arm-none-eabi.cmake> -S<path_to_Test> -B<path_to_Test/build/Debug> -G Ninja
$cmake --build <path_to_Test/build/Debug> -j 8
Errors;
Do you have any advice to integrate googletest into existing cmake project?
Unless you plan to run the unit tests on the target device (MCU), you cannot and should not include any microcontroller-specific code, such as HAL.
Here are the some approaches for unit testing embedded projects:
Not every piece of code is meant to be unit tested, do some more research to get a better idea of different test types.
Update
So the goal is to run the tests on the target. In that case, I would recommend choosing a different testing framework, as gtest is probably too big to fit on a MCU, even if you could somehow compile it.
I know someone who used cmocka for this purpose. The flow would be something like this:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.