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