From a1f1536a20b698772adbae8d22aeacf5dc571854 Mon Sep 17 00:00:00 2001 From: Luca Weiss Date: Sun, 30 Dec 2018 18:39:42 +0100 Subject: [PATCH] CMake cleanup --- CMakeLists.txt | 2 +- cmake/EnableCoverageReport.cmake | 153 ------------------------------- cmake/FindGtest.cmake | 53 ----------- cmake/FindLcov.cmake | 29 ------ cmake/Findgcovr.cmake | 31 ------- cmake/ParseArguments.cmake | 52 ----------- tests/CMakeLists.txt | 2 +- 7 files changed, 2 insertions(+), 320 deletions(-) delete mode 100644 cmake/EnableCoverageReport.cmake delete mode 100644 cmake/FindGtest.cmake delete mode 100644 cmake/FindLcov.cmake delete mode 100644 cmake/Findgcovr.cmake delete mode 100644 cmake/ParseArguments.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 0c7394e..728b40a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,6 @@ project(properties-cpp) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake) -include(cmake/EnableCoverageReport.cmake) include(cmake/PrePush.cmake) include(GNUInstallDirs) @@ -42,4 +41,5 @@ add_subdirectory(data) add_subdirectory(include) add_subdirectory(tests) +# find_package(CoverageReport) # enable_coverage_report(posix_process_test linux_process_test) diff --git a/cmake/EnableCoverageReport.cmake b/cmake/EnableCoverageReport.cmake deleted file mode 100644 index b109ad4..0000000 --- a/cmake/EnableCoverageReport.cmake +++ /dev/null @@ -1,153 +0,0 @@ -# - Creates a special coverage build type and target on GCC. -# -# Defines a function ENABLE_COVERAGE_REPORT which generates the coverage target -# for selected targets. Optional arguments to this function are used to filter -# unwanted results using globbing expressions. Moreover targets with tests for -# the source code can be specified to trigger regenerating the report if the -# test has changed -# -# ENABLE_COVERAGE_REPORT(TARGETS target... [FILTER filter...] [TESTS test targets...]) -# -# To generate a coverage report first build the project with -# CMAKE_BUILD_TYPE=coverage, then call make test and afterwards make coverage. -# -# The coverage report is based on gcov. Depending on the availability of lcov -# a HTML report will be generated and/or an XML report of gcovr is found. -# The generated coverage target executes all found solutions. Special targets -# exist to create e.g. only the xml report: coverage-xml. -# -# Copyright (C) 2010 by Johannes Wienke -# -# This program is free software; you can redistribute it -# and/or modify it under the terms of the GNU General -# Public License as published by the Free Software Foundation; -# either version 2, or (at your option) -# any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# - -INCLUDE(ParseArguments) - -FIND_PACKAGE(Lcov) -FIND_PACKAGE(gcovr) - -FUNCTION(ENABLE_COVERAGE_REPORT) - - # argument parsing - PARSE_ARGUMENTS(ARG "FILTER;TARGETS;TESTS" "" ${ARGN}) - - SET(COVERAGE_RAW_FILE "${CMAKE_BINARY_DIR}/coverage.raw.info") - SET(COVERAGE_FILTERED_FILE "${CMAKE_BINARY_DIR}/coverage.info") - SET(COVERAGE_REPORT_DIR "${CMAKE_BINARY_DIR}/coveragereport") - SET(COVERAGE_XML_FILE "${CMAKE_BINARY_DIR}/coverage.xml") - SET(COVERAGE_XML_COMMAND_FILE "${CMAKE_BINARY_DIR}/coverage-xml.cmake") - - # decide if there is any tool to create coverage data - SET(TOOL_FOUND FALSE) - IF(LCOV_FOUND OR GCOVR_FOUND) - SET(TOOL_FOUND TRUE) - ENDIF() - IF(NOT TOOL_FOUND) - MESSAGE(STATUS "Cannot enable coverage targets because neither lcov nor gcovr are found.") - ENDIF() - - STRING(TOLOWER "${CMAKE_BUILD_TYPE}" COVERAGE_BUILD_TYPE) - IF(CMAKE_COMPILER_IS_GNUCXX AND TOOL_FOUND AND "${COVERAGE_BUILD_TYPE}" MATCHES "coverage") - - MESSAGE(STATUS "Coverage support enabled for targets: ${ARG_TARGETS}") - - # create coverage build type - SET(CMAKE_CXX_FLAGS_COVERAGE ${CMAKE_CXX_FLAGS_DEBUG} PARENT_SCOPE) - SET(CMAKE_C_FLAGS_COVERAGE ${CMAKE_C_FLAGS_DEBUG} PARENT_SCOPE) - SET(CMAKE_CONFIGURATION_TYPES ${CMAKE_CONFIGURATION_TYPES} coverage PARENT_SCOPE) - - # instrument targets - SET_TARGET_PROPERTIES(${ARG_TARGETS} PROPERTIES COMPILE_FLAGS --coverage - LINK_FLAGS --coverage) - - # html report - IF (LCOV_FOUND) - - MESSAGE(STATUS "Enabling HTML coverage report") - - # set up coverage target - - ADD_CUSTOM_COMMAND(OUTPUT ${COVERAGE_RAW_FILE} - COMMAND ${LCOV_EXECUTABLE} -c -d ${CMAKE_BINARY_DIR} -o ${COVERAGE_RAW_FILE} - WORKING_DIRECTORY ${CMAKE_BINARY_DIR} - COMMENT "Collecting coverage data" - DEPENDS ${ARG_TARGETS} ${ARG_TESTS} - VERBATIM) - - # filter unwanted stuff - LIST(LENGTH ARG_FILTER FILTER_LENGTH) - IF(${FILTER_LENGTH} GREATER 0) - SET(FILTER COMMAND ${LCOV_EXECUTABLE}) - FOREACH(F ${ARG_FILTER}) - SET(FILTER ${FILTER} -r ${COVERAGE_FILTERED_FILE} ${F}) - ENDFOREACH() - SET(FILTER ${FILTER} -o ${COVERAGE_FILTERED_FILE}) - ELSE() - SET(FILTER "") - ENDIF() - - ADD_CUSTOM_COMMAND(OUTPUT ${COVERAGE_FILTERED_FILE} - COMMAND ${LCOV_EXECUTABLE} -e ${COVERAGE_RAW_FILE} "${CMAKE_SOURCE_DIR}*" -o ${COVERAGE_FILTERED_FILE} - ${FILTER} - DEPENDS ${COVERAGE_RAW_FILE} - COMMENT "Filtering recorded coverage data for project-relevant entries" - VERBATIM) - ADD_CUSTOM_COMMAND(OUTPUT ${COVERAGE_REPORT_DIR} - COMMAND ${CMAKE_COMMAND} -E make_directory ${COVERAGE_REPORT_DIR} - COMMAND ${GENHTML_EXECUTABLE} --legend --show-details -t "${PROJECT_NAME} test coverage" -o ${COVERAGE_REPORT_DIR} ${COVERAGE_FILTERED_FILE} - DEPENDS ${COVERAGE_FILTERED_FILE} - COMMENT "Generating HTML coverage report in ${COVERAGE_REPORT_DIR}" - VERBATIM) - - ADD_CUSTOM_TARGET(coverage-html - DEPENDS ${COVERAGE_REPORT_DIR}) - - ENDIF() - - # xml coverage report - IF(GCOVR_FOUND) - - MESSAGE(STATUS "Enabling XML coverage report") - - # gcovr cannot write directly to a file so the execution needs to - # be wrapped in a cmake file that generates the file output - FILE(WRITE ${COVERAGE_XML_COMMAND_FILE} - "SET(ENV{LANG} en)\n") - FILE(APPEND ${COVERAGE_XML_COMMAND_FILE} - "EXECUTE_PROCESS(COMMAND \"${GCOVR_EXECUTABLE}\" --exclude=tests.* --exclude=obj-.* --exclude=cmake.* -x -r \"${CMAKE_SOURCE_DIR}\" OUTPUT_FILE \"${COVERAGE_XML_FILE}\" WORKING_DIRECTORY \"${CMAKE_BINARY_DIR}\")\n") - - ADD_CUSTOM_COMMAND(OUTPUT ${COVERAGE_XML_FILE} - COMMAND ${CMAKE_COMMAND} ARGS -P ${COVERAGE_XML_COMMAND_FILE} - COMMENT "Generating coverage XML report" - VERBATIM) - - ADD_CUSTOM_TARGET(coverage-xml - DEPENDS ${COVERAGE_XML_FILE}) - - ENDIF() - - # provide a global coverage target executing both steps if available - SET(GLOBAL_DEPENDS "") - IF(LCOV_FOUND) - LIST(APPEND GLOBAL_DEPENDS ${COVERAGE_REPORT_DIR}) - ENDIF() - IF(GCOVR_FOUND) - LIST(APPEND GLOBAL_DEPENDS ${COVERAGE_XML_FILE}) - ENDIF() - IF(LCOV_FOUND OR GCOVR_FOUND) - ADD_CUSTOM_TARGET(coverage - DEPENDS ${GLOBAL_DEPENDS}) - ENDIF() - - ENDIF() - -ENDFUNCTION() diff --git a/cmake/FindGtest.cmake b/cmake/FindGtest.cmake deleted file mode 100644 index 1283174..0000000 --- a/cmake/FindGtest.cmake +++ /dev/null @@ -1,53 +0,0 @@ -include(ExternalProject) -include(FindPackageHandleStandardArgs) - -#gtest -set(GTEST_INSTALL_DIR /usr/src/gmock/gtest/include) -find_path(GTEST_INCLUDE_DIR gtest/gtest.h - HINTS ${GTEST_INSTALL_DIR}) - -#gmock -find_path(GMOCK_INSTALL_DIR gmock/CMakeLists.txt - HINTS /usr/src) -if(${GMOCK_INSTALL_DIR} STREQUAL "GMOCK_INSTALL_DIR-NOTFOUND") - message(FATAL_ERROR "google-mock package not found") -endif() - -set(GMOCK_INSTALL_DIR ${GMOCK_INSTALL_DIR}/gmock) -find_path(GMOCK_INCLUDE_DIR gmock/gmock.h) - -set(GMOCK_PREFIX gmock) -set(GMOCK_BINARY_DIR ${CMAKE_BINARY_DIR}/${GMOCK_PREFIX}/libs) -set(GTEST_BINARY_DIR ${GMOCK_BINARY_DIR}/gtest) - -set(GTEST_CMAKE_ARGS "") -if (${MIR_IS_CROSS_COMPILING}) - set(GTEST_CMAKE_ARGS - -DCMAKE_TOOLCHAIN_FILE=${CMAKE_MODULE_PATH}/LinuxCrossCompile.cmake) -endif() - -ExternalProject_Add( - GMock - #where to build in source tree - PREFIX ${GMOCK_PREFIX} - #where the source is external to the project - SOURCE_DIR ${GMOCK_INSTALL_DIR} - #forward the compilers to the subproject so cross-arch builds work - CMAKE_ARGS ${GTEST_CMAKE_ARGS} - BINARY_DIR ${GMOCK_BINARY_DIR} - - #we don't need to install, so skip - INSTALL_COMMAND "" -) - -set(GMOCK_LIBRARY ${GMOCK_BINARY_DIR}/libgmock.a) -set(GMOCK_MAIN_LIBRARY ${GMOCK_BINARY_DIR}/libgmock_main.a) -set(GMOCK_BOTH_LIBRARIES ${GMOCK_LIBRARY} ${GMOCK_MAIN_LIBRARY}) -set(GTEST_LIBRARY ${GTEST_BINARY_DIR}/libgtest.a) -set(GTEST_MAIN_LIBRARY ${GTEST_BINARY_DIR}/libgtest_main.a) -set(GTEST_BOTH_LIBRARIES ${GTEST_LIBRARY} ${GTEST_MAIN_LIBRARY}) -set(GTEST_ALL_LIBRARIES ${GTEST_BOTH_LIBRARIES} ${GMOCK_BOTH_LIBRARIES}) - -find_package_handle_standard_args(GTest DEFAULT_MSG - GMOCK_INCLUDE_DIR - GTEST_INCLUDE_DIR) diff --git a/cmake/FindLcov.cmake b/cmake/FindLcov.cmake deleted file mode 100644 index 70628f4..0000000 --- a/cmake/FindLcov.cmake +++ /dev/null @@ -1,29 +0,0 @@ -# - Find lcov -# Will define: -# -# LCOV_EXECUTABLE - the lcov binary -# GENHTML_EXECUTABLE - the genhtml executable -# -# Copyright (C) 2010 by Johannes Wienke -# -# This program is free software; you can redistribute it -# and/or modify it under the terms of the GNU General -# Public License as published by the Free Software Foundation; -# either version 2, or (at your option) -# any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# - -INCLUDE(FindPackageHandleStandardArgs) - -FIND_PROGRAM(LCOV_EXECUTABLE lcov) -FIND_PROGRAM(GENHTML_EXECUTABLE genhtml) - -FIND_PACKAGE_HANDLE_STANDARD_ARGS(Lcov DEFAULT_MSG LCOV_EXECUTABLE GENHTML_EXECUTABLE) - -# only visible in advanced view -MARK_AS_ADVANCED(LCOV_EXECUTABLE GENHTML_EXECUTABLE) diff --git a/cmake/Findgcovr.cmake b/cmake/Findgcovr.cmake deleted file mode 100644 index e4c43fe..0000000 --- a/cmake/Findgcovr.cmake +++ /dev/null @@ -1,31 +0,0 @@ -# - Find gcovr scrip -# Will define: -# -# GCOVR_EXECUTABLE - the gcovr script -# -# Uses: -# -# GCOVR_ROOT - root to search for the script -# -# Copyright (C) 2011 by Johannes Wienke -# -# This program is free software; you can redistribute it -# and/or modify it under the terms of the GNU General -# Public License as published by the Free Software Foundation; -# either version 2, or (at your option) -# any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# - -INCLUDE(FindPackageHandleStandardArgs) - -FIND_PROGRAM(GCOVR_EXECUTABLE gcovr HINTS ${GCOVR_ROOT} "${GCOVR_ROOT}/bin") - -FIND_PACKAGE_HANDLE_STANDARD_ARGS(gcovr DEFAULT_MSG GCOVR_EXECUTABLE) - -# only visible in advanced view -MARK_AS_ADVANCED(GCOVR_EXECUTABLE) diff --git a/cmake/ParseArguments.cmake b/cmake/ParseArguments.cmake deleted file mode 100644 index e13f671..0000000 --- a/cmake/ParseArguments.cmake +++ /dev/null @@ -1,52 +0,0 @@ -# Parse arguments passed to a function into several lists separated by -# upper-case identifiers and options that do not have an associated list e.g.: -# -# SET(arguments -# hello OPTION3 world -# LIST3 foo bar -# OPTION2 -# LIST1 fuz baz -# ) -# PARSE_ARGUMENTS(ARG "LIST1;LIST2;LIST3" "OPTION1;OPTION2;OPTION3" ${arguments}) -# -# results in 7 distinct variables: -# * ARG_DEFAULT_ARGS: hello;world -# * ARG_LIST1: fuz;baz -# * ARG_LIST2: -# * ARG_LIST3: foo;bar -# * ARG_OPTION1: FALSE -# * ARG_OPTION2: TRUE -# * ARG_OPTION3: TRUE -# -# taken from http://www.cmake.org/Wiki/CMakeMacroParseArguments - -MACRO(PARSE_ARGUMENTS prefix arg_names option_names) - SET(DEFAULT_ARGS) - FOREACH(arg_name ${arg_names}) - SET(${prefix}_${arg_name}) - ENDFOREACH(arg_name) - FOREACH(option ${option_names}) - SET(${prefix}_${option} FALSE) - ENDFOREACH(option) - - SET(current_arg_name DEFAULT_ARGS) - SET(current_arg_list) - FOREACH(arg ${ARGN}) - SET(larg_names ${arg_names}) - LIST(FIND larg_names "${arg}" is_arg_name) - IF (is_arg_name GREATER -1) - SET(${prefix}_${current_arg_name} ${current_arg_list}) - SET(current_arg_name ${arg}) - SET(current_arg_list) - ELSE (is_arg_name GREATER -1) - SET(loption_names ${option_names}) - LIST(FIND loption_names "${arg}" is_option) - IF (is_option GREATER -1) - SET(${prefix}_${arg} TRUE) - ELSE (is_option GREATER -1) - SET(current_arg_list ${current_arg_list} ${arg}) - ENDIF (is_option GREATER -1) - ENDIF (is_arg_name GREATER -1) - ENDFOREACH(arg) - SET(${prefix}_${current_arg_name} ${current_arg_list}) -ENDMACRO(PARSE_ARGUMENTS) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 180498f..cb05b48 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,7 +1,7 @@ set (OLD_CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) # Don't treat warnings as errors in 3rd_party/{gmock,cucumber-cpp} string (REPLACE " -Werror " " " CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) -find_package(Gtest REQUIRED) +find_package(GTest REQUIRED) include_directories(${GMOCK_INCLUDE_DIR} ${GTEST_INCLUDE_DIR}) set (CMAKE_CXX_FLAGS ${OLD_CMAKE_CXX_FLAGS})