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