Solve restriction of MinGW that users have to turn ffmpeg on for cmake.
[blender.git] / CMakeLists.txt
1 # -*- mode: cmake; indent-tabs-mode: t; -*-
2 # ***** BEGIN GPL LICENSE BLOCK *****
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software Foundation,
16 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 #
18 # The Original Code is Copyright (C) 2006, Blender Foundation
19 # All rights reserved.
20 #
21 # The Original Code is: all of this file.
22 #
23 # Contributor(s): Jacques Beaurain.
24 #
25 # ***** END GPL LICENSE BLOCK *****
26
27 #-----------------------------------------------------------------------------
28 # We don't allow in-source builds. This causes no end of troubles because
29 # all out-of-source builds will use the CMakeCache.txt file there and even
30 # build the libs and objects in it.
31
32 if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
33         if(NOT DEFINED WITH_IN_SOURCE_BUILD)
34                 message(FATAL_ERROR
35                         "CMake generation for blender is not allowed within the source directory!"
36                         "\n Remove the CMakeCache.txt file and try again from another folder, e.g.:"
37                         "\n "
38                         "\n rm CMakeCache.txt"
39                         "\n cd .."
40                         "\n mkdir cmake-make"
41                         "\n cd cmake-make"
42                         "\n cmake ../blender"
43                         "\n "
44                         "\n Alternately define WITH_IN_SOURCE_BUILD to force this option (not recommended!)"
45                 )
46         endif()
47 endif()
48
49 cmake_minimum_required(VERSION 2.8)
50
51 if(NOT EXECUTABLE_OUTPUT_PATH)
52         set(FIRST_RUN "TRUE")
53 endif()
54
55 # this starts out unset
56 list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/build_files/cmake/Modules")
57
58 # avoid having empty buildtype
59 set(CMAKE_BUILD_TYPE_INIT "Release")
60
61 # quiet output for Makefiles, 'make -s' helps too
62 # set_property(GLOBAL PROPERTY RULE_MESSAGES OFF)
63
64 # global compile definitions since add_definitions() adds for all.
65 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_DEBUG           DEBUG _DEBUG)
66 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_RELEASE         NDEBUG)
67 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_MINSIZEREL      NDEBUG)
68 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_RELWITHDEBINFO  NDEBUG)
69
70
71 #-----------------------------------------------------------------------------
72 # Set policy
73
74 # see "cmake --help-policy CMP0003"
75 # So library linking is more sane
76 cmake_policy(SET CMP0003 NEW)
77
78 # So BUILDINFO and BLENDERPATH strings are automatically quoted
79 cmake_policy(SET CMP0005 NEW)
80
81 # So syntax problems are errors
82 cmake_policy(SET CMP0010 NEW)
83
84 # Input directories must have CMakeLists.txt
85 cmake_policy(SET CMP0014 NEW)
86
87 #-----------------------------------------------------------------------------
88 # Load some macros.
89 include(build_files/cmake/macros.cmake)
90
91
92 #-----------------------------------------------------------------------------
93 # Initialize project.
94
95 blender_project_hack_pre()
96
97 project(Blender)
98
99 blender_project_hack_post()
100
101 enable_testing()
102
103 #-----------------------------------------------------------------------------
104 # Redirect output files
105
106 set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin CACHE INTERNAL "" FORCE )
107 set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib CACHE INTERNAL "" FORCE )
108
109 #-----------------------------------------------------------------------------
110 # Set default config options
111
112 get_blender_version()
113
114
115 # Blender internal features
116 option(WITH_BLENDER "Build blender (disable to build only the blender player)" ON)
117 mark_as_advanced(WITH_BLENDER)
118
119 option(WITH_INTERNATIONAL "Enable I18N (International fonts and text)" ON)
120
121 option(WITH_PYTHON        "Enable Embedded Python API  (only disable for development)" ON)
122 option(WITH_PYTHON_SECURITY "Disables execution of scripts within blend files by default (recommend to leave off)" OFF)
123 mark_as_advanced(WITH_PYTHON)  # dont want people disabling this unless they really know what they are doing.
124 mark_as_advanced(WITH_PYTHON_SECURITY)  # some distrobutions see this as a security issue, rather than have them patch it, make a build option.
125
126 option(WITH_PYTHON_SAFETY "Enable internal API error checking to track invalid data to prevent crash on access (at the expense of some effeciency, only enable for development)." OFF)
127 option(WITH_PYTHON_MODULE "Enable building as a python module (experimental, only enable for development)" OFF)
128 option(WITH_BUILDINFO     "Include extra build details (only disable for development & faster builds)" ON)
129 option(WITH_IK_ITASC      "Enable ITASC IK solver (only disable for development & for incompatible C++ compilers)" ON)
130 option(WITH_FFTW3         "Enable FFTW3 support (Used for smoke and audio effects)" OFF)
131 option(WITH_BULLET        "Enable Bullet (Physics Engine)" ON)
132 option(WITH_GAMEENGINE    "Enable Game Engine" ON)
133 option(WITH_PLAYER        "Build Player" OFF)
134
135 # GHOST Windowing Library Options
136 option(WITH_GHOST_DEBUG   "Enable debugging output for the GHOST library" OFF)
137 mark_as_advanced(WITH_GHOST_DEBUG)
138
139 option(WITH_GHOST_SDL    "Enable building blender against SDL for windowing rather then the native APIs" OFF)
140 mark_as_advanced(WITH_GHOST_SDL)
141
142 # Misc...
143 option(WITH_HEADLESS      "Build without graphical support (renderfarm, server mode only)" OFF)
144 mark_as_advanced(WITH_HEADLESS)
145
146 option(WITH_AUDASPACE    "Build with blenders audio library (only disable if you know what you're doing!)" ON)
147 mark_as_advanced(WITH_AUDASPACE)
148
149
150 # (unix defaults to OpenMP On)
151 if(UNIX AND NOT APPLE)
152         set(PLATFORM_DEFAULT ON)
153 else()
154         set(PLATFORM_DEFAULT OFF)
155 endif()
156 option(WITH_OPENMP        "Enable OpenMP (has to be supported by the compiler)" ${PLATFORM_DEFAULT})
157 unset(PLATFORM_DEFAULT)
158
159
160 if(UNIX AND NOT APPLE)
161         option(WITH_X11_XINPUT "Enable X11 Xinput (tablet support and unicode input)"   ON)
162         option(WITH_X11_XF86VMODE "Enable X11 video mode switching"     ON)
163         option(WITH_BUILTIN_GLEW "Use GLEW OpenGL wrapper library bundled with blender" ON)
164         option(WITH_XDG_USER_DIRS    "Build with XDG Base Directory Specification (only config and documents for now)" OFF)
165         mark_as_advanced(WITH_XDG_USER_DIRS)
166
167         # freebsd doesn't seems to support XDND
168         if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
169                 option(WITH_GHOST_XDND   "Enable drag'n'drop support on Linux using XDND protocol" ON)
170         endif()
171 else()
172         # not an option for other OS's
173         set(WITH_BUILTIN_GLEW ON)
174 endif()
175
176 # Modifiers
177 option(WITH_MOD_FLUID           "Enable Elbeem Modifier (Fluid Simulation)" ON)
178 option(WITH_MOD_SMOKE           "Enable Smoke Modifier (Smoke Simulation)" ON)
179 option(WITH_MOD_DECIMATE        "Enable Decimate Modifier" ON)
180 option(WITH_MOD_BOOLEAN         "Enable Boolean Modifier" ON)
181 option(WITH_MOD_REMESH          "Enable Remesh Modifier" ON)
182 option(WITH_MOD_CLOTH_ELTOPO    "Enable Experimental cloth solver" OFF)
183 mark_as_advanced(WITH_MOD_CLOTH_ELTOPO)
184 option(WITH_MOD_OCEANSIM        "Enable Ocean Modifier" OFF)
185
186 # Image format support
187 option(WITH_IMAGE_OPENEXR       "Enable OpenEXR Support (http://www.openexr.com)" ON)
188 option(WITH_IMAGE_OPENJPEG      "Enable OpenJpeg Support (http://www.openjpeg.org)" ON)
189 option(WITH_IMAGE_TIFF          "Enable LibTIFF Support" ON)
190 option(WITH_IMAGE_DDS           "Enable DDS Image Support" ON)
191 option(WITH_IMAGE_CINEON        "Enable CINEON and DPX Image Support" ON)
192 option(WITH_IMAGE_HDR           "Enable HDR Image Support" ON)
193 option(WITH_IMAGE_REDCODE       "Enable RedCode Image Support" OFF)
194 option(WITH_IMAGE_FRAMESERVER   "Enable image FrameServer Support for rendering" ON)
195
196 # Audio/Video format support
197 if(MINGW)
198         set(PLATFORM_DEFAULT ON)
199 else()
200         set(PLATFORM_DEFAULT OFF)
201 endif()
202 option(WITH_CODEC_FFMPEG        "Enable FFMPeg Support (http://ffmpeg.org)" ${PLATFORM_DEFAULT})
203 unset(PLATFORM_DEFAULT)
204
205 option(WITH_CODEC_SNDFILE       "Enable libsndfile Support (http://www.mega-nerd.com/libsndfile)" OFF)
206 if(APPLE OR (WIN32 AND NOT UNIX))
207         option(WITH_CODEC_QUICKTIME     "Enable Quicktime Support" OFF)
208 endif()
209
210 # 3D format support
211 # disable opencollada on non-apple unix because opencollada has no package for debian
212 option(WITH_OPENCOLLADA         "Enable OpenCollada Support (http://www.opencollada.org)"       OFF)
213
214 # Sound output
215 option(WITH_SDL           "Enable SDL for sound and joystick support" ON)
216 option(WITH_OPENAL        "Enable OpenAL Support (http://www.openal.org)" ON)
217 option(WITH_JACK          "Enable Jack Support (http://www.jackaudio.org)" OFF)
218
219 # Compression
220 option(WITH_LZO           "Enable fast LZO compression (used for pointcache)" ON)
221 option(WITH_LZMA          "Enable best LZMA compression, (used for pointcache)" ON)
222
223 # Camera/motion tracking
224 option(WITH_LIBMV         "Enable libmv structure from motion library" ON)
225
226 # Mesh boolean lib
227 option(WITH_CARVE         "Enable Carve library to handle mesh boolean operations" ON)
228
229 # Misc
230 option(WITH_INPUT_NDOF "Enable NDOF input devices (SpaceNavigator and friends)" ON)
231 option(WITH_RAYOPTIMIZATION     "Enable use of SIMD (SSE) optimizations for the raytracer" ON)
232 if(UNIX AND NOT APPLE)
233         option(WITH_INSTALL_PORTABLE "Install redistributeable runtime, otherwise install into CMAKE_INSTALL_PREFIX" ON)
234 endif()
235 option(WITH_PYTHON_INSTALL       "Copy system python into the blender install folder" ON)
236
237 # Cycles
238 option(WITH_CYCLES                                      "Enable cycles Render Engine" ON)
239 option(WITH_CYCLES_TEST                         "Build cycles test application" OFF)
240 option(WITH_CYCLES_CUDA_BINARIES        "Build cycles CUDA binaries" OFF)
241 set(CYCLES_CUDA_BINARIES_ARCH           sm_13 sm_20 sm_21 CACHE STRING "CUDA architectures to build binaries for")
242 mark_as_advanced(CYCLES_CUDA_BINARIES_ARCH)
243
244 # disable for now, but plan to support on all platforms eventually
245 option(WITH_MEM_JEMALLOC   "Enable malloc replacement (http://www.canonware.com/jemalloc)" OFF)
246 mark_as_advanced(WITH_MEM_JEMALLOC)
247
248 # Debug
249 option(WITH_CXX_GUARDEDALLOC "Enable GuardedAlloc for C++ memory allocation tracking (only enable for development)" OFF)
250 mark_as_advanced(WITH_CXX_GUARDEDALLOC)
251
252 option(WITH_ASSERT_ABORT "Call abort() when raising an assertion through BLI_assert()" OFF)
253 mark_as_advanced(WITH_ASSERT_ABORT)
254
255
256 if(APPLE)
257         if(NOT CMAKE_OSX_ARCHITECTURES)
258                 set(CMAKE_OSX_ARCHITECTURES x86_64 CACHE STRING
259                 "Choose the architecture you want to build Blender for: i386, x86_64 or ppc"
260                 FORCE)
261         endif()
262         
263         execute_process(COMMAND uname -r OUTPUT_VARIABLE MAC_SYS) # check for actual system-version
264         if (${MAC_SYS} MATCHES 11)
265                 set(OSX_SYSTEM 10.7)
266         elseif(${MAC_SYS} MATCHES 10)
267                 set(OSX_SYSTEM 10.6)
268         elseif(${MAC_SYS} MATCHES 9)
269                 set(OSX_SYSTEM 10.5)
270         else()
271                 set(OSX_SYSTEM unsupported)
272         endif()
273         message(STATUS "Detected system-version: " ${OSX_SYSTEM})
274         
275         if(NOT CMAKE_OSX_DEPLOYMENT_TARGET)
276                         set(CMAKE_OSX_DEPLOYMENT_TARGET "10.5" CACHE STRING "" FORCE) # 10.5 is our minimum target, if you have higher sdk, weak linking happens
277         endif()
278
279         if(${CMAKE_GENERATOR} MATCHES "Xcode")
280         
281                 ##### workaround for actual official cmake incompatibility with xcode 4.3 ##### 
282                 if(${XCODE_VERSION} MATCHES '') # cmake fails due looking for xcode in the wrong path, thus will be empty var
283                         message("Official cmake does not yet support Xcode 4.3, get a patched version here: http://www.jensverwiebe.de/Blender/CMake%202.8-7patched.zip")
284                 endif()
285                 ### end workaround for actual official cmake incompatibility with xcode 4.3 ### 
286                 
287                 if(${XCODE_VERSION} VERSION_EQUAL 4 OR ${XCODE_VERSION} VERSION_GREATER 4 AND ${XCODE_VERSION} VERSION_LESS 4.3)
288                         # Xcode 4 defaults to the Apple LLVM Compiler.
289                         # Override the default compiler selection because Blender only compiles with gcc up to xcode 4.2
290                         set(CMAKE_XCODE_ATTRIBUTE_GCC_VERSION "com.apple.compilers.llvmgcc42")
291                         message(STATUS "Setting compiler to: " ${CMAKE_XCODE_ATTRIBUTE_GCC_VERSION})
292                 endif()
293         else() # unix makefile generator does not fill XCODE_VERSION var, so we get it with a command
294                 execute_process(COMMAND xcodebuild -version OUTPUT_VARIABLE XCODE_VERS_BUILDNR )
295                 STRING(SUBSTRING ${XCODE_VERS_BUILDNR} 6 3 XCODE_VERSION) # truncate away build-nr
296         endif()
297         
298         message(STATUS "Detected Xcode-version: " ${XCODE_VERSION})
299         
300         option(WITH_COCOA         "Use Cocoa framework instead of deprecated Carbon" ON)
301         option(USE_QTKIT          "Use QtKit instead of Carbon quicktime (needed for having partial quicktime for 64bit)" OFF)
302         option(WITH_LIBS10.5  "Use 10.5 libs (needed for 64bit builds)" OFF)
303 endif()
304
305
306 #-----------------------------------------------------------------------------
307 # Check for conflicting/unsupported configurations
308
309 if(NOT WITH_BLENDER AND NOT WITH_PLAYER)
310         message(FATAL_ERROR "At least one of WITH_BLENDER or WITH_PLAYER must be enabled, nothing to do!")
311 endif()
312
313 if(NOT WITH_GAMEENGINE AND WITH_PLAYER)
314         message(FATAL_ERROR "WITH_PLAYER requires WITH_GAMEENGINE")
315 endif()
316
317 if(NOT WITH_AUDASPACE AND (WITH_OPENAL OR WITH_SDL OR WITH_JACK OR WITH_GAMEENGINE))
318         message(FATAL_ERROR "WITH_OPENAL/WITH_SDL/WITH_JACK/WITH_CODEC_FFMPEG/WITH_GAMEENGINE require WITH_AUDASPACE")
319 endif()
320
321 if(NOT WITH_SDL AND WITH_GHOST_SDL)
322         message(FATAL_ERROR "WITH_GHOST_SDL requires WITH_SDL to be ON")
323 endif()
324
325 if(WITH_IMAGE_REDCODE AND ((NOT WITH_IMAGE_OPENJPEG) OR (NOT WITH_CODEC_FFMPEG)))
326         message(FATAL_ERROR "WITH_IMAGE_REDCODE requires WITH_IMAGE_OPENJPEG and WITH_CODEC_FFMPEG")
327 endif()
328
329 # python module, needs some different options
330 if(WITH_PYTHON_MODULE AND WITH_PLAYER)
331         message(FATAL_ERROR "WITH_PYTHON_MODULE requires WITH_PLAYER to be OFF")
332 endif()
333
334 if(WITH_PYTHON_MODULE AND WITH_PYTHON_INSTALL)
335         message(FATAL_ERROR "WITH_PYTHON_MODULE requires WITH_PYTHON_INSTALL to be OFF")
336 endif()
337
338
339 if(NOT WITH_FFTW3 AND WITH_MOD_OCEANSIM)
340         message(FATAL_ERROR "WITH_MOD_OCEANSIM requires WITH_FFTW3 to be ON")
341 endif()
342
343 # may as well build python module without a UI
344 if(WITH_PYTHON_MODULE)
345         set(WITH_HEADLESS ON)
346 endif()
347
348 # auto enable openimageio for cycles
349 if(WITH_CYCLES)
350         set(WITH_OPENIMAGEIO ON)
351 endif()
352
353 # auto enable boost for cycles and carve
354 if(WITH_CYCLES OR WITH_CARVE)
355         set(WITH_BOOST ON)
356 endif()
357
358 # don't store paths to libs for portable distrobution
359 if(WITH_INSTALL_PORTABLE)
360         set(CMAKE_SKIP_BUILD_RPATH TRUE)
361 endif()
362
363 if(WITH_GHOST_SDL OR WITH_HEADLESS)
364         set(WITH_GHOST_XDND OFF)
365 endif()
366
367 if(MINGW)
368         if(WITH_CODEC_QUICKTIME)
369                 message(FATAL_ERROR "MINGW requires WITH_CODEC_QUICKTIME to be OFF "
370                                     "because it is currently unsupported, remove this "
371                                     "line if youre a developer who wants to add support.")
372         endif()
373 endif()
374
375 TEST_SSE_SUPPORT(COMPILER_SSE_FLAG COMPILER_SSE2_FLAG)
376
377
378 #-----------------------------------------------------------------------------
379 # Check for valid directories
380 # ... svn extern paths can be missing because of svn-git.
381
382 if(WITH_INTERNATIONAL)
383         if(NOT EXISTS "${CMAKE_SOURCE_DIR}/release/datafiles/locale")
384                 message(WARNING "Translation path '${CMAKE_SOURCE_DIR}/release/datafiles/locale' is missing, "
385                                                 "This is an 'svn external', which are known not to work with bridges to other version "
386                                                 "control systems, disabling 'WITH_INTERNATIONAL'.")
387                 set(WITH_INTERNATIONAL OFF)
388         endif()
389 endif()
390
391 if(WITH_PYTHON)
392         if(NOT EXISTS "${CMAKE_SOURCE_DIR}/release/scripts/addons")
393                 message(WARNING "Addons path '${CMAKE_SOURCE_DIR}/release/scripts/addons' is missing, "
394                                                 "This is an 'svn external', which are known not to work with bridges to other version "
395                                                 "control systems: * CONTINUING WITHOUT ADDONS *")
396         endif()
397 endif()
398
399 #-----------------------------------------------------------------------------
400 # Initialize un-cached vars, avoid unused warning
401
402 # linux only, not cached
403 set(WITH_BINRELOC OFF)
404
405 # MAXOSX only, set to avoid uninitialized
406 set(EXETYPE "")
407
408 # C/C++ flags
409 set(PLATFORM_CFLAGS)
410
411 # these are added to later on.
412 set(C_WARNINGS)
413 set(CXX_WARNINGS)
414
415 # for gcc -Wno-blah-blah
416 set(CC_REMOVE_STRICT_FLAGS)
417
418 # libraries to link the binary with passed to target_link_libraries()
419 # known as LLIBS to scons
420 set(PLATFORM_LINKLIBS "")
421
422 # Added to linker flags in setup_liblinks
423 # - CMAKE_EXE_LINKER_FLAGS
424 # - CMAKE_EXE_LINKER_FLAGS_DEBUG
425 set(PLATFORM_LINKFLAGS "")
426 set(PLATFORM_LINKFLAGS_DEBUG "")
427
428
429 # disabled for now, not supported
430 # option(WITH_WEBPLUGIN     "Enable Web Plugin (Unix only)" OFF)
431
432 # For alternate Python locations the commandline can be used to override detected/default cache settings, e.g:
433 # On Unix:
434 #   cmake ../blender \
435 #         -D PYTHON_VERSION=3.2 \
436 #         -D PYTHON_INCLUDE_DIR=/opt/py32/include/python3.2d \
437 #         -D PYTHON_LIBRARY=/opt/py32/lib/libpython3.2d.so
438 #
439 # On Macs:
440 #   cmake ../blender \
441 #         -D PYTHON_INCLUDE_DIR=/System/Library/Frameworks/Python.framework/Versions/3.2/include/python3.2 \
442 #         -D PYTHON_LIBPATH=/System/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/config \
443 #         -G Xcode
444 #
445 # When changing any of this remember to update the notes in doc/build_systems/cmake.txt
446
447 #-----------------------------------------------------------------------------
448 #Platform specifics
449
450 if(UNIX AND NOT APPLE)
451
452         # needed for ubuntu 11.04
453         if(EXISTS "/usr/lib/x86_64-linux-gnu")
454                 set(CMAKE_LIBRARY_PATH "/usr/lib/x86_64-linux-gnu;${CMAKE_LIBRARY_PATH}")
455         endif()
456
457         # set lib directory if it exists
458         if(CMAKE_SYSTEM_NAME MATCHES "Linux")
459                 if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
460                         set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/linux64)
461                 else()
462                         set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/linux)
463                 endif()
464
465                 if(NOT EXISTS ${LIBDIR})
466                         unset(LIBDIR)
467                 endif()
468         endif()
469
470         find_package(JPEG REQUIRED)
471         find_package(PNG REQUIRED)
472         find_package(ZLIB REQUIRED)
473         find_package(Freetype REQUIRED)
474
475         if(WITH_PYTHON)
476                 # No way to set py32. remove for now.
477                 # find_package(PythonLibs)
478
479                 # Use our own instead, since wothout py is such a rare case,
480                 # require this package
481                 find_package(PythonLibsUnix REQUIRED)
482         endif()
483
484
485         if(WITH_IMAGE_OPENEXR)
486                 find_package(OpenEXR)  # our own module
487                 if(NOT OPENEXR_FOUND)
488                         set(WITH_IMAGE_OPENEXR OFF)
489                 endif()
490         endif()
491
492         if(WITH_IMAGE_OPENJPEG)
493                 find_package(OpenJPEG)
494                 if(NOT OPENJPEG_FOUND)
495                         set(WITH_IMAGE_OPENJPEG OFF)
496                 endif()
497         endif()
498
499         if(WITH_IMAGE_TIFF)
500                 find_package(TIFF)
501                 if(NOT TIFF_FOUND)
502                         set(WITH_IMAGE_TIFF OFF)
503                 endif()
504         endif()
505
506         # Audio IO
507         if(WITH_OPENAL)
508                 find_package(OpenAL)
509                 if(NOT OPENAL_FOUND)
510                         set(WITH_OPENAL OFF)
511                 endif()
512         endif()
513
514         if(WITH_SDL)
515                 find_package(SDL)
516                 mark_as_advanced(
517                         SDLMAIN_LIBRARY
518                         SDL_INCLUDE_DIR
519                         SDL_LIBRARY
520                         SDL_LIBRARY_TEMP
521                 )
522                 # unset(SDLMAIN_LIBRARY CACHE)
523                 if(NOT SDL_FOUND)
524                         set(WITH_SDL OFF)
525                 endif()
526         endif()
527
528         if(WITH_JACK)
529                 find_package(Jack)
530                 if(NOT JACK_FOUND)
531                         set(WITH_JACK OFF)
532                 endif()
533         endif()
534
535         # Codecs
536         if(WITH_CODEC_SNDFILE)
537                 find_package(SndFile)
538                 if(NOT SNDFILE_FOUND)
539                         set(WITH_CODEC_SNDFILE OFF)
540                 endif()
541         endif()
542
543         if(WITH_CODEC_FFMPEG)
544                 # use lib dir if available and nothing else specified
545                 if(LIBDIR AND NOT FFMPEG)
546                         set(FFMPEG ${LIBDIR}/ffmpeg CACHE PATH "FFMPEG Directory")
547                         # XXX, some distros might need 'theoraenc theoradec' too
548                         set(FFMPEG_LIBRARIES avformat avcodec avutil avdevice swscale dirac_encoder mp3lame ogg orc-0.4 schroedinger-1.0 theora vorbis vorbisenc vpx x264 xvidcore faad asound CACHE STRING "FFMPEG Libraries")
549                 else()
550                         set(FFMPEG /usr CACHE PATH "FFMPEG Directory")
551                         set(FFMPEG_LIBRARIES avformat avcodec avutil avdevice swscale CACHE STRING "FFMPEG Libraries")
552                 endif()
553
554                 mark_as_advanced(FFMPEG)
555                 set(FFMPEG_INCLUDE_DIRS ${FFMPEG}/include)
556                 mark_as_advanced(FFMPEG_LIBRARIES)
557                 set(FFMPEG_LIBPATH ${FFMPEG}/lib)
558                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__STDC_CONSTANT_MACROS")
559         endif()
560
561         if(WITH_INTERNATIONAL)
562                 find_library(INTL_LIBRARY
563                         NAMES intl
564                         PATHS
565                         /sw/lib
566                 )
567
568                 find_library(ICONV_LIBRARY
569                         NAMES iconv
570                         PATHS
571                         /sw/lib
572                 )
573                 mark_as_advanced(
574                         ICONV_LIBRARY
575                         INTL_LIBRARY
576                 )
577
578                 if(INTL_LIBRARY AND ICONV_LIBRARY)
579                         set(GETTEXT_LIBRARIES ${INTL_LIBRARY} ${ICONV_LIBRARY})
580                 endif()
581         endif()
582
583         if(WITH_FFTW3)
584                 find_package(Fftw3)
585                 if(NOT FFTW3_FOUND)
586                         set(WITH_FFTW3 OFF)
587                 endif()
588         endif()
589
590         if(WITH_OPENCOLLADA)
591                 find_package(OpenCOLLADA)
592                 if(OPENCOLLADA_FOUND)
593                         find_package(XML2)
594                         find_package(PCRE)
595                 else()
596                         set(WITH_OPENCOLLADA OFF)
597                 endif()
598         endif()
599
600         if(WITH_MEM_JEMALLOC)
601                 find_package(JeMalloc)
602                 if(NOT JEMALLOC_FOUND)
603                         set(WITH_MEM_JEMALLOC OFF)
604                 endif()
605         endif()
606
607         if (WITH_INPUT_NDOF)
608                 find_package(Spacenav)
609                 if(NOT SPACENAV_FOUND)
610                         set(WITH_INPUT_NDOF OFF)
611                 endif()
612
613                 # use generic names within blenders buildsystem.
614                 if(SPACENAV_FOUND)
615                         set(NDOF_INCLUDE_DIRS ${SPACENAV_INCLUDE_DIRS})
616                         set(NDOF_LIBRARIES ${SPACENAV_LIBRARIES})
617                 endif()
618         endif()
619
620         if(WITH_BOOST)
621                 # uses in build instructions to override include and library variables
622                 if(NOT BOOST_CUSTOM)
623                         # use lib dir if available and nothing else specified
624                         if(LIBDIR AND NOT BOOST_ROOT)
625                                 set(BOOST_ROOT ${LIBDIR}/boost)
626                                 set(Boost_USE_MULTITHREADED OFF)
627                         else()
628                                 set(Boost_USE_MULTITHREADED ON)
629                         endif()
630                         find_package(Boost 1.34 COMPONENTS filesystem regex system thread)
631                         mark_as_advanced(Boost_DIR)  # why doesnt boost do this?
632                 endif()
633
634                 set(BOOST_INCLUDE_DIR ${Boost_INCLUDE_DIRS})
635                 set(BOOST_LIBRARIES ${Boost_LIBRARIES})
636                 set(BOOST_LIBPATH ${Boost_LIBRARY_DIRS})
637                 set(BOOST_DEFINITIONS "-DBOOST_ALL_NO_LIB")
638         endif()
639
640         if(WITH_OPENIMAGEIO)
641                 # use lib dir if available and nothing else specified
642                 if(LIBDIR AND NOT OPENIMAGEIO_ROOT_DIR)
643                         set(OPENIMAGEIO_ROOT_DIR ${LIBDIR}/oiio)
644                 endif()
645
646                 find_package(OpenImageIO)
647
648                 set(OPENIMAGEIO_LIBRARIES ${OPENIMAGEIO_LIBRARIES} ${PNG_LIBRARIES} ${JPEG_LIBRARIES} ${TIFF_LIBRARY} ${OPENEXR_LIBRARIES} ${ZLIB_LIBRARIES} ${BOOST_LIBRARIES})
649                 set(OPENIMAGEIO_LIBPATH)  # TODO, remove and reference the absolute path everywhere
650                 set(OPENIMAGEIO_DEFINITIONS)
651
652                 if(NOT OPENIMAGEIO_FOUND)
653                         set(WITH_OPENIMAGEIO OFF)
654                         set(WITH_CYCLES OFF)
655                         message(STATUS "OpenImageIO not found, disabling WITH_CYCLES")
656                 endif()
657         endif()
658
659         # OpenSuse needs lutil, ArchLinux not, for now keep, can avoid by using --as-needed
660         set(PLATFORM_LINKLIBS "-lutil -lc -lm -lpthread -lstdc++")
661
662         if((NOT WITH_HEADLESS) AND (NOT WITH_GHOST_SDL))
663                 find_package(X11 REQUIRED)
664                 find_path(X11_XF86keysym_INCLUDE_PATH X11/XF86keysym.h ${X11_INC_SEARCH_PATH})
665                 mark_as_advanced(X11_XF86keysym_INCLUDE_PATH)
666
667                 set(PLATFORM_LINKLIBS "${PLATFORM_LINKLIBS} ${X11_X11_LIB}")
668
669                 if(WITH_X11_XINPUT)
670                         set(PLATFORM_LINKLIBS "${PLATFORM_LINKLIBS} ${X11_Xinput_LIB}")
671                 endif()
672
673                 if(WITH_X11_XF86VMODE)
674                         # XXX, why dont cmake make this available?
675                         FIND_LIBRARY(X11_Xxf86vmode_LIB Xxf86vm   ${X11_LIB_SEARCH_PATH})
676                         mark_as_advanced(X11_Xxf86vmode_LIB)
677                         if(X11_Xxf86vmode_LIB)
678                                 set(PLATFORM_LINKLIBS "${PLATFORM_LINKLIBS} ${X11_Xxf86vmode_LIB}")
679                         else()
680                                 set(WITH_X11_XF86VMODE OFF)
681                         endif()
682                 endif()
683         endif()
684
685         if(CMAKE_SYSTEM_NAME MATCHES "Linux")
686                 if(NOT WITH_PYTHON_MODULE)
687                         # BSD's dont use libdl.so
688                 set(PLATFORM_LINKLIBS "${PLATFORM_LINKLIBS} -ldl")
689                         # binreloc is linux only
690                         set(BINRELOC_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/extern/binreloc/include)
691                         set(WITH_BINRELOC ON)
692                 endif()
693         endif()
694
695         set(PLATFORM_LINKFLAGS "-pthread")
696
697         # lfs on glibc, all compilers should use
698         add_definitions(-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE)
699
700         # GNU Compiler
701         if(CMAKE_COMPILER_IS_GNUCC)
702                 set(PLATFORM_CFLAGS "-pipe -fPIC -funsigned-char -fno-strict-aliasing")
703         # CLang is the same as GCC for now.
704         elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
705                 set(PLATFORM_CFLAGS "-pipe -fPIC -funsigned-char -fno-strict-aliasing")
706         # Solaris CC
707         elseif(CMAKE_CXX_COMPILER_ID MATCHES "SunPro") 
708                 set(PLATFORM_CFLAGS "-pipe -features=extensions -fPIC -D__FUNCTION__=__func__")
709                 
710         # Intel C++ Compiler
711         elseif(CMAKE_C_COMPILER_ID MATCHES "Intel")
712                 # think these next two are broken
713                 find_program(XIAR xiar)
714                 if(XIAR)
715                         set(CMAKE_AR "${XIAR}")
716                 endif()
717                 mark_as_advanced(XIAR)
718
719                 find_program(XILD xild)
720                 if(XILD)
721                         set(CMAKE_LINKER "${XILD}")
722                 endif()
723                 mark_as_advanced(XILD)
724
725                 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fp-model precise -prec_div -parallel")
726                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fp-model precise -prec_div -parallel")
727
728                 # set(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -diag-enable sc3")
729                 set(PLATFORM_CFLAGS "-pipe -fPIC -funsigned-char -fno-strict-aliasing")
730                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -static-intel")
731         endif()
732
733 elseif(WIN32)
734
735         # this file is included anyway when building under Windows with cl.exe
736         #  include(${CMAKE_ROOT}/Modules/Platform/Windows-cl.cmake)
737
738         set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/windows)
739
740         # Setup 64bit and 64bit windows systems
741         if(CMAKE_CL_64)
742                 message("64 bit compiler detected.")
743                 set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/win64)
744         endif()
745
746         add_definitions(-DWIN32)
747
748         if(WITH_INTERNATIONAL)
749                 set(ICONV ${LIBDIR}/iconv)
750                 set(ICONV_INCLUDE_DIRS ${ICONV}/include)
751                 set(ICONV_LIBRARIES iconv)
752                 set(ICONV_LIBPATH ${ICONV}/lib)
753         endif()
754
755         set(JPEG "${LIBDIR}/jpeg")
756         set(JPEG_INCLUDE_DIR "${JPEG}/include")
757         set(JPEG_LIBPATH ${JPEG}/lib) # not cmake defined
758
759         set(WINTAB_INC ${LIBDIR}/wintab/include)
760
761         if(WITH_OPENAL)
762                 set(OPENAL ${LIBDIR}/openal)
763                 set(OPENAL_INCLUDE_DIR ${OPENAL}/include)
764                 set(OPENAL_LIBRARY wrap_oal)
765                 set(OPENAL_LIBPATH ${OPENAL}/lib)
766         endif()
767
768         if(WITH_CODEC_SNDFILE)
769                 set(SNDFILE ${LIBDIR}/sndfile)
770                 set(SNDFILE_INCLUDE_DIRS ${SNDFILE}/include)
771                 set(SNDFILE_LIBRARIES libsndfile-1)
772                 set(SNDFILE_LIBPATH ${SNDFILE}/lib) # TODO, deprecate
773         endif()
774
775         if(WITH_SDL)
776                 set(SDL ${LIBDIR}/sdl)
777                 set(SDL_INCLUDE_DIR ${SDL}/include)
778                 set(SDL_LIBRARY SDL)
779                 set(SDL_LIBPATH ${SDL}/lib)
780         endif()
781
782         if(WITH_CODEC_QUICKTIME)
783                 set(QUICKTIME ${LIBDIR}/QTDevWin)
784                 set(QUICKTIME_INCLUDE_DIRS ${QUICKTIME}/CIncludes)
785                 set(QUICKTIME_LIBRARIES qtmlClient)
786                 set(QUICKTIME_LIBPATH ${QUICKTIME}/Libraries)
787         endif()
788
789         if(WITH_RAYOPTIMIZATION AND SUPPORT_SSE_BUILD)
790                 add_definitions(-D__SSE__ -D__MMX__)
791         endif()
792
793         if(MSVC)
794                 if(CMAKE_CL_64)
795                         set(PLATFORM_LINKLIBS ws2_32 vfw32 winmm kernel32 user32 gdi32 comdlg32 advapi32 shfolder shell32 ole32 oleaut32 uuid)
796                 else()
797                         set(PLATFORM_LINKLIBS ws2_32 vfw32 winmm kernel32 user32 gdi32 comdlg32 advapi32 shfolder shell32 ole32 oleaut32 uuid)
798                 endif()
799
800                 add_definitions(/D_CRT_NONSTDC_NO_DEPRECATE /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_CONSOLE /D_LIB)
801
802                 set(CMAKE_CXX_FLAGS "/nologo /J /W1 /Gd /wd4018 /wd4244 /wd4305 /wd4800 /wd4065 /wd4267 /we4013" CACHE STRING "MSVC MT C++ flags " FORCE)
803                 set(CMAKE_C_FLAGS   "/nologo /J /W1 /Gd /wd4018 /wd4244 /wd4305 /wd4800 /wd4065 /wd4267 /we4013 /EHsc" CACHE STRING "MSVC MT C++ flags " FORCE)
804
805                 if(CMAKE_CL_64)
806                         set(CMAKE_CXX_FLAGS_DEBUG "/Od /Gm /EHsc /RTC1 /MTd /W3 /nologo /Zi /J" CACHE STRING "MSVC MT flags " FORCE)
807                 else()
808                         set(CMAKE_CXX_FLAGS_DEBUG "/Od /Gm /EHsc /RTC1 /MTd /W3 /nologo /ZI /J" CACHE STRING "MSVC MT flags " FORCE)
809                 endif()
810                 set(CMAKE_CXX_FLAGS_RELEASE "/O2 /Ob2 /EHsc /MT /W3 /nologo /J" CACHE STRING "MSVC MT flags " FORCE)
811                 set(CMAKE_CXX_FLAGS_MINSIZEREL "/O1 /Ob1 /EHsc /MT /W3 /nologo /J" CACHE STRING "MSVC MT flags " FORCE)
812                 set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/O2 /Ob1 /EHsc /MT /W3 /nologo /Zi /J" CACHE STRING "MSVC MT flags " FORCE)
813                 if(CMAKE_CL_64)
814                         set(CMAKE_C_FLAGS_DEBUG "/Od /Gm /EHsc /RTC1 /MTd /W3 /nologo /Zi /J" CACHE STRING "MSVC MT flags " FORCE)
815                 else()
816                         set(CMAKE_C_FLAGS_DEBUG "/Od /Gm /EHsc /RTC1 /MTd /W3 /nologo /ZI /J" CACHE STRING "MSVC MT flags " FORCE)
817                 endif()
818                 set(CMAKE_C_FLAGS_RELEASE "/O2 /Ob2 /EHsc /MT /W3 /nologo /J" CACHE STRING "MSVC MT flags " FORCE)
819                 set(CMAKE_C_FLAGS_MINSIZEREL "/O1 /Ob1 /EHsc /MT /W3 /nologo /J" CACHE STRING "MSVC MT flags " FORCE)
820                 set(CMAKE_C_FLAGS_RELWITHDEBINFO "/O2 /Ob1 /EHsc /MT /W3 /nologo /Zi /J" CACHE STRING "MSVC MT flags " FORCE)
821
822                 if(WITH_INTERNATIONAL)
823                         set(GETTEXT ${LIBDIR}/gettext)
824                         set(GETTEXT_INCLUDE_DIRS ${GETTEXT}/include)
825                         set(GETTEXT_LIBPATH ${GETTEXT}/lib)
826                         set(GETTEXT_LIBRARIES gnu_gettext)
827                 endif()
828
829                 set(PNG_LIBRARIES libpng)
830                 set(JPEG_LIBRARIES libjpeg)
831                 
832                 set(PNG "${LIBDIR}/png")
833                 set(PNG_INCLUDE_DIR "${PNG}/include")
834                 set(PNG_LIBPATH ${PNG}/lib) # not cmake defined
835
836                 set(ZLIB_INCLUDE_DIRS ${LIBDIR}/zlib/include)
837                 if(CMAKE_CL_64)
838                         set(ZLIB_LIBRARIES ${LIBDIR}/zlib/lib/libz.lib)
839                 else()
840                         set(ZLIB_LIBRARIES ${LIBDIR}/zlib/lib/zlib.lib)
841                 endif()
842
843                 set(PTHREADS_INCLUDE_DIRS ${LIBDIR}/pthreads/include)
844                 set(PTHREADS_LIBRARIES ${LIBDIR}/pthreads/lib/pthreadVC2.lib)
845
846                 set(FREETYPE ${LIBDIR}/freetype)
847                 set(FREETYPE_INCLUDE_DIRS
848                         ${LIBDIR}/freetype/include
849                         ${LIBDIR}/freetype/include/freetype2
850                 )
851                 set(FREETYPE_LIBRARY ${LIBDIR}/freetype/lib/freetype2ST.lib)
852
853                 if(WITH_FFTW3)
854                         set(FFTW3 ${LIBDIR}/fftw3)
855                         set(FFTW3_LIBRARIES libfftw)
856                         set(FFTW3_INCLUDE_DIRS ${FFTW3}/include)
857                         set(FFTW3_LIBPATH ${FFTW3}/lib)
858                 endif()
859
860                 if(WITH_OPENCOLLADA)
861
862                         set(OPENCOLLADA_INCLUDE_DIRS
863                                 ${LIBDIR}/opencollada/include/COLLADAStreamWriter/include
864                                 ${LIBDIR}/opencollada/include/COLLADABaseUtils/include
865                                 ${LIBDIR}/opencollada/include/COLLADAFramework/include
866                                 ${LIBDIR}/opencollada/include/COLLADASaxFrameworkLoader/include
867                                 ${LIBDIR}/opencollada/include/GeneratedSaxParser/include
868                         )
869                         
870                         set_lib_path(OPENCOLLADA_LIBPATH "opencollada/lib")
871
872                         set(OPENCOLLADA_LIBRARIES
873                                 ${OPENCOLLADA_LIBPATH}/OpenCOLLADASaxFrameworkLoader.lib
874                                 ${OPENCOLLADA_LIBPATH}/OpenCOLLADAFramework.lib
875                                 ${OPENCOLLADA_LIBPATH}/OpenCOLLADABaseUtils.lib
876                                 ${OPENCOLLADA_LIBPATH}/OpenCOLLADAStreamWriter.lib
877                                 ${OPENCOLLADA_LIBPATH}/MathMLSolver.lib
878                                 ${OPENCOLLADA_LIBPATH}/GeneratedSaxParser.lib
879                                 ${OPENCOLLADA_LIBPATH}/xml2.lib
880                                 ${OPENCOLLADA_LIBPATH}/buffer.lib
881                                 ${OPENCOLLADA_LIBPATH}/ftoa.lib
882                                 ${OPENCOLLADA_LIBPATH}/UTF.lib
883                         )
884                         set(PCRE_LIBRARIES
885                                 ${OPENCOLLADA_LIBPATH}/pcre.lib
886                         )
887                         
888                         unset(OPENCOLLADA_LIBPATH)
889                         
890                 endif()
891
892                 if(WITH_CODEC_FFMPEG)
893                         set(FFMPEG_INCLUDE_DIRS
894                                 ${LIBDIR}/ffmpeg/include
895                                 ${LIBDIR}/ffmpeg/include/msvc
896                         )
897                         set(FFMPEG_LIBRARIES
898                                 ${LIBDIR}/ffmpeg/lib/avcodec-53.lib
899                                 ${LIBDIR}/ffmpeg/lib/avformat-53.lib
900                                 ${LIBDIR}/ffmpeg/lib/avdevice-53.lib
901                                 ${LIBDIR}/ffmpeg/lib/avutil-51.lib
902                                 ${LIBDIR}/ffmpeg/lib/swscale-2.lib
903                         )
904                 endif()
905
906                 if(WITH_IMAGE_OPENEXR)
907                         set_lib_path(OPENEXR "openexr")
908                         set_lib_path(OPENEXR_LIBPATH "openexr/lib")
909                         set(OPENEXR_LIBRARIES
910                                 ${OPENEXR_LIBPATH}/Iex.lib
911                                 ${OPENEXR_LIBPATH}/Half.lib
912                                 ${OPENEXR_LIBPATH}/IlmImf.lib
913                                 ${OPENEXR_LIBPATH}/Imath.lib
914                                 ${OPENEXR_LIBPATH}/IlmThread.lib
915                         )
916                         set_lib_path(OPENEXR_INCUDE "openexr/include")
917                         set(OPENEXR_INCLUDE_DIRS
918                                 ${OPENEXR_INCUDE}
919                                 ${OPENEXR_INCUDE}/IlmImf
920                                 ${OPENEXR_INCUDE}/Iex
921                                 ${OPENEXR_INCUDE}/Imath
922                         )
923                         unset(OPENEXR_INCUDE)
924                         unset(OPENEXR_LIBPATH)
925                 endif()
926
927                 if(WITH_IMAGE_TIFF)
928                         set(TIFF_LIBRARY ${LIBDIR}/tiff/lib/libtiff.lib)
929                         set(TIFF_INCLUDE_DIR ${LIBDIR}/tiff/include)
930                 endif()
931
932                 if(WITH_JACK)
933                         set(JACK_INCLUDE_DIRS
934                                 ${LIBDIR}/jack/include/jack
935                                 ${LIBDIR}/jack/include
936                         )
937                         set(JACK_LIBRARIES ${LIBDIR}/jack/lib/libjack.lib)
938                 endif()
939
940                 if(WITH_PYTHON)
941                         # normally cached but not since we include them with blender
942                         set(PYTHON_VERSION 3.2) # CACHE STRING)
943                         set_lib_path(PYTHON_INCLUDE_DIR "python/include/python${PYTHON_VERSION}")
944                         set_lib_path(PYTHON_LIBRARY "python/lib/python32.lib") #CACHE FILEPATH)
945                         
946                         # uncached vars
947                         set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}")
948                         set(PYTHON_LIBRARIES  "${PYTHON_LIBRARY}")
949                 endif()
950
951                 if(WITH_BOOST)
952                         set(BOOST ${LIBDIR}/boost)
953                         set(BOOST_INCLUDE_DIR ${BOOST}/include)
954                         if(MSVC10)
955                                 set(BOOST_POSTFIX "vc100-mt-s-1_47.lib")
956                                 set(BOOST_DEBUG_POSTFIX "vc100-mt-sgd-1_47.lib")
957                         else()
958                                 set(BOOST_POSTFIX "vc90-mt-s-1_47.lib")
959                                 set(BOOST_DEBUG_POSTFIX "vc90-mt-sgd-1_47.lib")                                 
960                         endif()
961                         set(BOOST_LIBRARIES
962                                 optimized libboost_date_time-${BOOST_POSTFIX} optimized libboost_filesystem-${BOOST_POSTFIX}
963                                 optimized libboost_regex-${BOOST_POSTFIX} optimized libboost_system-${BOOST_POSTFIX} optimized libboost_thread-${BOOST_POSTFIX}
964                                 debug libboost_date_time-${BOOST_DEBUG_POSTFIX} debug libboost_filesystem-${BOOST_DEBUG_POSTFIX}
965                                 debug libboost_regex-${BOOST_DEBUG_POSTFIX} debug libboost_system-${BOOST_DEBUG_POSTFIX} debug libboost_thread-${BOOST_DEBUG_POSTFIX})
966                         if(MSVC10)
967                                 set(BOOST_LIBPATH ${BOOST}/lib/vc_10)
968                         else()
969                                 set(BOOST_LIBPATH ${BOOST}/lib)
970                         endif()
971                         set(BOOST_DEFINITIONS "-DBOOST_ALL_NO_LIB")
972                 endif()
973                         
974                 if(WITH_OPENIMAGEIO)
975                         set(OPENIMAGEIO ${LIBDIR}/openimageio)
976                         set(OPENIMAGEIO_INCLUDE_DIRS ${OPENIMAGEIO}/include)
977                         set(OPENIMAGEIO_LIBRARIES OpenImageIO)
978                         set_lib_path(OPENIMAGEIO_LIBPATH "openimageio/lib")
979                         set(OPENIMAGEIO_DEFINITIONS)
980                 endif()
981
982                 set(PLATFORM_LINKFLAGS "/SUBSYSTEM:CONSOLE /STACK:2097152 /INCREMENTAL:NO /NODEFAULTLIB:msvcrt.lib /NODEFAULTLIB:msvcmrt.lib /NODEFAULTLIB:msvcurt.lib /NODEFAULTLIB:msvcrtd.lib")
983
984                 # MSVC only, Mingw doesnt need
985                 if(CMAKE_CL_64)
986                         set(PLATFORM_LINKFLAGS "/MACHINE:X64 /OPT:NOREF ${PLATFORM_LINKFLAGS}")
987                 else()
988                         set(PLATFORM_LINKFLAGS "/MACHINE:IX86 /LARGEADDRESSAWARE ${PLATFORM_LINKFLAGS}")
989                 endif()
990
991                 set(PLATFORM_LINKFLAGS_DEBUG "/NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:libc.lib")
992
993         else()
994                 # keep GCC specific stuff here
995                 if(CMAKE_COMPILER_IS_GNUCC)
996                         set(PLATFORM_LINKLIBS "-lshell32 -lshfolder -lgdi32 -lmsvcrt -lwinmm -lmingw32 -lm -lws2_32 -lz -lstdc++ -lole32 -luuid -lwsock32 -lpsapi")
997                         set(PLATFORM_CFLAGS "-pipe -funsigned-char -fno-strict-aliasing")
998
999                         add_definitions(-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE)
1000                 endif()
1001
1002                 add_definitions(-DFREE_WINDOWS)
1003
1004                 if(WITH_INTERNATIONAL)
1005                         set(GETTEXT ${LIBDIR}/gcc/gettext)
1006                         set(GETTEXT_INCLUDE_DIRS ${GETTEXT}/include)
1007                         set(GETTEXT_LIBPATH ${GETTEXT}/lib)
1008                         set(GETTEXT_LIBRARIES intl)
1009                 endif()
1010                 
1011                 set(PNG "${LIBDIR}/gcc/png")
1012                 set(PNG_INCLUDE_DIR "${PNG}/include")
1013                 set(PNG_LIBPATH ${PNG}/lib) # not cmake defined
1014
1015                 set(JPEG_LIBRARIES libjpeg)
1016                 set(PNG_LIBRARIES png)
1017
1018                 set(ZLIB ${LIBDIR}/zlib)
1019                 set(ZLIB_INCLUDE_DIRS ${ZLIB}/include)
1020                 set(ZLIB_LIBPATH ${ZLIB}/lib)
1021                 set(ZLIB_LIBRARIES z)
1022
1023                 set(PTHREADS ${LIBDIR}/pthreads)
1024                 set(PTHREADS_INCLUDE_DIRS ${PTHREADS}/include)
1025                 set(PTHREADS_LIBPATH ${PTHREADS}/lib)
1026                 set(PTHREADS_LIBRARIES pthreadGC2)
1027
1028                 set(FREETYPE ${LIBDIR}/gcc/freetype)
1029                 set(FREETYPE_INCLUDE_DIRS ${FREETYPE}/include ${FREETYPE}/include/freetype2)
1030                 set(FREETYPE_LIBPATH ${FREETYPE}/lib)
1031                 set(FREETYPE_LIBRARY freetype)
1032
1033                 if(WITH_FFTW3)
1034                         set(FFTW3 ${LIBDIR}/gcc/fftw3)
1035                         set(FFTW3_LIBRARIES fftw3)
1036                         set(FFTW3_INCLUDE_DIRS ${FFTW3}/include)
1037                         set(FFTW3_LIBPATH ${FFTW3}/lib)
1038                 endif()
1039
1040                 if(WITH_OPENCOLLADA)
1041                         set(OPENCOLLADA ${LIBDIR}/gcc/opencollada)
1042                         set(OPENCOLLADA_INCLUDE_DIRS
1043                                 ${LIBDIR}/gcc/opencollada/include/COLLADAStreamWriter/include
1044                                 ${LIBDIR}/gcc/opencollada/include/COLLADABaseUtils/include
1045                                 ${LIBDIR}/gcc/opencollada/include/COLLADAFramework/include
1046                                 ${LIBDIR}/gcc/opencollada/include/COLLADASaxFrameworkLoader/include
1047                                 ${LIBDIR}/gcc/opencollada/include/GeneratedSaxParser/include
1048                         )
1049                         set(OPENCOLLADA_LIBPATH ${OPENCOLLADA}/lib ${OPENCOLLADA}/lib)
1050                         set(OPENCOLLADA_LIBRARIES OpenCOLLADAStreamWriter OpenCOLLADASaxFrameworkLoader OpenCOLLADAFramework OpenCOLLADABaseUtils GeneratedSaxParser UTF MathMLSolver expat pcre buffer ftoa)
1051                         set(PCRE_LIBRARIES pcre)
1052                 endif()
1053
1054                 if(WITH_CODEC_FFMPEG)
1055                         set(FFMPEG ${LIBDIR}/ffmpeg)
1056                         set(FFMPEG_INCLUDE_DIRS ${FFMPEG}/include ${FFMPEG}/include)
1057                         set(FFMPEG_LIBRARIES avcodec-53 avformat-53 avdevice-53 avutil-51 swscale-2)
1058                         set(FFMPEG_LIBPATH ${FFMPEG}/lib)
1059                 endif()
1060
1061                 if(WITH_IMAGE_OPENEXR)
1062                         set(OPENEXR ${LIBDIR}/gcc/openexr)
1063                         set(OPENEXR_INCLUDE_DIRS ${OPENEXR}/include/OpenEXR)
1064                         set(OPENEXR_LIBRARIES Half IlmImf Imath IlmThread Iex)
1065                         set(OPENEXR_LIBPATH ${OPENEXR}/lib)
1066                 endif()
1067
1068                 if(WITH_IMAGE_TIFF)
1069                         set(TIFF ${LIBDIR}/gcc/tiff)
1070                         set(TIFF_LIBRARY tiff)
1071                         set(TIFF_INCLUDE_DIR ${TIFF}/include)
1072                         set(TIFF_LIBPATH ${TIFF}/lib)
1073                 endif()
1074
1075                 if(WITH_JACK)
1076                         set(JACK ${LIBDIR}/jack)
1077                         set(JACK_INCLUDE_DIRS ${JACK}/include/jack ${JACK}/include)
1078                         set(JACK_LIBRARIES jack)
1079                         set(JACK_LIBPATH ${JACK}/lib)
1080
1081                         # TODO, gives linking errors, force off
1082                         set(WITH_JACK OFF)
1083                 endif()
1084
1085                 if(WITH_PYTHON)
1086                         # normally cached but not since we include them with blender
1087                         set(PYTHON_VERSION 3.2) #  CACHE STRING)
1088                         set(PYTHON_INCLUDE_DIR "${LIBDIR}/python/include/python${PYTHON_VERSION}")  # CACHE PATH)
1089                         set(PYTHON_LIBRARY "${LIBDIR}/python/lib/python32mw.lib")  # CACHE FILEPATH)
1090
1091                         # uncached vars
1092                         set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}")
1093                         set(PYTHON_LIBRARIES  "${PYTHON_LIBRARY}")
1094                 endif()
1095
1096                 if(WITH_BOOST)
1097                         set(BOOST ${LIBDIR}/boost)
1098                         set(BOOST_INCLUDE_DIR ${BOOST}/include)
1099                         set(BOOST_POSTFIX "mgw46-mt-s-1_47")
1100                         set(BOOST_DEBUG_POSTFIX "mgw46-mt-sd-1_47")
1101                         set(BOOST_LIBRARIES
1102                                 optimized boost_date_time-${BOOST_POSTFIX} boost_filesystem-${BOOST_POSTFIX}
1103                                 boost_regex-${BOOST_POSTFIX} boost_system-${BOOST_POSTFIX} boost_thread-${BOOST_POSTFIX}
1104                                 debug boost_date_time-${BOOST_DEBUG_POSTFIX} boost_filesystem-${BOOST_DEBUG_POSTFIX}
1105                                 boost_regex-${BOOST_DEBUG_POSTFIX} boost_system-${BOOST_DEBUG_POSTFIX} boost_thread-${BOOST_DEBUG_POSTFIX})
1106                         set(BOOST_LIBPATH ${BOOST}/lib/gcc)
1107                         set(BOOST_DEFINITIONS "-DBOOST_ALL_NO_LIB -DBOOST_THREAD_USE_LIB ")
1108                 endif()
1109                         
1110                 if(WITH_OPENIMAGEIO)
1111                         set(OPENIMAGEIO ${LIBDIR}/gcc/openimageio)
1112                         set(OPENIMAGEIO_INCLUDE_DIRS ${OPENIMAGEIO}/include)
1113                         set(OPENIMAGEIO_LIBRARIES OpenImageIO)
1114                         set(OPENIMAGEIO_LIBPATH ${OPENIMAGEIO}/lib)
1115                         set(OPENIMAGEIO_DEFINITIONS)
1116                 endif()
1117                 
1118                 set(PLATFORM_LINKFLAGS "-Xlinker --stack=2097152")
1119
1120                 ## DISABLE - causes linking errors 
1121                 ## for re-distrobution, so users dont need mingw installed
1122                 # set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -static-libgcc -static-libstdc++")
1123
1124         endif()
1125
1126         # used in many places so include globally, like OpenGL
1127         blender_include_dirs("${PTHREADS_INCLUDE_DIRS}")
1128
1129 elseif(APPLE)
1130
1131         if(${CMAKE_OSX_DEPLOYMENT_TARGET} STREQUAL "10.5" OR ${CMAKE_OSX_DEPLOYMENT_TARGET} STRGREATER "10.5")
1132                 set(WITH_LIBS10.5 ON CACHE BOOL "Use 10.5 libs" FORCE) # valid also for 10.6/10.7
1133         endif()
1134
1135         if(${XCODE_VERSION} VERSION_LESS 4.3)
1136                 SET(CMAKE_OSX_SYSROOT /Developer/SDKs/MacOSX${OSX_SYSTEM}.sdk CACHE PATH "" FORCE ) # use guaranteed existing sdk
1137         else()
1138                 # note: i don't use xcode-select path on purpose, cause also /Applications/Xcode.app would be allowed
1139                 # absolute pathes are more foolproof here !
1140                 SET(OSX_SYSROOT_PREFIX /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform)
1141                 SET(OSX_DEVELOPER_PREFIX /Developer/SDKs/MacOSX${OSX_SYSTEM}.sdk) # use guaranteed existing sdk
1142                 SET(CMAKE_OSX_SYSROOT ${OSX_SYSROOT_PREFIX}/${OSX_DEVELOPER_PREFIX} CACHE PATH "" FORCE)
1143         endif() 
1144         
1145         if(WITH_LIBS10.5)
1146                 set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/darwin-9.x.universal)
1147         else()
1148                 if(CMAKE_OSX_ARCHITECTURES MATCHES i386)
1149                         set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/darwin-8.x.i386)
1150                 else()
1151                         set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/darwin-8.0.0-powerpc)
1152                 endif()
1153         endif()
1154
1155
1156         if(WITH_OPENAL)
1157                 find_package(OpenAL)
1158                 if(OPENAL_FOUND)
1159                         set(WITH_OPENAL ON)
1160                         set(OPENAL_INCLUDE_DIR "${LIBDIR}/openal/include")
1161                 else()
1162                         set(WITH_OPENAL OFF)
1163                 endif()
1164         endif()
1165
1166         if(WITH_JACK)
1167                 set(JACK /usr)
1168                 set(JACK_INCLUDE_DIRS ${JACK}/include/jack)
1169                 set(JACK_LIBRARIES jack)
1170                 set(JACK_LIBPATH ${JACK}/lib)
1171         endif()
1172
1173         if(WITH_CODEC_SNDFILE)
1174                 set(SNDFILE ${LIBDIR}/sndfile)
1175                 set(SNDFILE_INCLUDE_DIRS ${SNDFILE}/include)
1176                 set(SNDFILE_LIBRARIES sndfile FLAC ogg vorbis vorbisenc)
1177                 set(SNDFILE_LIBPATH ${SNDFILE}/lib ${FFMPEG}/lib)  # TODO, deprecate
1178         endif()
1179
1180         if(WITH_PYTHON)
1181                 if(NOT WITH_PYTHON_MODULE)
1182                         # we use precompiled libraries for py 3.2 and up by default
1183
1184                         # normally cached but not since we include them with blender
1185                         set(PYTHON_VERSION 3.2)
1186                         set(PYTHON_INCLUDE_DIR "${LIBDIR}/python/include/python${PYTHON_VERSION}")
1187                         # set(PYTHON_BINARY "${LIBDIR}/python/bin/python${PYTHON_VERSION}") # not used yet
1188                         set(PYTHON_LIBRARY python${PYTHON_VERSION})
1189                         set(PYTHON_LIBPATH "${LIBDIR}/python/lib/python${PYTHON_VERSION}")
1190                         # set(PYTHON_LINKFLAGS "-u _PyMac_Error")  # won't  build with this enabled
1191                 else()
1192                         # module must be compiled against Python framework
1193
1194                         # normally cached but not since we include them with blender
1195                         set(PYTHON_VERSION 3.2)
1196                         set(PYTHON_INCLUDE_DIR "/Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}/include/python${PYTHON_VERSION}m")
1197                         set(PYTHON_BINARY "/Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}/bin/python${PYTHON_VERSION}")
1198                         #set(PYTHON_LIBRARY python${PYTHON_VERSION})
1199                         set(PYTHON_LIBPATH "/Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}/lib/python${PYTHON_VERSION}/config-3.2m")
1200                         #set(PYTHON_LINKFLAGS "-u _PyMac_Error -framework Python")  # won't  build with this enabled
1201                 endif()
1202                 
1203                 # uncached vars
1204                 set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}")
1205                 set(PYTHON_LIBRARIES  "${PYTHON_LIBRARY}")
1206         endif()
1207
1208         if(WITH_INTERNATIONAL)
1209                 set(GETTEXT ${LIBDIR}/gettext)
1210                 set(GETTEXT_INCLUDE_DIRS "${GETTEXT}/include")
1211                 set(GETTEXT_LIBRARIES intl iconv)
1212                 set(GETTEXT_LIBPATH ${GETTEXT}/lib)
1213         endif()
1214
1215         if(WITH_FFTW3)
1216                 set(FFTW3 ${LIBDIR}/fftw3)
1217                 set(FFTW3_INCLUDE_DIRS ${FFTW3}/include)
1218                 set(FFTW3_LIBRARIES fftw3)
1219                 set(FFTW3_LIBPATH ${FFTW3}/lib)
1220         endif()
1221
1222         set(PNG_LIBRARIES png)
1223         set(JPEG_LIBRARIES jpeg)
1224
1225         set(ZLIB /usr)
1226         set(ZLIB_INCLUDE_DIRS "${ZLIB}/include")
1227         set(ZLIB_LIBRARIES z bz2)
1228
1229         set(FREETYPE ${LIBDIR}/freetype)
1230         set(FREETYPE_INCLUDE_DIRS ${FREETYPE}/include ${FREETYPE}/include/freetype2)
1231         set(FREETYPE_LIBPATH ${FREETYPE}/lib)
1232         set(FREETYPE_LIBRARY freetype)
1233
1234         if(WITH_IMAGE_OPENEXR)
1235                 set(OPENEXR ${LIBDIR}/openexr)
1236                 set(OPENEXR_INCLUDE_DIRS ${OPENEXR}/include/OpenEXR)
1237                 set(OPENEXR_LIBRARIES Iex Half IlmImf Imath IlmThread)
1238                 set(OPENEXR_LIBPATH ${OPENEXR}/lib)
1239         endif()
1240
1241         if(WITH_CODEC_FFMPEG)
1242                 set(FFMPEG ${LIBDIR}/ffmpeg)
1243                 set(FFMPEG_INCLUDE_DIRS ${FFMPEG}/include)
1244                 set(FFMPEG_LIBRARIES avcodec avdevice avformat avutil mp3lame swscale x264 xvidcore theora theoradec theoraenc vorbis vorbisenc vorbisfile ogg)
1245                 set(FFMPEG_LIBPATH ${FFMPEG}/lib)
1246                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__STDC_CONSTANT_MACROS")
1247         endif()
1248
1249         find_library(SYSTEMSTUBS_LIBRARY
1250                 NAMES
1251                 SystemStubs
1252                 PATHS
1253         )
1254         mark_as_advanced(SYSTEMSTUBS_LIBRARY)
1255         if(SYSTEMSTUBS_LIBRARY)
1256                 set(PLATFORM_LINKLIBS stdc++ SystemStubs)
1257         else()
1258                 set(PLATFORM_LINKLIBS stdc++)
1259         endif()
1260
1261         if(WITH_COCOA)
1262                 set(PLATFORM_CFLAGS "-pipe -funsigned-char -DGHOST_COCOA")
1263                 set(PLATFORM_LINKFLAGS "-fexceptions -framework CoreServices -framework Foundation -framework IOKit -framework AppKit -framework Cocoa -framework Carbon -framework AudioUnit -framework AudioToolbox -framework CoreAudio")
1264                 if(USE_QTKIT)
1265                         set(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -DUSE_QTKIT")
1266                         set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -framework QTKit")
1267                         if(CMAKE_OSX_ARCHITECTURES MATCHES i386)
1268                                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -framework QuickTime")
1269                                 #libSDL still needs 32bit carbon quicktime
1270                         endif()
1271                 elseif(WITH_CODEC_QUICKTIME)
1272                         set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -framework QuickTime")
1273                 endif()
1274
1275                 # XXX - SOME MAC DEV PLEASE TEST WITH THE SDK INSTALLED!
1276                 # ALSO SHOULD BE MOVED INTO OWN MODULE WHEN FUNCTIONAL
1277                 if(WITH_INPUT_NDOF)
1278                         # This thread it *should* work and check the framework - campbell
1279                         # http://www.cmake.org/pipermail/cmake/2005-December/007740.html
1280                         find_library(3D_CONNEXION_CLIENT_LIBRARY
1281                                 NAMES 3DconnexionClient
1282                         )
1283                         if(NOT 3D_CONNEXION_CLIENT_LIBRARY)
1284                                 set(WITH_INPUT_NDOF OFF)
1285                         endif()
1286
1287                         if(WITH_INPUT_NDOF)
1288                                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -weak_framework 3DconnexionClient")
1289                         endif()
1290                 endif()
1291
1292         else()
1293                 set(PLATFORM_CFLAGS "-pipe -funsigned-char")
1294                 set(PLATFORM_LINKFLAGS "-fexceptions -framework CoreServices -framework Foundation -framework IOKit -framework AppKit -framework Carbon -framework AGL -framework AudioUnit -framework AudioToolbox -framework CoreAudio -framework QuickTime")
1295                 set(WITH_INPUT_NDOF OFF)  # unsupported
1296         endif()
1297         
1298         if(WITH_PYTHON_MODULE)
1299                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} /Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}/python")# force cmake to link right framework
1300         endif()
1301         
1302         if(WITH_OPENCOLLADA)
1303                 set(OPENCOLLADA ${LIBDIR}/opencollada)
1304
1305                 set(OPENCOLLADA_INCLUDE_DIRS
1306                         ${LIBDIR}/opencollada/include/COLLADAStreamWriter
1307                         ${LIBDIR}/opencollada/include/COLLADABaseUtils
1308                         ${LIBDIR}/opencollada/include/COLLADAFramework
1309                         ${LIBDIR}/opencollada/include/COLLADASaxFrameworkLoader
1310                         ${LIBDIR}/opencollada/include/GeneratedSaxParser
1311                 )
1312
1313                 set(OPENCOLLADA_LIBPATH ${OPENCOLLADA}/lib)
1314                 set(OPENCOLLADA_LIBRARIES "OpenCOLLADASaxFrameworkLoader -lOpenCOLLADAFramework -lOpenCOLLADABaseUtils -lOpenCOLLADAStreamWriter -lMathMLSolver -lGeneratedSaxParser -lUTF -lxml2 -lbuffer -lftoa" )
1315                 #pcre is bundled with openCollada
1316                 #set(PCRE ${LIBDIR}/pcre)
1317                 #set(PCRE_LIBPATH ${PCRE}/lib)
1318                 set(PCRE_LIBRARIES pcre)
1319                 #libxml2 is used
1320                 #set(EXPAT ${LIBDIR}/expat)
1321                 #set(EXPAT_LIBPATH ${EXPAT}/lib)
1322                 set(EXPAT_LIB)
1323         endif()
1324
1325         if(WITH_SDL)
1326                 set(SDL ${LIBDIR}/sdl)
1327                 set(SDL_INCLUDE_DIR ${SDL}/include)
1328                 set(SDL_LIBRARY SDL)
1329                 set(SDL_LIBPATH ${SDL}/lib)
1330         endif()
1331
1332         set(PNG "${LIBDIR}/png")
1333         set(PNG_INCLUDE_DIR "${PNG}/include")
1334         set(PNG_LIBPATH ${PNG}/lib)
1335
1336         set(JPEG "${LIBDIR}/jpeg")
1337         set(JPEG_INCLUDE_DIR "${JPEG}/include")
1338         set(JPEG_LIBPATH ${JPEG}/lib)
1339
1340         if(WITH_IMAGE_TIFF)
1341                 set(TIFF ${LIBDIR}/tiff)
1342                 set(TIFF_INCLUDE_DIR ${TIFF}/include)
1343                 set(TIFF_LIBRARY tiff)
1344                 set(TIFF_LIBPATH ${TIFF}/lib)
1345         endif()
1346
1347         if (WITH_INPUT_NDOF)
1348                 # linker needs "-weak_framework 3DconnexionClient"
1349         endif()
1350
1351         if(WITH_BOOST)
1352                 set(BOOST ${LIBDIR}/boost)
1353                 set(BOOST_INCLUDE_DIR ${BOOST}/include)
1354                 set(BOOST_LIBRARIES boost_date_time-mt boost_filesystem-mt boost_regex-mt boost_system-mt boost_thread-mt)
1355                 set(BOOST_LIBPATH ${BOOST}/lib)
1356                 set(BOOST_DEFINITIONS)
1357         endif()
1358
1359         if(WITH_OPENIMAGEIO)
1360                 set(OPENIMAGEIO ${LIBDIR}/openimageio)
1361                 set(OPENIMAGEIO_INCLUDE_DIRS ${OPENIMAGEIO}/include)
1362                 set(OPENIMAGEIO_LIBRARIES OpenImageIO ${PNG_LIBRARIES} ${JPEG_LIBRARIES} ${TIFF_LIBRARY} ${OPENEXR_LIBRARIES} ${ZLIB_LIBRARIES})
1363                 set(OPENIMAGEIO_LIBPATH ${OPENIMAGEIO}/lib ${JPEG_LIBPATH} ${PNG_LIBPATH} ${TIFF_LIBPATH} ${OPENEXR_LIBPATH} ${ZLIB_LIBPATH})
1364                 set(OPENIMAGEIO_DEFINITIONS "-DOIIO_STATIC_BUILD")
1365         endif()
1366
1367         set(EXETYPE MACOSX_BUNDLE)
1368
1369         set(CMAKE_C_FLAGS_DEBUG "-fno-strict-aliasing -g")
1370         set(CMAKE_CXX_FLAGS_DEBUG "-fno-strict-aliasing -g")
1371         if(CMAKE_OSX_ARCHITECTURES MATCHES "i386")
1372                 set(CMAKE_CXX_FLAGS_RELEASE "-O2 -mdynamic-no-pic -ftree-vectorize -msse -msse2 -fvariable-expansion-in-unroller")
1373                 set(CMAKE_C_FLAGS_RELEASE "-O2 -mdynamic-no-pic -ftree-vectorize -msse -msse2 -fvariable-expansion-in-unroller")
1374         elseif(CMAKE_OSX_ARCHITECTURES MATCHES "x86_64")
1375                 set(CMAKE_CXX_FLAGS_RELEASE "-O2 -mdynamic-no-pic -ftree-vectorize -msse -msse2 -msse3 -mssse3 -fvariable-expansion-in-unroller")
1376                 set(CMAKE_C_FLAGS_RELEASE "-O2 -mdynamic-no-pic -ftree-vectorize -msse -msse2 -msse3 -mssse3 -fvariable-expansion-in-unroller")
1377         else()
1378                 set(CMAKE_C_FLAGS_RELEASE "-mdynamic-no-pic -fno-strict-aliasing")
1379                 set(CMAKE_CXX_FLAGS_RELEASE "-mdynamic-no-pic -fno-strict-aliasing")
1380         endif()
1381 endif()
1382
1383 #-----------------------------------------------------------------------------
1384 # Common.
1385
1386 if(APPLE OR WIN32)
1387         if(NOT EXISTS "${LIBDIR}/")
1388                 message(FATAL_ERROR "Apple and Windows require pre-compiled libs at: '${LIBDIR}'")
1389         endif()
1390 endif()
1391
1392 # See TEST_SSE_SUPPORT() for how this is defined.
1393
1394 if(WITH_RAYOPTIMIZATION)
1395         if(SUPPORT_SSE_BUILD)
1396                 set(PLATFORM_CFLAGS " ${COMPILER_SSE_FLAG} ${PLATFORM_CFLAGS}")
1397                 add_definitions(-D__SSE__ -D__MMX__)
1398         endif()
1399         if(SUPPORT_SSE2_BUILD)
1400                 set(PLATFORM_CFLAGS " ${COMPILER_SSE2_FLAG} ${PLATFORM_CFLAGS}")
1401                 add_definitions(-D__SSE2__)
1402                 if(NOT SUPPORT_SSE_BUILD) # dont double up
1403                         add_definitions(-D__MMX__)
1404                 endif()
1405         endif()
1406 endif()
1407
1408
1409 # set the endian define
1410 if(MSVC)
1411         # for some reason this fails on msvc
1412         add_definitions(-D__LITTLE_ENDIAN__)
1413 else()
1414         include(TestBigEndian)
1415         test_big_endian(_SYSTEM_BIG_ENDIAN)
1416         if(_SYSTEM_BIG_ENDIAN)
1417                 add_definitions(-D__BIG_ENDIAN__)
1418         else()
1419                 add_definitions(-D__LITTLE_ENDIAN__)
1420         endif()
1421         unset(_SYSTEM_BIG_ENDIAN)
1422 endif()
1423
1424
1425 if(WITH_IMAGE_OPENJPEG)
1426         if(UNIX AND NOT APPLE)
1427                 # dealt with above
1428         else()
1429                 set(OPENJPEG_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/extern/libopenjpeg")
1430         endif()
1431 endif()
1432
1433 if(WITH_IMAGE_REDCODE)
1434         set(REDCODE ${CMAKE_SOURCE_DIR}/extern)
1435         set(REDCODE_INC ${REDCODE})
1436 endif()
1437
1438 #-----------------------------------------------------------------------------
1439 # Blender WebPlugin
1440
1441 if(WITH_WEBPLUGIN)
1442         set(GECKO_DIR "${CMAKE_SOURCE_DIR}/../gecko-sdk/" CACHE PATH "Gecko SDK path")
1443         set(WEBPLUGIN_SANDBOX_MODE "apparmor" CACHE STRING "WEB Plugin sandbox mode, can be apparmor, privsep, none")
1444
1445         set(WITH_PLAYER ON)
1446 endif()
1447
1448
1449 #-----------------------------------------------------------------------------
1450 # Configure OpenGL.
1451 find_package(OpenGL)
1452 blender_include_dirs_sys("${OPENGL_INCLUDE_DIR}")
1453 # unset(OPENGL_LIBRARIES CACHE) # not compat with older cmake
1454 # unset(OPENGL_xmesa_INCLUDE_DIR CACHE) # not compat with older cmake
1455
1456 #-----------------------------------------------------------------------------
1457 # Configure OpenMP.
1458 if(WITH_OPENMP)
1459         find_package(OpenMP)
1460         if(OPENMP_FOUND)
1461                 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
1462                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
1463
1464                 if(APPLE AND ${CMAKE_GENERATOR} MATCHES "Xcode")
1465                         set(CMAKE_XCODE_ATTRIBUTE_ENABLE_OPENMP_SUPPORT "YES")
1466                 endif()
1467         else()
1468                 set(WITH_OPENMP OFF)
1469         endif()
1470
1471         mark_as_advanced(
1472                 OpenMP_C_FLAGS
1473                 OpenMP_CXX_FLAGS
1474         )
1475 endif()
1476
1477 #-----------------------------------------------------------------------------
1478 # Configure GLEW
1479
1480 if(WITH_BUILTIN_GLEW)
1481         # set(GLEW_LIBRARY "")  # unused
1482         set(GLEW_INCLUDE_PATH "${CMAKE_SOURCE_DIR}/extern/glew/include")
1483 else()
1484         find_package(GLEW)
1485
1486         if(NOT GLEW_FOUND)
1487                 message(FATAL_ERROR "GLEW is required to build blender, install it or use WITH_BUILTIN_GLEW")
1488         endif()
1489
1490         mark_as_advanced(
1491                 GLEW_LIBRARY
1492                 GLEW_INCLUDE_PATH
1493         )
1494 endif()
1495
1496 #-----------------------------------------------------------------------------
1497 # Configure Python.
1498
1499 if(WITH_PYTHON_MODULE)
1500         add_definitions(-DPy_ENABLE_SHARED)
1501 endif()
1502
1503 #-----------------------------------------------------------------------------
1504 # Extra compile flags
1505
1506 if(CMAKE_COMPILER_IS_GNUCC)
1507
1508         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
1509         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_CAST_ALIGN -Wcast-align)
1510         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_DECLARATION_AFTER_STATEMENT -Werror=declaration-after-statement)
1511         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_IMPLICIT_FUNCTION_DECLARATION -Werror=implicit-function-declaration)
1512         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_RETURN_TYPE -Werror=return-type)
1513         # system headers sometimes do this, disable for now, was: -Werror=strict-prototypes
1514         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_STRICT_PROTOTYPES -Wstrict-prototypes)
1515         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_CHAR_SUBSCRIPTS -Wno-char-subscripts)
1516         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
1517         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_POINTER_ARITH -Wpointer-arith)
1518         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNUSED_PARAMETER -Wunused-parameter)
1519         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_WRITE_STRINGS -Wwrite-strings)
1520
1521         # # this causes too many warnings, disable
1522         # ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNDEFINED -Wundef)
1523
1524         # disable because it gives warnings for printf() & friends.
1525         # ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_DOUBLE_PROMOTION -Wdouble-promotion -Wno-error=double-promotion)
1526
1527         if(NOT APPLE)
1528                 ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_ERROR_UNUSED_BUT_SET_VARIABLE -Wno-error=unused-but-set-variable)
1529         endif()
1530
1531         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ALL -Wall)
1532         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_INVALID_OFFSETOF -Wno-invalid-offsetof)
1533         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_SIGN_COMPARE -Wno-sign-compare)
1534
1535         # # this causes too many warnings, disable
1536         # ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNDEFINED -Wundef)
1537
1538         # flags to undo strict flags
1539         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_DEPRECATED_DECLARATIONS -Wno-deprecated-declarations)
1540         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_PARAMETER        -Wno-unused-parameter)
1541
1542         if(NOT APPLE)
1543                 ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_ERROR_UNUSED_BUT_SET_VARIABLE -Wno-error=unused-but-set-variable)
1544         endif()
1545
1546 elseif(CMAKE_C_COMPILER_ID MATCHES "Intel")
1547
1548         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
1549         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_POINTER_ARITH -Wpointer-arith)
1550         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
1551
1552         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ALL -Wall)
1553         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_INVALID_OFFSETOF -Wno-invalid-offsetof)
1554         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_SIGN_COMPARE -Wno-sign-compare)
1555
1556         # disable numbered, false positives
1557         set(C_WARNINGS "${C_WARNINGS} -wd188,186,144,913,556")
1558         set(CXX_WARNINGS "${CXX_WARNINGS} -wd188,186,144,913,556")
1559
1560 endif()
1561
1562 # MSVC2010 fails to links C++ libs right
1563 if(MSVC10)
1564         if(WITH_IMAGE_OPENEXR)
1565                 message(WARNING "MSVC 2010 does not support OpenEXR, disabling WITH_IMAGE_OPENEXR. To enable support use Use MSVC 2008")
1566         endif()
1567         if(WITH_OPENCOLLADA)
1568                 message(WARNING "MSVC 2010 does not support OpenCollada, disabling WITH_OPENCOLLADA. To enable support use Use MSVC 2008")
1569         endif()
1570 endif()
1571
1572 # ensure python header is found since detection can fail, this could happen
1573 # with _any_ library but since we used a fixed python version this tends to
1574 # be most problematic.
1575 if(WITH_PYTHON)
1576         if(NOT EXISTS "${PYTHON_INCLUDE_DIR}/Python.h")
1577                 message(FATAL_ERROR "Missing: \"${PYTHON_INCLUDE_DIR}/Python.h\",\n"
1578                                                         "Set the cache entry 'PYTHON_INCLUDE_DIR' to point "
1579                                                         "to a valid python include path. Containing "
1580                                                         "Python.h for python version \"${PYTHON_VERSION}\"")
1581         endif()
1582 endif()
1583
1584
1585 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${PLATFORM_CFLAGS} ${C_WARNINGS}")
1586 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${PLATFORM_CFLAGS} ${CXX_WARNINGS}")
1587
1588 #-------------------------------------------------------------------------------
1589 # Global Defines
1590
1591 # better not set includes here but this debugging option is off by default.
1592 if(WITH_CXX_GUARDEDALLOC)
1593         include_directories(${CMAKE_SOURCE_DIR}/intern/guardedalloc)
1594 endif()
1595
1596 if(WITH_ASSERT_ABORT)
1597         add_definitions(-DWITH_ASSERT_ABORT)
1598 endif()
1599
1600 # message(STATUS "Using CFLAGS: ${CMAKE_C_FLAGS}")
1601 # message(STATUS "Using CXXFLAGS: ${CMAKE_CXX_FLAGS}")
1602
1603 #-----------------------------------------------------------------------------
1604 # Libraries
1605
1606 add_subdirectory(source)
1607 add_subdirectory(intern)
1608 add_subdirectory(extern)
1609
1610
1611 #-----------------------------------------------------------------------------
1612 # Blender Application
1613 if(WITH_BLENDER)
1614         add_subdirectory(source/creator)
1615 endif()
1616
1617
1618 #-----------------------------------------------------------------------------
1619 # Blender Player
1620 if(WITH_PLAYER)
1621         add_subdirectory(source/blenderplayer)
1622 endif()
1623
1624 #-----------------------------------------------------------------------------
1625 # CPack for generating packages
1626 include(build_files/cmake/packaging.cmake)
1627
1628
1629 #-----------------------------------------------------------------------------
1630 # Print Final Configuration
1631
1632 if(FIRST_RUN)
1633         set(_config_msg "\n* Blender Configuration *")
1634         macro(info_cfg_option
1635                 _setting)
1636                 set(_msg "   * ${_setting}")
1637                 string(LENGTH "${_msg}" _len)
1638                 while("28" GREATER "${_len}")
1639                         set(_msg "${_msg} ")
1640                          math(EXPR _len "${_len} + 1")
1641                 endwhile()
1642
1643                 set(_config_msg "${_config_msg}\n${_msg}${${_setting}}")
1644         endmacro()
1645
1646         macro(info_cfg_text
1647                 _text)
1648                 set(_config_msg "${_config_msg}\n\n  ${_text}")
1649
1650
1651         endmacro()
1652
1653         info_cfg_text("Build Options:")
1654         info_cfg_option(WITH_GAMEENGINE)
1655         info_cfg_option(WITH_PLAYER)
1656         info_cfg_option(WITH_BULLET)
1657         info_cfg_option(WITH_IK_ITASC)
1658         info_cfg_option(WITH_OPENCOLLADA)
1659         info_cfg_option(WITH_FFTW3)
1660         info_cfg_option(WITH_INTERNATIONAL)
1661         info_cfg_option(WITH_INPUT_NDOF)
1662         info_cfg_option(WITH_CYCLES)
1663
1664         info_cfg_text("Compiler Options:")
1665         info_cfg_option(WITH_BUILDINFO)
1666         info_cfg_option(WITH_OPENMP)
1667         info_cfg_option(WITH_RAYOPTIMIZATION)
1668
1669         info_cfg_text("System Options:")
1670         info_cfg_option(WITH_INSTALL_PORTABLE)
1671         info_cfg_option(WITH_X11_XF86VMODE)
1672         info_cfg_option(WITH_X11_XINPUT)
1673         info_cfg_option(WITH_BUILTIN_GLEW)
1674         info_cfg_option(WITH_MEM_JEMALLOC)
1675
1676         info_cfg_text("Image Formats:")
1677         info_cfg_option(WITH_IMAGE_CINEON)
1678         info_cfg_option(WITH_IMAGE_DDS)
1679         info_cfg_option(WITH_IMAGE_HDR)
1680         info_cfg_option(WITH_IMAGE_OPENEXR)
1681         info_cfg_option(WITH_IMAGE_OPENJPEG)
1682         info_cfg_option(WITH_IMAGE_REDCODE)
1683         info_cfg_option(WITH_IMAGE_TIFF)
1684
1685         info_cfg_text("Audio:")
1686         info_cfg_option(WITH_OPENAL)
1687         info_cfg_option(WITH_SDL)
1688         info_cfg_option(WITH_JACK)
1689         info_cfg_option(WITH_CODEC_FFMPEG)
1690         info_cfg_option(WITH_CODEC_SNDFILE)
1691
1692         info_cfg_text("Compression:")
1693         info_cfg_option(WITH_LZMA)
1694         info_cfg_option(WITH_LZO)
1695
1696         info_cfg_text("Python:")
1697         info_cfg_option(WITH_PYTHON_INSTALL)
1698         info_cfg_option(WITH_PYTHON_MODULE)
1699         info_cfg_option(WITH_PYTHON_SAFETY)
1700
1701         info_cfg_text("Modifiers:")
1702         info_cfg_option(WITH_MOD_BOOLEAN)
1703         info_cfg_option(WITH_MOD_REMESH)
1704         info_cfg_option(WITH_MOD_DECIMATE)
1705         info_cfg_option(WITH_MOD_FLUID)
1706         info_cfg_option(WITH_MOD_OCEANSIM)
1707
1708         info_cfg_text("")
1709
1710         message("${_config_msg}")
1711 endif()