Update build system
This commit is contained in:
parent
73a810ac18
commit
e5ca2d8578
6 changed files with 344 additions and 42 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -8,4 +8,6 @@ coverage/
|
||||||
*.test
|
*.test
|
||||||
cmake-build-debug/
|
cmake-build-debug/
|
||||||
cmake-build-release/
|
cmake-build-release/
|
||||||
|
build/
|
||||||
.idea/
|
.idea/
|
||||||
|
src/mqtt.h
|
||||||
|
|
8
.vscode/c_cpp_properties.json
vendored
8
.vscode/c_cpp_properties.json
vendored
|
@ -8,10 +8,6 @@
|
||||||
"${workspaceRoot}/tests",
|
"${workspaceRoot}/tests",
|
||||||
"/usr/include"
|
"/usr/include"
|
||||||
],
|
],
|
||||||
"defines": [
|
|
||||||
"MAX_BUFFER_SIZE=256",
|
|
||||||
"DEBUG=1"
|
|
||||||
],
|
|
||||||
"intelliSenseMode": "clang-x64",
|
"intelliSenseMode": "clang-x64",
|
||||||
"browse": {
|
"browse": {
|
||||||
"path": [
|
"path": [
|
||||||
|
@ -26,7 +22,9 @@
|
||||||
"databaseFilename": "",
|
"databaseFilename": "",
|
||||||
"compilerPath": "/usr/bin/clang",
|
"compilerPath": "/usr/bin/clang",
|
||||||
"cStandard": "c99",
|
"cStandard": "c99",
|
||||||
"cppStandard": "c++17"
|
"cppStandard": "c++17",
|
||||||
|
"configurationProvider": "vector-of-bool.cmake-tools",
|
||||||
|
"compileCommands": "${workspaceFolder}/build/compile_commands.json"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"version": 4
|
"version": 4
|
||||||
|
|
24
.vscode/settings.json
vendored
24
.vscode/settings.json
vendored
|
@ -1,19 +1,15 @@
|
||||||
{
|
{
|
||||||
"files.associations": {
|
"files.associations": {
|
||||||
"stdlib.h": "c",
|
|
||||||
"mqtt_internal.h": "c",
|
"mqtt_internal.h": "c",
|
||||||
"platform.h": "c",
|
"platform.h": "c",
|
||||||
"tidyplatform.h": "c",
|
|
||||||
"type_traits": "cpp",
|
|
||||||
"istream": "c",
|
|
||||||
"optional": "c",
|
|
||||||
"ostream": "c",
|
|
||||||
"ratio": "c",
|
|
||||||
"system_error": "c",
|
|
||||||
"array": "c",
|
|
||||||
"string_view": "c",
|
|
||||||
"packet.h": "c",
|
"packet.h": "c",
|
||||||
"debug.h": "c"
|
"buffer.h": "c",
|
||||||
|
"debug.h": "c",
|
||||||
|
"protocol.h": "c",
|
||||||
|
"state_queue.h": "c",
|
||||||
|
"subscriptions.h": "c",
|
||||||
|
"mqtt.h": "c",
|
||||||
|
"tidyplatform.h": "c"
|
||||||
},
|
},
|
||||||
"files.exclude": {
|
"files.exclude": {
|
||||||
"**/.git": true,
|
"**/.git": true,
|
||||||
|
@ -26,6 +22,8 @@
|
||||||
"**/*.gcno": true,
|
"**/*.gcno": true,
|
||||||
"**/*.gcda": true,
|
"**/*.gcda": true,
|
||||||
"**/*.gcov": true,
|
"**/*.gcov": true,
|
||||||
"**/*.a": true
|
"**/*.a": true,
|
||||||
}
|
"**/build": true
|
||||||
|
},
|
||||||
|
"coverage-gutters.lcovname": "coverage.info"
|
||||||
}
|
}
|
||||||
|
|
47
.vscode/tasks.json
vendored
47
.vscode/tasks.json
vendored
|
@ -4,37 +4,68 @@
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"tasks": [
|
"tasks": [
|
||||||
{
|
{
|
||||||
"label": "Build linux",
|
"label": "Build",
|
||||||
"type": "shell",
|
"type": "shell",
|
||||||
"command": "make",
|
"command": "make",
|
||||||
"args": [
|
"args": [
|
||||||
"-f",
|
"-j",
|
||||||
"Makefile.linux",
|
"8",
|
||||||
"clean",
|
"clean",
|
||||||
"all"
|
"all"
|
||||||
],
|
],
|
||||||
"options": {
|
"options": {
|
||||||
"cwd": "${workspaceRoot}"
|
"cwd": "${workspaceRoot}/build"
|
||||||
},
|
},
|
||||||
"group": {
|
"group": {
|
||||||
"kind": "build",
|
"kind": "build",
|
||||||
"isDefault": true
|
"isDefault": true
|
||||||
},
|
},
|
||||||
|
"problemMatcher": {
|
||||||
|
// The problem is owned by the cpp language service.
|
||||||
|
"owner": "cpp",
|
||||||
|
// The file name for reported problems is relative to the opened folder.
|
||||||
|
"fileLocation": "absolute",
|
||||||
|
// The actual pattern to match problems in the output.
|
||||||
|
"pattern": {
|
||||||
|
// The regular expression. Example to match: helloWorld.c:5:3: warning: implicit declaration of function ‘printf’ [-Wimplicit-function-declaration]
|
||||||
|
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
|
||||||
|
// The first match group matches the file name which is relative.
|
||||||
|
"file": 1,
|
||||||
|
// The second match group matches the line on which the problem occurred.
|
||||||
|
"line": 2,
|
||||||
|
// The third match group matches the column at which the problem occurred.
|
||||||
|
"column": 3,
|
||||||
|
// The fourth match group matches the problem's severity. Can be ignored. Then all problems are captured as errors.
|
||||||
|
"severity": 4,
|
||||||
|
// The fifth match group matches the message.
|
||||||
|
"message": 5
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "CMake",
|
||||||
|
"type": "shell",
|
||||||
|
"command": "cmake",
|
||||||
|
"args": [
|
||||||
|
".."
|
||||||
|
],
|
||||||
|
"options": {
|
||||||
|
"cwd": "${workspaceRoot}/build"
|
||||||
|
},
|
||||||
|
"group": "build",
|
||||||
"problemMatcher": [
|
"problemMatcher": [
|
||||||
"$gcc"
|
"$gcc"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"label": "Clean linux",
|
"label": "Clean",
|
||||||
"type": "shell",
|
"type": "shell",
|
||||||
"command": "make",
|
"command": "make",
|
||||||
"args": [
|
"args": [
|
||||||
"-f",
|
|
||||||
"Makefile.linux",
|
|
||||||
"clean"
|
"clean"
|
||||||
],
|
],
|
||||||
"options": {
|
"options": {
|
||||||
"cwd": "${workspaceRoot}"
|
"cwd": "${workspaceRoot}/build"
|
||||||
},
|
},
|
||||||
"problemMatcher": [
|
"problemMatcher": [
|
||||||
"$gcc"
|
"$gcc"
|
||||||
|
|
143
CMakeLists.txt
143
CMakeLists.txt
|
@ -1,47 +1,158 @@
|
||||||
cmake_minimum_required(VERSION 2.6)
|
cmake_minimum_required(VERSION 3.0)
|
||||||
project(LIBMQTT)
|
project(LIBMQTT LANGUAGES C)
|
||||||
|
|
||||||
|
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMakeModules)
|
||||||
|
|
||||||
|
#
|
||||||
|
# Version
|
||||||
|
#
|
||||||
set (LIBMQTT_VERSION_MAJOR 0)
|
set (LIBMQTT_VERSION_MAJOR 0)
|
||||||
set (LIBMQTT_VERSION_MINOR 1)
|
set (LIBMQTT_VERSION_MINOR 1)
|
||||||
|
|
||||||
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Wall -fprofile-arcs -ftest-coverage -O0 -pthread -DDEBUG=1")
|
configure_file (
|
||||||
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Wall -Os -pthread")
|
"${PROJECT_SOURCE_DIR}/src/mqtt.h.in"
|
||||||
|
"${PROJECT_SOURCE_DIR}/src/mqtt.h"
|
||||||
|
)
|
||||||
|
|
||||||
|
#
|
||||||
|
# Build flags
|
||||||
|
#
|
||||||
|
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Wall -Wextra -fprofile-arcs -ftest-coverage -O0 -pthread -DDEBUG=1")
|
||||||
|
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Wall -Os -pthread")
|
||||||
|
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "-lgcov")
|
||||||
|
|
||||||
|
#
|
||||||
|
# Platform abstraction
|
||||||
|
#
|
||||||
if (UNIX)
|
if (UNIX)
|
||||||
set(PLATFORM_CODE platform/linux.c)
|
set(PLATFORM_CODE
|
||||||
|
platform/linux.c
|
||||||
|
platform/platform.h
|
||||||
|
)
|
||||||
find_package(Threads REQUIRED)
|
find_package(Threads REQUIRED)
|
||||||
set(PLATFORM_LIBS ${CMAKE_THREAD_LIBS_INIT})
|
set(PLATFORM_LIBS ${CMAKE_THREAD_LIBS_INIT})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
configure_file (
|
#
|
||||||
"${PROJECT_SOURCE_DIR}/src/mqtt.h.in"
|
# Source files
|
||||||
"${PROJECT_BINARY_DIR}/mqtt.h"
|
#
|
||||||
|
set(mqtt-source
|
||||||
|
src/mqtt.c
|
||||||
|
src/mqtt_internal.h
|
||||||
|
src/packet.c
|
||||||
|
src/packet.h
|
||||||
|
src/protocol.c
|
||||||
|
src/protocol.h
|
||||||
|
src/state_queue.c
|
||||||
|
src/state_queue.h
|
||||||
|
src/subscriptions.c
|
||||||
|
src/subscriptions.h
|
||||||
|
src/debug.h
|
||||||
|
src/buffer.h
|
||||||
|
src/mqtt.h
|
||||||
|
${PLATFORM_CODE}
|
||||||
)
|
)
|
||||||
include_directories("${PROJECT_BINARY_DIR}")
|
|
||||||
include_directories("${PROJECT_SOURCE_DIR}/platform")
|
|
||||||
|
|
||||||
|
|
||||||
set(mqtt-source src/mqtt.c src/packet.c src/protocol.c src/state_queue.c src/subscriptions.c ${PLATFORM_CODE})
|
|
||||||
|
|
||||||
|
# full build library for testing
|
||||||
add_library(mqtt-full STATIC ${mqtt-source})
|
add_library(mqtt-full STATIC ${mqtt-source})
|
||||||
target_compile_definitions(mqtt-full PRIVATE MQTT_SERVER=1 MQTT_CLIENT=1)
|
target_compile_definitions(mqtt-full PRIVATE MQTT_SERVER=1 MQTT_CLIENT=1)
|
||||||
|
set_target_properties(mqtt-full PROPERTIES PUBLIC_HEADER "src/mqtt.h")
|
||||||
|
target_include_directories(mqtt-full
|
||||||
|
PUBLIC
|
||||||
|
$<INSTALL_INTERFACE:include>
|
||||||
|
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>
|
||||||
|
PRIVATE
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/platform
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/src
|
||||||
|
)
|
||||||
|
|
||||||
|
# libraries that could be deployed
|
||||||
add_library(mqtt_static STATIC ${mqtt-source})
|
add_library(mqtt_static STATIC ${mqtt-source})
|
||||||
|
set_target_properties(mqtt_static PROPERTIES PUBLIC_HEADER "src/mqtt.h")
|
||||||
|
target_include_directories(mqtt_static
|
||||||
|
PUBLIC
|
||||||
|
$<INSTALL_INTERFACE:include>
|
||||||
|
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>
|
||||||
|
PRIVATE
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/platform
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/src
|
||||||
|
)
|
||||||
|
|
||||||
add_library(mqtt SHARED ${mqtt-source})
|
add_library(mqtt SHARED ${mqtt-source})
|
||||||
|
set_target_properties(mqtt PROPERTIES
|
||||||
|
PUBLIC_HEADER "src/mqtt.h"
|
||||||
|
VERSION "${LIBMQTT_VERSION_MAJOR}.${LIBMQTT_VERSION_MINOR}"
|
||||||
|
SOVERSION ${LIBMQTT_VERSION_MAJOR}
|
||||||
|
)
|
||||||
|
target_include_directories(mqtt
|
||||||
|
PUBLIC
|
||||||
|
$<INSTALL_INTERFACE:include>
|
||||||
|
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>
|
||||||
|
PRIVATE
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/platform
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/src
|
||||||
|
)
|
||||||
|
|
||||||
|
# Test executables
|
||||||
include_directories ("${PROJECT_SOURCE_DIR}/src")
|
|
||||||
|
|
||||||
add_executable (connect_publish.test tests/connect_publish.c)
|
add_executable (connect_publish.test tests/connect_publish.c)
|
||||||
target_link_libraries (connect_publish.test mqtt-full ${PLATFORM_LIBS})
|
target_link_libraries (connect_publish.test mqtt-full ${PLATFORM_LIBS})
|
||||||
|
target_include_directories(connect_publish.test
|
||||||
|
PRIVATE
|
||||||
|
${PROJECT_BINARY_DIR}
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/src
|
||||||
|
)
|
||||||
|
add_test(NAME ConnectPublish COMMAND ${PROJECT_BINARY_DIR}/connect_publish.test)
|
||||||
|
|
||||||
add_executable (connect_subscribe.test tests/connect_subscribe.c)
|
add_executable (connect_subscribe.test tests/connect_subscribe.c)
|
||||||
target_link_libraries (connect_subscribe.test mqtt-full ${PLATFORM_LIBS})
|
target_link_libraries (connect_subscribe.test mqtt-full ${PLATFORM_LIBS})
|
||||||
|
target_include_directories(connect_subscribe.test
|
||||||
|
PRIVATE
|
||||||
|
${PROJECT_BINARY_DIR}
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/src
|
||||||
|
)
|
||||||
|
add_test(NAME ConnectSubscribe COMMAND ${PROJECT_BINARY_DIR}/connect_subscribe.test)
|
||||||
|
|
||||||
add_executable (decode_packet.test tests/decode_packet.c)
|
add_executable (decode_packet.test tests/decode_packet.c)
|
||||||
target_link_libraries (decode_packet.test mqtt-full ${PLATFORM_LIBS})
|
target_link_libraries (decode_packet.test mqtt-full ${PLATFORM_LIBS})
|
||||||
|
target_include_directories(decode_packet.test
|
||||||
|
PRIVATE
|
||||||
|
${PROJECT_BINARY_DIR}
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/src
|
||||||
|
)
|
||||||
|
add_test(NAME DecodePacket COMMAND ${PROJECT_BINARY_DIR}/decode_packet.test)
|
||||||
|
|
||||||
add_executable (encode_packet.test tests/encode_packet.c)
|
add_executable (encode_packet.test tests/encode_packet.c)
|
||||||
target_link_libraries (encode_packet.test mqtt-full ${PLATFORM_LIBS})
|
target_link_libraries (encode_packet.test mqtt-full ${PLATFORM_LIBS})
|
||||||
|
target_include_directories(encode_packet.test
|
||||||
|
PRIVATE
|
||||||
|
${PROJECT_BINARY_DIR}
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/src
|
||||||
|
)
|
||||||
|
add_test(NAME EncodePacket COMMAND ${PROJECT_BINARY_DIR}/encode_packet.test)
|
||||||
|
|
||||||
|
include(CTest)
|
||||||
|
enable_testing()
|
||||||
|
|
||||||
|
# check target, builds and runs all tests as the 'test' target is not able to build
|
||||||
|
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} DEPENDS
|
||||||
|
connect_publish.test
|
||||||
|
connect_subscribe.test
|
||||||
|
decode_packet.test
|
||||||
|
encode_packet.test
|
||||||
|
)
|
||||||
|
|
||||||
|
# code coverage target
|
||||||
|
if(CMAKE_COMPILER_IS_GNUCXX)
|
||||||
|
include(CodeCoverage)
|
||||||
|
setup_target_for_coverage(coverage check coverage)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
#
|
||||||
|
# Install
|
||||||
|
#
|
||||||
|
|
||||||
|
install(TARGETS mqtt mqtt_static
|
||||||
|
RUNTIME DESTINATION bin
|
||||||
|
PUBLIC_HEADER DESTINATION include/mqtt
|
||||||
|
LIBRARY DESTINATION lib CONFIGURATIONS Release
|
||||||
|
ARCHIVE DESTINATION lib CONFIGURATIONS Release)
|
||||||
|
|
162
CMakeModules/CodeCoverage.cmake
Normal file
162
CMakeModules/CodeCoverage.cmake
Normal file
|
@ -0,0 +1,162 @@
|
||||||
|
# Copyright (c) 2012 - 2015, Lars Bilke
|
||||||
|
# All rights reserved.
|
||||||
|
#
|
||||||
|
# Redistribution and use in source and binary forms, with or without modification,
|
||||||
|
# are permitted provided that the following conditions are met:
|
||||||
|
#
|
||||||
|
# 1. Redistributions of source code must retain the above copyright notice, this
|
||||||
|
# list of conditions and the following disclaimer.
|
||||||
|
#
|
||||||
|
# 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
# this list of conditions and the following disclaimer in the documentation
|
||||||
|
# and/or other materials provided with the distribution.
|
||||||
|
#
|
||||||
|
# 3. Neither the name of the copyright holder nor the names of its contributors
|
||||||
|
# may be used to endorse or promote products derived from this software without
|
||||||
|
# specific prior written permission.
|
||||||
|
#
|
||||||
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
|
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||||
|
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||||
|
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
#
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# 2012-01-31, Lars Bilke
|
||||||
|
# - Enable Code Coverage
|
||||||
|
#
|
||||||
|
# 2013-09-17, Joakim Söderberg
|
||||||
|
# - Added support for Clang.
|
||||||
|
# - Some additional usage instructions.
|
||||||
|
#
|
||||||
|
# USAGE:
|
||||||
|
|
||||||
|
# 0. (Mac only) If you use Xcode 5.1 make sure to patch geninfo as described here:
|
||||||
|
# http://stackoverflow.com/a/22404544/80480
|
||||||
|
#
|
||||||
|
# 1. Copy this file into your cmake modules path.
|
||||||
|
#
|
||||||
|
# 2. Add the following line to your CMakeLists.txt:
|
||||||
|
# INCLUDE(CodeCoverage)
|
||||||
|
#
|
||||||
|
# 3. Set compiler flags to turn off optimization and enable coverage:
|
||||||
|
# SET(CMAKE_CXX_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage")
|
||||||
|
# SET(CMAKE_C_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage")
|
||||||
|
#
|
||||||
|
# 3. Use the function SETUP_TARGET_FOR_COVERAGE to create a custom make target
|
||||||
|
# which runs your test executable and produces a lcov code coverage report:
|
||||||
|
# Example:
|
||||||
|
# SETUP_TARGET_FOR_COVERAGE(
|
||||||
|
# my_coverage_target # Name for custom target.
|
||||||
|
# test_driver # Name of the test driver target that runs the tests.
|
||||||
|
# coverage # Name of output directory.
|
||||||
|
# )
|
||||||
|
#
|
||||||
|
# 4. Build a Debug build:
|
||||||
|
# cmake -DCMAKE_BUILD_TYPE=Debug ..
|
||||||
|
# make
|
||||||
|
# make my_coverage_target
|
||||||
|
#
|
||||||
|
#
|
||||||
|
|
||||||
|
# Check prereqs
|
||||||
|
FIND_PROGRAM( GCOV_PATH gcov )
|
||||||
|
FIND_PROGRAM( LCOV_PATH lcov )
|
||||||
|
FIND_PROGRAM( GENHTML_PATH genhtml )
|
||||||
|
|
||||||
|
IF(NOT GCOV_PATH)
|
||||||
|
MESSAGE(FATAL_ERROR "gcov not found! Aborting...")
|
||||||
|
ENDIF() # NOT GCOV_PATH
|
||||||
|
|
||||||
|
IF("${CMAKE_CXX_COMPILER_ID}" MATCHES "(Apple)?[Cc]lang")
|
||||||
|
IF("${CMAKE_CXX_COMPILER_VERSION}" VERSION_LESS 3)
|
||||||
|
MESSAGE(FATAL_ERROR "Clang version must be 3.0.0 or greater! Aborting...")
|
||||||
|
ENDIF()
|
||||||
|
ELSEIF(NOT CMAKE_COMPILER_IS_GNUCXX)
|
||||||
|
MESSAGE(FATAL_ERROR "Compiler is not GNU gcc! Aborting...")
|
||||||
|
ENDIF() # CHECK VALID COMPILER
|
||||||
|
|
||||||
|
SET(CMAKE_CXX_FLAGS_COVERAGE
|
||||||
|
"-g -O0 --coverage -fprofile-arcs -ftest-coverage"
|
||||||
|
CACHE STRING "Flags used by the C++ compiler during coverage builds."
|
||||||
|
FORCE )
|
||||||
|
SET(CMAKE_C_FLAGS_COVERAGE
|
||||||
|
"-g -O0 --coverage -fprofile-arcs -ftest-coverage"
|
||||||
|
CACHE STRING "Flags used by the C compiler during coverage builds."
|
||||||
|
FORCE )
|
||||||
|
SET(CMAKE_EXE_LINKER_FLAGS_COVERAGE
|
||||||
|
""
|
||||||
|
CACHE STRING "Flags used for linking binaries during coverage builds."
|
||||||
|
FORCE )
|
||||||
|
SET(CMAKE_SHARED_LINKER_FLAGS_COVERAGE
|
||||||
|
""
|
||||||
|
CACHE STRING "Flags used by the shared libraries linker during coverage builds."
|
||||||
|
FORCE )
|
||||||
|
MARK_AS_ADVANCED(
|
||||||
|
CMAKE_CXX_FLAGS_COVERAGE
|
||||||
|
CMAKE_C_FLAGS_COVERAGE
|
||||||
|
CMAKE_EXE_LINKER_FLAGS_COVERAGE
|
||||||
|
CMAKE_SHARED_LINKER_FLAGS_COVERAGE )
|
||||||
|
|
||||||
|
IF ( NOT (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "Coverage"))
|
||||||
|
MESSAGE( WARNING "Code coverage results with an optimized (non-Debug) build may be misleading" )
|
||||||
|
ENDIF() # NOT CMAKE_BUILD_TYPE STREQUAL "Debug"
|
||||||
|
|
||||||
|
|
||||||
|
# Param _targetname The name of new the custom make target
|
||||||
|
# Param _testtarget The name of the target which runs the tests.
|
||||||
|
# MUST return ZERO always, even on errors.
|
||||||
|
# If not, no coverage report will be created!
|
||||||
|
# Param _outputname lcov output is generated as _outputname.info
|
||||||
|
# HTML report is generated in _outputname/index.html
|
||||||
|
FUNCTION(SETUP_TARGET_FOR_COVERAGE _targetname _testtarget _outputname)
|
||||||
|
|
||||||
|
IF(NOT LCOV_PATH)
|
||||||
|
MESSAGE(FATAL_ERROR "lcov not found! Aborting...")
|
||||||
|
ENDIF() # NOT LCOV_PATH
|
||||||
|
|
||||||
|
IF(NOT GENHTML_PATH)
|
||||||
|
MESSAGE(FATAL_ERROR "genhtml not found! Aborting...")
|
||||||
|
ENDIF() # NOT GENHTML_PATH
|
||||||
|
|
||||||
|
SET(coverage_info "${CMAKE_BINARY_DIR}/${_outputname}.info")
|
||||||
|
SET(coverage_cleaned "${coverage_info}.cleaned")
|
||||||
|
|
||||||
|
# Setup target
|
||||||
|
ADD_CUSTOM_TARGET(${_targetname}_clean
|
||||||
|
|
||||||
|
# Cleanup lcov
|
||||||
|
${LCOV_PATH} --directory . --zerocounters
|
||||||
|
|
||||||
|
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
|
||||||
|
COMMENT "Resetting code coverage counters to zero."
|
||||||
|
)
|
||||||
|
|
||||||
|
ADD_CUSTOM_TARGET(${_targetname}
|
||||||
|
|
||||||
|
# Capturing lcov counters and generating report
|
||||||
|
COMMAND ${LCOV_PATH} --directory . --capture --output-file ${coverage_info}
|
||||||
|
COMMAND ${LCOV_PATH} --remove ${coverage_info} '${PROJECT_SOURCE_DIR}/tests/*' '/usr/*' --output-file ${coverage_cleaned}
|
||||||
|
COMMAND ${GENHTML_PATH} -o ${_outputname} ${coverage_cleaned}
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E remove ${coverage_cleaned}
|
||||||
|
|
||||||
|
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
|
||||||
|
COMMENT "Processing code coverage counters and generating report."
|
||||||
|
)
|
||||||
|
|
||||||
|
add_dependencies(${_testtarget} ${_targetname}_clean)
|
||||||
|
add_dependencies(${_targetname} ${_testtarget})
|
||||||
|
|
||||||
|
# Show info where to find the report
|
||||||
|
ADD_CUSTOM_COMMAND(TARGET ${_targetname} POST_BUILD
|
||||||
|
COMMAND ;
|
||||||
|
COMMENT "Open ./${_outputname}/index.html in your browser to view the coverage report."
|
||||||
|
)
|
||||||
|
|
||||||
|
ENDFUNCTION() # SETUP_TARGET_FOR_COVERAGE
|
Loading…
Reference in a new issue