Compare commits
1 Commits
v2
...
078d866c8a
| Author | SHA1 | Date | |
|---|---|---|---|
|
078d866c8a
|
@@ -4,104 +4,60 @@
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE INTERNAL "")
|
||||
|
||||
project(nova VERSION 0.0.1)
|
||||
project(nova)
|
||||
enable_language(CXX)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 23)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
|
||||
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
||||
|
||||
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
|
||||
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build (Debug, Release, RelWithDebInfo, MinSizeRel)" FORCE)
|
||||
endif()
|
||||
|
||||
option(BUILD_SHARED_LIBS "Build using shared libraries" ON)
|
||||
|
||||
set(NOVA_SANITIZERS "" CACHE STRING "Sanitizers to enable (address, undefined, leak)")
|
||||
set(NOVA_WERROR OFF CACHE BOOL "Treat compiler warnings as errors")
|
||||
set(NOVA_LIBRARY_INSTALL OFF CACHE BOOL "Enable library installation targets")
|
||||
|
||||
# set(NOVA_BACKEND_DX12 ON CACHE BOOL "Enable DX12 backend")
|
||||
# set(NOVA_BACKEND_METAL ON CACHE BOOL "Enable Metal backend")
|
||||
set(NOVA_BACKEND_VULKAN ON CACHE BOOL "Enable Vulkan backend")
|
||||
# set(NOVA_BACKEND_WEBGPU ON CACHE BOOL "Enable WebGPU backend")
|
||||
|
||||
set(NOVA_USE_VOLK ON CACHE BOOL "Use volk for Vulkan function loading")
|
||||
|
||||
add_compile_definitions(
|
||||
NOVA_VERSION_MAJOR=${PROJECT_VERSION_MAJOR}
|
||||
NOVA_VERSION_MINOR=${PROJECT_VERSION_MINOR}
|
||||
NOVA_VERSION_PATCH=${PROJECT_VERSION_PATCH}
|
||||
)
|
||||
|
||||
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
|
||||
add_compile_options(
|
||||
/W4
|
||||
/permissive-
|
||||
/EHsc
|
||||
$<$<BOOL:${NOVA_WERROR}>:/WX>
|
||||
)
|
||||
|
||||
if (NOVA_SANITIZERS)
|
||||
string(REPLACE "," ";" SANITIZERS ${NOVA_SANITIZERS})
|
||||
foreach(sanitizer IN LISTS SANITIZERS)
|
||||
add_compile_options(/fsanitize=${sanitizer})
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
add_compile_definitions(
|
||||
NOVA_COMPILER_MSVC
|
||||
_CRT_SECURE_NO_WARNINGS
|
||||
_CRT_NONSTDC_NO_WARNINGS
|
||||
)
|
||||
elseif (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
|
||||
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
|
||||
add_compile_options(
|
||||
-Wall
|
||||
-Wextra
|
||||
-Wpedantic
|
||||
-Wshadow
|
||||
-Wold-style-cast
|
||||
$<$<BOOL:${NOVA_WERROR}>:-Werror>
|
||||
)
|
||||
|
||||
if (NOVA_SANITIZERS)
|
||||
add_compile_options(-fsanitize=${NOVA_SANITIZERS})
|
||||
add_link_options(-fsanitize=${NOVA_SANITIZERS})
|
||||
endif()
|
||||
|
||||
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||||
add_compile_definitions(NOVA_COMPILER_GCC)
|
||||
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
|
||||
add_compile_definitions(NOVA_COMPILER_CLANG)
|
||||
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
|
||||
add_compile_definitions(
|
||||
NOVA_COMPILER_GCC
|
||||
)
|
||||
else()
|
||||
add_compile_definitions(
|
||||
NOVA_COMPILER_CLANG
|
||||
NOVA_COMPILER_APPLE_CLANG
|
||||
)
|
||||
endif()
|
||||
else()
|
||||
message(FATAL_ERROR "Unsupported compiler")
|
||||
error("Unsupported compiler")
|
||||
endif()
|
||||
|
||||
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
|
||||
if (WIN32)
|
||||
add_compile_definitions(
|
||||
NOVA_PLATFORM_WINDOWS
|
||||
NOMINMAX
|
||||
WIN32_LEAN_AND_MEAN
|
||||
_CRT_SECURE_NO_WARNINGS
|
||||
_CRT_NONSTDC_NO_WARNINGS
|
||||
)
|
||||
elseif (APPLE)
|
||||
add_compile_definitions(
|
||||
NOVA_PLATFORM_MACOS
|
||||
)
|
||||
elseif (UNIX)
|
||||
add_compile_definitions(
|
||||
NOVA_PLATFORM_LINUX
|
||||
)
|
||||
elseif (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
|
||||
add_compile_definitions(NOVA_PLATFORM_MACOS)
|
||||
elseif (CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
||||
add_compile_definitions(NOVA_PLATFORM_LINUX)
|
||||
else()
|
||||
message(FATAL_ERROR "Unsupported platform")
|
||||
endif()
|
||||
|
||||
if (NOVA_LIBRARY_INSTALL)
|
||||
include(CMakePackageConfigHelpers)
|
||||
include(GNUInstallDirs)
|
||||
error("Unsupported platform")
|
||||
endif()
|
||||
|
||||
add_subdirectory(engine)
|
||||
|
||||
@@ -15,5 +15,5 @@ target_include_directories(nova-editor
|
||||
)
|
||||
|
||||
target_link_libraries(nova-editor
|
||||
PUBLIC nova::nova
|
||||
PUBLIC nova
|
||||
)
|
||||
|
||||
@@ -4,15 +4,18 @@
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#include <nova/core/debug.hpp>
|
||||
|
||||
#include <cstdlib>
|
||||
#include <print>
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
std::println("Hello, World!");
|
||||
nova::Debug::init();
|
||||
|
||||
for (int i = 0; i < argc; i++) {
|
||||
std::println("argv[{}]: {}", i, argv[i]);
|
||||
}
|
||||
std::println("Hello, World!");
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -1,102 +1,19 @@
|
||||
# Copyright (c) 2025, Jayden Grubb <contact@jaydengrubb.com>
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
include(FetchContent)
|
||||
|
||||
set(NOVA_ENGINE_SRC
|
||||
core/debug.cpp
|
||||
graphics/context.cpp
|
||||
)
|
||||
|
||||
list(TRANSFORM NOVA_ENGINE_SRC PREPEND ${CMAKE_CURRENT_SOURCE_DIR}/src/)
|
||||
|
||||
add_library(nova ${NOVA_ENGINE_SRC})
|
||||
add_library(nova SHARED ${NOVA_ENGINE_SRC})
|
||||
|
||||
target_include_directories(nova
|
||||
PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src
|
||||
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src
|
||||
)
|
||||
|
||||
if (NOVA_BACKEND_VULKAN)
|
||||
find_package(Vulkan REQUIRED)
|
||||
|
||||
set(NOVA_VULKAN_SRC
|
||||
backends/vulkan/context.cpp
|
||||
backends/vulkan/device.cpp
|
||||
target_compile_definitions(nova
|
||||
PRIVATE NOVA_EXPORT_SYMBOLS
|
||||
)
|
||||
|
||||
list(TRANSFORM NOVA_VULKAN_SRC PREPEND ${CMAKE_CURRENT_SOURCE_DIR}/src/)
|
||||
|
||||
target_sources(nova PRIVATE ${NOVA_VULKAN_SRC})
|
||||
target_compile_definitions(nova PRIVATE NOVA_BACKEND_VULKAN)
|
||||
target_include_directories(nova PRIVATE ${Vulkan_INCLUDE_DIRS})
|
||||
|
||||
if (NOVA_USE_VOLK)
|
||||
FetchContent_Declare(
|
||||
volk
|
||||
GIT_REPOSITORY https://github.com/zeux/volk.git
|
||||
GIT_TAG f30088b3f4160810b53e19258dd2f7395e5f0ba3 # 1.4.328.1
|
||||
)
|
||||
FetchContent_MakeAvailable(volk)
|
||||
|
||||
target_compile_definitions(nova PRIVATE NOVA_USE_VOLK)
|
||||
target_include_directories(nova PRIVATE ${volk_INCLUDE_DIRS})
|
||||
target_link_libraries(nova PRIVATE volk::volk)
|
||||
else()
|
||||
target_link_libraries(nova PRIVATE Vulkan::Vulkan)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
set_target_properties(nova PROPERTIES
|
||||
DEFINE_SYMBOL NOVA_EXPORT_SYMBOLS
|
||||
VERSION ${PROJECT_VERSION}
|
||||
SOVERSION ${PROJECT_VERSION_MAJOR}
|
||||
)
|
||||
|
||||
add_library(nova::nova ALIAS nova)
|
||||
|
||||
if (NOVA_LIBRARY_INSTALL)
|
||||
configure_package_config_file(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/cmake/nova-config.cmake.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/nova-config.cmake
|
||||
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/nova
|
||||
)
|
||||
|
||||
write_basic_package_version_file(
|
||||
${CMAKE_CURRENT_BINARY_DIR}/nova-config-version.cmake
|
||||
VERSION ${PROJECT_VERSION}
|
||||
COMPATIBILITY SameMajorVersion
|
||||
)
|
||||
|
||||
install(
|
||||
TARGETS nova
|
||||
EXPORT nova-targets
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
||||
)
|
||||
|
||||
install(
|
||||
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/nova
|
||||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
||||
FILES_MATCHING PATTERN "*.hpp"
|
||||
)
|
||||
|
||||
install(
|
||||
EXPORT nova-targets
|
||||
FILE nova-targets.cmake
|
||||
NAMESPACE nova::
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/nova
|
||||
)
|
||||
|
||||
install(
|
||||
FILES
|
||||
${CMAKE_CURRENT_BINARY_DIR}/nova-config.cmake
|
||||
${CMAKE_CURRENT_BINARY_DIR}/nova-config-version.cmake
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/nova
|
||||
)
|
||||
endif()
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
@PACKAGE_INIT@
|
||||
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/nova-targets.cmake")
|
||||
|
||||
check_required_components(nova)
|
||||
@@ -15,14 +15,13 @@
|
||||
#else
|
||||
#define NOVA_API __declspec(dllimport)
|
||||
#endif
|
||||
#elif defined(NOVA_PLATFORM_MACOS) || defined(NOVA_PLATFORM_LINUX)
|
||||
#elif defined(NOVA_PLATFORM_LINUX) || defined(NOVA_PLATFORM_MACOS)
|
||||
#if defined(NOVA_EXPORT_SYMBOLS)
|
||||
#define NOVA_API __attribute__((visibility("default")))
|
||||
#else
|
||||
#define NOVA_API
|
||||
#endif
|
||||
#else
|
||||
#warning "NOVA_API is not defined for this platform"
|
||||
#define NOVA_API
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -5,3 +5,17 @@
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <nova/core/api.hpp>
|
||||
|
||||
namespace nova::core {
|
||||
|
||||
struct NOVA_API Debug {
|
||||
static void init();
|
||||
};
|
||||
|
||||
} // namespace nova::core
|
||||
|
||||
namespace nova {
|
||||
using namespace core;
|
||||
};
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2025, Jayden Grubb <contact@jaydengrubb.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
namespace nova::types {
|
||||
|
||||
using u8 = uint8_t;
|
||||
using u16 = uint16_t;
|
||||
using u32 = uint32_t;
|
||||
using u64 = uint64_t;
|
||||
using usize = size_t;
|
||||
using uptr = uintptr_t;
|
||||
using umax = uintmax_t;
|
||||
|
||||
using i8 = int8_t;
|
||||
using i16 = int16_t;
|
||||
using i32 = int32_t;
|
||||
using i64 = int64_t;
|
||||
using isize = ptrdiff_t;
|
||||
using iptr = intptr_t;
|
||||
using imax = intmax_t;
|
||||
|
||||
using f32 = float;
|
||||
using f64 = double;
|
||||
|
||||
} // namespace nova::types
|
||||
|
||||
using namespace nova::types;
|
||||
@@ -1,38 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2025, Jayden Grubb <contact@jaydengrubb.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <nova/core/api.hpp>
|
||||
#include <nova/core/types.hpp>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
namespace nova::gfx {
|
||||
|
||||
class IDevice;
|
||||
|
||||
enum class API {
|
||||
UNDEFINED,
|
||||
VULKAN,
|
||||
};
|
||||
|
||||
class NOVA_API IContext {
|
||||
public:
|
||||
static std::unique_ptr<IContext> create(API api);
|
||||
virtual ~IContext() = default;
|
||||
|
||||
virtual API get_api() const = 0;
|
||||
virtual std::string get_api_name() const = 0;
|
||||
|
||||
virtual u32 get_api_version() const = 0;
|
||||
virtual std::string get_api_version_string() const = 0;
|
||||
|
||||
virtual std::unique_ptr<IDevice> create_device() = 0;
|
||||
};
|
||||
|
||||
} // namespace nova::gfx
|
||||
@@ -1,16 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2025, Jayden Grubb <contact@jaydengrubb.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <nova/core/api.hpp>
|
||||
#include <nova/core/types.hpp>
|
||||
|
||||
namespace nova::gfx {
|
||||
|
||||
class NOVA_API IDevice {};
|
||||
|
||||
} // namespace nova::gfx
|
||||
@@ -1,19 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2025, Jayden Grubb <contact@jaydengrubb.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace Nova::Utils {
|
||||
|
||||
template<typename... Ts>
|
||||
struct Overloaded : Ts... {
|
||||
using Ts::operator()...;
|
||||
};
|
||||
|
||||
template<typename... Ts>
|
||||
Overloaded(Ts...) -> Overloaded<Ts...>;
|
||||
|
||||
} // namespace Nova::Utils
|
||||
@@ -1,57 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2025, Jayden Grubb <contact@jaydengrubb.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#if defined(NOVA_USE_VOLK)
|
||||
#include <volk.h>
|
||||
#endif
|
||||
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
#include <format>
|
||||
|
||||
#include "backends/vulkan/context.hpp"
|
||||
#include "backends/vulkan/device.hpp"
|
||||
|
||||
namespace nova::gfx {
|
||||
|
||||
VulkanContext::VulkanContext() {
|
||||
#if defined(NOVA_USE_VOLK)
|
||||
if (volkInitialize() != VK_SUCCESS) {
|
||||
throw std::runtime_error("Failed to initialize volk");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
API VulkanContext::get_api() const {
|
||||
return API::VULKAN;
|
||||
}
|
||||
|
||||
std::string VulkanContext::get_api_name() const {
|
||||
return "Vulkan";
|
||||
}
|
||||
|
||||
u32 VulkanContext::get_api_version() const {
|
||||
u32 version;
|
||||
vkEnumerateInstanceVersion(&version);
|
||||
return version;
|
||||
}
|
||||
|
||||
std::string VulkanContext::get_api_version_string() const {
|
||||
const u32 version = get_api_version();
|
||||
return std::format(
|
||||
"{}.{}.{}-{}",
|
||||
VK_API_VERSION_MAJOR(version),
|
||||
VK_API_VERSION_MINOR(version),
|
||||
VK_API_VERSION_PATCH(version),
|
||||
VK_API_VERSION_VARIANT(version)
|
||||
);
|
||||
}
|
||||
|
||||
std::unique_ptr<IDevice> VulkanContext::create_device() {
|
||||
return std::make_unique<VulkanDevice>();
|
||||
}
|
||||
|
||||
} // namespace nova::gfx
|
||||
@@ -1,31 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2025, Jayden Grubb <contact@jaydengrubb.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <nova/graphics/context.hpp>
|
||||
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
namespace nova::gfx {
|
||||
|
||||
class VulkanContext final : public IContext {
|
||||
public:
|
||||
VulkanContext();
|
||||
|
||||
API get_api() const override;
|
||||
std::string get_api_name() const override;
|
||||
|
||||
u32 get_api_version() const override;
|
||||
std::string get_api_version_string() const override;
|
||||
|
||||
std::unique_ptr<IDevice> create_device() override;
|
||||
|
||||
private:
|
||||
VkInstance m_instance = VK_NULL_HANDLE;
|
||||
};
|
||||
|
||||
} // namespace nova::gfx
|
||||
@@ -1,15 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2025, Jayden Grubb <contact@jaydengrubb.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
#include "backends/vulkan/device.hpp"
|
||||
|
||||
namespace nova::gfx {
|
||||
|
||||
// TODO
|
||||
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2025, Jayden Grubb <contact@jaydengrubb.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <nova/graphics/device.hpp>
|
||||
|
||||
namespace nova::gfx {
|
||||
|
||||
class VulkanDevice final : public IDevice {
|
||||
public:
|
||||
// TODO
|
||||
};
|
||||
|
||||
} // namespace nova::gfx
|
||||
@@ -5,3 +5,14 @@
|
||||
*/
|
||||
|
||||
#include <nova/core/debug.hpp>
|
||||
|
||||
#include <print>
|
||||
|
||||
namespace nova::core {
|
||||
|
||||
void Debug::init() {
|
||||
std::println("Debug::init()");
|
||||
return;
|
||||
}
|
||||
|
||||
} // namespace nova::core
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2025, Jayden Grubb <contact@jaydengrubb.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#include <nova/graphics/context.hpp>
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
#if defined(NOVA_BACKEND_VULKAN)
|
||||
#include "backends/vulkan/context.hpp"
|
||||
#endif
|
||||
|
||||
namespace nova::gfx {
|
||||
|
||||
std::unique_ptr<IContext> IContext::create(API p_api) {
|
||||
switch (p_api) {
|
||||
#if defined(NOVA_BACKEND_VULKAN)
|
||||
case API::VULKAN:
|
||||
return std::make_unique<VulkanContext>();
|
||||
#endif
|
||||
default:
|
||||
throw std::runtime_error("Unsupported graphics API");
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace nova::gfx
|
||||
Reference in New Issue
Block a user