Skip to content

Commit

Permalink
feat(sdl): add sdl dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Milerius committed Oct 30, 2019
1 parent c68e388 commit e774c63
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 19 deletions.
34 changes: 15 additions & 19 deletions cmake/dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,14 @@ if (USE_SFML_ANTARA_WRAPPER)
endif ()

if (USE_SDL_ANTARA_WRAPPER)
if (WIN32)
FetchContent_Declare(
sdl
URL https://github.com/KomodoPlatform/antara-gaming-sdk/releases/download/1.0.0-alpha/antara_windows_x64_sdl_msvc.zip
)
else ()
FetchContent_Declare(
sdl
URL https://github.com/SDL-mirror/SDL/archive/release-2.0.10.zip
)
endif ()
include(ExternalProject)
ExternalProject_Add(external_sdl
PREFIX "${CMAKE_CURRENT_BINARY_DIR}/external"
URL "https://www.libsdl.org/release/SDL2-2.0.10.tar.gz"
URL_HASH SHA256=b4656c13a1f0d0023ae2f4a9cf08ec92fffb464e0f24238337784159b8b91d57
CMAKE_ARGS -DSDL_STATIC=ON -DSDL_SHARED=OFF -DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/external/installed
)
set_target_properties(external_sdl PROPERTIES EXCLUDE_FROM_ALL TRUE)
endif ()

FetchContent_MakeAvailable(doctest entt doom_st expected range-v3 refl-cpp doom_meta nlohmann_json joboccara-pipes)
Expand All @@ -95,16 +92,15 @@ if (USE_SFML_ANTARA_WRAPPER)
endif ()

if (USE_SDL_ANTARA_WRAPPER)
FetchContent_MakeAvailable(sdl)
add_library(antara_sdl_import INTERFACE)
add_library(antara::sdl_import ALIAS antara_sdl_import)
if (WIN32)
set(SDL2_DIR "${sdl_SOURCE_DIR}/cmake")
find_package(SDL2 REQUIRED)
target_link_libraries(antara_sdl_import INTERFACE SDL2::SDL2)
else()
target_link_libraries(antara_sdl_import INTERFACE SDL2)
endif()
add_dependencies(antara_sdl_import external_sdl)
include(GNUInstallDirs)
target_link_directories(antara_sdl_import INTERFACE ${CMAKE_BINARY_DIR}/external/installed/${CMAKE_INSTALL_LIBDIR})
target_include_directories(antara_sdl_import
INTERFACE
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/external/installed/${CMAKE_INSTALL_INCLUDEDIR}>
)
endif ()

add_library(nlohmann_json INTERFACE)
Expand Down
4 changes: 4 additions & 0 deletions modules/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,8 @@ endif()

if (USE_SFML_ANTARA_WRAPPER)
add_subdirectory(sfml)
endif()

if (USE_SDL_ANTARA_WRAPPER)
add_subdirectory(sdl)
endif()
5 changes: 5 additions & 0 deletions modules/sdl/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
add_library(antara_sdl STATIC)
target_sources(antara_sdl PRIVATE antara/gaming/sdl/graphic.system.cpp)
target_include_directories(antara_sdl PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(antara_sdl PUBLIC antara::sdl_import antara::ecs antara::event)
add_library(antara::sdl ALIAS antara_sdl)
33 changes: 33 additions & 0 deletions modules/sdl/antara/gaming/sdl/graphic.system.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/******************************************************************************
* Copyright © 2013-2019 The Komodo Platform Developers. *
* *
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
* the top-level directory of this distribution for the individual copyright *
* holder information and the developer policies on copyright and licensing. *
* *
* Unless otherwise agreed in a custom licensing agreement, no part of the *
* Komodo Platform software, including this file may be copied, modified, *
* propagated or distributed except according to the terms contained in the *
* LICENSE file *
* *
* Removal or modification of this copyright notice is prohibited. *
* *
******************************************************************************/

#include <SDL2/SDL.h>
#include "antara/gaming/event/fatal.error.hpp"
#include "antara/gaming/sdl/graphic.system.hpp"

namespace antara::gaming::sdl
{
void graphic_system::update() noexcept
{
}

graphic_system::graphic_system(entt::registry &registry) noexcept : system(registry)
{
if (auto res = SDL_Init(SDL_INIT_VIDEO); res < 0) {
this->dispatcher_.trigger<event::fatal_error>(std::error_code(res, std::generic_category()));
}
}
}
32 changes: 32 additions & 0 deletions modules/sdl/antara/gaming/sdl/graphic.system.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/******************************************************************************
* Copyright © 2013-2019 The Komodo Platform Developers. *
* *
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
* the top-level directory of this distribution for the individual copyright *
* holder information and the developer policies on copyright and licensing. *
* *
* Unless otherwise agreed in a custom licensing agreement, no part of the *
* Komodo Platform software, including this file may be copied, modified, *
* propagated or distributed except according to the terms contained in the *
* LICENSE file *
* *
* Removal or modification of this copyright notice is prohibited. *
* *
******************************************************************************/

#pragma once

#include <entt/entity/registry.hpp>
#include "antara/gaming/ecs/system.hpp"

namespace antara::gaming::sdl
{
class graphic_system final : public ecs::post_update_system<graphic_system>
{
public:
graphic_system(entt::registry& registry) noexcept;
void update() noexcept final;
};
}

REFL_AUTO(type(antara::gaming::sdl::graphic_system));

0 comments on commit e774c63

Please sign in to comment.