# # 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 test cases here (file name without the ".cpp" suffix) ####################################################################### set(test_cases test_connection test_transaction test_ccaosdb ) include(CheckCXXCompilerFlag) include(CheckCCompilerFlag) function(add_compiler_flag flag) string(FIND "${CMAKE_CXX_FLAGS}" "${flag}" cxx_present) if(cxx_present EQUAL -1) check_cxx_compiler_flag("${flag}" flag_supported) if(flag_supported) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}" PARENT_SCOPE) endif() unset(flag_supported CACHE) endif() unset(cxx_present CACHE) endfunction() ### but ignore these add_compiler_flag("-Wno-unused-parameter") add_compiler_flag("-Wno-unused-result") add_compiler_flag("-g") ####################################################### ### Linting with clang-tidy and include-what-you-use ####################################################### option(LINTING "clang-tidy and iwye" ON) if(LINTING) ### set paranoid compiler flags #add_compiler_flag("-Wall") #add_compiler_flag("-Wextra") #add_compiler_flag("-pedantic") #add_compiler_flag("-Werror") find_program(iwyu NAMES include-what-you-use iwyu PATHS ${CMAKE_SOURCE_DIR}/tools/include-what-you-use/${iwyu_os}/bin) if(NOT iwyu) message(WARNING "include-what-you-use: Not found") else() message(STATUS "include-what-you-use: ${iwyu}") set(_CMAKE_CXX_INCLUDE_WHAT_YOU_USE ${iwyu} "-Xiwyu" "--no_fwd_decls" "-Xiwyu" "--cxx17ns") endif() find_program(clang_tidy NAMES clang-tidy clang-tidy-11) if(NOT clang_tidy) message(WARNING "clang-tidy: Not found") else() message(STATUS "clang-tidy: ${clang_tidy}") set(_CMAKE_CXX_CLANG_TIDY "${clang_tidy}" "--header-filter=caosdb/.*[^\(\.pb\.h\)]$" "--warnings-as-errors=*" "--fix") set(_CMAKE_CXX_CLANG_TIDY_CHECKS "--checks=*,-fuchsia-*,-llvmlibc-*,-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") endif() else() message(STATUS "LINTING is OFF") endif() ################################################### ### Set up tests using GoogleTest (GTest) ################################################### # add special cmake functions for gtest include(GoogleTest REQUIRED) # 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) target_link_libraries(${test_case_name} PRIVATE ${CONAN_LIBS_CAOSDB} ${CONAN_LIBS_GTEST} ${CONAN_LIBS_GRPC} ${CONAN_LIBS_ABSEIL} ${CONAN_LIBS_OPENSSL} ${CONAN_LIBS_C-ARES} ${CONAN_LIBS_BZIP2} ${CONAN_LIBS_PROTOBUF} ${CONAN_LIBS_ZLIB} ${CONAN_LIBS_RE2} ${CONAN_LIBS_BOOST}) target_include_directories(${test_case_name} PUBLIC ${CONAN_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR}) if(LINTING) set_target_properties(${test_case_name} PROPERTIES CXX_CLANG_TIDY "${_CMAKE_CXX_CLANG_TIDY};${_CMAKE_CXX_CLANG_TIDY_CHECKS}" CXX_INCLUDE_WHAT_YOU_USE "${_CMAKE_CXX_INCLUDE_WHAT_YOU_USE}") endif() gtest_discover_tests(${test_case_name} PROPERTIES LABELS "caosdb-cpplib-int-tests") endforeach ()