diff --git a/tools/cmake/component.cmake b/tools/cmake/component.cmake index 1046364aca12..d7a7158cca31 100644 --- a/tools/cmake/component.cmake +++ b/tools/cmake/component.cmake @@ -531,10 +531,11 @@ endfunction() # to be passed here, too. # @param[in, optional] MOCK_HEADER_FILES (multivalue) list of header files from which the mocks shall be generated. # @param[in, optional] REQUIRES (multivalue) any other components required by the mock component. +# @param[in, optional] MOCK_SUBDIR (singlevalue) tells cmake where are the CMock generated c files. # function(idf_component_mock) set(options) - set(single_value) + set(single_value MOCK_SUBDIR) set(multi_value MOCK_HEADER_FILES INCLUDE_DIRS REQUIRES) cmake_parse_arguments(_ "${options}" "${single_value}" "${multi_value}" ${ARGN}) @@ -550,8 +551,14 @@ function(idf_component_mock) foreach(header_file ${__MOCK_HEADER_FILES}) get_filename_component(file_without_dir ${header_file} NAME_WE) - list(APPEND MOCK_GENERATED_HEADERS "${MOCK_GEN_DIR}/mocks/Mock${file_without_dir}.h") - list(APPEND MOCK_GENERATED_SRCS "${MOCK_GEN_DIR}/mocks/Mock${file_without_dir}.c") + if("${__MOCK_SUBDIR}" STREQUAL "") + list(APPEND MOCK_GENERATED_HEADERS "${MOCK_GEN_DIR}/mocks/Mock${file_without_dir}.h") + list(APPEND MOCK_GENERATED_SRCS "${MOCK_GEN_DIR}/mocks/Mock${file_without_dir}.c") + else() + list(APPEND MOCK_GENERATED_HEADERS "${MOCK_GEN_DIR}/mocks/${__MOCK_SUBDIR}/Mock${file_without_dir}.h") + list(APPEND MOCK_GENERATED_SRCS "${MOCK_GEN_DIR}/mocks/${__MOCK_SUBDIR}/Mock${file_without_dir}.c") + endif() + endforeach() file(MAKE_DIRECTORY "${MOCK_GEN_DIR}/mocks")