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