Added new CMake option to use relative paths for shaders and assets (USE_RELATIVE_ASSET_PATH)

See BUILD.md for details
Refs #1090
This commit is contained in:
Sascha Willems 2023-11-28 19:33:14 +01:00
parent 3c0f3e18cd
commit b77417e7c8
2 changed files with 26 additions and 10 deletions

View file

@ -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.
## <img src="./images/windowslogo.png" alt="" height="32px"> 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
### <img src="./images/windowslogo.png" alt="" height="32px"> 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
```
## <img src="./images/linuxlogo.png" alt="" height="32px"> Linux
### <img src="./images/linuxlogo.png" alt="" height="32px"> 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```)
## <img src="./images/androidlogo.png" alt="" height="32px"> [Android](android/)
### <img src="./images/androidlogo.png" alt="" height="32px"> [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.
## <img src="./images/applelogo.png" alt="" height="32px"> [iOS and macOS](xcode/)
### <img src="./images/applelogo.png" alt="" height="32px"> [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

View file

@ -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,15 +115,18 @@ 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()
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
IF(MSVC)