-
Notifications
You must be signed in to change notification settings - Fork 14
C++ modules project directory structure #1
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
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
fc732f6
Fix URL
DaveTheEggman e34079b
Move logos to dedicated directory to keep root clean (#5)
JoltedJon d63a664
initial commit of c++ modules dir structure
OldDev78 40fa968
remove redundant CMake parameter
OldDev78 73ee60c
check compiler befor setting SIMD arguments
OldDev78 0fdaae3
comment typo, declare preprocessor macro in Debug build
OldDev78 5b42730
fix core.math bugs
OldDev78 0fe0ff6
noexcept consistency
OldDev78 b98d295
use PROJECT_SOURCE_DIR instead of CMAKE_SOURCE_DIR
OldDev78 1a041a2
add one more static assert for Vector4
OldDev78 b41808c
allow shared c++ libraries
OldDev78 301efa8
move source code down to engine/native
OldDev78 bbd8d17
Update cmake/Compiler.cmake
OldDev78 795d9b9
improve CMake scripts consistency
OldDev78 24dc8b5
trivially constructible does not imply zero-constructible
OldDev78 801ea95
Vector4: fail build on ARM64 NEON until we implement it
OldDev78 0696b44
prevent UB in math abs()
OldDev78 306a310
simplify assume/unreachable macros
OldDev78 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| .vscode/ | ||
| .idea/ | ||
|
|
||
| bits/ | ||
| cmake-build-*/ | ||
| bin/ | ||
| build/ | ||
|
|
||
| CMakeUserPresets.json |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| set(GRAPHVIZ_GRAPH_NAME "Draconic Engine dependency graph") | ||
| set(GRAPHVIZ_GRAPH_HEADER "node [ fontsize = \"10\" ];") | ||
| set(GRAPHVIZ_EXECUTABLES FALSE) | ||
| set(GRAPHVIZ_EXTERNAL_LIBS FALSE) | ||
| set(GRAPHVIZ_IGNORE_TARGETS "CMAKE_.*;test_.*|.*_test$") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| cmake_minimum_required(VERSION 4.2) | ||
| #4.0: set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD "a9e1cf81-9932-4810-974b-6eccaf14e457") | ||
| #4.2: set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD "d0edc3af-4c50-42ea-a356-e2862fe7a444") | ||
| project(DraconicEngine LANGUAGES C CXX) | ||
|
|
||
| list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") | ||
|
|
||
| include(CTest) | ||
|
|
||
| add_subdirectory(engine/native) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| { | ||
| "version": 10, | ||
| "cmakeMinimumRequired": { | ||
| "major": 4, | ||
| "minor": 0, | ||
| "patch": 3 | ||
| }, | ||
| "configurePresets": [ | ||
| { | ||
| "name": "default", | ||
| "hidden": true, | ||
| "displayName": "Default Config", | ||
| "description": "Base configuration", | ||
| "generator": "Ninja", | ||
| "graphviz": "graph/deps.dot", | ||
| "warnings": { | ||
| "unusedCli": false, | ||
| "dev": false | ||
| }, | ||
| "cacheVariables": { | ||
| "CMAKE_EXPERIMENTAL_CXX_IMPORT_STD": "d0edc3af-4c50-42ea-a356-e2862fe7a444", | ||
| "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" | ||
| } | ||
| }, | ||
| { | ||
| "name": "release", | ||
| "inherits": "default", | ||
| "displayName": "Release", | ||
| "description": "Release configuration, including C# support", | ||
|
Arctis-Fireblight marked this conversation as resolved.
|
||
| "binaryDir": "${sourceDir}/build/release", | ||
| "cacheVariables": { | ||
| "CMAKE_BUILD_TYPE": "Release" | ||
| } | ||
| }, | ||
| { | ||
| "name": "debug", | ||
| "inherits": "default", | ||
| "displayName": "Debug", | ||
| "description": "Debug configuration, including C# support", | ||
| "binaryDir": "${sourceDir}/build/debug", | ||
| "cacheVariables": { | ||
| "CMAKE_BUILD_TYPE": "Debug" | ||
| } | ||
| } | ||
| ] | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes
File renamed without changes
File renamed without changes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| include_guard(GLOBAL) | ||
|
|
||
| include(CheckIPOSupported) | ||
| check_ipo_supported(RESULT IPO_SUPPORTED OUTPUT ERROR) | ||
|
|
||
| if (CMAKE_BUILD_TYPE STREQUAL "Release") | ||
| if(IPO_SUPPORTED) | ||
| message(STATUS "IPO / LTO enabled") | ||
| add_link_options(-flto) | ||
| else() | ||
| message(STATUS "IPO / LTO not supported: <${ERROR}>") | ||
| endif() | ||
| else() | ||
| message(STATUS "IPO / LTO disabled") | ||
| add_compile_definitions(DEBUG) | ||
| endif() | ||
|
Arctis-Fireblight marked this conversation as resolved.
|
||
|
|
||
| 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 | ||
| add_compile_options(-mavx2 -mfma) | ||
| endif() | ||
| endif() | ||
|
OldDev78 marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| include_guard(GLOBAL) | ||
|
|
||
| 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") | ||
| 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) | ||
| "" # tags for single values | ||
| "" # tags for lists | ||
| "${ARGN}" | ||
| ) | ||
|
|
||
| set(LIB_PATH ${ARGV0}) | ||
|
|
||
| if (NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${LIB_PATH}") | ||
| message(FATAL_ERROR "Library directory ${LIB_PATH} not found") | ||
| endif() | ||
|
|
||
| set(LIB_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${LIB_PATH}") | ||
|
|
||
| if (EXISTS "${LIB_DIR}/CMakeLists.txt") # allow recursion | ||
| add_subdirectory(${LIB_DIR}) | ||
| endif() | ||
|
|
||
| string(MAKE_C_IDENTIFIER ${LIB_PATH} LIB_TARGET) | ||
| file(GLOB CPP_MODULE_FILES CONFIGURE_DEPENDS "${LIB_PATH}/*.cppm") | ||
| file(GLOB CPP_UNIT_TESTS CONFIGURE_DEPENDS "${LIB_PATH}/*.test.cpp") | ||
| file(GLOB CPP_SRC_FILES CONFIGURE_DEPENDS "${LIB_PATH}/*.cpp") | ||
| if (CPP_UNIT_TESTS) | ||
| list(REMOVE_ITEM CPP_SRC_FILES ${CPP_UNIT_TESTS}) | ||
| endif() | ||
|
|
||
| if (MOD_LIB_SHARED) | ||
| message(STATUS "Adding shared modules library ${LIB_TARGET}") | ||
| add_library(${LIB_TARGET} SHARED) | ||
| else() | ||
| message(STATUS "Adding static modules library ${LIB_TARGET}") | ||
| add_library(${LIB_TARGET} STATIC) | ||
| endif() | ||
| target_compile_features(${LIB_TARGET} PUBLIC cxx_std_23) | ||
| target_include_directories(${LIB_TARGET} PUBLIC ${NATIVE_SOURCE_DIR}) | ||
|
|
||
| target_sources(${LIB_TARGET} | ||
| PUBLIC | ||
| FILE_SET CXX_MODULES | ||
| BASE_DIRS ${LIB_DIR} | ||
| FILES ${CPP_MODULE_FILES} | ||
| ) | ||
|
|
||
| target_sources(${LIB_TARGET} PRIVATE ${CPP_SRC_FILES}) | ||
|
|
||
| if(CMAKE_TESTING_ENABLED) | ||
| foreach(UNIT_TEST_FILE ${CPP_UNIT_TESTS}) | ||
| string(REPLACE "${LIB_DIR}/" "" UNIT_TEST_TARGET "${UNIT_TEST_FILE}") | ||
| string(REPLACE ".test.cpp" "_test" UNIT_TEST_TARGET ${UNIT_TEST_TARGET}) | ||
| string(MAKE_C_IDENTIFIER ${UNIT_TEST_TARGET} UNIT_TEST_TARGET) | ||
| if (NOT UNIT_TEST_TARGET MATCHES ".*${LIB_TARGET}.*") | ||
| string(PREPEND UNIT_TEST_TARGET "${LIB_TARGET}_") | ||
| endif() | ||
| add_executable(${UNIT_TEST_TARGET} ${UNIT_TEST_FILE}) | ||
| target_compile_features(${UNIT_TEST_TARGET} PUBLIC cxx_std_23) | ||
| target_link_libraries(${UNIT_TEST_TARGET} PRIVATE boost_ut_main ${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() | ||
| endif() | ||
|
|
||
| endfunction() | ||
|
|
||
| function(target_link_modules) | ||
| cmake_parse_arguments( | ||
| MOD_LINK # prefix for all variables | ||
| "" # tags for flags (only defined ones will be true) | ||
| "" # tags for single values | ||
| "PRIVATE;PUBLIC" # tags for lists | ||
| "${ARGN}" | ||
| ) | ||
|
|
||
| if (MOD_LINK_PUBLIC) | ||
| foreach(NAME ${MOD_LINK_PUBLIC}) | ||
| set(DIR "${CMAKE_CURRENT_SOURCE_DIR}/${NAME}") | ||
| string(MAKE_C_IDENTIFIER ${NAME} TARGET) | ||
| target_link_libraries(${ARGV0} PUBLIC ${TARGET}) | ||
| endforeach() | ||
| endif() | ||
|
|
||
| if (MOD_LINK_PRIVATE) | ||
| foreach(NAME ${MOD_LINK_PRIVATE}) | ||
| set(DIR "${CMAKE_CURRENT_SOURCE_DIR}/${NAME}") | ||
| string(MAKE_C_IDENTIFIER ${NAME} TARGET) | ||
| target_link_libraries(${ARGV0} PRIVATE ${TARGET}) | ||
| endforeach() | ||
| endif() | ||
|
|
||
| endfunction() |
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| include(Compiler) | ||
| include(Modules) | ||
|
|
||
| add_modules_library(core SHARED) | ||
| target_link_libraries(core PUBLIC definitions math) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| add_modules_library(definitions) | ||
| add_modules_library(math) | ||
| target_link_libraries(math PUBLIC definitions) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| export module core; | ||
| export import core.defs; | ||
| export import core.math; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| 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> | ||
| concept arithmetic = std::is_arithmetic_v<T>; | ||
|
|
||
| template <typename T> | ||
| concept trivial = std::is_trivial_v<T>; | ||
|
|
||
| // Whether the default value of a type is just all-0 bytes. | ||
| // This can most commonly be exploited by using memset for these types instead of loop-construct. | ||
| // Must be explicitly specialized to mark a type as such. | ||
| template <typename T> | ||
| struct is_zero_constructible : std::false_type {}; | ||
|
|
||
| template <typename T> | ||
| constexpr bool is_zero_constructible_v = is_zero_constructible<T>::value; | ||
|
|
||
| template <typename T> | ||
| concept zero_constructible = is_zero_constructible_v<T>; | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| // Limit the depth of recursive algorithms when dealing with Array/Dictionary | ||
| constexpr int MAX_RECURSION = 100; | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| export module core.version; | ||
| export import std; | ||
| import std.compat; | ||
|
|
||
| export namespace draco { | ||
|
|
||
| struct Version { | ||
| uint16_t major; | ||
| uint16_t minor; | ||
| uint16_t patch; | ||
| }; | ||
|
|
||
| constexpr Version VERSION { .major = 2026, .minor = 0, .patch = 0 }; | ||
| } | ||
|
|
||
| export namespace std { | ||
| template<> struct formatter<draco::Version> { | ||
| constexpr auto parse(std::format_parse_context& ctx) { | ||
| return ctx.begin(); // Accept any format spec (or parse custom ones) | ||
| } | ||
|
|
||
| auto format(const draco::Version& v, std::format_context& ctx) const { | ||
| return std::format_to(ctx.out(), "{}.{}.{}", v.major, v.minor, v.patch); | ||
| } | ||
| }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| export module core.math.constants; | ||
| import std; | ||
|
|
||
| export namespace draco::math { | ||
| 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 LN2 = std::numbers::ln2_v<double>; | ||
| constexpr double LN10 = std::numbers::ln10_v<double>; | ||
| constexpr double PI = std::numbers::pi_v<double>; | ||
| constexpr double TAU = 2. * PI; | ||
| constexpr double E = std::numbers::e_v<double>; | ||
| constexpr double INF = std::numeric_limits<double>::infinity(); | ||
| 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()); | ||
|
|
||
| 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>; | ||
|
|
||
| template<std::floating_point T> constexpr T CMP_NORMALIZE_TOLERANCE = T{0.000001}; | ||
| template<std::floating_point T> constexpr T CMP_POINT_IN_PLANE_EPSILON = T{0.00001}; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.