diff --git a/CMakeLists.txt b/CMakeLists.txt index 497c078..4bd7037 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,9 +41,15 @@ endif () if (WIN32) add_compile_definitions( - _CRT_SECURE_NO_WARNINGS + NOVA_WINDOWS NOMINMAX WIN32_LEAN_AND_MEAN + _CRT_SECURE_NO_WARNINGS + _CRT_NONSTDC_NO_WARNINGS + ) +else () + add_compile_definitions( + NOVA_LINUX ) endif () diff --git a/engine/CMakeLists.txt b/engine/CMakeLists.txt index 418f7be..386574f 100644 --- a/engine/CMakeLists.txt +++ b/engine/CMakeLists.txt @@ -1,9 +1,55 @@ # Copyright (c) 2025, Jayden Grubb # SPDX-License-Identifier: BSD-3-Clause -find_package(Vulkan REQUIRED) include(FetchContent) +set(NOVA_VULKAN ON CACHE BOOL "Enable Vulkan support") +set(NOVA_WAYLAND ON CACHE BOOL "Enable Wayland support") +set(NOVA_X11 ON CACHE BOOL "Enable X11 support") + +set(ENGINE_SRC + core/debug.cpp + platform/system.cpp + render/renderer.cpp + render/render_device.cpp +) + +if (WIN32) + set(ENGINE_SRC + ${ENGINE_SRC} + drivers/windows/system_driver.cpp + ) + set(NOVA_WAYLAND OFF) + set(NOVA_X11 OFF) +else () + set(ENGINE_SRC + ${ENGINE_SRC} + drivers/linux/system_driver.cpp + ) +endif () + +if (NOVA_VULKAN) + find_package(Vulkan REQUIRED) + set(ENGINE_SRC + ${ENGINE_SRC} + drivers/vulkan/render_driver.cpp + ) +endif () +if (NOVA_WAYLAND) + set(ENGINE_SRC + ${ENGINE_SRC} + drivers/linux/wayland/system_driver.cpp + ) +endif () +if (NOVA_X11) + set(ENGINE_SRC + ${ENGINE_SRC} + drivers/linux/x11/system_driver.cpp + ) +endif () + +list(TRANSFORM ENGINE_SRC PREPEND ${CMAKE_CURRENT_SOURCE_DIR}/src/) + FetchContent_Declare( spdlog GIT_REPOSITORY https://github.com/gabime/spdlog.git @@ -20,23 +66,9 @@ FetchContent_Declare( ) FetchContent_MakeAvailable(SDL3) -set(ENGINE_SRC - core/debug.cpp - drivers/vulkan/render_driver.cpp - drivers/windows/system_driver.cpp - drivers/linux/system_driver.cpp - drivers/linux/wayland/system_driver.cpp - drivers/linux/x11/system_driver.cpp - platform/system.cpp - render/renderer.cpp - render/render_device.cpp -) - -list(TRANSFORM ENGINE_SRC PREPEND ${CMAKE_CURRENT_SOURCE_DIR}/src/) - set(ENGINE_INCLUDES_PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src - ${Vulkan_INCLUDE_DIRS} + $<$:${Vulkan_INCLUDE_DIRS}> ${SDL3_INCLUDE_DIRS} ) set(ENGINE_INCLUDES_PUBLIC @@ -44,12 +76,17 @@ set(ENGINE_INCLUDES_PUBLIC ${spdlog_INCLUDE_DIRS} ) set(ENGINE_LIBS_PRIVATE - Vulkan::Vulkan + $<$:Vulkan::Vulkan> SDL3::SDL3 ) set(ENGINE_LIBS_PUBLIC spdlog::spdlog ) +set(ENGINE_DEFS + $<$:NOVA_VULKAN> + $<$:NOVA_WAYLAND> + $<$:NOVA_X11> +) if (NOVA_ENGINE_SHARED) add_library(nova SHARED ${ENGINE_SRC}) @@ -63,6 +100,7 @@ if (NOVA_ENGINE_SHARED) ) target_compile_definitions(nova PRIVATE NOVA_DLL_EXPORT + ${ENGINE_DEFS} ) endif () if (NOVA_ENGINE_STATIC) @@ -75,4 +113,7 @@ if (NOVA_ENGINE_STATIC) PUBLIC ${ENGINE_LIBS_PUBLIC} PRIVATE ${ENGINE_LIBS_PRIVATE} ) + target_compile_definitions(nova_static PRIVATE + ${ENGINE_DEFS} + ) endif () diff --git a/engine/include/nova/api.h b/engine/include/nova/api.h index e71b6a1..6c36b57 100644 --- a/engine/include/nova/api.h +++ b/engine/include/nova/api.h @@ -7,7 +7,7 @@ #pragma once #ifndef NOVA_API - #ifdef WIN32 + #ifdef NOVA_WINDOWS #ifdef NOVA_DLL_EXPORT #define NOVA_API __declspec(dllexport) #elif NOVA_DLL_IMPORT @@ -15,7 +15,7 @@ #else #define NOVA_API #endif - #else + #elif NOVA_LINUX #ifdef NOVA_DLL_EXPORT #define NOVA_API __attribute__((visibility("default"))) #else diff --git a/engine/src/drivers/linux/system_driver.cpp b/engine/src/drivers/linux/system_driver.cpp index e86e41c..8b48f1b 100644 --- a/engine/src/drivers/linux/system_driver.cpp +++ b/engine/src/drivers/linux/system_driver.cpp @@ -4,10 +4,17 @@ * SPDX-License-Identifier: BSD-3-Clause */ -#include "drivers/linux/system_driver.h" +#ifdef NOVA_WAYLAND + #include "drivers/linux/wayland/system_driver.h" +#endif +#ifdef NOVA_X11 + #include "drivers/linux/x11/system_driver.h" +#endif #include +#include "drivers/linux/system_driver.h" + using namespace Nova; LinuxSystemDriver::LinuxSystemDriver() { @@ -17,3 +24,21 @@ LinuxSystemDriver::LinuxSystemDriver() { LinuxSystemDriver::~LinuxSystemDriver() { NOVA_AUTO_TRACE(); } + +std::unique_ptr LinuxSystemDriver::get_default_driver() { + NOVA_AUTO_TRACE(); + +#ifdef NOVA_WAYLAND + if (std::getenv("WAYLAND_DISPLAY")) { + return std::make_unique(); + } +#endif +#ifdef NOVA_X11 + if (std::getenv("DISPLAY")) { + return std::make_unique(); + } +#endif + + NOVA_WARN("Unsupported display server"); + return std::make_unique(); +} diff --git a/engine/src/drivers/linux/system_driver.h b/engine/src/drivers/linux/system_driver.h index 1eac671..f9faa9c 100644 --- a/engine/src/drivers/linux/system_driver.h +++ b/engine/src/drivers/linux/system_driver.h @@ -8,10 +8,14 @@ #include +#include + namespace Nova { class LinuxSystemDriver : public SystemDriver { public: LinuxSystemDriver(); ~LinuxSystemDriver() override; + + static std::unique_ptr get_default_driver(); }; } // namespace Nova diff --git a/engine/src/platform/system.cpp b/engine/src/platform/system.cpp index 7cb334d..d77ae3a 100644 --- a/engine/src/platform/system.cpp +++ b/engine/src/platform/system.cpp @@ -4,12 +4,17 @@ * SPDX-License-Identifier: BSD-3-Clause */ +#ifdef NOVA_WINDOWS + #include "drivers/windows/system_driver.h" +#endif +#ifdef NOVA_LINUX + #include "drivers/linux/system_driver.h" +#endif + #include #include -#include "drivers/linux/wayland/system_driver.h" -#include "drivers/linux/x11/system_driver.h" -#include "drivers/windows/system_driver.h" +#include using namespace Nova; @@ -19,17 +24,12 @@ void System::init() { NOVA_AUTO_TRACE(); NOVA_ASSERT(!s_driver); -#ifdef WIN32 +#ifdef NOVA_WINDOWS s_driver = std::make_unique(); +#elif NOVA_LINUX + s_driver = LinuxSystemDriver::get_default_driver(); #else - if (std::getenv("WAYLAND_DISPLAY")) { - s_driver = std::make_unique(); - } else if (std::getenv("DISPLAY")) { - s_driver = std::make_unique(); - } else { - NOVA_ERROR("Unsupported windowing system"); - s_driver = std::make_unique(); - } + throw std::runtime_error("Unsupported platform"); #endif } diff --git a/engine/src/render/renderer.cpp b/engine/src/render/renderer.cpp index 780bc16..485eefe 100644 --- a/engine/src/render/renderer.cpp +++ b/engine/src/render/renderer.cpp @@ -4,13 +4,15 @@ * SPDX-License-Identifier: BSD-3-Clause */ +#ifdef NOVA_VULKAN + #include "drivers/vulkan/render_driver.h" +#endif + #include #include #include -#include "drivers/vulkan/render_driver.h" - using namespace Nova; static std::unique_ptr s_driver; @@ -18,13 +20,15 @@ static std::unique_ptr s_driver; void Renderer::init(const RenderAPI api) { NOVA_AUTO_TRACE(); NOVA_ASSERT(!s_driver); + switch (api) { +#ifdef NOVA_VULKAN case RenderAPI::VULKAN: s_driver = std::make_unique(); break; +#endif default: - NOVA_ERROR("Unsupported render API"); - break; + throw std::runtime_error("Unsupported render API"); } }