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