Camera tracking integration
[blender.git] / CMakeLists.txt
1 # -*- mode: cmake; indent-tabs-mode: t; -*-
2 # $Id$
3 # ***** BEGIN GPL LICENSE BLOCK *****
4 #
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software Foundation,
17 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 #
19 # The Original Code is Copyright (C) 2006, Blender Foundation
20 # All rights reserved.
21 #
22 # The Original Code is: all of this file.
23 #
24 # Contributor(s): Jacques Beaurain.
25 #
26 # ***** END GPL LICENSE BLOCK *****
27
28 #-----------------------------------------------------------------------------
29 # We don't allow in-source builds. This causes no end of troubles because 
30 # all out-of-source builds will use the CMakeCache.txt file there and even 
31 # build the libs and objects in it.
32
33 if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
34         if(NOT DEFINED WITH_IN_SOURCE_BUILD)
35                 message(FATAL_ERROR
36                         "CMake generation for blender is not allowed within the source directory!"
37                         "\n Remove the CMakeCache.txt file and try again from another folder, e.g.:"
38                         "\n "
39                         "\n rm CMakeCache.txt"
40                         "\n cd .."
41                         "\n mkdir cmake-make"
42                         "\n cd cmake-make"
43                         "\n cmake ../blender"
44                         "\n "
45                         "\n Alternately define WITH_IN_SOURCE_BUILD to force this option (not recommended!)"
46                 )
47         endif()
48 endif()
49
50 cmake_minimum_required(VERSION 2.8)
51
52 if(NOT EXECUTABLE_OUTPUT_PATH)
53         set(FIRST_RUN "TRUE")
54 endif()
55
56 # this starts out unset
57 list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/build_files/cmake/Modules")
58
59 # avoid having empty buildtype
60 set(CMAKE_BUILD_TYPE_INIT "Release")
61
62 # quiet output for Makefiles, 'make -s' helps too
63 # set_property(GLOBAL PROPERTY RULE_MESSAGES OFF)
64
65 #-----------------------------------------------------------------------------
66 # Load some macros.
67 include(build_files/cmake/macros.cmake)
68
69
70 #-----------------------------------------------------------------------------
71 # Initialize project.
72
73 blender_project_hack_pre()
74
75 project(Blender)
76
77 blender_project_hack_post()
78
79 enable_testing()
80
81 #-----------------------------------------------------------------------------
82 # Redirect output files
83
84 set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin CACHE INTERNAL "" FORCE )
85 set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib CACHE INTERNAL "" FORCE )
86
87 #-----------------------------------------------------------------------------
88 # Set default config options
89
90 get_blender_version()
91
92 # Blender internal features
93 option(WITH_BLENDER "Build blender (disable to build only the blender player)" ON)
94 mark_as_advanced(WITH_BLENDER)
95
96 option(WITH_INTERNATIONAL "Enable I18N (International fonts and text)" ON)
97
98 option(WITH_PYTHON        "Enable Embedded Python API  (only disable for development)" ON)
99 option(WITH_PYTHON_SECURITY "Disables execution of scripts within blend files by default (recommend to leave off)" OFF)
100 mark_as_advanced(WITH_PYTHON)  # dont want people disabling this unless they really know what they are doing.
101 mark_as_advanced(WITH_PYTHON_SECURITY)  # some distrobutions see this as a security issue, rather than have them patch it, make a build option.
102
103 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)
104 option(WITH_PYTHON_MODULE "Enable building as a python module (experemental, only enable for development)" OFF)
105 option(WITH_BUILDINFO     "Include extra build details (only disable for development & faster builds)" ON)
106 option(WITH_IK_ITASC      "Enable ITASC IK solver (only disable for development & for incompatible C++ compilers)" ON)
107 option(WITH_FFTW3         "Enable FFTW3 support (Used for smoke and audio effects)" OFF)
108 option(WITH_BULLET        "Enable Bullet (Physics Engine)" ON)
109 option(WITH_GAMEENGINE    "Enable Game Engine" ON)
110 option(WITH_PLAYER        "Build Player" OFF)
111
112 # GHOST Windowing Library Options
113 option(WITH_GHOST_DEBUG   "Enable debugging output for the GHOST library" OFF)
114 mark_as_advanced(WITH_GHOST_DEBUG)
115
116 option(WITH_GHOST_SDL    "Enable building blender against SDL for windowing rather then the native APIs" OFF)
117 mark_as_advanced(WITH_GHOST_SDL)
118
119 # Misc...
120 option(WITH_HEADLESS      "Build without graphical support (renderfarm, server mode only)" OFF)
121 mark_as_advanced(WITH_HEADLESS)
122
123 option(WITH_AUDASPACE    "Build with blenders audio library (only disable if you know what you're doing!)" ON)
124 mark_as_advanced(WITH_AUDASPACE)
125
126
127 # (unix defaults to OpenMP On)
128 if(UNIX AND NOT APPLE)
129         option(WITH_OPENMP        "Enable OpenMP (has to be supported by the compiler)" ON)
130 else()
131         option(WITH_OPENMP        "Enable OpenMP (has to be supported by the compiler)" OFF)
132 endif()
133
134 if(UNIX AND NOT APPLE)
135         option(WITH_X11_XINPUT "Enable X11 Xinput (tablet support)"     ON)
136         option(WITH_BUILTIN_GLEW "Use GLEW OpenGL wrapper library bundled with blender" ON)
137 else()
138         # not an option for other OS's
139         set(WITH_BUILTIN_GLEW ON)
140 endif()
141
142 # Modifiers
143 option(WITH_MOD_FLUID           "Enable Elbeem Modifier (Fluid Simulation)" ON)
144 option(WITH_MOD_SMOKE           "Enable Smoke Modifier (Smoke Simulation)" ON)
145 option(WITH_MOD_DECIMATE        "Enable Decimate Modifier" ON)
146 option(WITH_MOD_BOOLEAN         "Enable Boolean Modifier" ON)
147 option(WITH_MOD_CLOTH_ELTOPO    "Enable Experemental cloth solver" OFF)
148 mark_as_advanced(WITH_MOD_CLOTH_ELTOPO)
149
150 # Image format support
151 option(WITH_IMAGE_OPENEXR       "Enable OpenEXR Support (http://www.openexr.com)" ON)
152 option(WITH_IMAGE_OPENJPEG      "Enable OpenJpeg Support (http://www.openjpeg.org)" ON)
153 option(WITH_IMAGE_TIFF          "Enable LibTIFF Support" ON)
154 option(WITH_IMAGE_DDS           "Enable DDS Image Support" ON)
155 option(WITH_IMAGE_CINEON        "Enable CINEON and DPX Image Support" ON)
156 option(WITH_IMAGE_HDR           "Enable HDR Image Support" ON)
157 option(WITH_IMAGE_REDCODE       "Enable RedCode Image Support" OFF)
158
159 # Audio/Video format support
160 option(WITH_CODEC_FFMPEG        "Enable FFMPeg Support (http://ffmpeg.org)" OFF)
161 option(WITH_CODEC_SNDFILE       "Enable libsndfile Support (http://www.mega-nerd.com/libsndfile)" OFF)
162 if(APPLE OR (WIN32 AND NOT UNIX))
163         option(WITH_CODEC_QUICKTIME     "Enable Quicktime Support" OFF)
164 endif()
165
166 # 3D format support
167 # disable opencollada on non-apple unix because opencollada has no package for debian
168 option(WITH_OPENCOLLADA         "Enable OpenCollada Support (http://www.opencollada.org)"       OFF)
169
170 # Sound output
171 option(WITH_SDL           "Enable SDL for sound and joystick support" ON)
172 option(WITH_OPENAL        "Enable OpenAL Support (http://www.openal.org)" ON)
173 option(WITH_JACK          "Enable Jack Support (http://www.jackaudio.org)" OFF)
174 option(WITH_SAMPLERATE    "Enable samplerate conversion" ON)
175
176 # Compression
177 option(WITH_LZO           "Enable fast LZO compression (used for pointcache)" ON)
178 option(WITH_LZMA          "Enable best LZMA compression, (used for pointcache)" ON)
179
180 # Tracking
181 option(WITH_LIBMV         "Enable libmv structure from motion library" ON)
182
183 # Misc
184 option(WITH_RAYOPTIMIZATION     "Enable use of SIMD (SSE) optimizations for the raytracer" ON) 
185 if(UNIX AND NOT APPLE)
186         option(WITH_INSTALL_PORTABLE "Install redistributeable runtime, otherwise install into CMAKE_INSTALL_PREFIX" ON)
187 endif()
188 option(WITH_PYTHON_INSTALL       "Copy system python into the blender install folder" ON)
189
190 # disable for now, but plan to support on all platforms eventually
191 option(WITH_MEM_JEMALLOC   "Enable malloc replacement (http://www.canonware.com/jemalloc)" OFF)
192 mark_as_advanced(WITH_MEM_JEMALLOC)
193
194 # Debug
195 option(WITH_CXX_GUARDEDALLOC "Enable GuardedAlloc for C++ memory allocation tracking (only enable for development)" OFF)
196 mark_as_advanced(WITH_CXX_GUARDEDALLOC)
197
198 option(WITH_ASSERT_ABORT "Call abort() when raising an assertion through BLI_assert()" OFF)
199 mark_as_advanced(WITH_ASSERT_ABORT)
200
201 if(APPLE)
202         if(NOT CMAKE_OSX_ARCHITECTURES)
203                 set(CMAKE_OSX_ARCHITECTURES x86_64 CACHE STRING
204                 "Choose the architecture you want to build Blender for: i386, x86_64 or ppc"
205                 FORCE)
206         endif()
207         if(NOT CMAKE_OSX_DEPLOYMENT_TARGET)
208                 set(CMAKE_OSX_DEPLOYMENT_TARGET 10.5 CACHE STRING
209                 "Choose the minimum OSX version required: 10.4 or 10.5"
210                 FORCE)
211         endif()
212         option(WITH_COCOA         "Use Cocoa framework instead of deprecated Carbon" ON)
213         option(USE_QTKIT          "Use QtKit instead of Carbon quicktime (needed for having partial quicktime for 64bit)" OFF)
214         option(WITH_LIBS10.5  "Use 10.5 libs (needed for 64bit builds)" OFF)
215 endif()
216
217 #-----------------------------------------------------------------------------
218 # Check for conflicting/unsupported configurations
219
220 if(NOT WITH_BLENDER AND NOT WITH_PLAYER)
221         message(FATAL_ERROR "At least one of WITH_BLENDER or WITH_PLAYER must be enabled, nothing to do!")
222 endif()
223
224 if(NOT WITH_GAMEENGINE AND WITH_PLAYER)
225         message(FATAL_ERROR "WITH_PLAYER requires WITH_GAMEENGINE")
226 endif()
227
228 if(NOT WITH_AUDASPACE AND (WITH_OPENAL OR WITH_SDL OR WITH_JACK))
229         message(FATAL_ERROR "WITH_OPENAL/WITH_SDL/WITH_JACK/WITH_CODEC_FFMPEG require WITH_AUDASPACE")
230 endif()
231
232 if(NOT WITH_SDL AND WITH_GHOST_SDL)
233         message(FATAL_ERROR "WITH_GHOST_SDL requires WITH_SDL to be ON")
234 endif()
235
236 if(NOT WITH_IMAGE_OPENJPEG AND WITH_IMAGE_REDCODE)
237         message(FATAL_ERROR "WITH_IMAGE_REDCODE requires WITH_IMAGE_OPENJPEG")
238 endif()
239
240 # python module, needs some different options
241 if(WITH_PYTHON_MODULE AND WITH_PLAYER)
242         message(FATAL_ERROR "WITH_PYTHON_MODULE requires WITH_PLAYER to be OFF")
243 endif()
244
245 if(WITH_PYTHON_MODULE AND WITH_PYTHON_INSTALL)
246         message(FATAL_ERROR "WITH_PYTHON_MODULE requires WITH_PYTHON_INSTALL to be OFF")
247 endif()
248
249 if(WITH_CODEC_QUICKTIME AND MINGW)
250         message(FATAL_ERROR "MINGW requires WITH_CODEC_QUICKTIME to be OFF "
251                                                 "because it is currently unsupported, remove this "
252                                                 "line if youre a developer who wants to add support.")
253 endif()
254
255 # may as well build python module without a UI
256 if(WITH_PYTHON_MODULE)
257         set(WITH_HEADLESS ON)
258 endif()
259
260 TEST_SSE_SUPPORT()
261
262 #-----------------------------------------------------------------------------
263 # Initialize un-cached vars, avoid unused warning
264
265 # linux only, not cached
266 set(WITH_BINRELOC OFF)
267
268 # MAXOSX only, set to avoid uninitialized 
269 set(EXETYPE)
270
271 # C/C++ flags
272 set(PLATFORM_CFLAGS)
273
274 # these are added to later on.
275 set(C_WARNINGS)
276 set(CXX_WARNINGS)
277
278 # libraries to link the binary with passed to target_link_libraries()
279 # known as LLIBS to scons
280 set(PLATFORM_LINKLIBS)
281
282 # Added to linker flags in setup_liblinks
283 # - CMAKE_EXE_LINKER_FLAGS
284 # - CMAKE_EXE_LINKER_FLAGS_DEBUG
285 set(PLATFORM_LINKFLAGS)
286 set(PLATFORM_LINKFLAGS_DEBUG)
287
288
289 # disabled for now, not supported
290 # option(WITH_WEBPLUGIN     "Enable Web Plugin (Unix only)" OFF)
291
292 # For alternate Python locations the commandline can be used to override detected/default cache settings, e.g:
293 # On Unix: 
294 #   cmake ../blender \
295 #         -D PYTHON_VERSION=3.2 \
296 #         -D PYTHON_INCLUDE_DIR=/opt/py32/include/python3.2d \
297 #         -D PYTHON_LIBRARY=/opt/py32/lib/libpython3.2d.so
298 #
299 # On Macs: 
300 #   cmake ../blender \
301 #         -D PYTHON_INCLUDE_DIR=/System/Library/Frameworks/Python.framework/Versions/3.2/include/python3.2 \
302 #         -D PYTHON_LIBPATH=/System/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/config \
303 #         -G Xcode
304 #
305 # When changing any of this remember to update the notes in doc/build_systems/cmake.txt
306
307 #-----------------------------------------------------------------------------
308 #Platform specifics
309
310 if(UNIX AND NOT APPLE)
311         
312         # needed for ubuntu 11.04
313         if(EXISTS "/usr/lib/x86_64-linux-gnu")
314                 set(CMAKE_LIBRARY_PATH "/usr/lib/x86_64-linux-gnu;${CMAKE_LIBRARY_PATH}")
315         endif()
316
317         find_package(JPEG REQUIRED)
318         find_package(PNG REQUIRED)
319         find_package(ZLIB REQUIRED)
320         find_package(Freetype REQUIRED)
321
322         if(WITH_PYTHON)
323                 # No way to set py32. remove for now.
324                 # find_package(PythonLibs)
325
326                 # Use our own instead, since wothout py is such a rare case,
327                 # require this package
328                 find_package(PythonLibsUnix REQUIRED)
329         endif()
330
331
332         if(WITH_IMAGE_OPENEXR)
333                 find_package(OpenEXR)  # our own module
334                 if(NOT OPENEXR_FOUND)
335                         set(WITH_IMAGE_OPENEXR OFF)
336                 endif()
337         endif()
338
339         if(WITH_IMAGE_OPENJPEG)
340                 find_package(OpenJPEG)
341                 if(NOT OPENJPEG_FOUND)
342                         set(WITH_IMAGE_OPENJPEG OFF)
343                 endif()
344         endif()
345
346         if(WITH_IMAGE_TIFF)
347                 find_package(TIFF)
348                 if(NOT TIFF_FOUND)
349                         set(WITH_IMAGE_TIFF OFF)
350                 endif()
351         endif()
352
353         # Audio IO
354         if(WITH_OPENAL)
355                 find_package(OpenAL)
356                 if(NOT OPENAL_FOUND)
357                         set(WITH_OPENAL OFF)
358                 endif()
359         endif()
360
361         if(WITH_SDL)
362                 find_package(SDL)
363                 mark_as_advanced(SDLMAIN_LIBRARY)
364                 mark_as_advanced(SDL_INCLUDE_DIR)
365                 mark_as_advanced(SDL_LIBRARY)
366                 mark_as_advanced(SDL_LIBRARY_TEMP)
367                 # unset(SDLMAIN_LIBRARY CACHE)
368                 if(NOT SDL_FOUND)
369                         set(WITH_SDL OFF)
370                 endif()
371         endif()
372
373         if(WITH_JACK)
374                 find_package(Jack)
375                 if(NOT JACK_FOUND)
376                         set(WITH_JACK OFF)
377                 endif()
378         endif()
379
380         # Codecs
381         if(WITH_CODEC_SNDFILE)
382                 find_package(SndFile)
383                 if(NOT SNDFILE_FOUND)
384                         set(WITH_CODEC_SNDFILE OFF)
385                 endif()
386         endif()
387
388         if(WITH_CODEC_FFMPEG)
389                 set(FFMPEG /usr CACHE PATH "FFMPEG Directory")
390                 mark_as_advanced(FFMPEG)
391                 set(FFMPEG_INCLUDE_DIRS ${FFMPEG}/include)
392                 set(FFMPEG_LIBRARIES avformat avcodec avutil avdevice swscale CACHE STRING "FFMPEG Libraries")
393                 mark_as_advanced(FFMPEG_LIBRARIES)
394                 set(FFMPEG_LIBPATH ${FFMPEG}/lib)
395                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__STDC_CONSTANT_MACROS")
396         endif()
397
398         if(WITH_INTERNATIONAL)
399                 find_library(INTL_LIBRARY
400                         NAMES intl
401                         PATHS
402                         /sw/lib
403                 )
404
405                 find_library(ICONV_LIBRARY
406                         NAMES iconv
407                         PATHS
408                         /sw/lib
409                 )
410                 mark_as_advanced(ICONV_LIBRARY)
411                 mark_as_advanced(INTL_LIBRARY)
412
413                 if(INTL_LIBRARY AND ICONV_LIBRARY)
414                         set(GETTEXT_LIB ${INTL_LIBRARY} ${ICONV_LIBRARY})
415                 endif()
416         endif()
417
418         if(WITH_FFTW3)
419                 find_package(Fftw3)
420                 if(NOT FFTW3_FOUND)
421                         set(WITH_FFTW3 OFF)
422                 endif()
423         endif()
424
425         if(WITH_SAMPLERATE)
426                 find_package(Samplerate)
427                 if(NOT SAMPLERATE_FOUND)
428                         set(WITH_SAMPLERATE OFF)
429                 endif()
430         endif()
431
432         if(WITH_OPENCOLLADA)
433                 set(OPENCOLLADA /usr/local/opencollada CACHE PATH "OpenCollada Directory")
434                 mark_as_advanced(OPENCOLLADA)
435                 set(OPENCOLLADA_LIBPATH ${OPENCOLLADA}/lib)
436                 set(OPENCOLLADA_LIBRARIES OpenCOLLADAStreamWriter OpenCOLLADASaxFrameworkLoader OpenCOLLADAFramework OpenCOLLADABaseUtils GeneratedSaxParser UTF MathMLSolver pcre ftoa buffer xml2)
437                 set(OPENCOLLADA_INCLUDE_DIR ${OPENCOLLADA})
438
439                 set(PCRE /usr CACHE PATH "PCRE Directory")
440                 mark_as_advanced(PCRE)
441                 set(PCRE_LIBPATH ${PCRE}/lib)
442                 set(PCRE_LIB pcre)
443
444                 set(EXPAT /usr CACHE PATH "Expat Directory")
445                 mark_as_advanced(EXPAT)
446                 set(EXPAT_LIBPATH ${EXPAT}/lib)
447                 set(EXPAT_LIB expat)
448         endif()
449
450         if(WITH_MEM_JEMALLOC)
451                 find_package(JeMalloc)
452                 if(NOT JEMALLOC_FOUND)
453                         set(WITH_MEM_JEMALLOC OFF)
454                 endif()
455         endif()
456
457         # OpenSuse needs lutil, ArchLinux not, for now keep, can avoid by using --as-needed
458         set(PLATFORM_LINKLIBS "-lutil -lc -lm -lpthread -lstdc++")
459
460         if((NOT WITH_HEADLESS) AND (NOT WITH_GHOST_SDL))
461                 find_package(X11 REQUIRED)
462                 find_path(X11_XF86keysym_INCLUDE_PATH X11/XF86keysym.h ${X11_INC_SEARCH_PATH})
463                 mark_as_advanced(X11_XF86keysym_INCLUDE_PATH)
464
465                 list(APPEND PLATFORM_LINKLIBS ${X11_X11_LIB})
466
467                 if(WITH_X11_XINPUT)
468                         list(APPEND PLATFORM_LINKLIBS ${X11_Xinput_LIB})
469                 endif()
470         endif()
471
472         if(CMAKE_SYSTEM_NAME MATCHES "Linux")
473                 if(NOT WITH_PYTHON_MODULE)
474                         # BSD's dont use libdl.so
475                         list(APPEND PLATFORM_LINKLIBS -ldl)
476                         # binreloc is linux only
477                         set(BINRELOC_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/extern/binreloc/include)
478                         set(WITH_BINRELOC ON)
479                 endif()
480         endif()
481
482         set(PLATFORM_LINKFLAGS "-pthread")
483
484         set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE")
485         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE")
486
487         # GNU Compiler
488         if(CMAKE_COMPILER_IS_GNUCC)
489                 set(PLATFORM_CFLAGS "-pipe -fPIC -funsigned-char -fno-strict-aliasing")
490         # Intel C++ Compiler
491         elseif(CMAKE_C_COMPILER_ID MATCHES "Intel")
492                 # think these next two are broken
493                 find_program(XIAR xiar) 
494                 if(XIAR) 
495                         set(CMAKE_AR "${XIAR}")
496                 endif() 
497                 mark_as_advanced(XIAR)
498
499                 find_program(XILD xild) 
500                 if(XILD) 
501                         set(CMAKE_LINKER "${XILD}")
502                 endif() 
503                 mark_as_advanced(XILD)
504
505                 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fp-model precise -prec_div -parallel")
506                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fp-model precise -prec_div -parallel")
507
508                 # set(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -diag-enable sc3")
509                 set(PLATFORM_CFLAGS "-pipe -fPIC -funsigned-char -fno-strict-aliasing")
510                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -static-intel")
511         endif()
512
513 elseif(WIN32)
514
515         # this file is included anyway when building under Windows with cl.exe
516         #  include(${CMAKE_ROOT}/Modules/Platform/Windows-cl.cmake)
517
518         set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/windows)
519
520         # Setup 64bit and 64bit windows systems
521         if(CMAKE_CL_64)
522                 message("64 bit compiler detected.")
523                 set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/win64)
524         endif()
525         
526         add_definitions(-DWIN32)
527
528         if(WITH_INTERNATIONAL)
529                 set(ICONV ${LIBDIR}/iconv)
530                 set(ICONV_INCLUDE_DIRS ${ICONV}/include)
531                 set(ICONV_LIBRARIES iconv)
532                 set(ICONV_LIBPATH ${ICONV}/lib)
533         endif()
534
535         if(WITH_SAMPLERATE)
536                 set(SAMPLERATE ${LIBDIR}/samplerate)
537                 set(SAMPLERATE_INCLUDE_DIRS ${SAMPLERATE}/include)
538                 set(SAMPLERATE_LIBRARIES libsamplerate)
539                 set(SAMPLERATE_LIBPATH ${SAMPLERATE}/lib)
540         endif()
541
542         set(PNG "${LIBDIR}/png")
543         set(PNG_INCLUDE_DIR "${PNG}/include")
544         set(PNG_LIBPATH ${PNG}/lib) # not cmake defined
545
546         set(JPEG "${LIBDIR}/jpeg")
547         set(JPEG_INCLUDE_DIR "${JPEG}/include")
548         set(JPEG_LIBPATH ${JPEG}/lib) # not cmake defined
549
550         set(WINTAB_INC ${LIBDIR}/wintab/include) 
551
552         if(WITH_OPENAL)
553                 set(OPENAL ${LIBDIR}/openal)
554                 set(OPENAL_INCLUDE_DIR ${OPENAL}/include)
555                 set(OPENAL_LIBRARY wrap_oal)
556                 set(OPENAL_LIBPATH ${OPENAL}/lib)
557         endif()
558
559         if(WITH_CODEC_SNDFILE)
560                 set(SNDFILE ${LIBDIR}/sndfile)
561                 set(SNDFILE_INCLUDE_DIRS ${SNDFILE}/include)
562                 set(SNDFILE_LIBRARIES libsndfile-1)
563                 set(SNDFILE_LIBPATH ${SNDFILE}/lib) # TODO, deprecate
564         endif()
565
566         if(WITH_SDL)
567                 set(SDL ${LIBDIR}/sdl)
568                 set(SDL_INCLUDE_DIR ${SDL}/include)
569                 set(SDL_LIBRARY SDL)
570                 set(SDL_LIBPATH ${SDL}/lib)
571         endif()
572
573         if(WITH_CODEC_QUICKTIME)
574                 set(QUICKTIME ${LIBDIR}/QTDevWin)
575                 set(QUICKTIME_INCLUDE_DIRS ${QUICKTIME}/CIncludes)
576                 set(QUICKTIME_LIBRARIES qtmlClient)
577                 set(QUICKTIME_LIBPATH ${QUICKTIME}/Libraries)
578         endif()
579
580         if(WITH_RAYOPTIMIZATION AND SUPPORT_SSE_BUILD)
581                 add_definitions(-D__SSE__ -D__MMX__)
582         endif()
583
584         if(MSVC)
585                 if(CMAKE_CL_64)
586                         set(PLATFORM_LINKLIBS ws2_32 vfw32 winmm kernel32 user32 gdi32 comdlg32 advapi32 shfolder shell32 ole32 oleaut32 uuid)
587                 else()
588                         set(PLATFORM_LINKLIBS ws2_32 vfw32 winmm kernel32 user32 gdi32 comdlg32 advapi32 shfolder shell32 ole32 oleaut32 uuid)
589                 endif()
590
591                 add_definitions(/D_CRT_NONSTDC_NO_DEPRECATE /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_CONSOLE /D_LIB)
592
593                 set(CMAKE_CXX_FLAGS "/nologo /J /W0 /Gd /wd4018 /wd4244 /wd4305 /wd4800 /wd4065 /wd4267 /we4013" CACHE STRING "MSVC MT C++ flags " FORCE)
594                 set(CMAKE_C_FLAGS   "/nologo /J /W0 /Gd /wd4018 /wd4244 /wd4305 /wd4800 /wd4065 /wd4267 /we4013 /EHsc" CACHE STRING "MSVC MT C++ flags " FORCE)
595
596                 if(CMAKE_CL_64)
597                         set(CMAKE_CXX_FLAGS_DEBUG "/D_DEBUG /Od /Gm /EHsc /RTC1 /MTd /W3 /nologo /Zi /J" CACHE STRING "MSVC MT flags " FORCE)
598                 else()
599                         set(CMAKE_CXX_FLAGS_DEBUG "/D_DEBUG /Od /Gm /EHsc /RTC1 /MTd /W3 /nologo /ZI /J" CACHE STRING "MSVC MT flags " FORCE)
600                 endif()
601                 set(CMAKE_CXX_FLAGS_RELEASE "/O2 /Ob2 /DNDEBUG /EHsc /MT /W3 /nologo /J" CACHE STRING "MSVC MT flags " FORCE)
602                 set(CMAKE_CXX_FLAGS_MINSIZEREL "/O1 /Ob1 /DNDEBUG /EHsc /MT /W3 /nologo /J" CACHE STRING "MSVC MT flags " FORCE)
603                 set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/O2 /Ob1 /DNDEBUG /EHsc /MT /W3 /nologo /Zi /J" CACHE STRING "MSVC MT flags " FORCE)
604                 if(CMAKE_CL_64)
605                         set(CMAKE_C_FLAGS_DEBUG "/D_DEBUG /Od /Gm /EHsc /RTC1 /MTd /W3 /nologo /Zi /J" CACHE STRING "MSVC MT flags " FORCE)
606                 else()
607                         set(CMAKE_C_FLAGS_DEBUG "/D_DEBUG /Od /Gm /EHsc /RTC1 /MTd /W3 /nologo /ZI /J" CACHE STRING "MSVC MT flags " FORCE)
608                 endif()
609                 set(CMAKE_C_FLAGS_RELEASE "/O2 /Ob2 /DNDEBUG /EHsc /MT /W3 /nologo /J" CACHE STRING "MSVC MT flags " FORCE)
610                 set(CMAKE_C_FLAGS_MINSIZEREL "/O1 /Ob1 /DNDEBUG /EHsc /MT /W3 /nologo /J" CACHE STRING "MSVC MT flags " FORCE)
611                 set(CMAKE_C_FLAGS_RELWITHDEBINFO "/O2 /Ob1 /DNDEBUG /EHsc /MT /W3 /nologo /Zi /J" CACHE STRING "MSVC MT flags " FORCE)
612
613                 if(WITH_INTERNATIONAL)
614                         set(GETTEXT ${LIBDIR}/gettext)
615                         set(GETTEXT_INC ${GETTEXT}/include)
616                         set(GETTEXT_LIBPATH ${GETTEXT}/lib)
617                         if(CMAKE_CL_64)
618                                 set(GETTEXT_LIB gettext)
619                         else()
620                                 set(GETTEXT_LIB gnu_gettext)
621                         endif()
622                 endif()
623
624                 if(CMAKE_CL_64)
625                         set(PNG_LIBRARIES libpng)
626                 else()
627                         set(PNG_LIBRARIES libpng_st)
628                 endif()
629                 set(JPEG_LIBRARIES libjpeg)
630
631                 set(ZLIB_INCLUDE_DIRS ${LIBDIR}/zlib/include)
632                 if(CMAKE_CL_64)
633                         set(ZLIB_LIBRARIES ${LIBDIR}/zlib/lib/libz.lib)
634                 else()
635                         set(ZLIB_LIBRARIES ${LIBDIR}/zlib/lib/zlib.lib)
636                 endif()
637
638                 set(PTHREADS_INCLUDE_DIRS ${LIBDIR}/pthreads/include)
639                 set(PTHREADS_LIBRARIES ${LIBDIR}/pthreads/lib/pthreadVC2.lib)
640
641                 set(FREETYPE ${LIBDIR}/freetype)
642                 set(FREETYPE_INCLUDE_DIRS
643                         ${LIBDIR}/freetype/include
644                         ${LIBDIR}/freetype/include/freetype2
645                 )
646                 set(FREETYPE_LIBRARY ${LIBDIR}/freetype/lib/freetype2ST.lib)
647
648                 if(WITH_FFTW3)
649                         set(FFTW3 ${LIBDIR}/fftw3)
650                         set(FFTW3_LIBRARIES libfftw)
651                         set(FFTW3_INCLUDE_DIRS ${FFTW3}/include)
652                         set(FFTW3_LIBPATH ${FFTW3}/lib)
653                 endif()
654
655                 if(WITH_OPENCOLLADA)
656                         set(OPENCOLLADA_INCLUDE_DIR
657                                 ${LIBDIR}/opencollada/include
658                         )
659                         set(OPENCOLLADA_LIBRARIES
660                                 ${LIBDIR}/opencollada/lib/OpenCOLLADASaxFrameworkLoader.lib
661                                 ${LIBDIR}/opencollada/lib/OpenCOLLADAFramework.lib
662                                 ${LIBDIR}/opencollada/lib/OpenCOLLADABaseUtils.lib
663                                 ${LIBDIR}/opencollada/lib/OpenCOLLADAStreamWriter.lib
664                                 ${LIBDIR}/opencollada/lib/MathMLSolver.lib
665                                 ${LIBDIR}/opencollada/lib/GeneratedSaxParser.lib
666                                 ${LIBDIR}/opencollada/lib/xml2.lib
667                                 ${LIBDIR}/opencollada/lib/buffer.lib
668                                 ${LIBDIR}/opencollada/lib/ftoa.lib
669                                 ${LIBDIR}/opencollada/lib/UTF.lib
670                         )
671                         set(PCRE_LIB
672                                 ${LIBDIR}/opencollada/lib/pcre.lib
673                         )
674                 endif()
675
676                 if(WITH_CODEC_FFMPEG)
677                         set(FFMPEG_INCLUDE_DIRS
678                                 ${LIBDIR}/ffmpeg/include
679                                 ${LIBDIR}/ffmpeg/include/msvc
680                         )
681                         set(FFMPEG_LIBRARIES
682                                 ${LIBDIR}/ffmpeg/lib/avcodec-52.lib
683                                 ${LIBDIR}/ffmpeg/lib/avformat-52.lib
684                                 ${LIBDIR}/ffmpeg/lib/avdevice-52.lib
685                                 ${LIBDIR}/ffmpeg/lib/avutil-50.lib
686                                 ${LIBDIR}/ffmpeg/lib/swscale-0.lib
687                         )
688                 endif()
689
690                 if(WITH_IMAGE_OPENEXR)
691                         if(MSVC90)
692                                 set(MSVC_LIB _vs2008)
693                                 set(MSVC_INC)
694                         elseif(MSVC10)
695                                 set(MSVC_LIB _vs2010)
696                                 set(MSVC_INC _vs2010)
697                         else()
698                                 set(MSVC_LIB msvc)
699                                 set(MSVC_INC)
700                         endif()
701                         set(OPENEXR ${LIBDIR}/openexr)
702                         set(OPENEXR_LIBPATH ${OPENEXR}/lib${MSVC_LIB})
703                         set(OPENEXR_LIBRARIES
704                                 ${OPENEXR_LIBPATH}/Iex.lib
705                                 ${OPENEXR_LIBPATH}/Half.lib
706                                 ${OPENEXR_LIBPATH}/IlmImf.lib
707                                 ${OPENEXR_LIBPATH}/Imath.lib
708                                 ${OPENEXR_LIBPATH}/IlmThread.lib
709                         )
710                         set(OPENEXR_INCUDE ${OPENEXR}/include${MSVC_INC})
711                         set(OPENEXR_INCLUDE_DIRS
712                                 ${OPENEXR_INCUDE}
713                                 ${OPENEXR_INCUDE}/IlmImf
714                                 ${OPENEXR_INCUDE}/Iex
715                                 ${OPENEXR_INCUDE}/Imath
716                         )
717                         unset(OPENEXR_INCUDE)
718                         unset(OPENEXR_LIBPATH)
719                 endif()
720
721                 if(WITH_IMAGE_TIFF)
722                         set(TIFF_LIBRARY ${LIBDIR}/tiff/lib/libtiff.lib)
723                         set(TIFF_INCLUDE_DIR ${LIBDIR}/tiff/include)
724                 endif()
725
726                 if(WITH_JACK)
727                         set(JACK_INCLUDE_DIRS
728                                 ${LIBDIR}/jack/include/jack
729                                 ${LIBDIR}/jack/include
730                         )
731                         set(JACK_LIBRARIES ${LIBDIR}/jack/lib/libjack.lib)
732                 endif()
733
734                 if(WITH_PYTHON)
735                         set(PYTHON_VERSION 3.2)
736                         set(PYTHON_INCLUDE_DIRS "${LIBDIR}/python/include/python${PYTHON_VERSION}")
737                         # set(PYTHON_BINARY python) # not used yet
738                         set(PYTHON_LIBRARIES ${LIBDIR}/python/lib/python32.lib)
739                 endif()
740
741                 set(PLATFORM_LINKFLAGS "/SUBSYSTEM:CONSOLE /STACK:2097152 /INCREMENTAL:NO /NODEFAULTLIB:msvcrt.lib /NODEFAULTLIB:msvcmrt.lib /NODEFAULTLIB:msvcurt.lib /NODEFAULTLIB:msvcrtd.lib")
742
743                 # MSVC only, Mingw doesnt need
744                 if(CMAKE_CL_64)
745                         set(PLATFORM_LINKFLAGS "/MACHINE:X64 /OPT:NOREF ${PLATFORM_LINKFLAGS}")
746                 else()
747                         set(PLATFORM_LINKFLAGS "/MACHINE:IX86 /LARGEADDRESSAWARE ${PLATFORM_LINKFLAGS}")
748                 endif()
749
750                 set(PLATFORM_LINKFLAGS_DEBUG "/NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:libc.lib")
751
752         else()
753                 # keep GCC spesific stuff here
754                 if(CMAKE_COMPILER_IS_GNUCC)
755                         set(PLATFORM_LINKLIBS "-lshell32 -lshfolder -lgdi32 -lmsvcrt -lwinmm -lmingw32 -lm -lws2_32 -lz -lstdc++ -lole32 -luuid")
756                         set(PLATFORM_CFLAGS "-pipe -funsigned-char -fno-strict-aliasing")
757
758                         add_definitions(-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE)
759                 endif()
760
761                 add_definitions(-DFREE_WINDOWS)
762
763                 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_DEBUG")
764                 set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_DEBUG")
765
766                 if(WITH_INTERNATIONAL)
767                         set(GETTEXT ${LIBDIR}/gcc/gettext)
768                         set(GETTEXT_INC ${GETTEXT}/include)
769                         set(GETTEXT_LIBPATH ${GETTEXT}/lib)
770                         set(GETTEXT_LIB intl)
771                 endif()
772
773                 set(JPEG_LIBRARIES libjpeg)
774                 set(PNG_LIBRARIES png)
775
776                 set(ZLIB ${LIBDIR}/zlib)
777                 set(ZLIB_INCLUDE_DIRS ${ZLIB}/include)
778                 set(ZLIB_LIBPATH ${ZLIB}/lib)
779                 set(ZLIB_LIBRARIES z)
780
781                 set(PTHREADS ${LIBDIR}/pthreads)
782                 set(PTHREADS_INCLUDE_DIRS ${PTHREADS}/include)
783                 set(PTHREADS_LIBPATH ${PTHREADS}/lib)
784                 set(PTHREADS_LIBRARIES pthreadGC2)
785                 
786                 set(FREETYPE ${LIBDIR}/gcc/freetype)
787                 set(FREETYPE_INCLUDE_DIRS ${FREETYPE}/include ${FREETYPE}/include/freetype2)
788                 set(FREETYPE_LIBPATH ${FREETYPE}/lib)
789                 set(FREETYPE_LIBRARY freetype)
790
791                 if(WITH_FFTW3)
792                         set(FFTW3 ${LIBDIR}/gcc/fftw3)
793                         set(FFTW3_LIBRARIES fftw3)
794                         set(FFTW3_INCLUDE_DIRS ${FFTW3}/include)
795                         set(FFTW3_LIBPATH ${FFTW3}/lib)
796                 endif()
797
798                 if(WITH_OPENCOLLADA)
799                         set(OPENCOLLADA ${LIBDIR}/gcc/opencollada)
800                         set(OPENCOLLADA_INCLUDE_DIR ${OPENCOLLADA}/include)
801                         set(OPENCOLLADA_LIBPATH ${OPENCOLLADA}/lib ${OPENCOLLADA}/lib)
802                         set(OPENCOLLADA_LIBRARIES OpenCOLLADAStreamWriter OpenCOLLADASaxFrameworkLoader OpenCOLLADAFramework OpenCOLLADABaseUtils GeneratedSaxParser UTF MathMLSolver expat pcre buffer ftoa)
803                         set(PCRE_LIB pcre)
804                 endif()
805                 
806                 if(WITH_CODEC_FFMPEG)
807                         set(FFMPEG ${LIBDIR}/ffmpeg)
808                         set(FFMPEG_INCLUDE_DIRS ${FFMPEG}/include ${FFMPEG}/include)
809                         set(FFMPEG_LIBRARIES avcodec-52 avformat-52 avdevice-52 avutil-50 swscale-0)
810                         set(FFMPEG_LIBPATH ${FFMPEG}/lib)
811                 endif()
812
813                 if(WITH_IMAGE_OPENEXR)
814                         set(OPENEXR ${LIBDIR}/gcc/openexr)
815                         set(OPENEXR_INCLUDE_DIRS ${OPENEXR}/include/OpenEXR)
816                         set(OPENEXR_LIBRARIES Half IlmImf Imath IlmThread Iex)
817                         set(OPENEXR_LIBPATH ${OPENEXR}/lib)
818                 endif()
819
820                 if(WITH_IMAGE_TIFF)
821                         set(TIFF ${LIBDIR}/gcc/tiff)
822                         set(TIFF_LIBRARY tiff)
823                         set(TIFF_INCLUDE_DIR ${TIFF}/include)
824                         set(TIFF_LIBPATH ${TIFF}/lib)
825                 endif()
826
827                 if(WITH_JACK)
828                         set(JACK ${LIBDIR}/jack)
829                         set(JACK_INCLUDE_DIRS ${JACK}/include/jack ${JACK}/include)
830                         set(JACK_LIBRARIES jack)
831                         set(JACK_LIBPATH ${JACK}/lib)
832                         
833                         # TODO, gives linking errors, force off
834                         set(WITH_JACK OFF)
835                 endif()
836
837                 if(WITH_PYTHON)
838                         set(PYTHON ${LIBDIR}/python)
839                         set(PYTHON_VERSION 3.2)
840                         set(PYTHON_INCLUDE_DIRS "${PYTHON}/include/python${PYTHON_VERSION}")
841                         # set(PYTHON_BINARY python) # not used yet
842                         set(PYTHON_LIBRARIES ${PYTHON}/lib/python32mw.lib)
843                         set(PYTHON_LIBPATH ${PYTHON}/lib)
844                 endif()
845
846                 set(PLATFORM_LINKFLAGS "--stack,2097152")
847
848         endif()
849
850         # used in many places so include globally, like OpenGL
851         blender_include_dirs("${PTHREADS_INCLUDE_DIRS}")
852
853 elseif(APPLE)
854
855         if (${CMAKE_OSX_DEPLOYMENT_TARGET} STREQUAL "10.5")
856                 set(WITH_LIBS10.5 ON CACHE BOOL "Use 10.5 libs" FORCE)
857         endif()
858
859         if(WITH_LIBS10.5)
860                 set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/darwin-9.x.universal)
861         else()
862                 if(CMAKE_OSX_ARCHITECTURES MATCHES i386)
863                         set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/darwin-8.x.i386)
864                 else()
865                         set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/darwin-8.0.0-powerpc)
866                 endif()
867         endif()
868         
869
870         if(WITH_OPENAL)
871                 find_package(OpenAL)
872                 if(OPENAL_FOUND)
873                         set(WITH_OPENAL ON)
874                         set(OPENAL_INCLUDE_DIR "${LIBDIR}/openal/include")
875                 else()
876                         set(WITH_OPENAL OFF)
877                 endif()
878         endif()
879
880         if(WITH_JACK)
881                 set(JACK /usr)
882                 set(JACK_INCLUDE_DIRS ${JACK}/include/jack)
883                 set(JACK_LIBRARIES jack)
884                 set(JACK_LIBPATH ${JACK}/lib)
885         endif()
886
887         if(WITH_CODEC_SNDFILE)
888                 set(SNDFILE ${LIBDIR}/sndfile)
889                 set(SNDFILE_INCLUDE_DIRS ${SNDFILE}/include)
890                 set(SNDFILE_LIBRARIES sndfile FLAC ogg vorbis vorbisenc)
891                 set(SNDFILE_LIBPATH ${SNDFILE}/lib ${FFMPEG}/lib)  # TODO, deprecate
892         endif()
893
894         set(PYTHON_VERSION 3.2)
895
896         if(PYTHON_VERSION MATCHES 3.2)
897                 # we use precompiled libraries for py 3.2 and up by default
898
899                 set(PYTHON ${LIBDIR}/python)
900                 set(PYTHON_INCLUDE_DIRS "${PYTHON}/include/python${PYTHON_VERSION}")
901                 # set(PYTHON_BINARY "${PYTHON}/bin/python${PYTHON_VERSION}") # not used yet
902                 set(PYTHON_LIBRARIES python${PYTHON_VERSION})
903                 set(PYTHON_LIBPATH "${PYTHON}/lib/python${PYTHON_VERSION}")
904                 # set(PYTHON_LINKFLAGS "-u _PyMac_Error")  # won't  build with this enabled
905         else()
906                 # otherwise, use custom system framework
907
908                 set(PYTHON /System/Library/Frameworks/Python.framework/Versions/)
909                 set(PYTHON_VERSION 3.2)
910                 set(PYTHON_INCLUDE_DIRS "${PYTHON}${PYTHON_VERSION}/include/python${PYTHON_VERSION}")
911                 # set(PYTHON_BINARY ${PYTHON}${PYTHON_VERSION}/bin/python${PYTHON_VERSION}) # not used yet
912                 set(PYTHON_LIBRARIES "")
913                 set(PYTHON_LIBPATH ${PYTHON}${PYTHON_VERSION}/lib/python${PYTHON_VERSION}/config)
914                 set(PYTHON_LINKFLAGS "-u _PyMac_Error -framework System -framework Python")
915         endif()
916
917         if(WITH_INTERNATIONAL)
918                 set(GETTEXT ${LIBDIR}/gettext)
919                 set(GETTEXT_INC "${GETTEXT}/include")
920                 set(GETTEXT_LIB intl iconv)
921                 set(GETTEXT_LIBPATH ${GETTEXT}/lib)
922         endif()
923
924         if(WITH_FFTW3)
925                 set(FFTW3 ${LIBDIR}/fftw3)
926                 set(FFTW3_INCLUDE_DIRS ${FFTW3}/include)
927                 set(FFTW3_LIBRARIES fftw3)
928                 set(FFTW3_LIBPATH ${FFTW3}/lib)
929         endif()
930
931         set(PNG_LIBRARIES png)
932         set(JPEG_LIBRARIES jpeg)
933
934         set(ZLIB /usr)
935         set(ZLIB_INCLUDE_DIRS "${ZLIB}/include")
936         set(ZLIB_LIBRARIES z bz2)
937
938         set(FREETYPE ${LIBDIR}/freetype)
939         set(FREETYPE_INCLUDE_DIRS ${FREETYPE}/include ${FREETYPE}/include/freetype2)
940         set(FREETYPE_LIBPATH ${FREETYPE}/lib)
941         set(FREETYPE_LIBRARY freetype)
942
943         if(WITH_IMAGE_OPENEXR)
944                 set(OPENEXR ${LIBDIR}/openexr)
945                 set(OPENEXR_INCLUDE_DIRS ${OPENEXR}/include/OpenEXR)
946                 set(OPENEXR_LIBRARIES Iex Half IlmImf Imath IlmThread)
947                 set(OPENEXR_LIBPATH ${OPENEXR}/lib)
948         endif()
949
950         if(WITH_CODEC_FFMPEG)
951                 set(FFMPEG ${LIBDIR}/ffmpeg)
952                 set(FFMPEG_INCLUDE_DIRS ${FFMPEG}/include)
953                 set(FFMPEG_LIBRARIES avcodec avdevice avformat avutil mp3lame swscale x264 xvidcore theora theoradec theoraenc vorbis vorbisenc vorbisfile ogg)
954                 set(FFMPEG_LIBPATH ${FFMPEG}/lib)
955                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__STDC_CONSTANT_MACROS")
956         endif()
957
958         if(WITH_SAMPLERATE)
959                 set(SAMPLERATE ${LIBDIR}/samplerate)
960                 set(SAMPLERATE_INCLUDE_DIRS ${SAMPLERATE}/include)
961                 set(SAMPLERATE_LIBRARIES samplerate)
962                 set(SAMPLERATE_LIBPATH ${SAMPLERATE}/lib)
963         endif()
964
965         set(PLATFORM_LINKLIBS stdc++ SystemStubs)
966
967         if(WITH_COCOA)
968                 set(PLATFORM_CFLAGS "-pipe -funsigned-char -DGHOST_COCOA")
969                 set(PLATFORM_LINKFLAGS "-fexceptions -framework CoreServices -framework Foundation -framework IOKit -framework AppKit -framework Cocoa -framework Carbon -framework AudioUnit -framework AudioToolbox -framework CoreAudio")
970                 if(USE_QTKIT)
971                         set(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -DUSE_QTKIT")
972                         set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -framework QTKit")
973                         if(CMAKE_OSX_ARCHITECTURES MATCHES i386)
974                                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -framework QuickTime")
975                                 #libSDL still needs 32bit carbon quicktime 
976                         endif()
977                 elseif(WITH_CODEC_QUICKTIME)
978                         set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -framework QuickTime")
979                 endif()
980         else()
981                 set(PLATFORM_CFLAGS "-pipe -funsigned-char")
982                 set(PLATFORM_LINKFLAGS "-fexceptions -framework CoreServices -framework Foundation -framework IOKit -framework AppKit -framework Carbon -framework AGL -framework AudioUnit -framework AudioToolbox -framework CoreAudio -framework QuickTime")
983         endif()
984
985         if(WITH_OPENCOLLADA)
986                 set(OPENCOLLADA ${LIBDIR}/opencollada)
987                 set(OPENCOLLADA_INCLUDE_DIR ${OPENCOLLADA}/include)
988                 set(OPENCOLLADA_LIBPATH ${OPENCOLLADA}/lib)
989                 set(OPENCOLLADA_LIBRARIES "OpenCOLLADASaxFrameworkLoader -lOpenCOLLADAFramework -lOpenCOLLADABaseUtils -lOpenCOLLADAStreamWriter -lMathMLSolver -lGeneratedSaxParser -lUTF -lxml2 -lbuffer -lftoa" )
990                 #pcre is bundled with openCollada
991                 #set(PCRE ${LIBDIR}/pcre)
992                 #set(PCRE_LIBPATH ${PCRE}/lib)
993                 set(PCRE_LIB pcre)
994                 #libxml2 is used
995                 #set(EXPAT ${LIBDIR}/expat)
996                 #set(EXPAT_LIBPATH ${EXPAT}/lib)
997                 set(EXPAT_LIB)
998         endif()
999
1000         if(WITH_SDL)
1001                 set(SDL ${LIBDIR}/sdl)
1002                 set(SDL_INCLUDE_DIR ${SDL}/include)
1003                 set(SDL_LIBRARY SDL)
1004                 set(SDL_LIBPATH ${SDL}/lib)
1005         endif()
1006
1007         set(PNG "${LIBDIR}/png")
1008         set(PNG_INCLUDE_DIR "${PNG}/include")
1009         set(PNG_LIBPATH ${PNG}/lib)
1010
1011         set(JPEG "${LIBDIR}/jpeg")
1012         set(JPEG_INCLUDE_DIR "${JPEG}/include")
1013         set(JPEG_LIBPATH ${JPEG}/lib)
1014
1015         if(WITH_IMAGE_TIFF)
1016                 set(TIFF ${LIBDIR}/tiff)
1017                 set(TIFF_INCLUDE_DIR ${TIFF}/include)
1018                 set(TIFF_LIBRARY tiff)
1019                 set(TIFF_LIBPATH ${TIFF}/lib)
1020         endif()
1021
1022         set(EXETYPE MACOSX_BUNDLE)
1023
1024         set(CMAKE_C_FLAGS_DEBUG "-fno-strict-aliasing -g")
1025         set(CMAKE_CXX_FLAGS_DEBUG "-fno-strict-aliasing -g")
1026         if(CMAKE_OSX_ARCHITECTURES MATCHES "i386")
1027                 set(CMAKE_CXX_FLAGS_RELEASE "-O3 -mdynamic-no-pic -ftree-vectorize -msse -msse2 -fvariable-expansion-in-unroller")
1028                 set(CMAKE_C_FLAGS_RELEASE "-O3 -mdynamic-no-pic -ftree-vectorize -msse -msse2 -fvariable-expansion-in-unroller")
1029         elseif(CMAKE_OSX_ARCHITECTURES MATCHES "x86_64")
1030                 set(CMAKE_CXX_FLAGS_RELEASE "-O3 -mdynamic-no-pic -ftree-vectorize -msse -msse2 -msse3 -mssse3 -fvariable-expansion-in-unroller")
1031                 set(CMAKE_C_FLAGS_RELEASE "-O3 -mdynamic-no-pic -ftree-vectorize -msse -msse2 -msse3 -mssse3 -fvariable-expansion-in-unroller")
1032         else()
1033                 set(CMAKE_C_FLAGS_RELEASE "-mdynamic-no-pic -fno-strict-aliasing")
1034                 set(CMAKE_CXX_FLAGS_RELEASE "-mdynamic-no-pic -fno-strict-aliasing")
1035         endif()
1036 endif()
1037
1038 #-----------------------------------------------------------------------------
1039 # Common.
1040
1041 if(APPLE OR WIN32)
1042         if(NOT EXISTS "${LIBDIR}/")
1043                 message(FATAL_ERROR "Apple and Windows require pre-compiled libs at: '${LIBDIR}'")
1044         endif()
1045 endif()
1046
1047 if(WITH_RAYOPTIMIZATION)
1048         if(CMAKE_COMPILER_IS_GNUCC)
1049                 if(SUPPORT_SSE_BUILD)
1050                         set(PLATFORM_CFLAGS " -msse ${PLATFORM_CFLAGS}")
1051                         add_definitions(-D__SSE__ -D__MMX__)
1052                 endif()
1053                 if(SUPPORT_SSE2_BUILD)
1054                         set(PLATFORM_CFLAGS " -msse2 ${PLATFORM_CFLAGS}")
1055                         add_definitions(-D__SSE2__)
1056                         if(NOT SUPPORT_SSE_BUILD) # dont double up
1057                                 add_definitions(-D__MMX__)
1058                         endif()
1059                 endif()
1060         endif()
1061 endif()
1062
1063 if(WITH_IMAGE_OPENJPEG)
1064         if(UNIX AND NOT APPLE)
1065                 # dealt with above
1066         else()
1067                 set(OPENJPEG_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/extern/libopenjpeg")
1068         endif()
1069 endif()
1070
1071 if(WITH_IMAGE_REDCODE)
1072         set(REDCODE ${CMAKE_SOURCE_DIR}/extern)
1073         set(REDCODE_INC ${REDCODE})
1074 endif()
1075
1076 #-----------------------------------------------------------------------------
1077 # Blender WebPlugin
1078
1079 if(WITH_WEBPLUGIN) 
1080         set(GECKO_DIR "${CMAKE_SOURCE_DIR}/../gecko-sdk/" CACHE PATH "Gecko SDK path")
1081         set(WEBPLUGIN_SANDBOX_MODE "apparmor" CACHE STRING "WEB Plugin sandbox mode, can be apparmor, privsep, none")
1082
1083         set(WITH_PLAYER ON)
1084 endif()
1085
1086
1087 #-----------------------------------------------------------------------------
1088 # Configure OpenGL.
1089 find_package(OpenGL)
1090 blender_include_dirs_sys("${OPENGL_INCLUDE_DIR}")
1091 # unset(OPENGL_LIBRARIES CACHE) # not compat with older cmake 
1092 # unset(OPENGL_xmesa_INCLUDE_DIR CACHE) # not compat with older cmake 
1093
1094 #-----------------------------------------------------------------------------
1095 # Configure OpenMP.
1096 if(WITH_OPENMP)
1097         find_package(OpenMP)    
1098         if(OPENMP_FOUND)
1099                 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
1100                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
1101
1102                 if(APPLE AND ${CMAKE_GENERATOR} MATCHES "Xcode")
1103                         set(CMAKE_XCODE_ATTRIBUTE_ENABLE_OPENMP_SUPPORT "YES")
1104                 endif()
1105         else()
1106                 set(WITH_OPENMP OFF)
1107         endif()
1108
1109         mark_as_advanced(OpenMP_C_FLAGS)
1110         mark_as_advanced(OpenMP_CXX_FLAGS)
1111 endif() 
1112
1113 #-----------------------------------------------------------------------------
1114 # Configure GLEW
1115
1116 if(WITH_BUILTIN_GLEW)
1117         # set(GLEW_LIBRARY "")  # unused
1118         set(GLEW_INCLUDE_PATH "${CMAKE_SOURCE_DIR}/extern/glew/include")
1119 else()
1120         find_package(GLEW)
1121
1122         if(NOT GLEW_FOUND)
1123                 message(FATAL_ERROR "GLEW is required to build blender, install it or use WITH_BUILTIN_GLEW")
1124         endif()
1125
1126         mark_as_advanced(GLEW_LIBRARY)
1127         mark_as_advanced(GLEW_INCLUDE_PATH)
1128 endif()
1129
1130 #-----------------------------------------------------------------------------
1131 # Configure Python.
1132
1133 if(WITH_PYTHON_MODULE)
1134         add_definitions(-DPy_ENABLE_SHARED)
1135 endif() 
1136
1137 #-----------------------------------------------------------------------------
1138 # Extra compile flags
1139
1140 if((NOT WIN32) AND (NOT MSVC))
1141         # used for internal debug checks
1142         set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG")
1143         set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DDEBUG")
1144         
1145         # assert() checks for this.
1146         set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DNDEBUG")
1147         set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} -DNDEBUG")
1148         set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -DNDEBUG")
1149
1150         set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -DNDEBUG")
1151         set(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} -DNDEBUG")
1152         set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -DNDEBUG")
1153 endif()
1154
1155 if(CMAKE_COMPILER_IS_GNUCC)
1156
1157         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
1158         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_CAST_ALIGN -Wcast-align)
1159         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_DECLARATION_AFTER_STATEMENT -Werror=declaration-after-statement)
1160         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_IMPLICIT_FUNCTION_DECLARATION -Werror=implicit-function-declaration)
1161         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_RETURN_TYPE -Werror=return-type)
1162         # system headers sometimes do this, disable for now, was: -Werror=strict-prototypes
1163         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_STRICT_PROTOTYPES -Wstrict-prototypes)
1164         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_CHAR_SUBSCRIPTS -Wno-char-subscripts)
1165         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
1166         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_POINTER_ARITH -Wpointer-arith)
1167         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNUSED_PARAMETER -Wunused-parameter)
1168         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_WRITE_STRINGS -Wwrite-strings)
1169         # disable because it gives warnings for printf() & friends.
1170         # ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_DOUBLE_PROMOTION -Wdouble-promotion -Wno-error=double-promotion)
1171         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_ERROR_UNUSED_BUT_SET_VARIABLE -Wno-error=unused-but-set-variable)
1172
1173         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ALL -Wall)
1174         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_INVALID_OFFSETOF -Wno-invalid-offsetof)
1175         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_SIGN_COMPARE -Wno-sign-compare)
1176
1177 elseif(CMAKE_C_COMPILER_ID MATCHES "Intel")
1178
1179         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
1180         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_POINTER_ARITH -Wpointer-arith)
1181         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
1182
1183         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ALL -Wall)
1184         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_INVALID_OFFSETOF -Wno-invalid-offsetof)
1185         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_SIGN_COMPARE -Wno-sign-compare)
1186
1187 endif()
1188
1189 # MSVC2010 fails to links C++ libs right
1190 if(MSVC10)
1191         if(WITH_IMAGE_OPENEXR)
1192                 message(WARNING "MSVC 2010 does not support OpenEXR, disabling WITH_IMAGE_OPENEXR. To enable support use Use MSVC 2008")
1193                 set(WITH_IMAGE_OPENEXR OFF)
1194         endif()
1195         if(WITH_OPENCOLLADA)
1196                 message(WARNING "MSVC 2010 does not support OpenCollada, disabling WITH_OPENCOLLADA. To enable support use Use MSVC 2008")
1197                 set(WITH_OPENCOLLADA OFF)
1198         endif()
1199 endif()
1200
1201 if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
1202         if(WITH_IK_ITASC OR WITH_MOD_FLUID)
1203                 message(WARNING "Using Clang as CXX compiler: disabling WITH_IK_ITASC and WITH_MOD_FLUID, these features will be missing.")
1204                 set(WITH_IK_ITASC OFF)
1205                 set(WITH_MOD_FLUID OFF)
1206         endif()
1207 endif()
1208
1209 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${PLATFORM_CFLAGS} ${C_WARNINGS}")
1210 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${PLATFORM_CFLAGS} ${CXX_WARNINGS}")
1211
1212 #-------------------------------------------------------------------------------
1213 # Global Defines
1214
1215 # better not set includes here but this debugging option is off by default.
1216 if(WITH_CXX_GUARDEDALLOC)
1217         include_directories(${CMAKE_SOURCE_DIR}/intern/guardedalloc)
1218 endif()
1219
1220 if(WITH_ASSERT_ABORT)
1221         add_definitions(-DWITH_ASSERT_ABORT)
1222 endif()
1223
1224 # message(STATUS "Using CFLAGS: ${CMAKE_C_FLAGS}")
1225 # message(STATUS "Using CXXFLAGS: ${CMAKE_CXX_FLAGS}")
1226
1227 #-----------------------------------------------------------------------------
1228 # Libraries
1229
1230 add_subdirectory(source)
1231 add_subdirectory(intern)
1232 add_subdirectory(extern)
1233
1234
1235 #-----------------------------------------------------------------------------
1236 # Blender Application
1237 if(WITH_BLENDER)
1238         add_subdirectory(source/creator)
1239 endif()
1240
1241
1242 #-----------------------------------------------------------------------------
1243 # Blender Player
1244 if(WITH_PLAYER)
1245         add_subdirectory(source/blenderplayer)
1246 endif()
1247
1248 #-----------------------------------------------------------------------------
1249 # CPack for generating packages
1250 include(build_files/cmake/packaging.cmake)
1251
1252
1253 #-----------------------------------------------------------------------------
1254 # Print Final Configuration
1255
1256 if(FIRST_RUN)
1257         set(_config_msg "\n* Blender Configuration *")
1258         macro(info_cfg_option
1259                 _setting)
1260                 set(_msg "   * ${_setting}")
1261                 string(LENGTH "${_msg}" _len)
1262                 while("28" GREATER "${_len}")
1263                         set(_msg "${_msg} ")
1264                          math(EXPR _len "${_len} + 1")
1265                 endwhile()
1266
1267                 set(_config_msg "${_config_msg}\n${_msg}${${_setting}}")
1268         endmacro()
1269
1270         macro(info_cfg_text
1271                 _text)
1272                 set(_config_msg "${_config_msg}\n\n  ${_text}")
1273                 
1274                 
1275         endmacro()
1276
1277         info_cfg_text("Build Options:")
1278         info_cfg_option(WITH_GAMEENGINE)
1279         info_cfg_option(WITH_PLAYER)
1280         info_cfg_option(WITH_BULLET)
1281         info_cfg_option(WITH_IK_ITASC)
1282         info_cfg_option(WITH_OPENCOLLADA)
1283         info_cfg_option(WITH_FFTW3)
1284         info_cfg_option(WITH_INTERNATIONAL)
1285
1286         info_cfg_text("Compiler Options:")
1287         info_cfg_option(WITH_BUILDINFO)
1288         info_cfg_option(WITH_OPENMP)
1289         info_cfg_option(WITH_RAYOPTIMIZATION)
1290
1291         info_cfg_text("System Options:")
1292         info_cfg_option(WITH_INSTALL_PORTABLE)
1293         info_cfg_option(WITH_X11_XINPUT)
1294         info_cfg_option(WITH_BUILTIN_GLEW)
1295
1296         info_cfg_text("Image Formats:")
1297         info_cfg_option(WITH_IMAGE_CINEON)
1298         info_cfg_option(WITH_IMAGE_DDS)
1299         info_cfg_option(WITH_IMAGE_HDR)
1300         info_cfg_option(WITH_IMAGE_OPENEXR)
1301         info_cfg_option(WITH_IMAGE_OPENJPEG)
1302         info_cfg_option(WITH_IMAGE_REDCODE)
1303         info_cfg_option(WITH_IMAGE_TIFF)
1304
1305         info_cfg_text("Audio:")
1306         info_cfg_option(WITH_OPENAL)
1307         info_cfg_option(WITH_SDL)
1308         info_cfg_option(WITH_JACK)
1309         info_cfg_option(WITH_CODEC_FFMPEG)
1310         info_cfg_option(WITH_CODEC_SNDFILE)
1311         info_cfg_option(WITH_SAMPLERATE)
1312
1313         info_cfg_text("Compression:")
1314         info_cfg_option(WITH_LZMA)
1315         info_cfg_option(WITH_LZO)
1316
1317         info_cfg_text("Python:")
1318         info_cfg_option(WITH_PYTHON_INSTALL)
1319         info_cfg_option(WITH_PYTHON_MODULE)
1320         info_cfg_option(WITH_PYTHON_SAFETY)
1321
1322         info_cfg_text("Modifiers:")
1323         info_cfg_option(WITH_MOD_BOOLEAN)
1324         info_cfg_option(WITH_MOD_DECIMATE)
1325         info_cfg_option(WITH_MOD_FLUID)
1326
1327         info_cfg_text("")
1328
1329         message("${_config_msg}")
1330 endif()