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