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