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