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