Skip to content

Add CMake support #505

@orjangj

Description

@orjangj

Hi,

Considering that CMock already support Meson, and that Unity supports both Meson and CMake, I was curious if you're interested in adding CMake support for CMock as well? I would be happy to contribute with a PR if you're willing to accept this feature request.

My proposed outcome of this feature request is:

  1. Add CMake support to build a cmock library target (similar to how Unity CMakeLists.txt currently does it).
  2. Add CMock.cmake script that provides two functions to help CMake-based projects use the CMock framework:
    cmock_generate_mocks: Runs cmock.rb under the hood to generate the mock sources and headers
    cmock_add_library: Uses cmock_generate_mocks, but goes a step further by constructing a target library based on the mocked sources and headers. The function would also take care of linking with the cmock library.
  3. Add documentation and examples on how to use CMock with CMake.

Example: Consider the following function signature: cmock_add_library(<name> HEADERS <headers> EXTRA_INCLUDES <include dirs>)

cmock_add_library(
  example_mock
  HEADERS header1.h header2.h header3.h
  EXTRA_INCLUDES some/other/dir
)

target_link_library(example_test_runner PRIVATE example_mock)

Note, EXTRA_INCLUDES is optional, but may be necessary if the mocked headers include i.e. a third party dependency in its public interface. The example_mock target will fail to compile unless the extra include path can be resolved. The motivation behind the cmock_add_library function is ease-of-use by providing a linkable mock target that one or more test executables can link to.

Let me know if this looks interesting to you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions