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