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