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