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