From 75b8b2020d93d3560f3e45e94623454a3ec62418 Mon Sep 17 00:00:00 2001 From: Honeybunch Date: Thu, 5 Sep 2024 17:15:54 -0700 Subject: [PATCH] Refactoring cmake to be a bit more structured --- .github/workflows/android.yml | 2 +- .github/workflows/ios.yml | 2 +- .github/workflows/linux.yml | 2 +- .github/workflows/macos.yml | 2 +- .github/workflows/windows.yml | 2 +- CMakeLists.txt | 680 ++---------------------------- cmake/tb_app.cmake | 191 +++++++++ cmake/tb_cooking.cmake | 212 ++++++++++ cmake/tb_packages.cmake | 54 +++ cmake/tb_platform.cmake | 62 +++ include/tb_descriptor_buffer.h | 2 +- include/tb_log.h | 2 +- include/tb_render_thread.h | 2 +- include/tb_vk_dbg.h | 2 +- source/tb_assets.c | 2 +- source/tb_config.h.in | 9 +- source/tb_coreui_system.c | 2 - source/tb_descriptor_buffer.c | 6 +- source/tb_render_thread.c | 2 +- source/tb_time_of_day_system.c | 6 +- source/tb_visual_logging_system.c | 16 +- source/tb_vk_dbg.c | 2 +- source/tb_world.c | 6 +- 23 files changed, 582 insertions(+), 686 deletions(-) create mode 100644 cmake/tb_app.cmake create mode 100644 cmake/tb_cooking.cmake create mode 100644 cmake/tb_packages.cmake create mode 100644 cmake/tb_platform.cmake diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml index 753beea2..d07c43da 100644 --- a/.github/workflows/android.yml +++ b/.github/workflows/android.yml @@ -25,7 +25,7 @@ jobs: - uses: actions/checkout@v4 - name: Configure - run: cmake --preset ${{matrix.toolsets.preset}} -DCOOK_ASSETS=OFF + run: cmake --preset ${{matrix.toolsets.preset}} -DTB_COOK_ASSETS=OFF - name: Build Debug run: cmake --build --preset debug-${{matrix.toolsets.preset}} diff --git a/.github/workflows/ios.yml b/.github/workflows/ios.yml index 55afc3ab..6af89eb7 100644 --- a/.github/workflows/ios.yml +++ b/.github/workflows/ios.yml @@ -25,7 +25,7 @@ jobs: - uses: actions/checkout@v4 - name: Configure - run: cmake --preset ${{matrix.toolsets.preset}} -DCOOK_ASSETS=OFF + run: cmake --preset ${{matrix.toolsets.preset}} -DTB_COOK_ASSETS=OFF - name: Build Debug run: cmake --build --preset debug-${{matrix.toolsets.preset}} diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 54bb67f6..8868bbc2 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -23,7 +23,7 @@ jobs: - uses: actions/checkout@v4 - name: Configure - run: cmake --preset ${{matrix.toolsets.preset}} -DCOOK_ASSETS=OFF -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ + run: cmake --preset ${{matrix.toolsets.preset}} -DTB_COOK_ASSETS=OFF -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ - name: Build Debug run: cmake --build --preset debug-${{matrix.toolsets.preset}} diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 4f136a1c..d6a4d2d7 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -23,7 +23,7 @@ jobs: - uses: actions/checkout@v4 - name: Configure - run: cmake --preset ${{matrix.toolsets.preset}} -DCOOK_ASSETS=OFF + run: cmake --preset ${{matrix.toolsets.preset}} -DTB_COOK_ASSETS=OFF - name: Build Debug run: cmake --build --preset debug-${{matrix.toolsets.preset}} diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 2a0dc1c8..82ea658a 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -24,7 +24,7 @@ jobs: - uses: actions/checkout@v4 - name: Configure - run: cmake --preset ${{matrix.toolsets.preset}} -DCOOK_ASSETS=OFF + run: cmake --preset ${{matrix.toolsets.preset}} -DTB_COOK_ASSETS=OFF - name: Build Debug run: cmake --build --preset debug-${{matrix.toolsets.preset}} diff --git a/CMakeLists.txt b/CMakeLists.txt index 3e68ae94..89f3a3c5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,8 +2,6 @@ cmake_minimum_required(VERSION 3.21) set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake) -get_property(isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) - # Determine version from the vcpkg json manifest file(READ vcpkg.json VCPKG_MANIFEST) string(JSON VCPKG_VERSION GET ${VCPKG_MANIFEST} "version") @@ -15,679 +13,60 @@ project(toybox option(TB_BUILD_SAMPLES "Compile samples" ON) option(TB_BUILD_VIEWER "Build the viewer application" ON) -option(FINAL "Compile with the intention to redistribute" OFF) -option(PROFILE_TRACY "Compile with support for the tracy profiler" ON) -option(COOK_ASSETS "Process assets for runtime loading" ON) - -set(toybox_source_dir ${CMAKE_CURRENT_LIST_DIR}) - -set(ENGINE_NAME "toybox") -set(ENGINE_VERSION_MAJOR ${CMAKE_PROJECT_VERSION_MAJOR}) -set(ENGINE_VERSION_MINOR ${CMAKE_PROJECT_VERSION_MINOR}) -set(ENGINE_VERSION_PATCH ${CMAKE_PROJECT_VERSION_PATCH}) - -set(config $) - -# Get target CPU architecture -include(${CMAKE_CURRENT_LIST_DIR}/cmake/TargetArch.cmake) -target_architecture(arch) - -# Platform detection -set(tb_windows 0) -set(tb_macos 0) -set(tb_linux 0) -set(tb_android 0) -set(tb_ios 0) -if(WIN32) - set(platform "windows") - set(tb_windows 1) -elseif(APPLE) - if(IOS) - set(platform "ios") - set(tb_ios 1) - else() - set(platform "macos") - set(tb_macos 1) - endif() -elseif(ANDROID) - set(platform "android") - set(tb_android 1) -elseif(UNIX) - set(platform "linux") - set(tb_linux 1) -else() - message(FATAL_ERROR "Unknown platform") -endif() - -# Host detection -if(CMAKE_HOST_WIN32) - set(host "windows") -elseif(CMAKE_HOST_UNIX) - if(CMAKE_HOST_APPLE) - set(host "osx") - else() - set(host "linux") - endif() -else() -message(FATAL_ERROR "Unknown host") -endif() - -set(tb_x64 0) -set(tb_arm64 0) -if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "AMD64") - set(host_arch "x64") - set(tb_x64 1) -elseif(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86_64") - set(host_arch "x64") - set(tb_x64 1) -elseif(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "arm64") - set(host_arch "arm64") - set(tb_arm64 1) -elseif(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "aarch64") - set(host_arch "arm64") - set(tb_arm64 1) -else() - message(FATAL_ERROR "Unknown host arch: ${CMAKE_HOST_SYSTEM_PROCESSOR}") -endif() - -set(host_triple ${host_arch}-${host}) - -# Set install prefix if not already overridden -set(toybox_install "${CMAKE_CURRENT_SOURCE_DIR}/install/${platform}") -if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) - set (CMAKE_INSTALL_PREFIX ${toybox_install} CACHE PATH "Default Install Path" FORCE ) -else() - set(toybox_install ${CMAKE_INSTALL_PREFIX}) -endif() - -# Clang only for now -if(NOT ${CMAKE_C_COMPILER_ID} MATCHES "Clang" AND - NOT ${CMAKE_C_COMPILER_ID} MATCHES "AppleClang") - message(FATAL_ERROR "${CMAKE_C_COMPILER_ID} Unsupported - Clang only") -endif() - -if(${VCPKG_TARGET_TRIPLET} MATCHES static OR ${VCPKG_TARGET_TRIPLET} MATCHES android) - set(STATIC ON) -endif() - -find_package(SDL3 CONFIG REQUIRED) -find_package(SDL3_mixer CONFIG REQUIRED) -find_package(volk CONFIG REQUIRED) -find_package(imgui CONFIG REQUIRED) -find_package(mimalloc CONFIG REQUIRED) -find_package(zstd CONFIG REQUIRED) -find_package(Ktx CONFIG REQUIRED) -find_package(Threads REQUIRED) -find_package(flecs CONFIG REQUIRED) -find_package(unofficial-joltphysics CONFIG REQUIRED) -if(PROFILE_TRACY) - find_package(Tracy CONFIG REQUIRED) -endif() -if(UNIX) - if(NOT ANDROID) - add_library(zstd::zstd ALIAS zstd::libzstd_static) - endif() -endif() -find_package(json-c CONFIG REQUIRED) -find_package(meshoptimizer CONFIG REQUIRED) -find_package(enkiTS CONFIG REQUIRED) -find_package(mysofa CONFIG REQUIRED) -find_package(pffft CONFIG REQUIRED) -find_package(flatbuffers CONFIG REQUIRED) -find_package(steam-audio CONFIG REQUIRED) -find_package(VulkanHeaders CONFIG REQUIRED) -find_package(VulkanMemoryAllocator CONFIG REQUIRED) - -find_path(CGLTF_INCLUDE_DIRS "cgltf.h") - -set(VULKAN_BIN_PATH "bin") -if(platform MATCHES "windows") - set(VULKAN_BIN_PATH "Bin") -endif() -# Prefer whatever dxc is in the vulkan SDK -# If this picks up a windows kit dxc it may not have spirv support -# but on linux a dxc on the default path will probably have spirv codegen -# so *shrug* -set(CMAKE_FIND_ROOT_PATH "$ENV{VULKAN_SDK}/${VULKAN_BIN_PATH};${CMAKE_FIND_ROOT_PATH}") -find_program(GLTFPACK gltfpack - PATHS ${CMAKE_CURRENT_BINARY_DIR}/vcpkg_installed/${host_triple}/tools/meshoptimizer - REQUIRED) - -find_program(SLANG slangc - PATHS ${CMAKE_CURRENT_BINARY_DIR}/vcpkg_installed/${host_triple}/tools/shader-slang - REQUIRED) - -# The list of all external targets to link -list(APPEND library_list "$,flecs::flecs,flecs::flecs_static>") -list(APPEND library_list "volk::volk") -list(APPEND library_list "volk::volk_headers") -list(APPEND library_list "imgui::imgui") -list(APPEND library_list "mimalloc") -list(APPEND library_list "mimalloc-static") -list(APPEND library_list "KTX::ktx") -list(APPEND library_list "json-c::json-c") -list(APPEND library_list "meshoptimizer::meshoptimizer") -list(APPEND library_list "unofficial::joltphysics::Jolt") -list(APPEND library_list "enkiTS::enkiTS") -list(APPEND library_list "steam-audio::phonon") -list(APPEND library_list "Vulkan::Headers") -list(APPEND library_list "GPUOpen::VulkanMemoryAllocator") - -set(engine_shader_include_dir "${CMAKE_CURRENT_LIST_DIR}/include") - -# Helper function to cook shaders -function(cook_shaders out_shader_sources out_shader_headers) - - # Compile Shaders - set(shader_include_dir "${CMAKE_CURRENT_LIST_DIR}/include") - file(GLOB shader_includes CONFIGURE_DEPENDS "${shader_include_dir}/*.hlsli" "${shader_include_dir}/*.h") - - file(GLOB slang_shaders CONFIGURE_DEPENDS "${CMAKE_CURRENT_LIST_DIR}/source/*.slang") - foreach(shader ${slang_shaders}) - get_filename_component(filename ${shader} NAME_WLE) - set(shader_out_path ${CMAKE_CFG_INTDIR}/shaders) - - # Outputting short names for shader spv modules because due to xxd nonsense - # the name of the variable in the C header will be based on this file name - set(vert_out_path "${filename}_vert") - set(frag_out_path "${filename}_frag") - set(out_paths "${vert_out_path};${frag_out_path}") - - add_custom_command( - OUTPUT ${out_paths} - COMMAND ${CMAKE_COMMAND} -E make_directory ${shader_out_path} - COMMAND ${SLANG} -DTB_SHADER=1 -profile sm_6_5 -stage vertex -entry vert -target spirv $<$:-O0> $<$>:-g> -I ${shader_include_dir} -I ${engine_shader_include_dir} -o ${vert_out_path} ${shader} - COMMAND ${SLANG} -DTB_SHADER=1 -profile sm_6_5 -stage fragment -entry frag -target spirv $<$:-O0> $<$>:-g> -I ${shader_include_dir} -I ${engine_shader_include_dir} -o ${frag_out_path} ${shader} - MAIN_DEPENDENCY ${shader} - DEPENDS ${shader_includes} - ) - - set(vert_header "${shader_out_path}/${filename}_vert.h") - set(frag_header "${shader_out_path}/${filename}_frag.h") - - # Use xxd to convert spv binary files to C headers that can be included - # Renaming shenanigans to work around old xxd versions not supporting the - # '-n' flag to rename the C variable - add_custom_command( - OUTPUT ${vert_header} - COMMAND xxd -i ${vert_out_path} ${vert_header} - MAIN_DEPENDENCY ${vert_out_path} - ) - add_custom_command( - OUTPUT ${frag_header} - COMMAND xxd -i ${frag_out_path} ${frag_header} - MAIN_DEPENDENCY ${frag_out_path} - ) - - list(APPEND shader_headers ${vert_header} ${vert_out_path}) - list(APPEND shader_headers ${frag_header} ${frag_out_path}) - endforeach() - - file(GLOB slang_compute_shaders CONFIGURE_DEPENDS "${CMAKE_CURRENT_LIST_DIR}/source/*.slangc") - foreach(shader ${slang_compute_shaders}) - get_filename_component(filename ${shader} NAME_WLE) - set(shader_out_path ${CMAKE_CFG_INTDIR}/shaders) - - # Outputting short names for shader spv modules because due to xxd nonsense - # the name of the variable in the C header will be based on this file name - set(comp_out_path "${filename}_comp") - set(out_paths "${comp_out_path};") - - add_custom_command( - OUTPUT ${out_paths} - COMMAND ${CMAKE_COMMAND} -E make_directory ${shader_out_path} - COMMAND ${SLANG} -DTB_SHADER=1 -lang slang -profile sm_6_5 -stage compute -entry comp -target spirv $<$:-O0> $<$>:-g> -I ${shader_include_dir} -I ${engine_shader_include_dir} -o ${comp_out_path} ${shader} - MAIN_DEPENDENCY ${shader} - DEPENDS ${shader_includes} - ) - - set(comp_header "${shader_out_path}/${filename}_comp.h") - - # Use xxd to convert spv binary files to C headers that can be included - # Renaming shenanigans to work around old xxd versions not supporting the - # '-n' flag to rename the C variable - add_custom_command( - OUTPUT ${comp_header} - COMMAND xxd -i ${comp_out_path} ${comp_header} - MAIN_DEPENDENCY ${comp_out_path} - ) - - list(APPEND shader_headers ${comp_header} ${comp_out_path}) - endforeach() - - #[[ - file(GLOB shader_files CONFIGURE_DEPENDS "${CMAKE_CURRENT_LIST_DIR}/source/*.hlsl") - foreach(shader ${shader_files}) - get_filename_component(filename ${shader} NAME_WLE) - set(shader_out_path ${CMAKE_CFG_INTDIR}/shaders) - - set(vert_out_path "${shader_out_path}/${filename}_vert.h") - set(frag_out_path "${shader_out_path}/${filename}_frag.h") - set(out_paths "${vert_out_path};${frag_out_path}") - - add_custom_command( - OUTPUT ${out_paths} - COMMAND ${CMAKE_COMMAND} -E make_directory ${shader_out_path} - COMMAND ${DXC} -DTB_SHADER=1 -T vs_6_5 -E vert -Vn ${filename}_vert $<$:-O0> $<$>:-Zi> -I ${shader_include_dir} -I ${engine_shader_include_dir} $<$>:-Qembed_debug> -enable-16bit-types -fspv-target-env=vulkan1.3 -spirv ${shader} -Fh ${vert_out_path} - COMMAND ${DXC} -DTB_SHADER=1 -T ps_6_5 -E frag -Vn ${filename}_frag $<$:-O0> $<$>:-Zi> -I ${shader_include_dir} -I ${engine_shader_include_dir} $<$>:-Qembed_debug> -enable-16bit-types -fspv-target-env=vulkan1.3 -spirv ${shader} -Fh ${frag_out_path} - MAIN_DEPENDENCY ${shader} - DEPENDS ${shader_includes} - ) - list(APPEND shader_headers ${out_paths}) - endforeach() - list(APPEND shader_sources ${shader_files}) - ]]# - - #[[ - file(GLOB mesh_shader_files CONFIGURE_DEPENDS "${CMAKE_CURRENT_LIST_DIR}/source/*.hlsl.m") - foreach(shader ${mesh_shader_files}) - get_filename_component(filename ${shader} NAME_WLE) - get_filename_component(filename ${filename} NAME_WLE) - set(shader_out_path ${CMAKE_CFG_INTDIR}/shaders) - - set(mesh_out_path "${shader_out_path}/${filename}_mesh.h") - set(frag_out_path "${shader_out_path}/${filename}_frag.h") - set(out_paths "${mesh_out_path};${frag_out_path}") - - add_custom_command( - OUTPUT ${out_paths} - COMMAND ${CMAKE_COMMAND} -E make_directory ${shader_out_path} - COMMAND ${DXC} -DTB_SHADER=1 -T ms_6_5 -E mesh -Vn ${filename}_mesh $<$:-O0> -I ${shader_include_dir} -I ${engine_shader_include_dir} $<$>:-Zi> $<$>:-Qembed_debug> -fspv-target-env=vulkan1.3 -spirv ${shader} -Fh ${mesh_out_path} - COMMAND ${DXC} -DTB_SHADER=1 -T ps_6_5 -E frag -Vn ${filename}_frag $<$:-O0> -I ${shader_include_dir} -I ${engine_shader_include_dir} $<$>:-Zi> $<$>:-Qembed_debug> -fspv-target-env=vulkan1.3 -spirv ${shader} -Fh ${frag_out_path} - MAIN_DEPENDENCY ${shader} - DEPENDS ${shader_includes} - ) - list(APPEND shader_headers ${out_paths}) - endforeach() - list(APPEND shader_sources ${mesh_shader_files}) - ]]# - - #[[ - file(GLOB compute_shader_files CONFIGURE_DEPENDS "${CMAKE_CURRENT_LIST_DIR}/source/*.hlsl.cs") - foreach(shader ${compute_shader_files}) - get_filename_component(filename ${shader} NAME_WLE) - get_filename_component(filename ${filename} NAME_WLE) - set(shader_out_path ${CMAKE_CFG_INTDIR}/shaders) - - set(comp_out_path "${shader_out_path}/${filename}_comp.h") - set(out_paths "${comp_out_path}") - - add_custom_command( - OUTPUT ${out_paths} - COMMAND ${CMAKE_COMMAND} -E make_directory ${shader_out_path} - COMMAND ${DXC} -DTB_SHADER=1 -T cs_6_5 -E comp -Vn ${filename}_comp $<$:-O0> -I ${shader_include_dir} -I ${engine_shader_include_dir} $<$>:-Zi> $<$>:-Qembed_debug> -enable-16bit-types -fspv-target-env=vulkan1.3 -spirv ${shader} -Fh ${comp_out_path} - MAIN_DEPENDENCY ${shader} - DEPENDS ${shader_includes} - ) - list(APPEND shader_headers ${out_paths}) - endforeach() - list(APPEND shader_sources ${compute_shader_files}) - ]]# - - set("${out_shader_sources}" "${shader_sources}" PARENT_SCOPE) - set("${out_shader_headers}" "${shader_headers}" PARENT_SCOPE) -endfunction() - -# Helper function to cook assets -function(cook_assets target_name out_assets_path) - set(assets_dest "assets") - if(ANDROID) - set(assets_dest "$/assets") - install(TARGETS ${out_target_name} - RUNTIME DESTINATION "$/lib/${arch}" - LIBRARY DESTINATION "$/lib/${arch}") - elseif(APPLE AND NOT IOS) - # Have to do this or else it won't be placed in the right part of the app package - install(TARGETS ${out_target_name} - RUNTIME DESTINATION "./../MacOS/" - BUNDLE DESTINATION "./../MacOS/") - else() - install(TARGETS ${out_target_name} - RUNTIME DESTINATION "." - BUNDLE DESTINATION "." - LIBRARY DESTINATION ".") - endif() - - # Cook scenes - file(GLOB_RECURSE source_scenes CONFIGURE_DEPENDS "${CMAKE_CURRENT_LIST_DIR}/assets/scenes/*.glb") - foreach(scene ${source_scenes}) - file(RELATIVE_PATH relpath ${CMAKE_CURRENT_LIST_DIR}/assets ${scene}) - get_filename_component(relpath ${relpath} DIRECTORY) - get_filename_component(filename ${scene} NAME_WE) - set(packed_scene ${CMAKE_CURRENT_BINARY_DIR}/$/assets/scenes/${filename}.glb) - - add_custom_command( - OUTPUT ${packed_scene} - COMMAND ${CMAKE_COMMAND} -E make_directory assets/${relpath} - COMMAND ${GLTFPACK} -cc -kn -km -ke -tc -i ${scene} -o ${packed_scene} - MAIN_DEPENDENCY ${scene} - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/$ - ) - - list(APPEND packed_scenes ${packed_scene}) - endforeach() - list(APPEND assets ${packed_scenes}) - add_custom_target(${target_name}_scenes DEPENDS ${packed_scenes}) +option(TB_FINAL "Compile with the intention to redistribute" OFF) +option(TB_PROFILE_TRACY "Compile with support for the tracy profiler" ON) - # Copy textures - file(GLOB_RECURSE source_textures CONFIGURE_DEPENDS "${CMAKE_CURRENT_LIST_DIR}/assets/textures/*.ktx2") - foreach(texture ${source_textures}) - file(RELATIVE_PATH relpath ${CMAKE_CURRENT_LIST_DIR}/assets ${texture}) - get_filename_component(relpath ${relpath} DIRECTORY) - get_filename_component(filename ${texture} NAME_WE) - set(packed ${CMAKE_CURRENT_BINARY_DIR}/$/assets/textures/${filename}.ktx2) +# Include Helpers +include(${CMAKE_MODULE_PATH}/tb_app.cmake) +include(${CMAKE_MODULE_PATH}/tb_cooking.cmake) +include(${CMAKE_MODULE_PATH}/tb_packages.cmake) - message("Copying ${texture} to ${packed}") - add_custom_command( - OUTPUT ${packed} - COMMAND ${CMAKE_COMMAND} -E make_directory assets/${relpath} - COMMAND ${CMAKE_COMMAND} -E copy ${texture} ${packed} - MAIN_DEPENDENCY ${texture} - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/$ - ) - - list(APPEND packed_textures ${packed}) - endforeach() - list(APPEND assets ${packed_textures}) - add_custom_target(${target_name}_textures DEPENDS ${packed_textures}) - - # Copy audio - file(GLOB_RECURSE source_audio CONFIGURE_DEPENDS "${CMAKE_CURRENT_LIST_DIR}/assets/audio/*.ogg" "${CMAKE_CURRENT_LIST_DIR}/assets/audio/*.wav") - foreach(audio ${source_audio}) - file(RELATIVE_PATH relpath ${CMAKE_CURRENT_LIST_DIR}/assets ${audio}) - get_filename_component(relpath ${relpath} DIRECTORY) - get_filename_component(filename ${audio} NAME) - set(packed ${CMAKE_CURRENT_BINARY_DIR}/$/assets/audio/${filename}) - - message("Copying ${audio} to ${packed}") - add_custom_command( - OUTPUT ${packed} - COMMAND ${CMAKE_COMMAND} -E make_directory assets/${relpath} - COMMAND ${CMAKE_COMMAND} -E copy ${audio} ${packed} - MAIN_DEPENDENCY ${audio} - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/$ - ) - - list(APPEND packed_audio ${packed}) - endforeach() - list(APPEND assets ${packed_audio}) - add_custom_target(${target_name}_audio DEPENDS ${packed_audio}) - - # Generate asset database - set(source_assets ${packed_scenes} ${packed_textures} ${packed_audio}) - list(LENGTH source_assets ASSET_NUM) - set(generated_manifest "${CMAKE_CURRENT_BINARY_DIR}/config/${target_name}_assetmanifest.h") - # Add all assets to asset list - # Also keep track of which assets are scenes - math(EXPR asset_idx "0") - foreach(asset ${source_assets}) - get_filename_component(asset_ext ${asset} EXT BASE_DIR ${CMAKE_CURRENT_BINARY_DIR}/$) - get_filename_component(asset_path ${asset} ABSOLUTE BASE_DIR ${CMAKE_CURRENT_BINARY_DIR}/$) - file(RELATIVE_PATH relpath ${CMAKE_CURRENT_BINARY_DIR}/$/assets ${asset_path}) - if(asset_ext MATCHES ".glb") - list(APPEND scene_index_list ${asset_idx}) - endif() - string(APPEND ASSET_LIST "\"${relpath}\",") - math(EXPR asset_idx "${asset_idx} + 1") - endforeach() - # Add all scene indexes to the string that will be sent to the generated file - list(LENGTH scene_index_list SCENE_NUM) - foreach(idx ${scene_index_list}) - string(APPEND SCENE_LIST "${idx},") - endforeach() - - configure_file(${toybox_source_dir}/source/tb_assetmanifest.h.in ${generated_manifest}) - add_custom_target(${target_name}_asset_manifest DEPENDS ${generated_manifest}) - - add_dependencies(${target_name} ${target_name}_scenes ${target_name}_textures ${target_name}_audio ${target_name}_asset_manifest) - - # Install cooked assets - install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/$/assets - DESTINATION ${assets_dest}) - - # Add a define to the target so we know that assets were cooked - # if they weren't we shouldn't even try to load the manifest - target_compile_definitions(${target_name} PRIVATE -DTB_COOKED=1) - - set(${out_assets_path} ${CMAKE_CURRENT_BINARY_DIR}/$/assets PARENT_SCOPE) -endfunction() - -# Setup toybox library -file(GLOB_RECURSE lib_source CONFIGURE_DEPENDS "${CMAKE_CURRENT_LIST_DIR}/source/*.c" "${CMAKE_CURRENT_LIST_DIR}/source/*.cpp" "${CMAKE_CURRENT_LIST_DIR}/source/*.h") -add_library(toybox OBJECT ${lib_source}) - -# We provide a cross platform blocks runtime so we can use this -target_compile_options(toybox PUBLIC -fblocks) - -if(WIN32) - # This really only matters for clang-cl - # ${CMAKE_C_COMPILER_ID} being MSVC would fail the above check - # So think of this more as `if(MSVC-style-compiler)` - if(MSVC) - target_compile_options(toybox PUBLIC -Wno-reserved-id-macro) - target_compile_options(toybox PUBLIC -Wno-documentation) - endif() - - # Annoying warning in C++ when having to use flecs C macros - target_compile_options(toybox PUBLIC -Wno-missing-field-initializers) - # Folding VLAs to constant arrays is desired - target_compile_options(toybox PUBLIC -Wno-gnu-folding-constant) - # We use anonymous structs - target_compile_options(toybox PUBLIC -Wno-gnu-anonymous-struct) - target_compile_options(toybox PUBLIC -Wno-nested-anon-types) - -elseif(ANDROID) - if(CMAKE_C_COMPILER_ARCHITECTURE_ID MATCHES "arm") - target_link_libraries(toybox PUBLIC KTX::astcenc-neon-static) - elseif(CMAKE_C_COMPILER_ARCHITECTURE_ID MATCHES "x86") - target_link_libraries(toybox PUBLIC KTX::astcenc-avx2-static) - endif() -endif() - -if(isMultiConfig) - get_filename_component(CMAKE_CFG_INTDIR_ABS "${CMAKE_CURRENT_BINARY_DIR}/$" ABSOLUTE) -else() - get_filename_component(CMAKE_CFG_INTDIR_ABS "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}" ABSOLUTE) -endif() - -target_link_libraries(toybox PUBLIC ${library_list}) - -if(PROFILE_TRACY) - target_link_libraries(toybox PUBLIC "Tracy::TracyClient") -endif() - -# Get the latest abbreviated commit hash of the working branch +# Generate config header execute_process(COMMAND git log -1 --format=%h WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} OUTPUT_VARIABLE GIT_COMMIT_HASH OUTPUT_STRIP_TRAILING_WHITESPACE) +set(tb_engine_config_include_dir ${CMAKE_CURRENT_BINARY_DIR}/config) +configure_file(source/tb_config.h.in ${tb_engine_config_include_dir}/tb_engine_config.h @ONLY) -# Generate config header -set(engine_config_include_dir ${CMAKE_CURRENT_BINARY_DIR}/config) -configure_file(source/tb_config.h.in ${engine_config_include_dir}/tb_engine_config.h @ONLY) +# Setup toybox as an object library +file(GLOB_RECURSE lib_source CONFIGURE_DEPENDS "${CMAKE_CURRENT_LIST_DIR}/source/*.c" "${CMAKE_CURRENT_LIST_DIR}/source/*.cpp" "${CMAKE_CURRENT_LIST_DIR}/source/*.h") +add_library(toybox OBJECT ${lib_source}) + +# Add default options +tb_options(toybox) +# Set include directories target_include_directories(toybox PUBLIC "${CMAKE_CURRENT_LIST_DIR}/include") -target_include_directories(toybox PUBLIC "source/" "${CGLTF_INCLUDE_DIRS}" "${engine_config_include_dir}") +target_include_directories(toybox PUBLIC "source/" "${CGLTF_INCLUDE_DIRS}" "${tb_engine_config_include_dir}") # Mingw generates warnings from generated shader headers. Include as a system directory to ignore target_include_directories(toybox SYSTEM PUBLIC "${CMAKE_CFG_INTDIR_ABS}/shaders") -target_compile_definitions(toybox PUBLIC "-DTB_CONFIG=\"$\"") -add_dependencies(toybox engine_shaders) -if(FINAL) - target_compile_definitions(toybox PUBLIC "-DFINAL") +# Link libraries +target_link_libraries(toybox PUBLIC ${tb_library_list}) +if(TB_PROFILE_TRACY) + target_link_libraries(toybox PUBLIC "Tracy::TracyClient") endif() -if(STATIC) +if(TB_STATIC) target_link_libraries(toybox PUBLIC SDL3::SDL3-static) - set_property(TARGET toybox PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") else() target_link_libraries(toybox PUBLIC SDL3::SDL3) endif() - target_link_libraries(toybox PUBLIC $,SDL3_mixer::SDL3_mixer,SDL3_mixer::SDL3_mixer-static>) -# Turn on warnings -target_compile_options(toybox PUBLIC - $<$:/W4> - $<$>:-Wall -Wextra -Wpedantic> -) - -target_compile_features(toybox PUBLIC c_std_23) -target_compile_features(toybox PUBLIC cxx_std_20) - # Cook engine shaders -cook_shaders(tb_engine_shader_sources tb_engine_shader_headers) -add_custom_target(engine_shaders ALL DEPENDS ${tb_engine_shader_headers}) -target_sources(engine_shaders PRIVATE ${tb_engine_shader_sources}) +tb_cook_shaders(tb_engine_shader_sources tb_engine_shader_headers) +add_custom_target(tb_engine_shaders ALL DEPENDS ${tb_engine_shader_headers}) +target_sources(tb_engine_shaders PRIVATE ${tb_engine_shader_sources}) +add_dependencies(toybox tb_engine_shaders) # Cook engine assets -if(COOK_ASSETS) - cook_assets(toybox engine_assets_path) +if(TB_COOK_ASSETS) + tb_cook_assets(toybox engine_assets_path) endif() -function(tb_new_addon target_name source) - add_library(${target_name} OBJECT ${source}) - - message("Found Addon: ${target_name}") - - # Set known language version requirements - target_compile_features(${target_name} PRIVATE c_std_11) - target_compile_features(${target_name} PRIVATE cxx_std_20) - - # Turn on warnings - target_compile_options(${target_name} PRIVATE - $<$:/W4> - $<$>:-Wall -Wextra -Wpedantic> - ) - - if(FINAL) - target_compile_definitions(${target_name} PRIVATE "-DFINAL") - endif() - - cook_shaders(${target_name}_shader_sources ${target_name}_shader_headers) - - add_custom_target(${target_name}_shaders ALL DEPENDS "${${target_name}_shader_headers}") - target_sources(${target_name}_shaders PRIVATE "${${target_name}_shader_sources}") - add_dependencies(${target_name} ${target_name}_shaders) - - if(COOK_ASSETS) - cook_assets(${target_name} ${target_name}_assets_path) - endif() - - target_link_libraries(${target_name} PUBLIC ${library_list}) - target_link_libraries(${target_name} PUBLIC toybox) - target_include_directories(${target_name} SYSTEM PUBLIC "${CMAKE_CURRENT_BINARY_DIR}/$/shaders") - target_include_directories(${target_name} PUBLIC "${CMAKE_CURRENT_LIST_DIR}/include") -endfunction() - -# Helper to describe applications that depend on toybox -function(tb_add_app target_name source) - if(WIN32) - if(MINGW) - add_executable(${target_name} ${source} "${CMAKE_CURRENT_LIST_DIR}/source/win32/${target_name}.rc") - target_link_libraries(${target_name} PRIVATE mingw32 pthread) - target_link_options(${target_name} PRIVATE -mwindows) - else() - add_executable(${target_name} WIN32 ${source} "${CMAKE_CURRENT_LIST_DIR}/source/win32/${target_name}.rc") - if(NOT MSVC) - target_link_options(${target_name} PRIVATE -Wl,/subsystem:windows) - endif() - endif() - elseif(ANDROID) - add_library(${target_name} SHARED ${source}) - elseif(UNIX) - if(APPLE) - if(IOS) - # iOS - find_library(IMAGEIO ImageIO REQUIRED) - find_library(CORESERVICES CoreServices REQUIRED) - add_executable(${target_name} ${source}) - target_link_libraries(${target_name} PRIVATE ${IMAGEIO} ${CORESERVICES}) - if(CMAKE_GENERATOR MATCHES "Xcode") - set_target_properties(${target_name} PROPERTIES XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER "com.honeybunch.${target_name}") - endif() - else() - # macOS - add_executable(${target_name} ${source}) - endif() - else() - add_executable(${target_name} ${source}) - endif() - endif() - - if(${VCPKG_TARGET_TRIPLET} MATCHES static OR ${VCPKG_TARGET_TRIPLET} MATCHES android) - set_property(TARGET ${target_name} PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") - endif() - - # Set known language version requirements - target_compile_features(${target_name} PRIVATE c_std_11) - target_compile_features(${target_name} PRIVATE cxx_std_20) - - # Turn on warnings - target_compile_options(${target_name} PRIVATE - $<$:/W4> - $<$>:-Wall -Wextra -Wpedantic> - ) - - if(FINAL) - target_compile_definitions(${target_name} PRIVATE "-DFINAL") - endif() - - # Find config header - set(config_include_dir ${CMAKE_CURRENT_BINARY_DIR}/config) - configure_file(${CMAKE_CURRENT_LIST_DIR}/source/tb_config.h.in ${config_include_dir}/tb_config.h @ONLY) - - cook_shaders(${target_name}_shader_sources ${target_name}_shader_headers) - if(out_shader_headers) - add_custom_target(${target_name}_shaders ALL DEPENDS ${target_name}_shader_headers) - target_sources(${target_name}_shaders PRIVATE ${target_name}_shader_sources) - add_dependencies(${target_name} ${target_name}_shaders) - endif() - - if(COOK_ASSETS) - cook_assets(${target_name} ${target_name}_assets_path) - endif() - - target_link_libraries(${target_name} PRIVATE ${library_list}) - target_link_libraries(${target_name} PRIVATE toybox) - target_include_directories(${target_name} PRIVATE ${config_include_dir}) - target_include_directories(${target_name} SYSTEM PRIVATE "${CMAKE_CFG_INTDIR_ABS}/shaders") - add_dependencies(${target_name} engine_shaders) - - if(engine_assets_path) - # Add a target to copy engine assets - add_custom_target(${target_name}_engine_assets - COMMAND ${CMAKE_COMMAND} -E copy_directory ${engine_assets_path} ${CMAKE_CURRENT_BINARY_DIR}/$/assets - ) - add_dependencies(${target_name}_engine_assets toybox) - add_dependencies(${target_name} ${target_name}_engine_assets) - endif() - - # Some helpers for Visual Studio - set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ${target_name}) - set_property(TARGET ${target_name} PROPERTY VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/$") -endfunction() - -function(tb_use_addon target addon) - target_link_libraries(${target} PUBLIC ${addon}) - - set(addon_asset_path "$/$/assets") - - # Add a target to copy assets - if(COOK_ASSETS) - add_custom_target(${addon}_assets - COMMAND ${CMAKE_COMMAND} -E copy_directory ${addon_asset_path} ${CMAKE_CURRENT_BINARY_DIR}/$/assets - ) - - add_dependencies(${addon}_assets toybox) - add_dependencies(${target}_scenes ${addon}_scenes) - add_dependencies(${target}_textures ${addon}_textures) - add_dependencies(${target}_audio ${addon}_audio) - add_dependencies(${target}_asset_manifest ${addon}_asset_manifest) - add_dependencies(${target}_engine_assets ${addon}_assets) - add_dependencies(${target} ${addon}_assets) - endif() -endfunction() +# Add optional sub-projects if(TB_BUILD_SAMPLES) add_subdirectory(samples) @@ -697,4 +76,5 @@ if(TB_BUILD_VIEWER) add_subdirectory(viewer) endif() +# Continue on to configure addons include(${CMAKE_CURRENT_LIST_DIR}/addons/CMakeLists.txt) diff --git a/cmake/tb_app.cmake b/cmake/tb_app.cmake new file mode 100644 index 00000000..7c1ea8c2 --- /dev/null +++ b/cmake/tb_app.cmake @@ -0,0 +1,191 @@ +# Clang only for now +if(NOT ${CMAKE_C_COMPILER_ID} MATCHES "Clang" AND + NOT ${CMAKE_C_COMPILER_ID} MATCHES "AppleClang") + message(FATAL_ERROR "${CMAKE_C_COMPILER_ID} Unsupported - Clang only") +endif() + +if(${VCPKG_TARGET_TRIPLET} MATCHES static OR ${VCPKG_TARGET_TRIPLET} MATCHES android) + set(TB_STATIC ON) +endif() + +# Set install prefix if not already overridden +set(toybox_install "${CMAKE_CURRENT_SOURCE_DIR}/install/${platform}") +if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) + set (CMAKE_INSTALL_PREFIX ${toybox_install} CACHE PATH "Default Install Path" FORCE ) +else() + set(toybox_install ${CMAKE_INSTALL_PREFIX}) +endif() + +get_property(tb_is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) +if(tb_is_multi_config) + get_filename_component(CMAKE_CFG_INTDIR_ABS "${CMAKE_CURRENT_BINARY_DIR}/$" ABSOLUTE) +else() + get_filename_component(CMAKE_CFG_INTDIR_ABS "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}" ABSOLUTE) +endif() + +# Helper functions + +function(tb_options target_name) + if(${VCPKG_TARGET_TRIPLET} MATCHES static OR ${VCPKG_TARGET_TRIPLET} MATCHES android) + set_property(TARGET ${target_name} PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") + endif() + + # Set known language version requirements + target_compile_features(${target_name} PRIVATE c_std_23) + target_compile_features(${target_name} PRIVATE cxx_std_20) + + # Turn on warnings + target_compile_options(${target_name} PRIVATE + $<$:/W4> + $<$>:-Wall -Wextra -Wpedantic> + ) + + if(TB_FINAL) + target_compile_definitions(${target_name} PRIVATE "-DTB_FINAL") + endif() + target_compile_definitions(${target_name} PRIVATE "-DTB_CONFIG=\"$\"") + + # We provide a cross platform blocks runtime so we can use this + target_compile_options(${target_name} PRIVATE -fblocks) + + # Platform specifics + if(WIN32) + # This really only matters for clang-cl + # ${CMAKE_C_COMPILER_ID} being MSVC would fail the above check + # So think of this more as `if(MSVC-style-compiler)` + if(MSVC) + target_compile_options(${target_name} PRIVATE -Wno-reserved-id-macro) + target_compile_options(${target_name} PRIVATE -Wno-documentation) + endif() + + # Annoying warning in C++ when having to use flecs C macros + target_compile_options(${target_name} PRIVATE -Wno-missing-field-initializers) + # Folding VLAs to constant arrays is desired + target_compile_options(${target_name} PRIVATE -Wno-gnu-folding-constant) + # We use anonymous structs + target_compile_options(${target_name} PRIVATE -Wno-gnu-anonymous-struct) + target_compile_options(${target_name} PRIVATE -Wno-nested-anon-types) + elseif(ANDROID) + if(CMAKE_C_COMPILER_ARCHITECTURE_ID MATCHES "arm") + target_link_libraries(${target_name} PRIVATE KTX::astcenc-neon-static) + elseif(CMAKE_C_COMPILER_ARCHITECTURE_ID MATCHES "x86") + target_link_libraries(${target_name} PRIVATE KTX::astcenc-avx2-static) + endif() + endif() +endfunction() + +function(tb_new_addon target_name source) + add_library(${target_name} OBJECT ${source}) + + message("Found Addon: ${target_name}") + + tb_options(${target_name}) + + tb_cook_shaders(${target_name}_shader_sources ${target_name}_shader_headers) + + add_custom_target(${target_name}_shaders ALL DEPENDS "${${target_name}_shader_headers}") + target_sources(${target_name}_shaders PRIVATE "${${target_name}_shader_sources}") + add_dependencies(${target_name} ${target_name}_shaders) + + if(TB_COOK_ASSETS) + tb_cook_assets(${target_name} ${target_name}_assets_path) + endif() + + target_link_libraries(${target_name} PUBLIC ${tb_library_list}) + target_link_libraries(${target_name} PUBLIC toybox) + target_include_directories(${target_name} SYSTEM PUBLIC "${CMAKE_CURRENT_BINARY_DIR}/$/shaders") + target_include_directories(${target_name} PUBLIC "${CMAKE_CURRENT_LIST_DIR}/include") +endfunction() + +# Helper to describe applications that depend on toybox +function(tb_add_app target_name source) + if(WIN32) + if(MINGW) + add_executable(${target_name} ${source} "${CMAKE_CURRENT_LIST_DIR}/source/win32/${target_name}.rc") + target_link_libraries(${target_name} PRIVATE mingw32 pthread) + target_link_options(${target_name} PRIVATE -mwindows) + else() + add_executable(${target_name} WIN32 ${source} "${CMAKE_CURRENT_LIST_DIR}/source/win32/${target_name}.rc") + if(NOT MSVC) + target_link_options(${target_name} PRIVATE -Wl,/subsystem:windows) + endif() + endif() + elseif(ANDROID) + add_library(${target_name} SHARED ${source}) + elseif(UNIX) + if(APPLE) + if(IOS) + # iOS + find_library(IMAGEIO ImageIO REQUIRED) + find_library(CORESERVICES CoreServices REQUIRED) + add_executable(${target_name} ${source}) + target_link_libraries(${target_name} PRIVATE ${IMAGEIO} ${CORESERVICES}) + if(CMAKE_GENERATOR MATCHES "Xcode") + set_target_properties(${target_name} PROPERTIES XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER "com.honeybunch.${target_name}") + endif() + else() + # macOS + add_executable(${target_name} ${source}) + endif() + else() + add_executable(${target_name} ${source}) + endif() + endif() + + tb_options(${target_name}) + + # Find config header + set(config_include_dir ${CMAKE_CURRENT_BINARY_DIR}/config) + configure_file(${CMAKE_CURRENT_LIST_DIR}/source/tb_config.h.in ${config_include_dir}/tb_config.h @ONLY) + + tb_cook_shaders(${target_name}_shader_sources ${target_name}_shader_headers) + if(out_shader_headers) + add_custom_target(${target_name}_shaders ALL DEPENDS ${target_name}_shader_headers) + target_sources(${target_name}_shaders PRIVATE ${target_name}_shader_sources) + add_dependencies(${target_name} ${target_name}_shaders) + endif() + + if(TB_COOK_ASSETS) + tb_cook_assets(${target_name} ${target_name}_assets_path) + endif() + + target_link_libraries(${target_name} PRIVATE ${tb_library_list}) + target_link_libraries(${target_name} PRIVATE toybox) + target_include_directories(${target_name} PRIVATE ${config_include_dir}) + target_include_directories(${target_name} SYSTEM PRIVATE "${CMAKE_CFG_INTDIR_ABS}/shaders") + add_dependencies(${target_name} tb_engine_shaders) + + if(engine_assets_path) + # Add a target to copy engine assets + add_custom_target(${target_name}_engine_assets + COMMAND ${CMAKE_COMMAND} -E copy_directory ${engine_assets_path} ${CMAKE_CURRENT_BINARY_DIR}/$/assets + ) + add_dependencies(${target_name}_engine_assets toybox) + add_dependencies(${target_name} ${target_name}_engine_assets) + endif() + + # Some helpers for Visual Studio + set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ${target_name}) + set_property(TARGET ${target_name} PROPERTY VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/$") +endfunction() + +function(tb_use_addon target addon) + target_link_libraries(${target} PUBLIC ${addon}) + + set(addon_asset_path "$/$/assets") + + # Add a target to copy assets + if(TB_COOK_ASSETS) + add_custom_target(${addon}_assets + COMMAND ${CMAKE_COMMAND} -E copy_directory ${addon_asset_path} ${CMAKE_CURRENT_BINARY_DIR}/$/assets + ) + + add_dependencies(${addon}_assets toybox) + add_dependencies(${target}_scenes ${addon}_scenes) + add_dependencies(${target}_textures ${addon}_textures) + add_dependencies(${target}_audio ${addon}_audio) + add_dependencies(${target}_asset_manifest ${addon}_asset_manifest) + add_dependencies(${target}_engine_assets ${addon}_assets) + add_dependencies(${target} ${addon}_assets) + endif() +endfunction() \ No newline at end of file diff --git a/cmake/tb_cooking.cmake b/cmake/tb_cooking.cmake new file mode 100644 index 00000000..aa266ae7 --- /dev/null +++ b/cmake/tb_cooking.cmake @@ -0,0 +1,212 @@ + +option(TB_COOK_ASSETS "Process assets for runtime loading" ON) + +set(engine_shader_include_dir "${CMAKE_SOURCE_DIR}/include") + +# Helper function to cook shaders +function(tb_cook_shaders out_shader_sources out_shader_headers) + + # Compile Shaders + set(shader_include_dir "${CMAKE_CURRENT_LIST_DIR}/include") + file(GLOB shader_includes CONFIGURE_DEPENDS "${shader_include_dir}/*.hlsli" "${shader_include_dir}/*.h") + + file(GLOB slang_shaders CONFIGURE_DEPENDS "${CMAKE_CURRENT_LIST_DIR}/source/*.slang") + foreach(shader ${slang_shaders}) + get_filename_component(filename ${shader} NAME_WLE) + set(shader_out_path ${CMAKE_CFG_INTDIR}/shaders) + + # Outputting short names for shader spv modules because due to xxd nonsense + # the name of the variable in the C header will be based on this file name + set(vert_out_path "${filename}_vert") + set(frag_out_path "${filename}_frag") + set(out_paths "${vert_out_path};${frag_out_path}") + + add_custom_command( + OUTPUT ${out_paths} + COMMAND ${CMAKE_COMMAND} -E make_directory ${shader_out_path} + COMMAND ${SLANG} -DTB_SHADER=1 -profile sm_6_5 -stage vertex -entry vert -target spirv $<$:-O0> $<$>:-g> -I ${shader_include_dir} -I ${engine_shader_include_dir} -o ${vert_out_path} ${shader} + COMMAND ${SLANG} -DTB_SHADER=1 -profile sm_6_5 -stage fragment -entry frag -target spirv $<$:-O0> $<$>:-g> -I ${shader_include_dir} -I ${engine_shader_include_dir} -o ${frag_out_path} ${shader} + MAIN_DEPENDENCY ${shader} + DEPENDS ${shader_includes} + ) + + set(vert_header "${shader_out_path}/${filename}_vert.h") + set(frag_header "${shader_out_path}/${filename}_frag.h") + + # Use xxd to convert spv binary files to C headers that can be included + # Renaming shenanigans to work around old xxd versions not supporting the + # '-n' flag to rename the C variable + add_custom_command( + OUTPUT ${vert_header} + COMMAND xxd -i ${vert_out_path} ${vert_header} + MAIN_DEPENDENCY ${vert_out_path} + ) + add_custom_command( + OUTPUT ${frag_header} + COMMAND xxd -i ${frag_out_path} ${frag_header} + MAIN_DEPENDENCY ${frag_out_path} + ) + + list(APPEND shader_headers ${vert_header} ${vert_out_path}) + list(APPEND shader_headers ${frag_header} ${frag_out_path}) + endforeach() + + file(GLOB slang_compute_shaders CONFIGURE_DEPENDS "${CMAKE_CURRENT_LIST_DIR}/source/*.slangc") + foreach(shader ${slang_compute_shaders}) + get_filename_component(filename ${shader} NAME_WLE) + set(shader_out_path ${CMAKE_CFG_INTDIR}/shaders) + + # Outputting short names for shader spv modules because due to xxd nonsense + # the name of the variable in the C header will be based on this file name + set(comp_out_path "${filename}_comp") + set(out_paths "${comp_out_path};") + + add_custom_command( + OUTPUT ${out_paths} + COMMAND ${CMAKE_COMMAND} -E make_directory ${shader_out_path} + COMMAND ${SLANG} -DTB_SHADER=1 -lang slang -profile sm_6_5 -stage compute -entry comp -target spirv $<$:-O0> $<$>:-g> -I ${shader_include_dir} -I ${engine_shader_include_dir} -o ${comp_out_path} ${shader} + MAIN_DEPENDENCY ${shader} + DEPENDS ${shader_includes} + ) + + set(comp_header "${shader_out_path}/${filename}_comp.h") + + # Use xxd to convert spv binary files to C headers that can be included + # Renaming shenanigans to work around old xxd versions not supporting the + # '-n' flag to rename the C variable + add_custom_command( + OUTPUT ${comp_header} + COMMAND xxd -i ${comp_out_path} ${comp_header} + MAIN_DEPENDENCY ${comp_out_path} + ) + + list(APPEND shader_headers ${comp_header} ${comp_out_path}) + endforeach() + + set("${out_shader_sources}" "${shader_sources}" PARENT_SCOPE) + set("${out_shader_headers}" "${shader_headers}" PARENT_SCOPE) +endfunction() + +# Helper function to cook assets +function(tb_cook_assets target_name out_assets_path) + set(assets_dest "assets") + if(ANDROID) + set(assets_dest "$/assets") + install(TARGETS ${out_target_name} + RUNTIME DESTINATION "$/lib/${arch}" + LIBRARY DESTINATION "$/lib/${arch}") + elseif(APPLE AND NOT IOS) + # Have to do this or else it won't be placed in the right part of the app package + install(TARGETS ${out_target_name} + RUNTIME DESTINATION "./../MacOS/" + BUNDLE DESTINATION "./../MacOS/") + else() + install(TARGETS ${out_target_name} + RUNTIME DESTINATION "." + BUNDLE DESTINATION "." + LIBRARY DESTINATION ".") + endif() + + # Cook scenes + file(GLOB_RECURSE source_scenes CONFIGURE_DEPENDS "${CMAKE_CURRENT_LIST_DIR}/assets/scenes/*.glb") + foreach(scene ${source_scenes}) + file(RELATIVE_PATH relpath ${CMAKE_CURRENT_LIST_DIR}/assets ${scene}) + get_filename_component(relpath ${relpath} DIRECTORY) + get_filename_component(filename ${scene} NAME_WE) + set(packed_scene ${CMAKE_CURRENT_BINARY_DIR}/$/assets/scenes/${filename}.glb) + + add_custom_command( + OUTPUT ${packed_scene} + COMMAND ${CMAKE_COMMAND} -E make_directory assets/${relpath} + COMMAND ${GLTFPACK} -cc -kn -km -ke -tc -i ${scene} -o ${packed_scene} + MAIN_DEPENDENCY ${scene} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/$ + ) + + list(APPEND packed_scenes ${packed_scene}) + endforeach() + list(APPEND assets ${packed_scenes}) + add_custom_target(${target_name}_scenes DEPENDS ${packed_scenes}) + + # Copy textures + file(GLOB_RECURSE source_textures CONFIGURE_DEPENDS "${CMAKE_CURRENT_LIST_DIR}/assets/textures/*.ktx2") + foreach(texture ${source_textures}) + file(RELATIVE_PATH relpath ${CMAKE_CURRENT_LIST_DIR}/assets ${texture}) + get_filename_component(relpath ${relpath} DIRECTORY) + get_filename_component(filename ${texture} NAME_WE) + set(packed ${CMAKE_CURRENT_BINARY_DIR}/$/assets/textures/${filename}.ktx2) + + message("Copying ${texture} to ${packed}") + add_custom_command( + OUTPUT ${packed} + COMMAND ${CMAKE_COMMAND} -E make_directory assets/${relpath} + COMMAND ${CMAKE_COMMAND} -E copy ${texture} ${packed} + MAIN_DEPENDENCY ${texture} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/$ + ) + + list(APPEND packed_textures ${packed}) + endforeach() + list(APPEND assets ${packed_textures}) + add_custom_target(${target_name}_textures DEPENDS ${packed_textures}) + + # Copy audio + file(GLOB_RECURSE source_audio CONFIGURE_DEPENDS "${CMAKE_CURRENT_LIST_DIR}/assets/audio/*.ogg" "${CMAKE_CURRENT_LIST_DIR}/assets/audio/*.wav") + foreach(audio ${source_audio}) + file(RELATIVE_PATH relpath ${CMAKE_CURRENT_LIST_DIR}/assets ${audio}) + get_filename_component(relpath ${relpath} DIRECTORY) + get_filename_component(filename ${audio} NAME) + set(packed ${CMAKE_CURRENT_BINARY_DIR}/$/assets/audio/${filename}) + + message("Copying ${audio} to ${packed}") + add_custom_command( + OUTPUT ${packed} + COMMAND ${CMAKE_COMMAND} -E make_directory assets/${relpath} + COMMAND ${CMAKE_COMMAND} -E copy ${audio} ${packed} + MAIN_DEPENDENCY ${audio} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/$ + ) + + list(APPEND packed_audio ${packed}) + endforeach() + list(APPEND assets ${packed_audio}) + add_custom_target(${target_name}_audio DEPENDS ${packed_audio}) + + # Generate asset database + set(source_assets ${packed_scenes} ${packed_textures} ${packed_audio}) + list(LENGTH source_assets ASSET_NUM) + set(generated_manifest "${CMAKE_CURRENT_BINARY_DIR}/config/${target_name}_assetmanifest.h") + # Add all assets to asset list + # Also keep track of which assets are scenes + math(EXPR asset_idx "0") + foreach(asset ${source_assets}) + get_filename_component(asset_ext ${asset} EXT BASE_DIR ${CMAKE_CURRENT_BINARY_DIR}/$) + get_filename_component(asset_path ${asset} ABSOLUTE BASE_DIR ${CMAKE_CURRENT_BINARY_DIR}/$) + file(RELATIVE_PATH relpath ${CMAKE_CURRENT_BINARY_DIR}/$/assets ${asset_path}) + if(asset_ext MATCHES ".glb") + list(APPEND scene_index_list ${asset_idx}) + endif() + string(APPEND ASSET_LIST "\"${relpath}\",") + math(EXPR asset_idx "${asset_idx} + 1") + endforeach() + # Add all scene indexes to the string that will be sent to the generated file + list(LENGTH scene_index_list SCENE_NUM) + foreach(idx ${scene_index_list}) + string(APPEND SCENE_LIST "${idx},") + endforeach() + + configure_file(${CMAKE_SOURCE_DIR}/source/tb_assetmanifest.h.in ${generated_manifest}) + add_custom_target(${target_name}_asset_manifest DEPENDS ${generated_manifest}) + + add_dependencies(${target_name} ${target_name}_scenes ${target_name}_textures ${target_name}_audio ${target_name}_asset_manifest) + + # Install cooked assets + install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/$/assets + DESTINATION ${assets_dest}) + + # Add a define to the target so we know that assets were cooked + # if they weren't we shouldn't even try to load the manifest + target_compile_definitions(${target_name} PRIVATE -DTB_COOKED=1) + + set(${out_assets_path} ${CMAKE_CURRENT_BINARY_DIR}/$/assets PARENT_SCOPE) +endfunction() diff --git a/cmake/tb_packages.cmake b/cmake/tb_packages.cmake new file mode 100644 index 00000000..ccbc01d8 --- /dev/null +++ b/cmake/tb_packages.cmake @@ -0,0 +1,54 @@ +include(${CMAKE_MODULE_PATH}/tb_platform.cmake) + +find_package(SDL3 CONFIG REQUIRED) +find_package(SDL3_mixer CONFIG REQUIRED) +find_package(volk CONFIG REQUIRED) +find_package(imgui CONFIG REQUIRED) +find_package(mimalloc CONFIG REQUIRED) +find_package(zstd CONFIG REQUIRED) +find_package(Ktx CONFIG REQUIRED) +find_package(Threads REQUIRED) +find_package(flecs CONFIG REQUIRED) +find_package(unofficial-joltphysics CONFIG REQUIRED) +if(TB_PROFILE_TRACY) + find_package(Tracy CONFIG REQUIRED) +endif() +if(UNIX) + if(NOT ANDROID) + add_library(zstd::zstd ALIAS zstd::libzstd_static) + endif() +endif() +find_package(json-c CONFIG REQUIRED) +find_package(meshoptimizer CONFIG REQUIRED) +find_package(enkiTS CONFIG REQUIRED) +find_package(mysofa CONFIG REQUIRED) +find_package(pffft CONFIG REQUIRED) +find_package(flatbuffers CONFIG REQUIRED) +find_package(steam-audio CONFIG REQUIRED) +find_package(VulkanHeaders CONFIG REQUIRED) +find_package(VulkanMemoryAllocator CONFIG REQUIRED) + +find_path(CGLTF_INCLUDE_DIRS "cgltf.h") + +find_program(GLTFPACK gltfpack + PATHS ${CMAKE_CURRENT_BINARY_DIR}/vcpkg_installed/${tb_host_triplet}/tools/meshoptimizer + REQUIRED) +find_program(SLANG slangc + PATHS ${CMAKE_CURRENT_BINARY_DIR}/vcpkg_installed/${tb_host_triplet}/tools/shader-slang + REQUIRED) + +# The list of all external targets to link +list(APPEND tb_library_list "$,flecs::flecs,flecs::flecs_static>") +list(APPEND tb_library_list "volk::volk") +list(APPEND tb_library_list "volk::volk_headers") +list(APPEND tb_library_list "imgui::imgui") +list(APPEND tb_library_list "mimalloc") +list(APPEND tb_library_list "mimalloc-static") +list(APPEND tb_library_list "KTX::ktx") +list(APPEND tb_library_list "json-c::json-c") +list(APPEND tb_library_list "meshoptimizer::meshoptimizer") +list(APPEND tb_library_list "unofficial::joltphysics::Jolt") +list(APPEND tb_library_list "enkiTS::enkiTS") +list(APPEND tb_library_list "steam-audio::phonon") +list(APPEND tb_library_list "Vulkan::Headers") +list(APPEND tb_library_list "GPUOpen::VulkanMemoryAllocator") \ No newline at end of file diff --git a/cmake/tb_platform.cmake b/cmake/tb_platform.cmake new file mode 100644 index 00000000..26cbf411 --- /dev/null +++ b/cmake/tb_platform.cmake @@ -0,0 +1,62 @@ +# Get target CPU architecture +include(${CMAKE_MODULE_PATH}/TargetArch.cmake) +target_architecture(arch) + +set(tb_windows 0) +set(tb_macos 0) +set(tb_linux 0) +set(tb_android 0) +set(tb_ios 0) +if(WIN32) + set(platform "windows") + set(tb_windows 1) +elseif(APPLE) + if(IOS) + set(platform "ios") + set(tb_ios 1) + else() + set(platform "macos") + set(tb_macos 1) + endif() +elseif(ANDROID) + set(platform "android") + set(tb_android 1) +elseif(UNIX) + set(platform "linux") + set(tb_linux 1) +else() + message(FATAL_ERROR "Unknown platform") +endif() + +# Host detection +if(CMAKE_HOST_WIN32) + set(host "windows") +elseif(CMAKE_HOST_UNIX) + if(CMAKE_HOST_APPLE) + set(host "osx") + else() + set(host "linux") + endif() +else() +message(FATAL_ERROR "Unknown host") +endif() + +set(tb_x64 0) +set(tb_arm64 0) +if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "AMD64") + set(host_arch "x64") + set(tb_x64 1) +elseif(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86_64") + set(host_arch "x64") + set(tb_x64 1) +elseif(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "arm64") + set(host_arch "arm64") + set(tb_arm64 1) +elseif(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "aarch64") + set(host_arch "arm64") + set(tb_arm64 1) +else() + message(FATAL_ERROR "Unknown host arch: ${CMAKE_HOST_SYSTEM_PROCESSOR}") +endif() + +set(tb_host_triplet "${host_arch}-${host}") diff --git a/include/tb_descriptor_buffer.h b/include/tb_descriptor_buffer.h index c9c40bdc..58266fa1 100644 --- a/include/tb_descriptor_buffer.h +++ b/include/tb_descriptor_buffer.h @@ -14,7 +14,7 @@ typedef struct TbDescriptorBuffer { TbBuffer buffer; TbHostBuffer host; uint8_t *data_ptr; -#ifndef FINAL +#ifndef TB_FINAL const char *name; #endif } TbDescriptorBuffer; diff --git a/include/tb_log.h b/include/tb_log.h index fe03537a..b04f05bf 100644 --- a/include/tb_log.h +++ b/include/tb_log.h @@ -8,7 +8,7 @@ enum { TB_LOG_CATEGORY_CUSTOM, }; -#ifdef FINAL +#ifdef TB_FINAL #define TB_LOG_VERBOSE(category, fmt, ...) #define TB_LOG_INFO(category, fmt, ...) #define TB_LOG_DEBUG(category, fmt, ...) diff --git a/include/tb_render_thread.h b/include/tb_render_thread.h index 51bc6d4b..07196e61 100644 --- a/include/tb_render_thread.h +++ b/include/tb_render_thread.h @@ -3,7 +3,7 @@ #include "tb_allocator.h" #include "tb_render_common.h" -#if !defined(FINAL) && !defined(__ANDROID__) +#if !defined(TB_FINAL) && !defined(__ANDROID__) #define VALIDATION #endif diff --git a/include/tb_vk_dbg.h b/include/tb_vk_dbg.h index 9af8cd06..41e9bb8c 100644 --- a/include/tb_vk_dbg.h +++ b/include/tb_vk_dbg.h @@ -4,7 +4,7 @@ #include "tb_sdl.h" #include "tb_simd.h" -#ifndef FINAL +#ifndef TB_FINAL typedef struct VkQueue_T *VkQueue; typedef struct VkCommandBuffer_T *VkCommandBuffer; typedef struct VkDevice_T *VkDevice; diff --git a/source/tb_assets.c b/source/tb_assets.c index e734e7a1..7fecb8df 100644 --- a/source/tb_assets.c +++ b/source/tb_assets.c @@ -69,7 +69,7 @@ cgltf_data *tb_read_glb(TbAllocator gp_alloc, const char *path) { TB_CHECK_RETURN(res == cgltf_result_success, "Failed to load glb buffers.", NULL); -#if !defined(FINAL) +#if !defined(TB_FINAL) res = cgltf_validate(data); TB_CHECK_RETURN(res == cgltf_result_success, "Failed to validate glb.", NULL); #endif diff --git a/source/tb_config.h.in b/source/tb_config.h.in index cb407fdd..17d63547 100644 --- a/source/tb_config.h.in +++ b/source/tb_config.h.in @@ -2,12 +2,11 @@ // clang-format off -#define TB_ENGINE_NAME "@ENGINE_NAME@" -#define TB_ENGINE_VERSION_MAJOR @ENGINE_VERSION_MAJOR@ -#define TB_ENGINE_VERSION_MINOR @ENGINE_VERSION_MINOR@ -#define TB_ENGINE_VERSION_PATCH @ENGINE_VERSION_PATCH@ +#define TB_ENGINE_VERSION_MAJOR @CMAKE_PROJECT_VERSION_MAJOR@ +#define TB_ENGINE_VERSION_MINOR @CMAKE_PROJECT_VERSION_MINOR@ +#define TB_ENGINE_VERSION_PATCH @CMAKE_PROJECT_VERSION_PATCH@ #define TB_ENGINE_VERSION \ - "@ENGINE_VERSION_MAJOR@.@ENGINE_VERSION_MINOR@.@ENGINE_VERSION_PATCH@" + "@CMAKE_PROJECT_VERSION_MAJOR@.@CMAKE_PROJECT_VERSION_MINOR@.@CMAKE_PROJECT_VERSION_PATCH@" // clang-format on diff --git a/source/tb_coreui_system.c b/source/tb_coreui_system.c index 28b21a59..fbd87c19 100644 --- a/source/tb_coreui_system.c +++ b/source/tb_coreui_system.c @@ -47,8 +47,6 @@ void destroy_coreui_system(TbCoreUISystem *self) { void coreui_show_about(bool *open) { if (igBegin("About Toybox", open, 0)) { igText("Version: %s", TB_ENGINE_VERSION); - igText("Platform: %s", TB_PLATFORM); - igText("Arch: %s", TB_ARCH); igText("Git Hash: %s", GIT_COMMIT_HASH); igEnd(); } diff --git a/source/tb_descriptor_buffer.c b/source/tb_descriptor_buffer.c index 2e341811..4d754013 100644 --- a/source/tb_descriptor_buffer.c +++ b/source/tb_descriptor_buffer.c @@ -27,7 +27,7 @@ VkResult tb_resize_desc_buffer(TbRenderSystem *rnd_sys, uint32_t capacity, VK_BUFFER_USAGE_TRANSFER_DST_BIT, }; const char *buf_name = ""; -#ifndef FINAL +#ifndef TB_FINAL buf_name = out_buf->name; #endif err = tb_rnd_sys_create_gpu_buffer(rnd_sys, &create_info, buf_name, @@ -63,7 +63,7 @@ VkResult tb_create_descriptor_buffer(TbRenderSystem *rnd_sys, VkDescriptorSetLayout layout, const char *name, uint32_t capacity, TbDescriptorBuffer *out_buf) { -#if FINAL +#if TB_FINAL (void)name; #endif const tb_auto alignment = @@ -80,7 +80,7 @@ VkResult tb_create_descriptor_buffer(TbRenderSystem *rnd_sys, .layout_size = layout_size, }; -#ifndef FINAL +#ifndef TB_FINAL const uint32_t name_len = SDL_strlen(name) + 1; char *buf_name = tb_alloc_nm_tp(rnd_sys->gp_alloc, name_len, char); SDL_strlcpy(buf_name, name, name_len); diff --git a/source/tb_render_thread.c b/source/tb_render_thread.c index de18a8de..293239b7 100644 --- a/source/tb_render_thread.c +++ b/source/tb_render_thread.c @@ -234,7 +234,7 @@ bool init_instance(TbAllocator tmp_alloc, const VkAllocationCallbacks *vk_alloc, app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; app_info.pApplicationName = "Toybox"; app_info.applicationVersion = VK_MAKE_VERSION(0, 1, 0); - app_info.pEngineName = TB_ENGINE_NAME; + app_info.pEngineName = "Toybox"; app_info.engineVersion = VK_MAKE_VERSION(TB_ENGINE_VERSION_MAJOR, TB_ENGINE_VERSION_MINOR, TB_ENGINE_VERSION_PATCH); diff --git a/source/tb_time_of_day_system.c b/source/tb_time_of_day_system.c index 6f260c01..cf17be5b 100644 --- a/source/tb_time_of_day_system.c +++ b/source/tb_time_of_day_system.c @@ -123,7 +123,7 @@ void time_of_day_tick(ecs_iter_t *it) { TracyCZoneEnd(ctx); } -#ifndef FINAL +#ifndef TB_FINAL typedef struct TbTimeOfDayContext { bool *coreui; } TbTimeOfDayContext; @@ -169,7 +169,7 @@ void tb_register_time_of_day_sys(TbWorld *world) { ECS_SYSTEM(ecs, time_of_day_tick, EcsOnUpdate, [inout] TbTimeOfDayComponent, [inout] TbSkyComponent, [inout] TbDirectionalLightComponent, [inout] TbTransformComponent); -#ifndef FINAL +#ifndef TB_FINAL tb_auto coreui = ecs_singleton_get_mut(ecs, TbCoreUISystem); ECS_COMPONENT_DEFINE(ecs, TbTimeOfDayContext); @@ -183,7 +183,7 @@ void tb_register_time_of_day_sys(TbWorld *world) { } void tb_unregister_time_of_day_sys(TbWorld *world) { (void)world; -#ifndef FINAL +#ifndef TB_FINAL ecs_singleton_remove(world->ecs, TbTimeOfDayContext); #endif } diff --git a/source/tb_visual_logging_system.c b/source/tb_visual_logging_system.c index 8ddf5132..d9717aa4 100644 --- a/source/tb_visual_logging_system.c +++ b/source/tb_visual_logging_system.c @@ -399,7 +399,7 @@ TbVisualLoggingSystem create_visual_logging_system( void destroy_visual_logging_system(ecs_world_t *ecs, TbVisualLoggingSystem *self) { (void)ecs; -#ifndef FINAL +#ifndef TB_FINAL tb_rnd_destroy_pipe_layout(self->rnd_sys, self->pipe_layout); tb_shader_destroy(ecs, self->shader); @@ -410,7 +410,7 @@ void destroy_visual_logging_system(ecs_world_t *ecs, void vlog_draw_tick(ecs_iter_t *it) { (void)it; -#ifndef FINAL +#ifndef TB_FINAL TracyCZoneNC(ctx, "Visual Logging System Draw", TracyCategoryColorCore, true); TbVisualLoggingSystem *sys = ecs_field(it, TbVisualLoggingSystem, 1); @@ -484,7 +484,7 @@ void vlog_draw_tick(ecs_iter_t *it) { void vlog_ui_tick(ecs_iter_t *it) { (void)it; -#ifndef FINAL +#ifndef TB_FINAL TracyCZoneNC(ctx, "Visual Logging System UI", TracyCategoryColorCore, true); TbVisualLoggingSystem *sys = ecs_field(it, TbVisualLoggingSystem, 1); @@ -625,21 +625,21 @@ VLogShape *vlog_acquire_frame_shape(TbVisualLoggingSystem *vlog, void tb_vlog_begin_recording(TbVisualLoggingSystem *vlog) { (void)vlog; -#ifndef FINAL +#ifndef TB_FINAL TB_CHECK(vlog->recording == false, "Visual Logger is already recording"); vlog->recording = true; #endif } void tb_vlog_end_recording(TbVisualLoggingSystem *vlog) { (void)vlog; -#ifndef FINAL +#ifndef TB_FINAL TB_CHECK(vlog->recording == true, "Visual Logger is not recording"); vlog->recording = false; #endif } void tb_vlog_clear(TbVisualLoggingSystem *vlog) { (void)vlog; -#ifndef FINAL +#ifndef TB_FINAL TB_DYN_ARR_CLEAR(vlog->frames); #endif } @@ -650,7 +650,7 @@ void tb_vlog_line(TbVisualLoggingSystem *vlog, float3 start, float3 end, (void)start; (void)end; (void)color; -#ifndef FINAL +#ifndef TB_FINAL if (!vlog->recording) { return; } @@ -672,7 +672,7 @@ void tb_vlog_location(TbVisualLoggingSystem *vlog, float3 position, (void)position; (void)radius; (void)color; -#ifndef FINAL +#ifndef TB_FINAL if (!vlog->recording) { return; } diff --git a/source/tb_vk_dbg.c b/source/tb_vk_dbg.c index 35e436b1..70008e68 100644 --- a/source/tb_vk_dbg.c +++ b/source/tb_vk_dbg.c @@ -2,7 +2,7 @@ #include "tb_vk.h" -#ifndef FINAL +#ifndef TB_FINAL void queue_begin_label(VkQueue queue, const char *label, float4 color) { if (vkQueueBeginDebugUtilsLabelEXT) { diff --git a/source/tb_world.c b/source/tb_world.c index 8a3cb4e0..3eb098fe 100644 --- a/source/tb_world.c +++ b/source/tb_world.c @@ -138,7 +138,7 @@ void tb_register_component(const char *name, TbRegisterComponentFn reg_fn, TracyCZoneEnd(ctx); } -#ifndef FINAL +#ifndef TB_FINAL int32_t tb_check_info_mode(int32_t argc, char *const *argv) { static const char *info_mode_str = "--info"; for (int32_t i = 0; i < argc; ++i) { @@ -218,7 +218,7 @@ bool tb_create_world(const TbWorldDesc *desc, TbWorld *world) { } // Run optional info mode in non-final builds only -#ifndef FINAL +#ifndef TB_FINAL if (tb_check_info_mode(desc->argc, desc->argv) > 0) { tb_write_info(world); TracyCZoneEnd(ctx); @@ -252,7 +252,7 @@ bool tb_create_world(const TbWorldDesc *desc, TbWorld *world) { TracyCZoneEnd(ctx); } -#ifndef FINAL +#ifndef TB_FINAL // By setting this singleton we allow the application to connect to the // flecs explorer ecs_singleton_set(ecs, EcsRest, {0});