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