-
Notifications
You must be signed in to change notification settings - Fork 10
/
CMakeLists.txt
201 lines (174 loc) · 7.02 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
cmake_minimum_required (VERSION 3.15)
# Options
option (DISABLE_SHADER_COMPILATION "Disable shader compilation" OFF)
option (USE_MINIMAL_DATA "Use minimal '_Data'(90MB)" OFF)
option (USE_DXC_FROM_PACKMAN_ON_AARCH64 "Use DXC from Packman for `aarch64`" ON)
set (SHADER_OUTPUT_PATH "${CMAKE_CURRENT_SOURCE_DIR}/_Shaders")
# Cached
set (DXC_CUSTOM_PATH "custom/path/to/dxc" CACHE STRING "This DXC will be used if Vulkan SDK is not installed")
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/_Bin" CACHE STRING "")
set (CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "")
# Create project
project (NRISamples LANGUAGES C CXX)
# Globals?
set_property (GLOBAL PROPERTY USE_FOLDERS ON)
set (CMAKE_CXX_STANDARD 17)
set (CMAKE_CXX_STANDARD_REQUIRED ON)
set (CMAKE_C_STANDARD 99)
if (MSVC)
set (CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif ()
# Download dependencies using Packman
if (WIN32)
set (PACKMAN_EXT ".cmd")
else ()
set (PACKMAN_EXT ".sh")
endif ()
if ((CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64") OR(CMAKE_SYSTEM_PROCESSOR MATCHES "AMD64"))
if (WIN32)
set (PACKMAN_PLATFORM "windows-x86_64")
else ()
set (PACKMAN_PLATFORM "linux-x86_64")
endif ()
elseif ((CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64") OR(CMAKE_SYSTEM_PROCESSOR MATCHES "arm64"))
set (PACKMAN_PLATFORM "linux-aarch64")
else ()
message (FATAL_ERROR "Unsupported architecture: '${CMAKE_SYSTEM_PROCESSOR}'")
endif ()
message ("Packman platform: ${PACKMAN_PLATFORM}")
if (USE_MINIMAL_DATA)
set (NRI_DATA_VERSION 2.3_minimal)
message ("Using minimal _Data.")
else ()
set (NRI_DATA_VERSION 2.3)
endif ()
execute_process (COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/External/Packman/packman${PACKMAN_EXT}" pull "${CMAKE_CURRENT_SOURCE_DIR}/Dependencies.xml" -p ${PACKMAN_PLATFORM} -t nri_data_version=${NRI_DATA_VERSION}
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
RESULT_VARIABLE PACKMAN_RESULT)
if (NOT "${PACKMAN_RESULT}" STREQUAL "0")
message (FATAL_ERROR "Packman failed(code = ${PACKMAN_RESULT})")
endif ()
# Setup dependencies
if ((CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64") OR(CMAKE_SYSTEM_PROCESSOR MATCHES "arm64"))
if (("${DXC_CUSTOM_PATH}" STREQUAL "") AND USE_DXC_FROM_PACKMAN_ON_AARCH64)
set (DXC_CUSTOM_PATH "${CMAKE_CURRENT_SOURCE_DIR}/External/DXC/bin/dxc" CACHE STRING "")
endif ()
endif ()
# Compile options
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set (COMPILE_OPTIONS -msse4.1 -Wextra)
elseif (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
set (COMPILE_OPTIONS -msse4.1 -Wextra)
elseif (MSVC)
set (COMPILE_OPTIONS /W4 /WX /wd4324)
else ()
message (WARNING "Unknown compiler!")
endif ()
# Compile definitions
if (WIN32)
set (COMPILE_DEFINITIONS WIN32_LEAN_AND_MEAN NOMINMAX _CRT_SECURE_NO_WARNINGS _UNICODE UNICODE)
endif ()
# External/NRIFramework
set (NRIF_SHADERS_PATH "${SHADER_OUTPUT_PATH}" CACHE STRING "")
add_subdirectory ("External/NRIFramework")
# Shaders
if (NOT DISABLE_SHADER_COMPILATION)
file (GLOB_RECURSE SHADERS "Shaders/*.hlsl" "Shaders/*.hlsli")
set_source_files_properties (${SHADERS} PROPERTIES VS_TOOL_OVERRIDE "None")
if (WIN32)
add_custom_target (${PROJECT_NAME}_Shaders ALL
COMMAND ShaderMake --useAPI
--binary --flatten --stripReflection --compiler "${DXC_PATH}"
--sourceDir "Shaders"
-p DXIL
-c Shaders.cfg
-o "${SHADER_OUTPUT_PATH}"
-I "Shaders"
-I "External"
-I "External/NRIFramework/External"
-I "External/NRIFramework/External/NRI/Include"
COMMAND ShaderMake --useAPI
--binary --flatten --stripReflection --compiler "${DXC_SPIRV_PATH}"
--sourceDir "Shaders"
-p SPIRV
-c Shaders.cfg
-o "${SHADER_OUTPUT_PATH}"
-I "Shaders"
-I "External"
-I "External/NRIFramework/External"
-I "External/NRIFramework/External/NRI/Include"
COMMAND ShaderMake --useAPI
--binary --flatten --stripReflection --compiler "${FXC_PATH}"
--sourceDir "Shaders"
-p DXBC
-c Shaders.cfg
-o "${SHADER_OUTPUT_PATH}"
-I "Shaders"
-I "External"
-I "External/NRIFramework/External"
-I "External/NRIFramework/External/NRI/Include"
DEPENDS ShaderMake
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
VERBATIM
SOURCES ${SHADERS}
)
else ()
add_custom_target (${PROJECT_NAME}_Shaders ALL
COMMAND ShaderMake
--binary --flatten --stripReflection --compiler "${DXC_SPIRV_PATH}"
--sourceDir "Shaders"
-p SPIRV
-c Shaders.cfg
-o "${SHADER_OUTPUT_PATH}"
-I "Shaders"
-I "External"
-I "External/NRIFramework/External"
-I "External/NRIFramework/External/NRI/Include"
DEPENDS ShaderMake
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
VERBATIM
SOURCES ${SHADERS}
)
endif ()
set_property (TARGET ${PROJECT_NAME}_Shaders PROPERTY FOLDER ${PROJECT_NAME})
endif ()
# Samples
function (add_sample NAME EXT)
add_executable (${NAME} "Source/${NAME}.${EXT}")
source_group ("" FILES "Source/${NAME}.${EXT}")
if (NOT DISABLE_SHADER_COMPILATION)
add_dependencies (${NAME} ${PROJECT_NAME}_Shaders)
endif ()
target_include_directories (${NAME} PRIVATE "External/NRIFramework/Include")
target_include_directories (${NAME} PRIVATE "External/NRIFramework/External")
target_include_directories (${NAME} PRIVATE "External/NRIFramework/External/NRI/Include")
target_compile_definitions (${NAME} PRIVATE ${COMPILE_DEFINITIONS} PROJECT_NAME=${NAME})
target_compile_options (${NAME} PRIVATE ${COMPILE_OPTIONS})
target_link_libraries (${NAME} PRIVATE NRIFramework NRI)
set_property (TARGET ${NAME} PROPERTY FOLDER ${PROJECT_NAME})
set_property (TARGET ${NAME} PROPERTY VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}")
# Copy arguments for Visual Studio Smart Command Line Arguments extension
if (WIN32 AND MSVC)
configure_file (.args "${CMAKE_BINARY_DIR}/${NAME}.args.json" COPYONLY)
endif ()
endfunction ()
add_sample (AsyncCompute cpp)
add_sample (Clear cpp)
add_sample (CTest c)
add_sample (DeviceInfo cpp)
add_sample (LowLatency cpp)
add_sample (MultiThreading cpp)
add_sample (Multiview cpp)
add_sample (RayTracingTriangle cpp)
add_sample (RayTracingBoxes cpp)
add_sample (Readback cpp)
add_sample (SceneViewer cpp)
add_sample (BindlessSceneViewer cpp)
add_sample (Triangle cpp)
add_sample (Wrapper cpp)
add_sample (Resize cpp)
# Samples - special
if (WIN32)
target_link_libraries (Wrapper PRIVATE d3d11 d3d12)
endif ()
target_include_directories (Wrapper PRIVATE "External/NRIFramework/External/NRI/External/vulkan/include")