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