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