Skip to content

Formalize sub-directories as library targets #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Oct 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_DEBUG_POSTFIX "-d")

set(target_prefix facade)

project(facade)

option(FACADE_BUILD_SHADERS "Build facade shaders" ON)
option(FACADE_PCH "Use PCH" ON)

if(FACADE_BUILD_SHADERS)
find_program(glslc glslc)
Expand All @@ -17,14 +20,8 @@ if(FACADE_BUILD_SHADERS)
endif()
endif()

set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
try_compile(has_make_unique_for_overwrite "${CMAKE_CURRENT_BINARY_DIR}" SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/cmake/src/make_unique_for_overwrite.cpp")

add_subdirectory(ext)
add_subdirectory(cmake/interface)
add_subdirectory(tools/embed_shader)

add_subdirectory(facade-lib)
add_subdirectory(lib)

if(FACADE_BUILD_SHADERS)
message(STATUS "Adding build step to embed shaders")
Expand Down Expand Up @@ -57,5 +54,16 @@ target_sources(${PROJECT_NAME} PRIVATE
src/bin/unlit_frag.spv.hpp
)

target_link_libraries(${PROJECT_NAME} PRIVATE facade::lib facade::compile-options)
target_link_libraries(${PROJECT_NAME} PRIVATE
facade::context
facade::editor
facade::compile-options
)

string(TOUPPER ${target_prefix} target_prefix_upper)

if(${${target_prefix_upper}_PCH})
target_precompile_headers(${PROJECT_NAME} REUSE_FROM ${target_prefix}-vk)
endif()

target_include_directories(${PROJECT_NAME} PRIVATE src)
18 changes: 0 additions & 18 deletions cmake/interface/CMakeLists.txt

This file was deleted.

177 changes: 0 additions & 177 deletions facade-lib/CMakeLists.txt

This file was deleted.

22 changes: 22 additions & 0 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
cmake_minimum_required(VERSION 3.18 FATAL_ERROR)

if("${target_prefix}" STREQUAL "")
message(FATAL_ERROR "target_prefix unset")
endif()

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_DEBUG_POSTFIX "-d")

project(${target_prefix}-lib)

add_subdirectory(ext)
add_subdirectory(interface)
add_subdirectory(util)
add_subdirectory(vk)
add_subdirectory(glfw)
add_subdirectory(render)
add_subdirectory(scene)
add_subdirectory(engine)
add_subdirectory(editor)
add_subdirectory(context)
39 changes: 39 additions & 0 deletions lib/context/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
if("${target_prefix}" STREQUAL "")
message(FATAL_ERROR "target_prefix unset")
endif()

project(${target_prefix}-context)

add_library(${PROJECT_NAME})
add_library(${target_prefix}::context ALIAS ${PROJECT_NAME})

target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_20)

target_include_directories(${PROJECT_NAME}
PUBLIC
include

PRIVATE
src
)

target_link_libraries(${PROJECT_NAME}
PUBLIC
${target_prefix}::engine
${target_prefix}::scene

PRIVATE
${target_prefix}::compile-options
)

string(TOUPPER ${target_prefix} target_prefix_upper)

if(${${target_prefix_upper}_PCH})
target_precompile_headers(${PROJECT_NAME} REUSE_FROM ${target_prefix}-vk)
endif()

target_sources(${PROJECT_NAME} PRIVATE
include/${target_prefix}/context/context.hpp

src/context.cpp
)
28 changes: 28 additions & 0 deletions lib/context/include/facade/context/context.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#pragma once
#include <facade/engine/engine.hpp>
#include <facade/scene/scene.hpp>
#include <facade/util/time.hpp>

namespace facade {
class Context {
public:
Context(Engine::CreateInfo const& create_info = {});

void add_shader(Shader shader);

void show(bool reset_dt);

bool running() const { return engine.running(); }
float next_frame();

void request_stop() { engine.request_stop(); }

Engine engine;
Scene scene;

private:
DeltaTime m_dt{};
vk::CommandBuffer m_cb{};
bool m_ready_to_render{};
};
} // namespace facade
22 changes: 22 additions & 0 deletions lib/context/src/context.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <facade/context/context.hpp>

namespace facade {
Context::Context(Engine::CreateInfo const& create_info) : engine(create_info), scene(engine.gfx()) {}

void Context::add_shader(Shader shader) { engine.add_shader(std::move(shader)); }

void Context::show(bool reset_dt) {
engine.show_window();
if (reset_dt) { m_dt = {}; }
}

float Context::next_frame() {
if (m_ready_to_render) {
if (m_cb) { scene.render(engine.renderer(), m_cb); }
engine.submit();
}
if (!engine.next_frame(m_cb)) { m_cb = vk::CommandBuffer{}; }
m_ready_to_render = true;
return m_dt();
}
} // namespace facade
Loading