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