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