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