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