@@ -6,6 +6,13 @@ if (${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME})
6
6
set (LPP_BUILD_TESTS 1 )
7
7
endif ()
8
8
9
+ if (ENABLE_COVERAGE )
10
+ set (LPP_TEST_CXX_FLAGS ${CMAKE_CXX_FLAGS} -g -O0 -fprofile-arcs -ftest-coverage )
11
+ message (STATUS "Coverage enabled" )
12
+ else ()
13
+ set (LPP_TEST_CXX_FLAGS ${CMAKE_CXX_FLAGS} -fcompare-debug-second )
14
+ endif ()
15
+
9
16
# Set standard of top level project or C++17
10
17
if (NOT DEFINED CMAKE_CXX_STANDARD )
11
18
set (CMAKE_CXX_STANDARD 17 )
@@ -85,9 +92,9 @@ if (GLOG_FOUND AND catkin_FOUND AND LPP_BUILD_TESTS)
85
92
test /glog/test_glog_vlog.cc )
86
93
87
94
target_include_directories (${GLOG_TESTS} PRIVATE ${LPP_INCLUDE_DIRECTORIES} test /glog )
88
- target_link_libraries (${GLOG_TESTS} glog gtest ${catkin_LIBRARIES} )
95
+ target_link_libraries (${GLOG_TESTS} glog gtest ${catkin_LIBRARIES} gcov )
89
96
target_compile_definitions (${GLOG_TESTS} PRIVATE MODE_GLOG )
90
- target_compile_options (${GLOG_TESTS} PRIVATE "-fcompare-debug-second" )
97
+ target_compile_options (${GLOG_TESTS} PRIVATE ${LPP_TEST_CXX_FLAGS} )
91
98
92
99
##### Log++ Tests #####
93
100
set (LPP_TESTS "test_lpp" )
@@ -101,9 +108,9 @@ if (GLOG_FOUND AND catkin_FOUND AND LPP_BUILD_TESTS)
101
108
test /lpp/test_lpp_vlog.cc )
102
109
103
110
target_include_directories (${LPP_TESTS} PRIVATE ${LPP_INCLUDE_DIRECTORIES} test /lpp )
104
- target_link_libraries (${LPP_TESTS} glog gtest ${catkin_LIBRARIES} )
111
+ target_link_libraries (${LPP_TESTS} glog gtest ${catkin_LIBRARIES} gcov )
105
112
target_compile_definitions (${LPP_TESTS} PRIVATE MODE_LPP )
106
- target_compile_options (${LPP_TESTS} PRIVATE "-fcompare-debug-second" )
113
+ target_compile_options (${LPP_TESTS} PRIVATE ${LPP_TEST_CXX_FLAGS} )
107
114
108
115
##### Log++ Custom Output Tests #####
109
116
set (LPP_TESTS_CUSTOM "test_lpp_custom" )
@@ -118,9 +125,9 @@ if (GLOG_FOUND AND catkin_FOUND AND LPP_BUILD_TESTS)
118
125
test /lpp/custom/test_lpp_custom_vlog.cc )
119
126
120
127
target_include_directories (${LPP_TESTS_CUSTOM} PRIVATE ${LPP_INCLUDE_DIRECTORIES} test /lpp )
121
- target_link_libraries (${LPP_TESTS_CUSTOM} glog gtest ${catkin_LIBRARIES} )
128
+ target_link_libraries (${LPP_TESTS_CUSTOM} glog gtest ${catkin_LIBRARIES} gcov )
122
129
target_compile_definitions (${LPP_TESTS_CUSTOM} PRIVATE MODE_LPP )
123
- target_compile_options (${LPP_TESTS_CUSTOM} PRIVATE "-fcompare-debug-second" )
130
+ target_compile_options (${LPP_TESTS_CUSTOM} PRIVATE ${LPP_TEST_CXX_FLAGS} )
124
131
125
132
##### Roslog Tests #####
126
133
set (ROSLOG_TESTS "test_roslog" )
@@ -134,9 +141,9 @@ if (GLOG_FOUND AND catkin_FOUND AND LPP_BUILD_TESTS)
134
141
test /roslog/test_roslog_vlog.cc )
135
142
136
143
target_include_directories (${ROSLOG_TESTS} PRIVATE ${LPP_INCLUDE_DIRECTORIES} test /roslog )
137
- target_link_libraries (${ROSLOG_TESTS} glog gtest ${catkin_LIBRARIES} )
144
+ target_link_libraries (${ROSLOG_TESTS} glog gtest ${catkin_LIBRARIES} gcov )
138
145
target_compile_definitions (${ROSLOG_TESTS} PRIVATE MODE_ROSLOG )
139
- target_compile_options (${ROSLOG_TESTS} PRIVATE "-fcompare-debug-second" )
146
+ target_compile_options (${ROSLOG_TESTS} PRIVATE ${LPP_TEST_CXX_FLAGS} )
140
147
141
148
##### Default Tests #####
142
149
set (DEFAULT_TESTS "test_default" )
@@ -153,9 +160,9 @@ if (GLOG_FOUND AND catkin_FOUND AND LPP_BUILD_TESTS)
153
160
test /default/test_severity_conversions.cc )
154
161
155
162
target_include_directories (${DEFAULT_TESTS} PRIVATE ${LPP_INCLUDE_DIRECTORIES} test /default )
156
- target_link_libraries (${DEFAULT_TESTS} glog gtest ${catkin_LIBRARIES} )
163
+ target_link_libraries (${DEFAULT_TESTS} glog gtest ${catkin_LIBRARIES} gcov )
157
164
target_compile_definitions (${DEFAULT_TESTS} PRIVATE MODE_DEFAULT )
158
- target_compile_options (${DEFAULT_TESTS} PRIVATE "-fcompare-debug-second" )
165
+ target_compile_options (${DEFAULT_TESTS} PRIVATE ${LPP_TEST_CXX_FLAGS} )
159
166
160
167
##### Nolog Tests #####
161
168
set (NOLOG_TESTS "test_nolog" )
@@ -171,7 +178,13 @@ if (GLOG_FOUND AND catkin_FOUND AND LPP_BUILD_TESTS)
171
178
)
172
179
173
180
target_include_directories (${NOLOG_TESTS} PRIVATE ${LPP_INCLUDE_DIRECTORIES} test /nolog )
174
- target_link_libraries (${NOLOG_TESTS} glog gtest ${catkin_LIBRARIES} )
181
+ target_link_libraries (${NOLOG_TESTS} glog gtest ${catkin_LIBRARIES} gcov )
175
182
target_compile_definitions (${NOLOG_TESTS} PRIVATE MODE_NOLOG )
176
- target_compile_options (${NOLOG_TESTS} PRIVATE "-fcompare-debug-second" )
183
+ target_compile_options (${NOLOG_TESTS} PRIVATE ${LPP_TEST_CXX_FLAGS} )
184
+
185
+ add_custom_target (coverage
186
+ COMMAND mkdir coverage && cd coverage && gcovr -r ${CMAKE_SOURCE_DIR} --html --html-details -o coverage.html
187
+ COMMENT "Generating coverage report"
188
+ WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
189
+ )
177
190
endif ()
0 commit comments