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