msvc: Use source folder structure for project file.
[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         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 set(WITH_CYCLES_DEVICE_OPENCL TRUE)
171 set(WITH_CYCLES_DEVICE_CUDA TRUE)
172 set(WITH_CYCLES_DEVICE_MULTI TRUE)
173
174 if(CYCLES_STANDALONE_REPOSITORY)
175         TEST_UNORDERED_MAP_SUPPORT()
176 endif()
177 if(WITH_CXX11)
178         add_definitions(-DCYCLES_STD_UNORDERED_MAP)
179 elseif(HAVE_STD_UNORDERED_MAP_HEADER)
180         if(HAVE_UNORDERED_MAP_IN_STD_NAMESPACE)
181                 add_definitions(-DCYCLES_STD_UNORDERED_MAP)
182         else()
183                 if(HAVE_UNORDERED_MAP_IN_TR1_NAMESPACE)
184                         add_definitions(-DCYCLES_STD_UNORDERED_MAP_IN_TR1_NAMESPACE)
185                 else()
186                         add_definitions(-DCYCLES_NO_UNORDERED_MAP)
187                         message(STATUS "Replacing unordered_map/set with map/set (warning: slower!)")
188                 endif()
189         endif()
190 else()
191         if(HAVE_UNORDERED_MAP_IN_TR1_NAMESPACE)
192                 add_definitions(-DCYCLES_TR1_UNORDERED_MAP)
193         else()
194                 add_definitions(-DCYCLES_NO_UNORDERED_MAP)
195                 message(STATUS "Replacing unordered_map/set with map/set (warning: slower!)")
196         endif()
197 endif()
198
199 # Logging capabilities using GLog library.
200 if(WITH_CYCLES_LOGGING)
201         add_definitions(-DWITH_CYCLES_LOGGING)
202         add_definitions(${GLOG_DEFINES})
203         add_definitions(-DCYCLES_GFLAGS_NAMESPACE=${GFLAGS_NAMESPACE})
204         include_directories(
205                 SYSTEM
206                 ${GLOG_INCLUDE_DIRS}
207                 ${GFLAGS_INCLUDE_DIRS}
208         )
209 endif()
210
211 # Debugging capabilities (debug passes etc).
212 if(WITH_CYCLES_DEBUG)
213         add_definitions(-DWITH_CYCLES_DEBUG)
214 endif()
215
216 if(NOT OPENIMAGEIO_PUGIXML_FOUND)
217         add_definitions(-DWITH_SYSTEM_PUGIXML)
218 endif()
219
220 include_directories(
221         SYSTEM
222         ${BOOST_INCLUDE_DIR}
223         ${OPENIMAGEIO_INCLUDE_DIRS}
224         ${OPENIMAGEIO_INCLUDE_DIRS}/OpenImageIO
225         ${OPENEXR_INCLUDE_DIR}
226         ${OPENEXR_INCLUDE_DIRS}
227         ${PUGIXML_INCLUDE_DIR}
228 )
229
230 if(CYCLES_STANDALONE_REPOSITORY)
231         include_directories(../third_party/atomic)
232 else()
233         include_directories(../atomic)
234 endif()
235
236 # Warnings
237 if(CMAKE_COMPILER_IS_GNUCXX)
238         ADD_CHECK_CXX_COMPILER_FLAG(CMAKE_CXX_FLAGS _has_cxxflag_float_conversion "-Werror=float-conversion")
239         ADD_CHECK_CXX_COMPILER_FLAG(CMAKE_CXX_FLAGS _has_cxxflag_double_promotion "-Werror=double-promotion")
240         ADD_CHECK_CXX_COMPILER_FLAG(CMAKE_CXX_FLAGS _has_no_error_unused_macros "-Wno-error=unused-macros")
241         unset(_has_cxxflag_float_conversion)
242         unset(_has_cxxflag_double_promotion)
243         unset(_has_no_error_unused_macros)
244 endif()
245
246 if(WITH_CYCLES_CUDA_BINARIES AND (NOT WITH_CYCLES_CUBIN_COMPILER))
247         if(MSVC)
248                 set(MAX_MSVC 1800)
249                 if(${CUDA_VERSION} EQUAL "8.0")
250                         set(MAX_MSVC 1900)
251                 elseif(${CUDA_VERSION} EQUAL "9.0")
252                         set(MAX_MSVC 1910)
253                 elseif(${CUDA_VERSION} EQUAL "9.1")
254                         set(MAX_MSVC 1911)
255                 endif()
256                 if (NOT MSVC_VERSION LESS ${MAX_MSVC})
257                         message(STATUS "nvcc not supported for this compiler version, using cycles_cubin_cc instead.")
258                         set(WITH_CYCLES_CUBIN_COMPILER ON)
259                 endif()
260                 unset(MAX_MSVC)
261         endif()
262 endif()
263
264
265 # Subdirectories
266
267 if(WITH_CYCLES_BLENDER)
268         add_definitions(-DWITH_BLENDER_GUARDEDALLOC)
269         add_subdirectory(blender)
270 endif()
271
272 if(WITH_CYCLES_NETWORK)
273         add_definitions(-DWITH_NETWORK)
274 endif()
275
276 if(WITH_CYCLES_STANDALONE OR WITH_CYCLES_NETWORK OR WITH_CYCLES_CUBIN_COMPILER)
277         add_subdirectory(app)
278 endif()
279
280 add_subdirectory(bvh)
281 add_subdirectory(device)
282 add_subdirectory(doc)
283 add_subdirectory(graph)
284 add_subdirectory(kernel)
285 add_subdirectory(render)
286 add_subdirectory(subd)
287 add_subdirectory(util)
288
289 # TODO(sergey): Make this to work with standalone repository.
290 if(WITH_GTESTS)
291         add_subdirectory(test)
292 endif()
293
294 if(NOT WITH_BLENDER AND WITH_CYCLES_STANDALONE)
295         delayed_do_install(${CMAKE_BINARY_DIR}/bin)
296 endif()
297