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