Skip to content

Commit

Permalink
Integrate Google Test library
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-veselov committed Aug 8, 2024
1 parent 5e2f910 commit 5c72fa1
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 13 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/cmake-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ jobs:
- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}

- name: Run Tests
working-directory: ${{github.workspace}}/build
run: ctest -C ${{env.BUILD_TYPE}}

- name: Run Benchmarks
working-directory: ${{github.workspace}}/build/${{env.BUILD_TYPE}}
run: .\Benchmarks.exe > benchmarks.txt
Expand Down
58 changes: 45 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,23 @@ cmake_minimum_required(VERSION 3.17)
include(FindCUDAToolkit)
include(FetchContent)

set(CMAKE_SUPPRESS_REGENERATION ON CACHE BOOL "" FORCE)
set(CMAKE_WARN_DEPRECATED OFF CACHE BOOL "" FORCE)
set(CMAKE_SUPPRESS_REGENERATION ON CACHE BOOL "" FORCE)
set(CMAKE_WARN_DEPRECATED OFF CACHE BOOL "" FORCE)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)

if(NOT DEFINED CMAKE_CUDA_ARCHITECTURES)
set(CMAKE_CUDA_ARCHITECTURES 75)
endif()

if(NOT DEFINED CMAKE_DEBUG_POSTFIX)
set(CMAKE_DEBUG_POSTFIX "")
endif()

# MandelbrotSetExplorer
project(MandelbrotSetExplorer LANGUAGES CUDA CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# glfw-external
FetchContent_Declare(glfw-external
URL https://github.com/glfw/glfw/releases/download/3.4/glfw-3.4.bin.WIN64.zip
Expand All @@ -20,9 +29,9 @@ FetchContent_Declare(glfw-external
)

# rapidjson-external
set(RAPIDJSON_BUILD_DOC OFF CACHE BOOL "" FORCE)
set(RAPIDJSON_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
set(RAPIDJSON_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(RAPIDJSON_BUILD_DOC OFF CACHE BOOL "" FORCE)
set(RAPIDJSON_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
set(RAPIDJSON_BUILD_TESTS OFF CACHE BOOL "" FORCE)
FetchContent_Declare(rapidjson-external
GIT_REPOSITORY https://github.com/Tencent/rapidjson.git
GIT_TAG v1.1.0
Expand All @@ -32,17 +41,28 @@ FetchContent_Declare(rapidjson-external

# googlebenchmark-external
set(BENCHMARK_ENABLE_GTEST_TESTS OFF CACHE BOOL "" FORCE)
set(BENCHMARK_ENABLE_INSTALL OFF CACHE BOOL "" FORCE)
set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "" FORCE)
set(BENCHMARK_INSTALL_DOCS OFF CACHE BOOL "" FORCE)
set(BENCHMARK_USE_BUNDLED_GTEST OFF CACHE BOOL "" FORCE)
set(BENCHMARK_ENABLE_INSTALL OFF CACHE BOOL "" FORCE)
set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "" FORCE)
set(BENCHMARK_INSTALL_DOCS OFF CACHE BOOL "" FORCE)
set(BENCHMARK_USE_BUNDLED_GTEST OFF CACHE BOOL "" FORCE)
FetchContent_Declare(googlebenchmark-external
GIT_REPOSITORY https://github.com/google/benchmark.git
GIT_TAG v1.8.5
BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/benchmark
DOWNLOAD_EXTRACT_TIMESTAMP true
)

# googletest-external
set(BUILD_GMOCK OFF CACHE BOOL "" FORCE)
set(INSTALL_GTEST OFF CACHE BOOL "" FORCE)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_Declare(googletest-external
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG v1.15.2
BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/googletest
DOWNLOAD_EXTRACT_TIMESTAMP true
)

# lodepng-external
FetchContent_Declare(lodepng-external
GIT_REPOSITORY https://github.com/lvandeve/lodepng.git
Expand All @@ -53,6 +73,7 @@ FetchContent_Declare(lodepng-external
FetchContent_MakeAvailable(
glfw-external
googlebenchmark-external
googletest-external
rapidjson-external
lodepng-external
)
Expand All @@ -66,6 +87,11 @@ FetchContent_GetProperties(
set_target_properties(benchmark PROPERTIES FOLDER "External")
set_target_properties(benchmark_main PROPERTIES FOLDER "External")

# Google test
# gtest and gtest_main targets are available
set_target_properties(gtest PROPERTIES FOLDER "External")
set_target_properties(gtest_main PROPERTIES FOLDER "External")

# OpenGL
add_library(OpenGL STATIC IMPORTED)
set_target_properties(OpenGL PROPERTIES
Expand Down Expand Up @@ -96,10 +122,6 @@ target_include_directories(LodePNG PUBLIC
)
set_target_properties(LodePNG PROPERTIES FOLDER "External")

# MandelbrotSetExplorer
project(MandelbrotSetExplorer LANGUAGES CUDA CXX)
set(CMAKE_CXX_STANDARD 17)

# Core library
set(CORE_INCLUDE_FOLDER "include/core")
set(CORE_SOURCE_FOLDER "src/core")
Expand All @@ -115,6 +137,16 @@ file(GLOB BENCHMARKS_SOURCES ${BENCHMARKS_SOURCE_FOLDER}/*.cpp)
add_executable(Benchmarks ${BENCHMARKS_SOURCES})
target_link_libraries(Benchmarks PRIVATE benchmark benchmark_main MandelbrotSetCore)

# Tests
enable_testing()
set(TESTS_SOURCE_FOLDER "src/tests")
file(GLOB TESTS_SOURCE_FOLDER ${TESTS_SOURCE_FOLDER}/*.cpp)
add_executable(Tests ${TESTS_SOURCE_FOLDER})
target_link_libraries(Tests PRIVATE gtest gtest_main)
target_link_libraries(Tests PUBLIC MandelbrotSetCore)
include(GoogleTest)
gtest_discover_tests(Tests)

# Application executable
set(APP_INCLUDE_FOLDER "include/application")
set(APP_SOURCE_FOLDER "src/application")
Expand Down
9 changes: 9 additions & 0 deletions src/tests/tests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <gtest/gtest.h>

namespace MandelbrotSet {

TEST(MandelbrotSet, Dummy) {
EXPECT_TRUE(true);
}

} // namespace MandelbrotSet

0 comments on commit 5c72fa1

Please sign in to comment.