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