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