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