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