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