Audaspace: use standalone library.
[blender-staging.git] / CMakeLists.txt
1 # ***** BEGIN GPL LICENSE BLOCK *****
2 #
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software Foundation,
15 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 #
17 # The Original Code is Copyright (C) 2006, Blender Foundation
18 # All rights reserved.
19 #
20 # The Original Code is: all of this file.
21 #
22 # Contributor(s): Jacques Beaurain.
23 #
24 # ***** END GPL LICENSE BLOCK *****
25
26 #-----------------------------------------------------------------------------
27 # We don't allow in-source builds. This causes no end of troubles because
28 # all out-of-source builds will use the CMakeCache.txt file there and even
29 # build the libs and objects in it.
30
31 if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
32         if(NOT DEFINED WITH_IN_SOURCE_BUILD)
33                 message(FATAL_ERROR
34                         "CMake generation for blender is not allowed within the source directory!"
35                         "\n Remove the CMakeCache.txt file and try again from another folder, e.g.:"
36                         "\n "
37                         "\n rm CMakeCache.txt"
38                         "\n cd .."
39                         "\n mkdir cmake-make"
40                         "\n cd cmake-make"
41                         "\n cmake ../blender"
42                         "\n "
43                         "\n Alternately define WITH_IN_SOURCE_BUILD to force this option (not recommended!)"
44                 )
45         endif()
46 endif()
47
48 cmake_minimum_required(VERSION 2.8)
49
50 if(NOT (${CMAKE_VERSION} VERSION_LESS 3.0))
51         # keep until CMake-3.0 is min requirement
52         cmake_policy(SET CMP0043 OLD)
53 endif()
54
55 if(NOT EXECUTABLE_OUTPUT_PATH)
56         set(FIRST_RUN TRUE)
57 else()
58         set(FIRST_RUN FALSE)
59 endif()
60
61 # this starts out unset
62 list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/build_files/cmake/Modules")
63
64 # avoid having empty buildtype
65 set(CMAKE_BUILD_TYPE_INIT "Release")
66
67 # quiet output for Makefiles, 'make -s' helps too
68 # set_property(GLOBAL PROPERTY RULE_MESSAGES OFF)
69
70 # global compile definitions since add_definitions() adds for all.
71 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_DEBUG           DEBUG _DEBUG)
72 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_RELEASE         NDEBUG)
73 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_MINSIZEREL      NDEBUG)
74 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_RELWITHDEBINFO  NDEBUG)
75
76 #-----------------------------------------------------------------------------
77 # Set policy
78
79 # see "cmake --help-policy CMP0003"
80 # So library linking is more sane
81 cmake_policy(SET CMP0003 NEW)
82
83 # So BUILDINFO and BLENDERPATH strings are automatically quoted
84 cmake_policy(SET CMP0005 NEW)
85
86 # So syntax problems are errors
87 cmake_policy(SET CMP0010 NEW)
88
89 # Input directories must have CMakeLists.txt
90 cmake_policy(SET CMP0014 NEW)
91
92 #-----------------------------------------------------------------------------
93 # Load some macros.
94 include(build_files/cmake/macros.cmake)
95
96
97 #-----------------------------------------------------------------------------
98 # Initialize project.
99
100 blender_project_hack_pre()
101
102 project(Blender)
103
104 blender_project_hack_post()
105
106 enable_testing()
107
108 #-----------------------------------------------------------------------------
109 # Redirect output files
110
111 set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin CACHE INTERNAL "" FORCE)
112 set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib CACHE INTERNAL "" FORCE)
113 set(TESTS_OUTPUT_DIR ${EXECUTABLE_OUTPUT_PATH}/tests CACHE INTERNAL "" FORCE)
114
115 #-----------------------------------------------------------------------------
116 # Set default config options
117
118 get_blender_version()
119
120
121 #-----------------------------------------------------------------------------
122 # Platform Specific Defaults
123
124 # list of var-names
125 set(_init_vars)
126
127 # initialize to ON
128 macro(option_defaults_init)
129         foreach(_var ${ARGV})
130                 set(${_var} ON)
131                 list(APPEND _init_vars "${_var}")
132         endforeach()
133         unset(_var)
134 endmacro()
135
136 # remove from namespace
137 macro(option_defaults_clear)
138         foreach(_var ${_init_vars})
139                 unset(${_var})
140         endforeach()
141         unset(_var)
142         unset(_init_vars)
143 endmacro()
144
145
146 # values to initialize WITH_****
147 option_defaults_init(
148         _init_BUILDINFO
149         _init_CODEC_FFMPEG
150         _init_CYCLES_OSL
151         _init_IMAGE_OPENEXR
152         _init_IMAGE_REDCODE
153         _init_INPUT_NDOF
154         _init_JACK
155         _init_LIBMV_SCHUR_SPECIALIZATION
156         _init_OPENCOLLADA
157         _init_OPENCOLORIO
158         _init_SDL
159         _init_FFTW3
160         _init_GAMEENGINE
161 )
162
163 # customize...
164 if (UNIX AND NOT APPLE)
165         # some of these libraries are problematic on Linux
166         # disable less important dependencies by default
167         set(_init_CODEC_FFMPEG                   OFF)
168         set(_init_CYCLES_OSL                     OFF)
169         set(_init_IMAGE_OPENEXR                  OFF)
170         set(_init_IMAGE_REDCODE                  OFF)
171         set(_init_INPUT_NDOF                     OFF)
172         set(_init_JACK                           OFF)
173         set(_init_OPENCOLLADA                    OFF)
174         set(_init_OPENCOLORIO                    OFF)
175         set(_init_SDL                            OFF)
176         set(_init_FFTW3                          OFF)
177 elseif(WIN32)
178         set(_init_JACK                           OFF)
179 elseif(APPLE)
180         set(_init_INPUT_NDOF                     OFF)
181         set(_init_JACK                           OFF)
182 endif()
183
184
185 #-----------------------------------------------------------------------------
186 # Options
187
188 # First platform spesific non-cached vars
189 if(UNIX AND NOT APPLE)
190         set(WITH_X11 ON)
191 endif()
192
193 # Blender internal features
194 option(WITH_BLENDER "Build blender (disable to build only the blender player)" ON)
195 mark_as_advanced(WITH_BLENDER)
196
197 option(WITH_INTERNATIONAL "Enable I18N (International fonts and text)" ON)
198
199 option(WITH_PYTHON        "Enable Embedded Python API  (only disable for development)" ON)
200 option(WITH_PYTHON_SECURITY "Disables execution of scripts within blend files by default" ON) 
201 mark_as_advanced(WITH_PYTHON)  # dont want people disabling this unless they really know what they are doing.
202 mark_as_advanced(WITH_PYTHON_SECURITY)  # some distributions see this as a security issue, rather than have them patch it, make a build option.
203
204 option(WITH_PYTHON_SAFETY "Enable internal API error checking to track invalid data to prevent crash on access (at the expense of some effeciency, only enable for development)." OFF)
205 mark_as_advanced(WITH_PYTHON_SAFETY)
206 option(WITH_PYTHON_MODULE "Enable building as a python module which runs without a user interface, like running regular blender in background mode (experimental, only enable for development), installs to PYTHON_SITE_PACKAGES (or CMAKE_INSTALL_PREFIX if WITH_INSTALL_PORTABLE is enabled)." OFF)
207 if(APPLE)
208         option(WITH_PYTHON_FRAMEWORK "Enable building using the Python available in the framework (OSX only)" OFF)
209 endif()
210
211 option(WITH_BUILDINFO     "Include extra build details (only disable for development & faster builds)" ${_init_BUILDINFO})
212 if(${CMAKE_VERSION} VERSION_LESS 2.8.8)
213         # add_library OBJECT arg unsupported
214         set(WITH_BUILDINFO OFF)
215 endif()
216
217 option(WITH_IK_ITASC      "Enable ITASC IK solver (only disable for development & for incompatible C++ compilers)" ON)
218 option(WITH_IK_SOLVER     "Enable Legacy IK solver (only disable for development)" ON)
219 option(WITH_FFTW3         "Enable FFTW3 support (Used for smoke and audio effects)" ${_init_FFTW3})
220 option(WITH_BULLET        "Enable Bullet (Physics Engine)" ON)
221 option(WITH_SYSTEM_BULLET "Use the systems bullet library (currently unsupported due to missing features in upstream!)" )
222 mark_as_advanced(WITH_SYSTEM_BULLET)
223 option(WITH_GAMEENGINE    "Enable Game Engine" ${_init_GAMEENGINE})
224 option(WITH_PLAYER        "Build Player" OFF)
225 option(WITH_OPENCOLORIO   "Enable OpenColorIO color management" ${_init_OPENCOLORIO})
226
227 # Compositor
228 option(WITH_COMPOSITOR         "Enable the tile based nodal compositor" ON)
229 option(WITH_COMPOSITOR_WERROR  "Treat warnings as errors in compositor code" OFF)
230 mark_as_advanced(WITH_COMPOSITOR_WERROR)
231
232 option(WITH_OPENSUBDIV    "Enable OpenSubdiv for surface subdivision" OFF)
233
234 # GHOST Windowing Library Options
235 option(WITH_GHOST_DEBUG   "Enable debugging output for the GHOST library" OFF)
236 mark_as_advanced(WITH_GHOST_DEBUG)
237
238 option(WITH_GHOST_SDL    "Enable building blender against SDL for windowing rather then the native APIs" OFF)
239 mark_as_advanced(WITH_GHOST_SDL)
240
241 if(WITH_X11)
242         option(WITH_GHOST_XDND    "Enable drag'n'drop support on X11 using XDND protocol" ON)
243 endif()
244
245 # Misc...
246 option(WITH_HEADLESS      "Build without graphical support (renderfarm, server mode only)" OFF)
247 mark_as_advanced(WITH_HEADLESS)
248
249 option(WITH_AUDASPACE    "Build with blenders audio library (only disable if you know what you're doing!)" ON)
250 option(WITH_EXTERNAL_AUDASPACE "Build with external audaspace library installed on the system (only enable if you know what you're doing!)" OFF)
251 mark_as_advanced(WITH_AUDASPACE)
252
253 option(WITH_OPENMP        "Enable OpenMP (has to be supported by the compiler)" ON)
254
255 if(WITH_X11)
256         option(WITH_X11_XINPUT    "Enable X11 Xinput (tablet support and unicode input)"  ON)
257         option(WITH_X11_XF86VMODE "Enable X11 video mode switching"                       ON)
258 endif()
259
260 if(UNIX AND NOT APPLE)
261         option(WITH_SYSTEM_GLEW "Use GLEW OpenGL wrapper library provided by the operating system" ON)
262         option(WITH_SYSTEM_GLES "Use OpenGL ES library provided by the operating system"           ON)
263 else()
264         # not an option for other OS's
265         set(WITH_SYSTEM_GLEW OFF)
266         set(WITH_SYSTEM_GLES OFF)
267 endif()
268
269
270 # (unix defaults to System OpenJPEG On)
271 option(WITH_SYSTEM_OPENJPEG "Use the operating systems OpenJPEG library" OFF)
272
273 if(UNIX AND NOT APPLE)
274         option(WITH_SYSTEM_EIGEN3 "Use the systems Eigen3 library" OFF)
275 endif()
276
277
278 # Modifiers
279 option(WITH_MOD_FLUID           "Enable Elbeem Modifier (Fluid Simulation)" ON)
280 option(WITH_MOD_SMOKE           "Enable Smoke Modifier (Smoke Simulation)" ON)
281 option(WITH_MOD_BOOLEAN         "Enable Boolean Modifier" ON)
282 option(WITH_MOD_REMESH          "Enable Remesh Modifier" ON)
283 # option(WITH_MOD_CLOTH_ELTOPO    "Enable Experimental cloth solver" OFF)  # this is now only available in a branch
284 # mark_as_advanced(WITH_MOD_CLOTH_ELTOPO)
285 option(WITH_MOD_OCEANSIM        "Enable Ocean Modifier" OFF)
286
287 # Image format support
288 option(WITH_OPENIMAGEIO         "Enable OpenImageIO Support (http://www.openimageio.org)" ON)
289 option(WITH_IMAGE_OPENEXR       "Enable OpenEXR Support (http://www.openexr.com)" ${_init_IMAGE_OPENEXR})
290 option(WITH_IMAGE_OPENJPEG      "Enable OpenJpeg Support (http://www.openjpeg.org)" ON)
291 option(WITH_IMAGE_TIFF          "Enable LibTIFF Support" ON)
292 option(WITH_IMAGE_DDS           "Enable DDS Image Support" ON)
293 option(WITH_IMAGE_CINEON        "Enable CINEON and DPX Image Support" ON)
294 option(WITH_IMAGE_HDR           "Enable HDR Image Support" ON)
295 option(WITH_IMAGE_REDCODE       "Enable RedCode Image Support" ${_init_IMAGE_REDCODE})
296 option(WITH_IMAGE_FRAMESERVER   "Enable image FrameServer Support for rendering" ON)
297
298 # Audio/Video format support
299 option(WITH_CODEC_AVI           "Enable Blenders own AVI file support (raw/jpeg)" ON)
300 option(WITH_CODEC_FFMPEG        "Enable FFMPeg Support (http://ffmpeg.org)" ${_init_CODEC_FFMPEG})
301 option(WITH_CODEC_SNDFILE       "Enable libsndfile Support (http://www.mega-nerd.com/libsndfile)" OFF)
302
303 if(APPLE)
304         option(WITH_CODEC_QUICKTIME     "Enable Quicktime Support" ON)
305 endif()
306
307 # 3D format support
308 # Disable opencollada when we don't have precompiled libs
309 option(WITH_OPENCOLLADA   "Enable OpenCollada Support (http://www.opencollada.org)" ${_init_OPENCOLLADA})
310
311 # Sound output
312 option(WITH_SDL           "Enable SDL for sound and joystick support" ${_init_SDL})
313 option(WITH_OPENAL        "Enable OpenAL Support (http://www.openal.org)" ON)
314 option(WITH_JACK          "Enable Jack Support (http://www.jackaudio.org)" ${_init_JACK})
315 if(UNIX AND NOT APPLE)
316         option(WITH_JACK_DYNLOAD  "Enable runtime dynamic Jack libraries loading" OFF)
317 endif()
318 if(UNIX AND NOT APPLE)
319         option(WITH_SDL_DYNLOAD  "Enable runtime dynamic SDL libraries loading" OFF)
320 endif()
321
322 # Compression
323 option(WITH_LZO           "Enable fast LZO compression (used for pointcache)" ON)
324 option(WITH_LZMA          "Enable best LZMA compression, (used for pointcache)" ON)
325 if(UNIX AND NOT APPLE)
326         option(WITH_SYSTEM_LZO    "Use the system LZO library" OFF)
327 endif()
328
329 # Camera/motion tracking
330 option(WITH_LIBMV         "Enable Libmv structure from motion library" ON)
331 option(WITH_LIBMV_SCHUR_SPECIALIZATIONS "Enable fixed-size schur specializations." ${_init_LIBMV_SCHUR_SPECIALIZATION})
332 option(WITH_LIBMV_WERROR  "Treat warnings as errors in Libmv (and Blender's motion tracking) code")
333 mark_as_advanced(WITH_LIBMV_SCHUR_SPECIALIZATIONS)
334 mark_as_advanced(WITH_LIBMV_WERROR)
335
336 # Freestyle
337 option(WITH_FREESTYLE     "Enable Freestyle (advanced edges rendering)" ON)
338
339 # Misc
340 if(WIN32)
341         option(WITH_INPUT_IME "Enable Input Method Editor (IME) for complex Asian character input" ON)
342 endif()
343 option(WITH_INPUT_NDOF "Enable NDOF input devices (SpaceNavigator and friends)" ${_init_INPUT_NDOF})
344 option(WITH_RAYOPTIMIZATION     "Enable use of SIMD (SSE) optimizations for the raytracer" ON)
345 option(WITH_OPENNL        "Enable use of Open Numerical Library" ON)
346 if(UNIX AND NOT APPLE)
347         option(WITH_INSTALL_PORTABLE "Install redistributeable runtime, otherwise install into CMAKE_INSTALL_PREFIX" ON)
348         option(WITH_STATIC_LIBS "Try to link with static libraries, as much as possible, to make blender more portable across distributions" OFF)
349         if(WITH_STATIC_LIBS)
350                 option(WITH_BOOST_ICU "Boost uses ICU library (required for linking with static Boost built with libicu)." OFF)
351                 mark_as_advanced(WITH_BOOST_ICU)
352         endif()
353 endif()
354 option(WITH_PYTHON_INSTALL       "Copy system python into the blender install folder" ON)
355 option(WITH_PYTHON_INSTALL_NUMPY "Copy system numpy into the blender install folder"  ON)
356 set(PYTHON_NUMPY_PATH            "" CACHE PATH "Path to python site-packages or dist-packages containing 'numpy' module")
357 mark_as_advanced(PYTHON_NUMPY_PATH)
358 option(WITH_CPU_SSE              "Enable SIMD instruction if they're detected on the host machine" ON)
359 mark_as_advanced(WITH_CPU_SSE)
360
361 if(UNIX AND NOT APPLE)
362         option(WITH_PYTHON_INSTALL_REQUESTS "Copy system requests into the blender install folder" ON)
363         set(PYTHON_REQUESTS_PATH "" CACHE PATH "Path to python site-packages or dist-packages containing 'requests' module")
364         mark_as_advanced(PYTHON_REQUESTS_PATH)
365 endif()
366
367 # Cycles
368 option(WITH_CYCLES                                      "Enable Cycles Render Engine" ON)
369 option(WITH_CYCLES_STANDALONE           "Build Cycles standalone application" OFF)
370 option(WITH_CYCLES_STANDALONE_GUI       "Build Cycles standalone with GUI" OFF)
371 option(WITH_CYCLES_OSL                          "Build Cycles with OSL support" ${_init_CYCLES_OSL})
372 option(WITH_CYCLES_CUDA_BINARIES        "Build Cycles CUDA binaries" OFF)
373 set(CYCLES_CUDA_BINARIES_ARCH sm_20 sm_21 sm_30 sm_35 sm_50 sm_52 CACHE STRING "CUDA architectures to build binaries for")
374 mark_as_advanced(CYCLES_CUDA_BINARIES_ARCH)
375 unset(PLATFORM_DEFAULT)
376 option(WITH_CYCLES_LOGGING      "Build Cycles with logging support" ON)
377 option(WITH_CYCLES_DEBUG        "Build Cycles with extra debug capabilities" OFF)
378 option(WITH_CYCLES_WERROR       "Treat warnings as errors in Cycles code" OFF)
379 mark_as_advanced(WITH_CYCLES_LOGGING)
380 mark_as_advanced(WITH_CYCLES_DEBUG)
381 mark_as_advanced(WITH_CYCLES_WERROR)
382
383 # LLVM
384 option(WITH_LLVM                                        "Use LLVM" OFF)
385 if(APPLE)
386         option(LLVM_STATIC                                      "Link with LLVM static libraries" ON) # we prefer static llvm build on Apple, dyn build possible though
387 else()
388         option(LLVM_STATIC                                      "Link with LLVM static libraries" OFF)
389 endif()
390 mark_as_advanced(LLVM_STATIC)
391
392 # disable for now, but plan to support on all platforms eventually
393 option(WITH_MEM_JEMALLOC   "Enable malloc replacement (http://www.canonware.com/jemalloc)" ON)
394 mark_as_advanced(WITH_MEM_JEMALLOC)
395
396 # currently only used for BLI_mempool
397 option(WITH_MEM_VALGRIND "Enable extended valgrind support for better reporting" OFF)
398 mark_as_advanced(WITH_MEM_VALGRIND)
399
400 # Debug
401 option(WITH_CXX_GUARDEDALLOC "Enable GuardedAlloc for C++ memory allocation tracking (only enable for development)" OFF)
402 mark_as_advanced(WITH_CXX_GUARDEDALLOC)
403
404 option(WITH_ASSERT_ABORT "Call abort() when raising an assertion through BLI_assert()" OFF)
405 mark_as_advanced(WITH_ASSERT_ABORT)
406
407 option(WITH_BOOST                                       "Enable features depending on boost" ON)
408
409 # Unit testsing
410 option(WITH_GTESTS "Enable GTest unit testing" OFF)
411
412
413 # Documentation
414 if(UNIX AND NOT APPLE)
415         option(WITH_DOC_MANPAGE "Create a manual page (Unix manpage)" OFF)
416 endif()
417
418
419 # OpenGL
420
421 option(WITH_GLEW_MX             "Support multiple GLEW contexts (experimental)"                                                                     OFF )
422 option(WITH_GLEW_ES             "Switches to experimental copy of GLEW that has support for OpenGL ES. (temporary option for development purposes)" OFF)
423 option(WITH_GL_EGL              "Use the EGL OpenGL system library instead of the platform specific OpenGL system library (CGL, glX, or WGL)"       OFF)
424 option(WITH_GL_PROFILE_COMPAT   "Support using the OpenGL 'compatibility' profile. (deprecated)"                                                    ON )
425 option(WITH_GL_PROFILE_CORE     "Support using the OpenGL 3.2+ 'core' profile."                                                                     OFF)
426 option(WITH_GL_PROFILE_ES20     "Support using OpenGL ES 2.0. (thru either EGL or the AGL/WGL/XGL 'es20' profile)"                                  OFF)
427
428 mark_as_advanced(
429         WITH_GLEW_MX
430         WITH_GLEW_ES
431         WITH_GL_EGL
432         WITH_GL_PROFILE_COMPAT
433         WITH_GL_PROFILE_CORE
434         WITH_GL_PROFILE_ES20
435 )
436
437 if(WITH_GL_PROFILE_COMPAT)
438         set(WITH_GLU ON)
439 else()
440         set(WITH_GLU OFF)
441 endif()
442
443 if(WIN32)
444         option(WITH_GL_ANGLE "Link with the ANGLE library, an OpenGL ES 2.0 implementation based on Direct3D, instead of the system OpenGL library." OFF)
445         mark_as_advanced(WITH_GL_ANGLE)
446 endif()
447
448 if(WITH_GLEW_ES AND WITH_SYSTEM_GLEW)
449         message(WARNING Ignoring WITH_SYSTEM_GLEW and using WITH_GLEW_ES)
450         set(WITH_SYSTEM_GLEW OFF)
451 endif()
452
453 if(MSVC)
454         getDefaultWindowsPrefixBase(CMAKE_GENERIC_PROGRAM_FILES)
455         set(CPACK_INSTALL_PREFIX ${CMAKE_GENERIC_PROGRAM_FILES}/${})
456 endif()
457
458 # Experimental support of C++11
459 option(WITH_CPP11 "Build with C++11 standard enabled, for development use only!" OFF)
460 mark_as_advanced(WITH_CPP11)
461
462 # Dependency graph
463 option(WITH_LEGACY_DEPSGRAPH "Build Blender with legacy dependency graph" ON)
464 mark_as_advanced(WITH_LEGACY_DEPSGRAPH)
465
466 # avoid using again
467 option_defaults_clear()
468
469 # end option(...)
470
471
472
473 # By default we want to install to the directory we are compiling our executables
474 # unless specified otherwise, which we currently do not allow
475 if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
476         if(MSVC)
477                 set(CMAKE_INSTALL_PREFIX ${EXECUTABLE_OUTPUT_PATH}/\${BUILD_TYPE} CACHE PATH "default install path" FORCE)
478         elseif(APPLE)
479                 set(CMAKE_INSTALL_PREFIX ${EXECUTABLE_OUTPUT_PATH}/\${BUILD_TYPE} CACHE PATH "default install path" FORCE)
480         else()
481                 if(WITH_INSTALL_PORTABLE)
482                         set(CMAKE_INSTALL_PREFIX ${EXECUTABLE_OUTPUT_PATH} CACHE PATH "default install path" FORCE)
483                 endif()
484         endif()
485 endif()
486
487
488
489 # Apple
490
491 if(APPLE)
492         if(${CMAKE_VERSION} VERSION_LESS 3.0) # else breaks setting CMP0043 policy
493                 cmake_minimum_required(VERSION 2.8.8)
494                 cmake_policy(VERSION 2.8.8)
495         endif()
496
497         if(NOT CMAKE_OSX_ARCHITECTURES)
498                 set(CMAKE_OSX_ARCHITECTURES x86_64 CACHE STRING
499                 "Choose the architecture you want to build Blender for: i386, x86_64 or ppc"
500                 FORCE)
501         endif()
502         
503         execute_process(COMMAND uname -r OUTPUT_VARIABLE MAC_SYS) # check for actual system-version
504         if(${MAC_SYS} MATCHES 14)
505                 set(OSX_SYSTEM 10.10)
506                 # throw an error here, older cmake cannot handle 2 digit subversion!
507                 cmake_minimum_required(VERSION 3.0.0)
508         elseif(${MAC_SYS} MATCHES 13)
509                 set(OSX_SYSTEM 10.9)
510         elseif(${MAC_SYS} MATCHES 12)
511                 set(OSX_SYSTEM 10.8)
512         elseif(${MAC_SYS} MATCHES 11)
513                 set(OSX_SYSTEM 10.7)
514         elseif(${MAC_SYS} MATCHES 10)
515                 set(OSX_SYSTEM 10.6)
516         elseif(${MAC_SYS} MATCHES 9)
517                 set(OSX_SYSTEM 10.5)
518         else()
519                 set(OSX_SYSTEM unsupported)
520         endif()
521         message(STATUS "Detected system-version: " ${OSX_SYSTEM})
522         
523         # workaround for incorrect cmake xcode lookup for developer previews - XCODE_VERSION does not take xcode-select path into accout
524         # but would always look into /Applications/Xcode.app while dev versions are named Xcode<version>-DP<preview_number>
525         execute_process(COMMAND xcode-select --print-path  OUTPUT_VARIABLE XCODE_CHECK OUTPUT_STRIP_TRAILING_WHITESPACE)
526         string(REPLACE "/Contents/Developer" "" XCODE_BUNDLE ${XCODE_CHECK}) # truncate to bundlepath in any case
527         message(STATUS "Xcode-bundle : " ${XCODE_BUNDLE})
528         
529         if(${CMAKE_GENERATOR} MATCHES "Xcode")
530         
531                 if(${XCODE_VERSION} VERSION_GREATER 4.2) # earlier xcode has no bundled developer dir, no sense in getting xcode path from
532                         string(SUBSTRING "${XCODE_CHECK}" 14 6 DP_NAME) # reduce to XCode name without dp extension
533                         if(${DP_NAME} MATCHES Xcode5)
534                                 set(XCODE_VERSION 5)
535                         endif()
536                 endif()
537
538                 ##### cmake incompatibility with xcode  4.3 and higher #####
539                 if(${XCODE_VERSION} MATCHES '') # cmake fails due looking for xcode in the wrong path, thus will be empty var
540                         message(FATAL_ERROR "Xcode 4.3 and higher must be used with cmake 2.8-8 or higher")
541                 endif()
542                 ### end cmake incompatibility with xcode 4.3 and higher ###
543                 
544                 if(${XCODE_VERSION} VERSION_EQUAL 4 OR ${XCODE_VERSION} VERSION_GREATER 4 AND ${XCODE_VERSION} VERSION_LESS 4.3)
545                         # Xcode 4 defaults to the Apple LLVM Compiler.
546                         # Override the default compiler selection because Blender only compiles with gcc up to xcode 4.2
547                         set(CMAKE_XCODE_ATTRIBUTE_GCC_VERSION "com.apple.compilers.llvmgcc42")
548                         message(STATUS "Setting compiler to: " ${CMAKE_XCODE_ATTRIBUTE_GCC_VERSION})
549                 endif()
550         else() # unix makefile generator does not fill XCODE_VERSION var, so we get it with a command
551                 execute_process(COMMAND xcodebuild -version OUTPUT_VARIABLE XCODE_VERS_BUILD_NR)
552                 string(SUBSTRING "${XCODE_VERS_BUILD_NR}" 6 3 XCODE_VERSION) # truncate away build-nr
553                 unset(XCODE_VERS_BUILD_NR)
554         endif()
555         
556         message(STATUS "Detected Xcode-version: " ${XCODE_VERSION})
557
558         if(${XCODE_VERSION} VERSION_LESS 4.3)
559                 set(CMAKE_OSX_SYSROOT /Developer/SDKs/MacOSX${OSX_SYSTEM}.sdk CACHE PATH "" FORCE)  # use guaranteed existing sdk
560         else()
561                 # note: xcode-select path could be ambigous, cause /Applications/Xcode.app/Contents/Developer or /Applications/Xcode.app would be allowed
562                 # so i use a selfcomposed bundlepath here  
563                 set(OSX_SYSROOT_PREFIX ${XCODE_BUNDLE}/Contents/Developer/Platforms/MacOSX.platform)
564                 message(STATUS "OSX_SYSROOT_PREFIX: " ${OSX_SYSROOT_PREFIX})
565                 set(OSX_DEVELOPER_PREFIX /Developer/SDKs/MacOSX${OSX_SYSTEM}.sdk) # use guaranteed existing sdk
566                 set(CMAKE_OSX_SYSROOT ${OSX_SYSROOT_PREFIX}/${OSX_DEVELOPER_PREFIX} CACHE PATH "" FORCE)
567                 if(${CMAKE_GENERATOR} MATCHES "Xcode")
568                         set(CMAKE_XCODE_ATTRIBUTE_SDKROOT macosx${OSX_SYSTEM}) # to silence sdk not found warning, just overrides CMAKE_OSX_SYSROOT
569                 endif()
570         endif()
571
572         if(OSX_SYSTEM MATCHES 10.9)
573                 set(CMAKE_FIND_ROOT_PATH ${CMAKE_OSX_SYSROOT}) # make sure syslibs and headers are looked up in sdk ( expecially for 10.9 openGL atm. )
574         endif()
575
576         if(NOT CMAKE_OSX_DEPLOYMENT_TARGET)
577                 set(CMAKE_OSX_DEPLOYMENT_TARGET "10.6" CACHE STRING "" FORCE) # 10.6 is our min. target, if you use higher sdk, weak linking happens
578         endif()
579         
580         if(NOT ${CMAKE_GENERATOR} MATCHES "Xcode")
581                 # force CMAKE_OSX_DEPLOYMENT_TARGET for makefiles, will not work else ( cmake bug ? )
582                 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET}")
583                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET}")
584                 add_definitions("-DMACOSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET}")
585         endif()
586
587         option(WITH_LIBS10.5  "Use 10.5 libs (needed for 64bit builds)" OFF)
588 endif()
589
590
591 #-----------------------------------------------------------------------------
592 # Check for conflicting/unsupported configurations
593
594 if(NOT WITH_BLENDER AND NOT WITH_PLAYER AND NOT WITH_CYCLES_STANDALONE)
595         message(FATAL_ERROR "At least one of WITH_BLENDER or WITH_PLAYER or WITH_CYCLES_STANDALONE must be enabled, nothing to do!")
596 endif()
597
598 if(NOT WITH_GAMEENGINE AND WITH_PLAYER)
599         message(FATAL_ERROR "WITH_PLAYER requires WITH_GAMEENGINE")
600 endif()
601
602 if(NOT WITH_AUDASPACE)
603         if(WITH_OPENAL)
604                 message(FATAL_ERROR "WITH_OPENAL requires WITH_AUDASPACE")
605         endif()
606         if(WITH_JACK)
607                 message(FATAL_ERROR "WITH_JACK requires WITH_AUDASPACE")
608         endif()
609         if(WITH_GAMEENGINE)
610                 message(FATAL_ERROR "WITH_GAMEENGINE requires WITH_AUDASPACE")
611         endif()
612 endif()
613
614 if(NOT WITH_SDL AND WITH_GHOST_SDL)
615         message(FATAL_ERROR "WITH_GHOST_SDL requires WITH_SDL")
616 endif()
617
618 if(WITH_IMAGE_REDCODE AND ((NOT WITH_IMAGE_OPENJPEG) OR (NOT WITH_CODEC_FFMPEG)))
619         message(FATAL_ERROR "WITH_IMAGE_REDCODE requires WITH_IMAGE_OPENJPEG and WITH_CODEC_FFMPEG")
620 endif()
621
622 # python module, needs some different options
623 if(WITH_PYTHON_MODULE AND WITH_PLAYER)
624         message(FATAL_ERROR "WITH_PYTHON_MODULE requires WITH_PLAYER to be OFF")
625 endif()
626
627 if(WITH_PYTHON_MODULE AND WITH_PYTHON_INSTALL)
628         message(FATAL_ERROR "WITH_PYTHON_MODULE requires WITH_PYTHON_INSTALL to be OFF")
629 endif()
630
631
632 # may as well build python module without a UI
633 if(WITH_PYTHON_MODULE)
634         set(WITH_HEADLESS ON)
635 endif()
636
637 if(NOT WITH_PYTHON)
638         set(WITH_CYCLES OFF)
639 endif()
640
641 # enable boost for cycles, audaspace or i18n
642 # otherwise if the user disabled
643 if(NOT WITH_BOOST)
644         # Explicitly disabled. so disable all deps.
645         macro(set_and_warn
646                 _setting _val)
647                 if(${${_setting}})
648                         message(STATUS "'WITH_BOOST' is disabled: forceing 'set(${_setting} ${_val})'")
649                 endif()
650                 set(${_setting} ${_val})
651         endmacro()
652
653         set_and_warn(WITH_CYCLES         OFF)
654         set_and_warn(WITH_AUDASPACE      OFF)
655         set_and_warn(WITH_INTERNATIONAL  OFF)
656
657         set_and_warn(WITH_OPENAL         OFF)  # depends on AUDASPACE
658         set_and_warn(WITH_GAMEENGINE     OFF)  # depends on AUDASPACE
659 elseif(WITH_CYCLES OR WITH_OPENIMAGEIO OR WITH_AUDASPACE OR WITH_INTERNATIONAL)
660         # Keep enabled
661 else()
662         # Enabled but we don't need it
663         set(WITH_BOOST OFF)
664 endif()
665
666 # auto enable openimageio for cycles
667 if(WITH_CYCLES)
668         set(WITH_OPENIMAGEIO ON)
669
670         # auto enable llvm for cycles_osl
671         if(WITH_CYCLES_OSL)
672                 set(WITH_LLVM ON CACHE BOOL "" FORCE)
673         endif()
674 else()
675         set(WITH_CYCLES_OSL OFF)
676 endif()
677
678 # auto enable openimageio linking dependencies
679 if(WITH_OPENIMAGEIO)
680         set(WITH_IMAGE_OPENEXR ON)
681         set(WITH_IMAGE_TIFF ON)
682 endif()
683
684 # don't store paths to libs for portable distribution
685 if(WITH_INSTALL_PORTABLE)
686         set(CMAKE_SKIP_BUILD_RPATH TRUE)
687 endif()
688
689 if(WITH_GHOST_SDL OR WITH_HEADLESS)
690         set(WITH_X11           OFF)
691         set(WITH_X11_XINPUT    OFF)
692         set(WITH_X11_XF86VMODE OFF)
693         set(WITH_GHOST_XDND    OFF)
694         set(WITH_INPUT_IME     OFF)
695 endif()
696
697 if(WITH_CPU_SSE)
698         TEST_SSE_SUPPORT(COMPILER_SSE_FLAG COMPILER_SSE2_FLAG)
699 else()
700         message(STATUS "SSE and SSE2 optimizations are DISABLED!")
701         set(COMPILER_SSE_FLAG)
702         set(COMPILER_SSE2_FLAG)
703 endif()
704
705 TEST_STDBOOL_SUPPORT()
706 if(HAVE_STDBOOL_H)
707         add_definitions(-DHAVE_STDBOOL_H)
708 endif()
709
710 #-----------------------------------------------------------------------------
711 # Check for valid directories
712 # ... a partial checkout may cause this.
713 #
714 # note: we need to check for a known subdir in both cases.
715 #       since uninitialized git submodules will give blank dirs
716
717 if(WITH_INTERNATIONAL)
718         if(NOT EXISTS "${CMAKE_SOURCE_DIR}/release/datafiles/locale/languages")
719                 message(WARNING "Translation path '${CMAKE_SOURCE_DIR}/release/datafiles/locale' is missing, "
720                                                 "This is a 'git submodule', which are known not to work with bridges to other version "
721                                                 "control systems, disabling 'WITH_INTERNATIONAL'.")
722                 set(WITH_INTERNATIONAL OFF)
723         endif()
724 endif()
725
726 if(WITH_PYTHON)
727         if(NOT EXISTS "${CMAKE_SOURCE_DIR}/release/scripts/addons/modules")
728                 message(WARNING "Addons path '${CMAKE_SOURCE_DIR}/release/scripts/addons' is missing, "
729                                                 "This is a 'git submodule', which are known not to work with bridges to other version "
730                                                 "control systems: * CONTINUING WITHOUT ADDONS *")
731         endif()
732 endif()
733
734 #-----------------------------------------------------------------------------
735 # Initialize un-cached vars, avoid unused warning
736
737 # linux only, not cached
738 set(WITH_BINRELOC OFF)
739
740 # MAXOSX only, set to avoid uninitialized
741 set(EXETYPE "")
742
743 # C/C++ flags
744 set(PLATFORM_CFLAGS)
745
746 # these are added to later on.
747 set(C_WARNINGS)
748 set(CXX_WARNINGS)
749
750 # for gcc -Wno-blah-blah
751 set(CC_REMOVE_STRICT_FLAGS)
752
753 # libraries to link the binary with passed to target_link_libraries()
754 # known as LLIBS to scons
755 set(PLATFORM_LINKLIBS "")
756
757 # Added to linker flags in setup_liblinks
758 # - CMAKE_EXE_LINKER_FLAGS
759 # - CMAKE_EXE_LINKER_FLAGS_DEBUG
760 set(PLATFORM_LINKFLAGS "")
761 set(PLATFORM_LINKFLAGS_DEBUG "")
762
763
764 # For alternate Python locations the commandline can be used to override detected/default cache settings, e.g:
765 # On Unix:
766 #   cmake ../blender \
767 #         -D PYTHON_VERSION=3.4 \
768 #         -D PYTHON_INCLUDE_DIR=/opt/py34/include/python3.4d \
769 #         -D PYTHON_LIBRARY=/opt/py34/lib/libpython3.4d.so
770 #
771 # On Macs:
772 #   cmake ../blender \
773 #         -D PYTHON_INCLUDE_DIR=/System/Library/Frameworks/Python.framework/Versions/3.4/include/python3.4 \
774 #         -D PYTHON_LIBPATH=/System/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/config \
775 #         -G Xcode
776 #
777 # When changing any of this remember to update the notes in doc/build_systems/cmake.txt
778
779 #-----------------------------------------------------------------------------
780 #Platform specifics
781
782 if(WITH_X11)
783         find_package(X11 REQUIRED)
784
785         find_path(X11_XF86keysym_INCLUDE_PATH X11/XF86keysym.h ${X11_INC_SEARCH_PATH})
786         mark_as_advanced(X11_XF86keysym_INCLUDE_PATH)
787
788         list(APPEND PLATFORM_LINKLIBS ${X11_X11_LIB})
789
790         if(WITH_X11_XINPUT)
791                 if(X11_Xinput_LIB)
792                         list(APPEND PLATFORM_LINKLIBS ${X11_Xinput_LIB})
793                 else()
794                         set(WITH_X11_XINPUT OFF)
795                 endif()
796         endif()
797
798         if(WITH_X11_XF86VMODE)
799                 # XXX, why dont cmake make this available?
800                 find_library(X11_Xxf86vmode_LIB Xxf86vm   ${X11_LIB_SEARCH_PATH})
801                 mark_as_advanced(X11_Xxf86vmode_LIB)
802                 if(X11_Xxf86vmode_LIB)
803                         list(APPEND PLATFORM_LINKLIBS ${X11_Xxf86vmode_LIB})
804                 else()
805                         set(WITH_X11_XF86VMODE OFF)
806                 endif()
807         endif()
808
809 endif()
810
811
812 # ----------------------------------------------------------------------------
813 # Main Platform Checks
814 #
815 # - UNIX
816 # - WIN32
817 # - APPLE
818
819 if(UNIX AND NOT APPLE)
820         macro(find_package_wrapper)
821                 if(WITH_STATIC_LIBS)
822                         set(_cmake_find_library_suffixes_back ${CMAKE_FIND_LIBRARY_SUFFIXES})
823                         set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
824                 endif()
825                 find_package(${ARGV})
826                 if(WITH_STATIC_LIBS)
827                         set(CMAKE_FIND_LIBRARY_SUFFIXES ${_cmake_find_library_suffixes_back})
828                         unset(_cmake_find_library_suffixes_back)
829                 endif()
830         endmacro()
831
832         find_package_wrapper(JPEG REQUIRED)
833         find_package_wrapper(PNG REQUIRED)
834         find_package_wrapper(ZLIB REQUIRED)
835         find_package_wrapper(Freetype REQUIRED)
836
837         if(WITH_LZO AND WITH_SYSTEM_LZO)
838                 find_package_wrapper(LZO)
839                 if(NOT LZO_FOUND)
840                         message(FATAL_ERROR "Failed finding system LZO version!")
841                 endif()
842         endif()
843
844         if(WITH_SYSTEM_EIGEN3)
845                 find_package_wrapper(Eigen3)
846                 if(NOT EIGEN3_FOUND)
847                         message(FATAL_ERROR "Failed finding system Eigen3 version!")
848                 endif()
849         endif()
850         # else values are set below for all platforms
851
852         if(WITH_PYTHON)
853                 # No way to set py34. remove for now.
854                 # find_package(PythonLibs)
855
856                 # Use our own instead, since wothout py is such a rare case,
857                 # require this package
858                 # XXX Linking errors with debian static python :/
859 #               find_package_wrapper(PythonLibsUnix REQUIRED)
860                 find_package(PythonLibsUnix REQUIRED)
861         endif()
862
863         if(WITH_IMAGE_OPENEXR)
864                 find_package_wrapper(OpenEXR)  # our own module
865                 if(NOT OPENEXR_FOUND)
866                         set(WITH_IMAGE_OPENEXR OFF)
867                 endif()
868         endif()
869
870         if(WITH_IMAGE_OPENJPEG)
871                 find_package_wrapper(OpenJPEG)
872                 if(NOT OPENJPEG_FOUND)
873                         set(WITH_IMAGE_OPENJPEG OFF)
874                 endif()
875         endif()
876
877         if(WITH_IMAGE_TIFF)
878                 # XXX Linking errors with debian static tiff :/
879 #               find_package_wrapper(TIFF)
880                 find_package(TIFF)
881                 if(NOT TIFF_FOUND)
882                         set(WITH_IMAGE_TIFF OFF)
883                 endif()
884         endif()
885
886         # Audio IO
887         if(WITH_EXTERNAL_AUDASPACE)
888                 find_package_wrapper(Audaspace)
889                 if(NOT AUDASPACE_FOUND OR NOT CAUDASPACE_FOUND)
890                         message(FATAL_ERROR "Audaspace external library not found!")
891                 endif()
892         endif()
893
894         if(WITH_OPENAL)
895                 find_package_wrapper(OpenAL)
896                 if(NOT OPENAL_FOUND)
897                         set(WITH_OPENAL OFF)
898                 endif()
899         endif()
900
901         if(WITH_SDL)
902                 if(WITH_SDL_DYNLOAD)
903                         set(SDL_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/extern/sdlew/include/SDL2")
904                         set(SDL_LIBRARY)
905                 else()
906                         find_package_wrapper(SDL2)
907                         if(SDL2_FOUND)
908                                 # Use same names for both versions of SDL until we move to 2.x.
909                                 set(SDL_INCLUDE_DIR "${SDL2_INCLUDE_DIR}")
910                                 set(SDL_LIBRARY "${SDL2_LIBRARY}")
911                                 set(SDL_FOUND "${SDL2_FOUND}")
912                         else()
913                                 find_package_wrapper(SDL)
914                         endif()
915                         mark_as_advanced(
916                                 SDL_INCLUDE_DIR
917                                 SDL_LIBRARY
918                         )
919                         # unset(SDLMAIN_LIBRARY CACHE)
920                         if(NOT SDL_FOUND)
921                                 set(WITH_SDL OFF)
922                         endif()
923                 endif()
924         endif()
925
926         if(WITH_JACK)
927                 find_package_wrapper(Jack)
928                 if(NOT JACK_FOUND)
929                         set(WITH_JACK OFF)
930                 endif()
931         endif()
932
933         # Codecs
934         if(WITH_CODEC_SNDFILE)
935                 find_package_wrapper(SndFile)
936                 if(NOT SNDFILE_FOUND)
937                         set(WITH_CODEC_SNDFILE OFF)
938                 endif()
939         endif()
940
941         if(WITH_CODEC_FFMPEG)
942                 set(FFMPEG /usr CACHE PATH "FFMPEG Directory")
943                 set(FFMPEG_LIBRARIES avformat avcodec avutil avdevice swscale CACHE STRING "FFMPEG Libraries")
944
945                 mark_as_advanced(FFMPEG)
946
947                 # lame, but until we have proper find module for ffmpeg
948                 set(FFMPEG_INCLUDE_DIRS ${FFMPEG}/include)
949                 if(EXISTS "${FFMPEG}/include/ffmpeg/")
950                         list(APPEND FFMPEG_INCLUDE_DIRS "${FFMPEG}/include/ffmpeg")
951                 endif()
952                 # end lameness
953
954                 mark_as_advanced(FFMPEG_LIBRARIES)
955                 set(FFMPEG_LIBPATH ${FFMPEG}/lib)
956         endif()
957
958         if(WITH_FFTW3)
959                 find_package_wrapper(Fftw3)
960                 if(NOT FFTW3_FOUND)
961                         set(WITH_FFTW3 OFF)
962                 endif()
963         endif()
964
965         if(WITH_OPENCOLLADA)
966                 find_package_wrapper(OpenCOLLADA)
967                 if(OPENCOLLADA_FOUND)
968                         find_package_wrapper(XML2)
969                         find_package_wrapper(PCRE)
970                 else()
971                         set(WITH_OPENCOLLADA OFF)
972                 endif()
973         endif()
974
975         if(WITH_MEM_JEMALLOC)
976                 find_package_wrapper(JeMalloc)
977                 if(NOT JEMALLOC_FOUND)
978                         set(WITH_MEM_JEMALLOC OFF)
979                 endif()
980         endif()
981
982         if(WITH_INPUT_NDOF)
983                 find_package_wrapper(Spacenav)
984                 if(NOT SPACENAV_FOUND)
985                         set(WITH_INPUT_NDOF OFF)
986                 endif()
987
988                 # use generic names within blenders buildsystem.
989                 if(SPACENAV_FOUND)
990                         set(NDOF_INCLUDE_DIRS ${SPACENAV_INCLUDE_DIRS})
991                         set(NDOF_LIBRARIES ${SPACENAV_LIBRARIES})
992                 endif()
993         endif()
994
995         if(WITH_CYCLES_OSL)
996                 set(CYCLES_OSL ${LIBDIR}/osl CACHE PATH "Path to OpenShadingLanguage installation")
997                 if(NOT OSL_ROOT)
998                         set(OSL_ROOT ${CYCLES_OSL})
999                 endif()
1000                 find_package_wrapper(OpenShadingLanguage)
1001                 if(OSL_FOUND)
1002                         if(${OSL_LIBRARY_VERSION_MAJOR} EQUAL "1" AND ${OSL_LIBRARY_VERSION_MINOR} LESS "6")
1003                                 # Note: --whole-archive is needed to force loading of all symbols in liboslexec,
1004                                 # otherwise LLVM is missing the osl_allocate_closure_component function
1005                                 set(OSL_LIBRARIES ${OSL_OSLCOMP_LIBRARY} -Wl,--whole-archive ${OSL_OSLEXEC_LIBRARY} -Wl,--no-whole-archive ${OSL_OSLQUERY_LIBRARY})
1006                         endif()
1007                 else()
1008                         message(STATUS "OSL not found, disabling it from Cycles")
1009                         set(WITH_CYCLES_OSL OFF)
1010                 endif()
1011         endif()
1012
1013         if(WITH_BOOST)
1014                 # uses in build instructions to override include and library variables
1015                 if(NOT BOOST_CUSTOM)
1016                         if(WITH_STATIC_LIBS)
1017                                 set(Boost_USE_STATIC_LIBS ON)
1018                         endif()
1019                         set(Boost_USE_MULTITHREADED ON)
1020                         set(__boost_packages filesystem regex system thread date_time)
1021                         if(WITH_CYCLES_OSL)
1022                                 if(NOT (${OSL_LIBRARY_VERSION_MAJOR} EQUAL "1" AND ${OSL_LIBRARY_VERSION_MINOR} LESS "6"))
1023                                         list(APPEND __boost_packages wave)
1024                                 else()
1025                                 endif()
1026                         endif()
1027                         if(WITH_INTERNATIONAL)
1028                                 list(APPEND __boost_packages locale)
1029                         endif()
1030                         if(WITH_CYCLES_NETWORK)
1031                                 list(APPEND __boost_packages serialization)
1032                         endif()
1033                         find_package(Boost 1.48 COMPONENTS ${__boost_packages})
1034                         if(NOT Boost_FOUND)
1035                                 # try to find non-multithreaded if -mt not found, this flag
1036                                 # doesn't matter for us, it has nothing to do with thread
1037                                 # safety, but keep it to not disturb build setups
1038                                 set(Boost_USE_MULTITHREADED OFF)
1039                                 find_package(Boost 1.48 COMPONENTS ${__boost_packages})
1040                         endif()
1041                         unset(__boost_packages)
1042                         if(Boost_USE_STATIC_LIBS AND WITH_BOOST_ICU)
1043                                 find_package(IcuLinux)
1044                         endif()
1045                         mark_as_advanced(Boost_DIR)  # why doesnt boost do this?
1046                 endif()
1047
1048                 set(BOOST_INCLUDE_DIR ${Boost_INCLUDE_DIRS})
1049                 set(BOOST_LIBRARIES ${Boost_LIBRARIES})
1050                 set(BOOST_LIBPATH ${Boost_LIBRARY_DIRS})
1051                 set(BOOST_DEFINITIONS "-DBOOST_ALL_NO_LIB")
1052         endif()
1053
1054         if(WITH_OPENIMAGEIO)
1055                 find_package_wrapper(OpenImageIO)
1056                 if(NOT OPENIMAGEIO_PUGIXML_FOUND AND WITH_CYCLES_STANDALONE)
1057                         find_package_wrapper(PugiXML)
1058                 else()
1059                         set(PUGIXML_INCLUDE_DIR "${OPENIMAGEIO_INCLUDE_DIR/OpenImageIO}")
1060                         set(PUGIXML_LIBRARIES "")
1061                 endif()
1062
1063                 set(OPENIMAGEIO_LIBRARIES ${OPENIMAGEIO_LIBRARIES} ${PNG_LIBRARIES} ${JPEG_LIBRARIES} ${ZLIB_LIBRARIES} ${BOOST_LIBRARIES})
1064                 set(OPENIMAGEIO_LIBPATH)  # TODO, remove and reference the absolute path everywhere
1065                 set(OPENIMAGEIO_DEFINITIONS "")
1066
1067                 if(WITH_IMAGE_TIFF)
1068                         list(APPEND OPENIMAGEIO_LIBRARIES "${TIFF_LIBRARY}")
1069                 endif()
1070                 if(WITH_IMAGE_OPENEXR)
1071                         list(APPEND OPENIMAGEIO_LIBRARIES "${OPENEXR_LIBRARIES}")
1072                 endif()
1073
1074                 if(NOT OPENIMAGEIO_FOUND)
1075                         set(WITH_OPENIMAGEIO OFF)
1076                         message(STATUS "OpenImageIO not found, disabling WITH_CYCLES")
1077                 endif()
1078         endif()
1079
1080         if(WITH_OPENCOLORIO)
1081                 find_package_wrapper(OpenColorIO)
1082
1083                 set(OPENCOLORIO_LIBRARIES ${OPENCOLORIO_LIBRARIES})
1084                 set(OPENCOLORIO_LIBPATH)  # TODO, remove and reference the absolute path everywhere
1085                 set(OPENCOLORIO_DEFINITIONS)
1086
1087                 if(NOT OPENCOLORIO_FOUND)
1088                         set(WITH_OPENCOLORIO OFF)
1089                         message(STATUS "OpenColorIO not found")
1090                 endif()
1091         endif()
1092
1093         if(WITH_LLVM)
1094                 find_package_wrapper(LLVM)
1095
1096                 if(NOT LLVM_FOUND)
1097                         set(WITH_LLVM OFF)
1098                         message(STATUS "LLVM not found")
1099                 endif()
1100         endif()
1101
1102         if(WITH_LLVM OR WITH_SDL_DYNLOAD)
1103                 # Fix for conflict with Mesa llvmpipe
1104                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -Wl,--version-script='${CMAKE_SOURCE_DIR}/source/creator/blender.map'")
1105         endif()
1106
1107         if(WITH_OPENSUBDIV)
1108                 find_package_wrapper(OpenSubdiv)
1109
1110                 set(OPENSUBDIV_LIBRARIES ${OPENSUBDIV_LIBRARIES})
1111                 set(OPENSUBDIV_LIBPATH)  # TODO, remove and reference the absolute path everywhere
1112
1113                 if(NOT OPENSUBDIV_FOUND)
1114                         set(WITH_OPENSUBDIV OFF)
1115                         message(STATUS "OpenSundiv not found")
1116                 endif()
1117         endif()
1118
1119         # OpenSuse needs lutil, ArchLinux not, for now keep, can avoid by using --as-needed
1120         list(APPEND PLATFORM_LINKLIBS -lutil -lc -lm)
1121
1122         find_package(Threads REQUIRED)
1123         list(APPEND PLATFORM_LINKLIBS ${CMAKE_THREAD_LIBS_INIT})
1124         # used by other platforms
1125         set(PTHREADS_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
1126
1127         if(CMAKE_DL_LIBS)
1128                 list(APPEND PLATFORM_LINKLIBS ${CMAKE_DL_LIBS})
1129         endif()
1130
1131         if(CMAKE_SYSTEM_NAME MATCHES "Linux")
1132                 if(NOT WITH_PYTHON_MODULE)
1133                         # binreloc is linux only
1134                         set(BINRELOC_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/extern/binreloc/include)
1135                         set(WITH_BINRELOC ON)
1136                 endif()
1137         endif()
1138
1139         # lfs on glibc, all compilers should use
1140         add_definitions(-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE)
1141
1142         # GNU Compiler
1143         if(CMAKE_COMPILER_IS_GNUCC)
1144                 set(PLATFORM_CFLAGS "-pipe -fPIC -funsigned-char -fno-strict-aliasing")
1145
1146                 if(NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "5.0")
1147                         # GCC5 uses gnu11, until we update, force c89
1148                         # though some c11 features can still be used.
1149                         set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu89")
1150                 endif()
1151
1152                 # use ld.gold linker if available, could make optional
1153                 execute_process(
1154                         COMMAND ${CMAKE_C_COMPILER} -fuse-ld=gold -Wl,--version
1155                         ERROR_QUIET OUTPUT_VARIABLE LD_VERSION)
1156                 if("${LD_VERSION}" MATCHES "GNU gold")
1157                         set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fuse-ld=gold")
1158                         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fuse-ld=gold")
1159                 else()
1160                         message(STATUS "GNU gold linker isn't available, using the default system linker.")
1161                 endif()
1162                 unset(LD_VERSION)
1163
1164         # CLang is the same as GCC for now.
1165         elseif(CMAKE_C_COMPILER_ID MATCHES "Clang")
1166                 set(PLATFORM_CFLAGS "-pipe -fPIC -funsigned-char -fno-strict-aliasing")
1167         # Solaris CC
1168         elseif(CMAKE_C_COMPILER_ID MATCHES "SunPro")
1169                 set(PLATFORM_CFLAGS "-pipe -features=extensions -fPIC -D__FUNCTION__=__func__")
1170                 
1171         # Intel C++ Compiler
1172         elseif(CMAKE_C_COMPILER_ID MATCHES "Intel")
1173                 # think these next two are broken
1174                 find_program(XIAR xiar)
1175                 if(XIAR)
1176                         set(CMAKE_AR "${XIAR}")
1177                 endif()
1178                 mark_as_advanced(XIAR)
1179
1180                 find_program(XILD xild)
1181                 if(XILD)
1182                         set(CMAKE_LINKER "${XILD}")
1183                 endif()
1184                 mark_as_advanced(XILD)
1185
1186                 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fp-model precise -prec_div -parallel")
1187                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fp-model precise -prec_div -parallel")
1188
1189                 # set(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -diag-enable sc3")
1190                 set(PLATFORM_CFLAGS "-pipe -fPIC -funsigned-char -fno-strict-aliasing")
1191                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -static-intel")
1192         endif()
1193
1194 elseif(WIN32)
1195
1196         add_definitions(-DWIN32)
1197
1198         if(MSVC)
1199
1200                 # needed for some MSVC installations
1201                 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SAFESEH:NO")
1202                 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /SAFESEH:NO")
1203                 set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} /SAFESEH:NO")
1204
1205                 list(APPEND PLATFORM_LINKLIBS ws2_32 vfw32 winmm kernel32 user32 gdi32 comdlg32 advapi32 shfolder shell32 ole32 oleaut32 uuid psapi Dbghelp)
1206
1207                 if(WITH_INPUT_IME)
1208                         list(APPEND PLATFORM_LINKLIBS imm32)
1209                 endif()
1210
1211                 add_definitions(
1212                         -D_CRT_NONSTDC_NO_DEPRECATE
1213                         -D_CRT_SECURE_NO_DEPRECATE
1214                         -D_SCL_SECURE_NO_DEPRECATE
1215                         -D_CONSOLE
1216                         -D_LIB
1217                 )
1218
1219                 # MSVC11 needs _ALLOW_KEYWORD_MACROS to build
1220                 add_definitions(-D_ALLOW_KEYWORD_MACROS)
1221
1222                 if(CMAKE_CL_64)
1223                         # We want to support Vista level ABI for x64
1224                         add_definitions(-D_WIN32_WINNT=0x600)
1225                 endif()
1226
1227                 # Make cmake find the msvc redistributables
1228                 set(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_SKIP TRUE)
1229                 include(InstallRequiredSystemLibraries)
1230
1231                 set(CMAKE_CXX_FLAGS "/nologo /J /Gd /EHsc /MP" CACHE STRING "MSVC MT C++ flags " FORCE)
1232                 set(CMAKE_C_FLAGS   "/nologo /J /Gd /MP"       CACHE STRING "MSVC MT C++ flags " FORCE)
1233
1234                 if(CMAKE_CL_64)
1235                         set(CMAKE_CXX_FLAGS_DEBUG "/Od /RTC1 /MTd /Zi /MP" CACHE STRING "MSVC MT flags " FORCE)
1236                 else()
1237                         set(CMAKE_CXX_FLAGS_DEBUG "/Od /RTC1 /MTd /ZI /MP" CACHE STRING "MSVC MT flags " FORCE)
1238                 endif()
1239                 set(CMAKE_CXX_FLAGS_RELEASE "/O2 /Ob2 /MT /MP" CACHE STRING "MSVC MT flags " FORCE)
1240                 set(CMAKE_CXX_FLAGS_MINSIZEREL "/O1 /Ob1 /MT /MP" CACHE STRING "MSVC MT flags " FORCE)
1241                 set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/O2 /Ob1 /MT /Zi /MP" CACHE STRING "MSVC MT flags " FORCE)
1242                 if(CMAKE_CL_64)
1243                         set(CMAKE_C_FLAGS_DEBUG "/Od /RTC1 /MTd /Zi /MP" CACHE STRING "MSVC MT flags " FORCE)
1244                 else()
1245                         set(CMAKE_C_FLAGS_DEBUG "/Od /RTC1 /MTd /ZI /MP" CACHE STRING "MSVC MT flags " FORCE)
1246                 endif()
1247                 set(CMAKE_C_FLAGS_RELEASE "/O2 /Ob2 /MT /MP" CACHE STRING "MSVC MT flags " FORCE)
1248                 set(CMAKE_C_FLAGS_MINSIZEREL "/O1 /Ob1 /MT /MP" CACHE STRING "MSVC MT flags " FORCE)
1249                 set(CMAKE_C_FLAGS_RELWITHDEBINFO "/O2 /Ob1 /MT /Zi /MP" CACHE STRING "MSVC MT flags " FORCE)
1250
1251
1252                 set(PLATFORM_LINKFLAGS "/SUBSYSTEM:CONSOLE /STACK:2097152 /INCREMENTAL:NO /NODEFAULTLIB:msvcrt.lib /NODEFAULTLIB:msvcmrt.lib /NODEFAULTLIB:msvcurt.lib /NODEFAULTLIB:msvcrtd.lib")
1253
1254                 # MSVC only, Mingw doesnt need
1255                 if(CMAKE_CL_64)
1256                         set(PLATFORM_LINKFLAGS "/MACHINE:X64 /OPT:NOREF ${PLATFORM_LINKFLAGS}")
1257                 else()
1258                         set(PLATFORM_LINKFLAGS "/MACHINE:IX86 /LARGEADDRESSAWARE ${PLATFORM_LINKFLAGS}")
1259                 endif()
1260
1261                 set(PLATFORM_LINKFLAGS_DEBUG "/IGNORE:4099 /NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:libc.lib")
1262
1263                 if(NOT DEFINED LIBDIR)
1264                         # Setup 64bit and 64bit windows systems
1265                         if(CMAKE_CL_64)
1266                                 message(STATUS "64 bit compiler detected.")
1267                                 set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/win64_vc12)
1268                         else()
1269                                 message(STATUS "32 bit compiler detected.")
1270                                 set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/windows_vc12)
1271                         endif()
1272                 else()
1273                         message(STATUS using LIBDIR  ${LIBDIR})
1274                 endif()
1275
1276                 # Add each of our libraries to our cmake_prefix_path so find_package() could work
1277                 file(GLOB children RELATIVE ${LIBDIR} ${LIBDIR}/*)
1278                 foreach(child ${children})
1279                 if(IS_DIRECTORY ${LIBDIR}/${child})
1280                         list(APPEND CMAKE_PREFIX_PATH  ${LIBDIR}/${child})
1281                 endif()
1282                 endforeach()
1283
1284                 set(ZLIB_INCLUDE_DIRS ${LIBDIR}/zlib/include)
1285                 set(ZLIB_LIBRARIES ${LIBDIR}/zlib/lib/libz_st.lib)
1286                 set(ZLIB_INCLUDE_DIR ${LIBDIR}/zlib/include)
1287                 set(ZLIB_LIBRARY ${LIBDIR}/zlib/lib/libz_st.lib)
1288                 set(ZLIB_DIR ${LIBDIR}/zlib)
1289                 #find_package(zlib) # we want to find before finding things that depend on it like png
1290
1291
1292                 find_package(png)
1293                 if(NOT PNG_FOUND)
1294                         message(WARNING "Using HARDCODED libpng locations")
1295                         set(PNG_PNG_INCLUDE_DIR ${LIBDIR}/png/include)
1296                         set(PNG_LIBRARIES libpng)
1297                         set(PNG "${LIBDIR}/png")
1298                         set(PNG_INCLUDE_DIRS "${PNG}/include")
1299                         set(PNG_LIBPATH ${PNG}/lib) # not cmake defined
1300                 endif()
1301
1302                 if(MSVC)
1303                         set(JPEG_NAMES ${JPEG_NAMES} libjpeg)
1304                 endif()
1305                 find_package(jpeg REQUIRED)
1306
1307                 set(PTHREADS_INCLUDE_DIRS ${LIBDIR}/pthreads/include)
1308                 set(PTHREADS_LIBRARIES ${LIBDIR}/pthreads/lib/pthreadVC2.lib)
1309
1310                 set(FREETYPE ${LIBDIR}/freetype)
1311                 set(FREETYPE_INCLUDE_DIRS
1312                         ${LIBDIR}/freetype/include
1313                         ${LIBDIR}/freetype/include/freetype2
1314                 )
1315                 set(FREETYPE_LIBRARY ${LIBDIR}/freetype/lib/freetype2ST.lib)
1316                 find_package(freetype REQUIRED)
1317
1318                 if(WITH_FFTW3)
1319                         set(FFTW3 ${LIBDIR}/fftw3)
1320                         set(FFTW3_LIBRARIES libfftw)
1321                         set(FFTW3_INCLUDE_DIRS ${FFTW3}/include)
1322                         set(FFTW3_LIBPATH ${FFTW3}/lib)
1323                 endif()
1324
1325                 if(WITH_OPENCOLLADA)
1326                         set(OPENCOLLADA ${LIBDIR}/opencollada)
1327
1328                         set(OPENCOLLADA_INCLUDE_DIRS
1329                                 ${OPENCOLLADA}/include/opencollada/COLLADAStreamWriter
1330                                 ${OPENCOLLADA}/include/opencollada/COLLADABaseUtils
1331                                 ${OPENCOLLADA}/include/opencollada/COLLADAFramework
1332                                 ${OPENCOLLADA}/include/opencollada/COLLADASaxFrameworkLoader
1333                                 ${OPENCOLLADA}/include/opencollada/GeneratedSaxParser
1334                         )
1335
1336                         set(OPENCOLLADA_LIBRARIES
1337                                 ${OPENCOLLADA}/lib/opencollada/OpenCOLLADASaxFrameworkLoader.lib
1338                                 ${OPENCOLLADA}/lib/opencollada/OpenCOLLADAFramework.lib
1339                                 ${OPENCOLLADA}/lib/opencollada/OpenCOLLADABaseUtils.lib
1340                                 ${OPENCOLLADA}/lib/opencollada/OpenCOLLADAStreamWriter.lib
1341                                 ${OPENCOLLADA}/lib/opencollada/MathMLSolver.lib
1342                                 ${OPENCOLLADA}/lib/opencollada/GeneratedSaxParser.lib
1343                                 ${OPENCOLLADA}/lib/opencollada/xml.lib
1344                                 ${OPENCOLLADA}/lib/opencollada/buffer.lib
1345                                 ${OPENCOLLADA}/lib/opencollada/ftoa.lib
1346                         )
1347
1348                         if(NOT WITH_LLVM)
1349                                 list(APPEND OPENCOLLADA_LIBRARIES ${OPENCOLLADA}/lib/opencollada/UTF.lib)
1350                         endif()
1351
1352                         set(PCRE_LIBRARIES
1353                                 ${OPENCOLLADA}/lib/opencollada/pcre.lib
1354                         )
1355                 endif()
1356
1357                 if(WITH_CODEC_FFMPEG)
1358                         set(FFMPEG_INCLUDE_DIRS
1359                                 ${LIBDIR}/ffmpeg/include
1360                                 ${LIBDIR}/ffmpeg/include/msvc
1361                         )
1362                         find_package(FFMPEG)
1363                         if(NOT FFMPEG_FOUND)
1364                                 message(WARNING "Using HARDCODED ffmpeg locations")
1365                                 set(FFMPEG_LIBRARY_VERSION 55)
1366                                 set(FFMPEG_LIBRARY_VERSION_AVU 52)
1367                                 set(FFMPEG_LIBRARIES
1368                                         ${LIBDIR}/ffmpeg/lib/avcodec-${FFMPEG_LIBRARY_VERSION}.lib
1369                                         ${LIBDIR}/ffmpeg/lib/avformat-${FFMPEG_LIBRARY_VERSION}.lib
1370                                         ${LIBDIR}/ffmpeg/lib/avdevice-${FFMPEG_LIBRARY_VERSION}.lib
1371                                         ${LIBDIR}/ffmpeg/lib/avutil-${FFMPEG_LIBRARY_VERSION_AVU}.lib
1372                                         ${LIBDIR}/ffmpeg/lib/swscale-2.lib
1373                                         )
1374                         endif()
1375                 endif()
1376
1377                 if(WITH_IMAGE_OPENEXR)
1378                         set(OPENEXR_ROOT_DIR ${LIBDIR}/openexr)
1379                         set(OPENEXR_VERSION "2.1")
1380                         find_package(OPENEXR REQUIRED)
1381                         if(NOT OPENEXR_FOUND)
1382                                 message(WARNING "Using HARDCODED OpenEXR locations")
1383                                 set(OPENEXR ${LIBDIR}/openexr)
1384                                 set(OPENEXR_INCLUDE_DIR ${OPENEXR}/include)
1385                                 set(OPENEXR_INCLUDE_DIRS ${OPENEXR}/include/OpenEXR)
1386                                 set(OPENEXR_LIBPATH ${OPENEXR}/lib)
1387                                 set(OPENEXR_LIBRARIES
1388                                         ${OPENEXR_LIBPATH}/Iex-2_2.lib
1389                                         ${OPENEXR_LIBPATH}/Half.lib
1390                                         ${OPENEXR_LIBPATH}/IlmImf-2_2.lib
1391                                         ${OPENEXR_LIBPATH}/Imath-2_2.lib
1392                                         ${OPENEXR_LIBPATH}/IlmThread-2_2.lib
1393                                 )
1394                         endif()
1395                 endif()
1396
1397                 if(WITH_IMAGE_TIFF)
1398                 # Try to find tiff first then complain and set static and maybe wrong paths
1399                 find_package(TIFF)
1400                 if(NOT TIFF_FOUND)
1401                         message(WARNING "Using HARDCODED libtiff locations")
1402                         set(TIFF_LIBRARY ${LIBDIR}/tiff/lib/libtiff.lib)
1403                         set(TIFF_INCLUDE_DIR ${LIBDIR}/tiff/include)
1404                 endif()
1405                 endif()
1406
1407                 if(WITH_JACK)
1408                         set(JACK_INCLUDE_DIRS
1409                                 ${LIBDIR}/jack/include/jack
1410                                 ${LIBDIR}/jack/include
1411                         )
1412                         set(JACK_LIBRARIES optimized ${LIBDIR}/jack/lib/libjack.lib debug ${LIBDIR}/jack/lib/libjack_d.lib)
1413                 endif()
1414
1415                 if(WITH_PYTHON)
1416                         set(PYTHON_VERSION 3.4) # CACHE STRING)
1417
1418                         string(REPLACE "." "" _PYTHON_VERSION_NO_DOTS ${PYTHON_VERSION})
1419                         # Use shared libs for vc2008 and vc2010 until we actually have vc2010 libs
1420                         set(PYTHON_LIBRARY ${LIBDIR}/python/lib/python${_PYTHON_VERSION_NO_DOTS}.lib)
1421                         unset(_PYTHON_VERSION_NO_DOTS)
1422
1423                         # Shared includes for both vc2008 and vc2010
1424                         set(PYTHON_INCLUDE_DIR ${LIBDIR}/python/include/python${PYTHON_VERSION})
1425
1426                         # uncached vars
1427                         set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}")
1428                         set(PYTHON_LIBRARIES  "${PYTHON_LIBRARY}")
1429                 endif()
1430
1431                 if(WITH_BOOST)
1432                         if(WITH_CYCLES_OSL)
1433                                 set(boost_extra_libs wave)
1434                         endif()
1435                         if(WITH_INTERNATIONAL)
1436                                 list(APPEND boost_extra_libs locale)
1437                         endif()
1438                         set(Boost_USE_STATIC_RUNTIME ON) # prefix lib
1439                         set(Boost_USE_MULTITHREADED ON) # suffix -mt
1440                         set(Boost_USE_STATIC_LIBS ON) # suffix -s
1441                         find_package(Boost COMPONENTS date_time filesystem thread regex system ${boost_extra_libs})
1442                         if(NOT Boost_FOUND)
1443                                 message(WARNING "USING HARDCODED boost locations")
1444                                 set(BOOST ${LIBDIR}/boost)
1445                                 set(BOOST_INCLUDE_DIR ${BOOST}/include)
1446                                 if(MSVC12)
1447                                         set(BOOST_LIBPATH ${BOOST}/lib)
1448                                         set(BOOST_POSTFIX "vc120-mt-s-1_55.lib")
1449                                         set(BOOST_DEBUG_POSTFIX "vc120-mt-sgd-1_55.lib")
1450                                 else()
1451                                         set(BOOST_LIBPATH ${BOOST}/lib)
1452                                         set(BOOST_POSTFIX "vc90-mt-s-1_49.lib")
1453                                         set(BOOST_DEBUG_POSTFIX "vc90-mt-sgd-1_49.lib")
1454                                 endif()
1455                                 set(BOOST_LIBRARIES
1456                                         optimized libboost_date_time-${BOOST_POSTFIX} optimized libboost_filesystem-${BOOST_POSTFIX}
1457                                         optimized libboost_regex-${BOOST_POSTFIX}
1458                                         optimized libboost_system-${BOOST_POSTFIX} optimized libboost_thread-${BOOST_POSTFIX}
1459                                         debug libboost_date_time-${BOOST_DEBUG_POSTFIX} debug libboost_filesystem-${BOOST_DEBUG_POSTFIX}
1460                                         debug libboost_regex-${BOOST_DEBUG_POSTFIX}
1461                                         debug libboost_system-${BOOST_DEBUG_POSTFIX} debug libboost_thread-${BOOST_DEBUG_POSTFIX})
1462                                 if(WITH_CYCLES_OSL)
1463                                         set(BOOST_LIBRARIES ${BOOST_LIBRARIES}
1464                                                 optimized libboost_wave-${BOOST_POSTFIX}
1465                                                 debug libboost_wave-${BOOST_DEBUG_POSTFIX})
1466                                 endif()
1467                                 if(WITH_INTERNATIONAL)
1468                                         set(BOOST_LIBRARIES ${BOOST_LIBRARIES}
1469                                                 optimized libboost_locale-${BOOST_POSTFIX}
1470                                                 debug libboost_locale-${BOOST_DEBUG_POSTFIX})
1471                                 endif()
1472                         else() # we found boost using find_package
1473                                 set(BOOST_INCLUDE_DIR ${Boost_INCLUDE_DIRS})
1474                                 set(BOOST_LIBRARIES ${Boost_LIBRARIES})
1475                                 set(BOOST_LIBPATH ${Boost_LIBRARY_DIRS})
1476                         endif()
1477                         set(BOOST_DEFINITIONS "-DBOOST_ALL_NO_LIB")
1478                 endif()
1479                         
1480                 if(WITH_OPENIMAGEIO)
1481                         find_package(OpenImageIO)
1482                         set(OPENIMAGEIO ${LIBDIR}/openimageio)
1483                         set(OPENIMAGEIO_INCLUDE_DIRS ${OPENIMAGEIO}/include)
1484                         set(OIIO_OPTIMIZED optimized OpenImageIO optimized OpenImageIO_Util)
1485                         set(OIIO_DEBUG debug OpenImageIO_d debug OpenImageIO_Util_d)
1486                         set(OPENIMAGEIO_LIBRARIES ${OIIO_OPTIMIZED} ${OIIO_DEBUG})
1487                         set(OPENIMAGEIO_LIBPATH ${OPENIMAGEIO}/lib)
1488                         set(OPENIMAGEIO_DEFINITIONS "-DUSE_TBB=0")
1489                         set(OPENCOLORIO_DEFINITIONS "-DOCIO_STATIC_BUILD")
1490                         set(OPENIMAGEIO_IDIFF "${OPENIMAGEIO}/bin/idiff.exe")
1491                         add_definitions(-DOIIO_STATIC_BUILD)
1492                 endif()
1493
1494                 if(WITH_LLVM)
1495                         set(LLVM_ROOT_DIR ${LIBDIR}/llvm CACHE PATH     "Path to the LLVM installation")
1496                         file(GLOB LLVM_LIBRARY_OPTIMIZED ${LLVM_ROOT_DIR}/lib/*.lib)
1497
1498                         if(EXISTS ${LLVM_ROOT_DIR}/debug/lib)
1499                                 foreach(LLVM_OPTIMIZED_LIB ${LLVM_LIBRARY_OPTIMIZED})
1500                                         get_filename_component(LIBNAME ${LLVM_OPTIMIZED_LIB} ABSOLUTE)
1501                                         list(APPEND LLVM_LIBS optimized ${LIBNAME})
1502                                 endforeach(LLVM_OPTIMIZED_LIB)
1503                         
1504                                 file(GLOB LLVM_LIBRARY_DEBUG ${LLVM_ROOT_DIR}/debug/lib/*.lib)
1505
1506                                 foreach(LLVM_DEBUG_LIB ${LLVM_LIBRARY_DEBUG})
1507                                         get_filename_component(LIBNAME ${LLVM_DEBUG_LIB} ABSOLUTE)
1508                                         list(APPEND LLVM_LIBS debug ${LIBNAME})
1509                                 endforeach(LLVM_DEBUG_LIB)
1510
1511                                 set(LLVM_LIBRARY ${LLVM_LIBS})
1512                         else()
1513                                 message(WARNING "LLVM debug libs not present on this system. Using release libs for debug builds.")
1514                                 set(LLVM_LIBRARY ${LLVM_LIBRARY_OPTIMIZED})
1515                         endif()
1516                         
1517                 endif()
1518         
1519                 if(WITH_OPENCOLORIO)
1520                         set(OPENCOLORIO ${LIBDIR}/opencolorio)
1521                         set(OPENCOLORIO_INCLUDE_DIRS ${OPENCOLORIO}/include)
1522                         set(OPENCOLORIO_LIBRARIES OpenColorIO)
1523                         set(OPENCOLORIO_LIBPATH ${LIBDIR}/opencolorio/lib)
1524                         set(OPENCOLORIO_DEFINITIONS)
1525                 endif()
1526                 
1527
1528                 if(WITH_MOD_CLOTH_ELTOPO)
1529                         set(LAPACK ${LIBDIR}/lapack)
1530                         # set(LAPACK_INCLUDE_DIR ${LAPACK}/include)
1531                         set(LAPACK_LIBPATH ${LAPACK}/lib)
1532                         set(LAPACK_LIBRARIES
1533                                 ${LIBDIR}/lapack/lib/libf2c.lib
1534                                 ${LIBDIR}/lapack/lib/clapack_nowrap.lib
1535                                 ${LIBDIR}/lapack/lib/BLAS_nowrap.lib
1536                         )
1537                 endif()
1538
1539                 if(WITH_OPENSUBDIV)
1540                         set(OPENSUBDIV_INCLUDE_DIR ${LIBDIR}/opensubdiv/include)
1541                         set(OPENSUBDIV_LIBPATH ${LIBDIR}/opensubdiv/lib)
1542                         set(OPENSUBDIV_LIBRARIES ${OPENSUBDIV_LIBPATH}/osdCPU.lib ${OPENSUBDIV_LIBPATH}/osdGPU.lib)
1543                         find_package(OpenSubdiv)
1544                 endif()
1545
1546                 if(WITH_SDL)
1547                         set(SDL ${LIBDIR}/sdl)
1548                         set(SDL_INCLUDE_DIR ${SDL}/include)
1549                         set(SDL_LIBRARY SDL2)
1550                         set(SDL_LIBPATH ${SDL}/lib)
1551                 endif()
1552
1553                 # used in many places so include globally, like OpenGL
1554                 blender_include_dirs_sys("${PTHREADS_INCLUDE_DIRS}")
1555
1556         elseif(CMAKE_COMPILER_IS_GNUCC)
1557                 # keep GCC specific stuff here
1558                 include(CheckCSourceCompiles)
1559                 # Setup 64bit and 64bit windows systems
1560                 CHECK_C_SOURCE_COMPILES("
1561                         #ifndef __MINGW64__
1562                         #error
1563                         #endif
1564                         int main(void) { return 0; }
1565                         " 
1566                         WITH_MINGW64)
1567                 
1568                 if(WITH_MINGW64)
1569                         message(STATUS "Compiling for 64 bit with MinGW-w64.")
1570                         execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
1571                         if(GCC_VERSION VERSION_GREATER 4.9 OR GCC_VERSION VERSION_EQUAL 4.9)
1572                                 set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/mingw64_gcc49)
1573                         else()
1574                                 set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/mingw64)
1575                         endif()
1576                 else()
1577                         message(STATUS "Compiling for 32 bit with MinGW-w32.")
1578                         set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/mingw32)
1579                         
1580                         if(WITH_RAYOPTIMIZATION)
1581                                 message(WARNING "MinGW-w32 is known to be unstable with 'WITH_RAYOPTIMIZATION' option enabled.")
1582                         endif()
1583                 endif()
1584                 
1585                 list(APPEND PLATFORM_LINKLIBS -lshell32 -lshfolder -lgdi32 -lmsvcrt -lwinmm -lmingw32 -lm -lws2_32 -lz -lstdc++ -lole32 -luuid -lwsock32 -lpsapi -ldbghelp)
1586
1587                 if(WITH_INPUT_IME)
1588                         list(APPEND PLATFORM_LINKLIBS -limm32)
1589                 endif()
1590
1591                 set(PLATFORM_CFLAGS "-pipe -funsigned-char -fno-strict-aliasing")
1592
1593                 if(WITH_MINGW64)
1594                         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive")
1595                         list(APPEND PLATFORM_LINKLIBS -lpthread)
1596                         
1597                         add_definitions(-DFREE_WINDOWS64 -DMS_WIN64)
1598                 endif()
1599
1600                 add_definitions(-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE)
1601
1602                 add_definitions(-DFREE_WINDOWS)
1603
1604                 set(PNG "${LIBDIR}/png")
1605                 set(PNG_INCLUDE_DIRS "${PNG}/include")
1606                 set(PNG_LIBPATH ${PNG}/lib) # not cmake defined
1607
1608                 if(WITH_MINGW64)
1609                         set(JPEG_LIBRARIES jpeg)
1610                 else()
1611                         set(JPEG_LIBRARIES libjpeg)
1612                 endif()
1613                 set(PNG_LIBRARIES png)
1614
1615                 set(ZLIB ${LIBDIR}/zlib)
1616                 set(ZLIB_INCLUDE_DIRS ${ZLIB}/include)
1617                 set(ZLIB_LIBPATH ${ZLIB}/lib)
1618                 set(ZLIB_LIBRARIES z)
1619
1620                 set(JPEG "${LIBDIR}/jpeg")
1621                 set(JPEG_INCLUDE_DIR "${JPEG}/include")
1622                 set(JPEG_LIBPATH ${JPEG}/lib) # not cmake defined
1623                 
1624                 # comes with own pthread library
1625                 if(NOT WITH_MINGW64)
1626                         set(PTHREADS ${LIBDIR}/pthreads)
1627                         #set(PTHREADS_INCLUDE_DIRS ${PTHREADS}/include)
1628                         set(PTHREADS_LIBPATH ${PTHREADS}/lib)
1629                         set(PTHREADS_LIBRARIES pthreadGC2)
1630                 endif()
1631                 
1632                 set(FREETYPE ${LIBDIR}/freetype)
1633                 set(FREETYPE_INCLUDE_DIRS ${FREETYPE}/include ${FREETYPE}/include/freetype2)
1634                 set(FREETYPE_LIBPATH ${FREETYPE}/lib)
1635                 set(FREETYPE_LIBRARY freetype)
1636
1637                 if(WITH_FFTW3)
1638                         set(FFTW3 ${LIBDIR}/fftw3)
1639                         set(FFTW3_LIBRARIES fftw3)
1640                         set(FFTW3_INCLUDE_DIRS ${FFTW3}/include)
1641                         set(FFTW3_LIBPATH ${FFTW3}/lib)
1642                 endif()
1643
1644                 if(WITH_OPENCOLLADA)
1645                         set(OPENCOLLADA ${LIBDIR}/opencollada)
1646                         set(OPENCOLLADA_INCLUDE_DIRS
1647                                 ${OPENCOLLADA}/include/opencollada/COLLADAStreamWriter
1648                                 ${OPENCOLLADA}/include/opencollada/COLLADABaseUtils
1649                                 ${OPENCOLLADA}/include/opencollada/COLLADAFramework
1650                                 ${OPENCOLLADA}/include/opencollada/COLLADASaxFrameworkLoader
1651                                 ${OPENCOLLADA}/include/opencollada/GeneratedSaxParser
1652                         )
1653                         set(OPENCOLLADA_LIBPATH ${OPENCOLLADA}/lib/opencollada)
1654                         set(OPENCOLLADA_LIBRARIES OpenCOLLADAStreamWriter OpenCOLLADASaxFrameworkLoader OpenCOLLADAFramework OpenCOLLADABaseUtils GeneratedSaxParser UTF MathMLSolver buffer ftoa xml)
1655                         set(PCRE_LIBRARIES pcre)
1656                 endif()
1657
1658                 if(WITH_CODEC_FFMPEG)
1659                         set(FFMPEG ${LIBDIR}/ffmpeg)
1660                         set(FFMPEG_INCLUDE_DIRS ${FFMPEG}/include)
1661                         if(WITH_MINGW64)
1662                                 set(FFMPEG_LIBRARIES avcodec.dll avformat.dll avdevice.dll avutil.dll swscale.dll swresample.dll)
1663                         else()
1664                                 set(FFMPEG_LIBRARIES avcodec-55 avformat-55 avdevice-55 avutil-52 swscale-2)
1665                         endif()
1666                         set(FFMPEG_LIBPATH ${FFMPEG}/lib)
1667                 endif()
1668
1669                 if(WITH_IMAGE_OPENEXR)
1670                         set(OPENEXR ${LIBDIR}/openexr)
1671                         set(OPENEXR_INCLUDE_DIR ${OPENEXR}/include)
1672                         set(OPENEXR_INCLUDE_DIRS ${OPENEXR}/include/OpenEXR)
1673                         set(OPENEXR_LIBRARIES Half IlmImf Imath IlmThread Iex)
1674                         set(OPENEXR_LIBPATH ${OPENEXR}/lib)
1675                 endif()
1676
1677                 if(WITH_IMAGE_TIFF)
1678                         set(TIFF ${LIBDIR}/tiff)
1679                         set(TIFF_LIBRARY tiff)
1680                         set(TIFF_INCLUDE_DIR ${TIFF}/include)
1681                         set(TIFF_LIBPATH ${TIFF}/lib)
1682                 endif()
1683
1684                 if(WITH_JACK)
1685                         set(JACK ${LIBDIR}/jack)
1686                         set(JACK_INCLUDE_DIRS ${JACK}/include/jack ${JACK}/include)
1687                         set(JACK_LIBRARIES jack)
1688                         set(JACK_LIBPATH ${JACK}/lib)
1689
1690                         # TODO, gives linking errors, force off
1691                         set(WITH_JACK OFF)
1692                 endif()
1693
1694                 if(WITH_PYTHON)
1695                         # normally cached but not since we include them with blender
1696                         set(PYTHON_VERSION 3.4) #  CACHE STRING)
1697                         string(REPLACE "." "" _PYTHON_VERSION_NO_DOTS ${PYTHON_VERSION})
1698                         set(PYTHON_INCLUDE_DIR "${LIBDIR}/python/include/python${PYTHON_VERSION}")  # CACHE PATH)
1699                         set(PYTHON_LIBRARY "${LIBDIR}/python/lib/python${_PYTHON_VERSION_NO_DOTS}mw.lib")  # CACHE FILEPATH)
1700                         unset(_PYTHON_VERSION_NO_DOTS)
1701
1702                         # uncached vars
1703                         set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}")
1704                         set(PYTHON_LIBRARIES  "${PYTHON_LIBRARY}")
1705                 endif()
1706
1707                 if(WITH_BOOST)
1708                         set(BOOST ${LIBDIR}/boost)
1709                         set(BOOST_INCLUDE_DIR ${BOOST}/include)
1710                         if(WITH_MINGW64)
1711                                 set(BOOST_POSTFIX "mgw47-mt-s-1_49")
1712                                 set(BOOST_DEBUG_POSTFIX "mgw47-mt-sd-1_49")
1713                         else()
1714                                 set(BOOST_POSTFIX "mgw46-mt-s-1_49")
1715                                 set(BOOST_DEBUG_POSTFIX "mgw46-mt-sd-1_49")
1716                         endif()
1717                         set(BOOST_LIBRARIES
1718                                 optimized boost_date_time-${BOOST_POSTFIX} boost_filesystem-${BOOST_POSTFIX}
1719                                 boost_regex-${BOOST_POSTFIX}
1720                                 boost_system-${BOOST_POSTFIX} boost_thread-${BOOST_POSTFIX}
1721                                 debug boost_date_time-${BOOST_DEBUG_POSTFIX} boost_filesystem-${BOOST_DEBUG_POSTFIX}
1722                                 boost_regex-${BOOST_DEBUG_POSTFIX}
1723                                 boost_system-${BOOST_DEBUG_POSTFIX} boost_thread-${BOOST_DEBUG_POSTFIX})
1724                         if(WITH_INTERNATIONAL)
1725                                 set(BOOST_LIBRARIES ${BOOST_LIBRARIES}
1726                                         optimized boost_locale-${BOOST_POSTFIX}
1727                                         debug boost_locale-${BOOST_DEBUG_POSTFIX}) 
1728                         endif()
1729                         if(WITH_CYCLES_OSL)
1730                                 set(BOOST_LIBRARIES ${BOOST_LIBRARIES}
1731                                         optimized boost_wave-${BOOST_POSTFIX}
1732                                         debug boost_wave-${BOOST_DEBUG_POSTFIX}) 
1733                         endif()
1734                         set(BOOST_LIBPATH ${BOOST}/lib)
1735                         set(BOOST_DEFINITIONS "-DBOOST_ALL_NO_LIB -DBOOST_THREAD_USE_LIB ")
1736                 endif()
1737                         
1738                 if(WITH_OPENIMAGEIO)
1739                         set(OPENIMAGEIO ${LIBDIR}/openimageio)
1740                         set(OPENIMAGEIO_INCLUDE_DIRS ${OPENIMAGEIO}/include)
1741                         set(OPENIMAGEIO_LIBRARIES OpenImageIO)
1742                         set(OPENIMAGEIO_LIBPATH ${OPENIMAGEIO}/lib)
1743                         set(OPENIMAGEIO_DEFINITIONS "")
1744                         set(OPENIMAGEIO_IDIFF "${OPENIMAGEIO}/bin/idiff.exe")
1745                 endif()
1746                 
1747                 if(WITH_LLVM)
1748                         set(LLVM_ROOT_DIR ${LIBDIR}/llvm CACHE PATH     "Path to the LLVM installation")
1749                         set(LLVM_LIBPATH ${LLVM_ROOT_DIR}/lib)
1750                         # Explicitly set llvm lib order.
1751                         #---- WARNING ON GCC ORDER OF LIBS IS IMPORTANT, DO NOT CHANGE! ---------
1752                         set(LLVM_LIBRARY LLVMSelectionDAG LLVMCodeGen LLVMScalarOpts LLVMAnalysis LLVMArchive
1753                                 LLVMAsmParser LLVMAsmPrinter
1754                                 LLVMBitReader LLVMBitWriter
1755                                 LLVMDebugInfo LLVMExecutionEngine
1756                                 LLVMInstCombine LLVMInstrumentation
1757                                 LLVMInterpreter LLVMJIT
1758                                 LLVMLinker LLVMMC
1759                                 LLVMMCDisassembler LLVMMCJIT
1760                                 LLVMMCParser LLVMObject
1761                                 LLVMRuntimeDyld 
1762                                 LLVMSupport
1763                                 LLVMTableGen LLVMTarget
1764                                 LLVMTransformUtils LLVMVectorize
1765                                 LLVMX86AsmParser LLVMX86AsmPrinter
1766                                 LLVMX86CodeGen LLVMX86Desc
1767                                 LLVMX86Disassembler LLVMX86Info
1768                                 LLVMX86Utils LLVMipa
1769                                 LLVMipo LLVMCore)
1770                         # imagehelp is needed by LLVM 3.1 on MinGW, check lib\Support\Windows\Signals.inc
1771                         list(APPEND PLATFORM_LINKLIBS -limagehlp)
1772                 endif()
1773                 
1774                 if(WITH_OPENCOLORIO)
1775                         set(OPENCOLORIO ${LIBDIR}/opencolorio)
1776                         set(OPENCOLORIO_INCLUDE_DIRS ${OPENCOLORIO}/include)
1777                         set(OPENCOLORIO_LIBRARIES OpenColorIO)
1778                         set(OPENCOLORIO_LIBPATH ${OPENCOLORIO}/lib)
1779                         set(OPENCOLORIO_DEFINITIONS)
1780                 endif()
1781
1782                 if(WITH_SDL)
1783                         set(SDL ${LIBDIR}/sdl)
1784                         set(SDL_INCLUDE_DIR ${SDL}/include)
1785                         set(SDL_LIBRARY SDL)
1786                         set(SDL_LIBPATH ${SDL}/lib)
1787                 endif()
1788
1789                 set(PLATFORM_LINKFLAGS "-Xlinker --stack=2097152")
1790
1791                 ## DISABLE - causes linking errors 
1792                 ## for re-distribution, so users dont need mingw installed
1793                 # set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -static-libgcc -static-libstdc++")
1794
1795         endif()
1796         
1797         # Things common to both mingw and MSVC  should go here
1798
1799         set(WINTAB_INC ${LIBDIR}/wintab/include)
1800
1801         if(WITH_OPENAL)
1802                 set(OPENAL ${LIBDIR}/openal)
1803                 set(OPENALDIR ${LIBDIR}/openal)
1804                 set(OPENAL_INCLUDE_DIR ${OPENAL}/include)
1805                 if(MSVC12)
1806                         set(OPENAL_LIBRARY openal32)
1807                 else()
1808                         set(OPENAL_LIBRARY wrap_oal)
1809                 endif()
1810                 set(OPENAL_LIBPATH ${OPENAL}/lib)
1811         endif()
1812
1813         if(WITH_CODEC_SNDFILE)
1814                 set(SNDFILE ${LIBDIR}/sndfile)
1815                 set(SNDFILE_INCLUDE_DIRS ${SNDFILE}/include)
1816                 set(SNDFILE_LIBRARIES libsndfile-1)
1817                 set(SNDFILE_LIBPATH ${SNDFILE}/lib) # TODO, deprecate
1818         endif()
1819
1820         if(WITH_RAYOPTIMIZATION AND SUPPORT_SSE_BUILD)
1821                 add_definitions(-D__SSE__ -D__MMX__)
1822         endif()
1823
1824         if(WITH_CYCLES_OSL)
1825                 set(CYCLES_OSL ${LIBDIR}/osl CACHE PATH "Path to OpenShadingLanguage installation")
1826         
1827                 find_library(OSL_LIB_EXEC NAMES oslexec PATHS ${CYCLES_OSL}/lib)
1828                 find_library(OSL_LIB_COMP NAMES oslcomp PATHS ${CYCLES_OSL}/lib)
1829                 find_library(OSL_LIB_QUERY NAMES oslquery PATHS ${CYCLES_OSL}/lib)
1830                 find_library(OSL_LIB_EXEC_DEBUG NAMES oslexec_d PATHS ${CYCLES_OSL}/lib)
1831                 find_library(OSL_LIB_COMP_DEBUG NAMES oslcomp_d PATHS ${CYCLES_OSL}/lib)
1832                 find_library(OSL_LIB_QUERY_DEBUG NAMES oslquery_d PATHS ${CYCLES_OSL}/lib)
1833                 list(APPEND OSL_LIBRARIES optimized ${OSL_LIB_COMP} optimized ${OSL_LIB_EXEC} optimized ${OSL_LIB_QUERY} debug ${OSL_LIB_EXEC_DEBUG} debug ${OSL_LIB_COMP_DEBUG} debug ${OSL_LIB_QUERY_DEBUG})
1834                 find_path(OSL_INCLUDE_DIR OSL/oslclosure.h PATHS ${CYCLES_OSL}/include)
1835                 find_program(OSL_COMPILER NAMES oslc PATHS ${CYCLES_OSL}/bin)
1836         
1837                 if(OSL_INCLUDE_DIR AND OSL_LIBRARIES AND OSL_COMPILER)
1838                         set(OSL_FOUND TRUE)
1839                 else()
1840                         message(STATUS "OSL not found")
1841                         set(WITH_CYCLES_OSL OFF)
1842                 endif()
1843         endif()
1844
1845 elseif(APPLE)
1846
1847         if(${CMAKE_OSX_DEPLOYMENT_TARGET} STREQUAL "10.5" OR ${CMAKE_OSX_DEPLOYMENT_TARGET} STRGREATER "10.5")
1848                 set(WITH_LIBS10.5 ON CACHE BOOL "Use 10.5 libs" FORCE) # valid also for 10.6/7/8/9
1849         endif()
1850
1851         if(WITH_LIBS10.5)
1852                 set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/darwin-9.x.universal)
1853         else()
1854                 if(CMAKE_OSX_ARCHITECTURES MATCHES i386)
1855                         set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/darwin-8.x.i386)
1856                 else()
1857                         set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/darwin-8.0.0-powerpc)
1858                 endif()
1859         endif()
1860
1861
1862         if(WITH_OPENAL)
1863                 find_package(OpenAL)
1864                 if(OPENAL_FOUND)
1865                         set(WITH_OPENAL ON)
1866                         set(OPENAL_INCLUDE_DIR "${LIBDIR}/openal/include")
1867                 else()
1868                         set(WITH_OPENAL OFF)
1869                 endif()
1870         endif()
1871
1872         if(WITH_OPENSUBDIV)
1873                 set(OPENSUBDIV ${LIBDIR}/opensubdiv)
1874                 set(OPENSUBDIV_LIBPATH ${OPENSUBDIV}/lib)
1875                 find_library(OSL_LIB_UTIL NAMES osdutil PATHS ${OPENSUBDIV_LIBPATH})
1876                 find_library(OSL_LIB_CPU NAMES osdCPU PATHS ${OPENSUBDIV_LIBPATH})
1877                 find_library(OSL_LIB_GPU NAMES osdGPU PATHS ${OPENSUBDIV_LIBPATH})
1878                 set(OPENSUBDIV_INCLUDE_DIR ${OPENSUBDIV}/include)
1879                 set(OPENSUBDIV_INCLUDE_DIRS ${OPENSUBDIV_INCLUDE_DIR})
1880                 list(APPEND OPENSUBDIV_LIBRARIES ${OSL_LIB_UTIL} ${OSL_LIB_CPU} ${OSL_LIB_GPU})
1881         endif()
1882
1883         if(WITH_JACK)
1884                 find_library(JACK_FRAMEWORK
1885                         NAMES jackmp
1886                 )
1887                 set(JACK_INCLUDE_DIRS ${JACK_FRAMEWORK}/headers)
1888                 if(NOT JACK_FRAMEWORK)
1889                         set(WITH_JACK OFF)
1890                 endif()
1891         endif()
1892
1893         if(WITH_CODEC_SNDFILE)
1894                 set(SNDFILE ${LIBDIR}/sndfile)
1895                 set(SNDFILE_INCLUDE_DIRS ${SNDFILE}/include)
1896                 set(SNDFILE_LIBRARIES sndfile FLAC ogg vorbis vorbisenc)
1897                 set(SNDFILE_LIBPATH ${SNDFILE}/lib ${FFMPEG}/lib)  # TODO, deprecate
1898         endif()
1899
1900         if(WITH_PYTHON)
1901                 # we use precompiled libraries for py 3.4 and up by default
1902                 set(PYTHON_VERSION 3.4)
1903                 if(NOT WITH_PYTHON_MODULE AND NOT WITH_PYTHON_FRAMEWORK)
1904                         # normally cached but not since we include them with blender
1905                         set(PYTHON_INCLUDE_DIR "${LIBDIR}/python/include/python${PYTHON_VERSION}m")
1906                         # set(PYTHON_EXECUTABLE "${LIBDIR}/python/bin/python${PYTHON_VERSION}") # not used yet
1907                         set(PYTHON_LIBRARY python${PYTHON_VERSION}m)
1908                         set(PYTHON_LIBPATH "${LIBDIR}/python/lib/python${PYTHON_VERSION}")
1909                         # set(PYTHON_LINKFLAGS "-u _PyMac_Error")  # won't  build with this enabled
1910                 else()
1911                         # module must be compiled against Python framework
1912                         set(PYTHON_INCLUDE_DIR "/Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}/include/python${PYTHON_VERSION}m")
1913                         set(PYTHON_EXECUTABLE "/Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}/bin/python${PYTHON_VERSION}")
1914                         #set(PYTHON_LIBRARY python${PYTHON_VERSION})
1915                         set(PYTHON_LIBPATH "/Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}/lib/python${PYTHON_VERSION}/config-${PYTHON_VERSION}m")
1916                         #set(PYTHON_LINKFLAGS "-u _PyMac_Error -framework Python")  # won't  build with this enabled
1917                 endif()
1918                 
1919                 # uncached vars
1920                 set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}")
1921                 set(PYTHON_LIBRARIES  "${PYTHON_LIBRARY}")
1922         endif()
1923
1924         if(WITH_FFTW3)
1925                 set(FFTW3 ${LIBDIR}/fftw3)
1926                 set(FFTW3_INCLUDE_DIRS ${FFTW3}/include)
1927                 set(FFTW3_LIBRARIES fftw3)
1928                 set(FFTW3_LIBPATH ${FFTW3}/lib)
1929         endif()
1930
1931         set(PNG_LIBRARIES png)
1932         set(JPEG_LIBRARIES jpeg)
1933
1934         set(ZLIB /usr)
1935         set(ZLIB_INCLUDE_DIRS "${ZLIB}/include")
1936         set(ZLIB_LIBRARIES z bz2)
1937
1938         set(FREETYPE ${LIBDIR}/freetype)
1939         set(FREETYPE_INCLUDE_DIRS ${FREETYPE}/include ${FREETYPE}/include/freetype2)
1940         set(FREETYPE_LIBPATH ${FREETYPE}/lib)
1941         set(FREETYPE_LIBRARY freetype)
1942
1943         if(WITH_IMAGE_OPENEXR)
1944                 set(OPENEXR ${LIBDIR}/openexr)
1945                 set(OPENEXR_INCLUDE_DIR ${OPENEXR}/include)
1946                 set(OPENEXR_INCLUDE_DIRS ${OPENEXR}/include/OpenEXR)
1947                 set(OPENEXR_LIBRARIES Iex Half IlmImf Imath IlmThread)
1948                 set(OPENEXR_LIBPATH ${OPENEXR}/lib)
1949         endif()
1950
1951         if(WITH_CODEC_FFMPEG)
1952                 set(FFMPEG ${LIBDIR}/ffmpeg)
1953                 set(FFMPEG_INCLUDE_DIRS ${FFMPEG}/include)
1954                 set(FFMPEG_LIBRARIES avcodec avdevice avformat avutil mp3lame swscale x264 xvidcore theora theoradec theoraenc vorbis vorbisenc vorbisfile ogg)
1955                 set(FFMPEG_LIBPATH ${FFMPEG}/lib)
1956         endif()
1957
1958         find_library(SYSTEMSTUBS_LIBRARY
1959                 NAMES
1960                 SystemStubs
1961                 PATHS
1962         )
1963         mark_as_advanced(SYSTEMSTUBS_LIBRARY)
1964         if(SYSTEMSTUBS_LIBRARY)
1965                 list(APPEND PLATFORM_LINKLIBS stdc++ SystemStubs)
1966         else()
1967                 list(APPEND PLATFORM_LINKLIBS stdc++)
1968         endif()
1969
1970         set(PLATFORM_CFLAGS "-pipe -funsigned-char")
1971         set(PLATFORM_LINKFLAGS "-fexceptions -framework CoreServices -framework Foundation -framework IOKit -framework AppKit -framework Cocoa -framework Carbon -framework AudioUnit -framework AudioToolbox -framework CoreAudio")
1972         if(WITH_CODEC_QUICKTIME)
1973                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -framework QTKit")
1974                 if(CMAKE_OSX_ARCHITECTURES MATCHES i386)
1975                         set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -framework QuickTime")
1976                         # libSDL still needs 32bit carbon quicktime
1977                 endif()
1978         endif()
1979
1980         # XXX - SOME MAC DEV PLEASE TEST WITH THE SDK INSTALLED!
1981         # ALSO SHOULD BE MOVED INTO OWN MODULE WHEN FUNCTIONAL
1982         if(WITH_INPUT_NDOF)
1983                 # This thread it *should* work and check the framework - campbell
1984                 # http://www.cmake.org/pipermail/cmake/2005-December/007740.html
1985                 find_library(3DCONNEXION_CLIENT_FRAMEWORK
1986                         NAMES 3DconnexionClient
1987                 )
1988                 if(NOT 3DCONNEXION_CLIENT_FRAMEWORK)
1989                         set(WITH_INPUT_NDOF OFF)
1990                 endif()
1991
1992                 if(WITH_INPUT_NDOF)
1993                         set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -F/Library/Frameworks -weak_framework 3DconnexionClient")
1994                         set(NDOF_INCLUDE_DIRS /Library/Frameworks/3DconnexionClient.framework/Headers )
1995                 endif()
1996         endif()
1997
1998         if(WITH_JACK)
1999                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -F/Library/Frameworks -weak_framework jackmp")
2000         endif()
2001         
2002         if(WITH_PYTHON_MODULE OR WITH_PYTHON_FRAMEWORK)
2003                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} /Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}/Python")# force cmake to link right framework
2004         endif()
2005         
2006         if(WITH_OPENCOLLADA)
2007                 set(OPENCOLLADA ${LIBDIR}/opencollada)
2008
2009                 set(OPENCOLLADA_INCLUDE_DIRS
2010                         ${LIBDIR}/opencollada/include/COLLADAStreamWriter
2011                         ${LIBDIR}/opencollada/include/COLLADABaseUtils
2012                         ${LIBDIR}/opencollada/include/COLLADAFramework
2013                         ${LIBDIR}/opencollada/include/COLLADASaxFrameworkLoader
2014                         ${LIBDIR}/opencollada/include/GeneratedSaxParser
2015                 )
2016
2017                 set(OPENCOLLADA_LIBPATH ${OPENCOLLADA}/lib)
2018                 set(OPENCOLLADA_LIBRARIES "OpenCOLLADASaxFrameworkLoader -lOpenCOLLADAFramework -lOpenCOLLADABaseUtils -lOpenCOLLADAStreamWriter -lMathMLSolver -lGeneratedSaxParser -lxml2 -lbuffer -lftoa")
2019                 # Use UTF functions from collada if LLVM is not enabled
2020                 if(NOT WITH_LLVM)
2021                         set(OPENCOLLADA_LIBRARIES "${OPENCOLLADA_LIBRARIES} -lUTF")
2022                 endif()
2023                 # pcre is bundled with openCollada
2024                 #set(PCRE ${LIBDIR}/pcre)
2025                 #set(PCRE_LIBPATH ${PCRE}/lib)
2026                 set(PCRE_LIBRARIES pcre)
2027                 #libxml2 is used
2028                 #set(EXPAT ${LIBDIR}/expat)
2029                 #set(EXPAT_LIBPATH ${EXPAT}/lib)
2030                 set(EXPAT_LIB)
2031         endif()
2032
2033         if(WITH_SDL)
2034                 set(SDL ${LIBDIR}/sdl)
2035                 set(SDL_INCLUDE_DIR ${SDL}/include)
2036                 set(SDL_LIBRARY SDL2)
2037                 set(SDL_LIBPATH ${SDL}/lib)
2038                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -lazy_framework ForceFeedback")
2039         endif()
2040
2041         set(PNG "${LIBDIR}/png")
2042         set(PNG_INCLUDE_DIRS "${PNG}/include")
2043         set(PNG_LIBPATH ${PNG}/lib)
2044
2045         set(JPEG "${LIBDIR}/jpeg")
2046         set(JPEG_INCLUDE_DIR "${JPEG}/include")
2047         set(JPEG_LIBPATH ${JPEG}/lib)
2048
2049         if(WITH_IMAGE_TIFF)
2050                 set(TIFF ${LIBDIR}/tiff)
2051                 set(TIFF_INCLUDE_DIR ${TIFF}/include)
2052                 set(TIFF_LIBRARY tiff)
2053                 set(TIFF_LIBPATH ${TIFF}/lib)
2054         endif()
2055
2056         if(WITH_INPUT_NDOF)
2057                 # linker needs "-weak_framework 3DconnexionClient"
2058         endif()
2059
2060         if(WITH_BOOST)
2061                 set(BOOST ${LIBDIR}/boost)
2062                 set(BOOST_INCLUDE_DIR ${BOOST}/include)
2063                 set(BOOST_LIBRARIES boost_date_time-mt boost_filesystem-mt boost_regex-mt boost_system-mt boost_thread-mt boost_wave-mt)
2064                 if(WITH_INTERNATIONAL)
2065                         list(APPEND BOOST_LIBRARIES boost_locale-mt)
2066                 endif()
2067                 if(WITH_CYCLES_NETWORK)
2068                         list(APPEND BOOST_LIBRARIES boost_serialization-mt)
2069                 endif()
2070                 set(BOOST_LIBPATH ${BOOST}/lib)
2071                 set(BOOST_DEFINITIONS)
2072         endif()
2073         
2074         if(WITH_INTERNATIONAL OR WITH_CODEC_FFMPEG)
2075                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -liconv") # boost_locale and ffmpeg needs it !
2076         endif()
2077
2078         if(WITH_OPENIMAGEIO)
2079                 set(OPENIMAGEIO ${LIBDIR}/openimageio)
2080                 set(OPENIMAGEIO_INCLUDE_DIRS ${OPENIMAGEIO}/include)
2081                 set(OPENIMAGEIO_LIBRARIES ${OPENIMAGEIO}/lib/libOpenImageIO.a ${PNG_LIBRARIES} ${JPEG_LIBRARIES} ${TIFF_LIBRARY} ${OPENEXR_LIBRARIES} ${ZLIB_LIBRARIES})
2082                 set(OPENIMAGEIO_LIBPATH ${OPENIMAGEIO}/lib ${JPEG_LIBPATH} ${PNG_LIBPATH} ${TIFF_LIBPATH} ${OPENEXR_LIBPATH} ${ZLIB_LIBPATH})
2083                 set(OPENIMAGEIO_DEFINITIONS "-DOIIO_STATIC_BUILD")
2084                 set(OPENIMAGEIO_IDIFF "${LIBDIR}/openimageio/bin/idiff")
2085         endif()
2086
2087         if(WITH_OPENCOLORIO)
2088                 set(OPENCOLORIO ${LIBDIR}/opencolorio)
2089                 set(OPENCOLORIO_INCLUDE_DIRS ${OPENCOLORIO}/include)
2090                 set(OPENCOLORIO_LIBRARIES OpenColorIO tinyxml yaml-cpp)
2091                 set(OPENCOLORIO_LIBPATH ${OPENCOLORIO}/lib)
2092         endif()
2093
2094         if(WITH_LLVM)
2095                 set(LLVM_ROOT_DIR ${LIBDIR}/llvm CACHE PATH     "Path to the LLVM installation")
2096                 set(LLVM_VERSION "3.4" CACHE STRING     "Version of LLVM to use")
2097                 if(EXISTS "${LLVM_ROOT_DIR}/bin/llvm-config")
2098                         set(LLVM_CONFIG "${LLVM_ROOT_DIR}/bin/llvm-config")
2099                 else()
2100                         set(LLVM_CONFIG llvm-config)
2101                 endif()
2102                 execute_process(COMMAND ${LLVM_CONFIG} --version
2103                                 OUTPUT_VARIABLE LLVM_VERSION
2104                                 OUTPUT_STRIP_TRAILING_WHITESPACE)
2105                 execute_process(COMMAND ${LLVM_CONFIG} --prefix
2106                                 OUTPUT_VARIABLE LLVM_ROOT_DIR
2107                                 OUTPUT_STRIP_TRAILING_WHITESPACE)
2108                 execute_process(COMMAND ${LLVM_CONFIG} --libdir
2109                                 OUTPUT_VARIABLE LLVM_LIBPATH
2110                                 OUTPUT_STRIP_TRAILING_WHITESPACE)
2111                 find_library(LLVM_LIBRARY
2112                              NAMES LLVMAnalysis # first of a whole bunch of libs to get
2113                              PATHS ${LLVM_LIBPATH})
2114
2115                 if(LLVM_LIBRARY AND LLVM_ROOT_DIR AND LLVM_LIBPATH)
2116                         if(LLVM_STATIC)
2117                                 # if static LLVM libraries were requested, use llvm-config to generate
2118                                 # the list of what libraries we need, and substitute that in the right
2119                                 # way for LLVM_LIBRARY.
2120                                 execute_process(COMMAND ${LLVM_CONFIG} --libfiles
2121                                                 OUTPUT_VARIABLE LLVM_LIBRARY
2122                                                 OUTPUT_STRIP_TRAILING_WHITESPACE)
2123                                 string(REPLACE " " ";" LLVM_LIBRARY ${LLVM_LIBRARY})
2124                         else()
2125                                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -lLLVM-3.4")
2126                         endif()
2127                 else()
2128                         message(FATAL_ERROR "LLVM not found.")
2129                 endif()
2130         endif()
2131
2132         if(WITH_CYCLES_OSL)
2133                 set(CYCLES_OSL ${LIBDIR}/osl CACHE PATH "Path to OpenShadingLanguage installation")
2134         
2135                 find_library(OSL_LIB_EXEC NAMES oslexec PATHS ${CYCLES_OSL}/lib)
2136                 find_library(OSL_LIB_COMP NAMES oslcomp PATHS ${CYCLES_OSL}/lib)
2137                 find_library(OSL_LIB_QUERY NAMES oslquery PATHS ${CYCLES_OSL}/lib)
2138                 # WARNING! depends on correct order of OSL libs linking
2139                 list(APPEND OSL_LIBRARIES ${OSL_LIB_COMP} -force_load ${OSL_LIB_EXEC} ${OSL_LIB_QUERY})
2140                 find_path(OSL_INCLUDE_DIR OSL/oslclosure.h PATHS ${CYCLES_OSL}/include)
2141                 find_program(OSL_COMPILER NAMES oslc PATHS ${CYCLES_OSL}/bin)
2142         
2143                 if(OSL_INCLUDE_DIR AND OSL_LIBRARIES AND OSL_COMPILER)
2144                         set(OSL_FOUND TRUE)
2145                 else()
2146                         message(STATUS "OSL not found")
2147                         set(WITH_CYCLES_OSL OFF)
2148                 endif()
2149         endif()
2150         
2151         if(WITH_OPENMP)
2152                 execute_process(COMMAND ${CMAKE_C_COMPILER} --version OUTPUT_VARIABLE COMPILER_VENDOR)
2153                 string(SUBSTRING "${COMPILER_VENDOR}" 0 5 VENDOR_NAME) # truncate output
2154                 if(${VENDOR_NAME} MATCHES "Apple") # Apple does not support OpenMP reliable with gcc and not with clang
2155                         set(WITH_OPENMP OFF)
2156                 else() # vanilla gcc or clang_omp support OpenMP
2157                         message(STATUS "Using special OpenMP enabled compiler !") # letting find_package(OpenMP) module work for gcc
2158                         if(CMAKE_C_COMPILER_ID MATCHES "Clang") # clang-omp in darwin libs
2159                                 set(OPENMP_FOUND ON)
2160                                 set(OpenMP_C_FLAGS "-fopenmp" CACHE STRING "C compiler flags for OpenMP parallization" FORCE)
2161                                 set(OpenMP_CXX_FLAGS "-fopenmp" CACHE STRING "C++ compiler flags for OpenMP parallization" FORCE)
2162                                 include_directories(${LIBDIR}/openmp/include)
2163                                 link_directories(${LIBDIR}/openmp/lib)
2164                                 # This is a workaround for our helperbinaries ( datatoc, masgfmt, ... ),
2165                                 # They are linked also to omp lib, so we need it in builddir for runtime exexcution, TODO: remove all unneeded dependencies from these
2166                                 execute_process(COMMAND ditto -arch ${CMAKE_OSX_ARCHITECTURES} ${LIBDIR}/openmp/lib/libiomp5.dylib ${CMAKE_BINARY_DIR}/Resources/lib/libiomp5.dylib) # for intermediate binaries, in respect to lib ID
2167                         endif()
2168                 endif()
2169         endif()
2170
2171         set(EXETYPE MACOSX_BUNDLE)
2172
2173         set(CMAKE_C_FLAGS_DEBUG "-fno-strict-aliasing -g")
2174         set(CMAKE_CXX_FLAGS_DEBUG "-fno-strict-aliasing -g")
2175         if(CMAKE_OSX_ARCHITECTURES MATCHES "x86_64" OR CMAKE_OSX_ARCHITECTURES MATCHES "i386")
2176                 set(CMAKE_CXX_FLAGS_RELEASE "-O2 -mdynamic-no-pic -msse -msse2 -msse3 -mssse3")
2177                 set(CMAKE_C_FLAGS_RELEASE "-O2 -mdynamic-no-pic  -msse -msse2 -msse3 -mssse3")
2178                 if(NOT CMAKE_C_COMPILER_ID MATCHES "Clang")
2179                         set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -ftree-vectorize  -fvariable-expansion-in-unroller")
2180                         set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -ftree-vectorize  -fvariable-expansion-in-unroller")
2181                 endif()
2182         else()
2183                 set(CMAKE_C_FLAGS_RELEASE "-mdynamic-no-pic -fno-strict-aliasing")
2184                 set(CMAKE_CXX_FLAGS_RELEASE "-mdynamic-no-pic -fno-strict-aliasing")
2185         endif()
2186
2187         if(${XCODE_VERSION} VERSION_EQUAL 5 OR ${XCODE_VERSION} VERSION_GREATER 5)
2188                 # Xcode 5 is always using CLANG, which has too low template depth of 128 for libmv
2189                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ftemplate-depth=1024")
2190         endif()
2191         # Get rid of eventually clashes, we export some symbols explicite as local
2192         set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -Xlinker -unexported_symbols_list -Xlinker ${CMAKE_SOURCE_DIR}/source/creator/osx_locals.map")
2193 endif()
2194
2195 #-----------------------------------------------------------------------------
2196 # Common.
2197
2198 if(APPLE OR WIN32)
2199         if(NOT EXISTS "${LIBDIR}/")
2200                 message(FATAL_ERROR "Apple and Windows require pre-compiled libs at: '${LIBDIR}'")
2201         endif()
2202 endif()
2203
2204 if(NOT WITH_FFTW3 AND WITH_MOD_OCEANSIM)
2205         message(FATAL_ERROR "WITH_MOD_OCEANSIM requires WITH_FFTW3 to be ON")
2206 endif()
2207
2208 if(WITH_CYCLES)
2209         if(NOT WITH_OPENIMAGEIO)
2210                 message(FATAL_ERROR "Cycles requires WITH_OPENIMAGEIO, the library may not have been found. Configure OIIO or disable WITH_CYCLES")
2211         endif()
2212         if(NOT WITH_BOOST)
2213                 message(FATAL_ERROR "Cycles requires WITH_BOOST, the library may not have been found. Configure BOOST or disable WITH_CYCLES")
2214         endif()
2215
2216         if(WITH_CYCLES_OSL)
2217                 if(NOT WITH_LLVM)
2218                         message(FATAL_ERROR "Cycles OSL requires WITH_LLVM, the library may not have been found. Configure LLVM or disable WITH_CYCLES_OSL")
2219                 endif()
2220         endif()
2221 endif()
2222
2223 if(WITH_INTERNATIONAL)
2224         if(NOT WITH_BOOST)
2225                 message(FATAL_ERROR "Internationalization requires WITH_BOOST, the library may not have been found. Configure BOOST or disable WITH_INTERNATIONAL")
2226         endif()
2227 endif()
2228
2229 # See TEST_SSE_SUPPORT() for how this is defined.
2230
2231 if(WITH_RAYOPTIMIZATION)
2232         if(SUPPORT_SSE_BUILD)
2233                 set(PLATFORM_CFLAGS " ${COMPILER_SSE_FLAG} ${PLATFORM_CFLAGS}")
2234                 add_definitions(-D__SSE__ -D__MMX__)
2235         endif()
2236         if(SUPPORT_SSE2_BUILD)
2237                 set(PLATFORM_CFLAGS " ${COMPILER_SSE2_FLAG} ${PLATFORM_CFLAGS}")
2238                 add_definitions(-D__SSE2__)
2239                 if(NOT SUPPORT_SSE_BUILD) # dont double up
2240                         add_definitions(-D__MMX__)
2241                 endif()
2242         endif()
2243 endif()
2244
2245
2246 # set the endian define
2247 if(MSVC)
2248         # for some reason this fails on msvc
2249         add_definitions(-D__LITTLE_ENDIAN__)
2250         
2251 # OSX-Note: as we do crosscompiling with specific set architecture,
2252 # endianess-detection and autosetting is counterproductive
2253 # so we just set endianess according CMAKE_OSX_ARCHITECTURES
2254
2255 elseif(CMAKE_OSX_ARCHITECTURES MATCHES i386 OR CMAKE_OSX_ARCHITECTURES MATCHES x86_64)
2256         add_definitions(-D__LITTLE_ENDIAN__)
2257 elseif(CMAKE_OSX_ARCHITECTURES MATCHES ppc OR CMAKE_OSX_ARCHITECTURES MATCHES ppc64)            
2258         add_definitions(-D__BIG_ENDIAN__)
2259         
2260 else()
2261         include(TestBigEndian)
2262         test_big_endian(_SYSTEM_BIG_ENDIAN)
2263         if(_SYSTEM_BIG_ENDIAN)
2264                 add_definitions(-D__BIG_ENDIAN__)
2265         else()
2266                 add_definitions(-D__LITTLE_ENDIAN__)
2267         endif()
2268         unset(_SYSTEM_BIG_ENDIAN)
2269 endif()
2270
2271
2272 if(WITH_IMAGE_OPENJPEG)
2273         if(WITH_SYSTEM_OPENJPEG)
2274                 # dealt with above
2275         else()
2276                 set(OPENJPEG_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/extern/libopenjpeg")
2277                 add_definitions(-DOPJ_STATIC)
2278         endif()
2279 endif()
2280
2281 if(WITH_IMAGE_REDCODE)
2282         set(REDCODE ${CMAKE_SOURCE_DIR}/extern)
2283         set(REDCODE_INC ${REDCODE})
2284 endif()
2285
2286 if(NOT WITH_SYSTEM_EIGEN3)
2287         set(EIGEN3_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/extern/Eigen3)
2288 endif()
2289
2290 #-----------------------------------------------------------------------------
2291 # Configure OpenGL.
2292
2293 find_package(OpenGL)
2294 blender_include_dirs_sys("${OPENGL_INCLUDE_DIR}")
2295
2296 if(WITH_GLU)
2297         list(APPEND BLENDER_GL_LIBRARIES "${OPENGL_glu_LIBRARY}")
2298         list(APPEND GL_DEFINITIONS -DWITH_GLU)
2299 endif()
2300
2301 if(WITH_SYSTEM_GLES)
2302         find_package_wrapper(OpenGLES)
2303 endif()
2304
2305 if(WITH_GL_PROFILE_COMPAT OR WITH_GL_PROFILE_CORE)
2306         list(APPEND BLENDER_GL_LIBRARIES "${OPENGL_gl_LIBRARY}")
2307
2308 elseif(WITH_GL_PROFILE_ES20)
2309         if(WITH_SYSTEM_GLES)
2310                 if(NOT OPENGLES_LIBRARY)
2311                         message(FATAL_ERROR "Unable to find OpenGL ES libraries.  Install them or disable WITH_SYSTEM_GLES.")
2312                 endif()
2313
2314                 list(APPEND BLENDER_GL_LIBRARIES OPENGLES_LIBRARY)
2315
2316         else()
2317                 set(OPENGLES_LIBRARY "" CACHE FILEPATH "OpenGL ES 2.0 library file")
2318                 mark_as_advanced(OPENGLES_LIBRARY)
2319
2320                 list(APPEND BLENDER_GL_LIBRARIES "${OPENGLES_LIBRARY}")
2321
2322                 if(NOT OPENGLES_LIBRARY)
2323                         message(FATAL_ERROR "To compile WITH_GL_EGL you need to set OPENGLES_LIBRARY to the file path of an OpenGL ES 2.0 library.")
2324                 endif()
2325
2326         endif()
2327
2328         if(WIN32)
2329                 # Setup paths to files needed to install and redistribute Windows Blender with OpenGL ES
2330
2331                 set(OPENGLES_DLL "" CACHE FILEPATH "OpenGL ES 2.0 redistributable DLL file")
2332                 mark_as_advanced(OPENGLES_DLL)
2333
2334                 if(NOT OPENGLES_DLL)
2335                         message(FATAL_ERROR "To compile WITH_GL_PROFILE_ES20 you need to set OPENGLES_DLL to the file path of an OpenGL ES 2.0 runtime dynamic link library (DLL).")
2336                 endif()
2337
2338                 if(WITH_GL_ANGLE)
2339                         list(APPEND GL_DEFINITIONS -DWITH_ANGLE)
2340
2341                         set(D3DCOMPILER_DLL "" CACHE FILEPATH "Direct3D Compiler redistributable DLL file (needed by ANGLE)")
2342
2343                         get_filename_component(D3DCOMPILER_FILENAME "${D3DCOMPILER_DLL}" NAME)
2344                         list(APPEND GL_DEFINITIONS "-DD3DCOMPILER=\"\\\"${D3DCOMPILER_FILENAME}\\\"\"")
2345
2346                         mark_as_advanced(D3DCOMPILER_DLL)
2347
2348                         if(D3DCOMPILER_DLL STREQUAL "")
2349                                 message(FATAL_ERROR "To compile WITH_GL_ANGLE you need to set D3DCOMPILER_DLL to the file path of a copy of the DirectX redistributable DLL file: D3DCompiler_46.dll")
2350                         endif()
2351
2352                 endif()
2353
2354         endif()
2355
2356 endif()
2357
2358 if(WITH_GL_EGL)
2359         list(APPEND GL_DEFINITIONS -DWITH_GL_EGL)
2360
2361         if(WITH_SYSTEM_GLES)
2362                 if(NOT OPENGLES_EGL_LIBRARY)
2363                         message(FATAL_ERROR "Unable to find OpenGL ES libraries.  Install them or disable WITH_SYSTEM_GLES.")
2364                 endif()
2365
2366                 list(APPEND BLENDER_GL_LIBRARIES OPENGLES_EGL_LIBRARY)
2367
2368         else()
2369                 set(OPENGLES_EGL_LIBRARY "" CACHE FILEPATH "EGL library file")
2370                 mark_as_advanced(OPENGLES_EGL_LIBRARY)
2371
2372                 list(APPEND BLENDER_GL_LIBRARIES "${OPENGLES_LIBRARY}" "${OPENGLES_EGL_LIBRARY}")
2373
2374                 if(NOT OPENGLES_EGL_LIBRARY)
2375                         message(FATAL_ERROR "To compile WITH_GL_EGL you need to set OPENGLES_EGL_LIBRARY to the file path of an EGL library.")
2376                 endif()
2377
2378         endif()
2379
2380         if(WIN32)
2381                 # Setup paths to files needed to install and redistribute Windows Blender with OpenGL ES
2382
2383                 set(OPENGLES_EGL_DLL "" CACHE FILEPATH "EGL redistributable DLL file")
2384                 mark_as_advanced(OPENGLES_EGL_DLL)
2385
2386                 if(NOT OPENGLES_EGL_DLL)
2387                         message(FATAL_ERROR "To compile WITH_GL_EGL you need to set OPENGLES_EGL_DLL to the file path of an EGL runtime dynamic link library (DLL).")
2388                 endif()
2389
2390         endif()
2391
2392 endif()
2393
2394 if(WITH_GL_PROFILE_COMPAT)
2395         list(APPEND GL_DEFINITIONS -DWITH_GL_PROFILE_COMPAT)
2396 endif()
2397
2398 if(WITH_GL_PROFILE_CORE)
2399         list(APPEND GL_DEFINITIONS -DWITH_GL_PROFILE_CORE)
2400 endif()
2401
2402 if(WITH_GL_PROFILE_ES20)
2403         list(APPEND GL_DEFINITIONS -DWITH_GL_PROFILE_ES20)
2404 endif()
2405
2406 if(WITH_GL_EGL)
2407         list(APPEND GL_DEFINITIONS -DWITH_EGL)
2408 endif()
2409
2410 #-----------------------------------------------------------------------------
2411 # Configure OpenMP.
2412 if(WITH_OPENMP)
2413         find_package(OpenMP)
2414         if(OPENMP_FOUND)
2415                 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
2416                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
2417         else()
2418                 set(WITH_OPENMP OFF)
2419         endif()
2420
2421         mark_as_advanced(
2422                 OpenMP_C_FLAGS
2423                 OpenMP_CXX_FLAGS
2424         )
2425 endif()
2426
2427 #-----------------------------------------------------------------------------
2428 # Configure GLEW
2429
2430 if(WITH_GLEW_MX)
2431         list(APPEND GL_DEFINITIONS -DWITH_GLEW_MX)
2432 endif()
2433
2434 if(WITH_SYSTEM_GLEW)
2435         find_package(GLEW)
2436
2437         # Note: There is an assumption here that the system GLEW is not a static library.
2438
2439         if(NOT GLEW_FOUND)
2440                 message(FATAL_ERROR "GLEW is required to build Blender. Install it or disable WITH_SYSTEM_GLEW.")
2441         endif()
2442
2443         if(WITH_GLEW_MX)
2444                 set(BLENDER_GLEW_LIBRARIES ${GLEW_MX_LIBRARY})
2445         else()
2446                 set(BLENDER_GLEW_LIBRARIES ${GLEW_LIBRARY})
2447         endif()
2448 else()
2449         if(WITH_GLEW_ES)
2450                 set(GLEW_INCLUDE_PATH "${CMAKE_SOURCE_DIR}/extern/glew-es/include")
2451
2452                 list(APPEND GL_DEFINITIONS -DGLEW_STATIC -DWITH_GLEW_ES)
2453
2454                 # These definitions remove APIs from glew.h, making GLEW smaller, and catching unguarded API usage
2455                 if(NOT WITH_GL_PROFILE_ES20)
2456                         # No ES functions are needed
2457                         list(APPEND GL_DEFINITIONS -DGLEW_NO_ES)
2458                 elseif(NOT (WITH_GL_PROFILE_CORE OR WITH_GL_PROFILE_COMPAT))
2459                         # ES is enabled, but the other functions are all disabled
2460                         list(APPEND GL_DEFINITIONS -DGLEW_ES_ONLY)
2461                 endif()
2462
2463                 if(WITH_GL_PROFILE_ES20)
2464                         if(WITH_GL_EGL)
2465                                 list(APPEND GL_DEFINITIONS -DGLEW_USE_LIB_ES20)
2466                         endif()
2467
2468                         # ToDo: This is an experiment to eliminate ES 1 symbols,
2469                         # GLEW doesn't really properly provide this level of control
2470                         # (for example, without modification it eliminates too many symbols)
2471                         # so there are lots of modifications to GLEW to make this work,
2472                         # and no attempt to make it work beyond Blender at this point.
2473                         list(APPEND GL_DEFINITIONS -DGL_ES_VERSION_1_0=0 -DGL_ES_VERSION_CL_1_1=0 -DGL_ES_VERSION_CM_1_1=0)
2474                 endif()
2475
2476                 if(WITH_GL_EGL)
2477                         list(APPEND GL_DEFINITIONS -DGLEW_INC_EGL)
2478                 endif()
2479
2480                 set(BLENDER_GLEW_LIBRARIES extern_glew_es bf_intern_glew_mx)
2481
2482         else()
2483                 set(GLEW_INCLUDE_PATH "${CMAKE_SOURCE_DIR}/extern/glew/include")
2484
2485                 list(APPEND GL_DEFINITIONS -DGLEW_STATIC)
2486
2487                 # This won't affect the non-experimental glew library, 
2488                 # but is used for conditional compilation elsewhere.
2489                 list(APPEND GL_DEFINITIONS -DGLEW_NO_ES)
2490
2491                 set(BLENDER_GLEW_LIBRARIES extern_glew)
2492
2493         endif()
2494
2495 endif()
2496
2497 if(NOT WITH_GLU)
2498         list(APPEND GL_DEFINITIONS -DGLEW_NO_GLU)
2499 endif()
2500
2501 #-----------------------------------------------------------------------------
2502 # Configure Bullet
2503
2504 if(WITH_BULLET AND WITH_SYSTEM_BULLET)
2505         find_package(Bullet)
2506         if(NOT BULLET_FOUND)
2507                 set(WITH_BULLET OFF)
2508         endif()
2509 else()
2510         set(BULLET_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/extern/bullet2/src")
2511         # set(BULLET_LIBRARIES "")
2512 endif()
2513
2514 #-----------------------------------------------------------------------------
2515 # Configure Python.
2516
2517 if(WITH_PYTHON_MODULE)
2518         add_definitions(-DPy_ENABLE_SHARED)
2519 endif()
2520
2521 #-----------------------------------------------------------------------------
2522 # Extra compile flags
2523
2524 if(CMAKE_COMPILER_IS_GNUCC)
2525
2526         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
2527         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_CAST_ALIGN -Wcast-align)
2528         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_DECLARATION_AFTER_STATEMENT -Werror=declaration-after-statement)
2529         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_IMPLICIT_FUNCTION_DECLARATION -Werror=implicit-function-declaration)
2530         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_RETURN_TYPE  -Werror=return-type)
2531         # system headers sometimes do this, disable for now, was: -Werror=strict-prototypes
2532         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_STRICT_PROTOTYPES  -Wstrict-prototypes)
2533         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_MISSING_PROTOTYPES -Wmissing-prototypes)
2534         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_CHAR_SUBSCRIPTS -Wno-char-subscripts)
2535         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
2536         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_POINTER_ARITH -Wpointer-arith)
2537         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNUSED_PARAMETER -Wunused-parameter)
2538         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_WRITE_STRINGS -Wwrite-strings)
2539         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_LOGICAL_OP -Wlogical-op)
2540         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNDEF -Wundef)
2541         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_INIT_SELF -Winit-self)  # needs -Wuninitialized
2542         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_NULL -Wnonnull)  # C only
2543         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_MISSING_INCLUDE_DIRS -Wmissing-include-dirs)
2544         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_DIV_BY_ZERO -Wno-div-by-zero)
2545         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_TYPE_LIMITS -Wtype-limits)
2546         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_FORMAT_SIGN -Wformat-signedness)
2547
2548         # gcc 4.2 gives annoying warnings on every file with this
2549         if(NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "4.3")
2550                 ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNINITIALIZED -Wuninitialized)
2551         endif()
2552
2553         # versions before gcc4.6 give many BLI_math warnings
2554         if(NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "4.6")
2555                 ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_REDUNDANT_DECLS       -Wredundant-decls)
2556                 ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_REDUNDANT_DECLS -Wredundant-decls)
2557         endif()
2558
2559         # disable because it gives warnings for printf() & friends.
2560         # ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_DOUBLE_PROMOTION -Wdouble-promotion -Wno-error=double-promotion)
2561
2562         if(NOT APPLE)
2563                 ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_ERROR_UNUSED_BUT_SET_VARIABLE -Wno-error=unused-but-set-variable)
2564         endif()
2565
2566         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ALL -Wall)
2567         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_INVALID_OFFSETOF -Wno-invalid-offsetof)
2568         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_SIGN_COMPARE -Wno-sign-compare)
2569         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_LOGICAL_OP -Wlogical-op)
2570         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_INIT_SELF -Winit-self)  # needs -Wuninitialized
2571         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_MISSING_INCLUDE_DIRS -Wmissing-include-dirs)
2572         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_DIV_BY_ZERO -Wno-div-by-zero)
2573         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_TYPE_LIMITS -Wtype-limits)
2574         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ERROR_RETURN_TYPE  -Werror=return-type)
2575         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ERROR_DECLARATION_AFTER_STATEMENT -Werror=declaration-after-statement)
2576         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ERROR_IMPLICIT_FUNCTION_DECLARATION -Werror=implicit-function-declaration)
2577         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_CHAR_SUBSCRIPTS -Wno-char-subscripts)
2578         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
2579         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_POINTER_ARITH -Wpointer-arith)
2580         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNUSED_PARAMETER -Wunused-parameter)
2581         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_WRITE_STRINGS -Wwrite-strings)
2582         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNDEF -Wundef)
2583         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_FORMAT_SIGN -Wformat-signedness)
2584
2585         # gcc 4.2 gives annoying warnings on every file with this
2586         if(NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "4.3")
2587                 ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNINITIALIZED -Wuninitialized)
2588         endif()
2589
2590         # causes too many warnings
2591         if(NOT APPLE)
2592                 ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNDEF -Wundef)
2593                 ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_MISSING_DECLARATIONS -Wmissing-declarations)
2594         endif()
2595
2596         # flags to undo strict flags
2597         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_DEPRECATED_DECLARATIONS -Wno-deprecated-declarations)
2598         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_PARAMETER        -Wno-unused-parameter)
2599
2600         if(NOT APPLE)
2601                 ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_ERROR_UNUSED_BUT_SET_VARIABLE -Wno-error=unused-but-set-variable)
2602         endif()
2603
2604 elseif(CMAKE_C_COMPILER_ID MATCHES "Clang")
2605
2606         if(APPLE AND WITH_OPENMP) # we need the Intel omp lib linked here to not fail all tests due presence of -fopenmp !
2607                 set(CMAKE_REQUIRED_FLAGS "-L${LIBDIR}/openmp/lib -liomp5") # these are only used for the checks
2608         endif()
2609
2610         # strange, clang complains these are not supported, but then yses them.
2611         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
2612         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_DECLARATION_AFTER_STATEMENT -Werror=declaration-after-statement)
2613         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_IMPLICIT_FUNCTION_DECLARATION -Werror=implicit-function-declaration)
2614         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_RETURN_TYPE  -Werror=return-type)
2615         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_AUTOLOGICAL_COMPARE -Wno-tautological-compare)
2616         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
2617         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_CHAR_SUBSCRIPTS -Wno-char-subscripts)
2618         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_STRICT_PROTOTYPES  -Wstrict-prototypes)
2619         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_MISSING_PROTOTYPES -Wmissing-prototypes)
2620         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNUSED_PARAMETER -Wunused-parameter)
2621
2622         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ALL -Wall)
2623         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_AUTOLOGICAL_COMPARE -Wno-tautological-compare)
2624         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_UNKNOWN_PRAGMAS     -Wno-unknown-pragmas)
2625         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_CHAR_SUBSCRIPTS     -Wno-char-subscripts)
2626         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_OVERLOADED_VIRTUAL  -Wno-overloaded-virtual)  # we get a lot of these, if its a problem a dev needs to look into it.
2627         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_SIGN_COMPARE        -Wno-sign-compare)
2628         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_INVALID_OFFSETOF    -Wno-invalid-offsetof)
2629
2630         # gives too many unfixable warnings
2631         # ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNUSED_MACROS      -Wunused-macros)
2632         # ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNUSED_MACROS          -Wunused-macros)
2633
2634         # flags to undo strict flags
2635         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_PARAMETER -Wno-unused-parameter)
2636         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_MACROS    -Wno-unused-macros)
2637
2638         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_MISSING_VARIABLE_DECLARATIONS -Wno-missing-variable-declarations)
2639         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_INCOMPAT_PTR_DISCARD_QUAL -Wno-incompatible-pointer-types-discards-qualifiers)
2640         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_FUNCTION -Wno-unused-function)
2641         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_INT_TO_VOID_POINTER_CAST -Wno-int-to-void-pointer-cast)
2642         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_MISSING_PROTOTYPES -Wno-missing-prototypes)
2643         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_DUPLICATE_ENUM -Wno-duplicate-enum)
2644         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_UNDEF -Wno-undef)
2645         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_MISSING_NORETURN -Wno-missing-noreturn)
2646
2647         ADD_CHECK_CXX_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS CXX_WARN_NO_UNUSED_PRIVATE_FIELD -Wno-unused-private-field)
2648         ADD_CHECK_CXX_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS CXX_WARN_NO_CXX11_NARROWING -Wno-c++11-narrowing)
2649         ADD_CHECK_CXX_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS CXX_WARN_NO_NON_VIRTUAL_DTOR -Wno-non-virtual-dtor)
2650         ADD_CHECK_CXX_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS CXX_WARN_NO_UNUSED_MACROS -Wno-unused-macros)
2651         ADD_CHECK_CXX_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS CXX_WARN_NO_REORDER -Wno-reorder)
2652
2653 elseif(CMAKE_C_COMPILER_ID MATCHES "Intel")
2654
2655         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
2656         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_POINTER_ARITH -Wpointer-arith)
2657         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
2658
2659         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ALL -Wall)
2660         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_INVALID_OFFSETOF -Wno-invalid-offsetof)
2661         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_SIGN_COMPARE -Wno-sign-compare)
2662
2663         # disable numbered, false positives
2664         set(C_WARNINGS "${C_WARNINGS} -wd188,186,144,913,556")
2665         set(CXX_WARNINGS "${CXX_WARNINGS} -wd188,186,144,913,556")
2666 elseif(CMAKE_C_COMPILER_ID MATCHES "MSVC")
2667         # most msvc warnings are C & C++
2668         set(_WARNINGS
2669                 # warning level:
2670                 "/W3"
2671                 "/w34062"  # switch statement contains 'default' but no 'case' labels
2672                 # disable:
2673                 "/wd4018"  # signed/unsigned mismatch
2674                 "/wd4065"  # switch statement contains 'default' but no 'case' labels
2675                 "/wd4127"  # conditional expression is constant
2676                 "/wd4181"  # qualifier applied to reference type; ignored
2677                 "/wd4200"  # zero-sized array in struct/union
2678                 "/wd4244"  # conversion from 'type1' to 'type2', possible loss of data
2679                 "/wd4267"  # conversion from 'size_t' to 'type', possible loss of data
2680                 "/wd4305"  # truncation from 'type1' to 'type2'
2681                 "/wd4800"  # forcing value to bool 'true' or 'false'
2682                 # errors:
2683                 "/we4013"  # 'function' undefined; assuming extern returning int
2684                 "/we4431"  # missing type specifier - int assumed
2685         )
2686
2687         string(REPLACE ";" " " _WARNINGS "${_WARNINGS}")
2688         set(C_WARNINGS "${_WARNINGS}")
2689         set(CXX_WARNINGS "${_WARNINGS}")
2690         unset(_WARNINGS)
2691 endif()
2692
2693 # ensure python header is found since detection can fail, this could happen
2694 # with _any_ library but since we used a fixed python version this tends to
2695 # be most problematic.
2696 if(WITH_PYTHON)
2697         if(NOT EXISTS "${PYTHON_INCLUDE_DIR}/Python.h")
2698                 message(FATAL_ERROR "Missing: \"${PYTHON_INCLUDE_DIR}/Python.h\",\n"
2699                                                         "Set the cache entry 'PYTHON_INCLUDE_DIR' to point "
2700                                                         "to a valid python include path. Containing "
2701                                                         "Python.h for python version \"${PYTHON_VERSION}\"")
2702         endif()
2703
2704         if(WIN32)
2705                 # pass, we have this in an archive to extract
2706         elseif(WITH_PYTHON_INSTALL AND WITH_PYTHON_INSTALL_NUMPY)
2707                 find_python_package(numpy)
2708         endif()
2709
2710         if(WIN32 OR APPLE)
2711                 # pass, we have this in lib/python/site-packages
2712         elseif(WITH_PYTHON_INSTALL_REQUESTS)
2713                 find_python_package(requests)
2714         endif()
2715 endif()
2716
2717 if(WITH_CPP11)
2718         if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
2719                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
2720         elseif(MSVC12)
2721                 # Nothing special is needed, C++11 features are available by default.
2722         else()
2723                 message(FATAL_ERROR "Compiler ${CMAKE_C_COMPILER_ID} is not supported for C++11 build yet")
2724         endif()
2725 endif()
2726
2727 # Include warnings first, so its possible to disable them with user defined flags
2728 # eg: -Wno-uninitialized
2729 set(CMAKE_C_FLAGS "${C_WARNINGS} ${CMAKE_C_FLAGS} ${PLATFORM_CFLAGS}")
2730 set(CMAKE_CXX_FLAGS "${CXX_WARNINGS} ${CMAKE_CXX_FLAGS} ${PLATFORM_CFLAGS}")
2731
2732 # defined above, platform spesific but shared names
2733 mark_as_advanced(
2734         CYCLES_OSL
2735         OSL_LIB_EXEC
2736         OSL_COMPILER
2737         OSL_LIB_COMP
2738         OSL_LIB_QUERY
2739         OSL_INCLUDE_DIR
2740 )
2741
2742 mark_as_advanced(
2743         LLVM_CONFIG
2744         LLVM_ROOT_DIR
2745         LLVM_LIBRARY
2746         LLVM_VERSION
2747 )
2748
2749 #-------------------------------------------------------------------------------
2750 # Global Defines
2751
2752 # better not set includes here but this debugging option is off by default.
2753 if(WITH_CXX_GUARDEDALLOC)
2754         include_directories(${CMAKE_SOURCE_DIR}/intern/guardedalloc)
2755         add_definitions(-DWITH_CXX_GUARDEDALLOC)
2756 endif()
2757
2758 if(WITH_ASSERT_ABORT)
2759         add_definitions(-DWITH_ASSERT_ABORT)
2760 endif()
2761
2762 # message(STATUS "Using CFLAGS: ${CMAKE_C_FLAGS}")
2763 # message(STATUS "Using CXXFLAGS: ${CMAKE_CXX_FLAGS}")
2764
2765 #-----------------------------------------------------------------------------
2766 # Libraries
2767
2768 if(WITH_GTESTS)
2769         include(GTestTesting)
2770 endif()
2771
2772 if(WITH_BLENDER OR WITH_PLAYER)
2773         add_subdirectory(intern)
2774         add_subdirectory(extern)
2775
2776         # source after intern and extern to gather all
2777         # internal and external library information first, for test linking
2778         add_subdirectory(source)
2779 elseif(WITH_CYCLES_STANDALONE)
2780         add_subdirectory(intern/cycles)
2781         add_subdirectory(extern/clew)
2782         add_subdirectory(extern/cuew)
2783         if(NOT WITH_SYSTEM_GLEW)
2784                 add_subdirectory(extern/glew)
2785         endif()
2786 endif()
2787
2788 #-----------------------------------------------------------------------------
2789 # Blender Application
2790 if(WITH_BLENDER)
2791         add_subdirectory(source/creator)
2792 endif()
2793
2794
2795 #-----------------------------------------------------------------------------
2796 # Blender Player
2797 if(WITH_PLAYER)
2798         add_subdirectory(source/blenderplayer)
2799 endif()
2800
2801
2802 #-----------------------------------------------------------------------------
2803 # Testing
2804 add_subdirectory(tests)
2805
2806
2807 #-----------------------------------------------------------------------------
2808 # CPack for generating packages
2809 include(build_files/cmake/packaging.cmake)
2810
2811
2812 #-----------------------------------------------------------------------------
2813 # Print Final Configuration
2814
2815 if(FIRST_RUN)
2816
2817         set(_config_msg "\nBlender Configuration\n=====================")
2818
2819         function(info_cfg_option
2820                 _setting
2821                 )
2822
2823                 set(_msg "  - ${_setting}")
2824                 string(LENGTH "${_msg}" _len)
2825                 while("32" GREATER "${_len}")
2826                         set(_msg "${_msg} ")
2827                          math(EXPR _len "${_len} + 1")
2828                 endwhile()
2829
2830                 set(_config_msg "${_config_msg}\n${_msg}${${_setting}}" PARENT_SCOPE)
2831         endfunction()
2832
2833         function(info_cfg_text
2834                 _text
2835                 )
2836
2837                 set(_config_msg "${_config_msg}\n\n  ${_text}" PARENT_SCOPE)
2838         endfunction()
2839
2840         message(STATUS "C Compiler:   \"${CMAKE_C_COMPILER_ID}\"")
2841         message(STATUS "C++ Compiler: \"${CMAKE_CXX_COMPILER_ID}\"")
2842
2843         info_cfg_text("Build Options:")
2844         info_cfg_option(WITH_GAMEENGINE)
2845         info_cfg_option(WITH_PLAYER)
2846         info_cfg_option(WITH_BULLET)
2847         info_cfg_option(WITH_IK_SOLVER)
2848         info_cfg_option(WITH_IK_ITASC)
2849         info_cfg_option(WITH_OPENCOLLADA)
2850         info_cfg_option(WITH_FFTW3)
2851         info_cfg_option(WITH_INTERNATIONAL)
2852         info_cfg_option(WITH_INPUT_NDOF)
2853         info_cfg_option(WITH_CYCLES)
2854         info_cfg_option(WITH_FREESTYLE)
2855         info_cfg_option(WITH_OPENCOLORIO)
2856
2857         info_cfg_text("Compiler Options:")
2858         info_cfg_option(WITH_BUILDINFO)
2859         info_cfg_option(WITH_OPENMP)
2860         info_cfg_option(WITH_RAYOPTIMIZATION)
2861
2862         info_cfg_text("System Options:")
2863         info_cfg_option(WITH_INSTALL_PORTABLE)
2864         info_cfg_option(WITH_X11_XF86VMODE)
2865         info_cfg_option(WITH_X11_XINPUT)
2866         info_cfg_option(WITH_MEM_JEMALLOC)
2867         info_cfg_option(WITH_MEM_VALGRIND)
2868         info_cfg_option(WITH_SYSTEM_GLEW)
2869         info_cfg_option(WITH_SYSTEM_OPENJPEG)
2870
2871         info_cfg_text("Image Formats:")
2872         info_cfg_option(WITH_OPENIMAGEIO)
2873         info_cfg_option(WITH_IMAGE_CINEON)
2874         info_cfg_option(WITH_IMAGE_DDS)
2875         info_cfg_option(WITH_IMAGE_HDR)
2876         info_cfg_option(WITH_IMAGE_OPENEXR)
2877         info_cfg_option(WITH_IMAGE_OPENJPEG)
2878         info_cfg_option(WITH_IMAGE_REDCODE)
2879         info_cfg_option(WITH_IMAGE_TIFF)
2880
2881         info_cfg_text("Audio:")
2882         info_cfg_option(WITH_OPENAL)
2883         info_cfg_option(WITH_SDL)
2884         info_cfg_option(WITH_SDL_DYNLOAD)
2885         info_cfg_option(WITH_JACK)
2886         info_cfg_option(WITH_JACK_DYNLOAD)
2887         info_cfg_option(WITH_CODEC_AVI)
2888         info_cfg_option(WITH_CODEC_FFMPEG)
2889         info_cfg_option(WITH_CODEC_SNDFILE)
2890
2891         info_cfg_text("Compression:")
2892         info_cfg_option(WITH_LZMA)
2893         info_cfg_option(WITH_LZO)
2894
2895         info_cfg_text("Python:")
2896         info_cfg_option(WITH_PYTHON_INSTALL)
2897         info_cfg_option(WITH_PYTHON_INSTALL_NUMPY)
2898         info_cfg_option(WITH_PYTHON_MODULE)
2899         info_cfg_option(WITH_PYTHON_SAFETY)
2900         if(APPLE)
2901                 info_cfg_option(WITH_PYTHON_FRAMEWORK)
2902         endif()
2903
2904         info_cfg_text("Modifiers:")
2905         info_cfg_option(WITH_MOD_BOOLEAN)
2906         info_cfg_option(WITH_MOD_REMESH)
2907         info_cfg_option(WITH_MOD_FLUID)
2908         info_cfg_option(WITH_MOD_OCEANSIM)
2909
2910         info_cfg_text("OpenGL:")
2911         info_cfg_option(WITH_GLEW_ES)
2912         info_cfg_option(WITH_GLU)
2913         info_cfg_option(WITH_GL_EGL)
2914         info_cfg_option(WITH_GL_PROFILE_COMPAT)
2915         info_cfg_option(WITH_GL_PROFILE_CORE)
2916         info_cfg_option(WITH_GL_PROFILE_ES20)
2917         if(WIN32)
2918                 info_cfg_option(WITH_GL_ANGLE)
2919         endif()
2920
2921         info_cfg_text("Other:")
2922         info_cfg_option(WITH_OPENNL)
2923
2924         # debug
2925         message(STATUS "HAVE_STDBOOL_H = ${HAVE_STDBOOL_H}")
2926
2927         info_cfg_text("")
2928
2929         message("${_config_msg}")
2930 endif()
2931
2932 if(0)
2933         print_all_vars()
2934 endif()
2935