Skip to content

Commit 35f80e8

Browse files
committed
add lcov.cmake, modify data/CMakeLists.txt for faster lcov builds
1 parent 2236a5b commit 35f80e8

3 files changed

Lines changed: 71 additions & 4 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ IF(SCL_ENABLE_COVERAGE)
129129
SET(CMAKE_C_FLAGS_DEBUG "-O0 -g -fprofile-arcs -ftest-coverage" CACHE STRING "Extra compile flags required by code coverage" FORCE)
130130
SET(CMAKE_MODULE_LINKER_FLAGS_DEBUG "-fprofile-arcs -ftest-coverage" CACHE STRING "Extra linker flags required by code coverage" FORCE)
131131
SET(SCL_BUILD_TYPE "Debug" CACHE STRING "Build type required by testing framework" FORCE)
132+
SET( SCL_PYTHON_GENERATOR OFF ) #won't build with static libs
132133
ENDIF(SCL_ENABLE_COVERAGE)
133134

134135
#---------------------------------------------------------------------

data/CMakeLists.txt

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# To build one or more schemas, configure with
1+
# To build one or more schemas, configure with
22
# 'cmake -DSCL_BUILD_SCHEMAS="path/to/schema.exp;path/to/schema2.exp"
33

4-
# This function runs fedex on one express file. The generated source goes in a dir
5-
# in the build dir, and it is compiled into a library. A p21read executable is
4+
# This function runs fedex on one express file. The generated source goes in a dir
5+
# in the build dir, and it is compiled into a library. A p21read executable is
66
# compiled and linked to the lib. p21read is used to test the lib.
77
FUNCTION(BUILD_A_SCHEMA SCHEMA_FILE)
88
if( EXISTS "${CMAKE_BINARY_DIR}/${SCHEMA_FILE}" ) #try absolute path. if that fails, must already be absolute.
@@ -27,7 +27,7 @@ FUNCTION(BUILD_A_SCHEMA SCHEMA_FILE)
2727
string(TOUPPER ${SCHEMA_N} SCHEMA_LONG_NAME) #fedex_plus always uses upper case for file names
2828
get_filename_component( SCHEMA_SN ${SCHEMA_FILE} NAME )
2929
string( REGEX REPLACE "\(.*\).[Ee][Xx][Pp]" "\\1" SCHEMA_SHORT_NAME ${SCHEMA_SN} )
30-
30+
3131
project( sdai_${SCHEMA_SHORT_NAME} )
3232
message( STATUS "Generating code for ${SCHEMA_SHORT_NAME}.")
3333
set( SCHEMA_OUTPUT_DIR ${CMAKE_BINARY_DIR}/${SCHEMA_SHORT_NAME} )
@@ -54,12 +54,24 @@ FUNCTION(BUILD_A_SCHEMA SCHEMA_FILE)
5454
WORKING_DIRECTORY ${SCHEMA_OUTPUT_DIR}
5555
COMMENT "Running fedex_plus for ${SCHEMA_SHORT_NAME}..."
5656
VERBATIM )
57+
58+
if( SCL_ENABLE_COVERAGE AND NOT SC_COVER_SCHEMAS )
59+
# Coverage will always be sparse on schema libs. Compiling the libs with the -fprofile-arcs and
60+
# -ftest-coverage is extremely slow. We can avoid that by temporarily changing build type to release.
61+
set( PREV_BUILD_TYPE ${CMAKE_BUILD_TYPE} )
62+
set( CMAKE_BUILD_TYPE "Release" )
63+
endif( SCL_ENABLE_COVERAGE AND NOT SC_COVER_SCHEMAS )
64+
5765
# if testing is enabled, "TESTABLE" sets property EXCLUDE_FROM_ALL and prevents installation
5866
SCL_ADDLIB( ${PROJECT_NAME} "${FEDEX_OUT}" "stepdai stepcore express stepeditor steputils base" "TESTABLE" )
5967
add_dependencies( ${PROJECT_NAME} generate_cpp_${SCHEMA_SHORT_NAME} )
6068
set_target_properties( ${PROJECT_NAME} PROPERTIES COMPILE_FLAGS
6169
${${PROJECT_NAME}_COMPILE_FLAGS} )
6270

71+
if( SCL_ENABLE_COVERAGE AND NOT SC_COVER_SCHEMAS )
72+
set( CMAKE_BUILD_TYPE ${PREV_BUILD_TYPE} )
73+
endif( SCL_ENABLE_COVERAGE AND NOT SC_COVER_SCHEMAS )
74+
6375
add_test( NAME generate_cpp_${SCHEMA_SHORT_NAME}
6476
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
6577
COMMAND ${CMAKE_COMMAND} --build .
@@ -93,6 +105,8 @@ FUNCTION(BUILD_A_SCHEMA SCHEMA_FILE)
93105

94106
ENDFUNCTION(BUILD_A_SCHEMA)
95107

108+
#----------------------------------------------------------------------------------------------------
109+
96110
if( DEFINED SCL_BUILD_SCHEMAS )
97111
if( SCL_BUILD_SCHEMAS STREQUAL "ALL" )
98112
file( GLOB_RECURSE SCL_BUILD_SCHEMAS ${SCL_SOURCE_DIR}/data/*.exp )

lcov.cmake

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# lcov.cmake
2+
# `ctest -S lcov.cmake`
3+
4+
if( NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Linux" )
5+
message( FATAL_ERROR "LCOV is Linux-only" )
6+
endif( NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Linux" )
7+
8+
set( CTEST_SOURCE_DIRECTORY . )
9+
set( CTEST_BINARY_DIRECTORY build_lcov )
10+
set( CTEST_CMAKE_GENERATOR "Unix Makefiles" )
11+
set( CTEST_MEMORYCHECK_COMMAND /usr/bin/valgrind )
12+
set( CTEST_INITIAL_CACHE "
13+
SITE:STRING=${CTEST_SITE}
14+
BUILDNAME:STRING=${CTEST_BUILD_NAME}
15+
SCL_ENABLE_TESTING:BOOL=ON
16+
SCL_ENABLE_COVERAGE:BOOL=ON
17+
SCL_BUILD_SCHEMAS:STRING=ALL
18+
SCL_BUILD_TYPE:STRING=Debug
19+
")
20+
21+
set( LCOV_OUT "${CTEST_BINARY_DIRECTORY}/lcov_html" )
22+
23+
ctest_start(lcov)
24+
ctest_empty_binary_directory(${CTEST_BINARY_DIRECTORY})
25+
message("configuring...")
26+
ctest_configure( BUILD "${CTEST_BINARY_DIRECTORY}" OPTIONS "-DSCL_BUILD_SCHEMAS=ALL;-DSCL_ENABLE_COVERAGE=ON;-SCL_PYTHON_GENERATOR=OFF" )
27+
message("lcov: resetting counters...")
28+
execute_process( COMMAND lcov -z -d .
29+
WORKING_DIRECTORY ${CTEST_BINARY_DIRECTORY} OUTPUT_QUIET )
30+
31+
message("building...")
32+
ctest_build( BUILD "${CTEST_BINARY_DIRECTORY}" )
33+
34+
message("running tests...")
35+
ctest_test( BUILD "${CTEST_BINARY_DIRECTORY}" PARALLEL_LEVEL 1 )
36+
37+
message( "analyzing profiling data using lcov..." )
38+
execute_process( COMMAND lcov -c -d . -o stepcode.lcov
39+
WORKING_DIRECTORY ${CTEST_BINARY_DIRECTORY} OUTPUT_QUIET )
40+
message("removing system headers...")
41+
execute_process( COMMAND lcov -r stepcode.lcov "/usr/include/*" -o stepcode_no_usr.lcov
42+
WORKING_DIRECTORY ${CTEST_BINARY_DIRECTORY} OUTPUT_QUIET )
43+
execute_process( COMMAND ${CMAKE_COMMAND} -E make_directory ${LCOV_OUT} )
44+
45+
message( "creating html files..." )
46+
execute_process( COMMAND genhtml ../stepcode_no_usr.lcov
47+
WORKING_DIRECTORY ${LCOV_OUT} OUTPUT_QUIET )
48+
49+
message( "html files are located in ${LCOV_OUT}" )
50+
execute_process( COMMAND ${CMAKE_COMMAND} -E tar czf ${LCOV_OUT}.tgz ${LCOV_OUT} WORKING_DIRECTORY ${CTEST_SOURCE_DIRECTORY} )
51+
52+
message( "tarball at ${LCOV_OUT}.tgz" )

0 commit comments

Comments
 (0)