CMake: Enable strict flags for C++
[blender.git] / intern / cycles / kernel / CMakeLists.txt
1 remove_extra_strict_flags()
2
3 set(INC
4         .
5         ../util
6         osl
7         svm
8 )
9
10 set(INC_SYS
11
12 )
13
14 set(SRC
15         kernel.cpp
16         kernel.cl
17         kernel.cu
18 )
19
20 set(SRC_HEADERS
21         kernel.h
22         kernel_accumulate.h
23         kernel_bake.h
24         kernel_camera.h
25         kernel_compat_cpu.h
26         kernel_compat_cuda.h
27         kernel_compat_opencl.h
28         kernel_debug.h
29         kernel_differential.h
30         kernel_emission.h
31         kernel_film.h
32         kernel_globals.h
33         kernel_jitter.h
34         kernel_light.h
35         kernel_math.h
36         kernel_montecarlo.h
37         kernel_passes.h
38         kernel_path.h
39         kernel_path_state.h
40         kernel_path_surface.h
41         kernel_path_volume.h
42         kernel_projection.h
43         kernel_random.h
44         kernel_shader.h
45         kernel_shadow.h
46         kernel_subsurface.h
47         kernel_textures.h
48         kernel_types.h
49         kernel_volume.h
50 )
51
52 set(SRC_CLOSURE_HEADERS
53         closure/bsdf.h
54         closure/bsdf_ashikhmin_velvet.h
55         closure/bsdf_diffuse.h
56         closure/bsdf_diffuse_ramp.h
57         closure/bsdf_microfacet.h
58         closure/bsdf_oren_nayar.h
59         closure/bsdf_phong_ramp.h
60         closure/bsdf_reflection.h
61         closure/bsdf_refraction.h
62         closure/bsdf_toon.h
63         closure/bsdf_transparent.h
64         closure/bsdf_util.h
65         closure/bsdf_ashikhmin_shirley.h
66         closure/bsdf_hair.h
67         closure/bssrdf.h
68         closure/emissive.h
69         closure/volume.h
70 )
71 set(SRC_SVM_HEADERS
72         svm/svm.h
73         svm/svm_attribute.h
74         svm/svm_blackbody.h
75         svm/svm_camera.h
76         svm/svm_closure.h
77         svm/svm_convert.h
78         svm/svm_checker.h
79         svm/svm_brick.h
80         svm/svm_displace.h
81         svm/svm_fresnel.h
82         svm/svm_wireframe.h
83         svm/svm_wavelength.h
84         svm/svm_gamma.h
85         svm/svm_brightness.h
86         svm/svm_geometry.h
87         svm/svm_gradient.h
88         svm/svm_hsv.h
89         svm/svm_image.h
90         svm/svm_invert.h
91         svm/svm_light_path.h
92         svm/svm_magic.h
93         svm/svm_mapping.h
94         svm/svm_math.h
95         svm/svm_math_util.h
96         svm/svm_mix.h
97         svm/svm_musgrave.h
98         svm/svm_noise.h
99         svm/svm_noisetex.h
100         svm/svm_normal.h
101         svm/svm_ramp.h
102         svm/svm_sepcomb_hsv.h
103         svm/svm_sepcomb_vector.h
104         svm/svm_sky.h
105         svm/svm_tex_coord.h
106         svm/svm_texture.h
107         svm/svm_types.h
108         svm/svm_value.h
109         svm/svm_vector_transform.h
110         svm/svm_voronoi.h
111         svm/svm_wave.h
112 )
113
114 set(SRC_GEOM_HEADERS
115         geom/geom.h
116         geom/geom_attribute.h
117         geom/geom_bvh.h
118         geom/geom_bvh_shadow.h
119         geom/geom_bvh_subsurface.h
120         geom/geom_bvh_traversal.h
121         geom/geom_bvh_volume.h
122         geom/geom_curve.h
123         geom/geom_motion_curve.h
124         geom/geom_motion_triangle.h
125         geom/geom_object.h
126         geom/geom_primitive.h
127         geom/geom_qbvh.h
128         geom/geom_qbvh_shadow.h
129         geom/geom_qbvh_subsurface.h
130         geom/geom_qbvh_traversal.h
131         geom/geom_qbvh_volume.h
132         geom/geom_triangle.h
133         geom/geom_triangle_intersect.h
134         geom/geom_volume.h
135 )
136
137 set(SRC_UTIL_HEADERS
138         ../util/util_color.h
139         ../util/util_half.h
140         ../util/util_math.h
141         ../util/util_math_fast.h
142         ../util/util_transform.h
143         ../util/util_types.h
144 )
145 # CUDA module
146
147 if(WITH_CYCLES_CUDA_BINARIES)
148         # 32 bit or 64 bit
149         if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
150                 set(CUDA_BITS 64)
151         else()
152                 set(CUDA_BITS 32)
153         endif()
154
155         # CUDA version
156         execute_process (COMMAND ${CUDA_NVCC_EXECUTABLE} "--version" OUTPUT_VARIABLE NVCC_OUT)
157         string(REGEX REPLACE ".*release ([0-9]+)\\.([0-9]+).*" "\\1" CUDA_VERSION_MAJOR ${NVCC_OUT})
158         string(REGEX REPLACE ".*release ([0-9]+)\\.([0-9]+).*" "\\2" CUDA_VERSION_MINOR ${NVCC_OUT})
159         set(CUDA_VERSION "${CUDA_VERSION_MAJOR}${CUDA_VERSION_MINOR}")
160
161         # warn for other versions
162         if(CUDA_VERSION MATCHES "65")
163         else()
164                 message(WARNING
165                         "CUDA version ${CUDA_VERSION_MAJOR}.${CUDA_VERSION_MINOR} detected, "
166                         "build may succeed but only CUDA 6.5 is officially supported")
167         endif()
168
169         # build for each arch
170         set(cuda_sources kernel.cu ${SRC_HEADERS} ${SRC_SVM_HEADERS} ${SRC_GEOM_HEADERS} ${SRC_CLOSURE_HEADERS} ${SRC_UTIL_HEADERS})
171         set(cuda_cubins)
172
173         macro(CYCLES_CUDA_KERNEL_ADD arch experimental)
174                 if(${experimental})
175                         set(cuda_extra_flags "-D__KERNEL_CUDA_EXPERIMENTAL__")
176                         set(cuda_cubin kernel_experimental_${arch}.cubin)
177                 else()
178                         set(cuda_extra_flags "")
179                         set(cuda_cubin kernel_${arch}.cubin)
180                 endif()
181
182                 if(WITH_CYCLES_DEBUG)
183                         set(cuda_debug_flags "-D__KERNEL_DEBUG__")
184                 else()
185                         set(cuda_debug_flags "")
186                 endif()
187
188                 set(cuda_version_flags "-D__KERNEL_CUDA_VERSION__=${CUDA_VERSION}")
189                 set(cuda_math_flags "--use_fast_math")
190
191                 add_custom_command(
192                         OUTPUT ${cuda_cubin}
193                         COMMAND ${CUDA_NVCC_EXECUTABLE}
194                                         -arch=${arch}
195                                         -m${CUDA_BITS}
196                                         --cubin ${CMAKE_CURRENT_SOURCE_DIR}/kernel.cu
197                                         -o ${CMAKE_CURRENT_BINARY_DIR}/${cuda_cubin}
198                                         --ptxas-options="-v"
199                                         ${cuda_arch_flags}
200                                         ${cuda_version_flags}
201                                         ${cuda_math_flags}
202                                         ${cuda_extra_flags}
203                                         ${cuda_debug_flags}
204                                         -I${CMAKE_CURRENT_SOURCE_DIR}/../util
205                                         -I${CMAKE_CURRENT_SOURCE_DIR}/svm
206                                         -DCCL_NAMESPACE_BEGIN=
207                                         -DCCL_NAMESPACE_END=
208                                         -DNVCC
209
210                         DEPENDS ${cuda_sources})
211
212                 delayed_install("${CMAKE_CURRENT_BINARY_DIR}" "${cuda_cubin}" ${CYCLES_INSTALL_PATH}/lib)
213                 list(APPEND cuda_cubins ${cuda_cubin})
214
215                 unset(cuda_extra_flags)
216                 unset(cuda_debug_flags)
217         endmacro()
218
219         foreach(arch ${CYCLES_CUDA_BINARIES_ARCH})
220                 # Compile regular kernel
221                 CYCLES_CUDA_KERNEL_ADD(${arch} FALSE)
222
223                 # Compile experimental kernel
224                 CYCLES_CUDA_KERNEL_ADD(${arch} TRUE)
225         endforeach()
226
227         add_custom_target(cycles_kernel_cuda ALL DEPENDS ${cuda_cubins})
228 endif()
229
230 # OSL module
231
232 if(WITH_CYCLES_OSL)
233         add_subdirectory(osl)
234         add_subdirectory(shaders)
235 endif()
236
237 # CPU module
238
239 include_directories(${INC})
240 include_directories(SYSTEM ${INC_SYS})
241
242 if(CXX_HAS_SSE)
243         list(APPEND SRC
244                 kernel_sse2.cpp
245                 kernel_sse3.cpp
246                 kernel_sse41.cpp
247         )
248
249         set_source_files_properties(kernel_sse2.cpp PROPERTIES COMPILE_FLAGS "${CYCLES_SSE2_KERNEL_FLAGS}")
250         set_source_files_properties(kernel_sse3.cpp PROPERTIES COMPILE_FLAGS "${CYCLES_SSE3_KERNEL_FLAGS}")
251         set_source_files_properties(kernel_sse41.cpp PROPERTIES COMPILE_FLAGS "${CYCLES_SSE41_KERNEL_FLAGS}")
252 endif()
253
254 if(CXX_HAS_AVX)
255         list(APPEND SRC
256                 kernel_avx.cpp
257         )
258         set_source_files_properties(kernel_avx.cpp PROPERTIES COMPILE_FLAGS "${CYCLES_AVX_KERNEL_FLAGS}")
259 endif()
260
261 if(CXX_HAS_AVX2)
262         list(APPEND SRC
263                 kernel_avx2.cpp
264         )
265         set_source_files_properties(kernel_avx2.cpp PROPERTIES COMPILE_FLAGS "${CYCLES_AVX2_KERNEL_FLAGS}")
266 endif()
267
268 add_library(cycles_kernel ${SRC} ${SRC_HEADERS} ${SRC_CLOSURE_HEADERS} ${SRC_SVM_HEADERS} ${SRC_GEOM_HEADERS})
269
270 if(WITH_CYCLES_CUDA)
271         add_dependencies(cycles_kernel cycles_kernel_cuda)
272 endif()
273
274 # OpenCL kernel
275
276 #set(KERNEL_PREPROCESSED ${CMAKE_CURRENT_BINARY_DIR}/kernel_preprocessed.cl)
277 #add_custom_command(
278 #       OUTPUT ${KERNEL_PREPROCESSED}
279 #       COMMAND gcc -x c++ -E ${CMAKE_CURRENT_SOURCE_DIR}/kernel.cl -I ${CMAKE_CURRENT_SOURCE_DIR}/../util/ -DCCL_NAMESPACE_BEGIN= -DCCL_NAMESPACE_END= -o ${KERNEL_PREPROCESSED}
280 #       DEPENDS ${SRC_KERNEL} ${SRC_UTIL_HEADERS})
281 #add_custom_target(cycles_kernel_preprocess ALL DEPENDS ${KERNEL_PREPROCESSED})
282 #delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "${KERNEL_PREPROCESSED}" ${CYCLES_INSTALL_PATH}/kernel)
283
284 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "kernel.cl" ${CYCLES_INSTALL_PATH}/kernel)
285 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "kernel.cu" ${CYCLES_INSTALL_PATH}/kernel)
286 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "${SRC_HEADERS}" ${CYCLES_INSTALL_PATH}/kernel)
287 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "${SRC_CLOSURE_HEADERS}" ${CYCLES_INSTALL_PATH}/kernel/closure)
288 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "${SRC_SVM_HEADERS}" ${CYCLES_INSTALL_PATH}/kernel/svm)
289 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "${SRC_GEOM_HEADERS}" ${CYCLES_INSTALL_PATH}/kernel/geom)
290 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "${SRC_UTIL_HEADERS}" ${CYCLES_INSTALL_PATH}/kernel)
291