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