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