ed6961f49e0c3d18afc7bc59a2e31a36fd8ac4f0
[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: refactor this code to match scons
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_NETWORK)
125         add_definitions(-DWITH_NETWORK)
126 endif()
127
128 if(WITH_CYCLES_STANDALONE_GUI)
129         add_definitions(-DWITH_CYCLES_STANDALONE_GUI)
130 endif()
131
132 if(WITH_CYCLES_PTEX)
133         add_definitions(-DWITH_PTEX)
134 endif()
135
136 if(WITH_CYCLES_OPENSUBDIV)
137         add_definitions(-DWITH_OPENSUBDIV)
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 add_definitions(
150         -DWITH_OPENCL
151         -DWITH_CUDA
152         -DWITH_MULTI
153 )
154
155 TEST_UNORDERED_MAP_SUPPORT()
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         unset(_has_cxxflag_float_conversion)
214         unset(_has_cxxflag_double_promotion)
215 endif()
216
217
218 # Subdirectories
219
220 if(WITH_CYCLES_BLENDER)
221         add_subdirectory(blender)
222 endif()
223
224 if(WITH_CYCLES_STANDALONE OR WITH_CYCLES_NETWORK)
225         add_subdirectory(app)
226 endif()
227
228 add_subdirectory(bvh)
229 add_subdirectory(device)
230 add_subdirectory(doc)
231 add_subdirectory(kernel)
232 add_subdirectory(render)
233 add_subdirectory(subd)
234 add_subdirectory(util)
235
236 if(NOT WITH_BLENDER AND WITH_CYCLES_STANDALONE)
237         delayed_do_install(${CMAKE_BINARY_DIR}/bin)
238 endif()
239