Cycles:
[blender.git] / intern / cycles / kernel / CMakeLists.txt
1
2 set(INC
3         .
4         ../util
5         osl
6         svm
7 )
8
9 set(INC_SYS
10
11 )
12
13 set(SRC
14         kernel.cpp
15         kernel_sse2.cpp
16         kernel_sse3.cpp
17         kernel.cl
18         kernel.cu
19 )
20
21 set(SRC_HEADERS
22         kernel.h
23         kernel_accumulate.h
24         kernel_bvh.h
25         kernel_bvh_traversal.h
26         kernel_camera.h
27         kernel_compat_cpu.h
28         kernel_compat_cuda.h
29         kernel_compat_opencl.h
30         kernel_curve.h
31         kernel_differential.h
32         kernel_displace.h
33         kernel_emission.h
34         kernel_film.h
35         kernel_globals.h
36         kernel_jitter.h
37         kernel_light.h
38         kernel_math.h
39         kernel_montecarlo.h
40         kernel_object.h
41         kernel_passes.h
42         kernel_path.h
43         kernel_primitive.h
44         kernel_projection.h
45         kernel_random.h
46         kernel_shader.h
47         kernel_subsurface.h
48         kernel_textures.h
49         kernel_triangle.h
50         kernel_types.h
51 )
52
53 set(SRC_CLOSURE_HEADERS
54         closure/bsdf.h
55         closure/bsdf_ashikhmin_velvet.h
56         closure/bsdf_diffuse.h
57         closure/bsdf_diffuse_ramp.h
58         closure/bsdf_microfacet.h
59         closure/bsdf_oren_nayar.h
60         closure/bsdf_phong_ramp.h
61         closure/bsdf_reflection.h
62         closure/bsdf_refraction.h
63         closure/bsdf_toon.h
64         closure/bsdf_transparent.h
65         closure/bsdf_util.h
66         closure/bsdf_ward.h
67         closure/bsdf_westin.h
68         closure/bssrdf.h
69         closure/emissive.h
70         closure/volume.h
71 )
72 set(SRC_SVM_HEADERS
73         svm/svm.h
74         svm/svm_attribute.h
75         svm/svm_blackbody.h
76         svm/svm_camera.h
77         svm/svm_closure.h
78         svm/svm_convert.h
79         svm/svm_checker.h
80         svm/svm_brick.h
81         svm/svm_displace.h
82         svm/svm_fresnel.h
83         svm/svm_wireframe.h
84         svm/svm_wavelength.h
85         svm/svm_gamma.h
86         svm/svm_brightness.h
87         svm/svm_geometry.h
88         svm/svm_gradient.h
89         svm/svm_hsv.h
90         svm/svm_image.h
91         svm/svm_invert.h
92         svm/svm_light_path.h
93         svm/svm_magic.h
94         svm/svm_mapping.h
95         svm/svm_math.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_rgb.h
103         svm/svm_sepcomb_hsv.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_UTIL_HEADERS
115         ../util/util_color.h
116         ../util/util_math.h
117         ../util/util_transform.h
118         ../util/util_types.h
119 )
120 # CUDA module
121
122 if(WITH_CYCLES_CUDA_BINARIES)
123         # 32 bit or 64 bit
124         if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
125                 set(CUDA_BITS 64)
126         else()
127                 set(CUDA_BITS 32)
128         endif()
129
130         # CUDA version
131         execute_process (COMMAND ${CUDA_NVCC_EXECUTABLE} "--version" OUTPUT_VARIABLE NVCC_OUT)
132         string(REGEX REPLACE ".*release ([0-9]+)\\.([0-9]+).*" "\\1" CUDA_VERSION_MAJOR ${NVCC_OUT})
133         string(REGEX REPLACE ".*release ([0-9]+)\\.([0-9]+).*" "\\2" CUDA_VERSION_MINOR ${NVCC_OUT})
134         set(CUDA_VERSION "${CUDA_VERSION_MAJOR}${CUDA_VERSION_MINOR}")
135
136         # warn for other versions
137         if(CUDA_VERSION MATCHES "50")
138         else()
139                 message(WARNING "CUDA version ${CUDA_VERSION_MAJOR}.${CUDA_VERSION_MINOR} detected, build may succeed but only CUDA 5.0 is officially supported")
140         endif()
141
142         # build for each arch
143         set(cuda_sources kernel.cu ${SRC_HEADERS} ${SRC_SVM_HEADERS} ${SRC_CLOSURE_HEADERS} ${SRC_UTIL_HEADERS})
144         set(cuda_cubins)
145
146         foreach(arch ${CYCLES_CUDA_BINARIES_ARCH})
147                 set(cuda_cubin kernel_${arch}.cubin)
148
149                 set(cuda_version_flags "-D__KERNEL_CUDA_VERSION__=${CUDA_VERSION}")
150
151                 # build flags depending on CUDA version and arch
152                 if(CUDA_VERSION LESS 50)
153                         # CUDA 4.x
154                         if(${arch} MATCHES "sm_1[0-9]")
155                                 # sm_1x
156                                 set(cuda_arch_flags "--maxrregcount=24 --opencc-options -OPT:Olimit=0")
157                         elseif(${arch} MATCHES "sm_2[0-9]")
158                                 # sm_2x
159                                 set(cuda_arch_flags "--maxrregcount=24")
160                         else()
161                                 # sm_3x
162                                 set(cuda_arch_flags "--maxrregcount=32")
163                         endif()
164
165                         set(cuda_math_flags "")
166                 else()
167                         # CUDA 5.x
168                         if(${arch} MATCHES "sm_1[0-9]")
169                                 # sm_1x
170                                 set(cuda_arch_flags "--maxrregcount=24 --opencc-options -OPT:Olimit=0")
171                         elseif(${arch} MATCHES "sm_2[0-9]")
172                                 # sm_2x
173                                 set(cuda_arch_flags "--maxrregcount=32")
174                         else()
175                                 # sm_3x
176                                 set(cuda_arch_flags "--maxrregcount=32")
177                         endif()
178
179                         set(cuda_math_flags "--use_fast_math")
180                 endif()
181                 
182                 if(CUDA_VERSION LESS 50 AND ${arch} MATCHES "sm_35")
183                         message(WARNING "Can't build kernel for CUDA sm_35 architecture, skipping")
184                 else()
185                         add_custom_command(
186                                 OUTPUT ${cuda_cubin}
187                                 COMMAND ${CUDA_NVCC_EXECUTABLE} -arch=${arch} -m${CUDA_BITS} --cubin ${CMAKE_CURRENT_SOURCE_DIR}/kernel.cu -o ${CMAKE_CURRENT_BINARY_DIR}/${cuda_cubin} --ptxas-options="-v" ${cuda_arch_flags} ${cuda_version_flags} ${cuda_math_flags} -I${CMAKE_CURRENT_SOURCE_DIR}/../util -I${CMAKE_CURRENT_SOURCE_DIR}/svm -DCCL_NAMESPACE_BEGIN= -DCCL_NAMESPACE_END= -DNVCC
188                                 DEPENDS ${cuda_sources})
189
190                         delayed_install("${CMAKE_CURRENT_BINARY_DIR}" "${cuda_cubin}" ${CYCLES_INSTALL_PATH}/lib)
191                         list(APPEND cuda_cubins ${cuda_cubin})
192                 endif()
193         endforeach()
194
195         add_custom_target(cycles_kernel_cuda ALL DEPENDS ${cuda_cubins})
196 endif()
197
198 # OSL module
199
200 if(WITH_CYCLES_OSL)
201         add_subdirectory(osl)
202         add_subdirectory(shaders)
203 endif()
204
205 # CPU module
206
207 include_directories(${INC})
208 include_directories(SYSTEM ${INC_SYS})
209
210 add_library(cycles_kernel ${SRC} ${SRC_HEADERS} ${SRC_CLOSURE_HEADERS} ${SRC_SVM_HEADERS})
211
212 if(WITH_CYCLES_OPTIMIZED_KERNEL)
213         set_source_files_properties(kernel_sse2.cpp PROPERTIES COMPILE_FLAGS "${CYCLES_SSE2_KERNEL_FLAGS}")
214         set_source_files_properties(kernel_sse3.cpp PROPERTIES COMPILE_FLAGS "${CYCLES_SSE3_KERNEL_FLAGS}")
215 endif()
216
217 if(WITH_CYCLES_CUDA)
218         add_dependencies(cycles_kernel cycles_kernel_cuda)
219 endif()
220
221 # OpenCL kernel
222
223 #set(KERNEL_PREPROCESSED ${CMAKE_CURRENT_BINARY_DIR}/kernel_preprocessed.cl)
224 #add_custom_command(
225 #       OUTPUT ${KERNEL_PREPROCESSED}
226 #       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}
227 #       DEPENDS ${SRC_KERNEL} ${SRC_UTIL_HEADERS})
228 #add_custom_target(cycles_kernel_preprocess ALL DEPENDS ${KERNEL_PREPROCESSED})
229 #delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "${KERNEL_PREPROCESSED}" ${CYCLES_INSTALL_PATH}/kernel)
230
231 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "kernel.cl" ${CYCLES_INSTALL_PATH}/kernel)
232 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "kernel.cu" ${CYCLES_INSTALL_PATH}/kernel)
233 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "${SRC_HEADERS}" ${CYCLES_INSTALL_PATH}/kernel)
234 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "${SRC_CLOSURE_HEADERS}" ${CYCLES_INSTALL_PATH}/kernel/closure)
235 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "${SRC_SVM_HEADERS}" ${CYCLES_INSTALL_PATH}/kernel/svm)
236 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "${SRC_UTIL_HEADERS}" ${CYCLES_INSTALL_PATH}/kernel)
237