# ! ------------------------------------------------------------------ ! # ! Changing this file incorrectly can cause your program to not build ! # ! If you don't know CMake well DO NOT touch this file ! # ! ------------------------------------------------------------------ ! cmake_minimum_required(VERSION 3.20) project(OOP VERSION 0.1.0) enable_testing() set(CMAKE_CXX_STANDARD 17) #### GTest option(FETCH_GOOGLETEST "Download googletest source" ON) if(FETCH_GOOGLETEST) # reference: https://google.github.io/googletest/quickstart-cmake.html include(FetchContent) FetchContent_Declare( googletest GIT_REPOSITORY https://github.com/google/googletest.git GIT_TAG release-1.12.1 ) # For Windows: Prevent overriding the parent project's compiler/linker settings set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) FetchContent_MakeAvailable(googletest) else() message("Using custom googletest installation") # reference: https://cmake.org/cmake/help/latest/module/FindGTest.html find_package(GTest REQUIRED) endif() include(files.cmake) set(SRC_DIR ${CMAKE_SOURCE_DIR}/src) set(INCLUDE_DIR ${CMAKE_SOURCE_DIR}/include) set(TEST_DIR ${CMAKE_SOURCE_DIR}/test) list(TRANSFORM SRC_FILES PREPEND ${SRC_DIR}/) list(TRANSFORM INCLUDE_FILES PREPEND ${INCLUDE_DIR}/) list(TRANSFORM TEST_FILES PREPEND ${TEST_DIR}/) find_program(MEMORYCHECK_COMMAND valgrind) set(MEMORYCHECK_COMMAND_OPTIONS "--error-exitcode=1 --track-origins=yes --leak-check=full" ) include(CTest) option(COVERAGE "Enable coverage" OFF) if(COVERAGE) set(CMAKE_C_FLAGS "--coverage -g -O0") set(CMAKE_CXX_FLAGS "--coverage -g -O0") include(scripts/CodeCoverage.cmake) set(CODE_COVERAGE_VERBOSE ON) set(COVERAGE_EXCLUDE ${CMAKE_BINARY_DIR}/_deps/* ${PROJECT_SOURCE_DIR}/test/* ) if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") set(GCOVR_ADDITIONAL_ARGS --gcov-executable "llvm-cov gcov" ) endif() append_coverage_compiler_flags() setup_target_for_coverage_gcovr_html( NAME ut_all_coverage DEPENDENCIES ut_all EXCLUDE ${COVERAGE_EXCLUDE} ) endif() if (MSVC) add_compile_options( /W4 ) else() add_compile_options( -Wall -Wextra -Wpedantic -Werror=return-type -Werror=uninitialized -Wfatal-errors ) endif() add_executable(ut_all ${SRC_FILES} ${INCLUDE_FILES} ${TEST_FILES} ) target_link_libraries(ut_all GTest::gtest_main ) target_include_directories(ut_all PRIVATE ${INCLUDE_DIR} ) target_compile_options(ut_all PRIVATE ${TARGET_COMPILER_OPTIONS} ) add_executable(ut_snack include/Snack.hpp src/Snack.cpp test/ut_snack.cpp ) target_link_libraries(ut_snack GTest::gtest_main ) target_include_directories(ut_snack PRIVATE ${INCLUDE_DIR} ) target_compile_options(ut_snack PRIVATE ${TARGET_COMPILER_OPTIONS} ) add_executable(ut_storage include/Snack.hpp include/Storage.hpp src/Snack.cpp src/Storage.cpp test/ut_storage.cpp ) target_link_libraries(ut_storage GTest::gtest_main ) target_include_directories(ut_storage PRIVATE ${INCLUDE_DIR} ) target_compile_options(ut_storage PRIVATE ${TARGET_COMPILER_OPTIONS} ) add_executable(ut_storage_manager include/Snack.hpp include/Storage.hpp include/StorageManager.hpp src/Snack.cpp src/Storage.cpp src/StorageManager.cpp test/ut_storage_manager.cpp ) target_link_libraries(ut_storage_manager GTest::gtest_main ) target_include_directories(ut_storage_manager PRIVATE ${INCLUDE_DIR} ) target_compile_options(ut_storage_manager PRIVATE ${TARGET_COMPILER_OPTIONS} ) include(GoogleTest) gtest_discover_tests(ut_all)