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