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