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                         # normally cached but not since we include them with blender
736                         set(PYTHON_VERSION 3.2) # CACHE STRING)
737                         set(PYTHON_INCLUDE_DIR "${LIBDIR}/python/include/python${PYTHON_VERSION}") # CACHE PATH)
738                         set(PYTHON_LIBRARY "${LIBDIR}/python/lib/python32.lib") #CACHE FILEPATH)
739
740                         # uncached vars
741                         set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}")
742                         set(PYTHON_LIBRARIES  "${PYTHON_LIBRARY}")
743                 endif()
744
745                 set(PLATFORM_LINKFLAGS "/SUBSYSTEM:CONSOLE /STACK:2097152 /INCREMENTAL:NO /NODEFAULTLIB:msvcrt.lib /NODEFAULTLIB:msvcmrt.lib /NODEFAULTLIB:msvcurt.lib /NODEFAULTLIB:msvcrtd.lib")
746
747                 # MSVC only, Mingw doesnt need
748                 if(CMAKE_CL_64)
749                         set(PLATFORM_LINKFLAGS "/MACHINE:X64 /OPT:NOREF ${PLATFORM_LINKFLAGS}")
750                 else()
751                         set(PLATFORM_LINKFLAGS "/MACHINE:IX86 /LARGEADDRESSAWARE ${PLATFORM_LINKFLAGS}")
752                 endif()
753
754                 set(PLATFORM_LINKFLAGS_DEBUG "/NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:libc.lib")
755
756         else()
757                 # keep GCC spesific stuff here
758                 if(CMAKE_COMPILER_IS_GNUCC)
759                         set(PLATFORM_LINKLIBS "-lshell32 -lshfolder -lgdi32 -lmsvcrt -lwinmm -lmingw32 -lm -lws2_32 -lz -lstdc++ -lole32 -luuid")
760                         set(PLATFORM_CFLAGS "-pipe -funsigned-char -fno-strict-aliasing")
761
762                         add_definitions(-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE)
763                 endif()
764
765                 add_definitions(-DFREE_WINDOWS)
766
767                 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_DEBUG")
768                 set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_DEBUG")
769
770                 if(WITH_INTERNATIONAL)
771                         set(GETTEXT ${LIBDIR}/gcc/gettext)
772                         set(GETTEXT_INC ${GETTEXT}/include)
773                         set(GETTEXT_LIBPATH ${GETTEXT}/lib)
774                         set(GETTEXT_LIB intl)
775                 endif()
776
777                 set(JPEG_LIBRARIES libjpeg)
778                 set(PNG_LIBRARIES png)
779
780                 set(ZLIB ${LIBDIR}/zlib)
781                 set(ZLIB_INCLUDE_DIRS ${ZLIB}/include)
782                 set(ZLIB_LIBPATH ${ZLIB}/lib)
783                 set(ZLIB_LIBRARIES z)
784
785                 set(PTHREADS ${LIBDIR}/pthreads)
786                 set(PTHREADS_INCLUDE_DIRS ${PTHREADS}/include)
787                 set(PTHREADS_LIBPATH ${PTHREADS}/lib)
788                 set(PTHREADS_LIBRARIES pthreadGC2)
789                 
790                 set(FREETYPE ${LIBDIR}/gcc/freetype)
791                 set(FREETYPE_INCLUDE_DIRS ${FREETYPE}/include ${FREETYPE}/include/freetype2)
792                 set(FREETYPE_LIBPATH ${FREETYPE}/lib)
793                 set(FREETYPE_LIBRARY freetype)
794
795                 if(WITH_FFTW3)
796                         set(FFTW3 ${LIBDIR}/gcc/fftw3)
797                         set(FFTW3_LIBRARIES fftw3)
798                         set(FFTW3_INCLUDE_DIRS ${FFTW3}/include)
799                         set(FFTW3_LIBPATH ${FFTW3}/lib)
800                 endif()
801
802                 if(WITH_OPENCOLLADA)
803                         set(OPENCOLLADA ${LIBDIR}/gcc/opencollada)
804                         set(OPENCOLLADA_INCLUDE_DIR ${OPENCOLLADA}/include)
805                         set(OPENCOLLADA_LIBPATH ${OPENCOLLADA}/lib ${OPENCOLLADA}/lib)
806                         set(OPENCOLLADA_LIBRARIES OpenCOLLADAStreamWriter OpenCOLLADASaxFrameworkLoader OpenCOLLADAFramework OpenCOLLADABaseUtils GeneratedSaxParser UTF MathMLSolver expat pcre buffer ftoa)
807                         set(PCRE_LIB pcre)
808                 endif()
809                 
810                 if(WITH_CODEC_FFMPEG)
811                         set(FFMPEG ${LIBDIR}/ffmpeg)
812                         set(FFMPEG_INCLUDE_DIRS ${FFMPEG}/include ${FFMPEG}/include)
813                         set(FFMPEG_LIBRARIES avcodec-52 avformat-52 avdevice-52 avutil-50 swscale-0)
814                         set(FFMPEG_LIBPATH ${FFMPEG}/lib)
815                 endif()
816
817                 if(WITH_IMAGE_OPENEXR)
818                         set(OPENEXR ${LIBDIR}/gcc/openexr)
819                         set(OPENEXR_INCLUDE_DIRS ${OPENEXR}/include/OpenEXR)
820                         set(OPENEXR_LIBRARIES Half IlmImf Imath IlmThread Iex)
821                         set(OPENEXR_LIBPATH ${OPENEXR}/lib)
822                 endif()
823
824                 if(WITH_IMAGE_TIFF)
825                         set(TIFF ${LIBDIR}/gcc/tiff)
826                         set(TIFF_LIBRARY tiff)
827                         set(TIFF_INCLUDE_DIR ${TIFF}/include)
828                         set(TIFF_LIBPATH ${TIFF}/lib)
829                 endif()
830
831                 if(WITH_JACK)
832                         set(JACK ${LIBDIR}/jack)
833                         set(JACK_INCLUDE_DIRS ${JACK}/include/jack ${JACK}/include)
834                         set(JACK_LIBRARIES jack)
835                         set(JACK_LIBPATH ${JACK}/lib)
836                         
837                         # TODO, gives linking errors, force off
838                         set(WITH_JACK OFF)
839                 endif()
840
841                 if(WITH_PYTHON)
842                         # normally cached but not since we include them with blender
843                         set(PYTHON_VERSION 3.2) #  CACHE STRING)
844                         set(PYTHON_INCLUDE_DIR "${LIBDIR}/python/include/python${PYTHON_VERSION}")  # CACHE PATH)
845                         set(PYTHON_LIBRARY "${LIBDIR}/python/lib/python32mw.lib")  # CACHE FILEPATH)
846
847                         # uncached vars
848                         set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}")
849                         set(PYTHON_LIBRARIES  "${PYTHON_LIBRARY}")
850                 endif()
851
852                 set(PLATFORM_LINKFLAGS "--stack,2097152")
853
854         endif()
855
856         # used in many places so include globally, like OpenGL
857         blender_include_dirs("${PTHREADS_INCLUDE_DIRS}")
858
859 elseif(APPLE)
860
861         if (${CMAKE_OSX_DEPLOYMENT_TARGET} STREQUAL "10.5")
862                 set(WITH_LIBS10.5 ON CACHE BOOL "Use 10.5 libs" FORCE)
863         endif()
864
865         if(WITH_LIBS10.5)
866                 set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/darwin-9.x.universal)
867         else()
868                 if(CMAKE_OSX_ARCHITECTURES MATCHES i386)
869                         set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/darwin-8.x.i386)
870                 else()
871                         set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/darwin-8.0.0-powerpc)
872                 endif()
873         endif()
874         
875
876         if(WITH_OPENAL)
877                 find_package(OpenAL)
878                 if(OPENAL_FOUND)
879                         set(WITH_OPENAL ON)
880                         set(OPENAL_INCLUDE_DIR "${LIBDIR}/openal/include")
881                 else()
882                         set(WITH_OPENAL OFF)
883                 endif()
884         endif()
885
886         if(WITH_JACK)
887                 set(JACK /usr)
888                 set(JACK_INCLUDE_DIRS ${JACK}/include/jack)
889                 set(JACK_LIBRARIES jack)
890                 set(JACK_LIBPATH ${JACK}/lib)
891         endif()
892
893         if(WITH_CODEC_SNDFILE)
894                 set(SNDFILE ${LIBDIR}/sndfile)
895                 set(SNDFILE_INCLUDE_DIRS ${SNDFILE}/include)
896                 set(SNDFILE_LIBRARIES sndfile FLAC ogg vorbis vorbisenc)
897                 set(SNDFILE_LIBPATH ${SNDFILE}/lib ${FFMPEG}/lib)  # TODO, deprecate
898         endif()
899
900         if(WITH_PYTHON)
901                 set(PYTHON_VERSION 3.2)
902                 if(PYTHON_VERSION MATCHES 3.2)
903                         # we use precompiled libraries for py 3.2 and up by default
904
905                         # normally cached but not since we include them with blender
906                         set(PYTHON_INCLUDE_DIR "${LIBDIR}/python/include/python${PYTHON_VERSION}")
907                         # set(PYTHON_BINARY "${LIBDIR}/python/bin/python${PYTHON_VERSION}") # not used yet
908                         set(PYTHON_LIBRARY python${PYTHON_VERSION})
909                         set(PYTHON_LIBPATH "${LIBDIR}/python/lib/python${PYTHON_VERSION}")
910                         # set(PYTHON_LINKFLAGS "-u _PyMac_Error")  # won't  build with this enabled
911                 else()
912                         # otherwise, use custom system framework
913                         # *not used but maintained incase some dev wants to*
914
915                         set(PYTHON "/System/Library/Frameworks/Python.framework/Versions/" CACHE PATH)
916                         set(PYTHON_INCLUDE_DIR "${PYTHON}${PYTHON_VERSION}/include/python${PYTHON_VERSION}" CACHE PATH)
917                         # set(PYTHON_BINARY ${PYTHON}${PYTHON_VERSION}/bin/python${PYTHON_VERSION}) # not used yet
918                         set(PYTHON_LIBRARY "" CACHE FILEPATH)
919                         set(PYTHON_LIBPATH "${PYTHON}${PYTHON_VERSION}/lib/python${PYTHON_VERSION}/config" CACHE PATH)
920                         set(PYTHON_LINKFLAGS "-u _PyMac_Error -framework System -framework Python" CACHE STRING)
921                         unset(PYTHON)
922                 endif()
923
924                 # uncached vars
925                 set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}")
926                 set(PYTHON_LIBRARIES  "${PYTHON_LIBRARY}")
927         endif()
928
929         if(WITH_INTERNATIONAL)
930                 set(GETTEXT ${LIBDIR}/gettext)
931                 set(GETTEXT_INC "${GETTEXT}/include")
932                 set(GETTEXT_LIB intl iconv)
933                 set(GETTEXT_LIBPATH ${GETTEXT}/lib)
934         endif()
935
936         if(WITH_FFTW3)
937                 set(FFTW3 ${LIBDIR}/fftw3)
938                 set(FFTW3_INCLUDE_DIRS ${FFTW3}/include)
939                 set(FFTW3_LIBRARIES fftw3)
940                 set(FFTW3_LIBPATH ${FFTW3}/lib)
941         endif()
942
943         set(PNG_LIBRARIES png)
944         set(JPEG_LIBRARIES jpeg)
945
946         set(ZLIB /usr)
947         set(ZLIB_INCLUDE_DIRS "${ZLIB}/include")
948         set(ZLIB_LIBRARIES z bz2)
949
950         set(FREETYPE ${LIBDIR}/freetype)
951         set(FREETYPE_INCLUDE_DIRS ${FREETYPE}/include ${FREETYPE}/include/freetype2)
952         set(FREETYPE_LIBPATH ${FREETYPE}/lib)
953         set(FREETYPE_LIBRARY freetype)
954
955         if(WITH_IMAGE_OPENEXR)
956                 set(OPENEXR ${LIBDIR}/openexr)
957                 set(OPENEXR_INCLUDE_DIRS ${OPENEXR}/include/OpenEXR)
958                 set(OPENEXR_LIBRARIES Iex Half IlmImf Imath IlmThread)
959                 set(OPENEXR_LIBPATH ${OPENEXR}/lib)
960         endif()
961
962         if(WITH_CODEC_FFMPEG)
963                 set(FFMPEG ${LIBDIR}/ffmpeg)
964                 set(FFMPEG_INCLUDE_DIRS ${FFMPEG}/include)
965                 set(FFMPEG_LIBRARIES avcodec avdevice avformat avutil mp3lame swscale x264 xvidcore theora theoradec theoraenc vorbis vorbisenc vorbisfile ogg)
966                 set(FFMPEG_LIBPATH ${FFMPEG}/lib)
967                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__STDC_CONSTANT_MACROS")
968         endif()
969
970         if(WITH_SAMPLERATE)
971                 set(SAMPLERATE ${LIBDIR}/samplerate)
972                 set(SAMPLERATE_INCLUDE_DIRS ${SAMPLERATE}/include)
973                 set(SAMPLERATE_LIBRARIES samplerate)
974                 set(SAMPLERATE_LIBPATH ${SAMPLERATE}/lib)
975         endif()
976
977         set(PLATFORM_LINKLIBS stdc++ SystemStubs)
978
979         if(WITH_COCOA)
980                 set(PLATFORM_CFLAGS "-pipe -funsigned-char -DGHOST_COCOA")
981                 set(PLATFORM_LINKFLAGS "-fexceptions -framework CoreServices -framework Foundation -framework IOKit -framework AppKit -framework Cocoa -framework Carbon -framework AudioUnit -framework AudioToolbox -framework CoreAudio")
982                 if(USE_QTKIT)
983                         set(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -DUSE_QTKIT")
984                         set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -framework QTKit")
985                         if(CMAKE_OSX_ARCHITECTURES MATCHES i386)
986                                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -framework QuickTime")
987                                 #libSDL still needs 32bit carbon quicktime 
988                         endif()
989                 elseif(WITH_CODEC_QUICKTIME)
990                         set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -framework QuickTime")
991                 endif()
992         else()
993                 set(PLATFORM_CFLAGS "-pipe -funsigned-char")
994                 set(PLATFORM_LINKFLAGS "-fexceptions -framework CoreServices -framework Foundation -framework IOKit -framework AppKit -framework Carbon -framework AGL -framework AudioUnit -framework AudioToolbox -framework CoreAudio -framework QuickTime")
995         endif()
996
997         if(WITH_OPENCOLLADA)
998                 set(OPENCOLLADA ${LIBDIR}/opencollada)
999                 set(OPENCOLLADA_INCLUDE_DIR ${OPENCOLLADA}/include)
1000                 set(OPENCOLLADA_LIBPATH ${OPENCOLLADA}/lib)
1001                 set(OPENCOLLADA_LIBRARIES "OpenCOLLADASaxFrameworkLoader -lOpenCOLLADAFramework -lOpenCOLLADABaseUtils -lOpenCOLLADAStreamWriter -lMathMLSolver -lGeneratedSaxParser -lUTF -lxml2 -lbuffer -lftoa" )
1002                 #pcre is bundled with openCollada
1003                 #set(PCRE ${LIBDIR}/pcre)
1004                 #set(PCRE_LIBPATH ${PCRE}/lib)
1005                 set(PCRE_LIB pcre)
1006                 #libxml2 is used
1007                 #set(EXPAT ${LIBDIR}/expat)
1008                 #set(EXPAT_LIBPATH ${EXPAT}/lib)
1009                 set(EXPAT_LIB)
1010         endif()
1011
1012         if(WITH_SDL)
1013                 set(SDL ${LIBDIR}/sdl)
1014                 set(SDL_INCLUDE_DIR ${SDL}/include)
1015                 set(SDL_LIBRARY SDL)
1016                 set(SDL_LIBPATH ${SDL}/lib)
1017         endif()
1018
1019         set(PNG "${LIBDIR}/png")
1020         set(PNG_INCLUDE_DIR "${PNG}/include")
1021         set(PNG_LIBPATH ${PNG}/lib)
1022
1023         set(JPEG "${LIBDIR}/jpeg")
1024         set(JPEG_INCLUDE_DIR "${JPEG}/include")
1025         set(JPEG_LIBPATH ${JPEG}/lib)
1026
1027         if(WITH_IMAGE_TIFF)
1028                 set(TIFF ${LIBDIR}/tiff)
1029                 set(TIFF_INCLUDE_DIR ${TIFF}/include)
1030                 set(TIFF_LIBRARY tiff)
1031                 set(TIFF_LIBPATH ${TIFF}/lib)
1032         endif()
1033
1034         set(EXETYPE MACOSX_BUNDLE)
1035
1036         set(CMAKE_C_FLAGS_DEBUG "-fno-strict-aliasing -g")
1037         set(CMAKE_CXX_FLAGS_DEBUG "-fno-strict-aliasing -g")
1038         if(CMAKE_OSX_ARCHITECTURES MATCHES "i386")
1039                 set(CMAKE_CXX_FLAGS_RELEASE "-O3 -mdynamic-no-pic -ftree-vectorize -msse -msse2 -fvariable-expansion-in-unroller")
1040                 set(CMAKE_C_FLAGS_RELEASE "-O3 -mdynamic-no-pic -ftree-vectorize -msse -msse2 -fvariable-expansion-in-unroller")
1041         elseif(CMAKE_OSX_ARCHITECTURES MATCHES "x86_64")
1042                 set(CMAKE_CXX_FLAGS_RELEASE "-O3 -mdynamic-no-pic -ftree-vectorize -msse -msse2 -msse3 -mssse3 -fvariable-expansion-in-unroller")
1043                 set(CMAKE_C_FLAGS_RELEASE "-O3 -mdynamic-no-pic -ftree-vectorize -msse -msse2 -msse3 -mssse3 -fvariable-expansion-in-unroller")
1044         else()
1045                 set(CMAKE_C_FLAGS_RELEASE "-mdynamic-no-pic -fno-strict-aliasing")
1046                 set(CMAKE_CXX_FLAGS_RELEASE "-mdynamic-no-pic -fno-strict-aliasing")
1047         endif()
1048 endif()
1049
1050 #-----------------------------------------------------------------------------
1051 # Common.
1052
1053 if(APPLE OR WIN32)
1054         if(NOT EXISTS "${LIBDIR}/")
1055                 message(FATAL_ERROR "Apple and Windows require pre-compiled libs at: '${LIBDIR}'")
1056         endif()
1057 endif()
1058
1059 if(WITH_RAYOPTIMIZATION)
1060         if(CMAKE_COMPILER_IS_GNUCC)
1061                 if(SUPPORT_SSE_BUILD)
1062                         set(PLATFORM_CFLAGS " -msse ${PLATFORM_CFLAGS}")
1063                         add_definitions(-D__SSE__ -D__MMX__)
1064                 endif()
1065                 if(SUPPORT_SSE2_BUILD)
1066                         set(PLATFORM_CFLAGS " -msse2 ${PLATFORM_CFLAGS}")
1067                         add_definitions(-D__SSE2__)
1068                         if(NOT SUPPORT_SSE_BUILD) # dont double up
1069                                 add_definitions(-D__MMX__)
1070                         endif()
1071                 endif()
1072         endif()
1073 endif()
1074
1075 if(WITH_IMAGE_OPENJPEG)
1076         if(UNIX AND NOT APPLE)
1077                 # dealt with above
1078         else()
1079                 set(OPENJPEG_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/extern/libopenjpeg")
1080         endif()
1081 endif()
1082
1083 if(WITH_IMAGE_REDCODE)
1084         set(REDCODE ${CMAKE_SOURCE_DIR}/extern)
1085         set(REDCODE_INC ${REDCODE})
1086 endif()
1087
1088 #-----------------------------------------------------------------------------
1089 # Blender WebPlugin
1090
1091 if(WITH_WEBPLUGIN) 
1092         set(GECKO_DIR "${CMAKE_SOURCE_DIR}/../gecko-sdk/" CACHE PATH "Gecko SDK path")
1093         set(WEBPLUGIN_SANDBOX_MODE "apparmor" CACHE STRING "WEB Plugin sandbox mode, can be apparmor, privsep, none")
1094
1095         set(WITH_PLAYER ON)
1096 endif()
1097
1098
1099 #-----------------------------------------------------------------------------
1100 # Configure OpenGL.
1101 find_package(OpenGL)
1102 blender_include_dirs_sys("${OPENGL_INCLUDE_DIR}")
1103 # unset(OPENGL_LIBRARIES CACHE) # not compat with older cmake 
1104 # unset(OPENGL_xmesa_INCLUDE_DIR CACHE) # not compat with older cmake 
1105
1106 #-----------------------------------------------------------------------------
1107 # Configure OpenMP.
1108 if(WITH_OPENMP)
1109         find_package(OpenMP)    
1110         if(OPENMP_FOUND)
1111                 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
1112                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
1113
1114                 if(APPLE AND ${CMAKE_GENERATOR} MATCHES "Xcode")
1115                         set(CMAKE_XCODE_ATTRIBUTE_ENABLE_OPENMP_SUPPORT "YES")
1116                 endif()
1117         else()
1118                 set(WITH_OPENMP OFF)
1119         endif()
1120
1121         mark_as_advanced(OpenMP_C_FLAGS)
1122         mark_as_advanced(OpenMP_CXX_FLAGS)
1123 endif() 
1124
1125 #-----------------------------------------------------------------------------
1126 # Configure GLEW
1127
1128 if(WITH_BUILTIN_GLEW)
1129         # set(GLEW_LIBRARY "")  # unused
1130         set(GLEW_INCLUDE_PATH "${CMAKE_SOURCE_DIR}/extern/glew/include")
1131 else()
1132         find_package(GLEW)
1133
1134         if(NOT GLEW_FOUND)
1135                 message(FATAL_ERROR "GLEW is required to build blender, install it or use WITH_BUILTIN_GLEW")
1136         endif()
1137
1138         mark_as_advanced(GLEW_LIBRARY)
1139         mark_as_advanced(GLEW_INCLUDE_PATH)
1140 endif()
1141
1142 #-----------------------------------------------------------------------------
1143 # Configure Python.
1144
1145 if(WITH_PYTHON_MODULE)
1146         add_definitions(-DPy_ENABLE_SHARED)
1147 endif() 
1148
1149 #-----------------------------------------------------------------------------
1150 # Extra compile flags
1151
1152 if((NOT WIN32) AND (NOT MSVC))
1153         # used for internal debug checks
1154         set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG")
1155         set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DDEBUG")
1156         
1157         # assert() checks for this.
1158         set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DNDEBUG")
1159         set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} -DNDEBUG")
1160         set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -DNDEBUG")
1161
1162         set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -DNDEBUG")
1163         set(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} -DNDEBUG")
1164         set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -DNDEBUG")
1165 endif()
1166
1167 if(CMAKE_COMPILER_IS_GNUCC)
1168
1169         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
1170         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_CAST_ALIGN -Wcast-align)
1171         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_DECLARATION_AFTER_STATEMENT -Werror=declaration-after-statement)
1172         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_IMPLICIT_FUNCTION_DECLARATION -Werror=implicit-function-declaration)
1173         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_RETURN_TYPE -Werror=return-type)
1174         # system headers sometimes do this, disable for now, was: -Werror=strict-prototypes
1175         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_STRICT_PROTOTYPES -Wstrict-prototypes)
1176         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_CHAR_SUBSCRIPTS -Wno-char-subscripts)
1177         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
1178         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_POINTER_ARITH -Wpointer-arith)
1179         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNUSED_PARAMETER -Wunused-parameter)
1180         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_WRITE_STRINGS -Wwrite-strings)
1181         # disable because it gives warnings for printf() & friends.
1182         # ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_DOUBLE_PROMOTION -Wdouble-promotion -Wno-error=double-promotion)
1183         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_ERROR_UNUSED_BUT_SET_VARIABLE -Wno-error=unused-but-set-variable)
1184
1185         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ALL -Wall)
1186         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_INVALID_OFFSETOF -Wno-invalid-offsetof)
1187         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_SIGN_COMPARE -Wno-sign-compare)
1188
1189 elseif(CMAKE_C_COMPILER_ID MATCHES "Intel")
1190
1191         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
1192         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_POINTER_ARITH -Wpointer-arith)
1193         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
1194
1195         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ALL -Wall)
1196         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_INVALID_OFFSETOF -Wno-invalid-offsetof)
1197         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_SIGN_COMPARE -Wno-sign-compare)
1198
1199 endif()
1200
1201 # MSVC2010 fails to links C++ libs right
1202 if(MSVC10)
1203         if(WITH_IMAGE_OPENEXR)
1204                 message(WARNING "MSVC 2010 does not support OpenEXR, disabling WITH_IMAGE_OPENEXR. To enable support use Use MSVC 2008")
1205                 set(WITH_IMAGE_OPENEXR OFF)
1206         endif()
1207         if(WITH_OPENCOLLADA)
1208                 message(WARNING "MSVC 2010 does not support OpenCollada, disabling WITH_OPENCOLLADA. To enable support use Use MSVC 2008")
1209                 set(WITH_OPENCOLLADA OFF)
1210         endif()
1211 endif()
1212
1213 if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
1214         if(WITH_IK_ITASC OR WITH_MOD_FLUID)
1215                 message(WARNING "Using Clang as CXX compiler: disabling WITH_IK_ITASC and WITH_MOD_FLUID, these features will be missing.")
1216                 set(WITH_IK_ITASC OFF)
1217                 set(WITH_MOD_FLUID OFF)
1218         endif()
1219 endif()
1220
1221
1222 # ensure python header is found since detection can fail, this could happen
1223 # with _any_ library but since we used a fixed python version this tends to
1224 # be most problematic.
1225 if(WITH_PYTHON)
1226         if(NOT EXISTS "${PYTHON_INCLUDE_DIR}/Python.h")
1227                 message(FATAL_ERROR "Missing: \"${PYTHON_INCLUDE_DIR}/Python.h\",\n"
1228                                                         "Set the cache entry 'PYTHON_INCLUDE_DIR' to point "
1229                                                         "to a valid python include path. Containing "
1230                                                         "Python.h for python version \"${PYTHON_VERSION}\"")
1231         endif()
1232 endif()
1233
1234
1235 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${PLATFORM_CFLAGS} ${C_WARNINGS}")
1236 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${PLATFORM_CFLAGS} ${CXX_WARNINGS}")
1237
1238 #-------------------------------------------------------------------------------
1239 # Global Defines
1240
1241 # better not set includes here but this debugging option is off by default.
1242 if(WITH_CXX_GUARDEDALLOC)
1243         include_directories(${CMAKE_SOURCE_DIR}/intern/guardedalloc)
1244 endif()
1245
1246 if(WITH_ASSERT_ABORT)
1247         add_definitions(-DWITH_ASSERT_ABORT)
1248 endif()
1249
1250 # message(STATUS "Using CFLAGS: ${CMAKE_C_FLAGS}")
1251 # message(STATUS "Using CXXFLAGS: ${CMAKE_CXX_FLAGS}")
1252
1253 #-----------------------------------------------------------------------------
1254 # Libraries
1255
1256 add_subdirectory(source)
1257 add_subdirectory(intern)
1258 add_subdirectory(extern)
1259
1260
1261 #-----------------------------------------------------------------------------
1262 # Blender Application
1263 if(WITH_BLENDER)
1264         add_subdirectory(source/creator)
1265 endif()
1266
1267
1268 #-----------------------------------------------------------------------------
1269 # Blender Player
1270 if(WITH_PLAYER)
1271         add_subdirectory(source/blenderplayer)
1272 endif()
1273
1274 #-----------------------------------------------------------------------------
1275 # CPack for generating packages
1276 include(build_files/cmake/packaging.cmake)
1277
1278
1279 #-----------------------------------------------------------------------------
1280 # Print Final Configuration
1281
1282 if(FIRST_RUN)
1283         set(_config_msg "\n* Blender Configuration *")
1284         macro(info_cfg_option
1285                 _setting)
1286                 set(_msg "   * ${_setting}")
1287                 string(LENGTH "${_msg}" _len)
1288                 while("28" GREATER "${_len}")
1289                         set(_msg "${_msg} ")
1290                          math(EXPR _len "${_len} + 1")
1291                 endwhile()
1292
1293                 set(_config_msg "${_config_msg}\n${_msg}${${_setting}}")
1294         endmacro()
1295
1296         macro(info_cfg_text
1297                 _text)
1298                 set(_config_msg "${_config_msg}\n\n  ${_text}")
1299                 
1300                 
1301         endmacro()
1302
1303         info_cfg_text("Build Options:")
1304         info_cfg_option(WITH_GAMEENGINE)
1305         info_cfg_option(WITH_PLAYER)
1306         info_cfg_option(WITH_BULLET)
1307         info_cfg_option(WITH_IK_ITASC)
1308         info_cfg_option(WITH_OPENCOLLADA)
1309         info_cfg_option(WITH_FFTW3)
1310         info_cfg_option(WITH_INTERNATIONAL)
1311
1312         info_cfg_text("Compiler Options:")
1313         info_cfg_option(WITH_BUILDINFO)
1314         info_cfg_option(WITH_OPENMP)
1315         info_cfg_option(WITH_RAYOPTIMIZATION)
1316
1317         info_cfg_text("System Options:")
1318         info_cfg_option(WITH_INSTALL_PORTABLE)
1319         info_cfg_option(WITH_X11_XINPUT)
1320         info_cfg_option(WITH_BUILTIN_GLEW)
1321
1322         info_cfg_text("Image Formats:")
1323         info_cfg_option(WITH_IMAGE_CINEON)
1324         info_cfg_option(WITH_IMAGE_DDS)
1325         info_cfg_option(WITH_IMAGE_HDR)
1326         info_cfg_option(WITH_IMAGE_OPENEXR)
1327         info_cfg_option(WITH_IMAGE_OPENJPEG)
1328         info_cfg_option(WITH_IMAGE_REDCODE)
1329         info_cfg_option(WITH_IMAGE_TIFF)
1330
1331         info_cfg_text("Audio:")
1332         info_cfg_option(WITH_OPENAL)
1333         info_cfg_option(WITH_SDL)
1334         info_cfg_option(WITH_JACK)
1335         info_cfg_option(WITH_CODEC_FFMPEG)
1336         info_cfg_option(WITH_CODEC_SNDFILE)
1337         info_cfg_option(WITH_SAMPLERATE)
1338
1339         info_cfg_text("Compression:")
1340         info_cfg_option(WITH_LZMA)
1341         info_cfg_option(WITH_LZO)
1342
1343         info_cfg_text("Python:")
1344         info_cfg_option(WITH_PYTHON_INSTALL)
1345         info_cfg_option(WITH_PYTHON_MODULE)
1346         info_cfg_option(WITH_PYTHON_SAFETY)
1347
1348         info_cfg_text("Modifiers:")
1349         info_cfg_option(WITH_MOD_BOOLEAN)
1350         info_cfg_option(WITH_MOD_DECIMATE)
1351         info_cfg_option(WITH_MOD_FLUID)
1352
1353         info_cfg_text("")
1354
1355         message("${_config_msg}")
1356 endif()