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