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