-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
213 lines (182 loc) · 8.29 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
202
203
204
205
206
207
208
209
210
211
212
213
cmake_minimum_required(VERSION 3.5)
project(toytrace)
set (CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
set (Rapidjson_ENABLE False CACHE BOOL "For debug data output and loading of atmospheric data.")
set (BuildTests True CACHE BOOL "Build the tests")
set (BuildPythonBindings True CACHE BOOL "Build Python bindings")
if(NOT WIN32)
set (CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} -std=c++17) # Set this only for c++ files.
add_compile_options (-Wextra -Wall)
add_compile_options (-fPIC)
add_compile_options (-Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wno-char-subscripts -Winit-self -Wno-unused-function)
add_compile_options ("$<$<CONFIG:RELEASE>:-march=native>")
add_compile_options ("$<$<CONFIG:RELEASE>:-O3>")
add_compile_options ("$<$<CONFIG:RELWITHDEBINFO>:-march=native>")
add_compile_options ("$<$<CONFIG:RELWITHDEBINFO>:-fno-omit-frame-pointer>")
#add_compile_options(-fsanitize=address -fno-omit-frame-pointer)
#set(CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address)
else()
add_compile_options(-std:c++17)
#add_compile_options(/EHsc) # Enable exceptions? Strange, should be enable by default. But got link error without it.
add_definitions(-DNOMINMAX -D_CRT_SECURE_NO_WARNINGS -D_NOEXCEPT=noexcept)
add_definitions(-D_SILENCE_CXX17_ITERATOR_BASE_CLASS_DEPRECATION_WARNING) # Mostly for YAML-Cpp
add_definitions(-D_SILENCE_CXX17_ADAPTOR_TYPEDEFS_DEPRECATION_WARNING) # For Eigen
add_definitions(-DNOGDI -DWIN32_LEAN_AND_MEAN) # Don't let windows api pollute the global namespace with silly macros. windows.h is included by TBB. Nothing else I can do about that.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4244 /wd4305") # float <-> double conversion. Until I get that mess sorted out.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4068") # Unkown pragma
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4099") # pdb file not found
endif()
add_compile_options ("$<$<CONFIG:DEBUG>:-DEIGEN_INITIALIZE_MATRICES_BY_NAN>")
# Eliminate link error caused by boost/pool/simple_segregated_storage.hpp
# https://stackoverflow.com/questions/9723793/undefined-reference-to-boostsystemsystem-category-when-compiling
add_definitions("-DBOOST_SYSTEM_NO_DEPRECATED")
add_definitions("-DFMT_HEADER_ONLY") # Header only mode for fmt lib
#################################################
### Dependencies
#################################################
# Just to get TBB to work ...
if (WIN32)
find_package(tbb REQUIRED)
# VCPKG stuff. Any way to make it independent of package manager?
# Regular find script cannot find it. On Ubuntu, the config file which
# imports this nice TBB::tbb target is not available.
# So I have to get to a common ground here.
#get_target_property(TBB_DEBUG_LIBRARIES TBB::tbb IMPORTED_LOCATION_DEBUG)
#get_target_property(TBB_LIBRARIES TBB::tbb IMPORTED_LOCATION_RELEASE)
#get_target_property(TBB_INCLUDE_DIRS TBB::tbb INTERFACE_INCLUDE_DIRECTORIES)
else()
find_package(TBB REQUIRED)
if (NOT TBB_DEBUG_LIBRARIES)
# On linux there are no special debug libs? But we need to set it to be able
# to deal use the same link command on windows and linux.
set (TBB_DEBUG_LIBRARIES ${TBB_LIBRARIES})
endif()
endif(WIN32)
#message(WARNING "Tbb libs are: ${TBB_LIBRARIES} ${TBB_DEBUG_LIBRARIES} and the include dirs: ${TBB_INCLUDE_DIRS}")
find_package(X11)
find_package(Threads REQUIRED)
find_package(assimp REQUIRED)
find_package(GTest REQUIRED)
find_package(Boost REQUIRED COMPONENTS program_options filesystem system)
find_path(CImg_INCLUDE_DIR
NAMES CImg.h
PATHS
${CMAKE_INSTALL_PREFIX}/include
/usr/include
/usr/local/include
)
message(STATUS "CImg: ${CImg_INCLUDE_DIR}")
find_path(Embree_INCLUDE_DIR
NAMES rtcore.h
PATHS
${CMAKE_INSTALL_PREFIX}/include
/usr/include
/usr/local/include)
find_library(Embree_LIBRARY NAMES libembree3)
message(STATUS "Embree: ${Embree_INCLUDE_DIR}, ${Embree_LIBRARY}")
find_library(OPENIMAGEIO_LIBRARY NAMES openimageio OpenImageIO)
find_package(JPEG)
find_package(PNG)
if (Rapidjson_ENABLE)
find_path(Rapidjson_INCLUDE_DIR
NAMES rapidjson/rapidjson.h
PATHS
${CMAKE_INSTALL_PREFIX}/include
/usr/include
/usr/local/include
)
if (NOT Rapidjson_INCLUDE_DIR)
message(FATAL_ERROR "Rapidjson not found!")
else()
message(STATUS "Rapidjson: ${Rapidjson_INCLUDE_DIR}")
endif()
add_definitions("-DHAVE_JSON")
endif()
find_path(YAML_CPP_INCLUDE_DIR
NAMES yaml-cpp/yaml.h
PATHS
${CMAKE_INSTALL_PREFIX}/include
/usr/include
/usr/local/include
)
find_library(YAML_CPP_LIBRARY NAMES yaml-cpp PATHS /usr/local/lib)
message(STATUS "Yaml-cpp Inlcude Path: ${YAML_CPP_INCLUDE_DIR}")
message(STATUS "Yaml-cpp LIBRARY: ${YAML_CPP_LIBRARY}")
#################################################
### Library with common stuff
#################################################
add_library(eigen_plugins INTERFACE)
target_include_directories(eigen_plugins INTERFACE "src/eigen_plugins")
add_library(commonstuff STATIC
src/image.cxx src/parsenff.cxx src/parse_yaml_scene.cxx src/parse_common.cxx src/shader.cxx src/ray.cxx src/sampler.cxx
src/phasefunctions.cxx src/atmosphere.cxx src/spectral.cxx src/primitive.cxx src/renderingalgorithms.cxx
src/light.cxx src/texture.cxx src/embreeaccelerator.cxx src/scene.cxx src/lightpicker_trivial.cxx src/lightpicker_ucb.cxx src/renderingalgorithms_photonmap.cxx src/renderingalgorithms_pathtracing2.cxx
src/renderingalgorithms_normalvisualizer.cxx src/renderingalgorithms_pathtracing.cxx
src/rendering_util.cxx src/pathlogger.cxx src/photonintersector.cxx external/cubature/hcubature.c
src/path_guiding.cxx src/renderingalgorithms_pathtracing_guided.cxx src/distribution_mixture_models.cxx src/path_guiding_tree.cxx src/path_guiding_quadtree.cxx
src/ndarray.hxx src/sampler_tables.cxx src/sampler_sobol_matrices.cxx src/media_integrator.cxx)
file(GLOB headers RELATIVE ${CMAKE_SOURCE_DIR} "src/*.hxx")
target_sources(commonstuff PRIVATE ${headers})
target_link_libraries(commonstuff
${ASSIMP_LIBRARIES}
${Embree_LIBRARY}
${OPENIMAGEIO_LIBRARY}
optimized ${Boost_FILESYSTEM_LIBRARY_RELEASE}
debug ${Boost_FILESYSTEM_LIBRARY_DEBUG}
optimized ${Boost_SYSTEM_LIBRARY_RELEASE}
debug ${Boost_SYSTEM_LIBRARY_DEBUG}
${PNG_LIBRARY} ${JPEG_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
${X11_LIBRARIES}
${YAML_CPP_LIBRARY}
optimized ${TBB_LIBRARIES}
debug ${TBB_DEBUG_LIBRARIES}
eigen_plugins
)
target_include_directories(commonstuff PUBLIC
${PNG_INCLUDE_DIR}
${JPEG_INCLUDE_DIR}
${CImg_INCLUDE_DIR}
${Rapidjson_INCLUDE_DIR}
${Embree_INCLUDE_DIR}
${YAML_CPP_INCLUDE_DIR}
${TBB_INCLUDE_DIRS}
"external/cubature"
"external/variant/include"
"external/fmt/include"
"external")
#################################################
### Executables
#################################################
add_executable(toytrace src/toytrace.cxx)
target_link_libraries(toytrace commonstuff
optimized ${Boost_PROGRAM_OPTIONS_LIBRARY_RELEASE}
debug ${Boost_PROGRAM_OPTIONS_LIBRARY_DEBUG})
if(BuildTests)
add_executable(tests src/tests.cxx src/tests3.cxx src/tests_sampling.cxx src/tests_microfacet.cxx src/tests_stats.cxx src/tests_scene.cxx src/tests_guiding.cxx)
add_executable(tests2 src/tests2.cxx)
add_executable(tests_tbb src/tests_tbb.cxx)
add_executable(experimentation src/experimentation.cxx)
foreach(EXE tests tests2 tests_tbb)
target_include_directories(${EXE} PUBLIC ${GTEST_INCLUDE_DIRS})
target_link_libraries(${EXE} commonstuff ${GTEST_LIBRARIES})
endforeach()
target_link_libraries(experimentation commonstuff)
endif(BuildTests)
#################################################
## Python Lib
#################################################
if (BuildPythonBindings)
find_package(PythonInterp REQUIRED)
find_package(PythonLibs REQUIRED)
add_library(path_guiding SHARED src/path_guiding_py.cxx)
target_link_libraries(path_guiding commonstuff ${PYTHON_LIBRARIES})
target_include_directories(path_guiding PRIVATE ${PYTHON_INCLUDE_DIRS})
set_target_properties(
path_guiding
PROPERTIES
PREFIX ""
OUTPUT_NAME "path_guiding"
LINKER_LANGUAGE C
)
endif(BuildPythonBindings)