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