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