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