cmake fix for Windows: link OpenCollada <libraryname>_d.lib in debug builds and ...
[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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, 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.4)
46 PROJECT(Blender)
47
48 #-----------------------------------------------------------------------------
49 # Redirect output files
50
51 SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
52 SET(LIBRARY_OUTPUT_PATH  ${CMAKE_BINARY_DIR}/lib)
53
54 # Note! - Could create this from the blender version string
55 # ...but thats quite involved, make sure this matches the blender version.
56 SET(BLENDER_VERSION  2.5)
57
58 #-----------------------------------------------------------------------------
59 # Set default config options
60 OPTION(WITH_PLAYER        "Build Player" OFF)
61 OPTION(WITH_GAMEENGINE    "Enable Game Engine" ON)
62 OPTION(WITH_BULLET        "Enable Bullet (Physics Engine)" ON)
63 OPTION(WITH_INTERNATIONAL "Enable I18N   (International fonts and text)" ON)
64 OPTION(WITH_ELBEEM        "Enable Elbeem (Fluid Simulation)" ON)
65 OPTION(WITH_QUICKTIME     "Enable Quicktime Support" OFF)
66 OPTION(WITH_OPENEXR       "Enable OpenEXR Support (http://www.openexr.com)" ON)
67 OPTION(WITH_DDS           "Enable DDS Support" ON)
68 OPTION(WITH_FFMPEG        "Enable FFMPeg Support (http://ffmpeg.mplayerhq.hu/)" OFF)
69 OPTION(WITH_PYTHON        "Enable Embedded Python API" ON)
70 OPTION(WITH_SDL           "Enable SDL for sound and joystick support" ON)
71 OPTION(WITH_OPENJPEG      "Enable OpenJpeg Support (http://www.openjpeg.org/)" OFF)
72 OPTION(WITH_OPENAL        "Enable OpenAL Support (http://www.openal.org)" ON)
73 OPTION(WITH_WEBPLUGIN     "Enable Web Plugin (Unix only)" OFF)
74 OPTION(WITH_FFTW3         "Enable FFTW3 support" OFF)
75 OPTION(WITH_JACK          "Enable Jack Support (http://www.jackaudio.org)" OFF)
76 OPTION(WITH_SNDFILE       "Enable libsndfile Support (http://www.mega-nerd.com/libsndfile)" OFF)
77 OPTION(WITH_LZO           "Enable fast LZO compression, used for pointcache" ON)
78 OPTION(WITH_LZMA          "Enable best LZMA compression, used for pointcache" ON)
79 OPTION(WITH_CXX_GUARDEDALLOC "Enable GuardedAlloc for C++ memory allocation" OFF)
80 OPTION(WITH_BUILDINFO     "Include extra build details" ON)
81 OPTION(WITH_INSTALL       "Install accompanying scripts and language files needed to run blender" ON)
82 OPTION(WITH_OPENCOLLADA         "Enable OpenCollada Support (http://www.opencollada.org/)"      ON)
83
84 # Unix defaults to OpenMP On
85 IF (UNIX)
86         OPTION(WITH_OPENMP        "Enable OpenMP (has to be supported by the compiler)" ON)
87 ELSE(UNIX)
88         OPTION(WITH_OPENMP        "Enable OpenMP (has to be supported by the compiler)" OFF)
89 ENDIF(UNIX)
90
91 IF (APPLE)
92         OPTION(WITH_COCOA         "Use Cocoa framework instead of deprecated Carbon" ON)
93         OPTION(USE_QTKIT          "Use QtKit instead of Carbon quicktime (needed for having partial quicktime for 64bit)" OFF)
94         OPTION(WITH_LIBS10.5  "Use 10.5 libs (needed for 64bit builds)" OFF)
95 ENDIF (APPLE)
96
97 IF(NOT WITH_GAMEENGINE AND WITH_PLAYER)
98         MESSAGE("WARNING: WITH_PLAYER needs WITH_GAMEENGINE")
99 ENDIF(NOT WITH_GAMEENGINE AND WITH_PLAYER)
100
101 # For alternate Python locations the commandline can be used to override detected/default cache settings, e.g:
102 # On Unix: 
103 #   cmake -D PYTHON_LIB=/usr/local/lib/python2.3/config/libpython2.3.so -D PYTHON_INC=/usr/local/include/python2.3 -D PYTHON_BINARY=/usr/local/bin/python2.3 -G "Unix Makefiles" ../blender
104 # On Macs: 
105 #   cmake -D PYTHON_INC=/System/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5 -D PYTHON_LIBPATH=/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/config -D PYTHON_BINARY=/System/Library/Frameworks/Python.framework/Versions/2.5/bin/python2.5 -G Xcode ../blender
106 #
107 # When changing any of this remember to update the notes in doc/blender-cmake.txt
108
109 #-----------------------------------------------------------------------------
110 # Load some macros.
111 INCLUDE(CMake/macros.cmake)
112
113 #-----------------------------------------------------------------------------
114 #Platform specifics
115
116 IF(UNIX AND NOT APPLE)
117
118
119         IF(WITH_OPENAL)
120                 FIND_PACKAGE(OpenAL)
121                 IF(OPENAL_FOUND)
122                         SET(WITH_OPENAL ON)
123                 ELSE(OPENAL_FOUND)
124                         SET(WITH_OPENAL OFF)
125                 ENDIF(OPENAL_FOUND)
126         ENDIF(WITH_OPENAL)
127
128         IF(WITH_JACK)
129                 SET(JACK /usr)
130                 SET(JACK_INC ${JACK}/include/jack)
131                 SET(JACK_LIB jack)
132                 SET(JACK_LIBPATH ${JACK}/lib)
133         ENDIF(WITH_JACK)
134
135         IF(WITH_SNDFILE)
136         SET(SNDFILE /usr)
137         SET(SNDFILE_INC ${SNDFILE}/include)
138         SET(SNDFILE_LIB sndfile)
139         SET(SNDFILE_LIBPATH ${SNDFILE}/lib)
140         ENDIF(WITH_SNDFILE)
141
142         FIND_LIBRARY(INTL_LIBRARY
143                 NAMES intl
144                 PATHS
145                 /sw/lib
146         )
147         FIND_LIBRARY(ICONV_LIBRARY
148                 NAMES iconv
149                 PATHS
150                 /sw/lib
151         )
152   
153         IF(INTL_LIBRARY AND ICONV_LIBRARY)
154                 SET(GETTEXT_LIB ${INTL_LIBRARY} ${ICONV_LIBRARY})
155         ENDIF(INTL_LIBRARY AND ICONV_LIBRARY)
156
157         FIND_PACKAGE(Freetype)
158         # UNSET(FREETYPE_INCLUDE_DIRS CACHE) # cant use
159
160         # No way to set py31. remove for now.
161         # FIND_PACKAGE(PythonLibs)
162         SET(PYTHON /usr)
163         SET(PYTHON_VERSION 3.1)
164         SET(PYTHON_INC "${PYTHON}/include/python${PYTHON_VERSION}" CACHE STRING "")
165         # SET(PYTHON_BINARY python) # not used yet
166         SET(PYTHON_LIB python${PYTHON_VERSION} CACHE STRING "")
167         SET(PYTHON_LIBPATH ${PYTHON}/lib CACHE STRING "")
168   
169         # FIND_PACKAGE(PythonInterp) # not used yet
170         # SET(PYTHON_BINARY ${PYTHON_EXECUTABLE} CACHE STRING "")
171   
172         SET(PYTHON_LINKFLAGS "-Xlinker -export-dynamic")
173
174         IF(WITH_SDL)
175                 FIND_PACKAGE(SDL)
176                 # UNSET(SDLMAIN_LIBRARY CACHE)
177                 IF(NOT SDL_FOUND)
178                         SET(WITH_SDL OFF)
179                 ENDIF(NOT SDL_FOUND)
180         ENDIF(WITH_SDL)
181
182         FIND_PATH(OPENEXR_INC
183                 ImfXdr.h
184                 PATHS
185                 /usr/local/include/OpenEXR
186                 /usr/include/OpenEXR
187                 /sw/include/OpenEXR
188                 /opt/local/include/OpenEXR
189                 /opt/csw/include/OpenEXR
190                 /opt/include/OpenEXR
191         )
192         SET(OPENEXR_LIB Half IlmImf Iex Imath)
193
194         SET(FFMPEG /usr)
195         SET(FFMPEG_INC ${FFMPEG}/include)
196         SET(FFMPEG_LIB avformat avcodec avutil avdevice swscale)
197         SET(FFMPEG_LIBPATH ${FFMPEG}/lib)
198   
199         IF(WITH_FFTW3)
200                 SET(FFTW3 /usr)
201                 SET(FFTW3_INC ${FFTW3}/include)
202                 SET(FFTW3_LIB fftw3)
203                 SET(FFTW3_LIBPATH ${FFTW3}/lib)
204         ENDIF(WITH_FFTW3)
205
206         SET(LIBSAMPLERATE /usr)
207         SET(LIBSAMPLERATE_INC ${LIBSAMPLERATE}/include)
208         SET(LIBSAMPLERATE_LIB samplerate)
209         SET(LIBSAMPLERATE_LIBPATH ${LIBSAMPLERATE}/lib)
210
211         FIND_PACKAGE(JPEG REQUIRED)
212
213         FIND_PACKAGE(PNG REQUIRED)
214
215         FIND_PACKAGE(ZLIB REQUIRED)
216
217         IF (WITH_OPENCOLLADA)
218                 SET(OPENCOLLADA /usr/local/opencollada CACHE FILEPATH "OpenCollada Directory")
219                 SET(OPENCOLLADA_LIBPATH ${OPENCOLLADA}/lib)
220                 SET(OPENCOLLADA_LIB OpenCOLLADAStreamWriter OpenCOLLADASaxFrameworkLoader OpenCOLLADAFramework OpenCOLLADABaseUtils GeneratedSaxParser UTF MathMLSolver pcre ftoa Buffer)
221                 SET(OPENCOLLADA_INC ${OPENCOLLADA})
222                 SET(PCRE /usr CACHE FILEPATH "PCRE Directory")
223                 SET(PCRE_LIBPATH ${PCRE}/lib)
224                 SET(PCRE_LIB pcre)
225                 SET(EXPAT /usr CACHE FILEPATH "Expat Directory")
226                 SET(EXPAT_LIBPATH ${EXPAT}/lib)
227                 SET(EXPAT_LIB expat)
228         ENDIF (WITH_OPENCOLLADA)
229
230
231         # Could use ${X11_Xinput_LIB} ${X11_X11_LIB} too
232         SET(LLIBS "-lXi -lutil -lc -lm -lpthread -lstdc++ -lX11")
233
234         IF(CMAKE_SYSTEM_NAME MATCHES "Linux")
235                 # BSD's dont use libdl.so
236                 SET(LLIBS "${LLIBS} -ldl")
237         ENDIF(CMAKE_SYSTEM_NAME MATCHES "Linux")
238
239         IF(WITH_OPENMP)
240                 SET(LLIBS "${LLIBS} -lgomp")
241                 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fopenmp")
242                 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
243         ENDIF(WITH_OPENMP)
244
245
246         SET(PLATFORM_CFLAGS "-pipe -fPIC -funsigned-char -fno-strict-aliasing -Wno-char-subscripts")
247
248         SET(PLATFORM_LINKFLAGS "-pthread")
249
250         # Better warnings
251         SET(C_WARNINGS "-Wall -Wno-char-subscripts -Wpointer-arith -Wcast-align -Wdeclaration-after-statement")
252         SET(CXX_WARNINGS "-Wall -Wno-invalid-offsetof -Wno-sign-compare")
253
254         INCLUDE_DIRECTORIES(${JPEG_INCLUDE_DIR} ${PNG_INCLUDE_DIR} ${ZLIB_INCLUDE_DIR} )
255 ENDIF(UNIX AND NOT APPLE)
256
257 IF(WIN32)
258
259         # this file is included anyway when building under Windows with cl.exe
260         #  INCLUDE(${CMAKE_ROOT}/Modules/Platform/Windows-cl.cmake)
261   
262         SET(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/windows)
263
264         # Setup 64bit and 64bit windows systems
265         IF(CMAKE_CL_64)
266                 message("64 bit compiler detected.")
267                 SET(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/win64)
268         ENDIF(CMAKE_CL_64)
269
270         SET(PYTHON ${LIBDIR}/python)
271         SET(PYTHON_VERSION 3.1)
272         SET(PYTHON_INC "${PYTHON}/include/python${PYTHON_VERSION}")
273         # SET(PYTHON_BINARY python) # not used yet
274         SET(PYTHON_LIB python31)
275         SET(PYTHON_LIBPATH ${PYTHON}/lib)
276
277         IF(CMAKE_CL_64)
278                 SET(WITH_OPENAL OFF)
279         ELSE(CMAKE_CL_64)
280                 #SET(WITH_OPENAL ON)
281                 SET(OPENAL ${LIBDIR}/openal)
282                 SET(OPENAL_INCLUDE_DIR ${OPENAL}/include)
283                 SET(OPENAL_LIBRARY wrap_oal)
284                 SET(OPENAL_LIBPATH ${OPENAL}/lib)
285         ENDIF(CMAKE_CL_64)
286
287         IF(WITH_JACK)
288                 SET(JACK ${LIBDIR}/jack)
289                 SET(JACK_INC ${JACK}/include/jack ${JACK}/include)
290                 SET(JACK_LIB libjack)
291                 SET(JACK_LIBPATH ${JACK}/lib)
292         ENDIF(WITH_JACK)
293
294         IF(WITH_SNDFILE)
295                 SET(SNDFILE ${LIBDIR}/sndfile)
296                 SET(SNDFILE_INC ${SNDFILE}/include)
297                 SET(SNDFILE_LIB libsndfile-1)
298                 SET(SNDFILE_LIBPATH ${SNDFILE}/lib)
299         ENDIF(WITH_SNDFILE)
300
301         IF(CMAKE_CL_64)
302                 SET(PNG_LIBRARIES libpng)
303         ELSE(CMAKE_CL_64)
304                 SET(PNG_LIBRARIES libpng_st)
305         ENDIF(CMAKE_CL_64)
306         SET(JPEG_LIBRARY libjpeg)
307
308         SET(ZLIB ${LIBDIR}/zlib)
309         SET(ZLIB_INC ${ZLIB}/include)
310         IF(CMAKE_CL_64)
311                 SET(ZLIB_LIBRARIES libz)
312         ELSE(CMAKE_CL_64)
313                 SET(ZLIB_LIBRARIES zlib)
314         ENDIF(CMAKE_CL_64)
315         SET(ZLIB_LIBPATH ${ZLIB}/lib)
316   
317         SET(PTHREADS ${LIBDIR}/pthreads)
318         SET(PTHREADS_INC ${PTHREADS}/include)
319         SET(PTHREADS_LIB pthreadVC2)
320         SET(PTHREADS_LIBPATH ${PTHREADS}/lib)
321   
322         SET(ICONV ${LIBDIR}/iconv)
323         SET(ICONV_INC ${ICONV}/include)
324         SET(ICONV_LIB iconv)
325         SET(ICONV_LIBPATH ${ICONV}/lib)
326   
327         IF(WITH_FFTW3)
328                 SET(FFTW3 ${LIBDIR}/fftw3)
329                 SET(FFTW3_INC ${FFTW3}/include)
330                 SET(FFTW3_LIB libfftw)
331                 SET(FFTW3_LIBPATH ${FFTW3}/lib)
332         ENDIF(WITH_FFTW3)
333   
334         SET(GETTEXT ${LIBDIR}/gettext)
335         SET(GETTEXT_INC ${GETTEXT}/include)
336         IF(CMAKE_CL_64)
337                 SET(GETTEXT_LIB gettext)
338         ELSE(CMAKE_CL_64)
339                 SET(GETTEXT_LIB gnu_gettext)
340         ENDIF(CMAKE_CL_64)
341         SET(GETTEXT_LIBPATH ${GETTEXT}/lib)
342
343         SET(FREETYPE ${LIBDIR}/freetype)
344         SET(FREETYPE_INCLUDE_DIRS ${FREETYPE}/include ${FREETYPE}/include/freetype2)
345         SET(FREETYPE_LIBPATH ${FREETYPE}/lib)
346         SET(FREETYPE_LIBRARY freetype2ST)
347   
348         SET(OPENEXR ${LIBDIR}/openexr)
349         SET(OPENEXR_INC ${OPENEXR}/include ${OPENEXR}/include/IlmImf ${OPENEXR}/include/Iex ${OPENEXR}/include/Imath)
350         SET(OPENEXR_LIB Iex Half IlmImf Imath IlmThread)
351         IF (MSVC80)
352                 SET(OPENEXR_LIBPATH ${OPENEXR}/lib_vs2005)
353         ELSE (MSVC80)
354                 SET(OPENEXR_LIBPATH ${OPENEXR}/lib_msvc)
355         ENDIF(MSVC80)
356         IF (MSVC90)
357                 SET(OPENEXR_LIBPATH ${OPENEXR}/lib_vs2008)
358         ENDIF(MSVC90)
359
360   
361         SET(QUICKTIME ${LIBDIR}/QTDevWin)
362         SET(QUICKTIME_INC ${QUICKTIME}/CIncludes)
363         SET(QUICKTIME_LIB qtmlClient)
364         SET(QUICKTIME_LIBPATH ${QUICKTIME}/Libraries)
365
366         SET(FFMPEG ${LIBDIR}/ffmpeg)
367         SET(FFMPEG_INC ${FFMPEG}/include ${FFMPEG}/include/msvc)
368         SET(FFMPEG_LIB avcodec-52 avformat-52 avdevice-52 avutil-50 swscale-0)
369         SET(FFMPEG_LIBPATH ${FFMPEG}/lib)
370
371         SET(LIBSAMPLERATE ${LIBDIR}/samplerate)
372         SET(LIBSAMPLERATE_INC ${LIBSAMPLERATE}/include)
373         SET(LIBSAMPLERATE_LIB libsamplerate)
374         SET(LIBSAMPLERATE_LIBPATH ${LIBSAMPLERATE}/lib)
375
376         IF(CMAKE_CL_64)
377                 SET(LLIBS kernel32 user32 vfw32 winmm ws2_32 )
378         ELSE(CMAKE_CL_64)
379                 SET(LLIBS kernel32 user32 gdi32 comdlg32 advapi32 shell32 ole32 oleaut32 uuid ws2_32 vfw32 winmm)
380         ENDIF(CMAKE_CL_64)
381
382         SET(CMAKE_CXX_FLAGS_DEBUG "/D_CRT_NONSTDC_NO_DEPRECATE /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /wd4800 /wd4244 /wd4305 /D_DEBUG /Od /Gm /EHsc /RTC1 /MTd /W3 /nologo /ZI /J" CACHE STRING "MSVC MT flags " FORCE)
383         SET(CMAKE_CXX_FLAGS_RELEASE "/D_CRT_NONSTDC_NO_DEPRECATE /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /wd4800 /wd4244 /wd4305 /O2 /Ob2 /DNDEBUG /EHsc /MT /W3 /nologo /J" CACHE STRING "MSVC MT flags " FORCE)
384         SET(CMAKE_CXX_FLAGS_MINSIZEREL "/D_CRT_NONSTDC_NO_DEPRECATE /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /wd4800 /wd4244 /wd4305 /O1 /Ob1 /DNDEBUG /EHsc /MT /W3 /nologo /J" CACHE STRING "MSVC MT flags " FORCE)
385         SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/D_CRT_NONSTDC_NO_DEPRECATE /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /wd4800 /wd4244 /wd4305 /O2 /Ob1 /DNDEBUG /EHsc /MT /W3 /nologo /Zi /J" CACHE STRING "MSVC MT flags " FORCE)
386         SET(CMAKE_C_FLAGS_DEBUG "/D_CRT_NONSTDC_NO_DEPRECATE /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /wd4800 /wd4244 /wd4305 /D_DEBUG /Od /Gm /EHsc /RTC1 /MTd /W3 /nologo /ZI /J" CACHE STRING "MSVC MT flags " FORCE)
387         SET(CMAKE_C_FLAGS_RELEASE "/D_CRT_NONSTDC_NO_DEPRECATE /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /wd4800 /wd4244 /wd4305 /O2 /Ob2 /DNDEBUG /EHsc /MT /W3 /nologo /J" CACHE STRING "MSVC MT flags " FORCE)
388         SET(CMAKE_C_FLAGS_MINSIZEREL "/D_CRT_NONSTDC_NO_DEPRECATE /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /wd4800 /wd4244 /wd4305 /O1 /Ob1 /DNDEBUG /EHsc /MT /W3 /nologo /J" CACHE STRING "MSVC MT flags " FORCE)
389         SET(CMAKE_C_FLAGS_RELWITHDEBINFO "/D_CRT_NONSTDC_NO_DEPRECATE /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /wd4800 /wd4244 /wd4305 /O2 /Ob1 /DNDEBUG /EHsc /MT /W3 /nologo /Zi /J" CACHE STRING "MSVC MT flags " FORCE)
390
391         IF(WITH_OPENMP)
392                 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /openmp ")
393                 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /openmp ")
394         ENDIF(WITH_OPENMP)
395
396         SET(SDL ${LIBDIR}/sdl)
397         SET(SDL_INCLUDE_DIR ${SDL}/include)
398         SET(SDL_LIBRARY SDL)
399         SET(SDL_LIBPATH ${SDL}/lib)
400
401         SET(PNG "${LIBDIR}/png")
402         SET(PNG_INC "${PNG}/include")
403         SET(PNG_LIBPATH ${PNG}/lib)
404
405         SET(JPEG "${LIBDIR}/jpeg")
406         SET(JPEG_INC "${JPEG}/include")
407         SET(JPEG_LIBPATH ${JPEG}/lib)
408
409         SET(TIFF ${LIBDIR}/tiff)
410         SET(TIFF_INC ${TIFF}/include)
411   
412         SET(WINTAB_INC ${LIBDIR}/wintab/include) 
413
414         SET(OPENCOLLADA ${LIBDIR}/opencollada)
415         SET(OPENCOLLADA_INC ${OPENCOLLADA}/include)
416         SET(OPENCOLLADA_LIBPATH ${OPENCOLLADA}/lib)
417         SET(OPENCOLLADA_LIB 
418                 debug OpenCOLLADASaxFrameworkLoader_d 
419                 debug OpenCOLLADAFramework_d 
420                 debug OpenCOLLADABaseUtils_d 
421                 debug OpenCOLLADAStreamWriter_d 
422                 debug MathMLSolver_d 
423                 debug GeneratedSaxParser_d 
424                 debug UTF_d 
425                 debug xml2_d 
426                 optimized OpenCOLLADASaxFrameworkLoader 
427                 optimized OpenCOLLADAFramework 
428                 optimized OpenCOLLADABaseUtils 
429                 optimized OpenCOLLADAStreamWriter 
430                 optimized MathMLSolver 
431                 optimized GeneratedSaxParser 
432                 optimized UTF 
433                 optimized xml2 )
434         #pcre is bundled with openCollada
435         #SET(PCRE ${LIBDIR}/pcre)
436         #SET(PCRE_LIBPATH ${PCRE}/lib)
437         SET(PCRE_LIB pcre)
438
439
440         IF(CMAKE_CL_64)
441                 SET(PLATFORM_LINKFLAGS "/MACHINE:X64 /NODEFAULTLIB:libc.lib;MSVCRT.lib ")
442         ELSE(CMAKE_CL_64)
443                 SET(PLATFORM_LINKFLAGS "/NODEFAULTLIB:libc.lib ")
444         ENDIF(CMAKE_CL_64)
445   
446         SET(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /NODEFAULTLIB:libcmt.lib;libc.lib ")
447 ENDIF(WIN32)
448
449 IF(APPLE)
450         IF(WITH_LIBS10.5)
451                 SET(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/darwin-9.x.universal)
452         ELSE(WITH_LIBS10.5)
453                 IF(CMAKE_OSX_ARCHITECTURES MATCHES i386)
454                         SET(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/darwin-8.x.i386)
455                 ELSE(CMAKE_OSX_ARCHITECTURES MATCHES i386)
456                         SET(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/darwin-8.0.0-powerpc)
457                 ENDIF(CMAKE_OSX_ARCHITECTURES MATCHES i386)
458         ENDIF(WITH_LIBS10.5)
459         
460
461         IF(WITH_OPENAL)
462                 FIND_PACKAGE(OpenAL)
463                 IF(OPENAL_FOUND)
464                         SET(WITH_OPENAL ON)
465                         SET(OPENAL_INCLUDE_DIR "${LIBDIR}/openal/include")
466                 ELSE(OPENAL_FOUND)
467                         SET(WITH_OPENAL OFF)
468                 ENDIF(OPENAL_FOUND)
469         ENDIF(WITH_OPENAL)
470
471         IF(WITH_JACK)
472                 SET(JACK /usr)
473                 SET(JACK_INC ${JACK}/include/jack)
474                 SET(JACK_LIB jack)
475                 SET(JACK_LIBPATH ${JACK}/lib)
476         ENDIF(WITH_JACK)
477
478         IF(WITH_SNDFILE)
479                 SET(SNDFILE ${LIBDIR}/sndfile)
480                 SET(SNDFILE_INC ${SNDFILE}/include)
481                 SET(SNDFILE_LIB sndfile)
482                 SET(SNDFILE_LIBPATH ${SNDFILE}/lib)
483         ENDIF(WITH_SNDFILE)
484
485         SET(PYTHON_VERSION 3.1)
486
487         IF(PYTHON_VERSION MATCHES 3.1)
488                 # we use precompiled libraries for py 3.1 and up by default
489
490                 SET(PYTHON ${LIBDIR}/python)
491                 SET(PYTHON_INC "${PYTHON}/include/python${PYTHON_VERSION}")
492                 # SET(PYTHON_BINARY "${PYTHON}/bin/python${PYTHON_VERSION}") # not used yet
493                 SET(PYTHON_LIB python${PYTHON_VERSION})
494                 SET(PYTHON_LIBPATH "${PYTHON}/lib/python${PYTHON_VERSION}")
495                 #    SET(PYTHON_LINKFLAGS "-u _PyMac_Error")  # won't  build with this enabled
496         ELSE(PYTHON_VERSION MATCHES 3.1)
497                 # otherwise, use custom system framework
498
499                 SET(PYTHON /System/Library/Frameworks/Python.framework/Versions/)
500                 SET(PYTHON_VERSION 2.5)
501                 SET(PYTHON_INC "${PYTHON}${PYTHON_VERSION}/include/python${PYTHON_VERSION}")
502                 # SET(PYTHON_BINARY ${PYTHON}${PYTHON_VERSION}/bin/python${PYTHON_VERSION}) # not used yet
503                 SET(PYTHON_LIB "")
504                 SET(PYTHON_LIBPATH ${PYTHON}${PYTHON_VERSION}/lib/python${PYTHON_VERSION}/config)
505                 SET(PYTHON_LINKFLAGS "-u _PyMac_Error -framework System -framework Python")
506         ENDIF(PYTHON_VERSION MATCHES 3.1)
507
508         SET(GETTEXT ${LIBDIR}/gettext)
509         SET(GETTEXT_INC "${GETTEXT}/include")
510         SET(GETTEXT_LIB intl iconv)
511         SET(GETTEXT_LIBPATH ${GETTEXT}/lib)
512   
513         IF(WITH_FFTW3)
514                 SET(FFTW3 ${LIBDIR}/fftw3)
515                 SET(FFTW3_INC ${FFTW3}/include)
516                 SET(FFTW3_LIB fftw3)
517                 SET(FFTW3_LIBPATH ${FFTW3}/lib)
518         ENDIF(WITH_FFTW3)
519
520         SET(PNG_LIBRARIES png)
521         SET(JPEG_LIBRARY jpeg)
522
523         SET(ZLIB /usr)
524         SET(ZLIB_INC "${ZLIB}/include")
525         SET(ZLIB_LIBRARIES z)
526
527         SET(FREETYPE ${LIBDIR}/freetype)
528         SET(FREETYPE_INCLUDE_DIRS ${FREETYPE}/include ${FREETYPE}/include/freetype2)
529         SET(FREETYPE_LIBPATH ${FREETYPE}/lib)
530         SET(FREETYPE_LIBRARY freetype)
531
532         SET(OPENEXR ${LIBDIR}/openexr)
533         SET(OPENEXR_INC ${OPENEXR}/include/OpenEXR ${OPENEXR}/include)
534         SET(OPENEXR_LIB Iex Half IlmImf Imath IlmThread)
535         SET(OPENEXR_LIBPATH ${OPENEXR}/lib)
536
537         SET(FFMPEG ${LIBDIR}/ffmpeg)
538         SET(FFMPEG_INC ${CMAKE_SOURCE_DIR}/extern/ffmpeg)
539         SET(FFMPEG_LIB avcodec avdevice avformat avutil mp3lame swscale x264 xvidcore)
540         SET(FFMPEG_LIBPATH ${FFMPEG}/lib)
541
542         SET(LIBSAMPLERATE ${LIBDIR}/samplerate)
543         SET(LIBSAMPLERATE_INC ${LIBSAMPLERATE}/include)
544         SET(LIBSAMPLERATE_LIB samplerate)
545         SET(LIBSAMPLERATE_LIBPATH ${LIBSAMPLERATE}/lib)
546
547         SET(LLIBS stdc++ SystemStubs)
548
549         IF (WITH_COCOA)
550                 SET(PLATFORM_CFLAGS "-pipe -funsigned-char -DGHOST_COCOA")
551                 SET(PLATFORM_LINKFLAGS "-fexceptions -framework CoreServices -framework Foundation -framework IOKit -framework AppKit -framework Cocoa -framework Carbon -framework AudioUnit -framework AudioToolbox -framework CoreAudio")
552                 IF(USE_QTKIT)
553                         SET(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -DUSE_QTKIT")
554                         SET(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -framework QTKit")
555                         IF(CMAKE_OSX_ARCHITECTURES MATCHES i386)
556                                 SET(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -framework QuickTime")
557                                 #libSDL still needs 32bit carbon quicktime 
558                         ENDIF(CMAKE_OSX_ARCHITECTURES MATCHES i386)
559                 ELSEIF(WITH_QUICKTIME)
560                         SET(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -framework QuickTime")
561                 ENDIF(USE_QTKIT)
562         ELSE (WITH_COCOA)
563                 SET(PLATFORM_CFLAGS "-pipe -funsigned-char")
564                 SET(PLATFORM_LINKFLAGS "-fexceptions -framework CoreServices -framework Foundation -framework IOKit -framework AppKit -framework Carbon -framework AGL -framework AudioUnit -framework AudioToolbox -framework CoreAudio -framework QuickTime")
565         ENDIF (WITH_COCOA)
566
567         IF(WITH_OPENMP)
568                 SET(LLIBS "${LLIBS} -lgomp")
569                 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fopenmp")
570                 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
571         ENDIF(WITH_OPENMP)
572
573         IF (WITH_OPENCOLLADA)
574                 SET(OPENCOLLADA ${LIBDIR}/opencollada)
575                 SET(OPENCOLLADA_INC ${OPENCOLLADA}/include)
576                 SET(OPENCOLLADA_LIBPATH ${OPENCOLLADA}/lib)
577                 SET(OPENCOLLADA_LIB "OpenCOLLADASaxFrameworkLoader -lOpenCOLLADAFramework -lOpenCOLLADABaseUtils -lOpenCOLLADAStreamWriter -lMathMLSolver -lGeneratedSaxParser -lUTF -lxml2" )
578                 #pcre is bundled with openCollada
579                 #SET(PCRE ${LIBDIR}/pcre)
580                 #SET(PCRE_LIBPATH ${PCRE}/lib)
581                 SET(PCRE_LIB pcre)
582                 #libxml2 is used
583                 #SET(EXPAT ${LIBDIR}/expat)
584                 #SET(EXPAT_LIBPATH ${EXPAT}/lib)
585                 SET(EXPAT_LIB)
586         ENDIF (WITH_OPENCOLLADA)
587
588         SET(SDL ${LIBDIR}/sdl)
589         SET(SDL_INCLUDE_DIR ${SDL}/include)
590         SET(SDL_LIBRARY SDL)
591         SET(SDL_LIBPATH ${SDL}/lib)
592
593         SET(PNG "${LIBDIR}/png")
594         SET(PNG_INC "${PNG}/include")
595         SET(PNG_LIBPATH ${PNG}/lib)
596
597         SET(JPEG "${LIBDIR}/jpeg")
598         SET(JPEG_INC "${JPEG}/include")
599         SET(JPEG_LIBPATH ${JPEG}/lib)
600
601         SET(TIFF ${LIBDIR}/tiff)
602         SET(TIFF_INC ${TIFF}/include)
603
604         SET(EXETYPE MACOSX_BUNDLE)
605
606         SET(CMAKE_C_FLAGS_DEBUG "-fno-strict-aliasing -g")
607         SET(CMAKE_CXX_FLAGS_DEBUG "-fno-strict-aliasing -g")
608         IF(CMAKE_OSX_ARCHITECTURES MATCHES "i386")
609                 SET(CMAKE_CXX_FLAGS_RELEASE "-O3 -mdynamic-no-pic -ftree-vectorize -msse -msse2 -fvariable-expansion-in-unroller")
610                 SET(CMAKE_C_FLAGS_RELEASE "-O3 -mdynamic-no-pic -ftree-vectorize -msse -msse2 -fvariable-expansion-in-unroller")
611         ELSEIF(CMAKE_OSX_ARCHITECTURES MATCHES "x86_64")
612                 SET(CMAKE_CXX_FLAGS_RELEASE "-O3 -mdynamic-no-pic -ftree-vectorize -msse -msse2 -msse3 -mssse3 -fvariable-expansion-in-unroller")
613                 SET(CMAKE_C_FLAGS_RELEASE "-O3 -mdynamic-no-pic -ftree-vectorize -msse -msse2 -msse3 -mssse3 -fvariable-expansion-in-unroller")
614         ELSE(CMAKE_OSX_ARCHITECTURES MATCHES "x86_64")
615                 SET(CMAKE_C_FLAGS_RELEASE "-mdynamic-no-pic -fno-strict-aliasing")
616                 SET(CMAKE_CXX_FLAGS_RELEASE "-mdynamic-no-pic -fno-strict-aliasing")
617         ENDIF(CMAKE_OSX_ARCHITECTURES MATCHES "i386")
618
619         # Better warnings
620         SET(C_WARNINGS "-Wall -Wno-char-subscripts -Wpointer-arith -Wcast-align -Wdeclaration-after-statement")
621         SET(CXX_WARNINGS "-Wall -Wno-invalid-offsetof -Wno-sign-compare")
622
623 ENDIF(APPLE)
624
625 IF(CMAKE_SYSTEM_NAME MATCHES "Linux")
626         SET(BINRELOC ${CMAKE_SOURCE_DIR}/extern/binreloc)
627         SET(BINRELOC_INC ${BINRELOC}/include)
628 ENDIF(CMAKE_SYSTEM_NAME MATCHES "Linux")
629
630
631 # buildinfo
632 IF(WITH_BUILDINFO)
633         # BUILD_PLATFORM and BUILD_PLATFORM are taken from CMake
634         IF(UNIX)
635                 EXEC_PROGRAM("date \"+%Y-%m-%d\"" OUTPUT_VARIABLE BUILD_DATE)
636                 EXEC_PROGRAM("date \"+%H:%M:%S\"" OUTPUT_VARIABLE BUILD_TIME)  
637                 EXEC_PROGRAM("svnversion ${CMAKE_SOURCE_DIR}" OUTPUT_VARIABLE BUILD_REV RETURN_VALUE BUILD_REV_RETURN)
638                 IF(BUILD_REV_RETURN)
639                         SET(BUILD_REV "unknown")
640                 ENDIF(BUILD_REV_RETURN)
641         ENDIF(UNIX)
642         
643         IF(WIN32)
644                 EXEC_PROGRAM("cmd /c date /t" OUTPUT_VARIABLE BUILD_DATE)
645                 EXEC_PROGRAM("cmd /c time /t" OUTPUT_VARIABLE BUILD_TIME)  
646                 EXEC_PROGRAM("svnversion ${CMAKE_SOURCE_DIR}" OUTPUT_VARIABLE BUILD_REV RETURN_VALUE BUILD_REV_RETURN)
647                 IF(BUILD_REV_RETURN)
648                         SET(BUILD_REV "unknown")
649                 ENDIF(BUILD_REV_RETURN)
650         ENDIF(WIN32)
651 ENDIF(WITH_BUILDINFO)
652         
653 #-----------------------------------------------------------------------------
654 # Common.
655
656 set(OPENJPEG ${CMAKE_SOURCE_DIR}/extern/libopenjpeg)
657 set(OPENJPEG_INC ${OPENJPEG})
658 set(OPENJPEG_LIb extern_libopenjpeg)
659
660 #-----------------------------------------------------------------------------
661 # Blender WebPlugin
662
663 IF(WITH_WEBPLUGIN) 
664         SET(GECKO_DIR "${CMAKE_SOURCE_DIR}/../gecko-sdk/" CACHE PATH "Gecko SDK path")
665         SET(WEBPLUGIN_SANDBOX_MODE "apparmor" CACHE STRING "WEB Plugin sandbox mode, can be apparmor, privsep, none")
666
667         SET(WITH_PLAYER ON)
668 ENDIF(WITH_WEBPLUGIN)
669
670
671 #-----------------------------------------------------------------------------
672 # Configure OpenGL.
673 FIND_PACKAGE(OpenGL)
674 INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR})
675 # UNSET(OPENGL_LIBRARIES CACHE) # not compat with older cmake 
676 # UNSET(OPENGL_xmesa_INCLUDE_DIR CACHE) # not compat with older cmake 
677
678 #-----------------------------------------------------------------------------
679 # Extra compile flags
680 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${PLATFORM_CFLAGS} ${C_WARNINGS}")
681 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${PLATFORM_CFLAGS} ${CXX_WARNINGS}")
682
683 # better not define flags here but this is a debugging option thats off by default.
684 IF(WITH_CXX_GUARDEDALLOC)
685         SET(CMAKE_CXX_FLAGS " -DWITH_CXX_GUARDEDALLOC -I${CMAKE_SOURCE_DIR}/intern/guardedalloc ${CMAKE_CXX_FLAGS}")
686 ENDIF(WITH_CXX_GUARDEDALLOC)
687
688 #-----------------------------------------------------------------------------
689 # Libraries
690 FILE(WRITE ${CMAKE_BINARY_DIR}/cmake_blender_libs.txt "")
691 ADD_SUBDIRECTORY(intern)
692 ADD_SUBDIRECTORY(extern)
693 ADD_SUBDIRECTORY(source)
694
695
696 #-----------------------------------------------------------------------------
697 # Blender Application
698 ADD_SUBDIRECTORY(source/creator)
699
700
701 #-----------------------------------------------------------------------------
702 # Blender Player
703 IF(WITH_PLAYER)
704         ADD_SUBDIRECTORY(source/blenderplayer)
705 ENDIF(WITH_PLAYER)
706