Another attempt
This commit is contained in:
parent
e6a2fb9c22
commit
089e7493b6
@ -7,14 +7,17 @@ on:
|
||||
pull_request:
|
||||
workflow_dispatch:
|
||||
schedule:
|
||||
- cron: "@weekly"
|
||||
- cron: "0 3 * * 1"
|
||||
|
||||
jobs:
|
||||
build:
|
||||
# ---------------------------------------------------------------------------
|
||||
# 1. Nix build: validates the flake build and produces the SPIR-V shaders
|
||||
# (SPIR-V is OS independent, and slangc is not packaged in Debian).
|
||||
# ---------------------------------------------------------------------------
|
||||
nix:
|
||||
runs-on: ubuntu-latest
|
||||
container: git.alexdelcamp.fr/alexandre_1a/flake-actions:latest
|
||||
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
@ -22,86 +25,135 @@ jobs:
|
||||
submodules: recursive
|
||||
fetch-depth: 0
|
||||
|
||||
|
||||
- name: Configure
|
||||
run: |
|
||||
nix develop --command cmake -S . -B build \
|
||||
-G Ninja \
|
||||
-DCMAKE_BUILD_TYPE=Release \
|
||||
-DVULKANENGINE_PORTABLE=ON
|
||||
|
||||
- name: Debug Nix linker environment
|
||||
run: |
|
||||
nix develop --command bash -c '
|
||||
echo "CC=$CC"
|
||||
echo "CXX=$CXX"
|
||||
echo "LD=$LD"
|
||||
echo
|
||||
echo "NIX_LDFLAGS:"
|
||||
printf "%s\n" "$NIX_LDFLAGS"
|
||||
echo
|
||||
echo "NIX_CFLAGS_LINK:"
|
||||
printf "%s\n" "$NIX_CFLAGS_LINK"
|
||||
'
|
||||
-DCMAKE_BUILD_TYPE=Release
|
||||
|
||||
- name: Build
|
||||
run: |
|
||||
nix develop --command cmake --build build \
|
||||
--parallel 2
|
||||
nix develop --command cmake --build build --parallel 2
|
||||
|
||||
- name: Install ELF inspection tools
|
||||
- name: Upload shaders
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: shaders
|
||||
path: build/engine/shaders
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# 2. Debian 12 builds: portable (static) and bundle (bin/ + lib/)
|
||||
# Built on glibc 2.36 => runs on Debian 12 and anything newer.
|
||||
# ---------------------------------------------------------------------------
|
||||
release:
|
||||
needs: nix
|
||||
runs-on: ubuntu-latest
|
||||
container: debian:12
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
variant: [PORTABLE, BUNDLE]
|
||||
|
||||
steps:
|
||||
# git + nodejs must exist before checkout (JS actions run in the container)
|
||||
- name: Dependencies
|
||||
run: |
|
||||
nix profile install \
|
||||
nixpkgs#binutils \
|
||||
nixpkgs#file \
|
||||
nixpkgs#gnugrep
|
||||
apt-get update
|
||||
apt-get install -y --no-install-recommends \
|
||||
git ca-certificates nodejs \
|
||||
build-essential cmake ninja-build pkg-config \
|
||||
libwayland-dev libwayland-bin wayland-protocols libxkbcommon-dev \
|
||||
libx11-dev libxrandr-dev libxinerama-dev libxcursor-dev libxi-dev
|
||||
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: recursive
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Git safe directory
|
||||
run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
|
||||
|
||||
- name: Download shaders
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: shaders
|
||||
path: prebuilt-shaders
|
||||
|
||||
- name: Configure
|
||||
run: |
|
||||
cmake -S . -B build -G Ninja \
|
||||
-DCMAKE_BUILD_TYPE=Release \
|
||||
-DVULKANENGINE_FETCH_DEPS=ON \
|
||||
-DVULKANENGINE_${{ matrix.variant }}=ON \
|
||||
-DVULKANENGINE_PREBUILT_SHADERS="$PWD/prebuilt-shaders"
|
||||
|
||||
- name: Build
|
||||
run: cmake --build build --parallel 2
|
||||
|
||||
- name: Install
|
||||
run: cmake --install build --prefix dist --strip
|
||||
|
||||
- name: Check binaries
|
||||
shell: bash
|
||||
run: |
|
||||
for bin in build/server/server build/engine/engine; do
|
||||
echo "========== $bin =========="
|
||||
set -euo pipefail
|
||||
for b in dist/bin/engine dist/bin/server; do
|
||||
echo "========== $b =========="
|
||||
readelf -l "$b" | grep 'program interpreter'
|
||||
readelf -d "$b" | grep -E 'RPATH|RUNPATH|NEEDED' || true
|
||||
|
||||
file "$bin"
|
||||
if strings "$b" | grep -q '/nix/store'; then
|
||||
echo "ERROR: $b references /nix/store"; exit 1
|
||||
fi
|
||||
|
||||
echo "--- INTERPRETER ---"
|
||||
readelf -l "$bin" | grep 'Requesting program interpreter' || true
|
||||
# The loader must come from volk (dlopen), never from NEEDED
|
||||
if readelf -d "$b" | grep -q 'libvulkan'; then
|
||||
echo "ERROR: $b links libvulkan directly"; exit 1
|
||||
fi
|
||||
|
||||
echo "--- DYNAMIC SECTION ---"
|
||||
readelf -d "$bin" | grep -E 'RPATH|RUNPATH|NEEDED' || true
|
||||
if [ "${{ matrix.variant }}" = "PORTABLE" ]; then
|
||||
if readelf -d "$b" | grep -Eq 'libstdc\+\+|libgcc_s'; then
|
||||
echo "ERROR: $b is not static for libstdc++/libgcc"; exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "--- NIX STORE REFERENCES ---"
|
||||
strings "$bin" | grep '/nix/store' || true
|
||||
max=$(objdump -T "$b" | grep -o 'GLIBC_[0-9.]*' | sed 's/GLIBC_//' | sort -uV | tail -1 || true)
|
||||
echo "Highest GLIBC symbol: ${max:-none}"
|
||||
if [ -n "$max" ] && [ "$(printf '%s\n%s\n' "$max" 2.36 | sort -V | tail -1)" != "2.36" ]; then
|
||||
echo "ERROR: needs glibc $max (> 2.36)"; exit 1
|
||||
fi
|
||||
|
||||
if ldd "$b" | grep 'not found'; then
|
||||
echo "ERROR: unresolved libraries in $b"; exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
if [ "${{ matrix.variant }}" = "BUNDLE" ]; then
|
||||
echo "========== lib/ =========="
|
||||
ls -la dist/lib
|
||||
fi
|
||||
|
||||
# tar keeps permissions and symlinks; artifact zips do not
|
||||
- name: Package
|
||||
run: |
|
||||
tar -C dist -czf VulkanEngine-${{ matrix.variant }}-linux-x86_64.tar.gz .
|
||||
|
||||
- name: Upload build
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: VulkanEngine-linux-x86_64
|
||||
path: build/
|
||||
|
||||
- name: Verify Nix independence
|
||||
run: |
|
||||
mkdir -p /tmp/vulkan-test
|
||||
cp build/server/server /tmp/vulkan-test/
|
||||
cp build/engine/engine /tmp/vulkan-test/
|
||||
|
||||
echo "=== Nix references ==="
|
||||
if strings /tmp/vulkan-test/server | grep -q '/nix/store'; then
|
||||
echo "ERROR: server contains /nix/store reference"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if strings /tmp/vulkan-test/engine | grep -q '/nix/store'; then
|
||||
echo "ERROR: engine contains /nix/store reference"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "OK: no /nix/store references"
|
||||
name: VulkanEngine-${{ matrix.variant }}-linux-x86_64
|
||||
path: VulkanEngine-${{ matrix.variant }}-linux-x86_64.tar.gz
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
notify:
|
||||
needs: [nix, release]
|
||||
if: always()
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Notify routine
|
||||
if: always()
|
||||
run: |
|
||||
curl \
|
||||
-H "Title: [Routine] VulkanEngine build" \
|
||||
-d "Build finished (status: ${{ job.status }})" \
|
||||
-d "Build finished (nix: ${{ needs.nix.result }}, release: ${{ needs.release.result }})" \
|
||||
https://ntfy.alexdelcamp.fr/FlakeBuild
|
||||
|
||||
284
CMakeLists.txt
284
CMakeLists.txt
@ -1,16 +1,24 @@
|
||||
cmake_minimum_required (VERSION 3.29)
|
||||
cmake_minimum_required(VERSION 3.25) # Debian 12 ships 3.25
|
||||
project(VulkanEngine)
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/CMake")
|
||||
|
||||
include(BuildInfo)
|
||||
include(FetchContent)
|
||||
#LTO
|
||||
# LTO
|
||||
include(CheckIPOSupported)
|
||||
check_ipo_supported(RESULT LTO_SUPPORTED OUTPUT LTO_ERROR)
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Build modes
|
||||
# (default) Nix dev build, deps from the Nix shell
|
||||
# FETCH_DEPS + PORTABLE Single directory, everything static except
|
||||
# glibc (and the Vulkan loader, loaded via volk)
|
||||
# FETCH_DEPS + BUNDLE bin/ + lib/, project libs shared in lib/,
|
||||
# system libstdc++ / libc / loader are used
|
||||
# ---------------------------------------------------------------------------
|
||||
option(VULKANENGINE_PORTABLE
|
||||
"Build a Linux binary without Nix-specific runtime paths"
|
||||
"Build a Linux binary without Nix-specific runtime paths (static libs)"
|
||||
OFF
|
||||
)
|
||||
|
||||
@ -19,6 +27,24 @@ option(VULKANENGINE_BUNDLE
|
||||
OFF
|
||||
)
|
||||
|
||||
option(VULKANENGINE_FETCH_DEPS
|
||||
"Fetch dependencies with FetchContent instead of using system/Nix packages"
|
||||
OFF
|
||||
)
|
||||
|
||||
set(VULKANENGINE_PREBUILT_SHADERS "" CACHE PATH
|
||||
"Directory containing precompiled .spv files (skips glslang/slangc)"
|
||||
)
|
||||
|
||||
if(VULKANENGINE_PORTABLE AND VULKANENGINE_BUNDLE)
|
||||
message(FATAL_ERROR "VULKANENGINE_PORTABLE and VULKANENGINE_BUNDLE are mutually exclusive")
|
||||
endif()
|
||||
|
||||
if((VULKANENGINE_PORTABLE OR VULKANENGINE_BUNDLE) AND NOT VULKANENGINE_FETCH_DEPS)
|
||||
message(FATAL_ERROR
|
||||
"PORTABLE/BUNDLE builds need -DVULKANENGINE_FETCH_DEPS=ON "
|
||||
"(Nix libraries must not leak into the result)")
|
||||
endif()
|
||||
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
|
||||
@ -26,10 +52,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
if(VULKANENGINE_PORTABLE)
|
||||
message(STATUS "VulkanEngine: PORTABLE build")
|
||||
|
||||
set(CMAKE_SKIP_BUILD_RPATH TRUE)
|
||||
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
|
||||
set(CMAKE_INSTALL_RPATH "")
|
||||
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH FALSE)
|
||||
set(CMAKE_SKIP_RPATH TRUE)
|
||||
|
||||
elseif(VULKANENGINE_BUNDLE)
|
||||
message(STATUS "VulkanEngine: BUNDLE build")
|
||||
@ -40,9 +63,11 @@ elseif(VULKANENGINE_BUNDLE)
|
||||
# Executables are installed in bin/
|
||||
# Libraries are installed in lib/
|
||||
set(CMAKE_INSTALL_RPATH "$ORIGIN/../lib")
|
||||
|
||||
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH FALSE)
|
||||
|
||||
# Every shared lib we build ends up here, installed as-is into lib/
|
||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
|
||||
|
||||
else()
|
||||
message(STATUS "VulkanEngine: normal build")
|
||||
endif()
|
||||
@ -53,9 +78,90 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||||
set(CMAKE_AR "${GCC_AR}")
|
||||
set(CMAKE_RANLIB "${GCC_RANLIB}")
|
||||
endif()
|
||||
# Fetch required things
|
||||
# fastgltf because it's not in nixpkgs
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Dependencies
|
||||
# ---------------------------------------------------------------------------
|
||||
set(ENGINE_EXTRA_DEFINITIONS "")
|
||||
|
||||
if(VULKANENGINE_FETCH_DEPS)
|
||||
# Portable = static libs, bundle = shared libs (in lib/)
|
||||
if(VULKANENGINE_BUNDLE)
|
||||
set(BUILD_SHARED_LIBS ON)
|
||||
else()
|
||||
set(BUILD_SHARED_LIBS OFF)
|
||||
endif()
|
||||
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
||||
|
||||
set(VULKAN_HEADERS_ENABLE_MODULE OFF CACHE BOOL "" FORCE)
|
||||
set(VULKAN_HEADERS_ENABLE_TESTS OFF CACHE BOOL "" FORCE)
|
||||
set(VULKAN_HEADERS_ENABLE_INSTALL OFF CACHE BOOL "" FORCE)
|
||||
set(VOLK_PULL_IN_VULKAN OFF CACHE BOOL "" FORCE)
|
||||
set(VOLK_INSTALL OFF CACHE BOOL "" FORCE)
|
||||
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
|
||||
set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
|
||||
set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
|
||||
set(GLFW_INSTALL OFF CACHE BOOL "" FORCE)
|
||||
set(FMT_INSTALL OFF CACHE BOOL "" FORCE)
|
||||
set(FMT_TEST OFF CACHE BOOL "" FORCE)
|
||||
set(SIMDJSON_DEVELOPER_MODE OFF CACHE BOOL "" FORCE)
|
||||
set(CLI11_BUILD_TESTS OFF CACHE BOOL "" FORCE)
|
||||
set(CLI11_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
|
||||
set(GLM_BUILD_TESTS OFF CACHE BOOL "" FORCE)
|
||||
set(GLM_BUILD_LIBRARY OFF CACHE BOOL "" FORCE)
|
||||
|
||||
# Keep these versions in sync with your nixpkgs (check the tags exist)
|
||||
FetchContent_Declare(VulkanHeaders
|
||||
GIT_REPOSITORY https://github.com/KhronosGroup/Vulkan-Headers.git
|
||||
GIT_TAG v1.4.309)
|
||||
FetchContent_Declare(volk
|
||||
GIT_REPOSITORY https://github.com/zeux/volk.git
|
||||
GIT_TAG 1.4.304)
|
||||
FetchContent_Declare(VMA
|
||||
GIT_REPOSITORY https://github.com/GPUOpen-LibrariesAndPatches/VulkanMemoryAllocator.git
|
||||
GIT_TAG v3.2.1)
|
||||
FetchContent_Declare(glfw
|
||||
GIT_REPOSITORY https://github.com/glfw/glfw.git
|
||||
GIT_TAG 3.4)
|
||||
FetchContent_Declare(vk-bootstrap
|
||||
GIT_REPOSITORY https://github.com/charles-lunarg/vk-bootstrap.git
|
||||
GIT_TAG v1.4.309)
|
||||
FetchContent_Declare(fmt
|
||||
GIT_REPOSITORY https://github.com/fmtlib/fmt.git
|
||||
GIT_TAG 11.0.2)
|
||||
FetchContent_Declare(CLI11
|
||||
GIT_REPOSITORY https://github.com/CLIUtils/CLI11.git
|
||||
GIT_TAG v2.4.2)
|
||||
FetchContent_Declare(glm
|
||||
GIT_REPOSITORY https://github.com/g-truc/glm.git
|
||||
GIT_TAG 1.0.1)
|
||||
FetchContent_Declare(simdjson
|
||||
GIT_REPOSITORY https://github.com/simdjson/simdjson.git
|
||||
GIT_TAG v3.10.1)
|
||||
|
||||
# Vulkan headers first: vk-bootstrap and volk pick up Vulkan::Headers
|
||||
FetchContent_MakeAvailable(VulkanHeaders)
|
||||
FetchContent_MakeAvailable(volk VMA glfw vk-bootstrap fmt CLI11 glm simdjson)
|
||||
|
||||
target_link_libraries(volk PUBLIC Vulkan::Headers)
|
||||
|
||||
# No link-time dependency on libvulkan: functions come from volk
|
||||
list(APPEND ENGINE_EXTRA_DEFINITIONS
|
||||
VK_NO_PROTOTYPES
|
||||
VMA_STATIC_VULKAN_FUNCTIONS=0
|
||||
VMA_DYNAMIC_VULKAN_FUNCTIONS=1
|
||||
)
|
||||
else()
|
||||
# Nix path (unchanged)
|
||||
find_package( glfw3 REQUIRED )
|
||||
find_package( glm REQUIRED )
|
||||
find_package( VulkanMemoryAllocator CONFIG REQUIRED )
|
||||
find_package( CLI11 REQUIRED )
|
||||
find_package( simdjson REQUIRED )
|
||||
endif()
|
||||
|
||||
# fastgltf because it's not in nixpkgs (declared after the switch above so it
|
||||
# inherits BUILD_SHARED_LIBS)
|
||||
FetchContent_Declare(
|
||||
fastgltf
|
||||
GIT_REPOSITORY https://github.com/spnda/fastgltf.git
|
||||
@ -63,28 +169,25 @@ FetchContent_Declare(
|
||||
)
|
||||
FetchContent_MakeAvailable(fastgltf)
|
||||
|
||||
# Find all package dependencies
|
||||
find_package( glfw3 REQUIRED )
|
||||
find_package( glm REQUIRED )
|
||||
find_package( VulkanMemoryAllocator CONFIG REQUIRED )
|
||||
find_package( CLI11 REQUIRED )
|
||||
find_package( simdjson REQUIRED )
|
||||
# ---------------------------------------------------------------------------
|
||||
# Shader compilers (not needed when precompiled shaders are provided)
|
||||
# ---------------------------------------------------------------------------
|
||||
if(NOT VULKANENGINE_PREBUILT_SHADERS)
|
||||
add_executable (glslang::validator IMPORTED)
|
||||
find_program (
|
||||
GLSLANG_VALIDATOR
|
||||
"glslangValidator"
|
||||
HINTS $ENV{VULKAN_SDK}/bin
|
||||
REQUIRED
|
||||
)
|
||||
|
||||
# Shader compilers
|
||||
add_executable (glslang::validator IMPORTED)
|
||||
find_program (
|
||||
GLSLANG_VALIDATOR
|
||||
"glslangValidator"
|
||||
HINTS $ENV{VULKAN_SDK}/bin
|
||||
REQUIRED
|
||||
)
|
||||
set_property (
|
||||
TARGET glslang::validator
|
||||
PROPERTY IMPORTED_LOCATION "${GLSLANG_VALIDATOR}"
|
||||
)
|
||||
|
||||
set_property (
|
||||
TARGET glslang::validator
|
||||
PROPERTY IMPORTED_LOCATION "${GLSLANG_VALIDATOR}"
|
||||
)
|
||||
|
||||
find_program(SLANGC_EXECUTABLE slangc HINTS $ENV{VULKAN_SDK}/bin REQUIRED)
|
||||
find_program(SLANGC_EXECUTABLE slangc HINTS $ENV{VULKAN_SDK}/bin REQUIRED)
|
||||
endif()
|
||||
|
||||
|
||||
# Helper functions to build shaders
|
||||
@ -130,7 +233,7 @@ endfunction()
|
||||
|
||||
# A function to automate executables aditions
|
||||
function ( addBinary BINARY_NAME )
|
||||
cmake_parse_arguments ( BINARY "IMGUI;LICENSE" "SOURCE" "SHADERS;SLANG_SHADERS;LIBS;TEXTURES;MODELS" ${ARGN} )
|
||||
cmake_parse_arguments ( BINARY "IMGUI;LICENSE" "SOURCE" "SHADERS;SLANG_SHADERS;SLANG_ENTRIES;LIBS;TEXTURES;MODELS" ${ARGN} )
|
||||
if (DEFINED BINARY_SOURCE)
|
||||
add_executable ( ${BINARY_NAME} src/${BINARY_SOURCE}.cpp )
|
||||
endif()
|
||||
@ -156,7 +259,13 @@ function ( addBinary BINARY_NAME )
|
||||
set_target_properties(${BINARY_NAME} PROPERTIES INTERPROCEDURAL_OPTIMIZATION TRUE)
|
||||
message("Enabled LTO")
|
||||
endif()
|
||||
set_target_properties(${BINARY_NAME} PROPERTIES CXX_SCAN_FOR_MODULES OFF)
|
||||
|
||||
# Portable: libstdc++/libgcc statically linked so the binary does not depend
|
||||
# on the host's version. NOT done for bundle: the shared libs in lib/ use the
|
||||
# system libstdc++, and mixing two copies in one process is asking for trouble.
|
||||
if(VULKANENGINE_PORTABLE)
|
||||
target_link_options(${BINARY_NAME} PRIVATE -static-libstdc++ -static-libgcc)
|
||||
endif()
|
||||
|
||||
# Define VULKAN_HPP_HANDLE_ERROR_OUT_OF_DATE_AS_SUCCESS to treat VK_ERROR_OUT_OF_DATE_KHR as a success code
|
||||
target_compile_definitions (
|
||||
@ -166,6 +275,7 @@ function ( addBinary BINARY_NAME )
|
||||
$<$<CONFIG:Debug>:DEBUG> # So CMAKE expose a #define DEBUG for debug builds
|
||||
# Exposes versions
|
||||
BUILD_ID="${ENGINE_VERSION}"
|
||||
${ENGINE_EXTRA_DEFINITIONS}
|
||||
)
|
||||
|
||||
if(BINARY_IMGUI)
|
||||
@ -186,6 +296,11 @@ function ( addBinary BINARY_NAME )
|
||||
${CMAKE_SOURCE_DIR}/include/imgui/backends/imgui_impl_glfw.cpp
|
||||
${CMAKE_SOURCE_DIR}/include/imgui/backends/imgui_impl_vulkan.cpp
|
||||
)
|
||||
|
||||
# imgui's Vulkan backend must use volk when there is no linked loader
|
||||
if(VULKANENGINE_FETCH_DEPS)
|
||||
target_compile_definitions(${BINARY_NAME} PRIVATE IMGUI_IMPL_VULKAN_USE_VOLK)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
||||
@ -196,38 +311,48 @@ function ( addBinary BINARY_NAME )
|
||||
|
||||
if(DEFINED BINARY_SHADERS)
|
||||
set(SHADER_OUTPUT_DIR ${CMAKE_BINARY_DIR}/${BINARY_NAME}/shaders)
|
||||
set(ALL_SPV_FILES "")
|
||||
set(EXPANDED_SHADERS "")
|
||||
|
||||
foreach(SHADER_PATTERN ${BINARY_SHADERS})
|
||||
if(SHADER_PATTERN MATCHES "[*?]")
|
||||
file(GLOB SHADER_FILES CONFIGURE_DEPENDS ${SHADER_PATTERN})
|
||||
list(APPEND EXPANDED_SHADERS ${SHADER_FILES})
|
||||
else()
|
||||
list(APPEND EXPANDED_SHADERS ${SHADER_PATTERN})
|
||||
if(VULKANENGINE_PREBUILT_SHADERS)
|
||||
# Copy the .spv produced by the Nix job instead of compiling them
|
||||
file(GLOB PREBUILT_SPV CONFIGURE_DEPENDS "${VULKANENGINE_PREBUILT_SHADERS}/*.spv")
|
||||
if(NOT PREBUILT_SPV)
|
||||
message(FATAL_ERROR "No .spv found in ${VULKANENGINE_PREBUILT_SHADERS}")
|
||||
endif()
|
||||
endforeach()
|
||||
file(COPY ${PREBUILT_SPV} DESTINATION ${SHADER_OUTPUT_DIR})
|
||||
else()
|
||||
set(ALL_SPV_FILES "")
|
||||
set(EXPANDED_SHADERS "")
|
||||
|
||||
foreach(SHADER_SRC ${EXPANDED_SHADERS})
|
||||
if(NOT IS_ABSOLUTE ${SHADER_SRC})
|
||||
set(SHADER_SRC ${CMAKE_CURRENT_SOURCE_DIR}/${SHADER_SRC})
|
||||
endif()
|
||||
get_filename_component(EXT ${SHADER_SRC} EXT)
|
||||
if(EXT STREQUAL ".slang")
|
||||
addSlangShader(${SHADER_SRC} "${BINARY_SLANG_ENTRIES}" ${SHADER_OUTPUT_DIR})
|
||||
list(APPEND ALL_SPV_FILES ${SPV_FILE})
|
||||
else()
|
||||
addGlslShader(${SHADER_SRC} ${SHADER_OUTPUT_DIR})
|
||||
list(APPEND ALL_SPV_FILES ${SPV_FILE})
|
||||
endif()
|
||||
endforeach()
|
||||
foreach(SHADER_PATTERN ${BINARY_SHADERS})
|
||||
if(SHADER_PATTERN MATCHES "[*?]")
|
||||
file(GLOB SHADER_FILES CONFIGURE_DEPENDS ${SHADER_PATTERN})
|
||||
list(APPEND EXPANDED_SHADERS ${SHADER_FILES})
|
||||
else()
|
||||
list(APPEND EXPANDED_SHADERS ${SHADER_PATTERN})
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
add_custom_target(shaders_${BINARY_NAME} DEPENDS ${ALL_SPV_FILES})
|
||||
add_dependencies(${BINARY_NAME} shaders_${BINARY_NAME})
|
||||
foreach(SHADER_SRC ${EXPANDED_SHADERS})
|
||||
if(NOT IS_ABSOLUTE ${SHADER_SRC})
|
||||
set(SHADER_SRC ${CMAKE_CURRENT_SOURCE_DIR}/${SHADER_SRC})
|
||||
endif()
|
||||
get_filename_component(EXT ${SHADER_SRC} EXT)
|
||||
if(EXT STREQUAL ".slang")
|
||||
addSlangShader(${SHADER_SRC} "${BINARY_SLANG_ENTRIES}" ${SHADER_OUTPUT_DIR})
|
||||
list(APPEND ALL_SPV_FILES ${SPV_FILE})
|
||||
else()
|
||||
addGlslShader(${SHADER_SRC} ${SHADER_OUTPUT_DIR})
|
||||
list(APPEND ALL_SPV_FILES ${SPV_FILE})
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
add_custom_target(shaders_${BINARY_NAME} DEPENDS ${ALL_SPV_FILES})
|
||||
add_dependencies(${BINARY_NAME} shaders_${BINARY_NAME})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (DEFINED BINARY_LIBS)
|
||||
target_link_libraries ( ${BINARY_NAME} ${BINARY_LIBS} )
|
||||
target_link_libraries ( ${BINARY_NAME} PRIVATE ${BINARY_LIBS} )
|
||||
endif()
|
||||
|
||||
if (DEFINED BINARY_MODELS) # Adds the 3D models in the binary folder
|
||||
@ -260,8 +385,9 @@ function ( addBinary BINARY_NAME )
|
||||
endfunction()
|
||||
|
||||
|
||||
# Adds the main binary
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Binaries
|
||||
# ---------------------------------------------------------------------------
|
||||
list(
|
||||
APPEND
|
||||
lib_list
|
||||
@ -269,11 +395,24 @@ list(
|
||||
glfw
|
||||
fmt
|
||||
vk-bootstrap
|
||||
#Vulkan::UtilityHeaders
|
||||
vulkan
|
||||
CLI11::CLI11
|
||||
fastgltf
|
||||
)
|
||||
|
||||
if(VULKANENGINE_FETCH_DEPS)
|
||||
# No libvulkan at link time: volk loads libvulkan.so.1 at runtime.
|
||||
# Remove what your code does not use (simdjson, glm...).
|
||||
list(APPEND lib_list
|
||||
volk
|
||||
Vulkan::Headers
|
||||
GPUOpen::VulkanMemoryAllocator
|
||||
glm::glm-header-only
|
||||
simdjson::simdjson
|
||||
)
|
||||
else()
|
||||
list(APPEND lib_list vulkan)
|
||||
endif()
|
||||
|
||||
addBinary (
|
||||
engine
|
||||
SOURCE Engine/main
|
||||
@ -291,3 +430,26 @@ addBinary (
|
||||
server
|
||||
SOURCE Server/main
|
||||
)
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Install (used for portable / bundle packaging)
|
||||
# dist/bin/{engine,server,shaders,models,textures}
|
||||
# dist/lib/*.so* (bundle only)
|
||||
# dist/LICENSE
|
||||
# Never bundled: libc, libstdc++, libvulkan, GL, X11, Wayland.
|
||||
# ---------------------------------------------------------------------------
|
||||
install(TARGETS engine server RUNTIME DESTINATION bin)
|
||||
install(DIRECTORY ${CMAKE_BINARY_DIR}/engine/shaders DESTINATION bin OPTIONAL)
|
||||
install(DIRECTORY ${CMAKE_BINARY_DIR}/engine/models DESTINATION bin OPTIONAL)
|
||||
install(DIRECTORY ${CMAKE_BINARY_DIR}/engine/textures DESTINATION bin OPTIONAL)
|
||||
install(FILES ${CMAKE_SOURCE_DIR}/LICENSE DESTINATION .)
|
||||
|
||||
if(VULKANENGINE_BUNDLE)
|
||||
# Every shared lib built from fetched deps (glfw, fmt, fastgltf and its own
|
||||
# simdjson, ...) with its symlinks. libstdc++ etc. are not built here.
|
||||
install(DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/
|
||||
DESTINATION lib
|
||||
USE_SOURCE_PERMISSIONS
|
||||
FILES_MATCHING PATTERN "*.so*"
|
||||
)
|
||||
endif()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user