Skip to content
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
13 changes: 0 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
cmake_minimum_required(VERSION 4.0)

if (CMAKE_VERSION VERSION_GREATER_EQUAL "4.3.0")
set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD "451f2fe2-a8a2-47c3-bc32-94786d8fc91b")
elseif (CMAKE_VERSION VERSION_GREATER_EQUAL "4.0.3")
set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD "d0edc3af-4c50-42ea-a356-e2862fe7a444")
elseif (CMAKE_VERSION VERSION_GREATER_EQUAL "4.0.0")
set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD "a9e1cf81-9932-4810-974b-6eccaf14e457")
endif()

find_package(Git QUIET)

if(GIT_FOUND AND EXISTS "${CMAKE_SOURCE_DIR}/.git")
Expand All @@ -25,11 +17,6 @@ endif()

project(DraconicEngine LANGUAGES C CXX)

# Only have safe global rules here
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_MODULE_STD ON)

list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")

include(CTest)
Expand Down
7 changes: 5 additions & 2 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@
"dev": false
},
"cacheVariables": {
"CMAKE_C_STANDARD": "17",
"CMAKE_C_STANDARD_REQUIRED": "ON",
"CMAKE_C_EXTENSIONS": "OFF",
"CMAKE_C_FLAGS_INIT": "-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0",
"CMAKE_CXX_STANDARD": "23",
"CMAKE_CXX_STANDARD_REQUIRED": "ON",
"CMAKE_CXX_EXTENSIONS": "OFF",
"CMAKE_CXX_MODULE_STD": "1",
"CMAKE_CXX_FLAGS_INIT": "-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0"
"CMAKE_CXX_SCAN_FOR_MODULES": "ON"
}
},
{
Expand Down
6 changes: 0 additions & 6 deletions cmake/Compiler.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@ else()
add_compile_definitions(DEBUG)
endif()

# Force Clang to use libc++
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-stdlib=libc++)
add_link_options(-stdlib=libc++)
endif()

if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
if (CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|AMD64")
# TODO: Make SIMD level configurable or detect at runtime
Expand Down
38 changes: 18 additions & 20 deletions cmake/Modules.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,22 @@ set(NATIVE_SOURCE_DIR "${PROJECT_SOURCE_DIR}/engine/native")
set(NATIVE_THIRD_PARTY_DIR "${NATIVE_SOURCE_DIR}/thirdparty")

if (BUILD_TESTING)
message(STATUS "Bootstrapping unit tests module boost.ut")
add_library(boost_ut_main "${NATIVE_THIRD_PARTY_DIR}/boost/ut_main.cpp")
set_target_properties(boost_ut_main PROPERTIES
CXX_SCAN_FOR_MODULES ON
CXX_EXTENSIONS OFF
)
target_sources(boost_ut_main
PUBLIC
FILE_SET CXX_MODULES
BASE_DIRS "${NATIVE_THIRD_PARTY_DIR}/boost"
FILES "${NATIVE_THIRD_PARTY_DIR}/boost/ut.cppm"
)
target_compile_features(boost_ut_main PUBLIC cxx_std_23)
set(DOCTEST_INCLUDE_DIR "${NATIVE_THIRD_PARTY_DIR}/doctest")
# message(STATUS "Bootstrapping unit tests module boost.ut")
# add_library(boost_ut_main "${NATIVE_THIRD_PARTY_DIR}/boost/ut_main.cpp")
# target_sources(boost_ut_main
# PUBLIC
# FILE_SET CXX_MODULES
# BASE_DIRS "${NATIVE_THIRD_PARTY_DIR}/boost"
# FILES "${NATIVE_THIRD_PARTY_DIR}/boost/ut.cppm"
# )
# target_compile_features(boost_ut_main PUBLIC cxx_std_23)
endif()

function(add_modules_library)
cmake_parse_arguments(
MOD_LIB # prefix for all variables
"STATIC;SHARED" # tags for flags (only defined ones will be true)
"STATIC;SHARED;PIC" # tags for flags (only defined ones will be true)
"" # tags for single values
"" # tags for lists
"${ARGN}"
Expand Down Expand Up @@ -57,11 +54,6 @@ function(add_modules_library)
add_library(${LIB_TARGET} STATIC)
endif()

set_target_properties(${LIB_TARGET} PROPERTIES
CXX_SCAN_FOR_MODULES ON
CXX_EXTENSIONS OFF
)

target_compile_features(${LIB_TARGET} PUBLIC cxx_std_23)
target_include_directories(${LIB_TARGET} PUBLIC ${NATIVE_SOURCE_DIR})

Expand All @@ -74,6 +66,10 @@ function(add_modules_library)

target_sources(${LIB_TARGET} PRIVATE ${CPP_SRC_FILES})

if (MOD_LIB_PIC)
set_target_properties(${LIB_TARGET} PROPERTIES POSITION_INDEPENDENT_CODE ON)
endif()

if(CMAKE_TESTING_ENABLED)
foreach(UNIT_TEST_FILE ${CPP_UNIT_TESTS})
string(REPLACE "${LIB_DIR}/" "" UNIT_TEST_TARGET "${UNIT_TEST_FILE}")
Expand All @@ -85,7 +81,9 @@ function(add_modules_library)
add_executable(${UNIT_TEST_TARGET} ${UNIT_TEST_FILE})
set_target_properties(${UNIT_TEST_TARGET} PROPERTIES CXX_SCAN_FOR_MODULES ON)
target_compile_features(${UNIT_TEST_TARGET} PUBLIC cxx_std_23)
target_link_libraries(${UNIT_TEST_TARGET} PRIVATE boost_ut_main ${LIB_TARGET})
#target_compile_options(${UNIT_TEST_TARGET} PUBLIC -fmodules-ts)
target_include_directories(${UNIT_TEST_TARGET} PUBLIC ${DOCTEST_INCLUDE_DIR})
target_link_libraries(${UNIT_TEST_TARGET} PRIVATE ${LIB_TARGET})
message(STATUS "Unit test ${UNIT_TEST_TARGET}")
add_test(NAME ${UNIT_TEST_TARGET} COMMAND ${UNIT_TEST_TARGET} --reporter junit --out "Testing/${UNIT_TEST_TARGET}.xml")
endforeach()
Expand Down
2 changes: 1 addition & 1 deletion engine/native/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
include(Compiler)
include(Modules)

add_subdirectory(thirdparty)
add_subdirectory(thirdparty SYSTEM)

add_modules_library(core SHARED)
target_link_libraries(core PUBLIC definitions math)
2 changes: 1 addition & 1 deletion engine/native/core/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
add_modules_library(definitions)
add_modules_library(definitions PIC)
add_modules_library(math)
target_link_libraries(math PUBLIC definitions)
15 changes: 6 additions & 9 deletions engine/native/core/definitions/definitions.cppm
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
module;

#include <type_traits>

export module core.defs;
export import core.version;
import std;

static_assert(__cplusplus >= 202302L, "Minimum of C++23 required.");

export namespace draco {

// Traits and Concepts

template <typename T>
template<typename T>
concept arithmetic = std::is_arithmetic_v<T>;

template <typename T>
template<typename T>
concept trivial = std::is_trivial_v<T>;

// Whether the default value of a type is just all-0 bytes.
Expand All @@ -25,8 +26,4 @@ export namespace draco {

template <typename T>
concept zero_constructible = is_zero_constructible_v<T>;

// Limit the depth of recursive algorithms when dealing with Array/Dictionary
constexpr int MAX_RECURSION = 100;

}
13 changes: 8 additions & 5 deletions engine/native/core/definitions/version.cppm
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
module;

#include <cstdint>
#include <format>

export module core.version;
export import std;
import std.compat;

export namespace draco {

struct Version {
uint16_t major;
uint16_t minor;
uint16_t patch;
std::uint16_t major;
std::uint16_t minor;
std::uint16_t patch;
};

constexpr Version VERSION { .major = 2026, .minor = 0, .patch = 0 };
Expand Down
18 changes: 14 additions & 4 deletions engine/native/core/math/constants.cppm
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
module;

#include <concepts>
#include <cstdint>
#include <limits>
#include <numbers>

export module core.math.constants;
import std;
import core.defs;

export namespace draco::math {
// Limit the depth of recursive algorithms
constexpr int MAX_RECURSIONS = 100;

constexpr double SQRT2 = std::numbers::sqrt2_v<double>;
constexpr double SQRT3 = std::numbers::sqrt3_v<double>;
constexpr double SQRT12 = 1. / SQRT2;
constexpr double SQRT13 = 1. / SQRT3;
constexpr double SQRT13 = std::numbers::inv_sqrt3_v<double>;
constexpr double LN2 = std::numbers::ln2_v<double>;
constexpr double LN10 = std::numbers::ln10_v<double>;
constexpr double PI = std::numbers::pi_v<double>;
Expand All @@ -15,8 +25,8 @@ export namespace draco::math {
constexpr double NaN = std::numeric_limits<double>::quiet_NaN();
constexpr double DB_CONVERSION_GAIN = 8.6858896380650365530225783783321;
constexpr double GAIN_CONVERSION_DB = 0.11512925464970228420089957273422;
constexpr double UINT32_MAX_D = 1. / static_cast<double>(std::numeric_limits<std::uint32_t>::max());
constexpr float UINT32_MAX_F = 1.f / static_cast<float>(std::numeric_limits<std::uint32_t>::max());
constexpr double UINT32_MAX_D = 1. / std::numeric_limits<uint32_t>::max();
constexpr float UINT32_MAX_F = 1.f / std::numeric_limits<uint32_t>::max();

template<std::floating_point T> constexpr T CMP_EPSILON = T{0.000001};
template<std::floating_point T> constexpr T CMP_EPSILON2 = CMP_EPSILON<T> * CMP_EPSILON<T>;
Expand Down
12 changes: 9 additions & 3 deletions engine/native/core/math/math.cppm
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
module;

#include <type_traits>
#include <concepts>
#include <limits>
#include <cmath>

export module core.math;
export import core.math.constants;
export import core.math.vector4;
export import core.defs;
import std;

export namespace draco::math {
template <arithmetic T>
Expand Down Expand Up @@ -43,12 +49,12 @@ export namespace draco::math {

template <std::floating_point T>
constexpr T deg_to_rad(T y) noexcept {
return y * (std::numbers::pi_v<T> / T{180.});
return y * (T{PI} / T{180.});
}

template <std::floating_point T>
constexpr T rad_to_deg(T y) noexcept {
return y * (T{180.} / std::numbers::pi_v<T>);
return y * (T{180.} / T{PI});
}

template <std::floating_point T>
Expand Down
Loading