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