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