Become a leader in the IoT community!
New DevHeads get a 320-point leaderboard boost when joining the DevHeads IoT Integration Community. In addition to learning and advising, active community leaders are rewarded with community recognition and free tech stuff. Start your Legendary Collaboration now!
Using Google Test for C-Code and mocking C-Modules
@undefined2001 can this be done with Cmake?
@lamboing you can use ordering
And it should be `target_include_directories` rather than `target_link_directories`
So it will be
“`cmake
target_include_directories(TARGET “main_dir_path”)
target_include_directories(TARGET “secondary_dir_path”)
“`
@undefined2001 Sorry for the confusion but I am already using “target_include_directories()”. And yes I think so too that the ordering should be sufficient. Seems like I have another Problem I havnt identified yet.
what is the problem
can you please show me the error?
Its on the notebook from work and also confidential so I cant really show the real code sorry. But I will get back to you if I will set up a similar environment on my private machine. Hope to get some time for it this weekend.
or don’t need the error message can you please tell what is the error about?
You first show cmake the path to the header files of the mocked modules and then to production includes. And that order should also be the order in which the header files are searched for. But somehow I cant get this to work. It seems like the build system ignores the mocked modules and only wants to use the “real” ones.
Do you all have some hints about what could be going wrong? Am I missing something? Is there an other/better way to achieve this?
if i consider this as your problem then i can show you this
“`cmake
option(PRODUCTION “Mock Build” OFF)
if(NOT PRODUCTION)
target_include_directories(TARGET “path/to/mock/include”)
else()
target_include_directories(TARGET “path/to/production/include”)
endif()
“`
then build with `cmake -DPRODUCTION=ON/OFF “build dir path”`
@lamboing Hope this helps
Thanks for the answer! The problem with this solution would be that I want to mix mocked modules and real modules. Only use mocks where hardware dependencies are present. Otherwise Im finde with using the real modules.
Also I dont want to change production code so i cant wrap the local #inlude inside the modul under tests C-File with:
“`
#if defined(PRODUCTION)
#include “module.c”
#else
#include “mocked_module.c”
#endif
“`
CONTRIBUTE TO THIS THREAD