procedural-3d-engine/CMakeLists.txt

182 lines
6.9 KiB
Text
Raw Permalink Normal View History

2025-01-24 09:53:06 +01:00
# Copyright (C) 2016-2025 by Sascha Willems - www.saschawillems.de
# This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
2025-04-11 19:52:01 +02:00
cmake_minimum_required(VERSION 3.10.0 FATAL_ERROR)
2016-02-16 19:33:57 +02:00
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
2016-02-16 15:07:25 +01:00
set(NAME inihb)
2016-02-16 15:07:25 +01:00
project(${NAME})
include_directories(external)
include_directories(external/glm)
include_directories(external/imgui)
2018-09-03 20:27:15 +02:00
include_directories(external/tinygltf)
Merge glTF branch (#747) * Added helper function for easy pipeline vertex input state create info structure setup from glTF model vertex class * Split glTF loader into header and implementation * Updated sample to use glTF * Removed collada files Replaced assets are now part of the asset pack * Return value for glTF model vertex input state create info helper * Removed unused assets * Use glTF assets * Added default material for glTF node's without materials * Use glTF assets * Apply pre-transforms to normals * Use glTF assets * Use glTF assets * Use vertex input state from glTF model class * Scene setup * Use glTF assets * Use glTF assets * Display error message and exit if glTF file could not be loaded * Use glTF assets * Use glTF assets * Use glTF assets * Remove unused buffer binds * Use glTF assets * Remove no longer used model files * Remove no longer used model files * Added support for rendering glTF models with images * glTF model normal pre-transform ignores translation * Use glTF assets * Use glTF assets * Use glTF assets * Use glTF assets * Use glTF assets * Only add combined image samplers to pool if actually used in the scene * Use global descriptor set layouts * Use global descriptor set layouts * Use glTF assets * Use glTF assets * Use glTF assets Code cleanup Updated GLSL and HLSL shaders * Use glTF assets Code cleanup * Use glTF assets Code cleanup Updated GLSL and HLSL shaders * Remove no-longer used model * Use glTF assets Code cleanup Updated GLSL and HLSL shaders * Use glTF assets Code cleanup Updated GLSL and HLSL shaders Removed no-longer used model * Use glTF assets Code cleanup Use RGBA texture instead of different compressed formats Removed no-longer used assets * Adnrdoid build file * Use glTF assets Code cleanup and refactoring Updated GLSL and HLSL shaders * Added vertex count and way of passing additional memory property type flags to glTF loader * Use glTF assets Updated GLSL and HLSL shaders Removed no-longer used assets * Use glTF assets Updated GLSL and HLSL shaders * Remove unfinished sample * Completely reworked push constants sample Use glTF assets Updated GLSL and HLSL shaders Removed no-longer used assets * Android CMake build files * Removed un-used asset * Explicit buffer binding function * Use glTF assets Code cleanup Updated GLSL and HLSL shaders * Use glTF assets Code cleanup * Use glTF assets Code cleanup Removed no-longer used assets * Use glTF assets Code cleanup Updated GLSL and HLSL shaders Removed no-longer used assets * Remove no-longer used asset * Use glTF assets Code cleanup and refactoring Performance optimizations Updated GLSL and HLSL shaders Removed no-longer used assets * Use glTF assets Code cleanup and refactoring Updated GLSL and HLSL shaders Removed no-longer used assets * Use glTF assets Code cleanup and refactoring Updated GLSL and HLSL shaders Removed no-longer used assets * Use glTF assets Code cleanup and refactoring Removed no-longer used assets * Use glTF assets Code cleanup and refactoring Removed no-longer used assets * Use glTF assets Code cleanup and refactoring * Use glTF assets Code cleanup and refactoring * Use glTF assets Code cleanup and refactoring Removed no-longer used assets * Pass vertex size and calculate multiplier in shaders instead of hard-coding With this, changes to the glTF vertex structure won't break the ray tracing samples * Load tangents (if present) * Use glTF assets Code cleanup and heavy refactoring Reworked debug display code * Android build * Normal mapping fixes Udpated HLSL shaders * Use glTF assets Code cleanup and heavy refactoring Reworked debug display code Updated GLSL and HLSL shaders * Code cleanup, comments * Use glTF assets Code cleanup and heavy refactoring Reworked debug display code Updated GLSL and HLSL shaders * Added sample count to framebuffer create info * Removed no-longer used assets * Android build Removed no-longer used assets * Code cleanup and heavy refactoring Updated GLSL and HLSL shaders Use tangents stored in GLSL instead of calculating them in the fragment shader * Renamed textured PBR sample main cpp file * Use glTF assets Code cleanup and refactoring Updated GLSL and HLSL shaders Removed no-longer used assets * Use glTF assets Removed no-longer used assets * Android build files * Android build files * Use glTF assets Removed no-longer used assets * Fixed HLSL shaders * Android build files * Use glTF assets Updated GLSL and HLSL shaders Removed no-longer used assets * Use glTF assets Updated GLSL and HLSL shaders Removed no-longer used assets * Added flag to disable glTF image loading Useful for samples that use their own textures or don't use textures at all to speed up loading * Use glTF assets Code cleanup Use Sponza scene instead of Sibenik to better highlight the effect Updated GLSL and HLSL shaders * Updated Android build files * Removed left-over comment * Use Sponza scene for the SSAO sample * Removed unused code * Removed ASSIMP No longer required as all samples now use the glTF file format * Added missing vertex shader stage * Removed old ASSIMP-based model loader * Added support for loading external glTF images from ktx Android fixes for loading external buffer files * Scene setup * Added missing shader stages * Removed ASSIMP from build files * Fixed compiler warning * Removed ASSIMP from readmes * Android build files cleanup * Replaced ktx submodule with only the files required for this repo The ktx submodule was a tad too big and contained lots of files not required for this repo * Moved ktx build files into base project * Use glTF assets * Use glTF assets * Removed license files, will be moved to asset pack * Use RGBA textures * Use RGBA cubemp texture with face assignment based on original images Refs #679 * Android build files * Removed textures All textures will be moved to the asset pack * Ignore asset folders * Removed font Fonts will be moved to the asset pack * Link to gltf asset pack * Updated gitignore * Android build file
2020-07-28 20:20:38 +02:00
include_directories(external/ktx/include)
include_directories(external/ktx/other_include)
2016-02-16 15:07:25 +01:00
include_directories(base)
OPTION(USE_D2D_WSI "Build the project using Direct to Display swapchain" OFF)
2020-09-13 10:12:33 +02:00
OPTION(USE_DIRECTFB_WSI "Build the project using DirectFB swapchain" OFF)
2017-02-02 08:54:56 +00:00
OPTION(USE_WAYLAND_WSI "Build the project using Wayland swapchain" OFF)
OPTION(USE_HEADLESS "Build the project using headless extension swapchain" OFF)
OPTION(USE_RELATIVE_ASSET_PATH "Load assets (shaders, models, textures) from a fixed path relative to the binar" OFF)
OPTION(FORCE_VALIDATION "Forces validation on for all samples at compile time (prefer using the -v / --validation command line arguments)" OFF)
set(RESOURCE_INSTALL_DIR "" CACHE PATH "Path to install resources to (leave empty for running uninstalled)")
2025-04-11 19:52:01 +02:00
message(STATUS "Using module to find Vulkan")
find_package(Vulkan)
IF(UNIX AND NOT APPLE)
set(LINUX TRUE)
ENDIF()
2016-02-16 15:07:25 +01:00
IF(WIN32)
IF (NOT Vulkan_FOUND)
find_library(Vulkan_LIBRARY NAMES vulkan-1 vulkan PATHS ${CMAKE_SOURCE_DIR}/libs/vulkan)
IF (Vulkan_LIBRARY)
set(Vulkan_FOUND ON)
MESSAGE("Using bundled Vulkan library version")
ENDIF()
ENDIF()
2016-02-16 15:07:25 +01:00
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DVK_USE_PLATFORM_WIN32_KHR")
ELSEIF(LINUX)
IF (NOT Vulkan_FOUND)
find_library(Vulkan_LIBRARY NAMES vulkan HINTS "$ENV{VULKAN_SDK}/lib" "${CMAKE_SOURCE_DIR}/libs/vulkan" REQUIRED)
IF (Vulkan_LIBRARY)
set(Vulkan_FOUND ON)
MESSAGE("Using bundled Vulkan library version")
ENDIF()
ENDIF()
find_package(Threads REQUIRED)
IF(USE_D2D_WSI)
MESSAGE("Using direct to display extension...")
add_definitions(-D_DIRECT2DISPLAY)
2020-09-13 10:12:33 +02:00
ELSEIF(USE_DIRECTFB_WSI)
find_package(DirectFB REQUIRED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DVK_USE_PLATFORM_DIRECTFB_EXT")
include_directories(${DIRECTFB_INCLUDE_DIR})
ELSEIF(USE_WAYLAND_WSI)
find_program(PKG_CONFIG pkg-config)
if (NOT PKG_CONFIG)
message(FATAL_ERROR "pkg-config binary not found")
endif ()
find_package(Wayland REQUIRED)
if (NOT WAYLAND_FOUND)
message(FATAL_ERROR "Wayland development package not found")
endif ()
pkg_check_modules(WAYLAND_PROTOCOLS REQUIRED wayland-protocols)
if (NOT WAYLAND_PROTOCOLS_FOUND)
message(FATAL_ERROR "Wayland protocols package not found")
endif ()
find_program(WAYLAND_SCANNER wayland-scanner)
if (NOT WAYLAND_SCANNER)
message(FATAL_ERROR "wayland-scanner binary not found")
endif ()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DVK_USE_PLATFORM_WAYLAND_KHR")
include_directories(${WAYLAND_INCLUDE_DIR})
pkg_get_variable(protocol_dir wayland-protocols pkgdatadir)
execute_process(COMMAND ${WAYLAND_SCANNER} client-header ${protocol_dir}/stable/xdg-shell/xdg-shell.xml ${CMAKE_BINARY_DIR}/xdg-shell-client-protocol.h
COMMAND ${WAYLAND_SCANNER} private-code ${protocol_dir}/stable/xdg-shell/xdg-shell.xml ${CMAKE_BINARY_DIR}/xdg-shell-protocol.c)
include_directories(${CMAKE_BINARY_DIR})
ELSEIF(USE_HEADLESS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DVK_USE_PLATFORM_HEADLESS_EXT")
ELSE(USE_D2D_WSI)
find_package(XCB REQUIRED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DVK_USE_PLATFORM_XCB_KHR")
ENDIF(USE_D2D_WSI)
ELSEIF(APPLE)
macOS/iOS fixes plus other generic fixes for clang and validation warnings (#1117) * Fix clang Objective-C++ flags for macOS command line builds * Fix getAssetPath() and getShaderBasePath() for macOS command line builds * Protect debugUtilsMessageCallback() from failing when pMessageIdName is NULL * Fix a few clang function override and mismatched type warnings * Fix validation layer warnings on exit for computeraytracing example * Fix regression in text visibility toggle for textOverlay example * Support VK_USE_PLATFORM_METAL_EXT vs. deprecated VK_USE_PLATFORM_MACOS_MVK / DVK_USE_PLATFORM_IOS_MVK * Check dynamic state features before enabling capabilities in dynamicstate example * Fix vkCmdDraw() vertexCount argument (PARTICLE_COUNT) in particlesystem example * Update examples list and restore benchmarking script (to top level) * Fix validation warning in descriptorindexing example * Fix device max recursion depth validation warnings in ray tracing examples * Fix OpenMP build settings for texture3d example on all platforms * Update and simplify build instructions for macOS * Update CI script with correct library path for libomp on macOS x86_64 * Update CI scipt to install libomp prior to macOS builds * Trying one more time to get the CI script working for macOS libomp * Fix vertexCount argument using calculated size in particlesystem example * Fix combined image descriptor offset calculation in descriptorbuffer example * macOS: Support non-system level Vulkan SDK installs, with fallback to MoltenVK library
2024-05-04 07:53:08 -04:00
IF (CMAKE_GENERATOR MATCHES "Xcode")
# Suppress regeneration for Xcode since environment variables will be lost if not set in Xcode locations/custom paths
set(CMAKE_SUPPRESS_REGENERATION ON)
set(CMAKE_XCODE_GENERATE_SCHEME ON)
IF (Vulkan_FOUND)
# If the Vulkan loader was found and its environment variables are defined, make them available within Xcode schemes
IF (DEFINED ENV{VK_ADD_LAYER_PATH})
set(CMAKE_XCODE_SCHEME_ENVIRONMENT "${CMAKE_XCODE_SCHEME_ENVIRONMENT};VK_ADD_LAYER_PATH=$ENV{VK_ADD_LAYER_PATH}")
ENDIF()
IF (DEFINED ENV{VK_ICD_FILENAMES})
set(CMAKE_XCODE_SCHEME_ENVIRONMENT "${CMAKE_XCODE_SCHEME_ENVIRONMENT};VK_ICD_FILENAMES=$ENV{VK_ICD_FILENAMES}")
ENDIF()
IF (DEFINED ENV{VK_DRIVER_FILES})
set(CMAKE_XCODE_SCHEME_ENVIRONMENT "${CMAKE_XCODE_SCHEME_ENVIRONMENT};VK_DRIVER_FILES=$ENV{VK_DRIVER_FILES}")
ENDIF()
ENDIF()
ENDIF()
IF (NOT Vulkan_FOUND)
# If the Vulkan loader was not found, then look for libMoltenVK.dylib in the Vulkan SDK and legacy MoltenVK locations
set(CMAKE_FIND_FRAMEWORK NEVER)
find_library(Vulkan_LIBRARY NAMES MoltenVK HINTS "$ENV{VULKAN_SDK}/lib" "$ENV{VULKAN_SDK}/dylib/macOS" REQUIRED)
IF (Vulkan_LIBRARY)
set(Vulkan_FOUND ON)
MESSAGE(STATUS "Using MoltenVK Vulkan Portability library")
ENDIF()
ENDIF()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DVK_USE_PLATFORM_METAL_EXT -DVK_EXAMPLE_XCODE_GENERATED")
2016-02-16 15:07:25 +01:00
# Todo : android?
ENDIF(WIN32)
IF (NOT Vulkan_FOUND)
message(FATAL_ERROR "Could not find Vulkan library!")
ELSE()
message(STATUS ${Vulkan_LIBRARY})
ENDIF()
2016-02-16 15:07:25 +01:00
# Set preprocessor defines
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNOMINMAX -D_USE_MATH_DEFINES")
2016-02-16 15:07:25 +01:00
# Clang specific stuff
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-switch-enum")
endif()
2016-02-16 15:07:25 +01:00
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
2025-01-24 09:53:06 +01:00
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
2016-02-16 15:07:25 +01:00
2017-08-17 20:40:52 +02:00
file(GLOB SOURCE *.cpp )
2016-02-16 15:07:25 +01:00
# Asset and shader path selection
if(RESOURCE_INSTALL_DIR)
add_definitions(-DVK_EXAMPLE_ASSETS_DIR=\"${RESOURCE_INSTALL_DIR}/\")
add_definitions(-DVK_EXAMPLE_SHADERS_DIR=\"${RESOURCE_INSTALL_DIR}/shaders/\")
install(DIRECTORY assets/ DESTINATION ${RESOURCE_INSTALL_DIR}/)
install(DIRECTORY shaders/ DESTINATION ${RESOURCE_INSTALL_DIR}/shaders/)
else()
if(NOT USE_RELATIVE_ASSET_PATH)
add_definitions(-DVK_EXAMPLE_ASSETS_DIR=\"${CMAKE_SOURCE_DIR}/assets/\")
add_definitions(-DVK_EXAMPLE_SHADERS_DIR=\"${CMAKE_SOURCE_DIR}/shaders/\")
endif()
endif()
# Force validation at compile time
if (FORCE_VALIDATION)
add_definitions(-DFORCE_VALIDATION)
endif()
2016-02-16 15:07:25 +01:00
# Compiler specific stuff
IF(MSVC)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc")
ELSEIF(APPLE)
macOS/iOS fixes plus other generic fixes for clang and validation warnings (#1117) * Fix clang Objective-C++ flags for macOS command line builds * Fix getAssetPath() and getShaderBasePath() for macOS command line builds * Protect debugUtilsMessageCallback() from failing when pMessageIdName is NULL * Fix a few clang function override and mismatched type warnings * Fix validation layer warnings on exit for computeraytracing example * Fix regression in text visibility toggle for textOverlay example * Support VK_USE_PLATFORM_METAL_EXT vs. deprecated VK_USE_PLATFORM_MACOS_MVK / DVK_USE_PLATFORM_IOS_MVK * Check dynamic state features before enabling capabilities in dynamicstate example * Fix vkCmdDraw() vertexCount argument (PARTICLE_COUNT) in particlesystem example * Update examples list and restore benchmarking script (to top level) * Fix validation warning in descriptorindexing example * Fix device max recursion depth validation warnings in ray tracing examples * Fix OpenMP build settings for texture3d example on all platforms * Update and simplify build instructions for macOS * Update CI script with correct library path for libomp on macOS x86_64 * Update CI scipt to install libomp prior to macOS builds * Trying one more time to get the CI script working for macOS libomp * Fix vertexCount argument using calculated size in particlesystem example * Fix combined image descriptor offset calculation in descriptorbuffer example * macOS: Support non-system level Vulkan SDK installs, with fallback to MoltenVK library
2024-05-04 07:53:08 -04:00
IF(CMAKE_GENERATOR MATCHES "Makefiles" OR CMAKE_GENERATOR MATCHES "Ninja")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fobjc-arc -ObjC++")
ELSE() # SRS - use objective-c++ language flag vs. ObjC++ for Xcode builds
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fobjc-arc -xobjective-c++")
macOS/iOS fixes plus other generic fixes for clang and validation warnings (#1117) * Fix clang Objective-C++ flags for macOS command line builds * Fix getAssetPath() and getShaderBasePath() for macOS command line builds * Protect debugUtilsMessageCallback() from failing when pMessageIdName is NULL * Fix a few clang function override and mismatched type warnings * Fix validation layer warnings on exit for computeraytracing example * Fix regression in text visibility toggle for textOverlay example * Support VK_USE_PLATFORM_METAL_EXT vs. deprecated VK_USE_PLATFORM_MACOS_MVK / DVK_USE_PLATFORM_IOS_MVK * Check dynamic state features before enabling capabilities in dynamicstate example * Fix vkCmdDraw() vertexCount argument (PARTICLE_COUNT) in particlesystem example * Update examples list and restore benchmarking script (to top level) * Fix validation warning in descriptorindexing example * Fix device max recursion depth validation warnings in ray tracing examples * Fix OpenMP build settings for texture3d example on all platforms * Update and simplify build instructions for macOS * Update CI script with correct library path for libomp on macOS x86_64 * Update CI scipt to install libomp prior to macOS builds * Trying one more time to get the CI script working for macOS libomp * Fix vertexCount argument using calculated size in particlesystem example * Fix combined image descriptor offset calculation in descriptorbuffer example * macOS: Support non-system level Vulkan SDK installs, with fallback to MoltenVK library
2024-05-04 07:53:08 -04:00
ENDIF()
2016-02-16 15:07:25 +01:00
ENDIF(MSVC)
IF(WIN32)
# Nothing here (yet)
ELSEIF(APPLE)
link_libraries(${Vulkan_LIBRARY} "-framework AppKit" "-framework QuartzCore")
2016-02-16 15:07:25 +01:00
ELSE(WIN32)
2020-09-13 10:12:33 +02:00
link_libraries(${XCB_LIBRARIES} ${Vulkan_LIBRARY} ${Vulkan_LIBRARY} ${DIRECTFB_LIBRARIES} ${WAYLAND_CLIENT_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
2016-02-16 15:07:25 +01:00
ENDIF(WIN32)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/")
2016-02-16 15:07:25 +01:00
2017-08-17 20:40:52 +02:00
add_subdirectory(base)
add_subdirectory(src)