ThrowTheSwitch / CMock

CMock - Mock/stub generator for C
http://throwtheswitch.org
MIT License
672 stars 273 forks source link

Cmake with CMock #379

Closed besessener closed 2 years ago

besessener commented 2 years ago

Hi,

is there a simple example in using CMock together with CMake? I am using CMake and integrated Unity and it's working like a charm. But I have no idea how to also include CMock, how to get dependencies it might need. Do you have any reference for it?

Matthias

mvandervoord commented 2 years ago

Matthias -- I don't believe we have an example of using CMake to build with CMock anywhere. The extra key step is that for any object dependencies that begin with Mock, you need to run the cmock scripts on the header to produce a c and h file. This is similar to the way the runner is being generated in the current cmake example.

Tuc-an commented 2 years ago

It's not necessarily a simple example, but https://github.com/booz-allen-hamilton/log4cpp_4innovator is an example of using CMock with CMake

besessener commented 2 years ago

@mvandervoord you propose to create a custom command that calls CMock scripts (ruby) like?

add_custom_command (
    OUTPUT mocks/${mock_name}.c
    COMMAND ruby
            ${CMAKE_SOURCE_DIR}/cmock/lib/cmock.rb
            -o ${CMAKE_SOURCE_DIR}/cmock-settings.yml
            ${header_abs_path}
)

Just calling this for every file under test? Or what is your proposal?

@Tuc-an I am not able to find relevant CMake code for CMock there. I can only find cmock in the make files. The call to the ruby scripts looks a bit similar at least.

besessener commented 2 years ago

got it working like written above. thanks for input.