Compare commits

...

3 Commits

Author SHA1 Message Date
7c1612be63 Various CMakeLists improvements 2025-11-10 19:04:08 +10:00
a32cd24417 Add Utils::Overloaded helper 2025-11-10 19:04:08 +10:00
2b5c9ac062 Add primitive types aliases 2025-11-10 19:04:08 +10:00
5 changed files with 96 additions and 21 deletions

View File

@@ -6,9 +6,19 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE INTERNAL "")
project(nova VERSION 0.0.1) project(nova VERSION 0.0.1)
enable_language(CXX) enable_language(CXX)
set(CMAKE_CXX_STANDARD 23) set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_VISIBILITY_PRESET hidden) 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()
set(NOVA_SANITIZERS "" CACHE STRING "Sanitizers to enable (address, undefined, leak)")
set(NOVA_WERROR OFF CACHE BOOL "Treat compiler warnings as errors")
add_compile_definitions( add_compile_definitions(
NOVA_VERSION_MAJOR=${PROJECT_VERSION_MAJOR} NOVA_VERSION_MAJOR=${PROJECT_VERSION_MAJOR}
@@ -21,32 +31,47 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
/W4 /W4
/permissive- /permissive-
/EHsc /EHsc
$<$<BOOL:${NOVA_WERROR}>:/WX>
) )
add_compile_definitions(
NOVA_COMPILER_MSVC if (NOVA_SANITIZERS)
) string(REPLACE "," ";" SANITIZERS ${NOVA_SANITIZERS})
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") foreach(sanitizer IN LISTS SANITIZERS)
add_compile_options(/fsanitize=${sanitizer})
endforeach()
endif()
add_compile_definitions(NOVA_COMPILER_MSVC)
elseif (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
add_compile_options( add_compile_options(
-Wall -Wall
-Wextra -Wextra
-Wpedantic -Wpedantic
-Wshadow -Wshadow
-Wold-style-cast -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") if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
add_compile_definitions( add_compile_definitions(NOVA_COMPILER_GCC)
NOVA_COMPILER_GCC elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
) add_compile_definitions(NOVA_COMPILER_CLANG)
else() elseif (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
add_compile_definitions( add_compile_definitions(
NOVA_COMPILER_CLANG NOVA_COMPILER_CLANG
NOVA_COMPILER_APPLE_CLANG
) )
endif() endif()
else() else()
error("Unsupported compiler") message(FATAL_ERROR "Unsupported compiler")
endif() endif()
if (WIN32) if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
add_compile_definitions( add_compile_definitions(
NOVA_PLATFORM_WINDOWS NOVA_PLATFORM_WINDOWS
NOMINMAX NOMINMAX
@@ -54,16 +79,12 @@ if (WIN32)
_CRT_SECURE_NO_WARNINGS _CRT_SECURE_NO_WARNINGS
_CRT_NONSTDC_NO_WARNINGS _CRT_NONSTDC_NO_WARNINGS
) )
elseif (APPLE) elseif (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
add_compile_definitions( add_compile_definitions(NOVA_PLATFORM_MACOS)
NOVA_PLATFORM_MACOS elseif (CMAKE_SYSTEM_NAME STREQUAL "Linux")
) add_compile_definitions(NOVA_PLATFORM_LINUX)
elseif (UNIX)
add_compile_definitions(
NOVA_PLATFORM_LINUX
)
else() else()
error("Unsupported platform") message(FATAL_ERROR "Unsupported platform")
endif() endif()
add_subdirectory(engine) add_subdirectory(engine)

View File

@@ -14,6 +14,6 @@ target_include_directories(nova
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src
) )
target_compile_definitions(nova set_target_properties(nova PROPERTIES
PRIVATE NOVA_EXPORT_SYMBOLS DEFINE_SYMBOL NOVA_EXPORT_SYMBOLS
) )

View File

@@ -0,0 +1,35 @@
/**
* 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;

View File

@@ -0,0 +1,19 @@
/**
* 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