UI: UV: Add Select Shortest Path to menu
[blender.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   # WINDOWS_PYTHON_DEBUG needs to write into the user addons folder since it will
7   # be started with --env-system-scripts pointing to the release folder, which will
8   # lack the cycles addon, and we don't want to write into it.
9   if(NOT WINDOWS_PYTHON_DEBUG)
10     set(CYCLES_INSTALL_PATH "scripts/addons/cycles")
11   else()
12     set(CYCLES_INSTALL_PATH "$ENV{appdata}/blender foundation/blender/${BLENDER_VERSION}/scripts/addons/cycles")
13   endif()
14 endif()
15
16 # External Libraries
17
18 include(cmake/external_libs.cmake)
19 include(cmake/macros.cmake)
20
21 # Build Flags
22 # todo: this code could be refactored a bit to avoid duplication
23 # note: CXX_HAS_SSE is needed in case passing SSE flags fails altogether (gcc-arm)
24
25 if(WITH_CYCLES_NATIVE_ONLY)
26   set(CXX_HAS_SSE FALSE)
27   set(CXX_HAS_AVX FALSE)
28   set(CXX_HAS_AVX2 FALSE)
29   add_definitions(
30     -DWITH_KERNEL_NATIVE
31   )
32
33   if(NOT MSVC)
34     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
35     set(CYCLES_KERNEL_FLAGS "-march=native")
36   endif()
37 elseif(NOT WITH_CPU_SSE)
38   set(CXX_HAS_SSE FALSE)
39   set(CXX_HAS_AVX FALSE)
40   set(CXX_HAS_AVX2 FALSE)
41 elseif(WIN32 AND MSVC AND NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang")
42   set(CXX_HAS_SSE TRUE)
43   set(CXX_HAS_AVX TRUE)
44   set(CXX_HAS_AVX2 TRUE)
45
46   # /arch:AVX for VC2012 and above
47   if(NOT MSVC_VERSION LESS 1700)
48     set(CYCLES_AVX_ARCH_FLAGS "/arch:AVX")
49     set(CYCLES_AVX2_ARCH_FLAGS "/arch:AVX /arch:AVX2")
50   elseif(NOT CMAKE_CL_64)
51     set(CYCLES_AVX_ARCH_FLAGS "/arch:SSE2")
52     set(CYCLES_AVX2_ARCH_FLAGS "/arch:SSE2")
53   endif()
54
55   # Unlike GCC/clang we still use fast math, because there is no fine
56   # grained control and the speedup we get here is too big to ignore.
57   set(CYCLES_KERNEL_FLAGS "/fp:fast -D_CRT_SECURE_NO_WARNINGS /GS-")
58
59   # there is no /arch:SSE3, but intrinsics are available anyway
60   if(CMAKE_CL_64)
61     set(CYCLES_SSE2_KERNEL_FLAGS "${CYCLES_KERNEL_FLAGS}")
62     set(CYCLES_SSE3_KERNEL_FLAGS "${CYCLES_KERNEL_FLAGS}")
63     set(CYCLES_SSE41_KERNEL_FLAGS "${CYCLES_KERNEL_FLAGS}")
64     set(CYCLES_AVX_KERNEL_FLAGS "${CYCLES_AVX_ARCH_FLAGS} ${CYCLES_KERNEL_FLAGS}")
65     set(CYCLES_AVX2_KERNEL_FLAGS "${CYCLES_AVX2_ARCH_FLAGS} ${CYCLES_KERNEL_FLAGS}")
66   else()
67     set(CYCLES_SSE2_KERNEL_FLAGS "/arch:SSE2 ${CYCLES_KERNEL_FLAGS}")
68     set(CYCLES_SSE3_KERNEL_FLAGS "/arch:SSE2 ${CYCLES_KERNEL_FLAGS}")
69     set(CYCLES_SSE41_KERNEL_FLAGS "/arch:SSE2 ${CYCLES_KERNEL_FLAGS}")
70     set(CYCLES_AVX_KERNEL_FLAGS "${CYCLES_AVX_ARCH_FLAGS} ${CYCLES_KERNEL_FLAGS}")
71     set(CYCLES_AVX2_KERNEL_FLAGS "${CYCLES_AVX2_ARCH_FLAGS} ${CYCLES_KERNEL_FLAGS}")
72   endif()
73
74   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CYCLES_KERNEL_FLAGS}")
75   set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Ox")
76   set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /Ox")
77   set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} /Ox")
78 elseif(CMAKE_COMPILER_IS_GNUCC OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
79   check_cxx_compiler_flag(-msse CXX_HAS_SSE)
80   check_cxx_compiler_flag(-mavx CXX_HAS_AVX)
81   check_cxx_compiler_flag(-mavx2 CXX_HAS_AVX2)
82
83   # Assume no signal trapping for better code generation.
84   set(CYCLES_KERNEL_FLAGS "-fno-trapping-math")
85   # Avoid overhead of setting errno for NaNs.
86   set(CYCLES_KERNEL_FLAGS "${CYCLES_KERNEL_FLAGS} -fno-math-errno")
87   # Let compiler optimize 0.0 - x without worrying about signed zeros.
88   set(CYCLES_KERNEL_FLAGS "${CYCLES_KERNEL_FLAGS} -fno-signed-zeros")
89
90   if(CMAKE_COMPILER_IS_GNUCC)
91     # Assume no signal trapping for better code generation.
92     set(CYCLES_KERNEL_FLAGS "${CYCLES_KERNEL_FLAGS} -fno-signaling-nans")
93     # Assume a fixed rounding mode for better constant folding.
94     set(CYCLES_KERNEL_FLAGS "${CYCLES_KERNEL_FLAGS} -fno-rounding-math")
95   endif()
96
97   if(CXX_HAS_SSE)
98     if(CMAKE_COMPILER_IS_GNUCC)
99       set(CYCLES_KERNEL_FLAGS "${CYCLES_KERNEL_FLAGS} -mfpmath=sse")
100     endif()
101
102     set(CYCLES_SSE2_KERNEL_FLAGS "${CYCLES_KERNEL_FLAGS} -msse -msse2")
103     set(CYCLES_SSE3_KERNEL_FLAGS "${CYCLES_SSE2_KERNEL_FLAGS} -msse3 -mssse3")
104     set(CYCLES_SSE41_KERNEL_FLAGS "${CYCLES_SSE3_KERNEL_FLAGS} -msse4.1")
105     if(CXX_HAS_AVX)
106       set(CYCLES_AVX_KERNEL_FLAGS "${CYCLES_SSE41_KERNEL_FLAGS} -mavx")
107     endif()
108     if(CXX_HAS_AVX2)
109       set(CYCLES_AVX2_KERNEL_FLAGS "${CYCLES_SSE41_KERNEL_FLAGS} -mavx -mavx2 -mfma -mlzcnt -mbmi -mbmi2 -mf16c")
110     endif()
111   endif()
112
113   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CYCLES_KERNEL_FLAGS}")
114 elseif(WIN32 AND CMAKE_CXX_COMPILER_ID MATCHES "Intel")
115   check_cxx_compiler_flag(/QxSSE2 CXX_HAS_SSE)
116   check_cxx_compiler_flag(/arch:AVX CXX_HAS_AVX)
117   check_cxx_compiler_flag(/QxCORE-AVX2 CXX_HAS_AVX2)
118
119   if(CXX_HAS_SSE)
120     set(CYCLES_SSE2_KERNEL_FLAGS "/QxSSE2")
121     set(CYCLES_SSE3_KERNEL_FLAGS "/QxSSSE3")
122     set(CYCLES_SSE41_KERNEL_FLAGS "/QxSSE4.1")
123
124     if(CXX_HAS_AVX)
125       set(CYCLES_AVX_KERNEL_FLAGS "/arch:AVX")
126     endif()
127
128     if(CXX_HAS_AVX2)
129       set(CYCLES_AVX2_KERNEL_FLAGS "/QxCORE-AVX2")
130     endif()
131   endif()
132 elseif(CMAKE_CXX_COMPILER_ID MATCHES "Intel")
133   if(APPLE)
134     # ICC does not support SSE2 flag on MacOSX
135     check_cxx_compiler_flag(-xssse3 CXX_HAS_SSE)
136   else()
137     check_cxx_compiler_flag(-xsse2 CXX_HAS_SSE)
138   endif()
139
140   check_cxx_compiler_flag(-xavx CXX_HAS_AVX)
141   check_cxx_compiler_flag(-xcore-avx2 CXX_HAS_AVX2)
142
143   if(CXX_HAS_SSE)
144     if(APPLE)
145       # ICC does not support SSE2 flag on MacOSX
146       set(CYCLES_SSE2_KERNEL_FLAGS "-xssse3")
147     else()
148       set(CYCLES_SSE2_KERNEL_FLAGS "-xsse2")
149     endif()
150
151     set(CYCLES_SSE3_KERNEL_FLAGS "-xssse3")
152     set(CYCLES_SSE41_KERNEL_FLAGS "-xsse4.1")
153
154     if(CXX_HAS_AVX)
155       set(CYCLES_AVX_KERNEL_FLAGS "-xavx")
156     endif()
157
158     if(CXX_HAS_AVX2)
159       set(CYCLES_AVX2_KERNEL_FLAGS "-xcore-avx2")
160     endif()
161   endif()
162 endif()
163
164 if(CXX_HAS_SSE)
165   add_definitions(
166     -DWITH_KERNEL_SSE2
167     -DWITH_KERNEL_SSE3
168     -DWITH_KERNEL_SSE41
169   )
170 endif()
171
172 if(CXX_HAS_AVX)
173   add_definitions(-DWITH_KERNEL_AVX)
174 endif()
175
176 if(CXX_HAS_AVX2)
177   add_definitions(-DWITH_KERNEL_AVX2)
178 endif()
179
180 # LLVM and OSL need to build without RTTI
181 if(WIN32 AND MSVC)
182   set(RTTI_DISABLE_FLAGS "/GR- -DBOOST_NO_RTTI -DBOOST_NO_TYPEID")
183 elseif(CMAKE_COMPILER_IS_GNUCC OR (CMAKE_C_COMPILER_ID MATCHES "Clang"))
184   set(RTTI_DISABLE_FLAGS "-fno-rtti -DBOOST_NO_RTTI -DBOOST_NO_TYPEID")
185 endif()
186
187 # Definitions and Includes
188
189 add_definitions(
190   ${BOOST_DEFINITIONS}
191   ${OPENIMAGEIO_DEFINITIONS}
192 )
193
194 add_definitions(
195   -DCCL_NAMESPACE_BEGIN=namespace\ ccl\ {
196   -DCCL_NAMESPACE_END=}
197 )
198
199 if(WITH_CYCLES_STANDALONE_GUI)
200   add_definitions(-DWITH_CYCLES_STANDALONE_GUI)
201 endif()
202
203 if(WITH_CYCLES_PTEX)
204   add_definitions(-DWITH_PTEX)
205 endif()
206
207 if(WITH_CYCLES_OSL)
208   add_definitions(-DWITH_OSL)
209   # osl 1.9.x
210   add_definitions(-DOSL_STATIC_BUILD)
211   # pre 1.9
212   add_definitions(-DOSL_STATIC_LIBRARY)
213   include_directories(
214     SYSTEM
215     ${OSL_INCLUDE_DIR}
216   )
217 endif()
218
219 if(WITH_CYCLES_DEVICE_OPTIX)
220   find_package(OptiX)
221
222   if(OPTIX_FOUND)
223     add_definitions(-DWITH_OPTIX)
224     include_directories(
225       SYSTEM
226       ${OPTIX_INCLUDE_DIR}
227       )
228   else()
229     message(STATUS "OptiX not found, disabling it from Cycles")
230     set(WITH_CYCLES_DEVICE_OPTIX OFF)
231   endif()
232 endif()
233
234 if(WITH_CYCLES_EMBREE)
235   add_definitions(-DWITH_EMBREE)
236   add_definitions(-DEMBREE_STATIC_LIB)
237   include_directories(
238     SYSTEM
239     ${EMBREE_INCLUDE_DIRS}
240   )
241 endif()
242
243 if(WITH_OPENSUBDIV)
244   add_definitions(-DWITH_OPENSUBDIV)
245   include_directories(
246     SYSTEM
247     ${OPENSUBDIV_INCLUDE_DIR}
248   )
249 endif()
250
251 if(WITH_CYCLES_STANDALONE)
252   set(WITH_CYCLES_DEVICE_OPENCL TRUE)
253   set(WITH_CYCLES_DEVICE_CUDA TRUE)
254   # Experimental and unfinished.
255   set(WITH_CYCLES_NETWORK FALSE)
256 endif()
257 # TODO(sergey): Consider removing it, only causes confusion in interface.
258 set(WITH_CYCLES_DEVICE_MULTI TRUE)
259
260 # Logging capabilities using GLog library.
261 if(WITH_CYCLES_LOGGING)
262   add_definitions(-DWITH_CYCLES_LOGGING)
263   add_definitions(${GLOG_DEFINES})
264   add_definitions(-DCYCLES_GFLAGS_NAMESPACE=${GFLAGS_NAMESPACE})
265   include_directories(
266     SYSTEM
267     ${GLOG_INCLUDE_DIRS}
268     ${GFLAGS_INCLUDE_DIRS}
269   )
270 endif()
271
272 # Debugging capabilities (debug passes etc).
273 if(WITH_CYCLES_DEBUG)
274   add_definitions(-DWITH_CYCLES_DEBUG)
275 endif()
276
277 if(NOT OPENIMAGEIO_PUGIXML_FOUND)
278   add_definitions(-DWITH_SYSTEM_PUGIXML)
279 endif()
280
281 include_directories(
282   SYSTEM
283   ${BOOST_INCLUDE_DIR}
284   ${OPENIMAGEIO_INCLUDE_DIRS}
285   ${OPENIMAGEIO_INCLUDE_DIRS}/OpenImageIO
286   ${OPENEXR_INCLUDE_DIR}
287   ${OPENEXR_INCLUDE_DIRS}
288   ${PUGIXML_INCLUDE_DIR}
289   ${TBB_INCLUDE_DIRS}
290 )
291
292 if(CYCLES_STANDALONE_REPOSITORY)
293   include_directories(../third_party/atomic)
294 else()
295   include_directories(../atomic)
296 endif()
297
298 # Warnings
299 if(CMAKE_COMPILER_IS_GNUCXX)
300   ADD_CHECK_CXX_COMPILER_FLAG(CMAKE_CXX_FLAGS _has_cxxflag_float_conversion "-Werror=float-conversion")
301   ADD_CHECK_CXX_COMPILER_FLAG(CMAKE_CXX_FLAGS _has_cxxflag_double_promotion "-Werror=double-promotion")
302   ADD_CHECK_CXX_COMPILER_FLAG(CMAKE_CXX_FLAGS _has_no_error_unused_macros "-Wno-error=unused-macros")
303   unset(_has_cxxflag_float_conversion)
304   unset(_has_cxxflag_double_promotion)
305   unset(_has_no_error_unused_macros)
306 endif()
307
308 if(WITH_CYCLES_CUDA_BINARIES AND (NOT WITH_CYCLES_CUBIN_COMPILER))
309   if(MSVC)
310     set(MAX_MSVC 1800)
311     if(${CUDA_VERSION} EQUAL "8.0")
312       set(MAX_MSVC 1900)
313     elseif(${CUDA_VERSION} EQUAL "9.0")
314       set(MAX_MSVC 1910)
315     elseif(${CUDA_VERSION} EQUAL "9.1")
316       set(MAX_MSVC 1911)
317     elseif(${CUDA_VERSION} LESS "11.0")
318       set(MAX_MSVC 1999)
319     endif()
320     if(NOT MSVC_VERSION LESS ${MAX_MSVC} OR CMAKE_C_COMPILER_ID MATCHES "Clang")
321       message(STATUS "nvcc not supported for this compiler version, using cycles_cubin_cc instead.")
322       set(WITH_CYCLES_CUBIN_COMPILER ON)
323     endif()
324     unset(MAX_MSVC)
325   elseif(APPLE)
326     if(NOT (${XCODE_VERSION} VERSION_LESS 10.0))
327       message(STATUS "nvcc not supported for this compiler version, using cycles_cubin_cc instead.")
328       set(WITH_CYCLES_CUBIN_COMPILER ON)
329     endif()
330   endif()
331 endif()
332
333 # NVRTC gives wrong rendering result in CUDA 10.0, so we must use NVCC.
334 if(WITH_CYCLES_CUDA_BINARIES AND WITH_CYCLES_CUBIN_COMPILER AND NOT WITH_CYCLES_CUBIN_COMPILER_OVERRRIDE)
335   if(NOT (${CUDA_VERSION} VERSION_LESS 10.0))
336     message(STATUS "cycles_cubin_cc not supported for CUDA 10.0+, using nvcc instead.")
337     set(WITH_CYCLES_CUBIN_COMPILER OFF)
338   endif()
339 endif()
340
341 # Subdirectories
342
343 if(WITH_CYCLES_BLENDER)
344   add_definitions(-DWITH_BLENDER_GUARDEDALLOC)
345   add_subdirectory(blender)
346 endif()
347
348 if(WITH_CYCLES_NETWORK)
349   add_definitions(-DWITH_NETWORK)
350 endif()
351
352 if(WITH_CYCLES_STANDALONE OR WITH_CYCLES_NETWORK OR WITH_CYCLES_CUBIN_COMPILER)
353   add_subdirectory(app)
354 endif()
355
356 add_subdirectory(bvh)
357 add_subdirectory(device)
358 add_subdirectory(doc)
359 add_subdirectory(graph)
360 add_subdirectory(kernel)
361 add_subdirectory(render)
362 add_subdirectory(subd)
363 add_subdirectory(util)
364
365 # TODO(sergey): Make this to work with standalone repository.
366 if(WITH_GTESTS)
367   add_subdirectory(test)
368 endif()
369
370 if(NOT WITH_BLENDER AND WITH_CYCLES_STANDALONE)
371   delayed_do_install(${CMAKE_BINARY_DIR}/bin)
372 endif()