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