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