Skip to content

Commit

Permalink
Build tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yksen committed Sep 8, 2023
1 parent bc6b6b9 commit bc8e11c
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 55 deletions.
9 changes: 2 additions & 7 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ env:

jobs:
build:
# The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac.
# You can convert this to a matrix build if you need cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
runs-on: windows-latest

steps:
Expand All @@ -25,9 +22,7 @@ jobs:
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}

- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} --target Everland

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

run: ctest -C ${{env.BUILD_TYPE}} --output-on-failure
22 changes: 13 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
cmake_minimum_required(VERSION 3.15...3.27)
project(Everland LANGUAGES CXX)
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)

enable_testing()

include(AddGoogleTest)

set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(SOURCES
${CMAKE_SOURCE_DIR}/src/Application.cpp
${CMAKE_SOURCE_DIR}/src/logic/Game.cpp
${CMAKE_SOURCE_DIR}/src/logic/Player.cpp
${CMAKE_SOURCE_DIR}/src/world/World.cpp
${CMAKE_SOURCE_DIR}/src/world/Generator.cpp
${CMAKE_SOURCE_DIR}/src/world/MeshBuilder.cpp
)
configure_file(${CMAKE_SOURCE_DIR}/resources/shaders/fragment.glsl ${CMAKE_BINARY_DIR}/resources/shaders/fragment.glsl COPYONLY)
configure_file(${CMAKE_SOURCE_DIR}/resources/shaders/vertex.glsl ${CMAKE_BINARY_DIR}/resources/shaders/vertex.glsl COPYONLY)

add_subdirectory(lib)
add_subdirectory(src)
Expand All @@ -23,4 +23,8 @@ add_custom_target(run
WORKING_DIRECTORY ${CMAKE_PROJECT_DIR}
)

enable_testing()
add_custom_target(run_tests
COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure
DEPENDS EverlandTest
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
10 changes: 10 additions & 0 deletions cmake/AddGoogleTest.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
include(FetchContent)

FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG v1.14.0
)

FetchContent_MakeAvailable(googletest)
include(GoogleTest)
27 changes: 16 additions & 11 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
add_executable(Everland
main.cpp
${SOURCES}
set(SOURCES
${CMAKE_SOURCE_DIR}/src/Application.cpp
${CMAKE_SOURCE_DIR}/src/logic/Game.cpp
${CMAKE_SOURCE_DIR}/src/logic/Player.cpp
${CMAKE_SOURCE_DIR}/src/world/World.cpp
${CMAKE_SOURCE_DIR}/src/world/Generator.cpp
${CMAKE_SOURCE_DIR}/src/world/MeshBuilder.cpp
)

target_include_directories(Everland PRIVATE ${CMAKE_SOURCE_DIR}/src)
target_include_directories(Everland SYSTEM PRIVATE
add_library(EverlandLib STATIC ${SOURCES})
target_link_libraries(EverlandLib PUBLIC fmt raylib raylib_cpp)

target_include_directories(EverlandLib PUBLIC ${CMAKE_SOURCE_DIR}/src)
target_include_directories(EverlandLib SYSTEM PUBLIC
${CMAKE_SOURCE_DIR}/lib/magic_enum/include
${CMAKE_SOURCE_DIR}/lib/raylib-cpp/include
${CMAKE_SOURCE_DIR}/lib/PerlinNoise
)

target_link_libraries(Everland PRIVATE fmt raylib raylib_cpp)

if (MSVC)
target_compile_options(Everland PRIVATE /W4)
target_compile_options(EverlandLib PUBLIC /W4)
else()
target_compile_options(Everland PRIVATE -Wall -Wextra -pedantic)
target_compile_options(EverlandLib PUBLIC -Wall -Wextra -pedantic)
endif()

configure_file(${CMAKE_SOURCE_DIR}/resources/shaders/fragment.glsl ${CMAKE_BINARY_DIR}/resources/shaders/fragment.glsl COPYONLY)
configure_file(${CMAKE_SOURCE_DIR}/resources/shaders/vertex.glsl ${CMAKE_BINARY_DIR}/resources/shaders/vertex.glsl COPYONLY)
add_executable(Everland main.cpp ${SOURCES})
target_link_libraries(Everland PUBLIC EverlandLib)
35 changes: 7 additions & 28 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,34 +1,13 @@
include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
)
include(GoogleTest)

set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)

set(TEST_SOURCES
world/WorldTest.cpp
)
add_executable(EverlandTest
${SOURCES}
${TEST_SOURCES}
)

target_include_directories(EverlandTest PRIVATE ${CMAKE_SOURCE_DIR}/src)
target_include_directories(EverlandTest SYSTEM PRIVATE
${CMAKE_SOURCE_DIR}/lib/magic_enum/include
${CMAKE_SOURCE_DIR}/lib/raylib-cpp/include
${CMAKE_SOURCE_DIR}/lib/PerlinNoise
)

target_link_libraries(EverlandTest gtest_main fmt raylib raylib_cpp)
add_executable(EverlandTest ${TEST_SOURCES})
target_link_libraries(EverlandTest gtest gtest_main EverlandLib)

gtest_discover_tests(EverlandTest)
gtest_discover_tests(EverlandTest
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
)

add_custom_target(run_tests
COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure
DEPENDS EverlandTest Everland
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
set_target_properties(EverlandTest PROPERTIES FOLDER test)

0 comments on commit bc8e11c

Please sign in to comment.