-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
142 lines (122 loc) · 4.79 KB
/
CMakeLists.txt
File metadata and controls
142 lines (122 loc) · 4.79 KB
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
cmake_minimum_required(VERSION 3.21)
# Enable building custom commands by Visual Studio in parallel. Introduced in CMake 3.27.
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.27")
cmake_policy(SET CMP0147 NEW)
endif()
set(CMAKE_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/CMake")
include("${CMAKE_INCLUDE_DIR}/SetBuildConfigurations.cmake")
include("${CMAKE_INCLUDE_DIR}/SetupDXC.cmake")
project(ZetaRay
LANGUAGES CXX
DESCRIPTION "Real-time Direct3D 12 path tracer")
option(BUILD_TESTS "Build unit tests" OFF)
option(BUILD_TOOLS "Build tools" ON)
option(COMPILE_SHADERS_WITH_DEBUG_INFO "Compile shaders with debug information (-Zi in dxc)" OFF)
# set output directories
set(CMAKE_SUPPRESS_REGENERATION true)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/bin")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
# append 'd' to debug targets
set(CMAKE_DEBUG_POSTFIX "d")
# enable folders for code organization
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
# if(MSVC)
# # generate pdb files for the release build (off by default)
# add_compile_options("$<$<CONFIG:RELEASE>:/Zi>")
# add_link_options("$<$<CONFIG:RELEASE>:/DEBUG>")
# endif()
#
# compiler options
#
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_COMPILE_WARNING_AS_ERROR ON)
if(MSVC)
if(MSVC_TOOLSET_VERSION VERSION_LESS 142)
message(FATAL_ERROR "MSVC toolset version 142 or greater is required.")
endif()
# disable exceptions
string(REPLACE "/EHsc" "" NEW_CXX_FLAGS ${CMAKE_CXX_FLAGS})
set(CMAKE_CXX_FLAGS ${NEW_CXX_FLAGS} CACHE STRING "" FORCE)
# disable runtime checks
string(REPLACE "/RTC1" "" NEW_CXX_DBG_FLAGS ${CMAKE_CXX_FLAGS_DEBUG})
set(CMAKE_CXX_FLAGS_DEBUG ${NEW_CXX_DBG_FLAGS} CACHE STRING "" FORCE)
# multi-processor compilation
add_compile_options(/MP)
# warning level
add_compile_options(/W4)
# enable intrinsic functions
add_compile_options(/Oi)
add_compile_options("$<$<CONFIG:DEBUG>:/Ob1>")
# disable RTTI
add_compile_options(/GR-)
# precise floating point
add_compile_options(/fp:precise)
# standards conformance
add_compile_options(/permissive-)
add_compile_options(/arch:AVX2)
# disable a few MSVC warnings
if (NOT CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
# _CRT_SECURE_NO_WARNINGS
add_compile_options(/wd4996)
# unreferenced local variable
add_compile_options(/wd4101)
# unreferenced formal parameter
add_compile_options(/wd4100)
# local variable is initialized but not referenced
add_compile_options(/wd4189)
# structure was padded due to alignment specifier
add_compile_options(/wd4324)
endif()
add_compile_definitions("ZETA_HAS_NO_UNIQUE_ADDRESS")
endif()
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
add_compile_options(-Wno-unused-parameter)
add_compile_options(-Wno-deprecated-declarations)
add_compile_options(-Wno-reorder-ctor)
add_compile_options(-Wno-unused-variable)
add_compile_options(-Wno-unused-but-set-variable)
add_compile_options(-Wno-sign-compare)
add_compile_options(-Wno-missing-braces)
add_compile_options(-Wno-unused-local-typedef)
add_compile_options(-Wno-unused-function)
add_compile_options(-Wno-unused-private-field)
if (${CMAKE_CXX_COMPILER_VERSION} VERSION_GREATER_EQUAL 18)
add_compile_options(-Wno-nan-infinity-disabled)
add_compile_definitions("ZETA_HAS_NO_UNIQUE_ADDRESS")
endif()
# Echo the currently compiled filename
if (${CMAKE_CXX_SIMULATE_ID} STREQUAL MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /showFilenames")
endif()
endif()
#
# common paths
#
set(EXTERNAL_DIR "${CMAKE_SOURCE_DIR}/External")
set(TOOLS_DIR "${CMAKE_SOURCE_DIR}/Tools")
set(ZETA_CORE_DIR "${CMAKE_SOURCE_DIR}/Source/ZetaCore")
set(ZETA_RENDER_PASS_DIR "${CMAKE_SOURCE_DIR}/Source/ZetaRenderPass")
string(LENGTH "${ZETA_RENDER_PASS_DIR}" ZETA_RENDER_PASS_DIR_LEN)
set(ZETA_RENDERER_DIR "${CMAKE_SOURCE_DIR}/Source/ZetaRenderer")
set(ASSET_DIR "${CMAKE_SOURCE_DIR}/Assets")
set(CSO_DIR "${ASSET_DIR}/CSO")
#
# setup DXC
#
SetupDXC(DXC_BIN_DIR)
add_subdirectory(Source)
if(BUILD_TESTS)
add_subdirectory(Tests)
endif()
if(BUILD_TOOLS)
add_subdirectory(Tools)
endif()