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