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