Skip to content
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ bits/
cmake-build-*/
bin/
build/
graph/

CMakeUserPresets.json
9 changes: 9 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[submodule "engine/native/thirdparty/bx"]
path = engine/native/thirdparty/bx
url = https://github.com/bkaradzic/bx
[submodule "engine/native/thirdparty/bimg"]
path = engine/native/thirdparty/bimg
url = https://github.com/bkaradzic/bimg
[submodule "engine/native/thirdparty/bgfx"]
path = engine/native/thirdparty/bgfx
url = https://github.com/bkaradzic/bgfx
20 changes: 20 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,28 @@ 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")
message(STATUS "Updating submodules...")
execute_process(
COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
RESULT_VARIABLE GIT_SUBMOD_RESULT
)

if(NOT GIT_SUBMOD_RESULT EQUAL "0")
message(FATAL_ERROR "Failed to update submodules. Please run manually.")
endif()
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
6 changes: 6 additions & 0 deletions cmake/Compiler.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ 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
18 changes: 18 additions & 0 deletions cmake/Modules.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ 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
Expand Down Expand Up @@ -52,6 +56,12 @@ function(add_modules_library)
message(STATUS "Adding static modules library ${LIB_TARGET}")
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 @@ -73,6 +83,7 @@ function(add_modules_library)
string(PREPEND UNIT_TEST_TARGET "${LIB_TARGET}_")
endif()
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})
message(STATUS "Unit test ${UNIT_TEST_TARGET}")
Expand All @@ -82,6 +93,13 @@ function(add_modules_library)

endfunction()

function(enable_modules target)
set_target_properties(
${target} PROPERTIES
CXX_SCAN_FOR_MODULES ON
)
endfunction()

function(target_link_modules)
cmake_parse_arguments(
MOD_LINK # prefix for all variables
Expand Down
2 changes: 2 additions & 0 deletions engine/native/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
include(Compiler)
include(Modules)

add_subdirectory(thirdparty)

add_modules_library(core SHARED)
target_link_libraries(core PUBLIC definitions math)
13 changes: 13 additions & 0 deletions engine/native/thirdparty/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
set(BGFX_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
set(BGFX_BUILD_TOOLS OFF CACHE BOOL "" FORCE)
set(BGFX_INSTALL OFF CACHE BOOL "" FORCE)
set(CMAKE_CXX_SCAN_FOR_MODULES OFF)

set(BX_DIR ${CMAKE_CURRENT_SOURCE_DIR}/bx CACHE STRING "" FORCE)
set(BIMG_DIR ${CMAKE_CURRENT_SOURCE_DIR}/bimg CACHE STRING "" FORCE)
set(BGFX_DIR ${CMAKE_CURRENT_SOURCE_DIR}/bgfx CACHE STRING "" FORCE)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/cmake/bx bx-build)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/cmake/bimg bimg-build)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/cmake/bgfx bgfx-build)

target_link_libraries(bgfx PUBLIC bx bimg)
1 change: 1 addition & 0 deletions engine/native/thirdparty/bgfx
Submodule bgfx added at 8532b2
1 change: 1 addition & 0 deletions engine/native/thirdparty/bimg
Submodule bimg added at 9114b4
1 change: 1 addition & 0 deletions engine/native/thirdparty/bx
Submodule bx added at cac72f
31 changes: 31 additions & 0 deletions engine/native/thirdparty/cmake/Config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
@PACKAGE_INIT@

if(@BGFX_CMAKE_USER_SCRIPT_PRESENT@)
include("${CMAKE_CURRENT_LIST_DIR}/@BGFX_CMAKE_USER_SCRIPT_INSTALL_NAME@")
endif()
include("${CMAKE_CURRENT_LIST_DIR}/@TARGETS_EXPORT_NAME@.cmake")
get_target_property(BGFX_INCLUDE_PATH bgfx::bgfx INTERFACE_INCLUDE_DIRECTORIES)
list(GET BGFX_INCLUDE_PATH 0 BGFX_INCLUDE_PATH_1) # bgfx::bgfx exports include directory twice?
set(BGFX_SHADER_INCLUDE_PATH ${BGFX_INCLUDE_PATH_1}/bgfx)

# If cross compiling, we need a host-compatible version of shaderc to compile shaders
macro(_bgfx_crosscompile_use_host_tool TOOL_NAME)
if(NOT TARGET bgfx::${TOOL_NAME})
find_program(
${TOOL_NAME}_EXECUTABLE
NAMES bgfx-${TOOL_NAME} ${TOOL_NAME}
PATHS @BGFX_ADDITIONAL_TOOL_PATHS@ /usr/bin
)
add_executable(bgfx::${TOOL_NAME} IMPORTED)
set_target_properties(bgfx::${TOOL_NAME} PROPERTIES IMPORTED_LOCATION "${${TOOL_NAME}_EXECUTABLE}")
Comment on lines +13 to +20
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# First, let's find and read the Config.cmake.in file to see the exact code
fd -t f "Config.cmake.in" engine/native/thirdparty/cmake/

Repository: Redot-Engine/DraconicEngine

Length of output: 117


🏁 Script executed:

# Read the file to see the context around lines 13-20
cat -n engine/native/thirdparty/cmake/Config.cmake.in | head -40

Repository: Redot-Engine/DraconicEngine

Length of output: 1512


🏁 Script executed:

# Find bgfxToolUtils.cmake to see how these targets are used
fd -t f "bgfxToolUtils.cmake" engine/native/

Repository: Redot-Engine/DraconicEngine

Length of output: 121


🏁 Script executed:

# Search for references to the tool targets (geometryc, etc.) in bgfxToolUtils.cmake
rg -n "bgfx::" engine/native/thirdparty/cmake/bgfxToolUtils.cmake -A 2 -B 2

Repository: Redot-Engine/DraconicEngine

Length of output: 1498


Create host-tool targets only after find_program() succeeds.

When find_program() fails to locate a tool, it sets ${TOOL_NAME}_EXECUTABLE to *-NOTFOUND, but this macro still creates bgfx::${TOOL_NAME} and sets its IMPORTED_LOCATION to that non-existent path. This causes if(TARGET bgfx::...) guards in bgfxToolUtils.cmake to pass, deferring the failure to build time when the tool is actually invoked, making the real issue harder to diagnose. Add a check after find_program() to ensure the tool was found before creating the target.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@engine/native/thirdparty/cmake/Config.cmake.in` around lines 13 - 20, After
the find_program() call, guard creation of the imported target by verifying the
tool was actually found: check the ${TOOL_NAME}_EXECUTABLE result (e.g. ensure
it is not equal to "${TOOL_NAME}-NOTFOUND" and optionally that the path exists
with EXISTS "${${TOOL_NAME}_EXECUTABLE}") before calling
add_executable(bgfx::${TOOL_NAME} IMPORTED) and set_target_properties(...
IMPORTED_LOCATION "${${TOOL_NAME}_EXECUTABLE}"); only create the
bgfx::${TOOL_NAME} target when the check passes so missing tools don't produce
bogus IMPORTED targets.

endif()
endmacro()

_bgfx_crosscompile_use_host_tool(bin2c)
_bgfx_crosscompile_use_host_tool(texturec)
_bgfx_crosscompile_use_host_tool(shaderc)
_bgfx_crosscompile_use_host_tool(texturev)
_bgfx_crosscompile_use_host_tool(geometryv)
Comment on lines +24 to +28
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

cat -n engine/native/thirdparty/cmake/Config.cmake.in | sed -n '20,35p'

Repository: Redot-Engine/DraconicEngine

Length of output: 591


🏁 Script executed:

rg "bgfx_compile_geometry" -A 10 -B 2

Repository: Redot-Engine/DraconicEngine

Length of output: 1909


🏁 Script executed:

rg "geometryc|geometryv" --type cmake

Repository: Redot-Engine/DraconicEngine

Length of output: 3380


Replace geometryv with geometryc on line 28.

bgfx_compile_geometry() requires bgfx::geometryc (the geometry compiler tool), but line 28 currently exposes geometryv (the geometry viewer). This breaks geometry compilation in cross-compiled or installed packages.

Suggested fix
 _bgfx_crosscompile_use_host_tool(bin2c)
 _bgfx_crosscompile_use_host_tool(texturec)
 _bgfx_crosscompile_use_host_tool(shaderc)
 _bgfx_crosscompile_use_host_tool(texturev)
-_bgfx_crosscompile_use_host_tool(geometryv)
+_bgfx_crosscompile_use_host_tool(geometryc)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
_bgfx_crosscompile_use_host_tool(bin2c)
_bgfx_crosscompile_use_host_tool(texturec)
_bgfx_crosscompile_use_host_tool(shaderc)
_bgfx_crosscompile_use_host_tool(texturev)
_bgfx_crosscompile_use_host_tool(geometryv)
_bgfx_crosscompile_use_host_tool(bin2c)
_bgfx_crosscompile_use_host_tool(texturec)
_bgfx_crosscompile_use_host_tool(shaderc)
_bgfx_crosscompile_use_host_tool(texturev)
_bgfx_crosscompile_use_host_tool(geometryc)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@engine/native/thirdparty/cmake/Config.cmake.in` around lines 24 - 28, The
invocation of _bgfx_crosscompile_use_host_tool incorrectly exposes the geometry
viewer tool; change the call that currently references geometryv to geometryc so
that the geometry compiler tool (bgfx::geometryc) is used by
bgfx_compile_geometry(); update the _bgfx_crosscompile_use_host_tool(geometryv)
line to _bgfx_crosscompile_use_host_tool(geometryc) to restore correct geometry
compilation in cross-compiled/installed packages.


include("${CMAKE_CURRENT_LIST_DIR}/bgfxToolUtils.cmake")
check_required_components("@PROJECT_NAME@")
26 changes: 26 additions & 0 deletions engine/native/thirdparty/cmake/bgfx/3rdparty/dear-imgui.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# bgfx.cmake - bgfx building in cmake
# Written in 2017 by Joshua Brookover <joshua.al.brookover@gmail.com>
#
# To the extent possible under law, the author(s) have dedicated all copyright
# and related and neighboring rights to this software to the public domain
# worldwide. This software is distributed without any warranty.
#
# You should have received a copy of the CC0 Public Domain Dedication along with
# this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.

# Ensure the directory exists
if(NOT IS_DIRECTORY ${BGFX_DIR})
message(SEND_ERROR "Could not load bgfx, directory does not exist. ${BGFX_DIR}")
return()
endif()

if(NOT DEAR_IMGUI_LIBRARIES)
file(
GLOB #
DEAR_IMGUI_SOURCES #
${BGFX_DIR}/3rdparty/dear-imgui/*.cpp #
${BGFX_DIR}/3rdparty/dear-imgui/*.h #
${BGFX_DIR}/3rdparty/dear-imgui/*.inl #
)
set(DEAR_IMGUI_INCLUDE_DIR ${BGFX_DIR}/3rdparty)
endif()
64 changes: 64 additions & 0 deletions engine/native/thirdparty/cmake/bgfx/3rdparty/fcpp.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# bgfx.cmake - bgfx building in cmake
# Written in 2017 by Joshua Brookover <joshua.al.brookover@gmail.com>
#
# To the extent possible under law, the author(s) have dedicated all copyright
# and related and neighboring rights to this software to the public domain
# worldwide. This software is distributed without any warranty.
#
# You should have received a copy of the CC0 Public Domain Dedication along with
# this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.

# Ensure the directory exists
if(NOT IS_DIRECTORY ${BGFX_DIR})
message(SEND_ERROR "Could not load bgfx, directory does not exist. ${BGFX_DIR}")
return()
endif()

set(FCPP_DIR ${BGFX_DIR}/3rdparty/fcpp)

file(
GLOB
FCPP_SOURCES
${FCPP_DIR}/*.h
${FCPP_DIR}/cpp1.c
${FCPP_DIR}/cpp2.c
${FCPP_DIR}/cpp3.c
${FCPP_DIR}/cpp4.c
${FCPP_DIR}/cpp5.c
${FCPP_DIR}/cpp6.c
${FCPP_DIR}/cpp6.c
)

add_library(fcpp STATIC ${FCPP_SOURCES})

target_compile_definitions(
fcpp
PRIVATE "NINCLUDE=64" #
"NWORK=65536" #
"NBUFF=65536" #
"OLD_PREPROCESSOR=0" #
# "MSG_PREFIX=\"Preprocessor: \"" #
)

# Put in a "bgfx" folder in Visual Studio
set_target_properties(fcpp PROPERTIES FOLDER "bgfx")

target_include_directories(fcpp PUBLIC ${FCPP_DIR})

if(MSVC)
target_compile_options(
fcpp
PRIVATE
"/wd4055" # warning C4055: 'type cast': from data pointer 'void *' to function pointer 'void (__cdecl *)(char *,void *)'
"/wd4244" # warning C4244: '=': conversion from 'const flex_int32_t' to 'YY_CHAR', possible loss of data
"/wd4701" # warning C4701: potentially uninitialized local variable 'lower' used
"/wd4706" # warning C4706: assignment within conditional expression
)
else()
target_compile_options(
fcpp
PRIVATE -Wno-implicit-fallthrough #
-Wno-incompatible-pointer-types #
-Wno-parentheses-equality #
)
endif()
Loading