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