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