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