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