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