Fix T54105: random walk SSS missing in branched indirect paths.
[blender-staging.git] / intern / cycles / CMakeLists.txt
1 # Standalone or with Blender
2 if(NOT WITH_BLENDER AND WITH_CYCLES_STANDALONE)
3         set(CYCLES_INSTALL_PATH "")
4 else()
5         set(WITH_CYCLES_BLENDER ON)
6         set(CYCLES_INSTALL_PATH "scripts/addons/cycles")
7 endif()
8
9 # External Libraries
10
11 include(cmake/external_libs.cmake)
12 include(cmake/macros.cmake)
13
14 # Build Flags
15 # todo: this code could be refactored a bit to avoid duplication
16 # note: CXX_HAS_SSE is needed in case passing SSE flags fails altogether (gcc-arm)
17
18 if(WITH_CYCLES_NATIVE_ONLY)
19         set(CXX_HAS_SSE FALSE)
20         set(CXX_HAS_AVX FALSE)
21         set(CXX_HAS_AVX2 FALSE)
22         add_definitions(
23                 -DWITH_KERNEL_NATIVE
24         )
25
26         if(NOT MSVC)
27                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
28                 set(CYCLES_KERNEL_FLAGS "-march=native")
29         endif()
30 elseif(NOT WITH_CPU_SSE)
31         set(CXX_HAS_SSE FALSE)
32         set(CXX_HAS_AVX FALSE)
33         set(CXX_HAS_AVX2 FALSE)
34 elseif(WIN32 AND MSVC)
35         set(CXX_HAS_SSE TRUE)
36         set(CXX_HAS_AVX TRUE)
37         set(CXX_HAS_AVX2 TRUE)
38
39         # /arch:AVX for VC2012 and above
40         if(NOT MSVC_VERSION LESS 1700)
41                 set(CYCLES_AVX_ARCH_FLAGS "/arch:AVX")
42                 set(CYCLES_AVX2_ARCH_FLAGS "/arch:AVX /arch:AVX2")
43         elseif(NOT CMAKE_CL_64)
44                 set(CYCLES_AVX_ARCH_FLAGS "/arch:SSE2")
45                 set(CYCLES_AVX2_ARCH_FLAGS "/arch:SSE2")
46         endif()
47
48         # Unlike GCC/clang we still use fast math, because there is no fine
49         # grained control and the speedup we get here is too big to ignore.
50         set(CYCLES_KERNEL_FLAGS "/fp:fast -D_CRT_SECURE_NO_WARNINGS /GS-")
51
52         # there is no /arch:SSE3, but intrinsics are available anyway
53         if(CMAKE_CL_64)
54                 set(CYCLES_SSE2_KERNEL_FLAGS "${CYCLES_KERNEL_FLAGS}")
55                 set(CYCLES_SSE3_KERNEL_FLAGS "${CYCLES_KERNEL_FLAGS}")
56                 set(CYCLES_SSE41_KERNEL_FLAGS "${CYCLES_KERNEL_FLAGS}")
57                 set(CYCLES_AVX_KERNEL_FLAGS "${CYCLES_AVX_ARCH_FLAGS} ${CYCLES_KERNEL_FLAGS}")
58                 set(CYCLES_AVX2_KERNEL_FLAGS "${CYCLES_AVX2_ARCH_FLAGS} ${CYCLES_KERNEL_FLAGS}")
59         else()
60                 set(CYCLES_SSE2_KERNEL_FLAGS "/arch:SSE2 ${CYCLES_KERNEL_FLAGS}")
61                 set(CYCLES_SSE3_KERNEL_FLAGS "/arch:SSE2 ${CYCLES_KERNEL_FLAGS}")
62                 set(CYCLES_SSE41_KERNEL_FLAGS "/arch:SSE2 ${CYCLES_KERNEL_FLAGS}")
63                 set(CYCLES_AVX_KERNEL_FLAGS "${CYCLES_AVX_ARCH_FLAGS} ${CYCLES_KERNEL_FLAGS}")
64                 set(CYCLES_AVX2_KERNEL_FLAGS "${CYCLES_AVX2_ARCH_FLAGS} ${CYCLES_KERNEL_FLAGS}")
65         endif()
66
67         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CYCLES_KERNEL_FLAGS}")
68         set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Ox")
69         set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /Ox")
70         set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} /Ox")
71 elseif(CMAKE_COMPILER_IS_GNUCC OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
72         check_cxx_compiler_flag(-msse CXX_HAS_SSE)
73         check_cxx_compiler_flag(-mavx CXX_HAS_AVX)
74         check_cxx_compiler_flag(-mavx2 CXX_HAS_AVX2)
75
76         # Assume no signal trapping for better code generation.
77         set(CYCLES_KERNEL_FLAGS "-fno-trapping-math")
78         # Avoid overhead of setting errno for NaNs.
79         set(CYCLES_KERNEL_FLAGS "${CYCLES_KERNEL_FLAGS} -fno-math-errno")
80         # Let compiler optimize 0.0 - x without worrying about signed zeros.
81         set(CYCLES_KERNEL_FLAGS "${CYCLES_KERNEL_FLAGS} -fno-signed-zeros")
82
83         if(CMAKE_COMPILER_IS_GNUCC)
84                 # Assume no signal trapping for better code generation.
85                 set(CYCLES_KERNEL_FLAGS "${CYCLES_KERNEL_FLAGS} -fno-signaling-nans")
86                 # Assume a fixed rounding mode for better constant folding.
87                 set(CYCLES_KERNEL_FLAGS "${CYCLES_KERNEL_FLAGS} -fno-rounding-math")
88         endif()
89
90         if(CXX_HAS_SSE)
91                 if(CMAKE_COMPILER_IS_GNUCC)
92                         set(CYCLES_KERNEL_FLAGS "${CYCLES_KERNEL_FLAGS} -mfpmath=sse")
93                 endif()
94
95                 set(CYCLES_SSE2_KERNEL_FLAGS "${CYCLES_KERNEL_FLAGS} -msse -msse2")
96                 set(CYCLES_SSE3_KERNEL_FLAGS "${CYCLES_SSE2_KERNEL_FLAGS} -msse3 -mssse3")
97                 set(CYCLES_SSE41_KERNEL_FLAGS "${CYCLES_SSE3_KERNEL_FLAGS} -msse4.1")
98                 if(CXX_HAS_AVX)
99                         set(CYCLES_AVX_KERNEL_FLAGS "${CYCLES_SSE41_KERNEL_FLAGS} -mavx")
100                 endif()
101                 if(CXX_HAS_AVX2)
102                         set(CYCLES_AVX2_KERNEL_FLAGS "${CYCLES_SSE41_KERNEL_FLAGS} -mavx -mavx2 -mfma -mlzcnt -mbmi -mbmi2 -mf16c")
103                 endif()
104         endif()
105
106         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CYCLES_KERNEL_FLAGS}")
107 endif()
108
109 if(CXX_HAS_SSE)
110         add_definitions(
111                 -DWITH_KERNEL_SSE2
112                 -DWITH_KERNEL_SSE3
113                 -DWITH_KERNEL_SSE41
114         )
115 endif()
116
117 if(CXX_HAS_AVX)
118         add_definitions(-DWITH_KERNEL_AVX)
119 endif()
120
121 if(CXX_HAS_AVX2)
122         add_definitions(-DWITH_KERNEL_AVX2)
123 endif()
124
125 if(WITH_CYCLES_OSL)
126         if(WIN32 AND MSVC)
127                 set(RTTI_DISABLE_FLAGS "/GR- -DBOOST_NO_RTTI -DBOOST_NO_TYPEID")
128         elseif(CMAKE_COMPILER_IS_GNUCC OR (CMAKE_C_COMPILER_ID MATCHES "Clang"))
129                 set(RTTI_DISABLE_FLAGS "-fno-rtti -DBOOST_NO_RTTI -DBOOST_NO_TYPEID")
130         endif()
131 endif()
132
133 # Definitions and Includes
134
135 add_definitions(
136         ${BOOST_DEFINITIONS}
137         ${OPENIMAGEIO_DEFINITIONS}
138 )
139
140 add_definitions(
141         -DCCL_NAMESPACE_BEGIN=namespace\ ccl\ {
142         -DCCL_NAMESPACE_END=}
143 )
144
145 if(WITH_CYCLES_STANDALONE_GUI)
146         add_definitions(-DWITH_CYCLES_STANDALONE_GUI)
147 endif()
148
149 if(WITH_CYCLES_PTEX)
150         add_definitions(-DWITH_PTEX)
151 endif()
152
153 if(WITH_CYCLES_OSL)
154         add_definitions(-DWITH_OSL)
155         add_definitions(-DOSL_STATIC_LIBRARY)
156         include_directories(
157                 SYSTEM
158                 ${OSL_INCLUDE_DIR}
159         )
160 endif()
161
162 if(WITH_CYCLES_OPENSUBDIV)
163         add_definitions(-DWITH_OPENSUBDIV)
164         include_directories(
165                 SYSTEM
166                 ${OPENSUBDIV_INCLUDE_DIR}
167         )
168 endif()
169
170 if(WITH_CYCLES_STANDALONE)
171         set(WITH_CYCLES_DEVICE_OPENCL TRUE)
172         set(WITH_CYCLES_DEVICE_CUDA TRUE)
173         # Experimental and unfinished.
174         set(WITH_CYCLES_NETWORK FALSE)
175 endif()
176 # TODO(sergey): Consider removing it, only causes confusion in interface.
177 set(WITH_CYCLES_DEVICE_MULTI TRUE)
178
179 if(CYCLES_STANDALONE_REPOSITORY)
180         TEST_UNORDERED_MAP_SUPPORT()
181 endif()
182 if(WITH_CXX11)
183         add_definitions(-DCYCLES_STD_UNORDERED_MAP)
184 elseif(HAVE_STD_UNORDERED_MAP_HEADER)
185         if(HAVE_UNORDERED_MAP_IN_STD_NAMESPACE)
186                 add_definitions(-DCYCLES_STD_UNORDERED_MAP)
187         else()
188                 if(HAVE_UNORDERED_MAP_IN_TR1_NAMESPACE)
189                         add_definitions(-DCYCLES_STD_UNORDERED_MAP_IN_TR1_NAMESPACE)
190                 else()
191                         add_definitions(-DCYCLES_NO_UNORDERED_MAP)
192                         message(STATUS "Replacing unordered_map/set with map/set (warning: slower!)")
193                 endif()
194         endif()
195 else()
196         if(HAVE_UNORDERED_MAP_IN_TR1_NAMESPACE)
197                 add_definitions(-DCYCLES_TR1_UNORDERED_MAP)
198         else()
199                 add_definitions(-DCYCLES_NO_UNORDERED_MAP)
200                 message(STATUS "Replacing unordered_map/set with map/set (warning: slower!)")
201         endif()
202 endif()
203
204 # Logging capabilities using GLog library.
205 if(WITH_CYCLES_LOGGING)
206         add_definitions(-DWITH_CYCLES_LOGGING)
207         add_definitions(${GLOG_DEFINES})
208         add_definitions(-DCYCLES_GFLAGS_NAMESPACE=${GFLAGS_NAMESPACE})
209         include_directories(
210                 SYSTEM
211                 ${GLOG_INCLUDE_DIRS}
212                 ${GFLAGS_INCLUDE_DIRS}
213         )
214 endif()
215
216 # Debugging capabilities (debug passes etc).
217 if(WITH_CYCLES_DEBUG)
218         add_definitions(-DWITH_CYCLES_DEBUG)
219 endif()
220
221 if(NOT OPENIMAGEIO_PUGIXML_FOUND)
222         add_definitions(-DWITH_SYSTEM_PUGIXML)
223 endif()
224
225 include_directories(
226         SYSTEM
227         ${BOOST_INCLUDE_DIR}
228         ${OPENIMAGEIO_INCLUDE_DIRS}
229         ${OPENIMAGEIO_INCLUDE_DIRS}/OpenImageIO
230         ${OPENEXR_INCLUDE_DIR}
231         ${OPENEXR_INCLUDE_DIRS}
232         ${PUGIXML_INCLUDE_DIR}
233 )
234
235 if(CYCLES_STANDALONE_REPOSITORY)
236         include_directories(../third_party/atomic)
237 else()
238         include_directories(../atomic)
239 endif()
240
241 # Warnings
242 if(CMAKE_COMPILER_IS_GNUCXX)
243         ADD_CHECK_CXX_COMPILER_FLAG(CMAKE_CXX_FLAGS _has_cxxflag_float_conversion "-Werror=float-conversion")
244         ADD_CHECK_CXX_COMPILER_FLAG(CMAKE_CXX_FLAGS _has_cxxflag_double_promotion "-Werror=double-promotion")
245         ADD_CHECK_CXX_COMPILER_FLAG(CMAKE_CXX_FLAGS _has_no_error_unused_macros "-Wno-error=unused-macros")
246         unset(_has_cxxflag_float_conversion)
247         unset(_has_cxxflag_double_promotion)
248         unset(_has_no_error_unused_macros)
249 endif()
250
251 if(WITH_CYCLES_CUDA_BINARIES AND (NOT WITH_CYCLES_CUBIN_COMPILER))
252         if(MSVC)
253                 set(MAX_MSVC 1800)
254                 if(${CUDA_VERSION} EQUAL "8.0")
255                         set(MAX_MSVC 1900)
256                 elseif(${CUDA_VERSION} EQUAL "9.0")
257                         set(MAX_MSVC 1910)
258                 elseif(${CUDA_VERSION} EQUAL "9.1")
259                         set(MAX_MSVC 1911)
260                 endif()
261                 if(NOT MSVC_VERSION LESS ${MAX_MSVC})
262                         message(STATUS "nvcc not supported for this compiler version, using cycles_cubin_cc instead.")
263                         set(WITH_CYCLES_CUBIN_COMPILER ON)
264                 endif()
265                 unset(MAX_MSVC)
266         endif()
267 endif()
268
269
270 # Subdirectories
271
272 if(WITH_CYCLES_BLENDER)
273         add_definitions(-DWITH_BLENDER_GUARDEDALLOC)
274         add_subdirectory(blender)
275 endif()
276
277 if(WITH_CYCLES_NETWORK)
278         add_definitions(-DWITH_NETWORK)
279 endif()
280
281 if(WITH_CYCLES_STANDALONE OR WITH_CYCLES_NETWORK OR WITH_CYCLES_CUBIN_COMPILER)
282         add_subdirectory(app)
283 endif()
284
285 add_subdirectory(bvh)
286 add_subdirectory(device)
287 add_subdirectory(doc)
288 add_subdirectory(graph)
289 add_subdirectory(kernel)
290 add_subdirectory(render)
291 add_subdirectory(subd)
292 add_subdirectory(util)
293
294 # TODO(sergey): Make this to work with standalone repository.
295 if(WITH_GTESTS)
296         add_subdirectory(test)
297 endif()
298
299 if(NOT WITH_BLENDER AND WITH_CYCLES_STANDALONE)
300         delayed_do_install(${CMAKE_BINARY_DIR}/bin)
301 endif()
302