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