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