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