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