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