From 2cf590494f025f4035e111e1829bb4ae33423faf Mon Sep 17 00:00:00 2001 From: Andrew Coffey Date: Wed, 10 Jan 2024 23:38:58 -0600 Subject: [PATCH 1/5] added gtest and cleaned up cmake --- .github/workflows/gtest.yml | 52 ++++++++ CMakeLists.txt | 253 +++++++++++++++++------------------- test/test_RenderWindow.cpp | 39 ++++++ 3 files changed, 210 insertions(+), 134 deletions(-) create mode 100644 .github/workflows/gtest.yml create mode 100644 test/test_RenderWindow.cpp diff --git a/.github/workflows/gtest.yml b/.github/workflows/gtest.yml new file mode 100644 index 0000000..de5ec53 --- /dev/null +++ b/.github/workflows/gtest.yml @@ -0,0 +1,52 @@ +name: gtest + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + build: + runs-on: ${{ matrix.os }} + + strategy: + # Set fail-fast to false to ensure that feedback is delivered for all matrix combinations. Consider changing this to true when your workflow is stable. + fail-fast: false + + # Set up a matrix to run the following 3 configurations: + # 1. + # 2. + # 3. + # + # To add more build types (Release, Debug, RelWithDebInfo, etc.) customize the build_type list. + matrix: + os: [ubuntu-latest, windows-latest] + build_type: [Release] + c_compiler: [gcc, clang, cl] + include: + - os: windows-latest + c_compiler: cl + cpp_compiler: cl + - os: ubuntu-latest + c_compiler: gcc + cpp_compiler: g++ + - os: ubuntu-latest + c_compiler: clang + cpp_compiler: clang++ + exclude: + - os: windows-latest + c_compiler: gcc + - os: windows-latest + c_compiler: clang + - os: ubuntu-latest + c_compiler: cl + + steps: + - uses: actions/checkout@v3 + - name: configure + run: mkdir bld && cd bld && cmake .. -G "Unix Makefiles" + - name: build + run: make -j8 + - name: run tests + run: cd ../bin && ./Kraken_Test \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index b8017f4..4db1873 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,173 +1,158 @@ cmake_minimum_required(VERSION 3.10) -project(Kraken LANGUAGES CXX) +set(LIBRARY "Kraken") +set(TESTING "Kraken_Test") +project(${TESTING} LANGUAGES CXX) +project(${LIBRARY} LANGUAGES CXX) + +file(GLOB SOURCES "src/*.cpp") +file(GLOB TESTS "test/*.cpp") +add_library(Kraken ${SOURCES}) +add_executable(Kraken_Test EXCLUDE_FROM_ALL ${SOURCES} ${TESTS}) set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -m64") -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/../bin) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) set(CMAKE_POSITION_INDEPENDENT_CODE ON) include_directories(include) include(FetchContent) +include(GoogleTest) + +enable_testing() # ================ ============== -set(FREETYPE_GIT_VERSION VER-2-13-2) set(SDL_GIT_VERSION release-2.28.5) set(SDL_TTF_GIT_VERSION release-2.20.2) set(SDL_IMAGE_GIT_VERSION release-2.8.2) set(SDL_MIXER_GIT_VERSION release-2.6.3) set(TMX_LITE_VERSION v1.4.4) -set(SDL2MIXER_VENDORED TRUE) - -if (NOT freetype_FOUND) # If there's none, fetch and build - include(FetchContent) - FetchContent_Declare( - freetype - GIT_REPOSITORY https://github.com/freetype/freetype.git - GIT_TAG ${FREETYPE_GIT_VERSION} - ) - FetchContent_GetProperties(freetype) - if (NOT freetype_POPULATED) - set(FETCHCONTENT_QUIET NO) - FetchContent_Populate(freetype) - message("freetype_LIBRARY: " ${freetype_LIBRARY}) # fail but define in cmake - message("freetype_INCLUDE_DIR: " ${freetype_INCLUDE_DIR}) #pass - message("freetype_SOURCE_DIR: " ${freetype_SOURCE_DIR}) # pass - message("freetype_BINARY_DIR: " ${freetype_BINARY_DIR}) # pass - - # build freetype - list(APPEND CPP_INCLUDE_DIRS ${freetype_SOURCE_DIR}/include) - list(APPEND CPP_INCLUDE_DIRS ${freetype_BINARY_DIR}/include) - list(APPEND CPP_HEADER_FILES ${freetype_SOURCE_DIR}/include/ft2build.h) - - list(APPEND FREETYPE_INCLUDE_DIRS ${freetype_SOURCE_DIR}/include) - list(APPEND FREETYPE_INCLUDE_DIRS ${freetype_BINARY_DIR}/include) - - set(FREETYPE_LIBRARY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}) - - add_subdirectory(${freetype_SOURCE_DIR} ${freetype_BINARY_DIR}) #add to build in sub dir - add_library(Freetype::Freetype ALIAS freetype) - - endif() -endif() - -message("sdl_FOUND:" ${SDL_FOUND}) -if (NOT sdl_FOUND) # If there's none, fetch and build sdl - include(FetchContent) - FetchContent_Declare( - sdl +############### +# SDL2 # +############### + +set(SDL2_DISABLE_INSTALL OFF CACHE BOOL "Disable installation of SDL2") # i forget why this is necessary but im assuming it wont work without +set(SDL_STATIC OFF CACHE BOOL "Build a static library") +set(SDL_SHARED ON CACHE BOOL "Build a shared library") +set(SDL_TEST OFF CACHE BOOL "Build the test programs") +set(SDL_STATIC_PIC OFF CACHE BOOL "Build static libraries with PIC (Position Independent Code)") +FetchContent_Declare( + SDL2 GIT_REPOSITORY https://github.com/libsdl-org/SDL.git - GIT_TAG ${SDL_GIT_VERSION} - ) - FetchContent_GetProperties(sdl) - if (NOT SDL2_POPULATED) - set(FETCHCONTENT_QUIET NO) - FetchContent_Populate(sdl) - # build SDL2 - list(APPEND CPP_INCLUDE_DIRS ${sdl_SOURCE_DIR}/include) - - link_directories(${PROJECT_BINARY_DIR}/Debug) - add_subdirectory(${sdl_SOURCE_DIR} ${sdl_BINARY_DIR}) - - #needed for sub modules - list(APPEND SDL2_INCLUDE_DIR ${sdl_SOURCE_DIR}/include) - - list(APPEND SDL2_LIBRARIES ${PROJECT_SOURCE_DIR}/build/Debug/SDL2maind.lib) - list(APPEND SDL2_LIBRARIES ${PROJECT_SOURCE_DIR}/build/Debug/SDL2-staticd.lib) - list(APPEND SDL2_LIBRARIES ${PROJECT_SOURCE_DIR}/build/Debug/SDL2d.lib) - - list(APPEND CPP_LIBS "SDL2main") - list(APPEND CPP_LIBS "SDL2-static") - add_library(SDL2::SDL2 ALIAS SDL2) - add_library(SDL2::SDL2-static ALIAS SDL2-static) - - endif() -endif() - -set(SDL2TTF_INSTALL OFF CACHE STRING "" FORCE) - -if (NOT sdl_ttf_FOUND) # If there's none, fetch and build sdl - include(FetchContent) - FetchContent_Declare( - sdl_ttf - GIT_REPOSITORY https://github.com/libsdl-org/SDL_ttf.git - GIT_TAG ${SDL_TTF_GIT_VERSION} - ) - FetchContent_GetProperties(sdl_ttf) - if (NOT sdl_ttf_POPULATED) # Have we downloaded raylib yet? - set(FETCHCONTENT_QUIET NO) - FetchContent_Populate(sdl_ttf) - add_subdirectory(${sdl_ttf_SOURCE_DIR} ${sdl_ttf_BINARY_DIR}) - endif() -endif() - -if (NOT sdl_image_FOUND) # If there's none, fetch and build sdl - include(FetchContent) - FetchContent_Declare( - sdl_image + GIT_TAG ${SDL_GIT_VERSION} + GIT_PROGRESS TRUE +) +# set(SDL_SHARED OFF CACHE BOOL "Build a shared library") +FetchContent_MakeAvailable(SDL2) +target_include_directories(Kraken PRIVATE ${SDL2_SOURCE_DIR}/include) +target_include_directories(Kraken_Test PRIVATE ${SDL2_SOURCE_DIR}/include) + +############### +# SDL2_ttf # +############### + +set(BUILD_SHARED_LIBS ON CACHE BOOL "Build the library as a shared library") +# set(SDL2TTF_BUILD_SHARED_LIBS OFF CACHE BOOL "Build the library as a shared library") +set(SDL2TTF_SAMPLES OFF CACHE BOOL "Build the SDL2_ttf sample program(s)") +# let it know it needs to get its vendored deps +set(SDL2TTF_VENDORED ON CACHE BOOL "Use the vendored version of FreeType and HarfBuzz") +FetchContent_Declare( + SDL2_ttf + GIT_REPOSITORY https://github.com/libsdl-org/SDL_ttf + GIT_TAG ${SDL_TTF_GIT_VERSION} + GIT_PROGRESS TRUE +) +FetchContent_MakeAvailable(SDL2_ttf) +target_include_directories(Kraken PRIVATE ${SDL2_ttf_SOURCE_DIR}) # include is in the root of the repo +target_include_directories(Kraken_Test PRIVATE ${SDL2_ttf_SOURCE_DIR}) # include is in the root of the repo + +############### +# SDL_image # +############### + +FetchContent_Declare( + SDL2_image GIT_REPOSITORY https://github.com/libsdl-org/SDL_image.git - GIT_TAG ${SDL_IMAGE_GIT_VERSION} - ) - FetchContent_GetProperties(sdl_image) - if (NOT sdl_image_POPULATED) # Have we downloaded raylib yet? - set(FETCHCONTENT_QUIET NO) - FetchContent_Populate(sdl_image) - - set(SUPPORT_JPG OFF CACHE BOOL "" FORCE) - set(SUPPORT_PNG ON CACHE BOOL "" FORCE) - set(BUILD_SHOWIMAGE OFF CACHE BOOL "" FORCE) - set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE) - - # build sdl2 image - add_subdirectory(${sdl_image_SOURCE_DIR} ${sdl_image_BINARY_DIR}) - endif() -endif() - -if (NOT sdl_mixer_FOUND) # If there's none, fetch and build sdl - include(FetchContent) - FetchContent_Declare( - sdl_mixer - GIT_REPOSITORY https://github.com/libsdl-org/SDL_mixer.git - GIT_TAG ${SDL_MIXER_GIT_VERSION} - ) - FetchContent_GetProperties(sdl_mixer) + GIT_TAG ${SDL_IMAGE_GIT_VERSION} + GIT_PROGRESS TRUE +) +FetchContent_MakeAvailable(SDL2_image) +target_include_directories(Kraken PRIVATE ${SDL2_image_SOURCE_DIR}/include) +target_include_directories(Kraken_Test PRIVATE ${SDL2_image_SOURCE_DIR}/include) + +############### +# SDL_mixer # +############### - if (NOT sdl_mixer_POPULATED) # Have we downloaded raylib yet? - set(FETCHCONTENT_QUIET NO) - FetchContent_Populate(sdl_mixer) +# disable annoying codecs we dont need that require dependencies i dont have +set(SDL2MIXER_OPUS OFF CACHE BOOL "Enable Opus support") +set(SDL2MIXER_FLAC OFF CACHE BOOL "Enable FLAC support") +set(SDL2MIXER_MOD OFF CACHE BOOL "Enable Mod support") +set(SDL2MIXER_MIDI OFF CACHE BOOL "Enable MIDI support") - set(SUPPORT_OGG ON CACHE BOOL "" FORCE) +# mp3 enabled +set(SDL2MIXER_MP3 ON CACHE BOOL "Enable MP3 support") - # build SDL2 MIXER - list(APPEND CPP_INCLUDE_DIRS ${sdl_mixer_SOURCE_DIR}/include) - add_subdirectory(${sdl_mixer_SOURCE_DIR} ${sdl_mixer_BINARY_DIR}) - list(APPEND CPP_LIBS "SDL2_mixer") - endif() -endif() +# wav enabled +set(SDL2MIXER_WAV ON CACHE BOOL "Enable WAV support") +FetchContent_Declare( + SDL2_mixer + GIT_REPOSITORY https://github.com/libsdl-org/SDL_mixer.git + GIT_TAG ${SDL_MIXER_GIT_VERSION} + GIT_PROGRESS TRUE +) +FetchContent_MakeAvailable(SDL2_mixer) +target_include_directories(Kraken PRIVATE ${SDL2_mixer_SOURCE_DIR}/include) +target_include_directories(Kraken_Test PRIVATE ${SDL2_mixer_SOURCE_DIR}/include) + +############# +# tmxlite # +############# + +set(TMXLITE_STATIC_LIB OFF CACHE BOOL "Build tmxlite as static") FetchContent_Declare( tmxlite GIT_REPOSITORY https://github.com/fallahn/tmxlite.git GIT_TAG ${TMX_LITE_VERSION} + GIT_PROGRESS TRUE ) - FetchContent_MakeAvailable(tmxlite) -message(STATUS "tmxlite_SOURCE_DIR " ${tmxlite_SOURCE_DIR}) + list(APPEND CPP_INCLUDE_DIRS ${tmxlite_SOURCE_DIR}/tmxlite/include) add_subdirectory(${tmxlite_SOURCE_DIR}/tmxlite ${tmxlite_BINARY_DIR}) list(APPEND CPP_LIBS "tmxlite") +target_include_directories(Kraken PRIVATE ${tmxlite_SOURCE_DIR}/tmxlite/include) +target_include_directories(Kraken_Test PRIVATE ${tmxlite_SOURCE_DIR}/tmxlite/include) + +########### +# gtest # +########### + +FetchContent_Declare(googletest + GIT_REPOSITORY https://github.com/google/googletest.git + GIT_TAG f8d7d77c06936315286eb55f8de22cd23c188571 + GIT_PROGRESS TRUE +) +# For Windows: Prevent overriding the parent project's compiler/linker settings +set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) +FetchContent_MakeAvailable(googletest) + # ================ ============== -file(GLOB SOURCES "src/*.cpp") -add_library(${PROJECT_NAME} ${SOURCES}) -FetchContent_MakeAvailable(SDL SDL_image SDL_ttf SDL_mixer) +# FetchContent_MakeAvailable(SDL SDL_image SDL_ttf SDL_mixer) + +target_link_libraries(Kraken PRIVATE SDL2 SDL2_image SDL2_ttf SDL2_mixer) +target_link_libraries(Kraken_Test PRIVATE SDL2 SDL2_image SDL2_ttf SDL2_mixer tmxlite gtest_main) + +target_include_directories(Kraken PRIVATE ${CMAKE_SOURCE_DIR}/include) +target_include_directories(Kraken_Test PRIVATE ${CMAKE_SOURCE_DIR}/include) -target_link_libraries(${PROJECT_NAME} PRIVATE SDL2 SDL2_image SDL2_ttf SDL2_mixer) +install(TARGETS Kraken) -target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_BINARY_DIR}/../include) -target_include_directories(${PROJECT_NAME} PRIVATE ${tmxlite_SOURCE_DIR}/tmxlite/include) -install(TARGETS ${PROJECT_NAME}) \ No newline at end of file +gtest_discover_tests(Kraken_Test) \ No newline at end of file diff --git a/test/test_RenderWindow.cpp b/test/test_RenderWindow.cpp new file mode 100644 index 0000000..0ddbc9f --- /dev/null +++ b/test/test_RenderWindow.cpp @@ -0,0 +1,39 @@ +#include + +#include "gtest/gtest.h" + +#include "RenderWindow.hpp" + +const kn::math::Vec2 kn::SCREEN_SIZE = {100, 100}; + +namespace +{ +using kn::RenderWindow; + +class RenderWindowTest : public ::testing::Test +{ + protected: + RenderWindowTest() + { + // Have to set this before first test + if (!RenderWindow::setScale(2)) + { + std::cout << "setScale failed in RenderWindowTest constructor\n"; + } + } + + virtual ~RenderWindowTest() {} + + virtual void SetUp() {} + + virtual void TearDown() {} +}; + +TEST_F(RenderWindowTest, SingletonPointersEqual) +{ + const RenderWindow* window1 = &RenderWindow::getInstance(); + const RenderWindow* window2 = &RenderWindow::getInstance(); + + EXPECT_EQ(window1, window2); +} +} \ No newline at end of file From 2f8b41304df8d12ddd8e64f90595b8918dda4ab8 Mon Sep 17 00:00:00 2001 From: Andrew Coffey Date: Wed, 10 Jan 2024 23:43:10 -0600 Subject: [PATCH 2/5] fixed workflow? --- .github/workflows/gtest.yml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/gtest.yml b/.github/workflows/gtest.yml index de5ec53..1d2260a 100644 --- a/.github/workflows/gtest.yml +++ b/.github/workflows/gtest.yml @@ -44,9 +44,7 @@ jobs: steps: - uses: actions/checkout@v3 - - name: configure - run: mkdir bld && cd bld && cmake .. -G "Unix Makefiles" - - name: build - run: make -j8 + - name: configure and build + run: mkdir bld && cd bld && cmake .. -G "Unix Makefiles" && make Kraken_Test -j8 - name: run tests - run: cd ../bin && ./Kraken_Test \ No newline at end of file + run: cd ../bld && ./Kraken_Test \ No newline at end of file From 7cf5a27afde3cda8af43a10ed5febcddd24496df Mon Sep 17 00:00:00 2001 From: Andrew Coffey Date: Thu, 11 Jan 2024 00:44:44 -0600 Subject: [PATCH 3/5] fixed workflow? other fixes --- .github/workflows/gtest.yml | 8 +++++-- CMakeLists.txt | 9 ++++---- include/Entity.hpp | 44 ++++++++++++++++++------------------- include/RenderWindow.hpp | 4 ++-- test/main.cpp | 8 +++++++ test/test_RenderWindow.cpp | 5 +---- 6 files changed, 44 insertions(+), 34 deletions(-) create mode 100644 test/main.cpp diff --git a/.github/workflows/gtest.yml b/.github/workflows/gtest.yml index 1d2260a..12b88a1 100644 --- a/.github/workflows/gtest.yml +++ b/.github/workflows/gtest.yml @@ -45,6 +45,10 @@ jobs: steps: - uses: actions/checkout@v3 - name: configure and build - run: mkdir bld && cd bld && cmake .. -G "Unix Makefiles" && make Kraken_Test -j8 + run: mkdir bld && cd bld && cmake .. -G "Unix Makefiles" + - name: build + run: cd bld && make -j8 && make Kraken_Test -j8 + - name: copy files + run: cp bin/* ../bin/ && cp Kraken_Test ../bin - name: run tests - run: cd ../bld && ./Kraken_Test \ No newline at end of file + run: cd ../bin && ./Kraken_Test \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 4db1873..e1ed2c1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,7 +12,7 @@ add_executable(Kraken_Test EXCLUDE_FROM_ALL ${SOURCES} ${TESTS}) set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -m64") -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/../bin) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) set(CMAKE_POSITION_INDEPENDENT_CODE ON) @@ -148,11 +148,12 @@ FetchContent_MakeAvailable(googletest) # FetchContent_MakeAvailable(SDL SDL_image SDL_ttf SDL_mixer) target_link_libraries(Kraken PRIVATE SDL2 SDL2_image SDL2_ttf SDL2_mixer) -target_link_libraries(Kraken_Test PRIVATE SDL2 SDL2_image SDL2_ttf SDL2_mixer tmxlite gtest_main) +target_link_libraries(Kraken_Test PRIVATE SDL2 SDL2_image SDL2_ttf SDL2_mixer tmxlite) target_include_directories(Kraken PRIVATE ${CMAKE_SOURCE_DIR}/include) target_include_directories(Kraken_Test PRIVATE ${CMAKE_SOURCE_DIR}/include) +target_include_directories(Kraken_Test PRIVATE ${tmxlite_SOURCE_DIR}/../googletest-src/googletest/include) +message(STATUS "googletest/include " {${tmxlite_SOURCE_DIR}/../googletest-src/googletest/include}) +gtest_discover_tests(Kraken_Test) install(TARGETS Kraken) - -gtest_discover_tests(Kraken_Test) \ No newline at end of file diff --git a/include/Entity.hpp b/include/Entity.hpp index c92fc3f..627cd90 100644 --- a/include/Entity.hpp +++ b/include/Entity.hpp @@ -18,6 +18,28 @@ namespace kn */ class Entity { +public: + /** + * @brief Create a entity. + * + * @param texture The texture of the entity. + */ + Entity(std::shared_ptr texture); + ~Entity() = default; + + /** + * @brief Get the entity's texture pointer. + * + * @return The entity's texture pointer. + */ + std::shared_ptr getTexture() const; + + Rect crop = {0, 0, 0, 0}; + Rect rect; + math::Vec2 position; + math::Vec2 direction; + math::Vec2 velocity; + protected: RenderWindow &window = RenderWindow::getInstance(); std::shared_ptr texture; @@ -87,28 +109,6 @@ class Entity } } } - -public: - /** - * @brief Create a entity. - * - * @param texture The texture of the entity. - */ - Entity(std::shared_ptr texture); - ~Entity() = default; - - /** - * @brief Get the entity's texture pointer. - * - * @return The entity's texture pointer. - */ - std::shared_ptr getTexture() const; - - Rect crop = {0, 0, 0, 0}; - Rect rect; - math::Vec2 position; - math::Vec2 direction; - math::Vec2 velocity; }; } diff --git a/include/RenderWindow.hpp b/include/RenderWindow.hpp index f24243f..79a2649 100644 --- a/include/RenderWindow.hpp +++ b/include/RenderWindow.hpp @@ -94,7 +94,7 @@ class RenderWindow final * * @return The user events. */ - const std::vector &getEvents(); + const std::vector &getEvents(); /** * @brief Get whether the window is fullscreen or not @@ -142,7 +142,7 @@ class RenderWindow final SDL_Renderer *m_renderer = nullptr; SDL_Window *m_window = nullptr; - KN_Event m_event; + kn::Event m_event; std::vector m_events; }; diff --git a/test/main.cpp b/test/main.cpp new file mode 100644 index 0000000..ff90c4c --- /dev/null +++ b/test/main.cpp @@ -0,0 +1,8 @@ +#include "gtest/gtest.h" + +int main(int argc, char** argv) +{ + testing::InitGoogleTest(&argc, argv); + + return RUN_ALL_TESTS(); +} diff --git a/test/test_RenderWindow.cpp b/test/test_RenderWindow.cpp index 0ddbc9f..c059cc5 100644 --- a/test/test_RenderWindow.cpp +++ b/test/test_RenderWindow.cpp @@ -16,10 +16,7 @@ class RenderWindowTest : public ::testing::Test RenderWindowTest() { // Have to set this before first test - if (!RenderWindow::setScale(2)) - { - std::cout << "setScale failed in RenderWindowTest constructor\n"; - } + RenderWindow::setScale(2); } virtual ~RenderWindowTest() {} From c40745821e26e6045e1d0a7d049a05602b223a5b Mon Sep 17 00:00:00 2001 From: Andrew Coffey Date: Thu, 11 Jan 2024 20:54:50 -0600 Subject: [PATCH 4/5] fixed the things --- .github/workflows/gtest.yml | 2 -- CMakeLists.txt | 60 ++++++++++++++++++++++++++++++------- test/test_RenderWindow.cpp | 1 + 3 files changed, 51 insertions(+), 12 deletions(-) diff --git a/.github/workflows/gtest.yml b/.github/workflows/gtest.yml index 12b88a1..b62a401 100644 --- a/.github/workflows/gtest.yml +++ b/.github/workflows/gtest.yml @@ -48,7 +48,5 @@ jobs: run: mkdir bld && cd bld && cmake .. -G "Unix Makefiles" - name: build run: cd bld && make -j8 && make Kraken_Test -j8 - - name: copy files - run: cp bin/* ../bin/ && cp Kraken_Test ../bin - name: run tests run: cd ../bin && ./Kraken_Test \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index e1ed2c1..61c6684 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.10) +cmake_minimum_required(VERSION 3.16) set(LIBRARY "Kraken") set(TESTING "Kraken_Test") project(${TESTING} LANGUAGES CXX) @@ -9,19 +9,27 @@ file(GLOB TESTS "test/*.cpp") add_library(Kraken ${SOURCES}) add_executable(Kraken_Test EXCLUDE_FROM_ALL ${SOURCES} ${TESTS}) +set_target_properties( ${LIBRARY} PROPERTIES RUNTIME_OUTPUT_DIRECTORY + ${CMAKE_SOURCE_DIR}/bin ) +set_target_properties( ${LIBRARY} PROPERTIES LIBRARY_OUTPUT_DIRECTORY + ${CMAKE_SOURCE_DIR}/bin ) + +set_target_properties( ${TESTING} PROPERTIES RUNTIME_OUTPUT_DIRECTORY + ${CMAKE_SOURCE_DIR}/bin ) +set_target_properties( ${TESTING} PROPERTIES LIBRARY_OUTPUT_DIRECTORY + ${CMAKE_SOURCE_DIR}/bin ) + set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -m64") -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/../bin) -set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin) set(CMAKE_POSITION_INDEPENDENT_CODE ON) include_directories(include) include(FetchContent) include(GoogleTest) -enable_testing() - # ================ ============== set(SDL_GIT_VERSION release-2.28.5) @@ -140,20 +148,52 @@ FetchContent_Declare(googletest ) # For Windows: Prevent overriding the parent project's compiler/linker settings set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) + FetchContent_MakeAvailable(googletest) # ================ ============== +enable_testing() -# FetchContent_MakeAvailable(SDL SDL_image SDL_ttf SDL_mixer) - -target_link_libraries(Kraken PRIVATE SDL2 SDL2_image SDL2_ttf SDL2_mixer) -target_link_libraries(Kraken_Test PRIVATE SDL2 SDL2_image SDL2_ttf SDL2_mixer tmxlite) +if (WIN32) + add_custom_command( + TARGET ${TESTING} + COMMENT "Copy gtest dlls" + PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/bld/bin/libgtest.dll ${CMAKE_SOURCE_DIR}/bin/ + VERBATIM + ) +endif() +if (WIN32) + add_custom_command( + TARGET ${TESTING} + COMMENT "Copy gtest dlls" + PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/bld/bin/libgmock.dll ${CMAKE_SOURCE_DIR}/bin/ + VERBATIM + ) +endif() +if (WIN32) + add_custom_command( + TARGET ${TESTING} + COMMENT "Copy gtest dlls" + PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/bld/bin/libgtest_main.dll ${CMAKE_SOURCE_DIR}/bin/ + VERBATIM + ) +endif() +if (WIN32) + add_custom_command( + TARGET ${TESTING} + COMMENT "Copy gtest dlls" + PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/bld/bin/libgmock_main.dll ${CMAKE_SOURCE_DIR}/bin/ + VERBATIM + ) +endif() + +target_link_libraries(Kraken PRIVATE SDL2 SDL2_image SDL2_ttf SDL2_mixer tmxlite) +target_link_libraries(Kraken_Test PRIVATE SDL2 SDL2_image SDL2_ttf SDL2_mixer tmxlite gtest) target_include_directories(Kraken PRIVATE ${CMAKE_SOURCE_DIR}/include) target_include_directories(Kraken_Test PRIVATE ${CMAKE_SOURCE_DIR}/include) target_include_directories(Kraken_Test PRIVATE ${tmxlite_SOURCE_DIR}/../googletest-src/googletest/include) -message(STATUS "googletest/include " {${tmxlite_SOURCE_DIR}/../googletest-src/googletest/include}) gtest_discover_tests(Kraken_Test) install(TARGETS Kraken) diff --git a/test/test_RenderWindow.cpp b/test/test_RenderWindow.cpp index c059cc5..4442ad5 100644 --- a/test/test_RenderWindow.cpp +++ b/test/test_RenderWindow.cpp @@ -4,6 +4,7 @@ #include "RenderWindow.hpp" +#define KN_SCREEN_SIZE_DEFINED const kn::math::Vec2 kn::SCREEN_SIZE = {100, 100}; namespace From e5a396c5c3e644489acd2e897ea2eb19e48ab8ab Mon Sep 17 00:00:00 2001 From: Andrew Coffey Date: Thu, 11 Jan 2024 21:25:08 -0600 Subject: [PATCH 5/5] removed testing from build actions --- .github/workflows/cmake-multi-platform.yml | 6 --- .github/workflows/gtest.yml | 52 ---------------------- 2 files changed, 58 deletions(-) delete mode 100644 .github/workflows/gtest.yml diff --git a/.github/workflows/cmake-multi-platform.yml b/.github/workflows/cmake-multi-platform.yml index e995f98..5ceee28 100644 --- a/.github/workflows/cmake-multi-platform.yml +++ b/.github/workflows/cmake-multi-platform.yml @@ -67,9 +67,3 @@ jobs: - name: Build # Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator). run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }} - - - name: Test - working-directory: ${{ steps.strings.outputs.build-output-dir }} - # Execute tests defined by the CMake configuration. Note that --build-config is needed because the default Windows generator is a multi-config generator (Visual Studio generator). - # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail - run: ctest --build-config ${{ matrix.build_type }} diff --git a/.github/workflows/gtest.yml b/.github/workflows/gtest.yml deleted file mode 100644 index b62a401..0000000 --- a/.github/workflows/gtest.yml +++ /dev/null @@ -1,52 +0,0 @@ -name: gtest - -on: - push: - branches: [main] - pull_request: - branches: [main] - -jobs: - build: - runs-on: ${{ matrix.os }} - - strategy: - # Set fail-fast to false to ensure that feedback is delivered for all matrix combinations. Consider changing this to true when your workflow is stable. - fail-fast: false - - # Set up a matrix to run the following 3 configurations: - # 1. - # 2. - # 3. - # - # To add more build types (Release, Debug, RelWithDebInfo, etc.) customize the build_type list. - matrix: - os: [ubuntu-latest, windows-latest] - build_type: [Release] - c_compiler: [gcc, clang, cl] - include: - - os: windows-latest - c_compiler: cl - cpp_compiler: cl - - os: ubuntu-latest - c_compiler: gcc - cpp_compiler: g++ - - os: ubuntu-latest - c_compiler: clang - cpp_compiler: clang++ - exclude: - - os: windows-latest - c_compiler: gcc - - os: windows-latest - c_compiler: clang - - os: ubuntu-latest - c_compiler: cl - - steps: - - uses: actions/checkout@v3 - - name: configure and build - run: mkdir bld && cd bld && cmake .. -G "Unix Makefiles" - - name: build - run: cd bld && make -j8 && make Kraken_Test -j8 - - name: run tests - run: cd ../bin && ./Kraken_Test \ No newline at end of file