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