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