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