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