Initial commit

This commit is contained in:
PoliEcho
2025-02-03 21:25:04 +01:00
committed by GitHub
commit 65af5ad2f9
1909 changed files with 14571 additions and 0 deletions
+22
View File
@@ -0,0 +1,22 @@
# SPDX-License-Identifier: Unlicense
# See: https://crascit.com/2016/04/09/using-ccache-with-cmake/
find_program( CCACHE_PROGRAM ccache )
if ( CCACHE_PROGRAM )
# get version information
execute_process(
COMMAND "${CCACHE_PROGRAM}" --version
OUTPUT_VARIABLE CCACHE_VERSION
)
string( REGEX MATCH "[^\r\n]*" CCACHE_VERSION ${CCACHE_VERSION} )
message( STATUS "Using ccache: ${CCACHE_PROGRAM} (${CCACHE_VERSION})" )
# Turn on ccache for all targets
set( CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_PROGRAM}" )
set( CMAKE_C_COMPILER_LAUNCHER "${CCACHE_PROGRAM}" )
unset( CCACHE_VERSION )
endif()
+31
View File
@@ -0,0 +1,31 @@
# SPDX-License-Identifier: Unlicense
find_program(CLANG_FORMAT_PROGRAM NAMES clang-format)
if (CLANG_FORMAT_PROGRAM)
execute_process(
COMMAND "${CLANG_FORMAT_PROGRAM}" --version
OUTPUT_VARIABLE CLANG_FORMAT_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
)
message("Using clang-format: ${CLANG_FORMAT_PROGRAM} (${CLANG_FORMAT_VERSION})")
file(GLOB_RECURSE
format_src_list
RELATIVE
"${CMAKE_CURRENT_SOURCE_DIR}"
"src/*.[hc]"
"src/*.[hc]pp"
)
foreach(_src_file ${format_src_list})
message(" formatting => ${_src_file}")
execute_process(
COMMAND "${CLANG_FORMAT_PROGRAM}" --style=file -i "${_src_file}"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
)
endforeach()
unset(CLANG_FORMAT_VERSION)
endif()
+111
View File
@@ -0,0 +1,111 @@
# Creates a custom "graphviz" target that outputs useful information
# about the project's (and sub target) lib deps/linkage relationships
function(run_active_cmake_diagnostics)
# enabled with -D DEPENDENCY_DIAGNOSTICS=ON
if(DEPENDENCY_DIAGNOSTICS MATCHES ON)
# prints a dependency hierarchy for all targets in project
set_property(GLOBAL PROPERTY GLOBAL_DEPENDS_DEBUG_MODE ON)
endif()
# enabled with -D GRAPHVIZ_OUTPUT=ON
if(GRAPHVIZ_OUTPUT MATCHES ON)
# Outputs graphviz dot files and generates png images showing dependency
# relationships for top level project and all targets it contains.
# All files will be generated in src/build/graphviz_output by default.
#
# Note: png image graph generation requires graphviz to be installed
include(${CMAKE_SOURCE_DIR}/CMakeGraphVizOptions.cmake)
add_custom_target(graphviz ALL
# TODO: wipe out ${CMAKE_BINARY_DIR}/graphviz_output dir here
COMMAND ${CMAKE_COMMAND} "--graphviz=${CMAKE_BINARY_DIR}/graphviz_output/${PROJECT_NAME}.dot" .
COMMAND for dot_file in \$$\(find "${CMAKE_BINARY_DIR}/graphviz_output/*.dot*" ! -name \"*.png\" \)\; do echo \"Generating \$\${dot_file}.png\" && dot -Tpng \"\$$dot_file\" -o \"\$$dot_file.png\" \; done;
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
)
endif()
endfunction(run_active_cmake_diagnostics)
# function to output all CMAKE variables along with their
# values using a case insentive regex match
#
# examples:
# 1. print all cmake variables:
# > dump_cmake_variables(".*")
# 2. print all boolt cmake variables:
# > dump_cmake_variables("^boost.*")
function(dump_cmake_variables)
get_cmake_property(_vars VARIABLES)
list(SORT _vars)
foreach(_var ${_vars})
if(ARGV0)
unset(MATCHED)
# case insenstitive match
string(TOLOWER "${ARGV0}" ARGV0_lower)
string(TOLOWER "${_var}" _var_lower)
string(REGEX MATCH ${ARGV0_lower} MATCHED ${_var_lower})
if(NOT MATCHED)
continue()
endif()
endif()
set(_value ${${_var}})
list(LENGTH _value _val_list_len)
if(_val_list_len GREATER 1)
message(DEBUG " [${_var}] =>")
foreach(_val ${_value})
message(DEBUG " - ${_val}")
endforeach()
else()
message(DEBUG " [${_var}] => ${_value}")
endif()
endforeach()
endfunction()
# prints a collection of useful C++ project configuration values
function(print_project_variables)
message(DEBUG "")
message(DEBUG "DEBUG CMake Cache Variable Dump")
message(DEBUG "=============================================")
message(DEBUG "")
dump_cmake_variables(".*")
message(NOTICE "")
message(NOTICE "Project Configuration Settigs: " ${PROJECT_NAME})
message(NOTICE "=============================================")
message(NOTICE "")
message(NOTICE "Build Configuration")
message(NOTICE " CMAKE_SYSTEM_PROCESSOR:..................: " ${CMAKE_SYSTEM_PROCESSOR})
message(NOTICE " CMAKE_HOST_SYSTEM_NAME:..................: " ${CMAKE_HOST_SYSTEM_NAME})
message(NOTICE " CMAKE_BUILD_TYPE:........................: " ${CMAKE_BUILD_TYPE})
message(NOTICE " CMAKE_CXX_COMPILER_ARCHITECTURE_ID:......: " ${CMAKE_CXX_COMPILER_ARCHITECTURE_ID})
message(NOTICE " CMAKE_CXX_STANDARD:......................: " ${CMAKE_CXX_STANDARD})
message(NOTICE " CMAKE_CXX_COMPILER_VERSION:..............: " ${CMAKE_CXX_COMPILER_VERSION})
message(NOTICE " CMAKE_CXX_SIZEOF_DATA_PTR:...............: " ${CMAKE_CXX_SIZEOF_DATA_PTR})
message(NOTICE " CMAKE_GENERATOR:.........................: " ${CMAKE_GENERATOR})
message(NOTICE " CMAKE_VERSION:...........................: " ${CMAKE_VERSION})
message(NOTICE " CMAKE_MINIMUM_REQUIRED_VERSION:..........: " ${CMAKE_MINIMUM_REQUIRED_VERSION})
message(NOTICE " VCPKG_TARGET_TRIPLET.....................: " ${VCPKG_TARGET_TRIPLET})
message(NOTICE " CMAKE_DEBUG_POSTFIX......................: " ${CMAKE_DEBUG_POSTFIX})
message(NOTICE "")
message(NOTICE "CMake Paths")
message(NOTICE " CMAKE_CURRENT_SOURCE_DIR.................: " ${CMAKE_CURRENT_SOURCE_DIR})
message(NOTICE " CMAKE_TOOLCHAIN_FILE:....................: " ${CMAKE_TOOLCHAIN_FILE})
message(NOTICE " CMAKE_SOURCE_DIR:........................: " ${CMAKE_SOURCE_DIR})
message(NOTICE " CMAKE_COMMAND:...........................: " ${CMAKE_COMMAND})
message(NOTICE " CLANG_FORMAT_PROGRAM:....................: " ${CLANG_FORMAT_PROGRAM})
message(NOTICE " SCONS_PROGRAM:...........................: " ${SCONS_PROGRAM})
message(NOTICE " CMAKE_CXX_COMPILER:......................: " ${CMAKE_CXX_COMPILER})
message(NOTICE " CMAKE_LINKER:............................: " ${CMAKE_LINKER})
message(NOTICE " CMAKE_BUILD_TOOL:........................: " ${CMAKE_BUILD_TOOL})
message(NOTICE " vcpkg_executable:........................: " ${vcpkg_executable})
message(NOTICE " godot_debug_editor_executable:...........: " ${godot_debug_editor_executable})
message(NOTICE " CMAKE_INSTALL_PREFIX:....................: " ${CMAKE_INSTALL_PREFIX})
message(NOTICE " CMAKE_BINARY_DIR:........................: " ${CMAKE_BINARY_DIR})
message(NOTICE " GDEXTENSION_LIB_PATH:....................: " ${GDEXTENSION_LIB_PATH})
message(NOTICE "")
endfunction(print_project_variables)
+207
View File
@@ -0,0 +1,207 @@
# =======================================================================
# Godot Engine submodule update/init
# =======================================================================
# confirm we found the godot engine source files.
# if the sources list is empty, the submodule probably
# hasn't been initialized or updated yet.
if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/extern/godot-engine/core")
message(NOTICE "Godot engine sources not found")
message(NOTICE "initializing/updating the engine submodule...")
# update the engine submodule to populate it with the
# code necessary to build a debug version of the editor that
# can be easily debugged along with the gdextension library
execute_process(
COMMAND git submodule update --init extern/godot-engine
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
COMMAND_ERROR_IS_FATAL ANY
)
endif()
# =======================================================================
# Godot-cpp bindings submodule update/init
# =======================================================================
# confirm we found the godot engine source files.
# if the sources list is empty, the submodule probably
# hasn't been initialized or updated yet.
if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/extern/godot-cpp/src")
message(NOTICE "godot-cpp bingings source not found")
message(NOTICE "initializing/updating the godot-cpp submodule...")
# update the c++ bingings submodule to populate it with
# the necessary source for the gdextension library
execute_process(
COMMAND git submodule update --init extern/godot-cpp
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND_ERROR_IS_FATAL ANY
)
endif()
# =======================================================================
# Godot editor/engine debug build
# =======================================================================
string(TOLOWER "${CMAKE_SYSTEM_NAME}" host_os)
set(cpu_arch "x86_64")
# define variable to be used in the engine build when specifying platform.
set(host_os_engine "${host_os}")
if (APPLE)
if ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "arm64")
set(cpu_arch "arm64")
endif()
# ${CMAKE_SYSTEM_NAME} returns Darwin, but the scons platform name will be macos
set(host_os_engine "macos")
elseif(UNIX)
# the scons build expects linuxbsd to be passed in as the platform
# when building on linux, so just append bsd to CMAKE_SYSTEM_NAME
set(host_os_engine "${host_os}bsd")
endif()
set(godot_debug_editor_executable
"${CMAKE_CURRENT_SOURCE_DIR}/extern/godot-engine/bin/godot.${host_os_engine}.editor.dev.${cpu_arch}${CMAKE_EXECUTABLE_SUFFIX}"
)
find_program(SCONS_PROGRAM NAMES scons)
if (NOT EXISTS "${SCONS_PROGRAM}")
message(FATAL_ERROR
"scons not found, it is required for the godot engine build. "
"Please install scons and confirm it is in your system PATH."
)
endif()
message(NOTICE "godot_debug_editor_executable = ${godot_debug_editor_executable}")
# if the engine/editor executable isn't found in the
# engine's submodule bin folder, invoke the scons build.
if(NOT EXISTS "${godot_debug_editor_executable}")
message(STATUS "Godot engine debug binaries not found, invoking debug build of engine...")
if (WIN32)
set(SCONS_COMMAND powershell -c)
endif()
set(SCONS_COMMAND
${SCONS_COMMAND}
${SCONS_PROGRAM}
target=editor
use_static_cpp=yes
dev_build=yes
debug_symbols=yes
optimize=none
use_lto=no
)
set(GODOT_ENGINE_CLEAN_BUILD OFF)
if (GODOT_ENGINE_CLEAN_BUILD MATCHES ON)
message(STATUS "Invoking scons clean: ${SCONS_COMMAND} --clean")
execute_process(
COMMAND "${SCONS_PROGRAM}" --clean
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/extern/godot-engine"
COMMAND_ERROR_IS_FATAL ANY
)
endif()
message(STATUS "Invoking scons build: ${SCONS_COMMAND}")
# this build should only ever need to be run once (unless the enging debug binaries
# are deleted or you want to change the build configuration/command invoked below).
execute_process(
COMMAND ${SCONS_COMMAND}
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/extern/godot-engine"
COMMAND_ERROR_IS_FATAL ANY
)
# not necessary, the temp file in here just confuses Visual Studio
file(REMOVE_RECURSE "${CMAKE_CURRENT_SOURCE_DIR}}/extern/godot-engine/.sconf_temp")
if(NOT EXISTS "${godot_debug_editor_executable}")
message(FATAL_ERROR "Couldn't find godot debug executable after scons build: ${godot_debug_editor_executable}")
endif()
endif()
# =======================================================================
# Godot C++ bindings library setup/configuration
# =======================================================================
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extern/godot-cpp)
# =======================================================================
# Godot engine library setup/configuration.
# Not necessary, just provides better support in multiple IDEs
# for engine source code browsing, intellisense, and debugging
# =======================================================================
# populate source file list for the godot engine submodule
file(GLOB_RECURSE godot_engine_sources CONFIGURE_DEPENDS
"${CMAKE_CURRENT_SOURCE_DIR}/extern/godot-engine/*.[hc]"
"${CMAKE_CURRENT_SOURCE_DIR}/extern/godot-engine/*.[hc]pp"
)
# add the engine sources as a library so intellisense works in VS and VSCode
# (and any other IDEs that support CMake in a way where the information from
# the CMake build is fed into the IDE for additional context about the code
# when browsing/debugging). even though the engine is being added as a library here,
# the EXCLUDE_FROM_ALL option will prevent it from compiling. This is done
# purely for IDE integration so it's able to properly navigate the engine
# source code using features like "go do definition", or typical tooltips.
add_library(godot_engine EXCLUDE_FROM_ALL ${godot_engine_sources})
# this is just a handful of additional include directories used by the engine.
# this isn't a complete list, I just add them as needed whenever I venture into
# code where the IDE can't find certain header files during engine source browsing.
target_include_directories(godot_engine PUBLIC
"${CMAKE_CURRENT_SOURCE_DIR}/extern/godot-engine"
"${CMAKE_CURRENT_SOURCE_DIR}/extern/godot-engine/platform/windows"
"${CMAKE_CURRENT_SOURCE_DIR}/extern/godot-engine/thirdparty/zlib"
"${CMAKE_CURRENT_SOURCE_DIR}/extern/godot-engine/thirdparty/vulkan"
"${CMAKE_CURRENT_SOURCE_DIR}/extern/godot-engine/thirdparty/vulkan/include"
"${CMAKE_CURRENT_SOURCE_DIR}/extern/godot-engine/thirdparty/vulkan/include/vulkan"
"${CMAKE_CURRENT_SOURCE_DIR}/extern/godot-engine/drivers/vulkan"
SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/extern/godot-engine/thirdparty/glad"
SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/extern/godot-engine/thirdparty/volk"
SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/extern/godot-engine/thirdparty/zstd"
SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/extern/godot-engine/thirdparty/mbedtls/include"
)
# define a bunch of the same symbol definitions
# used when by the scons engine build. These build
# flags can differen based on the engine's build for
# you system. Update as needed for your setup.
target_compile_definitions(godot_engine PUBLIC
$<$<CONFIG:Debug>:
DEBUG_ENABLED
DEBUG_METHODS_ENABLED
DEV_ENABLED
>
$<$<BOOL:UNIX>:
UNIX_ENABLED
VK_USE_PLATFORM_XLIB_KHR
>
$<$<BOOL:WIN32>:
WINDOWS_ENABLED
WASAPI_ENABLED
WINMIDI_ENABLED
TYPED_METHOD_BIND
NOMINMAX
WIN32
VK_USE_PLATFORM_WIN32_KHR
_SCRT_STARTUP_WINMAIN=1
$<$<BOOL:MSVC>:
MSVC
>
>
TOOLS_ENABLED
NO_EDITOR_SPLASH
GLAD_ENABLED
GLES3_ENABLED
GLES_OVER_GL
VULKAN_ENABLED
USE_VOLK
MINIZIP_ENABLED
BROTLI_ENABLED
ZSTD_STATIC_LINKING_ONLY
)
+1
View File
@@ -0,0 +1 @@
# TODO: implement include-what-you-use auto analysis target
+48
View File
@@ -0,0 +1,48 @@
# VCPKG submodule init/update
if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/extern/vcpkg/ports")
message(NOTICE "VCPKG package manager sources not found")
message(NOTICE "initializing/updating the vcpkg submodule...")
execute_process(
COMMAND git submodule update --init extern/vcpkg
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND_ERROR_IS_FATAL ANY
)
endif()
# =======================================================================
# VCPKG triplet definition (should enforce static linkage for all deps)
# This would typically be passed in from CMakePresets.json, but if
# the cmake configuration is invoked without using a preset this fallback
# should define a preset that prefers static linkage for 3rd party libs.
# =======================================================================
if (NOT VCPKG_TARGET_TRIPLET)
if (WIN32)
# static-md enforces static linkage to all dependencies,
# as well as dynamic linkage to the C runtime for consistency.
# if this gives you trouble change to "x64-windows-static".
set(VCPKG_TARGET_TRIPLET "x64-windows-static-md")
elseif(APPLE)
if ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "arm64")
set(VCPKG_TARGET_TRIPLET "arm64-osx")
else()
set(VCPKG_TARGET_TRIPLET "x64-osx")
endif()
elseif(UNIX)
set(VCPKG_TARGET_TRIPLET "x64-linux")
endif()
endif()
# =======================================================================
# Define VCPKG toolchain file. This would typically be passed in from
# CMakePresets.json, but if the cmake configuration is invoked without
# using a preset this fallback should detect that the path is missing.
# =======================================================================
if(NOT CMAKE_TOOLCHAIN_FILE)
set(toolchain_file_path "${CMAKE_CURRENT_SOURCE_DIR}/extern/vcpkg/scripts/buildsystems/vcpkg.cmake")
if (EXISTS "${toolchain_file_path}")
set(CMAKE_TOOLCHAIN_FILE "${toolchain_file_path}")
else()
message(WARNING "VCPKG toolchain file not found: ${toolchain_file_path}")
endif()
endif()
+31
View File
@@ -0,0 +1,31 @@
# =======================================================================
# VCPKG bootstrap / initialization.
# =======================================================================
set(vcpkg_executable "${CMAKE_CURRENT_SOURCE_DIR}/extern/vcpkg/vcpkg${CMAKE_EXECUTABLE_SUFFIX}")
if(EXISTS "${vcpkg_executable}")
message(NOTICE "Found VCPKG Executable: ${vcpkg_executable}")
else()
message(NOTICE "Could not find VCPKG Executable: ${vcpkg_executable}")
message(NOTICE "Calling VCPKG bootstrap scripts.")
if(WIN32)
execute_process(
COMMAND powershell -c "${CMAKE_CURRENT_SOURCE_DIR}/extern/vcpkg/bootstrap-vcpkg.bat"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
COMMAND_ERROR_IS_FATAL ANY
)
elseif(UNIX)
execute_process(
COMMAND bash "${CMAKE_CURRENT_SOURCE_DIR}/extern/vcpkg/bootstrap-vcpkg.sh"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
COMMAND_ERROR_IS_FATAL ANY
)
endif()
# fail out if vcpkg isn't found after setup
if(NOT EXISTS "${vcpkg_executable}")
message(FATAL_ERROR "ERROR: '${vcpkg_executable}' not found!")
endif()
endif()