Code refactor: add generic Cycles node infrastructure.
[blender-staging.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
13 # Build Flags
14 # todo: this code could be refactored a bit to avoid duplication
15 # note: CXX_HAS_SSE is needed in case passing SSE flags fails altogether (gcc-arm)
16
17 if(WITH_CYCLES_NATIVE_ONLY)
18         set(CXX_HAS_SSE FALSE)
19         set(CXX_HAS_AVX FALSE)
20         set(CXX_HAS_AVX2 FALSE)
21         add_definitions(
22                 -DWITH_KERNEL_NATIVE
23         )
24         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
25 elseif(NOT WITH_CPU_SSE)
26         set(CXX_HAS_SSE FALSE)
27         set(CXX_HAS_AVX FALSE)
28         set(CXX_HAS_AVX2 FALSE)
29 elseif(WIN32 AND MSVC)
30         set(CXX_HAS_SSE TRUE)
31         set(CXX_HAS_AVX TRUE)
32         set(CXX_HAS_AVX2 TRUE)
33
34         # /arch:AVX for VC2012 and above
35         if(NOT MSVC_VERSION LESS 1700)
36                 set(CYCLES_AVX_ARCH_FLAGS "/arch:AVX")
37                 set(CYCLES_AVX2_ARCH_FLAGS "/arch:AVX /arch:AVX2")
38         elseif(NOT CMAKE_CL_64)
39                 set(CYCLES_AVX_ARCH_FLAGS "/arch:SSE2")
40                 set(CYCLES_AVX2_ARCH_FLAGS "/arch:SSE2")
41         endif()
42
43         # there is no /arch:SSE3, but intrinsics are available anyway
44         if(CMAKE_CL_64)
45                 set(CYCLES_SSE2_KERNEL_FLAGS "/fp:fast -D_CRT_SECURE_NO_WARNINGS /GS-")
46                 set(CYCLES_SSE3_KERNEL_FLAGS "/fp:fast -D_CRT_SECURE_NO_WARNINGS /GS-")
47                 set(CYCLES_SSE41_KERNEL_FLAGS "/fp:fast -D_CRT_SECURE_NO_WARNINGS /GS-")
48                 set(CYCLES_AVX_KERNEL_FLAGS "${CYCLES_AVX_ARCH_FLAGS} /fp:fast -D_CRT_SECURE_NO_WARNINGS /GS-")
49                 set(CYCLES_AVX2_KERNEL_FLAGS "${CYCLES_AVX2_ARCH_FLAGS} /fp:fast -D_CRT_SECURE_NO_WARNINGS /GS-")
50         else()
51                 set(CYCLES_SSE2_KERNEL_FLAGS "/arch:SSE2 /fp:fast -D_CRT_SECURE_NO_WARNINGS /GS-")
52                 set(CYCLES_SSE3_KERNEL_FLAGS "/arch:SSE2 /fp:fast -D_CRT_SECURE_NO_WARNINGS /GS-")
53                 set(CYCLES_SSE41_KERNEL_FLAGS "/arch:SSE2 /fp:fast -D_CRT_SECURE_NO_WARNINGS /GS-")
54                 set(CYCLES_AVX_KERNEL_FLAGS "${CYCLES_AVX_ARCH_FLAGS} /fp:fast -D_CRT_SECURE_NO_WARNINGS /GS-")
55                 set(CYCLES_AVX2_KERNEL_FLAGS "${CYCLES_AVX2_ARCH_FLAGS} /fp:fast -D_CRT_SECURE_NO_WARNINGS /GS-")
56         endif()
57
58         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /fp:fast -D_CRT_SECURE_NO_WARNINGS /GS-")
59         set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Ox")
60         set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /Ox")
61         set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} /Ox")
62 elseif(CMAKE_COMPILER_IS_GNUCC)
63         check_cxx_compiler_flag(-msse CXX_HAS_SSE)
64         check_cxx_compiler_flag(-mavx CXX_HAS_AVX)
65         check_cxx_compiler_flag(-mavx2 CXX_HAS_AVX2)
66         if(CXX_HAS_SSE)
67                 set(CYCLES_SSE2_KERNEL_FLAGS "-ffast-math -msse -msse2 -mfpmath=sse")
68                 set(CYCLES_SSE3_KERNEL_FLAGS "-ffast-math -msse -msse2 -msse3 -mssse3 -mfpmath=sse")
69                 set(CYCLES_SSE41_KERNEL_FLAGS "-ffast-math -msse -msse2 -msse3 -mssse3 -msse4.1 -mfpmath=sse")
70         endif()
71         if(CXX_HAS_AVX)
72                 set(CYCLES_AVX_KERNEL_FLAGS "-ffast-math -msse -msse2 -msse3 -mssse3 -msse4.1 -mavx -mfpmath=sse")
73         endif()
74         if(CXX_HAS_AVX2)
75                 set(CYCLES_AVX2_KERNEL_FLAGS "-ffast-math -msse -msse2 -msse3 -mssse3 -msse4.1 -mavx -mavx2 -mfma -mlzcnt -mbmi -mbmi2 -mf16c -mfpmath=sse")
76         endif()
77         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ffast-math")
78 elseif(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         if(CXX_HAS_SSE)
83                 set(CYCLES_SSE2_KERNEL_FLAGS "-ffast-math -msse -msse2")
84                 set(CYCLES_SSE3_KERNEL_FLAGS "-ffast-math -msse -msse2 -msse3 -mssse3")
85                 set(CYCLES_SSE41_KERNEL_FLAGS "-ffast-math -msse -msse2 -msse3 -mssse3 -msse4.1")
86         endif()
87         if(CXX_HAS_AVX)
88                 set(CYCLES_AVX_KERNEL_FLAGS "-ffast-math -msse -msse2 -msse3 -mssse3 -msse4.1 -mavx")
89         endif()
90         if(CXX_HAS_AVX2)
91                 set(CYCLES_AVX2_KERNEL_FLAGS "-ffast-math -msse -msse2 -msse3 -mssse3 -msse4.1 -mavx -mavx2 -mfma -mlzcnt -mbmi -mbmi2 -mf16c")
92         endif()
93         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ffast-math")
94 endif()
95
96 if(CXX_HAS_SSE)
97         add_definitions(
98                 -DWITH_KERNEL_SSE2
99                 -DWITH_KERNEL_SSE3
100                 -DWITH_KERNEL_SSE41
101         )
102 endif()
103
104 if(CXX_HAS_AVX)
105         add_definitions(-DWITH_KERNEL_AVX)
106 endif()
107
108 if(CXX_HAS_AVX2)
109         add_definitions(-DWITH_KERNEL_AVX2)
110 endif()
111
112 if(WITH_CYCLES_OSL)
113         if(WIN32 AND MSVC)
114                 set(RTTI_DISABLE_FLAGS "/GR- -DBOOST_NO_RTTI -DBOOST_NO_TYPEID")
115         elseif(CMAKE_COMPILER_IS_GNUCC OR (CMAKE_C_COMPILER_ID MATCHES "Clang"))
116                 set(RTTI_DISABLE_FLAGS "-fno-rtti -DBOOST_NO_RTTI -DBOOST_NO_TYPEID")
117         endif()
118 endif()
119
120 # Definitions and Includes
121
122 add_definitions(
123         ${BOOST_DEFINITIONS}
124         ${OPENIMAGEIO_DEFINITIONS}
125 )
126
127 add_definitions(
128         -DCCL_NAMESPACE_BEGIN=namespace\ ccl\ {
129         -DCCL_NAMESPACE_END=}
130 )
131
132 if(WITH_CYCLES_STANDALONE_GUI)
133         add_definitions(-DWITH_CYCLES_STANDALONE_GUI)
134 endif()
135
136 if(WITH_CYCLES_PTEX)
137         add_definitions(-DWITH_PTEX)
138 endif()
139
140 if(WITH_CYCLES_OSL)
141         add_definitions(-DWITH_OSL)
142         add_definitions(-DOSL_STATIC_LIBRARY)
143         include_directories(
144                 SYSTEM
145                 ${OSL_INCLUDE_DIR}
146         )
147 endif()
148
149 set(WITH_CYCLES_DEVICE_OPENCL TRUE)
150 set(WITH_CYCLES_DEVICE_CUDA TRUE)
151 set(WITH_CYCLES_DEVICE_MULTI TRUE)
152
153 if(CYCLES_STANDALONE_REPOSITORY)
154         TEST_UNORDERED_MAP_SUPPORT()
155 endif()
156 if(WITH_CXX11)
157         add_definitions(-DCYCLES_STD_UNORDERED_MAP)
158 elseif(HAVE_STD_UNORDERED_MAP_HEADER)
159         if(HAVE_UNORDERED_MAP_IN_STD_NAMESPACE)
160                 add_definitions(-DCYCLES_STD_UNORDERED_MAP)
161         else()
162                 if(HAVE_UNORDERED_MAP_IN_TR1_NAMESPACE)
163                         add_definitions(-DCYCLES_STD_UNORDERED_MAP_IN_TR1_NAMESPACE)
164                 else()
165                         add_definitions(-DCYCLES_NO_UNORDERED_MAP)
166                         message(STATUS "Replacing unordered_map/set with map/set (warning: slower!)")
167                 endif()
168         endif()
169 else()
170         if(HAVE_UNORDERED_MAP_IN_TR1_NAMESPACE)
171                 add_definitions(-DCYCLES_TR1_UNORDERED_MAP)
172         else()
173                 add_definitions(-DCYCLES_NO_UNORDERED_MAP)
174                 message(STATUS "Replacing unordered_map/set with map/set (warning: slower!)")
175         endif()
176 endif()
177
178 # Logging capabilities using GLog library.
179 if(WITH_CYCLES_LOGGING)
180         add_definitions(-DWITH_CYCLES_LOGGING)
181         add_definitions(-DGOOGLE_GLOG_DLL_DECL=)
182         add_definitions(-DCYCLES_GFLAGS_NAMESPACE=${GFLAGS_NAMESPACE})
183         include_directories(
184                 SYSTEM
185                 ${GLOG_INCLUDE_DIRS}
186                 ${GFLAGS_INCLUDE_DIRS}
187         )
188 endif()
189
190 # Debugging capabilities (debug passes etc).
191 if(WITH_CYCLES_DEBUG)
192         add_definitions(-DWITH_CYCLES_DEBUG)
193 endif()
194
195 include_directories(
196         SYSTEM
197         ${BOOST_INCLUDE_DIR}
198         ${OPENIMAGEIO_INCLUDE_DIRS}
199         ${OPENIMAGEIO_INCLUDE_DIRS}/OpenImageIO
200         ${OPENEXR_INCLUDE_DIR}
201         ${OPENEXR_INCLUDE_DIRS}
202         ${PUGIXML_INCLUDE_DIR}
203 )
204
205 if(CYCLES_STANDALONE_REPOSITORY)
206         include_directories(../third_party/atomic)
207 else()
208         include_directories(../atomic)
209 endif()
210
211 # Warnings
212 if(CMAKE_COMPILER_IS_GNUCXX)
213         ADD_CHECK_CXX_COMPILER_FLAG(CMAKE_CXX_FLAGS _has_cxxflag_float_conversion "-Werror=float-conversion")
214         ADD_CHECK_CXX_COMPILER_FLAG(CMAKE_CXX_FLAGS _has_cxxflag_double_promotion "-Werror=double-promotion")
215         ADD_CHECK_CXX_COMPILER_FLAG(CMAKE_CXX_FLAGS _has_no_error_unused_macros "-Wno-error=unused-macros")
216         unset(_has_cxxflag_float_conversion)
217         unset(_has_cxxflag_double_promotion)
218         unset(_has_no_error_unused_macros)
219 endif()
220
221
222 # Subdirectories
223
224 if(WITH_CYCLES_BLENDER)
225         add_definitions(-DWITH_BLENDER_GUARDEDALLOC)
226         add_subdirectory(blender)
227 endif()
228
229 if(WITH_CYCLES_NETWORK)
230         add_definitions(-DWITH_NETWORK)
231 endif()
232
233 if(WITH_CYCLES_STANDALONE OR WITH_CYCLES_NETWORK)
234         add_subdirectory(app)
235 endif()
236
237 add_subdirectory(bvh)
238 add_subdirectory(device)
239 add_subdirectory(doc)
240 add_subdirectory(graph)
241 add_subdirectory(kernel)
242 add_subdirectory(render)
243 add_subdirectory(subd)
244 add_subdirectory(util)
245
246 # TODO(sergey): Make this to work with standalone repository.
247 if(WITH_GTESTS)
248         add_subdirectory(test)
249 endif()
250
251 if(NOT WITH_BLENDER AND WITH_CYCLES_STANDALONE)
252         delayed_do_install(${CMAKE_BINARY_DIR}/bin)
253 endif()
254