-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
184 lines (150 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
cmake_minimum_required(VERSION 3.16)
set(BUILD_TARGET "pbrlab")
project(${BUILD_TARGET} LANGUAGES C CXX)
# options
option(PBRLAB_USE_CCACHE "Use ccache for faster recompile." ON)
option(PBRLAB_BUILD_GUI "Build GUI." ON)
option(PBRLAB_USE_STACK_TRACE_LOGGER "Enable automatic stack trace logger of google-glog. You must install google glog on your computer if you enable this option." OFF)
option(PBRLAB_WITH_EMBREE "Use Embree submodule for faster ray tracing(Off = use NanoRT)." ON)
option(PBRLAB_USE_EXTERNAL_EMBREE "Use Embree(by linking externally) for faster ray tracing(Need to set path to Embree cmake config)." OFF)
# cmake modules
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
# list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/sanitizers)
find_package(Sanitizers) # Address sanitizer (-DSANITIZE_ADDRESS=ON)
# Overall compile options
#set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_GLIBCXX_DEBUG -D_LIBCPP_DEBUG")
#set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_GLIBCXX_DEBUG -D_LIBCPP_DEBUG")
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# [ccache]
if(PBRLAB_USE_CCACHE)
if(MSVC)
# No ccache support
else()
find_program(CCACHE_EXE ccache)
if(CCACHE_EXE)
message(STATUS "Use ccache : " ${CCACHE_EXE})
# CMAKE_C_COMPILER_LAUNCHER = available from cmake 3.4+)
if(CMAKE_C_COMPILER_LAUNCHER)
set(CMAKE_C_COMPILER_LAUNCHER "${CMAKE_C_COMPILER_LAUNCHER}"
"${CCACHE_EXE}")
else()
set(CMAKE_C_COMPILER_LAUNCHER "${CCACHE_EXE}")
endif()
if(CMAKE_CXX_COMPILER_LAUNCHER)
set(CMAKE_CXX_COMPILER_LAUNCHER "${CMAKE_CXX_COMPILER_LAUNCHER}"
"${CCACHE_EXE}")
else()
set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_EXE}")
endif()
endif(CCACHE_EXE)
endif()
endif()
set(PBRLAB_EXT_INCLUDE_DIRS_PRIVATE "")
set(PBRLAB_EXT_LIBRARIES_PRIVATE "")
set(PBRLAB_EXT_LIBRARIES_PUBLIC "")
# find package and check third party
# - pthread
# - OpenGL
# - glfw3
# - Embree3
# - mpark variant
# - ghc filesystem
# - StaticJson
# TODO check third_party
# [Threads]
find_package(Threads REQUIRED)
if(NOT Threads_FOUND)
message(FATAL_ERROR "Threads not found")
endif()
if (PBRLAB_BUILD_GUI)
# [OpenGL]
find_package(OpenGL REQUIRED)
# [glfw3]
set(GLFW_BUILD_EXAMPLES OFF CACHE INTERNAL "" FORCE)
set(GLFW_BUILD_TESTS OFF CACHE INTERNAL "" FORCE)
set(GLFW_BUILD_DOCS OFF CACHE INTERNAL "" FORCE)
set(GLFW_INSTALL OFF CACHE INTERNAL "" FORCE)
add_subdirectory(${PROJECT_SOURCE_DIR}/third_party/glfw)
endif()
# [Embree]
if (PBRLAB_WITH_EMBREE)
if (NOT PBRLAB_USE_EXTERNAL_EMBREE)
set(EMBREE_TASKING_SYSTEM Internal CACHE INTERNAL "" FORCE)
set(EMBREE_ISPC_SUPPORT Off CACHE INTERNAL "" FORCE)
set(EMBREE_TUTORIALS Off CACHE INTERNAL "" FORCE)
set(EMBREE_MAX_ISA SSE2 CACHE INTERNAL "" FORCE)
#set(EMBREE_MAX_ISA AVX CACHE INTERNAL "" FORCE)
set(EMBREE_RAY_PACKETS Off CACHE INTERNAL "" FORCE)
set(EMBREE_BUILD_VERIFY Off CACHE INTERNAL "" FORCE)
# Use static build
set(EMBREE_STATIC_LIB On CACHE INTERNAL "" FORCE)
# Use pbrlab's compile flags.
#set(EMBREE_USE_PARENT_PROJECT_COMPILER_FLAGS On CACHE INTERNAL "" FORCE)
if (SANITIZE_ADDRESS)
set(EMBREE_ADDRESS_SANITIZER On CACHE INTERNAL "" FORCE)
message(STATUS "Enable ASAN for Embree")
endif ()
add_subdirectory(${PROJECT_SOURCE_DIR}/third_party/embree-portable)
list(APPEND PBRLAB_EXT_LIBRARIES_PRIVATE embree)
list(APPEND PBRLAB_EXT_INCLUDE_DIRS_PRIVATE ${CMAKE_SOURCE_DIR}/third_party/embree-portable/include)
else()
message(STATUS "Searching external embree...")
find_package(embree 4.0 REQUIRED)
if (embree_FOUND)
message("External Embree found in ${EMBREE_INCLUDE_DIRS}")
else()
message(FATAL_ERROR "External Embree not found")
endif()
list(APPEND PBRLAB_EXT_LIBRARIES_PRIVATE ${EMBREE_LIBRARY})
list(APPEND PBRLAB_EXT_INCLUDE_DIRS_PRIVATE ${EMBREE_INCLUDE_DIRS})
endif ()
endif (PBRLAB_WITH_EMBREE)
# [mpark variant]
add_subdirectory(${PROJECT_SOURCE_DIR}/third_party/variant)
list(APPEND PBRLAB_EXT_LIBRARIES_PUBLIC mpark_variant)
# [ghc filesystem]
add_subdirectory(${PROJECT_SOURCE_DIR}/third_party/filesystem)
list(APPEND PBRLAB_EXT_LIBRARIES_PUBLIC ghc_filesystem)
# [Static JSON]
add_subdirectory(${PROJECT_SOURCE_DIR}/third_party/)
list(APPEND PBRLAB_EXT_LIBRARIES_PRIVATE staticjson)
set(PBRLAB_CLANG_COMPILE_OPTIONS -Wall -Wextra -Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-padded)
add_subdirectory(src)
add_subdirectory(pc)
# [VisualStudio]
if(MSVC)
# For easier debugging in VS IDE(cmake 3.8.0 or later required) Set working
# directory to ${BUILD_TARGET} git repo root.
if(CMAKE_VERSION VERSION_GREATER 3.8.0)
set_target_properties(pbrlab-cli
PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY
"${CMAKE_CURRENT_SOURCE_DIR}")
endif()
# For easier debugging in VS IDE, set a demo scene.
if(CMAKE_VERSION VERSION_GREATER 3.13.0)
set_target_properties(pbrlab-cli
PROPERTIES VS_DEBUGGER_COMMAND_ARGUMENTS
"./data/cornellbox_suzanne_lucy.obj")
endif()
if (PBRLAB_BUILD_GUI)
# For easier debugging in VS IDE(cmake 3.8.0 or later required) Set working
# directory to ${BUILD_TARGET} git repo root.
if(CMAKE_VERSION VERSION_GREATER 3.8.0)
set_target_properties(pbrlab-gui
PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY
"${CMAKE_CURRENT_SOURCE_DIR}")
endif()
# For easier debugging in VS IDE, set a demo scene.
if(CMAKE_VERSION VERSION_GREATER 3.13.0)
set_target_properties(pbrlab-gui
PROPERTIES VS_DEBUGGER_COMMAND_ARGUMENTS
"./data/cornellbox_suzanne_lucy.obj")
endif()
# Set startup project for VS IDE
set_property(DIRECTORY PROPERTY VS_STARTUP_PROJECT pbrlab-gui)
else()
set_property(DIRECTORY PROPERTY VS_STARTUP_PROJECT pbrlab-cli)
endif()
endif()