|
1 | 1 | # idf_create_coverage_report |
2 | 2 | # |
3 | 3 | # Create coverage report. |
| 4 | +# |
| 5 | +# Arguments: |
| 6 | +# report_dir - Directory where the coverage report will be generated |
| 7 | +# SOURCE_DIR - (Optional) Source directory to use as root for gcovr. |
| 8 | +# If not provided, defaults to PROJECT_DIR. |
| 9 | +# GCOV_OPTIONS - (Optional) Additional options to pass to gcovr. |
| 10 | +# |
| 11 | +# Example: |
| 12 | +# idf_create_coverage_report(${report_dir}) # Uses PROJECT_DIR |
| 13 | +# idf_create_coverage_report(${report_dir} SOURCE_DIR ${component_dir}) # Uses custom source dir |
| 14 | +# idf_create_coverage_report(${report_dir} GCOV_OPTIONS "--gcov-ignore-parse-errors=negative_hits.warn") |
| 15 | +# |
4 | 16 | function(idf_create_coverage_report report_dir) |
| 17 | + cmake_parse_arguments(ARG "" "SOURCE_DIR" "GCOV_OPTIONS" ${ARGN}) |
| 18 | + |
5 | 19 | set(gcov_tool ${_CMAKE_TOOLCHAIN_PREFIX}gcov) |
6 | | - idf_build_get_property(project_name PROJECT_NAME) |
7 | | - idf_build_get_property(project_dir PROJECT_DIR) |
| 20 | + |
| 21 | + # Use provided SOURCE_DIR or default to PROJECT_DIR |
| 22 | + if(ARG_SOURCE_DIR) |
| 23 | + set(source_root_dir "${ARG_SOURCE_DIR}") |
| 24 | + else() |
| 25 | + idf_build_get_property(source_root_dir PROJECT_DIR) |
| 26 | + endif() |
8 | 27 |
|
9 | 28 | file(TO_NATIVE_PATH "${report_dir}" _report_dir) |
10 | | - file(TO_NATIVE_PATH "${project_dir}" _project_dir) |
| 29 | + file(TO_NATIVE_PATH "${source_root_dir}" _source_root_dir) |
11 | 30 | file(TO_NATIVE_PATH "${report_dir}/html/index.html" _index_path) |
12 | 31 |
|
13 | 32 | add_custom_target(pre-cov-report |
14 | 33 | COMMENT "Generating coverage report in: ${_report_dir}" |
15 | 34 | COMMAND ${CMAKE_COMMAND} -E echo "Using gcov: ${gcov_tool}" |
| 35 | + COMMAND ${CMAKE_COMMAND} -E echo "Source root: ${_source_root_dir}" |
16 | 36 | COMMAND ${CMAKE_COMMAND} -E make_directory ${_report_dir}/html |
17 | 37 | ) |
18 | 38 |
|
19 | 39 | add_custom_target(gcovr-report |
20 | | - COMMAND gcovr -r ${_project_dir} --gcov-executable ${gcov_tool} -s --html-details ${_index_path} |
| 40 | + COMMAND gcovr -r ${_source_root_dir} --gcov-executable ${gcov_tool} ${ARG_GCOV_OPTIONS} -s --html-details ${_index_path} |
21 | 41 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} |
22 | 42 | DEPENDS pre-cov-report |
23 | 43 | ) |
|
0 commit comments