63637991c2917339ecd79d32800ffc7379d28d3f
[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_subsurface.h
26         kernel_bvh_traversal.h
27         kernel_camera.h
28         kernel_compat_cpu.h
29         kernel_compat_cuda.h
30         kernel_compat_opencl.h
31         kernel_curve.h
32         kernel_differential.h
33         kernel_displace.h
34         kernel_emission.h
35         kernel_film.h
36         kernel_globals.h
37         kernel_jitter.h
38         kernel_light.h
39         kernel_math.h
40         kernel_montecarlo.h
41         kernel_object.h
42         kernel_passes.h
43         kernel_path.h
44         kernel_path_state.h
45         kernel_primitive.h
46         kernel_projection.h
47         kernel_random.h
48         kernel_shader.h
49         kernel_shadow.h
50         kernel_subsurface.h
51         kernel_textures.h
52         kernel_triangle.h
53         kernel_types.h
54 )
55
56 set(SRC_CLOSURE_HEADERS
57         closure/bsdf.h
58         closure/bsdf_ashikhmin_velvet.h
59         closure/bsdf_diffuse.h
60         closure/bsdf_diffuse_ramp.h
61         closure/bsdf_microfacet.h
62         closure/bsdf_oren_nayar.h
63         closure/bsdf_phong_ramp.h
64         closure/bsdf_reflection.h
65         closure/bsdf_refraction.h
66         closure/bsdf_toon.h
67         closure/bsdf_transparent.h
68         closure/bsdf_util.h
69         closure/bsdf_ward.h
70         closure/bsdf_westin.h
71         closure/bsdf_hair.h
72         closure/bssrdf.h
73         closure/emissive.h
74         closure/volume.h
75 )
76 set(SRC_SVM_HEADERS
77         svm/svm.h
78         svm/svm_attribute.h
79         svm/svm_blackbody.h
80         svm/svm_camera.h
81         svm/svm_closure.h
82         svm/svm_convert.h
83         svm/svm_checker.h
84         svm/svm_brick.h
85         svm/svm_displace.h
86         svm/svm_fresnel.h
87         svm/svm_wireframe.h
88         svm/svm_wavelength.h
89         svm/svm_gamma.h
90         svm/svm_brightness.h
91         svm/svm_geometry.h
92         svm/svm_gradient.h
93         svm/svm_hsv.h
94         svm/svm_image.h
95         svm/svm_invert.h
96         svm/svm_light_path.h
97         svm/svm_magic.h
98         svm/svm_mapping.h
99         svm/svm_math.h
100         svm/svm_mix.h
101         svm/svm_musgrave.h
102         svm/svm_noise.h
103         svm/svm_noisetex.h
104         svm/svm_normal.h
105         svm/svm_ramp.h
106         svm/svm_sepcomb_rgb.h
107         svm/svm_sepcomb_hsv.h
108         svm/svm_sky.h
109         svm/svm_tex_coord.h
110         svm/svm_texture.h
111         svm/svm_types.h
112         svm/svm_value.h
113         svm/svm_vector_transform.h
114         svm/svm_voronoi.h
115         svm/svm_wave.h
116 )
117
118 set(SRC_UTIL_HEADERS
119         ../util/util_color.h
120         ../util/util_math.h
121         ../util/util_transform.h
122         ../util/util_types.h
123 )
124 # CUDA module
125
126 if(WITH_CYCLES_CUDA_BINARIES)
127         # 32 bit or 64 bit
128         if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
129                 set(CUDA_BITS 64)
130         else()
131                 set(CUDA_BITS 32)
132         endif()
133
134         # CUDA version
135         execute_process (COMMAND ${CUDA_NVCC_EXECUTABLE} "--version" OUTPUT_VARIABLE NVCC_OUT)
136         string(REGEX REPLACE ".*release ([0-9]+)\\.([0-9]+).*" "\\1" CUDA_VERSION_MAJOR ${NVCC_OUT})
137         string(REGEX REPLACE ".*release ([0-9]+)\\.([0-9]+).*" "\\2" CUDA_VERSION_MINOR ${NVCC_OUT})
138         set(CUDA_VERSION "${CUDA_VERSION_MAJOR}${CUDA_VERSION_MINOR}")
139
140         # warn for other versions
141         if(CUDA_VERSION MATCHES "50")
142         else()
143                 message(WARNING "CUDA version ${CUDA_VERSION_MAJOR}.${CUDA_VERSION_MINOR} detected, build may succeed but only CUDA 5.0 is officially supported")
144         endif()
145
146         # build for each arch
147         set(cuda_sources kernel.cu ${SRC_HEADERS} ${SRC_SVM_HEADERS} ${SRC_CLOSURE_HEADERS} ${SRC_UTIL_HEADERS})
148         set(cuda_cubins)
149
150         foreach(arch ${CYCLES_CUDA_BINARIES_ARCH})
151                 set(cuda_cubin kernel_${arch}.cubin)
152
153                 set(cuda_version_flags "-D__KERNEL_CUDA_VERSION__=${CUDA_VERSION}")
154
155                 # CUDA 5.x build flags for different archs
156                 if(${arch} MATCHES "sm_2[0-9]")
157                         # sm_2x
158                         set(cuda_arch_flags "--maxrregcount=32")
159                 elseif(${arch} MATCHES "sm_3[0-9]")
160                         # sm_3x
161                         set(cuda_arch_flags "--maxrregcount=32")
162                 endif()
163
164                 set(cuda_math_flags "--use_fast_math")
165                 
166                 if(CUDA_VERSION LESS 50 AND ${arch} MATCHES "sm_35")
167                         message(WARNING "Can't build kernel for CUDA sm_35 architecture, skipping")
168                 else()
169                         add_custom_command(
170                                 OUTPUT ${cuda_cubin}
171                                 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
172                                 DEPENDS ${cuda_sources})
173
174                         delayed_install("${CMAKE_CURRENT_BINARY_DIR}" "${cuda_cubin}" ${CYCLES_INSTALL_PATH}/lib)
175                         list(APPEND cuda_cubins ${cuda_cubin})
176                 endif()
177         endforeach()
178
179         add_custom_target(cycles_kernel_cuda ALL DEPENDS ${cuda_cubins})
180 endif()
181
182 # OSL module
183
184 if(WITH_CYCLES_OSL)
185         add_subdirectory(osl)
186         add_subdirectory(shaders)
187 endif()
188
189 # CPU module
190
191 include_directories(${INC})
192 include_directories(SYSTEM ${INC_SYS})
193
194 if(WITH_CYCLES_OPTIMIZED_KERNEL)
195         set_source_files_properties(kernel_sse2.cpp PROPERTIES COMPILE_FLAGS "${CYCLES_SSE2_KERNEL_FLAGS}")
196         set_source_files_properties(kernel_sse3.cpp PROPERTIES COMPILE_FLAGS "${CYCLES_SSE3_KERNEL_FLAGS}")
197 endif()
198
199 if(WITH_CYCLES_OPTIMIZED_KERNEL_SSE41)
200         set_source_files_properties(kernel_sse41.cpp PROPERTIES COMPILE_FLAGS "${CYCLES_SSE41_KERNEL_FLAGS}")
201         list(APPEND SRC kernel_sse41.cpp)
202 endif()
203
204 add_library(cycles_kernel ${SRC} ${SRC_HEADERS} ${SRC_CLOSURE_HEADERS} ${SRC_SVM_HEADERS})
205
206 if(WITH_CYCLES_CUDA)
207         add_dependencies(cycles_kernel cycles_kernel_cuda)
208 endif()
209
210 # OpenCL kernel
211
212 #set(KERNEL_PREPROCESSED ${CMAKE_CURRENT_BINARY_DIR}/kernel_preprocessed.cl)
213 #add_custom_command(
214 #       OUTPUT ${KERNEL_PREPROCESSED}
215 #       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}
216 #       DEPENDS ${SRC_KERNEL} ${SRC_UTIL_HEADERS})
217 #add_custom_target(cycles_kernel_preprocess ALL DEPENDS ${KERNEL_PREPROCESSED})
218 #delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "${KERNEL_PREPROCESSED}" ${CYCLES_INSTALL_PATH}/kernel)
219
220 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "kernel.cl" ${CYCLES_INSTALL_PATH}/kernel)
221 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "kernel.cu" ${CYCLES_INSTALL_PATH}/kernel)
222 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "${SRC_HEADERS}" ${CYCLES_INSTALL_PATH}/kernel)
223 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "${SRC_CLOSURE_HEADERS}" ${CYCLES_INSTALL_PATH}/kernel/closure)
224 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "${SRC_SVM_HEADERS}" ${CYCLES_INSTALL_PATH}/kernel/svm)
225 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "${SRC_UTIL_HEADERS}" ${CYCLES_INSTALL_PATH}/kernel)
226