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