svn merge ^/trunk/blender -r44204:44213
[blender-staging.git] / CMakeLists.txt
1 # -*- mode: cmake; indent-tabs-mode: t; -*-
2 # ***** BEGIN GPL LICENSE BLOCK *****
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software Foundation,
16 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 #
18 # The Original Code is Copyright (C) 2006, Blender Foundation
19 # All rights reserved.
20 #
21 # The Original Code is: all of this file.
22 #
23 # Contributor(s): Jacques Beaurain.
24 #
25 # ***** END GPL LICENSE BLOCK *****
26
27 #-----------------------------------------------------------------------------
28 # We don't allow in-source builds. This causes no end of troubles because
29 # all out-of-source builds will use the CMakeCache.txt file there and even
30 # build the libs and objects in it.
31
32 if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
33         if(NOT DEFINED WITH_IN_SOURCE_BUILD)
34                 message(FATAL_ERROR
35                         "CMake generation for blender is not allowed within the source directory!"
36                         "\n Remove the CMakeCache.txt file and try again from another folder, e.g.:"
37                         "\n "
38                         "\n rm CMakeCache.txt"
39                         "\n cd .."
40                         "\n mkdir cmake-make"
41                         "\n cd cmake-make"
42                         "\n cmake ../blender"
43                         "\n "
44                         "\n Alternately define WITH_IN_SOURCE_BUILD to force this option (not recommended!)"
45                 )
46         endif()
47 endif()
48
49 cmake_minimum_required(VERSION 2.8)
50
51 if(NOT EXECUTABLE_OUTPUT_PATH)
52         set(FIRST_RUN "TRUE")
53 endif()
54
55 # this starts out unset
56 list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/build_files/cmake/Modules")
57
58 # avoid having empty buildtype
59 set(CMAKE_BUILD_TYPE_INIT "Release")
60
61 # quiet output for Makefiles, 'make -s' helps too
62 # set_property(GLOBAL PROPERTY RULE_MESSAGES OFF)
63
64 # global compile definitions since add_definitions() adds for all.
65 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_DEBUG           DEBUG _DEBUG)
66 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_RELEASE         NDEBUG)
67 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_MINSIZEREL      NDEBUG)
68 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_RELWITHDEBINFO  NDEBUG)
69
70
71 #-----------------------------------------------------------------------------
72 # Set policy
73
74 # see "cmake --help-policy CMP0003"
75 # So library linking is more sane
76 cmake_policy(SET CMP0003 NEW)
77
78 # So BUILDINFO and BLENDERPATH strings are automatically quoted
79 cmake_policy(SET CMP0005 NEW)
80
81 # So syntax problems are errors
82 cmake_policy(SET CMP0010 NEW)
83
84 # Input directories must have CMakeLists.txt
85 cmake_policy(SET CMP0014 NEW)
86
87 #-----------------------------------------------------------------------------
88 # Load some macros.
89 include(build_files/cmake/macros.cmake)
90
91
92 #-----------------------------------------------------------------------------
93 # Initialize project.
94
95 blender_project_hack_pre()
96
97 project(Blender)
98
99 blender_project_hack_post()
100
101 enable_testing()
102
103 #-----------------------------------------------------------------------------
104 # Redirect output files
105
106 set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin CACHE INTERNAL "" FORCE )
107 set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib CACHE INTERNAL "" FORCE )
108
109 #-----------------------------------------------------------------------------
110 # Set default config options
111
112 get_blender_version()
113
114
115 # Blender internal features
116 option(WITH_BLENDER "Build blender (disable to build only the blender player)" ON)
117 mark_as_advanced(WITH_BLENDER)
118
119 option(WITH_INTERNATIONAL "Enable I18N (International fonts and text)" ON)
120
121 option(WITH_PYTHON        "Enable Embedded Python API  (only disable for development)" ON)
122 option(WITH_PYTHON_SECURITY "Disables execution of scripts within blend files by default (recommend to leave off)" OFF)
123 mark_as_advanced(WITH_PYTHON)  # dont want people disabling this unless they really know what they are doing.
124 mark_as_advanced(WITH_PYTHON_SECURITY)  # some distrobutions see this as a security issue, rather than have them patch it, make a build option.
125
126 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)
127 option(WITH_PYTHON_MODULE "Enable building as a python module (experemental, only enable for development)" OFF)
128 option(WITH_BUILDINFO     "Include extra build details (only disable for development & faster builds)" ON)
129 option(WITH_IK_ITASC      "Enable ITASC IK solver (only disable for development & for incompatible C++ compilers)" ON)
130 option(WITH_FFTW3         "Enable FFTW3 support (Used for smoke and audio effects)" OFF)
131 option(WITH_BULLET        "Enable Bullet (Physics Engine)" ON)
132 option(WITH_GAMEENGINE    "Enable Game Engine" OFF)  # DISABLE FOR BMESH UNTIL NAVMESH IS WORKING
133 option(WITH_PLAYER        "Build Player" OFF)
134
135 # GHOST Windowing Library Options
136 option(WITH_GHOST_DEBUG   "Enable debugging output for the GHOST library" OFF)
137 mark_as_advanced(WITH_GHOST_DEBUG)
138
139 option(WITH_GHOST_SDL    "Enable building blender against SDL for windowing rather then the native APIs" OFF)
140 mark_as_advanced(WITH_GHOST_SDL)
141
142 # Misc...
143 option(WITH_HEADLESS      "Build without graphical support (renderfarm, server mode only)" OFF)
144 mark_as_advanced(WITH_HEADLESS)
145
146 option(WITH_AUDASPACE    "Build with blenders audio library (only disable if you know what you're doing!)" ON)
147 mark_as_advanced(WITH_AUDASPACE)
148
149
150 # (unix defaults to OpenMP On)
151 if(UNIX AND NOT APPLE)
152         option(WITH_OPENMP        "Enable OpenMP (has to be supported by the compiler)" ON)
153 else()
154         option(WITH_OPENMP        "Enable OpenMP (has to be supported by the compiler)" OFF)
155 endif()
156
157 if(UNIX AND NOT APPLE)
158         option(WITH_X11_XINPUT "Enable X11 Xinput (tablet support and unicode input)"   ON)
159         option(WITH_X11_XF86VMODE "Enable X11 video mode switching"     ON)
160         option(WITH_BUILTIN_GLEW "Use GLEW OpenGL wrapper library bundled with blender" ON)
161         option(WITH_XDG_USER_DIRS    "Build with XDG Base Directory Specification (only config and documents for now)" OFF)
162         mark_as_advanced(WITH_XDG_USER_DIRS)
163
164         # freebsd doesn't seems to support XDND
165         if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
166                 option(WITH_GHOST_XDND   "Enable drag'n'drop support on Linux using XDND protocol" ON)
167         endif()
168 else()
169         # not an option for other OS's
170         set(WITH_BUILTIN_GLEW ON)
171 endif()
172
173 # Modifiers
174 option(WITH_MOD_FLUID           "Enable Elbeem Modifier (Fluid Simulation)" ON)
175 option(WITH_MOD_SMOKE           "Enable Smoke Modifier (Smoke Simulation)" ON)
176 option(WITH_MOD_DECIMATE        "Enable Decimate Modifier" ON)
177 option(WITH_MOD_BOOLEAN         "Enable Boolean Modifier" ON)
178 option(WITH_MOD_REMESH          "Enable Remesh Modifier" ON)
179 option(WITH_MOD_CLOTH_ELTOPO    "Enable Experemental cloth solver" OFF)
180 mark_as_advanced(WITH_MOD_CLOTH_ELTOPO)
181 option(WITH_MOD_OCEANSIM        "Enable Ocean Modifier" OFF)
182
183 # Image format support
184 option(WITH_IMAGE_OPENEXR       "Enable OpenEXR Support (http://www.openexr.com)" ON)
185 option(WITH_IMAGE_OPENJPEG      "Enable OpenJpeg Support (http://www.openjpeg.org)" ON)
186 option(WITH_IMAGE_TIFF          "Enable LibTIFF Support" ON)
187 option(WITH_IMAGE_DDS           "Enable DDS Image Support" ON)
188 option(WITH_IMAGE_CINEON        "Enable CINEON and DPX Image Support" ON)
189 option(WITH_IMAGE_HDR           "Enable HDR Image Support" ON)
190 option(WITH_IMAGE_REDCODE       "Enable RedCode Image Support" OFF)
191 option(WITH_IMAGE_FRAMESERVER   "Enable image FrameServer Support for rendering" ON)
192
193 # Audio/Video format support
194 option(WITH_CODEC_FFMPEG        "Enable FFMPeg Support (http://ffmpeg.org)" OFF)
195 option(WITH_CODEC_SNDFILE       "Enable libsndfile Support (http://www.mega-nerd.com/libsndfile)" OFF)
196 if(APPLE OR (WIN32 AND NOT UNIX))
197         option(WITH_CODEC_QUICKTIME     "Enable Quicktime Support" OFF)
198 endif()
199
200 # 3D format support
201 # disable opencollada on non-apple unix because opencollada has no package for debian
202 option(WITH_OPENCOLLADA         "Enable OpenCollada Support (http://www.opencollada.org)"       OFF)
203
204 # Sound output
205 option(WITH_SDL           "Enable SDL for sound and joystick support" ON)
206 option(WITH_OPENAL        "Enable OpenAL Support (http://www.openal.org)" ON)
207 option(WITH_JACK          "Enable Jack Support (http://www.jackaudio.org)" OFF)
208
209 # Compression
210 option(WITH_LZO           "Enable fast LZO compression (used for pointcache)" ON)
211 option(WITH_LZMA          "Enable best LZMA compression, (used for pointcache)" ON)
212
213 # Camera/motion tracking
214 option(WITH_LIBMV         "Enable libmv structure from motion library" ON)
215
216 # Mesh boolean lib
217 option(WITH_CARVE         "Enable Carve library to handle mesh boolean operations" ON)
218
219 # Misc
220 option(WITH_INPUT_NDOF "Enable NDOF input devices (SpaceNavigator and friends)" ON)
221 option(WITH_RAYOPTIMIZATION     "Enable use of SIMD (SSE) optimizations for the raytracer" ON)
222 if(UNIX AND NOT APPLE)
223         option(WITH_INSTALL_PORTABLE "Install redistributeable runtime, otherwise install into CMAKE_INSTALL_PREFIX" ON)
224 endif()
225 option(WITH_PYTHON_INSTALL       "Copy system python into the blender install folder" ON)
226
227 # Cycles
228 option(WITH_CYCLES                                      "Enable cycles Render Engine" ON)
229 option(WITH_CYCLES_TEST                         "Build cycles test application" OFF)
230 option(WITH_CYCLES_CUDA_BINARIES        "Build cycles CUDA binaries" OFF)
231 set(CYCLES_CUDA_BINARIES_ARCH           sm_13 sm_20 sm_21 CACHE STRING "CUDA architectures to build binaries for")
232 mark_as_advanced(CYCLES_CUDA_BINARIES_ARCH)
233
234 # disable for now, but plan to support on all platforms eventually
235 option(WITH_MEM_JEMALLOC   "Enable malloc replacement (http://www.canonware.com/jemalloc)" OFF)
236 mark_as_advanced(WITH_MEM_JEMALLOC)
237
238 # Debug
239 option(WITH_CXX_GUARDEDALLOC "Enable GuardedAlloc for C++ memory allocation tracking (only enable for development)" OFF)
240 mark_as_advanced(WITH_CXX_GUARDEDALLOC)
241
242 option(WITH_ASSERT_ABORT "Call abort() when raising an assertion through BLI_assert()" OFF)
243 mark_as_advanced(WITH_ASSERT_ABORT)
244
245
246 if(APPLE)
247         if(NOT CMAKE_OSX_ARCHITECTURES)
248                 set(CMAKE_OSX_ARCHITECTURES x86_64 CACHE STRING
249                 "Choose the architecture you want to build Blender for: i386, x86_64 or ppc"
250                 FORCE)
251         endif()
252         if(NOT CMAKE_OSX_DEPLOYMENT_TARGET)
253                 set(CMAKE_OSX_DEPLOYMENT_TARGET 10.5 CACHE STRING
254                 "Choose the minimum OSX version required: 10.4 or 10.5"
255                 FORCE)
256         endif()
257         if(${CMAKE_GENERATOR} MATCHES "Xcode" AND (${XCODE_VERSION} VERSION_EQUAL 4 OR ${XCODE_VERSION} VERSION_GREATER 4))
258                 # Xcode 4 defaults to the Apple LLVM Compiler.
259                 # Override the default compiler selection because Blender only compiles with gcc
260                 set(CMAKE_XCODE_ATTRIBUTE_GCC_VERSION "com.apple.compilers.llvmgcc42")
261                 message(STATUS "Setting compiler to: " ${CMAKE_XCODE_ATTRIBUTE_GCC_VERSION})
262         endif()
263         option(WITH_COCOA         "Use Cocoa framework instead of deprecated Carbon" ON)
264         option(USE_QTKIT          "Use QtKit instead of Carbon quicktime (needed for having partial quicktime for 64bit)" OFF)
265         option(WITH_LIBS10.5  "Use 10.5 libs (needed for 64bit builds)" OFF)
266 endif()
267
268 #-----------------------------------------------------------------------------
269 # Check for conflicting/unsupported configurations
270
271 if(NOT WITH_BLENDER AND NOT WITH_PLAYER)
272         message(FATAL_ERROR "At least one of WITH_BLENDER or WITH_PLAYER must be enabled, nothing to do!")
273 endif()
274
275 if(NOT WITH_GAMEENGINE AND WITH_PLAYER)
276         message(FATAL_ERROR "WITH_PLAYER requires WITH_GAMEENGINE")
277 endif()
278
279 if(NOT WITH_AUDASPACE AND (WITH_OPENAL OR WITH_SDL OR WITH_JACK))
280         message(FATAL_ERROR "WITH_OPENAL/WITH_SDL/WITH_JACK/WITH_CODEC_FFMPEG require WITH_AUDASPACE")
281 endif()
282
283 if(NOT WITH_SDL AND WITH_GHOST_SDL)
284         message(FATAL_ERROR "WITH_GHOST_SDL requires WITH_SDL to be ON")
285 endif()
286
287 if(WITH_IMAGE_REDCODE AND ((NOT WITH_IMAGE_OPENJPEG) OR (NOT WITH_CODEC_FFMPEG)))
288         message(FATAL_ERROR "WITH_IMAGE_REDCODE requires WITH_IMAGE_OPENJPEG and WITH_CODEC_FFMPEG")
289 endif()
290
291 # python module, needs some different options
292 if(WITH_PYTHON_MODULE AND WITH_PLAYER)
293         message(FATAL_ERROR "WITH_PYTHON_MODULE requires WITH_PLAYER to be OFF")
294 endif()
295
296 if(WITH_PYTHON_MODULE AND WITH_PYTHON_INSTALL)
297         message(FATAL_ERROR "WITH_PYTHON_MODULE requires WITH_PYTHON_INSTALL to be OFF")
298 endif()
299
300 if(MINGW)
301         if(WITH_CODEC_QUICKTIME)
302                 message(FATAL_ERROR "MINGW requires WITH_CODEC_QUICKTIME to be OFF "
303                                                         "because it is currently unsupported, remove this "
304                                                         "line if youre a developer who wants to add support.")
305         endif()
306 endif()
307
308 if(NOT WITH_FFTW3 AND WITH_MOD_OCEANSIM)
309         message(FATAL_ERROR "WITH_MOD_OCEANSIM requires WITH_FFTW3 to be ON")
310 endif()
311
312 # may as well build python module without a UI
313 if(WITH_PYTHON_MODULE)
314         set(WITH_HEADLESS ON)
315 endif()
316
317 # auto enable openimageio for cycles
318 if(WITH_CYCLES)
319         set(WITH_OPENIMAGEIO ON)
320 endif()
321
322 # auto enable boost for cycles and carve
323 if(WITH_CYCLES OR WITH_CARVE)
324         set(WITH_BOOST ON)
325 endif()
326
327 TEST_SSE_SUPPORT(COMPILER_SSE_FLAG COMPILER_SSE2_FLAG)
328
329 # don't store paths to libs for portable distrobution
330 if(WITH_INSTALL_PORTABLE)
331         set(CMAKE_SKIP_BUILD_RPATH TRUE)
332 endif()
333
334 #-----------------------------------------------------------------------------
335 # Initialize un-cached vars, avoid unused warning
336
337 # linux only, not cached
338 set(WITH_BINRELOC OFF)
339
340 # MAXOSX only, set to avoid uninitialized
341 set(EXETYPE "")
342
343 # C/C++ flags
344 set(PLATFORM_CFLAGS)
345
346 # these are added to later on.
347 set(C_WARNINGS)
348 set(CXX_WARNINGS)
349
350 # for gcc -Wno-blah-blah
351 set(CC_REMOVE_STRICT_FLAGS)
352
353 # libraries to link the binary with passed to target_link_libraries()
354 # known as LLIBS to scons
355 set(PLATFORM_LINKLIBS "")
356
357 # Added to linker flags in setup_liblinks
358 # - CMAKE_EXE_LINKER_FLAGS
359 # - CMAKE_EXE_LINKER_FLAGS_DEBUG
360 set(PLATFORM_LINKFLAGS "")
361 set(PLATFORM_LINKFLAGS_DEBUG "")
362
363
364 # disabled for now, not supported
365 # option(WITH_WEBPLUGIN     "Enable Web Plugin (Unix only)" OFF)
366
367 # For alternate Python locations the commandline can be used to override detected/default cache settings, e.g:
368 # On Unix:
369 #   cmake ../blender \
370 #         -D PYTHON_VERSION=3.2 \
371 #         -D PYTHON_INCLUDE_DIR=/opt/py32/include/python3.2d \
372 #         -D PYTHON_LIBRARY=/opt/py32/lib/libpython3.2d.so
373 #
374 # On Macs:
375 #   cmake ../blender \
376 #         -D PYTHON_INCLUDE_DIR=/System/Library/Frameworks/Python.framework/Versions/3.2/include/python3.2 \
377 #         -D PYTHON_LIBPATH=/System/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/config \
378 #         -G Xcode
379 #
380 # When changing any of this remember to update the notes in doc/build_systems/cmake.txt
381
382 #-----------------------------------------------------------------------------
383 #Platform specifics
384
385 if(UNIX AND NOT APPLE)
386
387         # needed for ubuntu 11.04
388         if(EXISTS "/usr/lib/x86_64-linux-gnu")
389                 set(CMAKE_LIBRARY_PATH "/usr/lib/x86_64-linux-gnu;${CMAKE_LIBRARY_PATH}")
390         endif()
391
392         # set lib directory if it exists
393         if(CMAKE_SYSTEM_NAME MATCHES "Linux")
394                 if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
395                         set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/linux64)
396                 else()
397                         set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/linux)
398                 endif()
399
400                 if(NOT EXISTS ${LIBDIR})
401                         unset(LIBDIR)
402                 endif()
403         endif()
404
405         find_package(JPEG REQUIRED)
406         find_package(PNG REQUIRED)
407         find_package(ZLIB REQUIRED)
408         find_package(Freetype REQUIRED)
409
410         if(WITH_PYTHON)
411                 # No way to set py32. remove for now.
412                 # find_package(PythonLibs)
413
414                 # Use our own instead, since wothout py is such a rare case,
415                 # require this package
416                 find_package(PythonLibsUnix REQUIRED)
417         endif()
418
419
420         if(WITH_IMAGE_OPENEXR)
421                 find_package(OpenEXR)  # our own module
422                 if(NOT OPENEXR_FOUND)
423                         set(WITH_IMAGE_OPENEXR OFF)
424                 endif()
425         endif()
426
427         if(WITH_IMAGE_OPENJPEG)
428                 find_package(OpenJPEG)
429                 if(NOT OPENJPEG_FOUND)
430                         set(WITH_IMAGE_OPENJPEG OFF)
431                 endif()
432         endif()
433
434         if(WITH_IMAGE_TIFF)
435                 find_package(TIFF)
436                 if(NOT TIFF_FOUND)
437                         set(WITH_IMAGE_TIFF OFF)
438                 endif()
439         endif()
440
441         # Audio IO
442         if(WITH_OPENAL)
443                 find_package(OpenAL)
444                 if(NOT OPENAL_FOUND)
445                         set(WITH_OPENAL OFF)
446                 endif()
447         endif()
448
449         if(WITH_SDL)
450                 find_package(SDL)
451                 mark_as_advanced(
452                         SDLMAIN_LIBRARY
453                         SDL_INCLUDE_DIR
454                         SDL_LIBRARY
455                         SDL_LIBRARY_TEMP
456                 )
457                 # unset(SDLMAIN_LIBRARY CACHE)
458                 if(NOT SDL_FOUND)
459                         set(WITH_SDL OFF)
460                 endif()
461         endif()
462
463         if(WITH_JACK)
464                 find_package(Jack)
465                 if(NOT JACK_FOUND)
466                         set(WITH_JACK OFF)
467                 endif()
468         endif()
469
470         # Codecs
471         if(WITH_CODEC_SNDFILE)
472                 find_package(SndFile)
473                 if(NOT SNDFILE_FOUND)
474                         set(WITH_CODEC_SNDFILE OFF)
475                 endif()
476         endif()
477
478         if(WITH_CODEC_FFMPEG)
479                 # use lib dir if available and nothing else specified
480                 if(LIBDIR AND NOT FFMPEG)
481                         set(FFMPEG ${LIBDIR}/ffmpeg CACHE PATH "FFMPEG Directory")
482                         # XXX, some distros might need 'theoraenc theoradec' too
483                         set(FFMPEG_LIBRARIES avformat avcodec avutil avdevice swscale dirac_encoder mp3lame ogg orc-0.4 schroedinger-1.0 theora vorbis vorbisenc vpx x264 xvidcore faad asound CACHE STRING "FFMPEG Libraries")
484                 else()
485                         set(FFMPEG /usr CACHE PATH "FFMPEG Directory")
486                         set(FFMPEG_LIBRARIES avformat avcodec avutil avdevice swscale CACHE STRING "FFMPEG Libraries")
487                 endif()
488
489                 mark_as_advanced(FFMPEG)
490                 set(FFMPEG_INCLUDE_DIRS ${FFMPEG}/include)
491                 mark_as_advanced(FFMPEG_LIBRARIES)
492                 set(FFMPEG_LIBPATH ${FFMPEG}/lib)
493                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__STDC_CONSTANT_MACROS")
494         endif()
495
496         if(WITH_INTERNATIONAL)
497                 find_library(INTL_LIBRARY
498                         NAMES intl
499                         PATHS
500                         /sw/lib
501                 )
502
503                 find_library(ICONV_LIBRARY
504                         NAMES iconv
505                         PATHS
506                         /sw/lib
507                 )
508                 mark_as_advanced(
509                         ICONV_LIBRARY
510                         INTL_LIBRARY
511                 )
512
513                 if(INTL_LIBRARY AND ICONV_LIBRARY)
514                         set(GETTEXT_LIBRARIES ${INTL_LIBRARY} ${ICONV_LIBRARY})
515                 endif()
516         endif()
517
518         if(WITH_FFTW3)
519                 find_package(Fftw3)
520                 if(NOT FFTW3_FOUND)
521                         set(WITH_FFTW3 OFF)
522                 endif()
523         endif()
524
525         if(WITH_OPENCOLLADA)
526                 find_package(OpenCOLLADA)
527                 if(OPENCOLLADA_FOUND)
528                         find_package(XML2)
529                         find_package(PCRE)
530                 else()
531                         set(WITH_OPENCOLLADA OFF)
532                 endif()
533         endif()
534
535         if(WITH_MEM_JEMALLOC)
536                 find_package(JeMalloc)
537                 if(NOT JEMALLOC_FOUND)
538                         set(WITH_MEM_JEMALLOC OFF)
539                 endif()
540         endif()
541
542         if (WITH_INPUT_NDOF)
543                 find_package(Spacenav)
544                 if(NOT SPACENAV_FOUND)
545                         set(WITH_INPUT_NDOF OFF)
546                 endif()
547
548                 # use generic names within blenders buildsystem.
549                 if(SPACENAV_FOUND)
550                         set(NDOF_INCLUDE_DIRS ${SPACENAV_INCLUDE_DIRS})
551                         set(NDOF_LIBRARIES ${SPACENAV_LIBRARIES})
552                 endif()
553         endif()
554
555         if(WITH_BOOST)
556                 # uses in build instructions to override include and library variables
557                 if(NOT BOOST_CUSTOM)
558                         # use lib dir if available and nothing else specified
559                         if(LIBDIR AND NOT BOOST_ROOT)
560                                 set(BOOST_ROOT ${LIBDIR}/boost)
561                                 set(Boost_USE_MULTITHREADED OFF)
562                         else()
563                                 set(Boost_USE_MULTITHREADED ON)
564                         endif()
565                         find_package(Boost 1.34 COMPONENTS filesystem regex system thread)
566                         mark_as_advanced(Boost_DIR)  # why doesnt boost do this?
567                 endif()
568
569                 set(BOOST_INCLUDE_DIR ${Boost_INCLUDE_DIRS})
570                 set(BOOST_LIBRARIES ${Boost_LIBRARIES})
571                 set(BOOST_LIBPATH ${Boost_LIBRARY_DIRS})
572                 set(BOOST_DEFINITIONS "-DBOOST_ALL_NO_LIB")
573         endif()
574
575         if(WITH_OPENIMAGEIO)
576                 # use lib dir if available and nothing else specified
577                 if(LIBDIR AND NOT OPENIMAGEIO_ROOT_DIR)
578                         set(OPENIMAGEIO_ROOT_DIR ${LIBDIR}/oiio)
579                 endif()
580
581                 find_package(OpenImageIO)
582
583                 set(OPENIMAGEIO_LIBRARIES ${OPENIMAGEIO_LIBRARIES} ${PNG_LIBRARIES} ${JPEG_LIBRARIES} ${TIFF_LIBRARY} ${OPENEXR_LIBRARIES} ${ZLIB_LIBRARIES} ${BOOST_LIBRARIES})
584                 set(OPENIMAGEIO_LIBPATH)  # TODO, remove and reference the absolute path everywhere
585                 set(OPENIMAGEIO_DEFINITIONS)
586
587                 if(NOT OPENIMAGEIO_FOUND)
588                         set(WITH_OPENIMAGEIO OFF)
589                         set(WITH_CYCLES OFF)
590                         message(STATUS "OpenImageIO not found, disabling WITH_CYCLES")
591                 endif()
592         endif()
593
594         # OpenSuse needs lutil, ArchLinux not, for now keep, can avoid by using --as-needed
595         set(PLATFORM_LINKLIBS "-lutil -lc -lm -lpthread -lstdc++")
596
597         if((NOT WITH_HEADLESS) AND (NOT WITH_GHOST_SDL))
598                 find_package(X11 REQUIRED)
599                 find_path(X11_XF86keysym_INCLUDE_PATH X11/XF86keysym.h ${X11_INC_SEARCH_PATH})
600                 mark_as_advanced(X11_XF86keysym_INCLUDE_PATH)
601
602                 set(PLATFORM_LINKLIBS "${PLATFORM_LINKLIBS} ${X11_X11_LIB}")
603
604                 if(WITH_X11_XINPUT)
605                         set(PLATFORM_LINKLIBS "${PLATFORM_LINKLIBS} ${X11_Xinput_LIB}")
606                 endif()
607
608                 if(WITH_X11_XF86VMODE)
609                         # XXX, why dont cmake make this available?
610                         FIND_LIBRARY(X11_Xxf86vmode_LIB Xxf86vm   ${X11_LIB_SEARCH_PATH})
611                         mark_as_advanced(X11_Xxf86vmode_LIB)
612                         if(X11_Xxf86vmode_LIB)
613                                 set(PLATFORM_LINKLIBS "${PLATFORM_LINKLIBS} ${X11_Xxf86vmode_LIB}")
614                         else()
615                                 set(WITH_X11_XF86VMODE OFF)
616                         endif()
617                 endif()
618         endif()
619
620         if(CMAKE_SYSTEM_NAME MATCHES "Linux")
621                 if(NOT WITH_PYTHON_MODULE)
622                         # BSD's dont use libdl.so
623                 set(PLATFORM_LINKLIBS "${PLATFORM_LINKLIBS} -ldl")
624                         # binreloc is linux only
625                         set(BINRELOC_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/extern/binreloc/include)
626                         set(WITH_BINRELOC ON)
627                 endif()
628         endif()
629
630         set(PLATFORM_LINKFLAGS "-pthread")
631
632         # lfs on glibc, all compilers should use
633         add_definitions(-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE)
634
635         # GNU Compiler
636         if(CMAKE_COMPILER_IS_GNUCC)
637                 set(PLATFORM_CFLAGS "-pipe -fPIC -funsigned-char -fno-strict-aliasing")
638         # CLang is the same as GCC for now.
639         elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
640                 set(PLATFORM_CFLAGS "-pipe -fPIC -funsigned-char -fno-strict-aliasing")
641         # Solaris CC
642         elseif(CMAKE_CXX_COMPILER_ID MATCHES "SunPro") 
643                 set(PLATFORM_CFLAGS "-pipe -features=extensions -fPIC -D__FUNCTION__=__func__")
644                 
645         # Intel C++ Compiler
646         elseif(CMAKE_C_COMPILER_ID MATCHES "Intel")
647                 # think these next two are broken
648                 find_program(XIAR xiar)
649                 if(XIAR)
650                         set(CMAKE_AR "${XIAR}")
651                 endif()
652                 mark_as_advanced(XIAR)
653
654                 find_program(XILD xild)
655                 if(XILD)
656                         set(CMAKE_LINKER "${XILD}")
657                 endif()
658                 mark_as_advanced(XILD)
659
660                 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fp-model precise -prec_div -parallel")
661                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fp-model precise -prec_div -parallel")
662
663                 # set(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -diag-enable sc3")
664                 set(PLATFORM_CFLAGS "-pipe -fPIC -funsigned-char -fno-strict-aliasing")
665                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -static-intel")
666         endif()
667
668 elseif(WIN32)
669
670         # this file is included anyway when building under Windows with cl.exe
671         #  include(${CMAKE_ROOT}/Modules/Platform/Windows-cl.cmake)
672
673         set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/windows)
674
675         # Setup 64bit and 64bit windows systems
676         if(CMAKE_CL_64)
677                 message("64 bit compiler detected.")
678                 set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/win64)
679         endif()
680
681         add_definitions(-DWIN32)
682
683         if(WITH_INTERNATIONAL)
684                 set(ICONV ${LIBDIR}/iconv)
685                 set(ICONV_INCLUDE_DIRS ${ICONV}/include)
686                 set(ICONV_LIBRARIES iconv)
687                 set(ICONV_LIBPATH ${ICONV}/lib)
688         endif()
689
690         set(JPEG "${LIBDIR}/jpeg")
691         set(JPEG_INCLUDE_DIR "${JPEG}/include")
692         set(JPEG_LIBPATH ${JPEG}/lib) # not cmake defined
693
694         set(WINTAB_INC ${LIBDIR}/wintab/include)
695
696         if(WITH_OPENAL)
697                 set(OPENAL ${LIBDIR}/openal)
698                 set(OPENAL_INCLUDE_DIR ${OPENAL}/include)
699                 set(OPENAL_LIBRARY wrap_oal)
700                 set(OPENAL_LIBPATH ${OPENAL}/lib)
701         endif()
702
703         if(WITH_CODEC_SNDFILE)
704                 set(SNDFILE ${LIBDIR}/sndfile)
705                 set(SNDFILE_INCLUDE_DIRS ${SNDFILE}/include)
706                 set(SNDFILE_LIBRARIES libsndfile-1)
707                 set(SNDFILE_LIBPATH ${SNDFILE}/lib) # TODO, deprecate
708         endif()
709
710         if(WITH_SDL)
711                 set(SDL ${LIBDIR}/sdl)
712                 set(SDL_INCLUDE_DIR ${SDL}/include)
713                 set(SDL_LIBRARY SDL)
714                 set(SDL_LIBPATH ${SDL}/lib)
715         endif()
716
717         if(WITH_CODEC_QUICKTIME)
718                 set(QUICKTIME ${LIBDIR}/QTDevWin)
719                 set(QUICKTIME_INCLUDE_DIRS ${QUICKTIME}/CIncludes)
720                 set(QUICKTIME_LIBRARIES qtmlClient)
721                 set(QUICKTIME_LIBPATH ${QUICKTIME}/Libraries)
722         endif()
723
724         if(WITH_RAYOPTIMIZATION AND SUPPORT_SSE_BUILD)
725                 add_definitions(-D__SSE__ -D__MMX__)
726         endif()
727
728         if(MSVC)
729                 if(CMAKE_CL_64)
730                         set(PLATFORM_LINKLIBS ws2_32 vfw32 winmm kernel32 user32 gdi32 comdlg32 advapi32 shfolder shell32 ole32 oleaut32 uuid)
731                 else()
732                         set(PLATFORM_LINKLIBS ws2_32 vfw32 winmm kernel32 user32 gdi32 comdlg32 advapi32 shfolder shell32 ole32 oleaut32 uuid)
733                 endif()
734
735                 add_definitions(/D_CRT_NONSTDC_NO_DEPRECATE /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_CONSOLE /D_LIB)
736
737                 set(CMAKE_CXX_FLAGS "/nologo /J /W1 /Gd /wd4018 /wd4244 /wd4305 /wd4800 /wd4065 /wd4267 /we4013" CACHE STRING "MSVC MT C++ flags " FORCE)
738                 set(CMAKE_C_FLAGS   "/nologo /J /W1 /Gd /wd4018 /wd4244 /wd4305 /wd4800 /wd4065 /wd4267 /we4013 /EHsc" CACHE STRING "MSVC MT C++ flags " FORCE)
739
740                 if(CMAKE_CL_64)
741                         set(CMAKE_CXX_FLAGS_DEBUG "/Od /Gm /EHsc /RTC1 /MTd /W3 /nologo /Zi /J" CACHE STRING "MSVC MT flags " FORCE)
742                 else()
743                         set(CMAKE_CXX_FLAGS_DEBUG "/Od /Gm /EHsc /RTC1 /MTd /W3 /nologo /ZI /J" CACHE STRING "MSVC MT flags " FORCE)
744                 endif()
745                 set(CMAKE_CXX_FLAGS_RELEASE "/O2 /Ob2 /EHsc /MT /W3 /nologo /J" CACHE STRING "MSVC MT flags " FORCE)
746                 set(CMAKE_CXX_FLAGS_MINSIZEREL "/O1 /Ob1 /EHsc /MT /W3 /nologo /J" CACHE STRING "MSVC MT flags " FORCE)
747                 set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/O2 /Ob1 /EHsc /MT /W3 /nologo /Zi /J" CACHE STRING "MSVC MT flags " FORCE)
748                 if(CMAKE_CL_64)
749                         set(CMAKE_C_FLAGS_DEBUG "/Od /Gm /EHsc /RTC1 /MTd /W3 /nologo /Zi /J" CACHE STRING "MSVC MT flags " FORCE)
750                 else()
751                         set(CMAKE_C_FLAGS_DEBUG "/Od /Gm /EHsc /RTC1 /MTd /W3 /nologo /ZI /J" CACHE STRING "MSVC MT flags " FORCE)
752                 endif()
753                 set(CMAKE_C_FLAGS_RELEASE "/O2 /Ob2 /EHsc /MT /W3 /nologo /J" CACHE STRING "MSVC MT flags " FORCE)
754                 set(CMAKE_C_FLAGS_MINSIZEREL "/O1 /Ob1 /EHsc /MT /W3 /nologo /J" CACHE STRING "MSVC MT flags " FORCE)
755                 set(CMAKE_C_FLAGS_RELWITHDEBINFO "/O2 /Ob1 /EHsc /MT /W3 /nologo /Zi /J" CACHE STRING "MSVC MT flags " FORCE)
756
757                 if(WITH_INTERNATIONAL)
758                         set(GETTEXT ${LIBDIR}/gettext)
759                         set(GETTEXT_INCLUDE_DIRS ${GETTEXT}/include)
760                         set(GETTEXT_LIBPATH ${GETTEXT}/lib)
761                         set(GETTEXT_LIBRARIES gnu_gettext)
762                 endif()
763
764                 set(PNG_LIBRARIES libpng)
765                 set(JPEG_LIBRARIES libjpeg)
766                 
767                 set(PNG "${LIBDIR}/png")
768                 set(PNG_INCLUDE_DIR "${PNG}/include")
769                 set(PNG_LIBPATH ${PNG}/lib) # not cmake defined
770
771                 set(ZLIB_INCLUDE_DIRS ${LIBDIR}/zlib/include)
772                 if(CMAKE_CL_64)
773                         set(ZLIB_LIBRARIES ${LIBDIR}/zlib/lib/libz.lib)
774                 else()
775                         set(ZLIB_LIBRARIES ${LIBDIR}/zlib/lib/zlib.lib)
776                 endif()
777
778                 set(PTHREADS_INCLUDE_DIRS ${LIBDIR}/pthreads/include)
779                 set(PTHREADS_LIBRARIES ${LIBDIR}/pthreads/lib/pthreadVC2.lib)
780
781                 set(FREETYPE ${LIBDIR}/freetype)
782                 set(FREETYPE_INCLUDE_DIRS
783                         ${LIBDIR}/freetype/include
784                         ${LIBDIR}/freetype/include/freetype2
785                 )
786                 set(FREETYPE_LIBRARY ${LIBDIR}/freetype/lib/freetype2ST.lib)
787
788                 if(WITH_FFTW3)
789                         set(FFTW3 ${LIBDIR}/fftw3)
790                         set(FFTW3_LIBRARIES libfftw)
791                         set(FFTW3_INCLUDE_DIRS ${FFTW3}/include)
792                         set(FFTW3_LIBPATH ${FFTW3}/lib)
793                 endif()
794
795                 if(WITH_OPENCOLLADA)
796
797                         set(OPENCOLLADA_INCLUDE_DIRS
798                                 ${LIBDIR}/opencollada/include/COLLADAStreamWriter/include
799                                 ${LIBDIR}/opencollada/include/COLLADABaseUtils/include
800                                 ${LIBDIR}/opencollada/include/COLLADAFramework/include
801                                 ${LIBDIR}/opencollada/include/COLLADASaxFrameworkLoader/include
802                                 ${LIBDIR}/opencollada/include/GeneratedSaxParser/include
803                         )
804                         
805                         set_lib_path(OPENCOLLADA_LIBPATH "opencollada/lib")
806
807                         set(OPENCOLLADA_LIBRARIES
808                                 ${OPENCOLLADA_LIBPATH}/OpenCOLLADASaxFrameworkLoader.lib
809                                 ${OPENCOLLADA_LIBPATH}/OpenCOLLADAFramework.lib
810                                 ${OPENCOLLADA_LIBPATH}/OpenCOLLADABaseUtils.lib
811                                 ${OPENCOLLADA_LIBPATH}/OpenCOLLADAStreamWriter.lib
812                                 ${OPENCOLLADA_LIBPATH}/MathMLSolver.lib
813                                 ${OPENCOLLADA_LIBPATH}/GeneratedSaxParser.lib
814                                 ${OPENCOLLADA_LIBPATH}/xml2.lib
815                                 ${OPENCOLLADA_LIBPATH}/buffer.lib
816                                 ${OPENCOLLADA_LIBPATH}/ftoa.lib
817                                 ${OPENCOLLADA_LIBPATH}/UTF.lib
818                         )
819                         set(PCRE_LIBRARIES
820                                 ${OPENCOLLADA_LIBPATH}/pcre.lib
821                         )
822                         
823                         unset(OPENCOLLADA_LIBPATH)
824                         
825                 endif()
826
827                 if(WITH_CODEC_FFMPEG)
828                         set(FFMPEG_INCLUDE_DIRS
829                                 ${LIBDIR}/ffmpeg/include
830                                 ${LIBDIR}/ffmpeg/include/msvc
831                         )
832                         set(FFMPEG_LIBRARIES
833                                 ${LIBDIR}/ffmpeg/lib/avcodec-53.lib
834                                 ${LIBDIR}/ffmpeg/lib/avformat-53.lib
835                                 ${LIBDIR}/ffmpeg/lib/avdevice-53.lib
836                                 ${LIBDIR}/ffmpeg/lib/avutil-51.lib
837                                 ${LIBDIR}/ffmpeg/lib/swscale-2.lib
838                         )
839                 endif()
840
841                 if(WITH_IMAGE_OPENEXR)
842                         set_lib_path(OPENEXR "openexr")
843                         set_lib_path(OPENEXR_LIBPATH "openexr/lib")
844                         set(OPENEXR_LIBRARIES
845                                 ${OPENEXR_LIBPATH}/Iex.lib
846                                 ${OPENEXR_LIBPATH}/Half.lib
847                                 ${OPENEXR_LIBPATH}/IlmImf.lib
848                                 ${OPENEXR_LIBPATH}/Imath.lib
849                                 ${OPENEXR_LIBPATH}/IlmThread.lib
850                         )
851                         set_lib_path(OPENEXR_INCUDE "openexr/include")
852                         set(OPENEXR_INCLUDE_DIRS
853                                 ${OPENEXR_INCUDE}
854                                 ${OPENEXR_INCUDE}/IlmImf
855                                 ${OPENEXR_INCUDE}/Iex
856                                 ${OPENEXR_INCUDE}/Imath
857                         )
858                         unset(OPENEXR_INCUDE)
859                         unset(OPENEXR_LIBPATH)
860                 endif()
861
862                 if(WITH_IMAGE_TIFF)
863                         set(TIFF_LIBRARY ${LIBDIR}/tiff/lib/libtiff.lib)
864                         set(TIFF_INCLUDE_DIR ${LIBDIR}/tiff/include)
865                 endif()
866
867                 if(WITH_JACK)
868                         set(JACK_INCLUDE_DIRS
869                                 ${LIBDIR}/jack/include/jack
870                                 ${LIBDIR}/jack/include
871                         )
872                         set(JACK_LIBRARIES ${LIBDIR}/jack/lib/libjack.lib)
873                 endif()
874
875                 if(WITH_PYTHON)
876                         # normally cached but not since we include them with blender
877                         set(PYTHON_VERSION 3.2) # CACHE STRING)
878                         set_lib_path(PYTHON_INCLUDE_DIR "python/include/python${PYTHON_VERSION}")
879                         set_lib_path(PYTHON_LIBRARY "python/lib/python32.lib") #CACHE FILEPATH)
880                         
881                         # uncached vars
882                         set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}")
883                         set(PYTHON_LIBRARIES  "${PYTHON_LIBRARY}")
884                 endif()
885
886                 if(WITH_BOOST)
887                         set(BOOST ${LIBDIR}/boost)
888                         set(BOOST_INCLUDE_DIR ${BOOST}/include)
889                         if(MSVC10)
890                                 set(BOOST_POSTFIX "vc100-mt-s-1_47.lib")
891                                 set(BOOST_DEBUG_POSTFIX "vc100-mt-sgd-1_47.lib")
892                         else()
893                                 set(BOOST_POSTFIX "vc90-mt-s-1_47.lib")
894                                 set(BOOST_DEBUG_POSTFIX "vc90-mt-sgd-1_47.lib")                                 
895                         endif()
896                         set(BOOST_LIBRARIES
897                                 optimized libboost_date_time-${BOOST_POSTFIX} optimized libboost_filesystem-${BOOST_POSTFIX}
898                                 optimized libboost_regex-${BOOST_POSTFIX} optimized libboost_system-${BOOST_POSTFIX} optimized libboost_thread-${BOOST_POSTFIX}
899                                 debug libboost_date_time-${BOOST_DEBUG_POSTFIX} debug libboost_filesystem-${BOOST_DEBUG_POSTFIX}
900                                 debug libboost_regex-${BOOST_DEBUG_POSTFIX} debug libboost_system-${BOOST_DEBUG_POSTFIX} debug libboost_thread-${BOOST_DEBUG_POSTFIX})
901                         if(MSVC10)
902                                 set(BOOST_LIBPATH ${BOOST}/lib/vc_10)
903                         else()
904                                 set(BOOST_LIBPATH ${BOOST}/lib)
905                         endif()
906                         set(BOOST_DEFINITIONS "-DBOOST_ALL_NO_LIB")
907                 endif()
908                         
909                 if(WITH_OPENIMAGEIO)
910                         set(OPENIMAGEIO ${LIBDIR}/openimageio)
911                         set(OPENIMAGEIO_INCLUDE_DIRS ${OPENIMAGEIO}/include)
912                         set(OPENIMAGEIO_LIBRARIES OpenImageIO)
913                         set_lib_path(OPENIMAGEIO_LIBPATH "openimageio/lib")
914                         set(OPENIMAGEIO_DEFINITIONS)
915                 endif()
916
917                 set(PLATFORM_LINKFLAGS "/SUBSYSTEM:CONSOLE /STACK:2097152 /INCREMENTAL:NO /NODEFAULTLIB:msvcrt.lib /NODEFAULTLIB:msvcmrt.lib /NODEFAULTLIB:msvcurt.lib /NODEFAULTLIB:msvcrtd.lib")
918
919                 # MSVC only, Mingw doesnt need
920                 if(CMAKE_CL_64)
921                         set(PLATFORM_LINKFLAGS "/MACHINE:X64 /OPT:NOREF ${PLATFORM_LINKFLAGS}")
922                 else()
923                         set(PLATFORM_LINKFLAGS "/MACHINE:IX86 /LARGEADDRESSAWARE ${PLATFORM_LINKFLAGS}")
924                 endif()
925
926                 set(PLATFORM_LINKFLAGS_DEBUG "/NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:libc.lib")
927
928         else()
929                 # keep GCC specific stuff here
930                 if(CMAKE_COMPILER_IS_GNUCC)
931                         set(PLATFORM_LINKLIBS "-lshell32 -lshfolder -lgdi32 -lmsvcrt -lwinmm -lmingw32 -lm -lws2_32 -lz -lstdc++ -lole32 -luuid -lwsock32 -lpsapi")
932                         set(PLATFORM_CFLAGS "-pipe -funsigned-char -fno-strict-aliasing")
933
934                         add_definitions(-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE)
935                 endif()
936
937                 add_definitions(-DFREE_WINDOWS)
938
939                 if(WITH_INTERNATIONAL)
940                         set(GETTEXT ${LIBDIR}/gcc/gettext)
941                         set(GETTEXT_INCLUDE_DIRS ${GETTEXT}/include)
942                         set(GETTEXT_LIBPATH ${GETTEXT}/lib)
943                         set(GETTEXT_LIBRARIES intl)
944                 endif()
945                 
946                 set(PNG "${LIBDIR}/gcc/png")
947                 set(PNG_INCLUDE_DIR "${PNG}/include")
948                 set(PNG_LIBPATH ${PNG}/lib) # not cmake defined
949
950                 set(JPEG_LIBRARIES libjpeg)
951                 set(PNG_LIBRARIES png)
952
953                 set(ZLIB ${LIBDIR}/zlib)
954                 set(ZLIB_INCLUDE_DIRS ${ZLIB}/include)
955                 set(ZLIB_LIBPATH ${ZLIB}/lib)
956                 set(ZLIB_LIBRARIES z)
957
958                 set(PTHREADS ${LIBDIR}/pthreads)
959                 set(PTHREADS_INCLUDE_DIRS ${PTHREADS}/include)
960                 set(PTHREADS_LIBPATH ${PTHREADS}/lib)
961                 set(PTHREADS_LIBRARIES pthreadGC2)
962
963                 set(FREETYPE ${LIBDIR}/gcc/freetype)
964                 set(FREETYPE_INCLUDE_DIRS ${FREETYPE}/include ${FREETYPE}/include/freetype2)
965                 set(FREETYPE_LIBPATH ${FREETYPE}/lib)
966                 set(FREETYPE_LIBRARY freetype)
967
968                 if(WITH_FFTW3)
969                         set(FFTW3 ${LIBDIR}/gcc/fftw3)
970                         set(FFTW3_LIBRARIES fftw3)
971                         set(FFTW3_INCLUDE_DIRS ${FFTW3}/include)
972                         set(FFTW3_LIBPATH ${FFTW3}/lib)
973                 endif()
974
975                 if(WITH_OPENCOLLADA)
976                         set(OPENCOLLADA ${LIBDIR}/gcc/opencollada)
977                         set(OPENCOLLADA_INCLUDE_DIRS
978                                 ${LIBDIR}/gcc/opencollada/include/COLLADAStreamWriter/include
979                                 ${LIBDIR}/gcc/opencollada/include/COLLADABaseUtils/include
980                                 ${LIBDIR}/gcc/opencollada/include/COLLADAFramework/include
981                                 ${LIBDIR}/gcc/opencollada/include/COLLADASaxFrameworkLoader/include
982                                 ${LIBDIR}/gcc/opencollada/include/GeneratedSaxParser/include
983                         )
984                         set(OPENCOLLADA_LIBPATH ${OPENCOLLADA}/lib ${OPENCOLLADA}/lib)
985                         set(OPENCOLLADA_LIBRARIES OpenCOLLADAStreamWriter OpenCOLLADASaxFrameworkLoader OpenCOLLADAFramework OpenCOLLADABaseUtils GeneratedSaxParser UTF MathMLSolver expat pcre buffer ftoa)
986                         set(PCRE_LIBRARIES pcre)
987                 endif()
988
989                 if(WITH_CODEC_FFMPEG)
990                         set(FFMPEG ${LIBDIR}/ffmpeg)
991                         set(FFMPEG_INCLUDE_DIRS ${FFMPEG}/include ${FFMPEG}/include)
992                         set(FFMPEG_LIBRARIES avcodec-53 avformat-53 avdevice-53 avutil-51 swscale-2)
993                         set(FFMPEG_LIBPATH ${FFMPEG}/lib)
994                 endif()
995
996                 if(WITH_IMAGE_OPENEXR)
997                         set(OPENEXR ${LIBDIR}/gcc/openexr)
998                         set(OPENEXR_INCLUDE_DIRS ${OPENEXR}/include/OpenEXR)
999                         set(OPENEXR_LIBRARIES Half IlmImf Imath IlmThread Iex)
1000                         set(OPENEXR_LIBPATH ${OPENEXR}/lib)
1001                 endif()
1002
1003                 if(WITH_IMAGE_TIFF)
1004                         set(TIFF ${LIBDIR}/gcc/tiff)
1005                         set(TIFF_LIBRARY tiff)
1006                         set(TIFF_INCLUDE_DIR ${TIFF}/include)
1007                         set(TIFF_LIBPATH ${TIFF}/lib)
1008                 endif()
1009
1010                 if(WITH_JACK)
1011                         set(JACK ${LIBDIR}/jack)
1012                         set(JACK_INCLUDE_DIRS ${JACK}/include/jack ${JACK}/include)
1013                         set(JACK_LIBRARIES jack)
1014                         set(JACK_LIBPATH ${JACK}/lib)
1015
1016                         # TODO, gives linking errors, force off
1017                         set(WITH_JACK OFF)
1018                 endif()
1019
1020                 if(WITH_PYTHON)
1021                         # normally cached but not since we include them with blender
1022                         set(PYTHON_VERSION 3.2) #  CACHE STRING)
1023                         set(PYTHON_INCLUDE_DIR "${LIBDIR}/python/include/python${PYTHON_VERSION}")  # CACHE PATH)
1024                         set(PYTHON_LIBRARY "${LIBDIR}/python/lib/python32mw.lib")  # CACHE FILEPATH)
1025
1026                         # uncached vars
1027                         set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}")
1028                         set(PYTHON_LIBRARIES  "${PYTHON_LIBRARY}")
1029                 endif()
1030
1031                 if(WITH_BOOST)
1032                         set(BOOST ${LIBDIR}/boost)
1033                         set(BOOST_INCLUDE_DIR ${BOOST}/include)
1034                         set(BOOST_POSTFIX "mgw45-mt-s-1_47")
1035                         set(BOOST_DEBUG_POSTFIX "mgw45-mt-sd-1_47")
1036                         set(BOOST_LIBRARIES
1037                                 optimized boost_date_time-${BOOST_POSTFIX} boost_filesystem-${BOOST_POSTFIX}
1038                                 boost_regex-${BOOST_POSTFIX} boost_system-${BOOST_POSTFIX} boost_thread-${BOOST_POSTFIX}
1039                                 debug boost_date_time-${BOOST_DEBUG_POSTFIX} boost_filesystem-${BOOST_DEBUG_POSTFIX}
1040                                 boost_regex-${BOOST_DEBUG_POSTFIX} boost_system-${BOOST_DEBUG_POSTFIX} boost_thread-${BOOST_DEBUG_POSTFIX})
1041                         set(BOOST_LIBPATH ${BOOST}/lib/gcc)
1042                         set(BOOST_DEFINITIONS "-DBOOST_ALL_NO_LIB -DBOOST_THREAD_USE_LIB ")
1043                 endif()
1044                         
1045                 if(WITH_OPENIMAGEIO)
1046                         set(OPENIMAGEIO ${LIBDIR}/gcc/openimageio)
1047                         set(OPENIMAGEIO_INCLUDE_DIRS ${OPENIMAGEIO}/include)
1048                         set(OPENIMAGEIO_LIBRARIES OpenImageIO)
1049                         set(OPENIMAGEIO_LIBPATH ${OPENIMAGEIO}/lib)
1050                         set(OPENIMAGEIO_DEFINITIONS)
1051                 endif()
1052                 
1053                 set(PLATFORM_LINKFLAGS "-Xlinker --stack=2097152")
1054
1055                 ## DISABLE - causes linking errors 
1056                 ## for re-distrobution, so users dont need mingw installed
1057                 # set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -static-libgcc -static-libstdc++")
1058
1059         endif()
1060
1061         # used in many places so include globally, like OpenGL
1062         blender_include_dirs("${PTHREADS_INCLUDE_DIRS}")
1063
1064 elseif(APPLE)
1065
1066         if (${CMAKE_OSX_DEPLOYMENT_TARGET} STREQUAL "10.5")
1067                 set(WITH_LIBS10.5 ON CACHE BOOL "Use 10.5 libs" FORCE)
1068         endif()
1069
1070         if(WITH_LIBS10.5)
1071                 set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/darwin-9.x.universal)
1072         else()
1073                 if(CMAKE_OSX_ARCHITECTURES MATCHES i386)
1074                         set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/darwin-8.x.i386)
1075                 else()
1076                         set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/darwin-8.0.0-powerpc)
1077                 endif()
1078         endif()
1079
1080
1081         if(WITH_OPENAL)
1082                 find_package(OpenAL)
1083                 if(OPENAL_FOUND)
1084                         set(WITH_OPENAL ON)
1085                         set(OPENAL_INCLUDE_DIR "${LIBDIR}/openal/include")
1086                 else()
1087                         set(WITH_OPENAL OFF)
1088                 endif()
1089         endif()
1090
1091         if(WITH_JACK)
1092                 set(JACK /usr)
1093                 set(JACK_INCLUDE_DIRS ${JACK}/include/jack)
1094                 set(JACK_LIBRARIES jack)
1095                 set(JACK_LIBPATH ${JACK}/lib)
1096         endif()
1097
1098         if(WITH_CODEC_SNDFILE)
1099                 set(SNDFILE ${LIBDIR}/sndfile)
1100                 set(SNDFILE_INCLUDE_DIRS ${SNDFILE}/include)
1101                 set(SNDFILE_LIBRARIES sndfile FLAC ogg vorbis vorbisenc)
1102                 set(SNDFILE_LIBPATH ${SNDFILE}/lib ${FFMPEG}/lib)  # TODO, deprecate
1103         endif()
1104
1105         if(WITH_PYTHON)
1106                 if(NOT WITH_PYTHON_MODULE)
1107                         # we use precompiled libraries for py 3.2 and up by default
1108
1109                         # normally cached but not since we include them with blender
1110                         set(PYTHON_VERSION 3.2)
1111                         set(PYTHON_INCLUDE_DIR "${LIBDIR}/python/include/python${PYTHON_VERSION}")
1112                         # set(PYTHON_BINARY "${LIBDIR}/python/bin/python${PYTHON_VERSION}") # not used yet
1113                         set(PYTHON_LIBRARY python${PYTHON_VERSION})
1114                         set(PYTHON_LIBPATH "${LIBDIR}/python/lib/python${PYTHON_VERSION}")
1115                         # set(PYTHON_LINKFLAGS "-u _PyMac_Error")  # won't  build with this enabled
1116                 else()
1117                         # module must be compiled against Python framework
1118
1119                         # normally cached but not since we include them with blender
1120                         set(PYTHON_VERSION 3.2)
1121                         set(PYTHON_INCLUDE_DIR "/Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}/include/python${PYTHON_VERSION}m")
1122                         set(PYTHON_BINARY "/Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}/bin/python${PYTHON_VERSION}")
1123                         #set(PYTHON_LIBRARY python${PYTHON_VERSION})
1124                         set(PYTHON_LIBPATH "/Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}/lib/python${PYTHON_VERSION}/config-3.2m")
1125                         #set(PYTHON_LINKFLAGS "-u _PyMac_Error -framework Python")  # won't  build with this enabled
1126                 endif()
1127                 
1128                 # uncached vars
1129                 set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}")
1130                 set(PYTHON_LIBRARIES  "${PYTHON_LIBRARY}")
1131         endif()
1132
1133         if(WITH_INTERNATIONAL)
1134                 set(GETTEXT ${LIBDIR}/gettext)
1135                 set(GETTEXT_INCLUDE_DIRS "${GETTEXT}/include")
1136                 set(GETTEXT_LIBRARIES intl iconv)
1137                 set(GETTEXT_LIBPATH ${GETTEXT}/lib)
1138         endif()
1139
1140         if(WITH_FFTW3)
1141                 set(FFTW3 ${LIBDIR}/fftw3)
1142                 set(FFTW3_INCLUDE_DIRS ${FFTW3}/include)
1143                 set(FFTW3_LIBRARIES fftw3)
1144                 set(FFTW3_LIBPATH ${FFTW3}/lib)
1145         endif()
1146
1147         set(PNG_LIBRARIES png)
1148         set(JPEG_LIBRARIES jpeg)
1149
1150         set(ZLIB /usr)
1151         set(ZLIB_INCLUDE_DIRS "${ZLIB}/include")
1152         set(ZLIB_LIBRARIES z bz2)
1153
1154         set(FREETYPE ${LIBDIR}/freetype)
1155         set(FREETYPE_INCLUDE_DIRS ${FREETYPE}/include ${FREETYPE}/include/freetype2)
1156         set(FREETYPE_LIBPATH ${FREETYPE}/lib)
1157         set(FREETYPE_LIBRARY freetype)
1158
1159         if(WITH_IMAGE_OPENEXR)
1160                 set(OPENEXR ${LIBDIR}/openexr)
1161                 set(OPENEXR_INCLUDE_DIRS ${OPENEXR}/include/OpenEXR)
1162                 set(OPENEXR_LIBRARIES Iex Half IlmImf Imath IlmThread)
1163                 set(OPENEXR_LIBPATH ${OPENEXR}/lib)
1164         endif()
1165
1166         if(WITH_CODEC_FFMPEG)
1167                 set(FFMPEG ${LIBDIR}/ffmpeg)
1168                 set(FFMPEG_INCLUDE_DIRS ${FFMPEG}/include)
1169                 set(FFMPEG_LIBRARIES avcodec avdevice avformat avutil mp3lame swscale x264 xvidcore theora theoradec theoraenc vorbis vorbisenc vorbisfile ogg)
1170                 set(FFMPEG_LIBPATH ${FFMPEG}/lib)
1171                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__STDC_CONSTANT_MACROS")
1172         endif()
1173
1174         find_library(SYSTEMSTUBS_LIBRARY
1175                 NAMES
1176                 SystemStubs
1177                 PATHS
1178         )
1179         mark_as_advanced(SYSTEMSTUBS_LIBRARY)
1180         if(SYSTEMSTUBS_LIBRARY)
1181                 set(PLATFORM_LINKLIBS stdc++ SystemStubs)
1182         else()
1183                 set(PLATFORM_LINKLIBS stdc++)
1184         endif()
1185
1186         if(WITH_COCOA)
1187                 set(PLATFORM_CFLAGS "-pipe -funsigned-char -DGHOST_COCOA")
1188                 set(PLATFORM_LINKFLAGS "-fexceptions -framework CoreServices -framework Foundation -framework IOKit -framework AppKit -framework Cocoa -framework Carbon -framework AudioUnit -framework AudioToolbox -framework CoreAudio")
1189                 if(USE_QTKIT)
1190                         set(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -DUSE_QTKIT")
1191                         set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -framework QTKit")
1192                         if(CMAKE_OSX_ARCHITECTURES MATCHES i386)
1193                                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -framework QuickTime")
1194                                 #libSDL still needs 32bit carbon quicktime
1195                         endif()
1196                 elseif(WITH_CODEC_QUICKTIME)
1197                         set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -framework QuickTime")
1198                 endif()
1199
1200                 # XXX - SOME MAC DEV PLEASE TEST WITH THE SDK INSTALLED!
1201                 # ALSO SHOULD BE MOVED INTO OWN MODULE WHEN FUNCTIONAL
1202                 if(WITH_INPUT_NDOF)
1203                         # This thread it *should* work and check the framework - campbell
1204                         # http://www.cmake.org/pipermail/cmake/2005-December/007740.html
1205                         find_library(3D_CONNEXION_CLIENT_LIBRARY
1206                                 NAMES 3DconnexionClient
1207                         )
1208                         if(NOT 3D_CONNEXION_CLIENT_LIBRARY)
1209                                 set(WITH_INPUT_NDOF OFF)
1210                         endif()
1211
1212                         if(WITH_INPUT_NDOF)
1213                                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -weak_framework 3DconnexionClient")
1214                         endif()
1215                 endif()
1216
1217         else()
1218                 set(PLATFORM_CFLAGS "-pipe -funsigned-char")
1219                 set(PLATFORM_LINKFLAGS "-fexceptions -framework CoreServices -framework Foundation -framework IOKit -framework AppKit -framework Carbon -framework AGL -framework AudioUnit -framework AudioToolbox -framework CoreAudio -framework QuickTime")
1220                 set(WITH_INPUT_NDOF OFF)  # unsupported
1221         endif()
1222         
1223         if(WITH_PYTHON_MODULE)
1224                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} /Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}/python")# force cmake to link right framework
1225         endif()
1226         
1227         if(WITH_OPENCOLLADA)
1228                 set(OPENCOLLADA ${LIBDIR}/opencollada)
1229
1230                 set(OPENCOLLADA_INCLUDE_DIRS
1231                         ${LIBDIR}/opencollada/include/COLLADAStreamWriter
1232                         ${LIBDIR}/opencollada/include/COLLADABaseUtils
1233                         ${LIBDIR}/opencollada/include/COLLADAFramework
1234                         ${LIBDIR}/opencollada/include/COLLADASaxFrameworkLoader
1235                         ${LIBDIR}/opencollada/include/GeneratedSaxParser
1236                 )
1237
1238                 set(OPENCOLLADA_LIBPATH ${OPENCOLLADA}/lib)
1239                 set(OPENCOLLADA_LIBRARIES "OpenCOLLADASaxFrameworkLoader -lOpenCOLLADAFramework -lOpenCOLLADABaseUtils -lOpenCOLLADAStreamWriter -lMathMLSolver -lGeneratedSaxParser -lUTF -lxml2 -lbuffer -lftoa" )
1240                 #pcre is bundled with openCollada
1241                 #set(PCRE ${LIBDIR}/pcre)
1242                 #set(PCRE_LIBPATH ${PCRE}/lib)
1243                 set(PCRE_LIBRARIES pcre)
1244                 #libxml2 is used
1245                 #set(EXPAT ${LIBDIR}/expat)
1246                 #set(EXPAT_LIBPATH ${EXPAT}/lib)
1247                 set(EXPAT_LIB)
1248         endif()
1249
1250         if(WITH_SDL)
1251                 set(SDL ${LIBDIR}/sdl)
1252                 set(SDL_INCLUDE_DIR ${SDL}/include)
1253                 set(SDL_LIBRARY SDL)
1254                 set(SDL_LIBPATH ${SDL}/lib)
1255         endif()
1256
1257         set(PNG "${LIBDIR}/png")
1258         set(PNG_INCLUDE_DIR "${PNG}/include")
1259         set(PNG_LIBPATH ${PNG}/lib)
1260
1261         set(JPEG "${LIBDIR}/jpeg")
1262         set(JPEG_INCLUDE_DIR "${JPEG}/include")
1263         set(JPEG_LIBPATH ${JPEG}/lib)
1264
1265         if(WITH_IMAGE_TIFF)
1266                 set(TIFF ${LIBDIR}/tiff)
1267                 set(TIFF_INCLUDE_DIR ${TIFF}/include)
1268                 set(TIFF_LIBRARY tiff)
1269                 set(TIFF_LIBPATH ${TIFF}/lib)
1270         endif()
1271
1272         if (WITH_INPUT_NDOF)
1273                 # linker needs "-weak_framework 3DconnexionClient"
1274         endif()
1275
1276         if(WITH_BOOST)
1277                 set(BOOST ${LIBDIR}/boost)
1278                 set(BOOST_INCLUDE_DIR ${BOOST}/include)
1279                 set(BOOST_LIBRARIES boost_date_time-mt boost_filesystem-mt boost_regex-mt boost_system-mt boost_thread-mt)
1280                 set(BOOST_LIBPATH ${BOOST}/lib)
1281                 set(BOOST_DEFINITIONS)
1282         endif()
1283
1284         if(WITH_OPENIMAGEIO)
1285                 set(OPENIMAGEIO ${LIBDIR}/openimageio)
1286                 set(OPENIMAGEIO_INCLUDE_DIRS ${OPENIMAGEIO}/include)
1287                 set(OPENIMAGEIO_LIBRARIES OpenImageIO ${PNG_LIBRARIES} ${JPEG_LIBRARIES} ${TIFF_LIBRARY} ${OPENEXR_LIBRARIES} ${ZLIB_LIBRARIES})
1288                 set(OPENIMAGEIO_LIBPATH ${OPENIMAGEIO}/lib ${JPEG_LIBPATH} ${PNG_LIBPATH} ${TIFF_LIBPATH} ${OPENEXR_LIBPATH} ${ZLIB_LIBPATH})
1289                 set(OPENIMAGEIO_DEFINITIONS "-DOIIO_STATIC_BUILD")
1290         endif()
1291
1292         set(EXETYPE MACOSX_BUNDLE)
1293
1294         set(CMAKE_C_FLAGS_DEBUG "-fno-strict-aliasing -g")
1295         set(CMAKE_CXX_FLAGS_DEBUG "-fno-strict-aliasing -g")
1296         if(CMAKE_OSX_ARCHITECTURES MATCHES "i386")
1297                 set(CMAKE_CXX_FLAGS_RELEASE "-O2 -mdynamic-no-pic -ftree-vectorize -msse -msse2 -fvariable-expansion-in-unroller")
1298                 set(CMAKE_C_FLAGS_RELEASE "-O2 -mdynamic-no-pic -ftree-vectorize -msse -msse2 -fvariable-expansion-in-unroller")
1299         elseif(CMAKE_OSX_ARCHITECTURES MATCHES "x86_64")
1300                 set(CMAKE_CXX_FLAGS_RELEASE "-O2 -mdynamic-no-pic -ftree-vectorize -msse -msse2 -msse3 -mssse3 -fvariable-expansion-in-unroller")
1301                 set(CMAKE_C_FLAGS_RELEASE "-O2 -mdynamic-no-pic -ftree-vectorize -msse -msse2 -msse3 -mssse3 -fvariable-expansion-in-unroller")
1302         else()
1303                 set(CMAKE_C_FLAGS_RELEASE "-mdynamic-no-pic -fno-strict-aliasing")
1304                 set(CMAKE_CXX_FLAGS_RELEASE "-mdynamic-no-pic -fno-strict-aliasing")
1305         endif()
1306 endif()
1307
1308 #-----------------------------------------------------------------------------
1309 # Common.
1310
1311 if(APPLE OR WIN32)
1312         if(NOT EXISTS "${LIBDIR}/")
1313                 message(FATAL_ERROR "Apple and Windows require pre-compiled libs at: '${LIBDIR}'")
1314         endif()
1315 endif()
1316
1317 # See TEST_SSE_SUPPORT() for how this is defined.
1318
1319 if(WITH_RAYOPTIMIZATION)
1320         if(SUPPORT_SSE_BUILD)
1321                 set(PLATFORM_CFLAGS " ${COMPILER_SSE_FLAG} ${PLATFORM_CFLAGS}")
1322                 add_definitions(-D__SSE__ -D__MMX__)
1323         endif()
1324         if(SUPPORT_SSE2_BUILD)
1325                 set(PLATFORM_CFLAGS " ${COMPILER_SSE2_FLAG} ${PLATFORM_CFLAGS}")
1326                 add_definitions(-D__SSE2__)
1327                 if(NOT SUPPORT_SSE_BUILD) # dont double up
1328                         add_definitions(-D__MMX__)
1329                 endif()
1330         endif()
1331 endif()
1332
1333
1334 # set the endian define
1335 if(MSVC)
1336         # for some reason this fails on msvc
1337         add_definitions(-D__LITTLE_ENDIAN__)
1338 else()
1339         include(TestBigEndian)
1340         test_big_endian(_SYSTEM_BIG_ENDIAN)
1341         if(_SYSTEM_BIG_ENDIAN)
1342                 add_definitions(-D__BIG_ENDIAN__)
1343         else()
1344                 add_definitions(-D__LITTLE_ENDIAN__)
1345         endif()
1346         unset(_SYSTEM_BIG_ENDIAN)
1347 endif()
1348
1349
1350 if(WITH_IMAGE_OPENJPEG)
1351         if(UNIX AND NOT APPLE)
1352                 # dealt with above
1353         else()
1354                 set(OPENJPEG_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/extern/libopenjpeg")
1355         endif()
1356 endif()
1357
1358 if(WITH_IMAGE_REDCODE)
1359         set(REDCODE ${CMAKE_SOURCE_DIR}/extern)
1360         set(REDCODE_INC ${REDCODE})
1361 endif()
1362
1363 #-----------------------------------------------------------------------------
1364 # Blender WebPlugin
1365
1366 if(WITH_WEBPLUGIN)
1367         set(GECKO_DIR "${CMAKE_SOURCE_DIR}/../gecko-sdk/" CACHE PATH "Gecko SDK path")
1368         set(WEBPLUGIN_SANDBOX_MODE "apparmor" CACHE STRING "WEB Plugin sandbox mode, can be apparmor, privsep, none")
1369
1370         set(WITH_PLAYER ON)
1371 endif()
1372
1373
1374 #-----------------------------------------------------------------------------
1375 # Configure OpenGL.
1376 find_package(OpenGL)
1377 blender_include_dirs_sys("${OPENGL_INCLUDE_DIR}")
1378 # unset(OPENGL_LIBRARIES CACHE) # not compat with older cmake
1379 # unset(OPENGL_xmesa_INCLUDE_DIR CACHE) # not compat with older cmake
1380
1381 #-----------------------------------------------------------------------------
1382 # Configure OpenMP.
1383 if(WITH_OPENMP)
1384         find_package(OpenMP)
1385         if(OPENMP_FOUND)
1386                 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
1387                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
1388
1389                 if(APPLE AND ${CMAKE_GENERATOR} MATCHES "Xcode")
1390                         set(CMAKE_XCODE_ATTRIBUTE_ENABLE_OPENMP_SUPPORT "YES")
1391                 endif()
1392         else()
1393                 set(WITH_OPENMP OFF)
1394         endif()
1395
1396         mark_as_advanced(
1397                 OpenMP_C_FLAGS
1398                 OpenMP_CXX_FLAGS
1399         )
1400 endif()
1401
1402 #-----------------------------------------------------------------------------
1403 # Configure GLEW
1404
1405 if(WITH_BUILTIN_GLEW)
1406         # set(GLEW_LIBRARY "")  # unused
1407         set(GLEW_INCLUDE_PATH "${CMAKE_SOURCE_DIR}/extern/glew/include")
1408 else()
1409         find_package(GLEW)
1410
1411         if(NOT GLEW_FOUND)
1412                 message(FATAL_ERROR "GLEW is required to build blender, install it or use WITH_BUILTIN_GLEW")
1413         endif()
1414
1415         mark_as_advanced(
1416                 GLEW_LIBRARY
1417                 GLEW_INCLUDE_PATH
1418         )
1419 endif()
1420
1421 #-----------------------------------------------------------------------------
1422 # Configure Python.
1423
1424 if(WITH_PYTHON_MODULE)
1425         add_definitions(-DPy_ENABLE_SHARED)
1426 endif()
1427
1428 #-----------------------------------------------------------------------------
1429 # Extra compile flags
1430
1431 if(CMAKE_COMPILER_IS_GNUCC)
1432
1433         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
1434         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_CAST_ALIGN -Wcast-align)
1435         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_DECLARATION_AFTER_STATEMENT -Werror=declaration-after-statement)
1436         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_IMPLICIT_FUNCTION_DECLARATION -Werror=implicit-function-declaration)
1437         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_RETURN_TYPE -Werror=return-type)
1438         # system headers sometimes do this, disable for now, was: -Werror=strict-prototypes
1439         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_STRICT_PROTOTYPES -Wstrict-prototypes)
1440         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_CHAR_SUBSCRIPTS -Wno-char-subscripts)
1441         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
1442         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_POINTER_ARITH -Wpointer-arith)
1443         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNUSED_PARAMETER -Wunused-parameter)
1444         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_WRITE_STRINGS -Wwrite-strings)
1445
1446         # # this causes too many warnings, disable
1447         # ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNDEFINED -Wundef)
1448
1449         # disable because it gives warnings for printf() & friends.
1450         # ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_DOUBLE_PROMOTION -Wdouble-promotion -Wno-error=double-promotion)
1451
1452         if(NOT APPLE)
1453                 ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_ERROR_UNUSED_BUT_SET_VARIABLE -Wno-error=unused-but-set-variable)
1454         endif()
1455
1456         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ALL -Wall)
1457         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_INVALID_OFFSETOF -Wno-invalid-offsetof)
1458         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_SIGN_COMPARE -Wno-sign-compare)
1459
1460         # # this causes too many warnings, disable
1461         # ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNDEFINED -Wundef)
1462
1463         # flags to undo strict flags
1464         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_DEPRECATED_DECLARATIONS -Wno-deprecated-declarations)
1465         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_PARAMETER        -Wno-unused-parameter)
1466
1467         if(NOT APPLE)
1468                 ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_ERROR_UNUSED_BUT_SET_VARIABLE -Wno-error=unused-but-set-variable)
1469         endif()
1470
1471 elseif(CMAKE_C_COMPILER_ID MATCHES "Intel")
1472
1473         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
1474         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_POINTER_ARITH -Wpointer-arith)
1475         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
1476
1477         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ALL -Wall)
1478         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_INVALID_OFFSETOF -Wno-invalid-offsetof)
1479         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_SIGN_COMPARE -Wno-sign-compare)
1480
1481         # disable numbered, false positives
1482         set(C_WARNINGS "${C_WARNINGS} -wd188,186,144,913,556")
1483         set(CXX_WARNINGS "${CXX_WARNINGS} -wd188,186,144,913,556")
1484
1485 endif()
1486
1487 # MSVC2010 fails to links C++ libs right
1488 if(MSVC10)
1489         if(WITH_IMAGE_OPENEXR)
1490                 message(WARNING "MSVC 2010 does not support OpenEXR, disabling WITH_IMAGE_OPENEXR. To enable support use Use MSVC 2008")
1491         endif()
1492         if(WITH_OPENCOLLADA)
1493                 message(WARNING "MSVC 2010 does not support OpenCollada, disabling WITH_OPENCOLLADA. To enable support use Use MSVC 2008")
1494         endif()
1495 endif()
1496
1497 if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
1498         if(WITH_IK_ITASC)
1499                 message(WARNING "Using Clang as CXX compiler: disabling WITH_IK_ITASC and WITH_MOD_FLUID, these features will be missing.")
1500                 set(WITH_IK_ITASC OFF)
1501         endif()
1502 endif()
1503
1504
1505 # ensure python header is found since detection can fail, this could happen
1506 # with _any_ library but since we used a fixed python version this tends to
1507 # be most problematic.
1508 if(WITH_PYTHON)
1509         if(NOT EXISTS "${PYTHON_INCLUDE_DIR}/Python.h")
1510                 message(FATAL_ERROR "Missing: \"${PYTHON_INCLUDE_DIR}/Python.h\",\n"
1511                                                         "Set the cache entry 'PYTHON_INCLUDE_DIR' to point "
1512                                                         "to a valid python include path. Containing "
1513                                                         "Python.h for python version \"${PYTHON_VERSION}\"")
1514         endif()
1515 endif()
1516
1517
1518 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${PLATFORM_CFLAGS} ${C_WARNINGS}")
1519 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${PLATFORM_CFLAGS} ${CXX_WARNINGS}")
1520
1521 #-------------------------------------------------------------------------------
1522 # Global Defines
1523
1524 # better not set includes here but this debugging option is off by default.
1525 if(WITH_CXX_GUARDEDALLOC)
1526         include_directories(${CMAKE_SOURCE_DIR}/intern/guardedalloc)
1527 endif()
1528
1529 if(WITH_ASSERT_ABORT)
1530         add_definitions(-DWITH_ASSERT_ABORT)
1531 endif()
1532
1533 # message(STATUS "Using CFLAGS: ${CMAKE_C_FLAGS}")
1534 # message(STATUS "Using CXXFLAGS: ${CMAKE_CXX_FLAGS}")
1535
1536 #-----------------------------------------------------------------------------
1537 # Libraries
1538
1539 add_subdirectory(source)
1540 add_subdirectory(intern)
1541 add_subdirectory(extern)
1542
1543
1544 #-----------------------------------------------------------------------------
1545 # Blender Application
1546 if(WITH_BLENDER)
1547         add_subdirectory(source/creator)
1548 endif()
1549
1550
1551 #-----------------------------------------------------------------------------
1552 # Blender Player
1553 if(WITH_PLAYER)
1554         add_subdirectory(source/blenderplayer)
1555 endif()
1556
1557 #-----------------------------------------------------------------------------
1558 # CPack for generating packages
1559 include(build_files/cmake/packaging.cmake)
1560
1561
1562 #-----------------------------------------------------------------------------
1563 # Print Final Configuration
1564
1565 if(FIRST_RUN)
1566         set(_config_msg "\n* Blender Configuration *")
1567         macro(info_cfg_option
1568                 _setting)
1569                 set(_msg "   * ${_setting}")
1570                 string(LENGTH "${_msg}" _len)
1571                 while("28" GREATER "${_len}")
1572                         set(_msg "${_msg} ")
1573                          math(EXPR _len "${_len} + 1")
1574                 endwhile()
1575
1576                 set(_config_msg "${_config_msg}\n${_msg}${${_setting}}")
1577         endmacro()
1578
1579         macro(info_cfg_text
1580                 _text)
1581                 set(_config_msg "${_config_msg}\n\n  ${_text}")
1582
1583
1584         endmacro()
1585
1586         info_cfg_text("Build Options:")
1587         info_cfg_option(WITH_GAMEENGINE)
1588         info_cfg_option(WITH_PLAYER)
1589         info_cfg_option(WITH_BULLET)
1590         info_cfg_option(WITH_IK_ITASC)
1591         info_cfg_option(WITH_OPENCOLLADA)
1592         info_cfg_option(WITH_FFTW3)
1593         info_cfg_option(WITH_INTERNATIONAL)
1594         info_cfg_option(WITH_INPUT_NDOF)
1595         info_cfg_option(WITH_CYCLES)
1596
1597         info_cfg_text("Compiler Options:")
1598         info_cfg_option(WITH_BUILDINFO)
1599         info_cfg_option(WITH_OPENMP)
1600         info_cfg_option(WITH_RAYOPTIMIZATION)
1601
1602         info_cfg_text("System Options:")
1603         info_cfg_option(WITH_INSTALL_PORTABLE)
1604         info_cfg_option(WITH_X11_XF86VMODE)
1605         info_cfg_option(WITH_X11_XINPUT)
1606         info_cfg_option(WITH_BUILTIN_GLEW)
1607
1608         info_cfg_text("Image Formats:")
1609         info_cfg_option(WITH_IMAGE_CINEON)
1610         info_cfg_option(WITH_IMAGE_DDS)
1611         info_cfg_option(WITH_IMAGE_HDR)
1612         info_cfg_option(WITH_IMAGE_OPENEXR)
1613         info_cfg_option(WITH_IMAGE_OPENJPEG)
1614         info_cfg_option(WITH_IMAGE_REDCODE)
1615         info_cfg_option(WITH_IMAGE_TIFF)
1616
1617         info_cfg_text("Audio:")
1618         info_cfg_option(WITH_OPENAL)
1619         info_cfg_option(WITH_SDL)
1620         info_cfg_option(WITH_JACK)
1621         info_cfg_option(WITH_CODEC_FFMPEG)
1622         info_cfg_option(WITH_CODEC_SNDFILE)
1623
1624         info_cfg_text("Compression:")
1625         info_cfg_option(WITH_LZMA)
1626         info_cfg_option(WITH_LZO)
1627
1628         info_cfg_text("Python:")
1629         info_cfg_option(WITH_PYTHON_INSTALL)
1630         info_cfg_option(WITH_PYTHON_MODULE)
1631         info_cfg_option(WITH_PYTHON_SAFETY)
1632
1633         info_cfg_text("Modifiers:")
1634         info_cfg_option(WITH_MOD_BOOLEAN)
1635         info_cfg_option(WITH_MOD_REMESH)
1636         info_cfg_option(WITH_MOD_DECIMATE)
1637         info_cfg_option(WITH_MOD_FLUID)
1638         info_cfg_option(WITH_MOD_OCEANSIM)
1639
1640         info_cfg_text("")
1641
1642         message("${_config_msg}")
1643 endif()