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