-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
189 lines (146 loc) · 6.14 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
cmake_minimum_required(VERSION 3.17)
project(mega_minecraft LANGUAGES CXX CUDA)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
# Enable C++11 for host code
set(CMAKE_CXX_STANDARD 11)
# Set a default build type if none was specified
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
SET(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
# Set the possible values of build type for cmake-gui
SET_PROPERTY(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()
########################################
# DirectX 11 Setup
########################################
if (DEFINED VCPKG_TARGET_ARCHITECTURE)
set(DIRECTX_ARCH ${VCPKG_TARGET_ARCHITECTURE})
elseif(CMAKE_GENERATOR_PLATFORM MATCHES "^[Ww][Ii][Nn]32$")
set(DIRECTX_ARCH x86)
elseif(CMAKE_GENERATOR_PLATFORM MATCHES "^[Xx]64$")
set(DIRECTX_ARCH x64)
elseif(CMAKE_GENERATOR_PLATFORM MATCHES "^[Aa][Rr][Mm]$")
set(DIRECTX_ARCH arm)
elseif(CMAKE_GENERATOR_PLATFORM MATCHES "^[Aa][Rr][Mm]64$")
set(DIRECTX_ARCH arm64)
endif()
set(LIBRARIES d3d11.dll dxgi.dll d3dcompiler.lib)
########################################
# CUDA Setup
########################################
find_package(CUDAToolkit 10 REQUIRED)
include(${CMAKE_MODULE_PATH}/CUDAComputesList.cmake)
#list(APPEND CUDA_NVCC_FLAGS ${CUDA_GENERATE_CODE})
#list(APPEND CUDA_NVCC_FLAGS_DEBUG "-g -G")
#set(CUDA_VERBOSE_BUILD ON)
include_directories(${CUDAToolkit_INCLUDE_DIRS})
message(STATUS ${CUDA_LIBRARIES})
message(STATUS ${CUDAToolkit_LIBRARY_DIR})
list(APPEND LIBRARIES CUDA::cudart)
########################################
find_package(OpenGL REQUIRED)
if(UNIX)
find_package(glfw3 REQUIRED)
find_package(GLEW REQUIRED)
list(APPEND LIBRARIES cuda glfw ${GLEW_LIBRARIES} ${OPENGL_gl_LIBRARY})
else(UNIX)
set(EXTERNAL "external")
set(GLFW_ROOT_DIR ${EXTERNAL})
set(GLFW_USE_STATIC_LIBS ON)
find_package(GLFW REQUIRED)
set(GLEW_ROOT_DIR ${EXTERNAL})
set(GLEW_USE_STATIC_LIBS ON)
find_package(GLEW REQUIRED)
add_definitions(${GLEW_DEFINITIONS})
include_directories(${GLEW_INCLUDE_DIR} ${GLFW_INCLUDE_DIR})
list(APPEND LIBRARIES cuda ${GLEW_LIBRARY} ${GLFW_LIBRARY} ${OPENGL_LIBRARY})
endif(UNIX)
set(GLM_ROOT_DIR "external")
set(OPTIX_ROOT_DIR "external")
find_package(GLM REQUIRED)
include_directories(${GLM_INCLUDE_DIRS})
message(STATUS "GLM include directories: ${GLM_INCLUDE_DIRS}")
include_directories(${CMAKE_SOURCE_DIR}/src)
########################################
# OptiX Setup + Compile
########################################
find_package(OPTIX REQUIRED)
include_directories(${OPTIX_INCLUDE_DIRS})
include("nvcuda_compile_module")
file(GLOB_RECURSE SHADERS "src/shaders/*.cu")
file(GLOB_RECURSE SHADER_HEADERS "src/shaders/*.h" "src/shaders/*.hpp")
# When using OptiX SDK 7.5.0 and CUDA 11.7 or higher, the modules can either be built from OptiX IR input or from PTX input.
# OPTIX_PROGRAM_TARGET and OPTIX_MODULE_EXTENSION switch the NVCC compilation between the two options.
NVCUDA_COMPILE_MODULE(
SOURCES ${SHADERS}
DEPENDENCIES ${SHADERS_HEADERS}
TARGET_PATH "${CMAKE_CURRENT_BINARY_DIR}/optix_shaders"
EXTENSION "${OPTIX_MODULE_EXTENSION}"
GENERATED_FILES PROGRAM_MODULES
NVCC_OPTIONS "${OPTIX_PROGRAM_TARGET}" "--machine=64" "--gpu-architecture=compute_50" "--use_fast_math" "--relocatable-device-code=true" "--generate-line-info" "-Wno-deprecated-gpu-targets" "-I${OPTIX_INCLUDE_DIR}" "-I${CMAKE_CURRENT_SOURCE_DIR}/shaders"
)
# Generate a header file with the file names
set(SHADER_LIST_FILE "${CMAKE_CURRENT_BINARY_DIR}/optix_shaders/ShaderList.h")
file(WRITE ${SHADER_LIST_FILE} "#pragma once\n#include <vector>\n#include <string>\nconst std::vector<std::string> shaderFiles = {\n")
foreach(SHADER_FILE ${PROGRAM_MODULES})
file(APPEND ${SHADER_LIST_FILE} " \"${SHADER_FILE}\",\n")
endforeach()
file(APPEND ${SHADER_LIST_FILE} "};\n")
# Add the binary dir to the include directories so that ShaderList.h can be included
include_directories(${CMAKE_CURRENT_BINARY_DIR}/optix_shaders)
if(USE_OPTIX_IR)
add_definitions(
# This define switches the OptiX program module filenames to either *.optixir or *.ptx extensions at compile time.
"-DUSE_OPTIX_IR"
)
endif()
########################################
file(GLOB_RECURSE headers "src/*.h" "src/*.hpp")
file(GLOB_RECURSE sources "src/*.cpp" "src/*.cu")
list(SORT headers)
list(SORT sources)
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/src" PREFIX "Headers" FILES ${headers})
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/src" PREFIX "Sources" FILES ${sources})
foreach(SHADER_SRC ${SHADERS})
set_source_files_properties(${SHADER_SRC} PROPERTIES HEADER_FILE_ONLY TRUE)
endforeach()
add_executable( ${CMAKE_PROJECT_NAME}
${headers}
${sources}
${PROGRAM_MODULES}
)
message(STATUS ${COMPUTES_DETECTED_LIST})
set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES CUDA_ARCHITECTURES "${COMPUTES_DETECTED_LIST}")
target_link_libraries(${CMAKE_PROJECT_NAME} ${LIBRARIES})
set(SHADER_DIR ${CMAKE_SOURCE_DIR}/shaders)
set(SHADER_OUTPUT_DIR ${CMAKE_BINARY_DIR}/shaders)
add_custom_command(
OUTPUT ${SHADER_OUTPUT_DIR}
COMMAND ${CMAKE_COMMAND} -E copy_directory
${SHADER_DIR}
${SHADER_OUTPUT_DIR}
COMMENT "Copying shaders from ${SHADER_DIR} to ${SHADER_OUTPUT_DIR}"
DEPENDS DIRECTORY ${SHADER_DIR}
)
add_custom_target(
CopyShadersTarget ALL
DEPENDS ${SHADER_OUTPUT_DIR}
)
set(TEXTURE_DIR ${CMAKE_SOURCE_DIR}/textures)
set(TEXTURE_OUTPUT_DIR ${CMAKE_BINARY_DIR}/textures)
add_custom_command(
OUTPUT ${TEXTURE_OUTPUT_DIR}
COMMAND ${CMAKE_COMMAND} -E copy_directory
${TEXTURE_DIR}
${TEXTURE_OUTPUT_DIR}
COMMENT "Copying textures from ${TEXTURE_DIR} to ${TEXTURE_OUTPUT_DIR}"
DEPENDS DIRECTORY ${TEXTURE_DIR}
)
add_custom_target(
CopyTexturesTarget ALL
DEPENDS ${TEXTURE_OUTPUT_DIR}
)
add_dependencies(${CMAKE_PROJECT_NAME} CopyShadersTarget CopyTexturesTarget)