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