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