]> granicus.if.org Git - esp-idf/commitdiff
gcov_example: Adds cmake target to generate report
authorAlexey Gerenkov <alexey@espressif.com>
Fri, 28 Jun 2019 13:24:05 +0000 (16:24 +0300)
committerbot <bot@espressif.com>
Fri, 5 Jul 2019 12:44:35 +0000 (12:44 +0000)
Closes IDF-727

components/app_trace/project_include.cmake [new file with mode: 0644]
examples/system/gcov/CMakeLists.txt
examples/system/gcov/README.md

diff --git a/components/app_trace/project_include.cmake b/components/app_trace/project_include.cmake
new file mode 100644 (file)
index 0000000..2278788
--- /dev/null
@@ -0,0 +1,23 @@
+# idf_create_lcov_report
+#
+# Create coverage report.
+function(idf_create_coverage_report report_dir)
+    set(gcov_tool ${CONFIG_SDK_TOOLPREFIX}gcov)
+    idf_build_get_property(project_name PROJECT_NAME)
+
+    add_custom_target(lcov-report
+        COMMENT "Generating coverage report in: ${report_dir}"
+        COMMAND ${CMAKE_COMMAND} -E echo "Using gcov: ${gcov_tool}"
+        COMMAND ${CMAKE_COMMAND} -E make_directory ${report_dir}/html
+        COMMAND lcov --gcov-tool ${gcov_tool} -c -d ${CMAKE_CURRENT_BINARY_DIR} -o ${report_dir}/${project_name}.info
+        COMMAND genhtml -o ${report_dir}/html ${report_dir}/${project_name}.info)
+endfunction()
+
+# idf_clean_coverage_report
+#
+# Clean coverage report.
+function(idf_clean_coverage_report report_dir)
+    add_custom_target(cov-data-clean
+        COMMENT "Clean coverage report in: ${report_dir}"
+        COMMAND ${CMAKE_COMMAND} -E remove_directory ${report_dir})
+endfunction()
\ No newline at end of file
index 8a1f715683f63ff045e907455495be118e5d3109..e40ee66d506e0f6c0dccbe9c6feab1c4e4297ff3 100644 (file)
@@ -4,3 +4,6 @@ cmake_minimum_required(VERSION 3.5)
 
 include($ENV{IDF_PATH}/tools/cmake/project.cmake)
 project(gcov_example)
+
+idf_create_coverage_report(${CMAKE_CURRENT_BINARY_DIR}/coverage_report)
+idf_clean_coverage_report(${CMAKE_CURRENT_BINARY_DIR}/coverage_report)
index de20784184c75102d35306e381416b1f9b72b53d..ffb5fef3bd385147b6623545abd1418aa32f1242 100644 (file)
@@ -127,6 +127,14 @@ cov-data-clean:
 .PHONY: lcov-report cov-data-clean
 ```
 
+For CMake-based build system, add the following lines to you project's `CMakeLists.txt` after the line including `project.cmake`:
+
+```
+include($ENV{IDF_PATH}/tools/cmake/gcov.cmake)
+idf_create_coverage_report(${CMAKE_CURRENT_BINARY_DIR}/coverage_report)
+idf_clean_coverage_report(${CMAKE_CURRENT_BINARY_DIR}/coverage_report)
+```
+
 Those lines add two build targets:
 * `lcov-report` - generates html coverage report in `$(BUILD_DIR_BASE)/coverage_report/html` directory.
 * `cov-data-clean` - removes all coverage data files and reports.
@@ -134,6 +142,8 @@ Those lines add two build targets:
 To generate report type the following command:
 `make lcov-report`
 
+  For CMake-based build system, type `cmake --build build/ --target lcov-report`
+
 The sample output of the command is below:
 
 ```