From b77417e7c8af7844180646dc9adfbd3881720e4d Mon Sep 17 00:00:00 2001 From: Sascha Willems Date: Tue, 28 Nov 2023 19:33:14 +0100 Subject: [PATCH] Added new CMake option to use relative paths for shaders and assets (USE_RELATIVE_ASSET_PATH) See BUILD.md for details Refs #1090 --- BUILD.md | 25 +++++++++++++++++-------- CMakeLists.txt | 11 +++++++++-- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/BUILD.md b/BUILD.md index 885e57c1..534a95ac 100644 --- a/BUILD.md +++ b/BUILD.md @@ -1,15 +1,26 @@ # Building -The repository contains everything required to compile and build the examples on Windows, Linux and Android using a C++ compiler that supports C++11. All required dependencies are included. +The repository contains everything required to compile and build the examples on Windows, Linux, Android and MacOS using a C++ compiler that supports at least C++11. All required dependencies are included. The project uses [CMake](https://cmake.org/) as the build system. -## Windows +## General CMake options + +### Asset path setup + +Asset (and shader) paths used by the samples can be adjusted using CMake options. By default, paths are absolute and are based on the top level of the current CMake source tree. The following arguments can be used to adjust this: + +- ```RESOURCE_INSTALL_DIR```: Set an absolute path for assets and shaders to which they are installed and from which they are loaded +- ```USE_RELATIVE_ASSET_PATH```: Use a fixed relative (to the binary) path for loading assets and shaders + +## Platform specific build instructions + +### Windows Use the provided CMakeLists.txt with [CMake](https://cmake.org) to generate a build configuration for your favorite IDE or compiler, e.g.: ``` cmake -G "Visual Studio 16 2019" -A x64 ``` -## Linux +### Linux Use the provided CMakeLists.txt with [CMake](https://cmake.org) to generate a build configuration for your favorite IDE or compiler. @@ -19,7 +30,7 @@ Use the provided CMakeLists.txt with [CMake](https://cmake.org) to generate a bu - **DirectFB**: Use cmake option ```USE_DIRECTFB_WSI``` (```-DUSE_DIRECTFB_WSI=ON```) - **DirectToDisplay**: Use cmake option ```USE_D2D_WSI``` (```-DUSE_D2D_WSI=ON```) -## [Android](android/) +### [Android](android/) Building on Android is done using the [Gradle Build Tool](https://gradle.org/): @@ -39,19 +50,17 @@ If you want to build and install on a connected device or emulator image, run `` If you want to build it through [Android Studio](https://developer.android.com/studio), open project folder ```android``` in Android Studio. -## [iOS and macOS](xcode/) +### [iOS and macOS](xcode/) Building for *iOS* and *macOS* is done using the [examples](xcode/examples.xcodeproj) *Xcode* project found in the [xcode](xcode) directory. These examples use the [**MoltenVK**](https://moltengl.com/moltenvk) Vulkan driver to provide Vulkan support on *iOS* and *macOS*, and require an *iOS* or *macOS* device that supports *Metal*. Please see the [MoltenVK Examples readme](xcode/README_MoltenVK_Examples.md) for more info on acquiring **MoltenVK** and building and deploying the examples on *iOS* and *macOS*. -##### MacOS +###### MacOS Install Libomp with: -brew install libomp find the path -brew --prefix libomp use the path from the above command to populate the path in the -DOpenMP_C_FLAGS, -DOpenMP_omp_LIBRARY & -DOpenMP_CXX_FOUND statement below - - Download Vulkan SDK and install it note the path as this will need to be configure in Xcode curl -O https://sdk.lunarg.com/sdk/download/latest/mac/vulkan_sdk.dmg diff --git a/CMakeLists.txt b/CMakeLists.txt index 28353f47..0c6f90cb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,3 +1,6 @@ +# Copyright (C) 2016-2023 by Sascha Willems - www.saschawillems.de +# This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) + cmake_minimum_required(VERSION 3.4 FATAL_ERROR) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake") @@ -18,6 +21,7 @@ OPTION(USE_D2D_WSI "Build the project using Direct to Display swapchain" OFF) OPTION(USE_DIRECTFB_WSI "Build the project using DirectFB swapchain" OFF) 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) set(RESOURCE_INSTALL_DIR "" CACHE PATH "Path to install resources to (leave empty for running uninstalled)") @@ -111,14 +115,17 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) file(GLOB SOURCE *.cpp ) +# 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() - add_definitions(-DVK_EXAMPLE_ASSETS_DIR=\"${CMAKE_SOURCE_DIR}/assets/\") - add_definitions(-DVK_EXAMPLE_SHADERS_DIR=\"${CMAKE_SOURCE_DIR}/shaders/\") + 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() # Compiler specific stuff