fix for user reported issues
[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 # this starts out unset
53 set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/build_files/cmake/Modules/")
54
55 # quiet output for Makefiles, 'make -s' helps too
56 # set_property(GLOBAL PROPERTY RULE_MESSAGES OFF)
57
58 # ignore system set flag, use our own
59 # must be before project(...)
60 # if the user wants to add their own its ok after first run.
61 if(DEFINED CMAKE_C_STANDARD_LIBRARIES)
62         set(_reset_standard_libraries OFF)
63 else()
64         set(_reset_standard_libraries ON)
65 endif()
66
67
68 project(Blender)
69
70
71 if (_reset_standard_libraries)
72         # Must come after project(...)
73         #
74         # MINGW workaround for -ladvapi32 being included which surprisingly causes
75         # string formatting of floats, eg: printf("%.*f", 3, value). to crash blender
76         # with a meaningless stack trace. by overriding this flag we ensure we only
77         # have libs we define and that cmake & scons builds match.
78         set(CMAKE_C_STANDARD_LIBRARIES "" CACHE STRING "" FORCE)
79         set(CMAKE_CXX_STANDARD_LIBRARIES "" CACHE STRING "" FORCE)
80         mark_as_advanced(CMAKE_C_STANDARD_LIBRARIES)
81         mark_as_advanced(CMAKE_CXX_STANDARD_LIBRARIES)
82 endif()
83 unset(_reset_standard_libraries)
84
85
86 enable_testing()
87
88 #-----------------------------------------------------------------------------
89 # Redirect output files
90
91 set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin CACHE INTERNAL "" FORCE )
92 set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib CACHE INTERNAL "" FORCE )
93
94 #-----------------------------------------------------------------------------
95 # Load some macros.
96 include(build_files/cmake/macros.cmake)
97
98 #-----------------------------------------------------------------------------
99 # Set default config options
100
101 get_blender_version()
102
103 # Blender internal features
104 option(WITH_INTERNATIONAL "Enable I18N (International fonts and text)" ON)
105
106 option(WITH_PYTHON        "Enable Embedded Python API  (only disable for development)" ON)
107 option(WITH_PYTHON_SECURITY "Disables execution of scripts within blend files by default (recommend to leave off)" OFF)
108 mark_as_advanced(WITH_PYTHON)  # dont want people disabling this unless they really know what they are doing.
109 mark_as_advanced(WITH_PYTHON_SECURITY)  # some distrobutions see this as a security issue, rather then have them patch it, make a build option.
110
111 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)
112 option(WITH_PYTHON_MODULE "Enable building as a python module (experemental, only enable for development)" OFF)
113 option(WITH_BUILDINFO     "Include extra build details (only disable for development & faster builds)" ON)
114 option(WITH_IK_ITASC      "Enable ITASC IK solver (only disable for development & for incompatible C++ compilers)" ON)
115 option(WITH_FFTW3         "Enable FFTW3 support (Used for smoke and audio effects)" OFF)
116 option(WITH_BULLET        "Enable Bullet (Physics Engine)" ON)
117 option(WITH_GAMEENGINE    "Enable Game Engine" ON)
118 option(WITH_PLAYER        "Build Player" OFF)
119 # (unix defaults to OpenMP On)
120 if(UNIX AND NOT APPLE)
121         option(WITH_OPENMP        "Enable OpenMP (has to be supported by the compiler)" ON)
122 else()
123         option(WITH_OPENMP        "Enable OpenMP (has to be supported by the compiler)" OFF)
124 endif()
125
126 if(UNIX AND NOT APPLE)
127         option(WITH_X11_XINPUT "Enable X11 Xinput (tablet support)"     ON)
128         option(WITH_BUILTIN_GLEW "Use GLEW OpenGL wrapper library bundled with blender" ON)
129 else()
130         # not an option for other OS's
131         set(WITH_BUILTIN_GLEW ON)
132 endif()
133
134 # Modifiers
135 option(WITH_MOD_FLUID           "Enable Elbeem Modifier (Fluid Simulation)" ON)
136 option(WITH_MOD_DECIMATE        "Enable Decimate Modifier" ON)
137 option(WITH_MOD_BOOLEAN         "Enable Boolean Modifier" ON)
138 option(WITH_MOD_CLOTH_ELTOPO    "Enable Experemental cloth solver" OFF)
139 mark_as_advanced(WITH_MOD_CLOTH_ELTOPO)
140
141 # Image format support
142 option(WITH_IMAGE_OPENEXR       "Enable OpenEXR Support (http://www.openexr.com)" ON)
143 option(WITH_IMAGE_OPENJPEG      "Enable OpenJpeg Support (http://www.openjpeg.org)" ON)
144 option(WITH_IMAGE_TIFF          "Enable LibTIFF Support" ON)
145 option(WITH_IMAGE_DDS           "Enable DDS Image Support" ON)
146 option(WITH_IMAGE_CINEON        "Enable CINEON and DPX Image Support" ON)
147 option(WITH_IMAGE_HDR           "Enable HDR Image Support" ON)
148 option(WITH_IMAGE_REDCODE       "Enable RedCode Image Support" OFF)
149
150 # Audio/Video format support
151 option(WITH_CODEC_FFMPEG        "Enable FFMPeg Support (http://ffmpeg.mplayerhq.hu)" OFF)
152 option(WITH_CODEC_SNDFILE       "Enable libsndfile Support (http://www.mega-nerd.com/libsndfile)" OFF)
153 if(APPLE OR (WIN32 AND NOT UNIX))
154         option(WITH_CODEC_QUICKTIME     "Enable Quicktime Support" OFF)
155 endif()
156
157 # 3D format support
158 # disable opencollada on non-apple unix because opencollada has no package for debian
159 option(WITH_OPENCOLLADA         "Enable OpenCollada Support (http://www.opencollada.org)"       OFF)
160
161 # Sound output
162 option(WITH_SDL           "Enable SDL for sound and joystick support" ON)
163 option(WITH_OPENAL        "Enable OpenAL Support (http://www.openal.org)" ON)
164 option(WITH_JACK          "Enable Jack Support (http://www.jackaudio.org)" OFF)
165 option(WITH_SAMPLERATE    "Enable samplerate conversion" ON)
166
167 # Compression
168 option(WITH_LZO           "Enable fast LZO compression (used for pointcache)" ON)
169 option(WITH_LZMA          "Enable best LZMA compression, (used for pointcache)" ON)
170
171 # Misc
172 option(WITH_RAYOPTIMIZATION     "Enable use of SIMD (SSE) optimizations for the raytracer" ON) 
173 if(UNIX AND NOT APPLE)
174         option(WITH_INSTALL_PORTABLE "Install redistributeable runtime, otherwise install into CMAKE_INSTALL_PREFIX" ON)
175 endif()
176 option(WITH_PYTHON_INSTALL       "Copy system python into the blender install folder" ON)
177
178 # disable for now, but plan to support on all platforms eventually
179 option(WITH_MEM_JEMALLOC   "Enable malloc replacement (http://www.canonware.com/jemalloc)" OFF)
180 mark_as_advanced(WITH_MEM_JEMALLOC)
181
182 # Debug
183 option(WITH_CXX_GUARDEDALLOC "Enable GuardedAlloc for C++ memory allocation tracking (only enable for development)" OFF)
184 mark_as_advanced(WITH_CXX_GUARDEDALLOC)
185
186 option(WITH_ASSERT_ABORT "Call abort() when raising an assertion through BLI_assert()" OFF)
187 mark_as_advanced(WITH_ASSERT_ABORT)
188
189 if(APPLE)
190         if(NOT CMAKE_OSX_ARCHITECTURES)
191                 set(CMAKE_OSX_ARCHITECTURES x86_64 CACHE STRING
192                 "Choose the architecture you want to build Blender for: i386, x86_64 or ppc"
193                 FORCE)
194         endif()
195         if(NOT CMAKE_OSX_DEPLOYMENT_TARGET)
196                 set(CMAKE_OSX_DEPLOYMENT_TARGET 10.5 CACHE STRING
197                 "Choose the minimum OSX version required: 10.4 or 10.5"
198                 FORCE)
199         endif()
200         option(WITH_COCOA         "Use Cocoa framework instead of deprecated Carbon" ON)
201         option(USE_QTKIT          "Use QtKit instead of Carbon quicktime (needed for having partial quicktime for 64bit)" OFF)
202         option(WITH_LIBS10.5  "Use 10.5 libs (needed for 64bit builds)" OFF)
203 endif()
204
205 # only for developers who want to make this functional
206 # option(WITH_LCMS          "Enable color correction with lcms" OFF)
207
208 if(NOT WITH_GAMEENGINE AND WITH_PLAYER)
209         message(FATAL_ERROR "WITH_PLAYER requires WITH_GAMEENGINE")
210 endif()
211
212 if(NOT WITH_SAMPLERATE AND (WITH_OPENAL OR WITH_SDL OR WITH_JACK))
213         message(FATAL_ERROR "WITH_OPENAL/WITH_SDL/WITH_JACK require WITH_SAMPLERATE")
214 endif()
215
216 if(NOT WITH_IMAGE_OPENJPEG AND WITH_IMAGE_REDCODE)
217         message(FATAL_ERROR "WITH_IMAGE_REDCODE requires WITH_IMAGE_OPENJPEG")
218 endif()
219
220 # python module, needs some different options
221 if(WITH_PYTHON_MODULE AND WITH_PLAYER)
222         message(FATAL_ERROR "WITH_PYTHON_MODULE requires WITH_PLAYER to be OFF")
223 endif()
224
225 if(WITH_PYTHON_MODULE AND WITH_PYTHON_INSTALL)
226         message(FATAL_ERROR "WITH_PYTHON_MODULE requires WITH_PYTHON_INSTALL to be OFF")
227 endif()
228
229 # remove old vars
230 unset(WITH_INSTALL CACHE)
231
232 TEST_SSE_SUPPORT()
233
234 #-----------------------------------------------------------------------------
235 # Initialize un-cached vars, avoid unused warning
236
237 # linux only, not cached
238 set(WITH_BINRELOC OFF)
239
240 # these are added to later on.
241 set(C_WARNINGS "")
242 set(CXX_WARNINGS "")
243
244
245 # disabled for now, not supported
246 # option(WITH_WEBPLUGIN     "Enable Web Plugin (Unix only)" OFF)
247
248 # For alternate Python locations the commandline can be used to override detected/default cache settings, e.g:
249 # On Unix: 
250 #   cmake ../blender \
251 #         -D PYTHON_VERSION=3.2 \
252 #         -D PYTHON_INCLUDE_DIRS=/opt/py32/include/python3.2d \
253 #         -D PYTHON_LIBPATH=/opt/py32/lib \
254 #         -D PYTHON_LIBRARY=python3.2d
255 #
256 # On Macs: 
257 #   cmake ../blender \
258 #         -D PYTHON_INCLUDE_DIRS=/System/Library/Frameworks/Python.framework/Versions/3.2/include/python3.2 \
259 #         -D PYTHON_LIBPATH=/System/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/config \
260 #         -G Xcode
261 #
262 # When changing any of this remember to update the notes in doc/build_systems/cmake.txt
263
264 #-----------------------------------------------------------------------------
265 #Platform specifics
266
267 if(UNIX AND NOT APPLE)
268         
269         # needed for ubuntu 11.04
270         if(EXISTS "/usr/lib/x86_64-linux-gnu")
271                 set(CMAKE_LIBRARY_PATH "/usr/lib/x86_64-linux-gnu;${CMAKE_LIBRARY_PATH}")
272         endif()
273
274         if(WITH_OPENAL)
275                 find_package(OpenAL)
276                 if(NOT OPENAL_FOUND)
277                         set(WITH_OPENAL OFF)
278                 endif()
279         endif()
280
281         if(WITH_JACK)
282                 set(JACK /usr)
283                 set(JACK_INC ${JACK}/include/jack)
284                 set(JACK_LIB jack)
285                 set(JACK_LIBPATH ${JACK}/lib)
286         endif()
287
288         if(WITH_CODEC_SNDFILE)
289                 set(SNDFILE /usr)
290                 set(SNDFILE_INC ${SNDFILE}/include)
291                 set(SNDFILE_LIB sndfile)
292                 set(SNDFILE_LIBPATH ${SNDFILE}/lib)
293         endif()
294
295         if(WITH_INTERNATIONAL)
296                 find_library(INTL_LIBRARY
297                         NAMES intl
298                         PATHS
299                         /sw/lib
300                 )
301
302                 find_library(ICONV_LIBRARY
303                         NAMES iconv
304                         PATHS
305                         /sw/lib
306                 )
307                 mark_as_advanced(ICONV_LIBRARY)
308                 mark_as_advanced(INTL_LIBRARY)
309
310                 if(INTL_LIBRARY AND ICONV_LIBRARY)
311                         set(GETTEXT_LIB ${INTL_LIBRARY} ${ICONV_LIBRARY})
312                 endif()
313         endif()
314
315         find_package(Freetype)
316         # unset(FREETYPE_INCLUDE_DIRS CACHE) # cant use
317
318
319         if(WITH_PYTHON)
320                 # No way to set py32. remove for now.
321                 # find_package(PythonLibs)
322
323                 # defines...
324                 
325                 #  PYTHON_VERSION
326                 #  PYTHON_INCLUDE_DIRS
327                 #  PYTHON_LIBRARY
328                 #  PYTHON_LIBPATH
329                 #  PYTHON_LINKFLAGS
330
331                 include(build_files/cmake/FindPythonLibsUnix.cmake)
332
333         endif()
334
335         if(WITH_SDL)
336                 find_package(SDL)
337                 mark_as_advanced(SDLMAIN_LIBRARY)
338                 mark_as_advanced(SDL_INCLUDE_DIR)
339                 mark_as_advanced(SDL_LIBRARY)
340                 mark_as_advanced(SDL_LIBRARY_TEMP)
341                 # unset(SDLMAIN_LIBRARY CACHE)
342                 if(NOT SDL_FOUND)
343                         set(WITH_SDL OFF)
344                 endif()
345         endif()
346
347         if(WITH_IMAGE_OPENEXR)
348                 set(OPENEXR /usr CACHE FILEPATH "OPENEXR Directory")
349                 mark_as_advanced(OPENEXR)
350                 find_path(OPENEXR_INC
351                         ImfXdr.h
352                         PATHS
353                         ${OPENEXR}/include/OpenEXR
354                         /usr/local/include/OpenEXR
355                         /sw/include/OpenEXR
356                         /opt/local/include/OpenEXR
357                         /opt/csw/include/OpenEXR
358                         /opt/include/OpenEXR
359                 )
360                 mark_as_advanced(OPENEXR_INC)
361
362                 set(OPENEXR_LIB Half IlmImf Iex Imath)
363                 
364                 if(NOT OPENEXR_INC)
365                         set(WITH_IMAGE_OPENEXR OFF)
366                 endif()
367         endif()
368
369         if(WITH_IMAGE_TIFF)
370                 find_package(TIFF)
371                 if(NOT TIFF_FOUND)
372                         set(WITH_IMAGE_TIFF OFF)
373                 endif()
374         endif()
375
376         find_package(JPEG REQUIRED)
377
378         find_package(PNG REQUIRED)
379
380         find_package(ZLIB REQUIRED)
381
382         if(WITH_LCMS)
383                 set(LCMS /usr CACHE FILEPATH "LCMS directory")
384                 set(LCMS_INCLUDE_DIR ${LCMS}/include)
385                 set(LCMS_LIBRARY lcms)
386                 set(LCMS_LIBPATH ${LCMS}/lib)
387         endif()
388
389         if(WITH_CODEC_FFMPEG)
390                 set(FFMPEG /usr CACHE FILEPATH "FFMPEG Directory")
391                 mark_as_advanced(FFMPEG)
392                 set(FFMPEG_INC ${FFMPEG}/include)
393                 set(FFMPEG_LIB avformat avcodec avutil avdevice swscale CACHE STRING "FFMPEG Libraries")
394                 mark_as_advanced(FFMPEG_LIB)
395                 set(FFMPEG_LIBPATH ${FFMPEG}/lib)
396                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__STDC_CONSTANT_MACROS")
397         endif()
398
399         if(WITH_FFTW3)
400                 set(FFTW3 /usr)
401                 set(FFTW3_INC ${FFTW3}/include)
402                 set(FFTW3_LIB fftw3)
403                 set(FFTW3_LIBPATH ${FFTW3}/lib)
404         endif()
405
406         if(WITH_SAMPLERATE)
407                 set(LIBSAMPLERATE /usr)
408                 set(LIBSAMPLERATE_INC ${LIBSAMPLERATE}/include)
409                 set(LIBSAMPLERATE_LIB samplerate)
410                 set(LIBSAMPLERATE_LIBPATH ${LIBSAMPLERATE}/lib)
411         endif()
412
413         if(WITH_OPENCOLLADA)
414                 set(OPENCOLLADA /usr/local/opencollada CACHE FILEPATH "OpenCollada Directory")
415                 mark_as_advanced(OPENCOLLADA)
416                 set(OPENCOLLADA_LIBPATH ${OPENCOLLADA}/lib)
417                 set(OPENCOLLADA_LIB OpenCOLLADAStreamWriter OpenCOLLADASaxFrameworkLoader OpenCOLLADAFramework OpenCOLLADABaseUtils GeneratedSaxParser UTF MathMLSolver pcre ftoa buffer xml2)
418                 set(OPENCOLLADA_INC ${OPENCOLLADA})
419
420                 set(PCRE /usr CACHE FILEPATH "PCRE Directory")
421                 mark_as_advanced(PCRE)
422                 set(PCRE_LIBPATH ${PCRE}/lib)
423                 set(PCRE_LIB pcre)
424
425                 set(EXPAT /usr CACHE FILEPATH "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                 set(JEMALLOC /usr)
433                 set(JEMALLOC_LIBRARY ljemalloc CACHE STRING "JeMalloc library")
434                 set(JEMALLOC_LIBPATH ${JEMALLOC}/lib  CACHE FILEPATH "JeMalloc library path")
435                 # no use for this yet.
436                 # set(JEMALLOC_INCLUDE_DIR ${JEMALLOC}/include  CACHE FILEPATH "JeMalloc include path")
437                 unset(JEMALLOC)
438         endif()
439
440         find_package(X11 REQUIRED)
441         find_path(X11_XF86keysym_INCLUDE_PATH X11/XF86keysym.h ${X11_INC_SEARCH_PATH})
442         mark_as_advanced(X11_XF86keysym_INCLUDE_PATH)
443
444         # OpenSuse needs lutil, ArchLinux not, for now keep, can avoid by using --as-needed
445         set(LLIBS "-lutil -lc -lm -lpthread -lstdc++ ${X11_X11_LIB}")
446
447         if(WITH_X11_XINPUT)
448                 list(APPEND LLIBS ${X11_Xinput_LIB})
449         endif()
450
451         if(CMAKE_SYSTEM_NAME MATCHES "Linux")
452                 if(NOT WITH_PYTHON_MODULE)
453                         # BSD's dont use libdl.so
454                         list(APPEND LLIBS -ldl)
455
456                         # binreloc is linux only
457                         set(BINRELOC ${CMAKE_SOURCE_DIR}/extern/binreloc)
458                         set(BINRELOC_INC ${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_INC ${ICONV}/include)
512                 set(ICONV_LIB iconv)
513                 set(ICONV_LIBPATH ${ICONV}/lib)
514         endif()
515
516         if(WITH_SAMPLERATE)
517                 set(LIBSAMPLERATE ${LIBDIR}/samplerate)
518                 set(LIBSAMPLERATE_INC ${LIBSAMPLERATE}/include)
519                 set(LIBSAMPLERATE_LIB libsamplerate)
520                 set(LIBSAMPLERATE_LIBPATH ${LIBSAMPLERATE}/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_INC ${SNDFILE}/include)
543                 set(SNDFILE_LIB libsndfile-1)
544                 set(SNDFILE_LIBPATH ${SNDFILE}/lib)
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_INC ${QUICKTIME}/CIncludes)
557                 set(QUICKTIME_LIB 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(LLIBS ws2_32 vfw32 winmm kernel32 user32 gdi32 comdlg32 advapi32 shfolder shell32 ole32 oleaut32 uuid )
568                 else()
569                         set(LLIBS kernel32 user32 gdi32 comdlg32 advapi32 shell32 ole32 oleaut32 uuid ws2_32 vfw32 winmm)
570                 endif()
571                 
572                 set(CMAKE_CXX_FLAGS "/D_CRT_NONSTDC_NO_DEPRECATE /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /we4013 /wd4018 /wd4800 /wd4244 /wd4305 /wd4065 /wd4267" CACHE STRING "MSVC MT C++ flags " FORCE)
573                 set(CMAKE_C_FLAGS   "/D_CRT_NONSTDC_NO_DEPRECATE /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /we4013 /wd4018 /wd4800 /wd4244 /wd4305 /wd4065 /wd4267" CACHE STRING "MSVC MT C++ flags " FORCE)
574
575                 if(CMAKE_CL_64)
576                         set(CMAKE_CXX_FLAGS_DEBUG "/D_DEBUG /Od /Gm /EHsc /RTC1 /MTd /W3 /nologo /Zi /J" CACHE STRING "MSVC MT flags " FORCE)
577                 else()
578                         set(CMAKE_CXX_FLAGS_DEBUG "/D_DEBUG /Od /Gm /EHsc /RTC1 /MTd /W3 /nologo /ZI /J" CACHE STRING "MSVC MT flags " FORCE)
579                 endif()
580                 set(CMAKE_CXX_FLAGS_RELEASE "/O2 /Ob2 /DNDEBUG /EHsc /MT /W3 /nologo /J" CACHE STRING "MSVC MT flags " FORCE)
581                 set(CMAKE_CXX_FLAGS_MINSIZEREL "/O1 /Ob1 /DNDEBUG /EHsc /MT /W3 /nologo /J" CACHE STRING "MSVC MT flags " FORCE)
582                 set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/O2 /Ob1 /DNDEBUG /EHsc /MT /W3 /nologo /Zi /J" CACHE STRING "MSVC MT flags " FORCE)
583                 if(CMAKE_CL_64)
584                         set(CMAKE_C_FLAGS_DEBUG "/D_DEBUG /Od /Gm /EHsc /RTC1 /MTd /W3 /nologo /Zi /J" CACHE STRING "MSVC MT flags " FORCE)
585                 else()
586                         set(CMAKE_C_FLAGS_DEBUG "/D_DEBUG /Od /Gm /EHsc /RTC1 /MTd /W3 /nologo /ZI /J" CACHE STRING "MSVC MT flags " FORCE)
587                 endif()
588                 set(CMAKE_C_FLAGS_RELEASE "/O2 /Ob2 /DNDEBUG /EHsc /MT /W3 /nologo /J" CACHE STRING "MSVC MT flags " FORCE)
589                 set(CMAKE_C_FLAGS_MINSIZEREL "/O1 /Ob1 /DNDEBUG /EHsc /MT /W3 /nologo /J" CACHE STRING "MSVC MT flags " FORCE)
590                 set(CMAKE_C_FLAGS_RELWITHDEBINFO "/O2 /Ob1 /DNDEBUG /EHsc /MT /W3 /nologo /Zi /J" CACHE STRING "MSVC MT flags " FORCE)
591
592                 if(WITH_INTERNATIONAL)
593                         set(GETTEXT ${LIBDIR}/gettext)
594                         set(GETTEXT_INC ${GETTEXT}/include)
595                         set(GETTEXT_LIBPATH ${GETTEXT}/lib)
596                         if(CMAKE_CL_64)
597                                 set(GETTEXT_LIB gettext)
598                         else()
599                                 set(GETTEXT_LIB gnu_gettext)
600                         endif()
601                 endif()
602
603                 if(CMAKE_CL_64)
604                         set(PNG_LIBRARIES libpng)
605                 else()
606                         set(PNG_LIBRARIES libpng_st)
607                 endif()
608                 set(JPEG_LIBRARIES libjpeg)
609
610                 set(ZLIB ${LIBDIR}/zlib)
611                 set(ZLIB_INCLUDE_DIRS ${ZLIB}/include)
612                 set(ZLIB_LIBPATH ${ZLIB}/lib)
613                 if(CMAKE_CL_64)
614                         set(ZLIB_LIBRARIES libz)
615                 else()
616                         set(ZLIB_LIBRARIES zlib)
617                 endif()
618
619                 set(PTHREADS ${LIBDIR}/pthreads)
620                 set(PTHREADS_INC ${PTHREADS}/include)
621                 set(PTHREADS_LIBPATH ${PTHREADS}/lib)
622                 set(PTHREADS_LIB pthreadVC2)
623                 
624                 set(FREETYPE ${LIBDIR}/freetype)
625                 set(FREETYPE_INCLUDE_DIRS ${FREETYPE}/include ${FREETYPE}/include/freetype2)
626                 set(FREETYPE_LIBPATH ${FREETYPE}/lib)
627                 set(FREETYPE_LIBRARY freetype2ST)
628
629                 if(WITH_FFTW3)
630                         set(FFTW3 ${LIBDIR}/fftw3)
631                         set(FFTW3_LIB libfftw)
632                         set(FFTW3_INC ${FFTW3}/include)
633                         set(FFTW3_LIBPATH ${FFTW3}/lib)
634                 endif()
635
636                 if(WITH_OPENCOLLADA)
637                         set(OPENCOLLADA ${LIBDIR}/opencollada)
638                         set(OPENCOLLADA_INC ${OPENCOLLADA}/include)
639                         set(OPENCOLLADA_LIBPATH ${OPENCOLLADA}/lib)
640                         set(OPENCOLLADA_LIB OpenCOLLADASaxFrameworkLoader OpenCOLLADAFramework OpenCOLLADABaseUtils OpenCOLLADAStreamWriter MathMLSolver GeneratedSaxParser xml2 buffer ftoa UTF)
641                         set(PCRE_LIB pcre)
642                 endif()
643                 
644                 if(WITH_LCMS)
645                         set(LCMS ${LIBDIR}/lcms)
646                         set(LCMS_INCLUDE_DIR ${LCMS}/include)
647                         set(LCMS_LIBPATH ${LCMS}/lib)
648                         set(LCMS_LIB lcms)
649                 endif()
650
651                 if(WITH_CODEC_FFMPEG)
652                         set(FFMPEG ${LIBDIR}/ffmpeg)
653                         set(FFMPEG_INC ${FFMPEG}/include ${FFMPEG}/include/msvc)
654                         set(FFMPEG_LIB avcodec-52 avformat-52 avdevice-52 avutil-50 swscale-0)
655                         set(FFMPEG_LIBPATH ${FFMPEG}/lib)
656                 endif()
657
658                 if(WITH_IMAGE_OPENEXR)
659                         if(MSVC80)
660                                 set(MSVC_LIB _vs2005)
661                                 set(MSVC_INC)
662                         elseif(MSVC90)
663                                 set(MSVC_LIB _vs2008)
664                                 set(MSVC_INC)
665                         elseif(MSVC10)
666                                 set(MSVC_LIB _vs2010)
667                                 set(MSVC_INC _vs2010)
668                         else()
669                                 set(MSVC_LIB msvc)
670                                 set(MSVC_INC)
671                         endif()
672                         set(OPENEXR ${LIBDIR}/openexr)                  
673                         set(OPENEXR_LIB Iex Half IlmImf Imath IlmThread)
674                         set(OPENEXR_LIBPATH ${OPENEXR}/lib${MSVC_LIB})
675                         set(OPENEXR_INCUDE ${OPENEXR}/include${MSVC_INC})
676                         set(OPENEXR_INC ${OPENEXR_INCUDE}/ ${OPENEXR_INCUDE}/IlmImf ${OPENEXR_INCUDE}/Iex ${OPENEXR_INCUDE}/Imath)
677                 endif()
678
679                 if(WITH_IMAGE_TIFF)
680                         set(TIFF ${LIBDIR}/tiff)
681                         set(TIFF_LIBRARY libtiff)
682                         set(TIFF_INCLUDE_DIR ${TIFF}/include)
683                         set(TIFF_LIBPATH ${TIFF}/lib)
684                 endif()
685
686                 if(WITH_JACK)
687                         set(JACK ${LIBDIR}/jack)
688                         set(JACK_INC ${JACK}/include/jack ${JACK}/include)
689                         set(JACK_LIB libjack)
690                         set(JACK_LIBPATH ${JACK}/lib)
691                 endif()
692
693                 if(WITH_PYTHON)
694                         set(PYTHON ${LIBDIR}/python)
695                         set(PYTHON_VERSION 3.2)
696                         set(PYTHON_INCLUDE_DIRS "${PYTHON}/include/python${PYTHON_VERSION}")
697                         # set(PYTHON_BINARY python) # not used yet
698                         set(PYTHON_LIBRARY python32)
699                         set(PYTHON_LIBPATH ${PYTHON}/lib)
700                 endif()
701
702                 # MSVC only, Mingw doesnt need
703                 if(CMAKE_CL_64)
704                         set(PLATFORM_LINKFLAGS "/MACHINE:X64 /NODEFAULTLIB:libc.lib /STACK:2097152 ")
705                 else()
706                         set(PLATFORM_LINKFLAGS "/NODEFAULTLIB:libc.lib /STACK:2097152 ")
707                 endif()
708
709                 set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /NODEFAULTLIB:libcmt.lib;libc.lib ")
710
711         else()
712                 # keep GCC spesific stuff here
713                 if(CMAKE_COMPILER_IS_GNUCC)
714                         set(LLIBS "-lshell32 -lshfolder -lgdi32 -lmsvcrt -lwinmm -lmingw32 -lm -lws2_32 -lz -lstdc++ -lole32 -luuid")
715                         set(PLATFORM_CFLAGS "-pipe -funsigned-char -fno-strict-aliasing")
716
717                         set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE")
718                         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE")
719                 endif()
720
721                 add_definitions(-DFREE_WINDOWS)
722
723                 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_DEBUG")
724                 set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_DEBUG")
725
726                 if(WITH_INTERNATIONAL)
727                         set(GETTEXT ${LIBDIR}/gcc/gettext)
728                         set(GETTEXT_INC ${GETTEXT}/include)
729                         set(GETTEXT_LIBPATH ${GETTEXT}/lib)
730                         set(GETTEXT_LIB intl)
731                 endif()
732
733                 set(JPEG_LIBRARIES libjpeg)
734                 set(PNG_LIBRARIES png)
735
736                 set(ZLIB ${LIBDIR}/zlib)
737                 set(ZLIB_INCLUDE_DIRS ${ZLIB}/include)
738                 set(ZLIB_LIBPATH ${ZLIB}/lib)
739                 set(ZLIB_LIBRARIES z)
740
741                 set(PTHREADS ${LIBDIR}/pthreads)
742                 set(PTHREADS_INC ${PTHREADS}/include)
743                 set(PTHREADS_LIBPATH ${PTHREADS}/lib)
744                 set(PTHREADS_LIB pthreadGC2)
745                 
746                 set(FREETYPE ${LIBDIR}/gcc/freetype)
747                 set(FREETYPE_INCLUDE_DIRS ${FREETYPE}/include ${FREETYPE}/include/freetype2)
748                 set(FREETYPE_LIBPATH ${FREETYPE}/lib)
749                 set(FREETYPE_LIBRARY freetype)
750
751                 if(WITH_FFTW3)
752                         set(FFTW3 ${LIBDIR}/gcc/fftw3)
753                         set(FFTW3_LIB fftw3)
754                         set(FFTW3_INC ${FFTW3}/include)
755                         set(FFTW3_LIBPATH ${FFTW3}/lib)
756                 endif()
757
758                 if(WITH_OPENCOLLADA)
759                         set(OPENCOLLADA ${LIBDIR}/gcc/opencollada)
760                         set(OPENCOLLADA_INC ${OPENCOLLADA}/include)
761                         set(OPENCOLLADA_LIBPATH ${OPENCOLLADA}/lib ${OPENCOLLADA}/lib)
762                         set(OPENCOLLADA_LIB OpenCOLLADAStreamWriter OpenCOLLADASaxFrameworkLoader OpenCOLLADAFramework OpenCOLLADABaseUtils GeneratedSaxParser UTF MathMLSolver expat pcre buffer ftoa)
763                         set(PCRE_LIB pcre)
764                 endif()
765                 
766                 if(WITH_CODEC_FFMPEG)
767                         set(FFMPEG ${LIBDIR}/ffmpeg)
768                         set(FFMPEG_INC ${FFMPEG}/include ${FFMPEG}/include)
769                         set(FFMPEG_LIB avcodec-52 avformat-52 avdevice-52 avutil-50 swscale-0)
770                         set(FFMPEG_LIBPATH ${FFMPEG}/lib)
771                 endif()
772
773                 if(WITH_IMAGE_OPENEXR)
774                         set(OPENEXR ${LIBDIR}/gcc/openexr)
775                         set(OPENEXR_INC ${OPENEXR}/include ${OPENEXR}/include/OpenEXR)
776                         set(OPENEXR_LIB Half IlmImf Imath IlmThread)
777                         set(OPENEXR_LIBPATH ${OPENEXR}/lib)
778
779                         # TODO, gives linking errors, force off
780                         set(WITH_IMAGE_OPENEXR OFF)
781                 endif()
782
783                 if(WITH_IMAGE_TIFF)
784                         set(TIFF ${LIBDIR}/gcc/tiff)
785                         set(TIFF_LIBRARY tiff)
786                         set(TIFF_INCLUDE_DIR ${TIFF}/include)
787                         set(TIFF_LIBPATH ${TIFF}/lib)
788                 endif()
789
790                 if(WITH_JACK)
791                         set(JACK ${LIBDIR}/jack)
792                         set(JACK_INC ${JACK}/include/jack ${JACK}/include)
793                         set(JACK_LIB jack)
794                         set(JACK_LIBPATH ${JACK}/lib)
795                         
796                         # TODO, gives linking errors, force off
797                         set(WITH_JACK OFF)
798                 endif()
799
800                 if(WITH_PYTHON)
801                         set(PYTHON ${LIBDIR}/python)
802                         set(PYTHON_VERSION 3.2)
803                         set(PYTHON_INCLUDE_DIRS "${PYTHON}/include/python${PYTHON_VERSION}")
804                         # set(PYTHON_BINARY python) # not used yet
805                         set(PYTHON_LIBRARY python32mw)
806                         set(PYTHON_LIBPATH ${PYTHON}/lib)
807                 endif()
808
809                 set(PLATFORM_LINKFLAGS "--stack,2097152")
810
811         endif()
812
813         # used in many places so include globally, like OpenGL
814         blender_include_dirs("${PTHREADS_INC}")
815
816 elseif(APPLE)
817
818         if (${CMAKE_OSX_DEPLOYMENT_TARGET} STREQUAL "10.5")
819                 set(WITH_LIBS10.5 ON CACHE BOOL "Use 10.5 libs" FORCE)
820         endif()
821
822         if(WITH_LIBS10.5)
823                 set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/darwin-9.x.universal)
824         else()
825                 if(CMAKE_OSX_ARCHITECTURES MATCHES i386)
826                         set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/darwin-8.x.i386)
827                 else()
828                         set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/darwin-8.0.0-powerpc)
829                 endif()
830         endif()
831         
832
833         if(WITH_OPENAL)
834                 find_package(OpenAL)
835                 if(OPENAL_FOUND)
836                         set(WITH_OPENAL ON)
837                         set(OPENAL_INCLUDE_DIR "${LIBDIR}/openal/include")
838                 else()
839                         set(WITH_OPENAL OFF)
840                 endif()
841         endif()
842
843         if(WITH_JACK)
844                 set(JACK /usr)
845                 set(JACK_INC ${JACK}/include/jack)
846                 set(JACK_LIB jack)
847                 set(JACK_LIBPATH ${JACK}/lib)
848         endif()
849
850         if(WITH_CODEC_SNDFILE)
851                 set(SNDFILE ${LIBDIR}/sndfile)
852                 set(SNDFILE_INC ${SNDFILE}/include)
853                 set(SNDFILE_LIB sndfile FLAC ogg vorbis vorbisenc)
854                 set(SNDFILE_LIBPATH ${SNDFILE}/lib ${FFMPEG}/lib)
855         endif()
856
857         set(PYTHON_VERSION 3.2)
858
859         if(PYTHON_VERSION MATCHES 3.2)
860                 # we use precompiled libraries for py 3.2 and up by default
861
862                 set(PYTHON ${LIBDIR}/python)
863                 set(PYTHON_INCLUDE_DIRS "${PYTHON}/include/python${PYTHON_VERSION}")
864                 # set(PYTHON_BINARY "${PYTHON}/bin/python${PYTHON_VERSION}") # not used yet
865                 set(PYTHON_LIBRARY python${PYTHON_VERSION})
866                 set(PYTHON_LIBPATH "${PYTHON}/lib/python${PYTHON_VERSION}")
867                 # set(PYTHON_LINKFLAGS "-u _PyMac_Error")  # won't  build with this enabled
868         else()
869                 # otherwise, use custom system framework
870
871                 set(PYTHON /System/Library/Frameworks/Python.framework/Versions/)
872                 set(PYTHON_VERSION 3.2)
873                 set(PYTHON_INCLUDE_DIRS "${PYTHON}${PYTHON_VERSION}/include/python${PYTHON_VERSION}")
874                 # set(PYTHON_BINARY ${PYTHON}${PYTHON_VERSION}/bin/python${PYTHON_VERSION}) # not used yet
875                 set(PYTHON_LIBRARY "")
876                 set(PYTHON_LIBPATH ${PYTHON}${PYTHON_VERSION}/lib/python${PYTHON_VERSION}/config)
877                 set(PYTHON_LINKFLAGS "-u _PyMac_Error -framework System -framework Python")
878         endif()
879
880         if(WITH_INTERNATIONAL)
881                 set(GETTEXT ${LIBDIR}/gettext)
882                 set(GETTEXT_INC "${GETTEXT}/include")
883                 set(GETTEXT_LIB intl iconv)
884                 set(GETTEXT_LIBPATH ${GETTEXT}/lib)
885         endif()
886
887         if(WITH_FFTW3)
888                 set(FFTW3 ${LIBDIR}/fftw3)
889                 set(FFTW3_INC ${FFTW3}/include)
890                 set(FFTW3_LIB fftw3)
891                 set(FFTW3_LIBPATH ${FFTW3}/lib)
892         endif()
893
894         set(PNG_LIBRARIES png)
895         set(JPEG_LIBRARIES jpeg)
896
897         set(ZLIB /usr)
898         set(ZLIB_INCLUDE_DIRS "${ZLIB}/include")
899         set(ZLIB_LIBRARIES z bz2)
900
901         set(FREETYPE ${LIBDIR}/freetype)
902         set(FREETYPE_INCLUDE_DIRS ${FREETYPE}/include ${FREETYPE}/include/freetype2)
903         set(FREETYPE_LIBPATH ${FREETYPE}/lib)
904         set(FREETYPE_LIBRARY freetype)
905
906         if(WITH_IMAGE_OPENEXR)
907                 set(OPENEXR ${LIBDIR}/openexr)
908                 set(OPENEXR_INC ${OPENEXR}/include/OpenEXR ${OPENEXR}/include)
909                 set(OPENEXR_LIB Iex Half IlmImf Imath IlmThread)
910                 set(OPENEXR_LIBPATH ${OPENEXR}/lib)
911         endif()
912
913         if(WITH_LCMS)
914                 set(LCMS ${LIBDIR}/lcms)
915                 set(LCMS_INCLUDE_DIR ${LCMS}/include)
916                 set(LCMS_LIBRARY lcms)
917                 set(LCMS_LIBPATH ${LCMS}/lib)
918         endif()
919
920         if(WITH_CODEC_FFMPEG)
921                 set(FFMPEG ${LIBDIR}/ffmpeg)
922                 set(FFMPEG_INC ${FFMPEG}/include)
923                 set(FFMPEG_LIB avcodec avdevice avformat avutil mp3lame swscale x264 xvidcore theora theoradec theoraenc vorbis vorbisenc vorbisfile ogg)
924                 set(FFMPEG_LIBPATH ${FFMPEG}/lib)
925                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__STDC_CONSTANT_MACROS")
926         endif()
927
928         if(WITH_SAMPLERATE)
929                 set(LIBSAMPLERATE ${LIBDIR}/samplerate)
930                 set(LIBSAMPLERATE_INC ${LIBSAMPLERATE}/include)
931                 set(LIBSAMPLERATE_LIB samplerate)
932                 set(LIBSAMPLERATE_LIBPATH ${LIBSAMPLERATE}/lib)
933         endif()
934
935         set(LLIBS stdc++ SystemStubs)
936
937         if(WITH_COCOA)
938                 set(PLATFORM_CFLAGS "-pipe -funsigned-char -DGHOST_COCOA")
939                 set(PLATFORM_LINKFLAGS "-fexceptions -framework CoreServices -framework Foundation -framework IOKit -framework AppKit -framework Cocoa -framework Carbon -framework AudioUnit -framework AudioToolbox -framework CoreAudio")
940                 if(USE_QTKIT)
941                         set(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -DUSE_QTKIT")
942                         set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -framework QTKit")
943                         if(CMAKE_OSX_ARCHITECTURES MATCHES i386)
944                                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -framework QuickTime")
945                                 #libSDL still needs 32bit carbon quicktime 
946                         endif()
947                 elseif(WITH_CODEC_QUICKTIME)
948                         set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -framework QuickTime")
949                 endif()
950         else()
951                 set(PLATFORM_CFLAGS "-pipe -funsigned-char")
952                 set(PLATFORM_LINKFLAGS "-fexceptions -framework CoreServices -framework Foundation -framework IOKit -framework AppKit -framework Carbon -framework AGL -framework AudioUnit -framework AudioToolbox -framework CoreAudio -framework QuickTime")
953         endif()
954
955         if(WITH_OPENCOLLADA)
956                 set(OPENCOLLADA ${LIBDIR}/opencollada)
957                 set(OPENCOLLADA_INC ${OPENCOLLADA}/include)
958                 set(OPENCOLLADA_LIBPATH ${OPENCOLLADA}/lib)
959                 set(OPENCOLLADA_LIB "OpenCOLLADASaxFrameworkLoader -lOpenCOLLADAFramework -lOpenCOLLADABaseUtils -lOpenCOLLADAStreamWriter -lMathMLSolver -lGeneratedSaxParser -lUTF -lxml2 -lbuffer -lftoa" )
960                 #pcre is bundled with openCollada
961                 #set(PCRE ${LIBDIR}/pcre)
962                 #set(PCRE_LIBPATH ${PCRE}/lib)
963                 set(PCRE_LIB pcre)
964                 #libxml2 is used
965                 #set(EXPAT ${LIBDIR}/expat)
966                 #set(EXPAT_LIBPATH ${EXPAT}/lib)
967                 set(EXPAT_LIB)
968         endif()
969
970         if(WITH_SDL)
971                 set(SDL ${LIBDIR}/sdl)
972                 set(SDL_INCLUDE_DIR ${SDL}/include)
973                 set(SDL_LIBRARY SDL)
974                 set(SDL_LIBPATH ${SDL}/lib)
975         endif()
976
977         set(PNG "${LIBDIR}/png")
978         set(PNG_INCLUDE_DIR "${PNG}/include")
979         set(PNG_LIBPATH ${PNG}/lib)
980
981         set(JPEG "${LIBDIR}/jpeg")
982         set(JPEG_INCLUDE_DIR "${JPEG}/include")
983         set(JPEG_LIBPATH ${JPEG}/lib)
984
985         if(WITH_IMAGE_TIFF)
986                 set(TIFF ${LIBDIR}/tiff)
987                 set(TIFF_INCLUDE_DIR ${TIFF}/include)
988                 set(TIFF_LIBRARY tiff)
989                 set(TIFF_LIBPATH ${TIFF}/lib)
990         endif()
991
992         set(EXETYPE MACOSX_BUNDLE)
993
994         set(CMAKE_C_FLAGS_DEBUG "-fno-strict-aliasing -g")
995         set(CMAKE_CXX_FLAGS_DEBUG "-fno-strict-aliasing -g")
996         if(CMAKE_OSX_ARCHITECTURES MATCHES "i386")
997                 set(CMAKE_CXX_FLAGS_RELEASE "-O3 -mdynamic-no-pic -ftree-vectorize -msse -msse2 -fvariable-expansion-in-unroller")
998                 set(CMAKE_C_FLAGS_RELEASE "-O3 -mdynamic-no-pic -ftree-vectorize -msse -msse2 -fvariable-expansion-in-unroller")
999         elseif(CMAKE_OSX_ARCHITECTURES MATCHES "x86_64")
1000                 set(CMAKE_CXX_FLAGS_RELEASE "-O3 -mdynamic-no-pic -ftree-vectorize -msse -msse2 -msse3 -mssse3 -fvariable-expansion-in-unroller")
1001                 set(CMAKE_C_FLAGS_RELEASE "-O3 -mdynamic-no-pic -ftree-vectorize -msse -msse2 -msse3 -mssse3 -fvariable-expansion-in-unroller")
1002         else()
1003                 set(CMAKE_C_FLAGS_RELEASE "-mdynamic-no-pic -fno-strict-aliasing")
1004                 set(CMAKE_CXX_FLAGS_RELEASE "-mdynamic-no-pic -fno-strict-aliasing")
1005         endif()
1006 endif()
1007
1008 #-----------------------------------------------------------------------------
1009 # Common.
1010
1011 if(WITH_RAYOPTIMIZATION)
1012         if(CMAKE_COMPILER_IS_GNUCC)
1013                 if(SUPPORT_SSE_BUILD)
1014                         set(PLATFORM_CFLAGS " -msse ${PLATFORM_CFLAGS}")
1015                         add_definitions(-D__SSE__ -D__MMX__)
1016                 endif()
1017                 if(SUPPORT_SSE2_BUILD)
1018                         set(PLATFORM_CFLAGS " -msse2 ${PLATFORM_CFLAGS}")
1019                         add_definitions(-D__SSE2__)
1020                         if(NOT SUPPORT_SSE_BUILD) # dont double up
1021                                 add_definitions(-D__MMX__)
1022                         endif()
1023                 endif()
1024         endif()
1025 endif()
1026
1027 if(WITH_IMAGE_OPENJPEG)
1028         if(UNIX AND NOT APPLE)
1029                 set(OPENJPEG /usr)
1030                 set(OPENJPEG_INC ${OPENJPEG}/include)
1031                 set(OPENJPEG_LIB openjpeg)
1032                 set(OPENJPEG_LIBPATH ${OPENJPEG}/lib)
1033         else()
1034                 set(OPENJPEG ${CMAKE_SOURCE_DIR}/extern/libopenjpeg)
1035                 set(OPENJPEG_INC ${OPENJPEG})
1036         endif()
1037 endif()
1038
1039 if(WITH_IMAGE_REDCODE)
1040         set(REDCODE ${CMAKE_SOURCE_DIR}/extern)
1041         set(REDCODE_INC ${REDCODE})
1042 endif()
1043
1044 #-----------------------------------------------------------------------------
1045 # Blender WebPlugin
1046
1047 if(WITH_WEBPLUGIN) 
1048         set(GECKO_DIR "${CMAKE_SOURCE_DIR}/../gecko-sdk/" CACHE PATH "Gecko SDK path")
1049         set(WEBPLUGIN_SANDBOX_MODE "apparmor" CACHE STRING "WEB Plugin sandbox mode, can be apparmor, privsep, none")
1050
1051         set(WITH_PLAYER ON)
1052 endif()
1053
1054
1055 #-----------------------------------------------------------------------------
1056 # Configure OpenGL.
1057 find_package(OpenGL)
1058 blender_include_dirs("${OPENGL_INCLUDE_DIR}")
1059 # unset(OPENGL_LIBRARIES CACHE) # not compat with older cmake 
1060 # unset(OPENGL_xmesa_INCLUDE_DIR CACHE) # not compat with older cmake 
1061
1062 #-----------------------------------------------------------------------------
1063 # Configure OpenMP.
1064 if(WITH_OPENMP)
1065         find_package(OpenMP)    
1066         if(OPENMP_FOUND)
1067                 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
1068                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
1069
1070                 if(APPLE AND ${CMAKE_GENERATOR} MATCHES "Xcode")
1071                         set(CMAKE_XCODE_ATTRIBUTE_ENABLE_OPENMP_SUPPORT "YES")
1072                 endif()
1073         else()
1074                 set(WITH_OPENMP OFF)
1075         endif()
1076
1077         mark_as_advanced(OpenMP_C_FLAGS)
1078         mark_as_advanced(OpenMP_CXX_FLAGS)
1079 endif() 
1080
1081 #-----------------------------------------------------------------------------
1082 # Configure GLEW
1083
1084 if(WITH_BUILTIN_GLEW)
1085         # set(GLEW_LIBRARY "")  # unused
1086         set(GLEW_INCLUDE_PATH "${CMAKE_SOURCE_DIR}/extern/glew/include")
1087 else()
1088         find_package(GLEW)
1089
1090         if(NOT GLEW_FOUND)
1091                 message(FATAL_ERROR "GLEW is required to build blender, install it or use WITH_BUILTIN_GLEW")
1092         endif()
1093
1094         mark_as_advanced(GLEW_LIBRARY)
1095         mark_as_advanced(GLEW_INCLUDE_PATH)
1096 endif()
1097
1098 #-----------------------------------------------------------------------------
1099 # Configure Python.
1100
1101 if(WITH_PYTHON_MODULE)
1102         add_definitions(-DPy_ENABLE_SHARED)
1103 endif() 
1104
1105 #-----------------------------------------------------------------------------
1106 # Extra compile flags
1107
1108 if((NOT WIN32) AND (NOT MSVC))
1109         # used for internal debug checks
1110         set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG")
1111         set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DDEBUG")
1112         
1113         # assert() checks for this.
1114         set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DNDEBUG")
1115         set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} -DNDEBUG")
1116         set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -DNDEBUG")
1117
1118         set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -DNDEBUG")
1119         set(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} -DNDEBUG")
1120         set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -DNDEBUG")
1121 endif()
1122
1123 if(CMAKE_COMPILER_IS_GNUCC)
1124
1125         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
1126         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_CAST_ALIGN -Wcast-align)
1127         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_DECLARATION_AFTER_STATEMENT -Werror=declaration-after-statement)
1128         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_IMPLICIT_FUNCTION_DECLARATION -Werror=implicit-function-declaration)
1129         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_RETURN_TYPE -Werror=return-type)
1130         # system headers sometimes do this, disable for now, was: -Werror=strict-prototypes
1131         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_STRICT_PROTOTYPES -Wstrict-prototypes)
1132         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_CHAR_SUBSCRIPTS -Wno-char-subscripts)
1133         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
1134         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_POINTER_ARITH -Wpointer-arith)
1135         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNUSED_PARAMETER -Wunused-parameter)
1136         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_WRITE_STRINGS -Wwrite-strings)
1137         # disable because it gives warnings for printf() & friends.
1138         # ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_DOUBLE_PROMOTION -Wdouble-promotion -Wno-error=double-promotion)
1139         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_ERROR_UNUSED_BUT_SET_VARIABLE -Wno-error=unused-but-set-variable)
1140
1141         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ALL -Wall)
1142         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_INVALID_OFFSETOF -Wno-invalid-offsetof)
1143         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_SIGN_COMPARE -Wno-sign-compare)
1144
1145 elseif(CMAKE_C_COMPILER_ID MATCHES "Intel")
1146
1147         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
1148         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_POINTER_ARITH -Wpointer-arith)
1149         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
1150
1151         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ALL -Wall)
1152         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_INVALID_OFFSETOF -Wno-invalid-offsetof)
1153         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_SIGN_COMPARE -Wno-sign-compare)
1154
1155 endif()
1156
1157 if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
1158         if(WITH_IK_ITASC OR WITH_MOD_FLUID)
1159                 message(WARNING "Using Clang as CXX compiler: disabling WITH_IK_ITASC and WITH_MOD_FLUID, these features will be missing.")
1160                 set(WITH_IK_ITASC OFF)
1161                 set(WITH_MOD_FLUID OFF)
1162         endif()
1163 endif()
1164
1165 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${PLATFORM_CFLAGS} ${C_WARNINGS}")
1166 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${PLATFORM_CFLAGS} ${CXX_WARNINGS}")
1167
1168 #-------------------------------------------------------------------------------
1169 # Global Defines
1170
1171 # better not define flags here but this is a debugging option thats off by default.
1172 if(WITH_CXX_GUARDEDALLOC)
1173         set(CMAKE_CXX_FLAGS " -DWITH_CXX_GUARDEDALLOC -I${CMAKE_SOURCE_DIR}/intern/guardedalloc ${CMAKE_CXX_FLAGS}")
1174 endif()
1175
1176 if(WITH_ASSERT_ABORT)
1177         add_definitions(-DWITH_ASSERT_ABORT)
1178 endif()
1179
1180 # message(STATUS "Using CFLAGS: ${CMAKE_C_FLAGS}")
1181 # message(STATUS "Using CXXFLAGS: ${CMAKE_CXX_FLAGS}")
1182
1183 #-----------------------------------------------------------------------------
1184 # Libraries
1185
1186 add_subdirectory(source)
1187 add_subdirectory(intern)
1188 add_subdirectory(extern)
1189
1190
1191 #-----------------------------------------------------------------------------
1192 # Blender Application
1193 add_subdirectory(source/creator)
1194
1195
1196 #-----------------------------------------------------------------------------
1197 # Blender Player
1198 if(WITH_PLAYER)
1199         add_subdirectory(source/blenderplayer)
1200 endif()
1201
1202 #-----------------------------------------------------------------------------
1203 # CPack for generating packages
1204 include(build_files/cmake/packaging.cmake)