Cycles: Remove odd definition from CMake file
[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 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 if(WITH_CYCLES_OPENSUBDIV)
150         add_definitions(-DWITH_OPENSUBDIV)
151         include_directories(
152                 SYSTEM
153                 ${OPENSUBDIV_INCLUDE_DIR}
154         )
155 endif()
156
157 set(WITH_CYCLES_DEVICE_OPENCL TRUE)
158 set(WITH_CYCLES_DEVICE_CUDA TRUE)
159 set(WITH_CYCLES_DEVICE_MULTI TRUE)
160
161 if(CYCLES_STANDALONE_REPOSITORY)
162         TEST_UNORDERED_MAP_SUPPORT()
163 endif()
164 if(WITH_CXX11)
165         add_definitions(-DCYCLES_STD_UNORDERED_MAP)
166 elseif(HAVE_STD_UNORDERED_MAP_HEADER)
167         if(HAVE_UNORDERED_MAP_IN_STD_NAMESPACE)
168                 add_definitions(-DCYCLES_STD_UNORDERED_MAP)
169         else()
170                 if(HAVE_UNORDERED_MAP_IN_TR1_NAMESPACE)
171                         add_definitions(-DCYCLES_STD_UNORDERED_MAP_IN_TR1_NAMESPACE)
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 else()
178         if(HAVE_UNORDERED_MAP_IN_TR1_NAMESPACE)
179                 add_definitions(-DCYCLES_TR1_UNORDERED_MAP)
180         else()
181                 add_definitions(-DCYCLES_NO_UNORDERED_MAP)
182                 message(STATUS "Replacing unordered_map/set with map/set (warning: slower!)")
183         endif()
184 endif()
185
186 # Logging capabilities using GLog library.
187 if(WITH_CYCLES_LOGGING)
188         add_definitions(-DWITH_CYCLES_LOGGING)
189         add_definitions(-DGOOGLE_GLOG_DLL_DECL=)
190         add_definitions(-DCYCLES_GFLAGS_NAMESPACE=${GFLAGS_NAMESPACE})
191         include_directories(
192                 SYSTEM
193                 ${GLOG_INCLUDE_DIRS}
194                 ${GFLAGS_INCLUDE_DIRS}
195         )
196 endif()
197
198 # Debugging capabilities (debug passes etc).
199 if(WITH_CYCLES_DEBUG)
200         add_definitions(-DWITH_CYCLES_DEBUG)
201 endif()
202
203 include_directories(
204         SYSTEM
205         ${BOOST_INCLUDE_DIR}
206         ${OPENIMAGEIO_INCLUDE_DIRS}
207         ${OPENIMAGEIO_INCLUDE_DIRS}/OpenImageIO
208         ${OPENEXR_INCLUDE_DIR}
209         ${OPENEXR_INCLUDE_DIRS}
210         ${PUGIXML_INCLUDE_DIR}
211 )
212
213 if(CYCLES_STANDALONE_REPOSITORY)
214         include_directories(../third_party/atomic)
215 else()
216         include_directories(../atomic)
217 endif()
218
219 # Warnings
220 if(CMAKE_COMPILER_IS_GNUCXX)
221         ADD_CHECK_CXX_COMPILER_FLAG(CMAKE_CXX_FLAGS _has_cxxflag_float_conversion "-Werror=float-conversion")
222         ADD_CHECK_CXX_COMPILER_FLAG(CMAKE_CXX_FLAGS _has_cxxflag_double_promotion "-Werror=double-promotion")
223         ADD_CHECK_CXX_COMPILER_FLAG(CMAKE_CXX_FLAGS _has_no_error_unused_macros "-Wno-error=unused-macros")
224         unset(_has_cxxflag_float_conversion)
225         unset(_has_cxxflag_double_promotion)
226         unset(_has_no_error_unused_macros)
227 endif()
228
229
230 # Subdirectories
231
232 if(WITH_CYCLES_BLENDER)
233         add_definitions(-DWITH_BLENDER_GUARDEDALLOC)
234         add_subdirectory(blender)
235 endif()
236
237 if(WITH_CYCLES_NETWORK)
238         add_definitions(-DWITH_NETWORK)
239 endif()
240
241 if(WITH_CYCLES_STANDALONE OR WITH_CYCLES_NETWORK)
242         add_subdirectory(app)
243 endif()
244
245 add_subdirectory(bvh)
246 add_subdirectory(device)
247 add_subdirectory(doc)
248 add_subdirectory(graph)
249 add_subdirectory(kernel)
250 add_subdirectory(render)
251 add_subdirectory(subd)
252 add_subdirectory(util)
253
254 # TODO(sergey): Make this to work with standalone repository.
255 if(WITH_GTESTS)
256         add_subdirectory(test)
257 endif()
258
259 if(NOT WITH_BLENDER AND WITH_CYCLES_STANDALONE)
260         delayed_do_install(${CMAKE_BINARY_DIR}/bin)
261 endif()
262