|
| 1 | +# This file is part of the AMD & HSC Work Graph Playground. |
| 2 | +# |
| 3 | +# Copyright (C) 2024 Advanced Micro Devices, Inc. and Coburg University of Applied Sciences and Arts. |
| 4 | +# All rights reserved. |
| 5 | +# |
| 6 | +# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | +# of this software and associated documentation files(the "Software"), to deal |
| 8 | +# in the Software without restriction, including without limitation the rights |
| 9 | +# to use, copy, modify, merge, publish, distribute, sublicense, and /or sell |
| 10 | +# copies of the Software, and to permit persons to whom the Software is |
| 11 | +# furnished to do so, subject to the following conditions : |
| 12 | +# |
| 13 | +# The above copyright notice and this permission notice shall be included in |
| 14 | +# all copies or substantial portions of the Software. |
| 15 | +# |
| 16 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE |
| 19 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 22 | +# THE SOFTWARE. |
| 23 | + |
| 24 | +cmake_minimum_required(VERSION 3.17) |
| 25 | +project(WorkGraphPlayground VERSION 0.1) |
| 26 | + |
| 27 | +set(CMAKE_CXX_STANDARD 20) |
| 28 | +set(CMAKE_CXX_STANDARD_REQUIRED True) |
| 29 | +set(CMAKE_POSITION_INDEPENDENT_CODE ON) |
| 30 | + |
| 31 | +set(CMAKE_EXECUTABLE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) |
| 32 | +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) |
| 33 | + |
| 34 | +add_compile_definitions(UNICODE _UNICODE) |
| 35 | + |
| 36 | +set_property(GLOBAL PROPERTY USE_FOLDERS ON) |
| 37 | + |
| 38 | +add_subdirectory(imported) |
| 39 | + |
| 40 | + |
| 41 | +file(GLOB PROJECT_SOURCE_FILES |
| 42 | + ${CMAKE_CURRENT_SOURCE_DIR}/include/*.h |
| 43 | + ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp) |
| 44 | +file(GLOB_RECURSE PROJECT_SHADER_FILES |
| 45 | + ${CMAKE_CURRENT_SOURCE_DIR}/tutorials/*.md |
| 46 | + ${CMAKE_CURRENT_SOURCE_DIR}/tutorials/*.png |
| 47 | + ${CMAKE_CURRENT_SOURCE_DIR}/tutorials/*.h |
| 48 | + ${CMAKE_CURRENT_SOURCE_DIR}/tutorials/*.hlsl) |
| 49 | +set_source_files_properties(${PROJECT_SHADER_FILES} PROPERTIES VS_TOOL_OVERRIDE "Text") |
| 50 | + |
| 51 | +add_executable(${PROJECT_NAME} ${PROJECT_SOURCE_FILES} ${PROJECT_SHADER_FILES}) |
| 52 | +target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include) |
| 53 | +target_link_libraries(${PROJECT_NAME} PRIVATE |
| 54 | + Microsoft.Direct3D.D3D12 |
| 55 | + Microsoft.Direct3D.DXC |
| 56 | + Microsoft.Direct3D.WARP |
| 57 | + d3d12 |
| 58 | + dxcompiler |
| 59 | + dxgi |
| 60 | + dxguid |
| 61 | + imgui) |
| 62 | + |
| 63 | +set_target_properties(${PROJECT_NAME} PROPERTIES |
| 64 | + VS_DPI_AWARE "PerMonitor" |
| 65 | + VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/$<CONFIG>") |
| 66 | +set_property(DIRECTORY "." PROPERTY VS_STARTUP_PROJECT ${PROJECT_NAME}) |
| 67 | + |
| 68 | +# set source group for shader files & link to bin folder |
| 69 | +set(SHADER_BASE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/tutorials) |
| 70 | +foreach(SHADER ${PROJECT_SHADER_FILES}) |
| 71 | + get_filename_component(SHADER_FILE_DIRECTORY ${SHADER} DIRECTORY) |
| 72 | + get_filename_component(SHADER_FILE_NAME ${SHADER} NAME) |
| 73 | + file(RELATIVE_PATH SHADER_FILE_DIRECTORY_RELATIVE_PATH ${SHADER_BASE_DIRECTORY} ${SHADER_FILE_DIRECTORY}) |
| 74 | + |
| 75 | + if ("${SHADER_FILE_DIRECTORY_RELATIVE_PATH}" STREQUAL "") |
| 76 | + source_group("Shader Source Files" FILES ${SHADER}) |
| 77 | + else() |
| 78 | + source_group("Shader Source Files/${SHADER_FILE_DIRECTORY_RELATIVE_PATH}" FILES ${SHADER}) |
| 79 | + endif() |
| 80 | + |
| 81 | + # to enable shader hot-reloading, instead of copying the shaders to the bin output folder at the end of the build, |
| 82 | + # we create hardlinks between a file in the bin folder and the shader source file. |
| 83 | + # This way, updates to the shader source file are automatically propagated to the bin folder, |
| 84 | + # and - unlike symlinks - the hardlinks allow copying/moving/compressing the bin folder without having broken links. |
| 85 | + |
| 86 | + # create parent folder |
| 87 | + add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD |
| 88 | + COMMAND ${CMAKE_COMMAND} -E make_directory |
| 89 | + ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/$<CONFIG>/tutorials/${SHADER_FILE_DIRECTORY_RELATIVE_PATH}) |
| 90 | + # create hardlink |
| 91 | + add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD |
| 92 | + COMMAND ${CMAKE_COMMAND} -E create_hardlink |
| 93 | + ${SHADER} |
| 94 | + ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/$<CONFIG>/tutorials/${SHADER_FILE_DIRECTORY_RELATIVE_PATH}/${SHADER_FILE_NAME}) |
| 95 | +endforeach() |
0 commit comments