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