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