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