Skip to content
Snippets Groups Projects
Select Git revision
  • 5859bde00b2c91617bfabc2d9cfa9108d751d39e
  • main default protected
  • f-sss4grpc
  • dev
  • 108-implement-rpc-call-for-server-side-scripting
  • f-windows-conan-create
  • f-to-string
  • f-update-requirements
  • f-related-projects
  • f-role
  • f-remote-path
  • f-rel-path
  • f-consol-message
  • v0.3.0
  • v0.2.2
  • v0.2.1
  • v0.2.0
  • v0.1.2
  • v0.1.1
  • v0.1
  • v0.0.19
  • v0.0.18
  • v0.0.16
  • v0.0.15
  • v0.0.10
  • v0.0.9
  • v0.0.8
  • v0.0.7
  • v0.0.6
  • v0.0.5
  • v0.0.4
  • v0.0.3
  • v0.0.2
33 results

CMakeLists.txt

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    CMakeLists.txt 4.79 KiB
    #
    # This file is a part of the CaosDB Project.
    #
    # Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com>
    # Copyright (C) 2021 IndiScale GmbH <info@indiscale.com>
    #
    # This program is free software: you can redistribute it and/or modify
    # it under the terms of the GNU Affero General Public License as
    # published by the Free Software Foundation, either version 3 of the
    # License, 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 Affero General Public License for more details.
    #
    # You should have received a copy of the GNU Affero General Public License
    # along with this program. If not, see <https://www.gnu.org/licenses/>.
    #
    
    # append all the test cases here (file name without the ".cpp" suffix)
    set(test_cases
        test_data_type
        test_configuration
        test_connection
        test_entity
        test_file_transmission
        test_info
        test_issues
        test_list_properties
        test_protobuf
        test_transaction
        test_utility
        test_value
        test_ccaosdb
        )
    
    ###################################################
    ### Set up tests using GoogleTest (GTest)
    ###################################################
    
    # special linting for tests
    set(_CMAKE_CXX_CLANG_TIDY_TEST_CHECKS
      "${_CMAKE_CXX_CLANG_TIDY_CHECKS},-cert-err58-cpp,-cppcoreguidelines-avoid-non-const-global-variables,-cppcoreguidelines-owning-memory,-modernize-use-trailing-return-type,-google-readability-avoid-underscore-in-googletest-name,-cppcoreguidelines-avoid-magic-numbers,-readability-magic-numbers,-cppcoreguidelines-avoid-goto,-hicpp-avoid-goto,-readability-function-cognitive-complexity,-cppcoreguidelines-non-private-member-variables-in-classes,-misc-non-private-member-variables-in-classes,-clang-analyzer-cplusplus.Move"
    )
    
    # add special cmake functions for gtest
    include(GoogleTest)
    
    
    # loop over all test cases and add them to the test runner
    list(LENGTH test_cases len_test_cases)
    math(EXPR len_test_cases "${len_test_cases} - 1")
    foreach (i RANGE "${len_test_cases}")
        list(GET test_cases ${i} test_case_name)
        add_executable(${test_case_name} ${test_case_name}.cpp)
        set(libcaosdb_TEST_SRC "${CMAKE_CURRENT_SOURCE_DIR}/${test_case_name}.cpp
            ${libcaosdb_TEST_SRC}")
        target_link_libraries(${test_case_name}
            PRIVATE ${LIBCAOSDB} ccaosdb ${CONAN_LIBS_GTEST} ${CONAN_LIBS_BOOST})
        target_include_directories(${test_case_name}
          PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
        if(_LINTING)
            message(STATUS "linting for tests: ${_CMAKE_CXX_INCLUDE_WHAT_YOU_USE}")
            set_target_properties(${test_case_name}
                PROPERTIES
                CXX_CLANG_TIDY "${_CMAKE_CXX_CLANG_TIDY};${_CMAKE_CXX_CLANG_TIDY_TEST_CHECKS}"
                CXX_INCLUDE_WHAT_YOU_USE "${_CMAKE_CXX_INCLUDE_WHAT_YOU_USE}")
        endif()
        gtest_discover_tests(${test_case_name}
            WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
            PROPERTIES
                LABELS "caosdb-cpplib-unit-tests"
            )
    endforeach ()
    
    # copy test data to build dir
    set(TEST_DATA_DIR "${CMAKE_CURRENT_SOURCE_DIR}/test_data")
    configure_file(${CMAKE_CURRENT_SOURCE_DIR}/caosdb_test_utility.h.in
      ${CMAKE_CURRENT_BINARY_DIR}/caosdb_test_utility.h)
    
    
    
    
    ###################################################
    ### Set up test coverage repor (Gcov + Lcov)
    ###################################################
    
    include(CodeCoverage)
    
    if (LCOV_PATH)
        message(STATUS "Found LCOV: ${LCOV_PATH}")
        target_link_libraries(caosdb gcov)
        target_link_libraries(ccaosdb gcov)
        setup_target_for_coverage_lcov(
            NAME unit_test_coverage
            EXECUTABLE ctest -L caosdb-cpplib-unit-tests
            EXCLUDE "${CMAKE_BINARY_DIR}/*"
            DEPENDENCIES caosdb ccaosdb ${test_cases}
            LCOV_ARGS --rc lcov_branch_coverage=1 --no-external
            GENHTML_ARGS --rc lcov_branch_coverage=1
            )
        message(STATUS "Adding COMPILE_FLAGS for coverage: ${COVERAGE_COMPILER_FLAGS}")
        set(TARGET_CAOSDB_COMPILE_FLAGS "${TARGET_CAOSDB_COMPILE_FLAGS} ${COVERAGE_COMPILER_FLAGS}")
        set(TARGET_CCAOSDB_COMPILE_FLAGS "${TARGET_CCAOSDB_COMPILE_FLAGS} ${COVERAGE_COMPILER_FLAGS}")
        set(TARGET_CAOSDB_COMPILE_FLAGS ${TARGET_CAOSDB_COMPILE_FLAGS} PARENT_SCOPE)
        set(TARGET_CCAOSDB_COMPILE_FLAGS ${TARGET_CCAOSDB_COMPILE_FLAGS} PARENT_SCOPE)
        set_target_properties(caosdb PROPERTIES
            COMPILE_FLAGS "${TARGET_CAOSDB_COMPILE_FLAGS}")
        set_target_properties(ccaosdb PROPERTIES
            COMPILE_FLAGS "${TARGET_CCAOSDB_COMPILE_FLAGS}")
    else ()
        if (NOT SKIP_CODE_COVERAGE)
            message(WARNING "Could not generate code coverage report. Please install lcov.")
            add_custom_target(unit_test_coverage ctest -L caosdb-cpplib-unit-tests
                DEPENDS caosdb ccaosdb ${test_cases}
            )
        endif()
    endif ()