Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cmake): support CMock subdir option with idf_component_mock (IDFGH-14547) #15308

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions tools/cmake/component.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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})

Expand All @@ -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")
Expand Down