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