* Enable opencolorio for scons/mingw32 (coming very soon)
[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                 set(FFMPEG_INCLUDE_DIRS ${FFMPEG}/include ${FFMPEG}/include/ffmpeg)
569                 mark_as_advanced(FFMPEG_LIBRARIES)
570                 set(FFMPEG_LIBPATH ${FFMPEG}/lib)
571                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__STDC_CONSTANT_MACROS")
572         endif()
573
574         if(WITH_INTERNATIONAL)
575                 find_library(INTL_LIBRARY
576                         NAMES intl
577                         PATHS
578                         /sw/lib
579                 )
580
581                 find_library(ICONV_LIBRARY
582                         NAMES iconv
583                         PATHS
584                         /sw/lib
585                 )
586                 mark_as_advanced(
587                         ICONV_LIBRARY
588                         INTL_LIBRARY
589                 )
590
591                 if(INTL_LIBRARY AND ICONV_LIBRARY)
592                         set(GETTEXT_LIBRARIES ${INTL_LIBRARY} ${ICONV_LIBRARY})
593                 endif()
594         endif()
595
596         if(WITH_FFTW3)
597                 find_package(Fftw3)
598                 if(NOT FFTW3_FOUND)
599                         set(WITH_FFTW3 OFF)
600                 endif()
601         endif()
602
603         if(WITH_OPENCOLLADA)
604                 find_package(OpenCOLLADA)
605                 if(OPENCOLLADA_FOUND)
606                         find_package(XML2)
607                         find_package(PCRE)
608                 else()
609                         set(WITH_OPENCOLLADA OFF)
610                 endif()
611         endif()
612
613         if(WITH_MEM_JEMALLOC)
614                 find_package(JeMalloc)
615                 if(NOT JEMALLOC_FOUND)
616                         set(WITH_MEM_JEMALLOC OFF)
617                 endif()
618         endif()
619
620         if (WITH_INPUT_NDOF)
621                 find_package(Spacenav)
622                 if(NOT SPACENAV_FOUND)
623                         set(WITH_INPUT_NDOF OFF)
624                 endif()
625
626                 # use generic names within blenders buildsystem.
627                 if(SPACENAV_FOUND)
628                         set(NDOF_INCLUDE_DIRS ${SPACENAV_INCLUDE_DIRS})
629                         set(NDOF_LIBRARIES ${SPACENAV_LIBRARIES})
630                 endif()
631         endif()
632
633         if(WITH_BOOST)
634                 # uses in build instructions to override include and library variables
635                 if(NOT BOOST_CUSTOM)
636                         # use lib dir if available and nothing else specified
637                         if(LIBDIR AND NOT BOOST_ROOT)
638                                 set(BOOST_ROOT ${LIBDIR}/boost)
639                                 set(Boost_USE_MULTITHREADED OFF)
640                         else()
641                                 set(Boost_USE_MULTITHREADED ON)
642                         endif()
643                         find_package(Boost 1.34 COMPONENTS filesystem regex system thread)
644                         mark_as_advanced(Boost_DIR)  # why doesnt boost do this?
645                 endif()
646
647                 set(BOOST_INCLUDE_DIR ${Boost_INCLUDE_DIRS})
648                 set(BOOST_LIBRARIES ${Boost_LIBRARIES})
649                 set(BOOST_LIBPATH ${Boost_LIBRARY_DIRS})
650                 set(BOOST_DEFINITIONS "-DBOOST_ALL_NO_LIB")
651         endif()
652
653         if(WITH_OPENIMAGEIO)
654                 # use lib dir if available and nothing else specified
655                 if(LIBDIR AND NOT OPENIMAGEIO_ROOT_DIR)
656                         set(OPENIMAGEIO_ROOT_DIR ${LIBDIR}/oiio)
657                 endif()
658
659                 find_package(OpenImageIO)
660
661                 set(OPENIMAGEIO_LIBRARIES ${OPENIMAGEIO_LIBRARIES} ${PNG_LIBRARIES} ${JPEG_LIBRARIES} ${ZLIB_LIBRARIES} ${BOOST_LIBRARIES})
662                 set(OPENIMAGEIO_LIBPATH)  # TODO, remove and reference the absolute path everywhere
663                 set(OPENIMAGEIO_DEFINITIONS)
664
665                 if(WITH_IMAGE_TIFF)
666                         list(APPEND OPENIMAGEIO_LIBRARIES "${TIFF_LIBRARY}")
667                 endif()
668                 if(WITH_IMAGE_OPENEXR)
669                         list(APPEND OPENIMAGEIO_LIBRARIES "${OPENEXR_LIBRARIES}")
670                 endif()
671
672                 if(NOT OPENIMAGEIO_FOUND)
673                         set(WITH_OPENIMAGEIO OFF)
674                         message(STATUS "OpenImageIO not found, disabling WITH_CYCLES")
675                 endif()
676         endif()
677
678         if(WITH_OPENCOLORIO)
679                 # use lib dir if available and nothing else specified
680                 if(LIBDIR AND NOT OPENCOLORIO_ROOT_DIR)
681                         set(OPENCOLORIO_ROOT_DIR ${LIBDIR}/ocio)
682                 endif()
683
684                 find_package(OpenColorIO)
685
686                 set(OPENCOLORIO_LIBRARIES ${OPENCOLORIO_LIBRARIES})
687                 set(OPENCOLORIO_LIBPATH)  # TODO, remove and reference the absolute path everywhere
688                 set(OPENCOLORIO_DEFINITIONS)
689
690                 if(NOT OPENCOLORIO_FOUND)
691                         set(WITH_OPENCOLORIO OFF)
692                         message(STATUS "OpenColorIO not found")
693                 endif()
694         endif()
695
696         if(WITH_CYCLES_OSL)
697                 set(CYCLES_OSL ${LIBDIR}/osl CACHE PATH "Path to OpenShadingLanguage installation")
698         
699                 message(STATUS "CYCLES_OSL = ${CYCLES_OSL}")
700         
701                 find_library(OSL_LIB_EXEC NAMES oslexec PATHS ${CYCLES_OSL}/lib)
702                 find_library(OSL_LIB_COMP NAMES oslcomp PATHS ${CYCLES_OSL}/lib)
703                 find_library(OSL_LIB_QUERY NAMES oslquery PATHS ${CYCLES_OSL}/lib)
704                 # WARNING! depends on correct order of OSL libs linking
705                 list(APPEND OSL_LIBRARIES ${OSL_LIB_COMP} ${OSL_LIB_EXEC} ${OSL_LIB_QUERY})
706                 find_path(OSL_INCLUDES OSL/oslclosure.h PATHS ${CYCLES_OSL}/include)
707                 find_program(OSL_COMPILER NAMES oslc PATHS ${CYCLES_OSL}/bin)
708         
709                 if(OSL_INCLUDES AND OSL_LIBRARIES AND OSL_COMPILER)
710                         set(OSL_FOUND TRUE)
711                         message(STATUS "OSL includes = ${OSL_INCLUDES}")
712                         message(STATUS "OSL library = ${OSL_LIBRARIES}")
713                         message(STATUS "OSL compiler = ${OSL_COMPILER}")
714                 else()
715                         message(STATUS "OSL not found")
716                 endif()
717         
718                 include_directories(${OSL_INCLUDES})
719         endif()
720
721         # OpenSuse needs lutil, ArchLinux not, for now keep, can avoid by using --as-needed
722         set(PLATFORM_LINKLIBS "-lutil -lc -lm -lpthread -lstdc++")
723
724         if((NOT WITH_HEADLESS) AND (NOT WITH_GHOST_SDL))
725                 find_package(X11 REQUIRED)
726                 find_path(X11_XF86keysym_INCLUDE_PATH X11/XF86keysym.h ${X11_INC_SEARCH_PATH})
727                 mark_as_advanced(X11_XF86keysym_INCLUDE_PATH)
728
729                 set(PLATFORM_LINKLIBS "${PLATFORM_LINKLIBS} ${X11_X11_LIB}")
730
731                 if(WITH_X11_XINPUT)
732                         set(PLATFORM_LINKLIBS "${PLATFORM_LINKLIBS} ${X11_Xinput_LIB}")
733                 endif()
734
735                 if(WITH_X11_XF86VMODE)
736                         # XXX, why dont cmake make this available?
737                         FIND_LIBRARY(X11_Xxf86vmode_LIB Xxf86vm   ${X11_LIB_SEARCH_PATH})
738                         mark_as_advanced(X11_Xxf86vmode_LIB)
739                         if(X11_Xxf86vmode_LIB)
740                                 set(PLATFORM_LINKLIBS "${PLATFORM_LINKLIBS} ${X11_Xxf86vmode_LIB}")
741                         else()
742                                 set(WITH_X11_XF86VMODE OFF)
743                         endif()
744                 endif()
745         endif()
746
747         if(CMAKE_SYSTEM_NAME MATCHES "Linux")
748                 if(NOT WITH_PYTHON_MODULE)
749                         # BSD's dont use libdl.so
750                 set(PLATFORM_LINKLIBS "${PLATFORM_LINKLIBS} -ldl")
751                         # binreloc is linux only
752                         set(BINRELOC_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/extern/binreloc/include)
753                         set(WITH_BINRELOC ON)
754                 endif()
755         endif()
756
757         set(PLATFORM_LINKFLAGS "-pthread")
758
759         # lfs on glibc, all compilers should use
760         add_definitions(-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE)
761
762         # GNU Compiler
763         if(CMAKE_COMPILER_IS_GNUCC)
764                 set(PLATFORM_CFLAGS "-pipe -fPIC -funsigned-char -fno-strict-aliasing")
765         # CLang is the same as GCC for now.
766         elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
767                 set(PLATFORM_CFLAGS "-pipe -fPIC -funsigned-char -fno-strict-aliasing")
768         # Solaris CC
769         elseif(CMAKE_CXX_COMPILER_ID MATCHES "SunPro") 
770                 set(PLATFORM_CFLAGS "-pipe -features=extensions -fPIC -D__FUNCTION__=__func__")
771                 
772         # Intel C++ Compiler
773         elseif(CMAKE_C_COMPILER_ID MATCHES "Intel")
774                 # think these next two are broken
775                 find_program(XIAR xiar)
776                 if(XIAR)
777                         set(CMAKE_AR "${XIAR}")
778                 endif()
779                 mark_as_advanced(XIAR)
780
781                 find_program(XILD xild)
782                 if(XILD)
783                         set(CMAKE_LINKER "${XILD}")
784                 endif()
785                 mark_as_advanced(XILD)
786
787                 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fp-model precise -prec_div -parallel")
788                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fp-model precise -prec_div -parallel")
789
790                 # set(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -diag-enable sc3")
791                 set(PLATFORM_CFLAGS "-pipe -fPIC -funsigned-char -fno-strict-aliasing")
792                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -static-intel")
793         endif()
794
795 elseif(WIN32)
796
797         # this file is included anyway when building under Windows with cl.exe
798         #  include(${CMAKE_ROOT}/Modules/Platform/Windows-cl.cmake)
799
800         if(CMAKE_COMPILER_IS_GNUCC)
801                 set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/mingw32)
802
803                 # Setup 64bit and 64bit windows systems         
804                 if(WITH_MINGW64)
805                         message("Set 64 bit compiler for MinGW.")
806                         set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/mingw64)
807                 endif()
808         else()
809                 set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/windows)
810
811                 # Setup 64bit and 64bit windows systems
812                 if(CMAKE_CL_64)
813                         message("64 bit compiler detected.")
814                         set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/win64)
815                 endif()
816         endif()
817                 
818         add_definitions(-DWIN32)
819
820         if(WITH_INTERNATIONAL)
821                 set(ICONV ${LIBDIR}/iconv)
822                 set(ICONV_INCLUDE_DIRS ${ICONV}/include)
823                 set(ICONV_LIBRARIES iconv)
824                 set(ICONV_LIBPATH ${ICONV}/lib)
825         endif()
826
827         set(JPEG "${LIBDIR}/jpeg")
828         set(JPEG_INCLUDE_DIR "${JPEG}/include")
829         set(JPEG_LIBPATH ${JPEG}/lib) # not cmake defined
830
831         set(WINTAB_INC ${LIBDIR}/wintab/include)
832
833         if(WITH_OPENAL)
834                 set(OPENAL ${LIBDIR}/openal)
835                 set(OPENAL_INCLUDE_DIR ${OPENAL}/include)
836                 set(OPENAL_LIBRARY wrap_oal)
837                 set(OPENAL_LIBPATH ${OPENAL}/lib)
838         endif()
839
840         if(WITH_CODEC_SNDFILE)
841                 set(SNDFILE ${LIBDIR}/sndfile)
842                 set(SNDFILE_INCLUDE_DIRS ${SNDFILE}/include)
843                 set(SNDFILE_LIBRARIES libsndfile-1)
844                 set(SNDFILE_LIBPATH ${SNDFILE}/lib) # TODO, deprecate
845         endif()
846
847         if(WITH_SDL)
848                 set(SDL ${LIBDIR}/sdl)
849                 set(SDL_INCLUDE_DIR ${SDL}/include)
850                 set(SDL_LIBRARY SDL)
851                 set(SDL_LIBPATH ${SDL}/lib)
852         endif()
853
854         if(WITH_CODEC_QUICKTIME)
855                 set(QUICKTIME ${LIBDIR}/QTDevWin)
856                 set(QUICKTIME_INCLUDE_DIRS ${QUICKTIME}/CIncludes)
857                 set(QUICKTIME_LIBRARIES qtmlClient)
858                 set(QUICKTIME_LIBPATH ${QUICKTIME}/Libraries)
859         endif()
860
861         if(WITH_RAYOPTIMIZATION AND SUPPORT_SSE_BUILD)
862                 add_definitions(-D__SSE__ -D__MMX__)
863         endif()
864
865         if(WITH_CYCLES_OSL)
866                 set(CYCLES_OSL ${LIBDIR}/osl CACHE PATH "Path to OpenShadingLanguage installation")
867         
868                 message(STATUS "CYCLES_OSL = ${CYCLES_OSL}")
869         
870                 find_library(OSL_LIB_EXEC NAMES oslexec PATHS ${CYCLES_OSL}/lib)
871                 find_library(OSL_LIB_COMP NAMES oslcomp PATHS ${CYCLES_OSL}/lib)
872                 find_library(OSL_LIB_QUERY NAMES oslquery PATHS ${CYCLES_OSL}/lib)
873                 # WARNING! depends on correct order of OSL libs linking
874                 list(APPEND OSL_LIBRARIES ${OSL_LIB_COMP} ${OSL_LIB_EXEC} ${OSL_LIB_QUERY})
875                 find_path(OSL_INCLUDES OSL/oslclosure.h PATHS ${CYCLES_OSL}/include)
876                 find_program(OSL_COMPILER NAMES oslc PATHS ${CYCLES_OSL}/bin)
877         
878                 if(OSL_INCLUDES AND OSL_LIBRARIES AND OSL_COMPILER)
879                         set(OSL_FOUND TRUE)
880                         message(STATUS "OSL includes = ${OSL_INCLUDES}")
881                         message(STATUS "OSL library = ${OSL_LIBRARIES}")
882                         message(STATUS "OSL compiler = ${OSL_COMPILER}")
883                 else()
884                         message(STATUS "OSL not found")
885                 endif()
886         
887                 include_directories(${OSL_INCLUDES})
888         endif()
889
890         if(MSVC)
891                 set(PLATFORM_LINKLIBS ws2_32 vfw32 winmm kernel32 user32 gdi32 comdlg32 advapi32 shfolder shell32 ole32 oleaut32 uuid)
892
893                 add_definitions(/D_CRT_NONSTDC_NO_DEPRECATE /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_CONSOLE /D_LIB)
894
895                 set(CMAKE_CXX_FLAGS "/nologo /J /Gd /EHsc" CACHE STRING "MSVC MT C++ flags " FORCE)
896                 set(CMAKE_C_FLAGS   "/nologo /J /Gd"       CACHE STRING "MSVC MT C++ flags " FORCE)
897
898                 if(CMAKE_CL_64)
899                         set(CMAKE_CXX_FLAGS_DEBUG "/Od /Gm /RTC1 /MTd /Zi" CACHE STRING "MSVC MT flags " FORCE)
900                 else()
901                         set(CMAKE_CXX_FLAGS_DEBUG "/Od /Gm /RTC1 /MTd /ZI" CACHE STRING "MSVC MT flags " FORCE)
902                 endif()
903                 set(CMAKE_CXX_FLAGS_RELEASE "/O2 /Ob2 /MT" CACHE STRING "MSVC MT flags " FORCE)
904                 set(CMAKE_CXX_FLAGS_MINSIZEREL "/O1 /Ob1 /MT" CACHE STRING "MSVC MT flags " FORCE)
905                 set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/O2 /Ob1 /MT /Zi" CACHE STRING "MSVC MT flags " FORCE)
906                 if(CMAKE_CL_64)
907                         set(CMAKE_C_FLAGS_DEBUG "/Od /Gm /RTC1 /MTd /Zi" CACHE STRING "MSVC MT flags " FORCE)
908                 else()
909                         set(CMAKE_C_FLAGS_DEBUG "/Od /Gm /RTC1 /MTd /ZI" CACHE STRING "MSVC MT flags " FORCE)
910                 endif()
911                 set(CMAKE_C_FLAGS_RELEASE "/O2 /Ob2 /MT" CACHE STRING "MSVC MT flags " FORCE)
912                 set(CMAKE_C_FLAGS_MINSIZEREL "/O1 /Ob1 /MT" CACHE STRING "MSVC MT flags " FORCE)
913                 set(CMAKE_C_FLAGS_RELWITHDEBINFO "/O2 /Ob1 /MT /Zi" CACHE STRING "MSVC MT flags " FORCE)
914
915                 # most msvc warnings are C & C++
916                 set(_WARNINGS "/W3 /wd4018 /wd4244 /wd4305 /wd4800 /wd4181 /wd4065 /wd4267 /we4013 /wd4200")
917                 set(C_WARNINGS "${_WARNINGS}")
918                 set(CXX_WARNINGS "${_WARNINGS}")
919                 unset(_WARNINGS)
920
921                 if(WITH_INTERNATIONAL)
922                         set(GETTEXT ${LIBDIR}/gettext)
923                         set(GETTEXT_INCLUDE_DIRS ${GETTEXT}/include)
924                         set(GETTEXT_LIBPATH ${GETTEXT}/lib)
925                         set(GETTEXT_LIBRARIES gnu_gettext)
926                 endif()
927                 
928                 if(WITH_MOD_CLOTH_ELTOPO)
929                         set(LAPACK ${LIBDIR}/lapack)
930                         # set(LAPACK_INCLUDE_DIR ${LAPACK}/include)
931                         set(LAPACK_LIBPATH ${LAPACK}/lib)       
932                         set(LAPACK_LIBRARIES
933                                 ${LIBDIR}/lapack/lib/libf2c.lib
934                                 ${LIBDIR}/lapack/lib/clapack_nowrap.lib
935                                 ${LIBDIR}/lapack/lib/BLAS_nowrap.lib
936                         )
937                 endif()
938
939                 set(PNG_LIBRARIES libpng)
940                 set(JPEG_LIBRARIES libjpeg)
941                 
942                 set(PNG "${LIBDIR}/png")
943                 set(PNG_INCLUDE_DIR "${PNG}/include")
944                 set(PNG_LIBPATH ${PNG}/lib) # not cmake defined
945
946                 set(ZLIB_INCLUDE_DIRS ${LIBDIR}/zlib/include)
947                 if(CMAKE_CL_64)
948                         set(ZLIB_LIBRARIES ${LIBDIR}/zlib/lib/libz.lib)
949                 else()
950                         set(ZLIB_LIBRARIES ${LIBDIR}/zlib/lib/zlib.lib)
951                 endif()
952
953                 set(PTHREADS_INCLUDE_DIRS ${LIBDIR}/pthreads/include)
954                 set(PTHREADS_LIBRARIES ${LIBDIR}/pthreads/lib/pthreadVC2.lib)
955
956                 set(FREETYPE ${LIBDIR}/freetype)
957                 set(FREETYPE_INCLUDE_DIRS
958                         ${LIBDIR}/freetype/include
959                         ${LIBDIR}/freetype/include/freetype2
960                 )
961                 set(FREETYPE_LIBRARY ${LIBDIR}/freetype/lib/freetype2ST.lib)
962
963                 if(WITH_FFTW3)
964                         set(FFTW3 ${LIBDIR}/fftw3)
965                         set(FFTW3_LIBRARIES libfftw)
966                         set(FFTW3_INCLUDE_DIRS ${FFTW3}/include)
967                         set(FFTW3_LIBPATH ${FFTW3}/lib)
968                 endif()
969
970                 if(WITH_OPENCOLLADA)
971                         set(OPENCOLLADA ${LIBDIR}/opencollada)
972
973                         set(OPENCOLLADA_INCLUDE_DIRS
974                                 ${LIBDIR}/opencollada/include/COLLADAStreamWriter/include
975                                 ${LIBDIR}/opencollada/include/COLLADABaseUtils/include
976                                 ${LIBDIR}/opencollada/include/COLLADAFramework/include
977                                 ${LIBDIR}/opencollada/include/COLLADASaxFrameworkLoader/include
978                                 ${LIBDIR}/opencollada/include/GeneratedSaxParser/include
979                         )
980                         set_lib_path(OPENCOLLADA_LIBPATH "opencollada")
981
982                         set(OPENCOLLADA_LIBRARIES
983                                 ${OPENCOLLADA_LIBPATH}/lib/OpenCOLLADASaxFrameworkLoader.lib
984                                 ${OPENCOLLADA_LIBPATH}/lib/OpenCOLLADAFramework.lib
985                                 ${OPENCOLLADA_LIBPATH}/lib/OpenCOLLADABaseUtils.lib
986                                 ${OPENCOLLADA_LIBPATH}/lib/OpenCOLLADAStreamWriter.lib
987                                 ${OPENCOLLADA_LIBPATH}/lib/MathMLSolver.lib
988                                 ${OPENCOLLADA_LIBPATH}/lib/GeneratedSaxParser.lib
989                                 ${OPENCOLLADA_LIBPATH}/lib/xml2.lib
990                                 ${OPENCOLLADA_LIBPATH}/lib/buffer.lib
991                                 ${OPENCOLLADA_LIBPATH}/lib/ftoa.lib
992                                 ${OPENCOLLADA_LIBPATH}/lib/UTF.lib
993                         )
994                         set(PCRE_LIBRARIES
995                                 ${OPENCOLLADA_LIBPATH}/lib/pcre.lib
996                         )
997                         
998                         unset(OPENCOLLADA_LIBPATH)
999                         
1000                 endif()
1001
1002                 if(WITH_CODEC_FFMPEG)
1003                         set(FFMPEG_INCLUDE_DIRS
1004                                 ${LIBDIR}/ffmpeg/include
1005                                 ${LIBDIR}/ffmpeg/include/msvc
1006                         )
1007                         set(FFMPEG_LIBRARIES
1008                                 ${LIBDIR}/ffmpeg/lib/avcodec-53.lib
1009                                 ${LIBDIR}/ffmpeg/lib/avformat-53.lib
1010                                 ${LIBDIR}/ffmpeg/lib/avdevice-53.lib
1011                                 ${LIBDIR}/ffmpeg/lib/avutil-51.lib
1012                                 ${LIBDIR}/ffmpeg/lib/swscale-2.lib
1013                         )
1014                 endif()
1015
1016                 if(WITH_IMAGE_OPENEXR)
1017                         set_lib_path(OPENEXR "openexr")
1018                         set(OPENEXR_INCLUDE_DIR ${OPENEXR}/include)
1019                         set(OPENEXR_LIBPATH ${OPENEXR}/lib)
1020                         set(OPENEXR_LIBRARIES
1021                                 ${OPENEXR_LIBPATH}/Iex.lib
1022                                 ${OPENEXR_LIBPATH}/Half.lib
1023                                 ${OPENEXR_LIBPATH}/IlmImf.lib
1024                                 ${OPENEXR_LIBPATH}/Imath.lib
1025                                 ${OPENEXR_LIBPATH}/IlmThread.lib
1026                         )
1027                         set(OPENEXR_INCLUDE_DIRS
1028                                 ${OPENEXR_INCLUDE_DIR}
1029                                 ${OPENEXR_INCLUDE_DIR}/IlmImf
1030                                 ${OPENEXR_INCLUDE_DIR}/Iex
1031                                 ${OPENEXR_INCLUDE_DIR}/Imath
1032                         )
1033                 endif()
1034
1035                 if(WITH_IMAGE_TIFF)
1036                         set(TIFF_LIBRARY ${LIBDIR}/tiff/lib/libtiff.lib)
1037                         set(TIFF_INCLUDE_DIR ${LIBDIR}/tiff/include)
1038                 endif()
1039
1040                 if(WITH_JACK)
1041                         set(JACK_INCLUDE_DIRS
1042                                 ${LIBDIR}/jack/include/jack
1043                                 ${LIBDIR}/jack/include
1044                         )
1045                         set(JACK_LIBRARIES ${LIBDIR}/jack/lib/libjack.lib)
1046                 endif()
1047
1048                 if(WITH_PYTHON)
1049                         # normally cached but not since we include them with blender
1050                         set(PYTHON_VERSION 3.2) # CACHE STRING)
1051                         set_lib_path(PYTHON "python")
1052                         set(PYTHON_LIBRARY ${PYTHON}/lib/python32.lib) #CACHE FILEPATH
1053                         #Shared includes for both vc2008 and vc2010
1054                         set(PYTHON_INCLUDE_DIR ${LIBDIR}/python/include/python${PYTHON_VERSION})
1055
1056                         # uncached vars
1057                         set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}")
1058                         set(PYTHON_LIBRARIES  "${PYTHON_LIBRARY}")
1059                 endif()
1060
1061                 if(WITH_BOOST)
1062                         set(BOOST ${LIBDIR}/boost)
1063                         set(BOOST_INCLUDE_DIR ${BOOST}/include)
1064                         if(MSVC10)
1065                                 set(BOOST_LIBPATH ${BOOST}/vc2010/lib)
1066                                 set(BOOST_POSTFIX "vc100-mt-s-1_49.lib")
1067                                 set(BOOST_DEBUG_POSTFIX "vc100-mt-sgd-1_49.lib")
1068                         else()
1069                                 set(BOOST_LIBPATH ${BOOST}/lib)
1070                                 set(BOOST_POSTFIX "vc90-mt-s-1_49.lib")
1071                                 set(BOOST_DEBUG_POSTFIX "vc90-mt-sgd-1_49.lib")                                 
1072                         endif()
1073                         set(BOOST_LIBRARIES
1074                                 optimized libboost_date_time-${BOOST_POSTFIX} optimized libboost_filesystem-${BOOST_POSTFIX}
1075                                 optimized libboost_regex-${BOOST_POSTFIX} optimized libboost_system-${BOOST_POSTFIX} optimized libboost_thread-${BOOST_POSTFIX}
1076                                 debug libboost_date_time-${BOOST_DEBUG_POSTFIX} debug libboost_filesystem-${BOOST_DEBUG_POSTFIX}
1077                                 debug libboost_regex-${BOOST_DEBUG_POSTFIX} debug libboost_system-${BOOST_DEBUG_POSTFIX} debug libboost_thread-${BOOST_DEBUG_POSTFIX})
1078                         set(BOOST_DEFINITIONS "-DBOOST_ALL_NO_LIB")
1079                 endif()
1080                         
1081                 if(WITH_OPENIMAGEIO)
1082                         set(OPENIMAGEIO ${LIBDIR}/openimageio)
1083                         set(OPENIMAGEIO_INCLUDE_DIRS ${OPENIMAGEIO}/include)
1084                         set(OPENIMAGEIO_LIBRARIES OpenImageIO)
1085                         set(OPENIMAGEIO_LIBPATH ${OPENIMAGEIO}/lib)
1086                         set(OPENIMAGEIO_DEFINITIONS)
1087                 endif()
1088
1089                 if(WITH_OPENCOLORIO)
1090                         set(OPENCOLORIO ${LIBDIR}/opencolorio)
1091                         set(OPENCOLORIO_INCLUDE_DIRS ${OPENCOLORIO}/include)
1092                         set(OPENCOLORIO_LIBRARIES OpenColorIO)
1093                         set_lib_path(OPENCOLORIO_LIBPATH "opencolorio/lib")
1094                         set(OPENCOLORIO_DEFINITIONS)
1095                 endif()
1096
1097                 set(PLATFORM_LINKFLAGS "/SUBSYSTEM:CONSOLE /STACK:2097152 /INCREMENTAL:NO /NODEFAULTLIB:msvcrt.lib /NODEFAULTLIB:msvcmrt.lib /NODEFAULTLIB:msvcurt.lib /NODEFAULTLIB:msvcrtd.lib")
1098
1099                 # MSVC only, Mingw doesnt need
1100                 if(CMAKE_CL_64)
1101                         set(PLATFORM_LINKFLAGS "/MACHINE:X64 /OPT:NOREF ${PLATFORM_LINKFLAGS}")
1102                 else()
1103                         set(PLATFORM_LINKFLAGS "/MACHINE:IX86 /LARGEADDRESSAWARE ${PLATFORM_LINKFLAGS}")
1104                 endif()
1105
1106                 set(PLATFORM_LINKFLAGS_DEBUG "/NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:libc.lib")
1107
1108                 # used in many places so include globally, like OpenGL
1109                 blender_include_dirs("${PTHREADS_INCLUDE_DIRS}")
1110
1111         elseif(CMAKE_COMPILER_IS_GNUCC)
1112         # keep GCC specific stuff here          
1113                 set(PLATFORM_LINKLIBS "-lshell32 -lshfolder -lgdi32 -lmsvcrt -lwinmm -lmingw32 -lm -lws2_32 -lz -lstdc++ -lole32 -luuid -lwsock32 -lpsapi")
1114                 set(PLATFORM_CFLAGS "-pipe -funsigned-char -fno-strict-aliasing")
1115
1116                 if(WITH_MINGW64)
1117                         #We need to take care though not to have these on debug builds because they may play funky with gdb
1118                         if(CMAKE_BUILD_TYPE MATCHES "Release")
1119                                 set(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -mmmx -ftree-vectorize")
1120                         endif()
1121                         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive")
1122                         set(PLATFORM_LINKLIBS "${PLATFORM_LINKLIBS} -lpthread")
1123                         
1124                         add_definitions(-DFREE_WINDOWS64 -DMS_WIN64)
1125                         #Turn off OpenMP since it causes crashes on render for subsurfed/multiresolution meshes
1126                         set(WITH_OPENMP OFF)
1127                 endif()
1128
1129                 add_definitions(-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE)
1130
1131
1132                 add_definitions(-DFREE_WINDOWS)
1133
1134                 if(WITH_INTERNATIONAL)
1135                         set(GETTEXT ${LIBDIR}/gettext)
1136                         set(GETTEXT_INCLUDE_DIRS ${GETTEXT}/include)
1137                         set(GETTEXT_LIBPATH ${GETTEXT}/lib)
1138                         set(GETTEXT_LIBRARIES intl)
1139                 endif()
1140                 
1141                 set(PNG "${LIBDIR}/png")
1142                 set(PNG_INCLUDE_DIR "${PNG}/include")
1143                 set(PNG_LIBPATH ${PNG}/lib) # not cmake defined
1144
1145                 if(WITH_MINGW64)
1146                         set(JPEG_LIBRARIES jpeg)
1147                 else()
1148                         set(JPEG_LIBRARIES libjpeg)
1149                 endif()
1150                 set(PNG_LIBRARIES png)
1151
1152                 set(ZLIB ${LIBDIR}/zlib)
1153                 set(ZLIB_INCLUDE_DIRS ${ZLIB}/include)
1154                 set(ZLIB_LIBPATH ${ZLIB}/lib)
1155                 set(ZLIB_LIBRARIES z)
1156
1157                 #comes with own pthread library
1158                 if(NOT WITH_MINGW64)
1159                         set(PTHREADS ${LIBDIR}/pthreads)
1160                         set(PTHREADS_INCLUDE_DIRS ${PTHREADS}/include)
1161                         set(PTHREADS_LIBPATH ${PTHREADS}/lib)
1162                         set(PTHREADS_LIBRARIES pthreadGC2)
1163                 endif()
1164                 
1165                 set(FREETYPE ${LIBDIR}/freetype)
1166                 set(FREETYPE_INCLUDE_DIRS ${FREETYPE}/include ${FREETYPE}/include/freetype2)
1167                 set(FREETYPE_LIBPATH ${FREETYPE}/lib)
1168                 set(FREETYPE_LIBRARY freetype)
1169
1170                 if(WITH_FFTW3)
1171                         set(FFTW3 ${LIBDIR}/fftw3)
1172                         set(FFTW3_LIBRARIES fftw3)
1173                         set(FFTW3_INCLUDE_DIRS ${FFTW3}/include)
1174                         set(FFTW3_LIBPATH ${FFTW3}/lib)
1175                 endif()
1176
1177                 if(WITH_OPENCOLLADA)
1178                         set(OPENCOLLADA ${LIBDIR}/opencollada)
1179                         set(OPENCOLLADA_INCLUDE_DIRS
1180                                 ${LIBDIR}/opencollada/include/COLLADAStreamWriter/include
1181                                 ${LIBDIR}/opencollada/include/COLLADABaseUtils/include
1182                                 ${LIBDIR}/opencollada/include/COLLADAFramework/include
1183                                 ${LIBDIR}/opencollada/include/COLLADASaxFrameworkLoader/include
1184                                 ${LIBDIR}/opencollada/include/GeneratedSaxParser/include
1185                         )
1186                         set(OPENCOLLADA_LIBPATH ${OPENCOLLADA}/lib ${OPENCOLLADA}/lib)
1187                         if(WITH_MINGW64)
1188                                 set(OPENCOLLADA_LIBRARIES OpenCOLLADAStreamWriter OpenCOLLADASaxFrameworkLoader OpenCOLLADAFramework OpenCOLLADABaseUtils GeneratedSaxParser UTF MathMLSolver pcre buffer ftoa xml)
1189                         else()
1190                                 set(OPENCOLLADA_LIBRARIES OpenCOLLADAStreamWriter OpenCOLLADASaxFrameworkLoader OpenCOLLADAFramework OpenCOLLADABaseUtils GeneratedSaxParser UTF MathMLSolver expat pcre buffer ftoa)
1191                         endif()
1192                         set(PCRE_LIBRARIES pcre)
1193                 endif()
1194
1195                 if(WITH_CODEC_FFMPEG)
1196                         set(FFMPEG ${LIBDIR}/ffmpeg)
1197                         set(FFMPEG_INCLUDE_DIRS ${FFMPEG}/include)
1198                         if(WITH_MINGW64)
1199                                 set(FFMPEG_LIBRARIES avcodec.dll avformat.dll avdevice.dll avutil.dll swscale.dll swresample.dll)
1200                         else()
1201                                 set(FFMPEG_LIBRARIES avcodec-53 avformat-53 avdevice-53 avutil-51 swscale-2)
1202                         endif()
1203                         set(FFMPEG_LIBPATH ${FFMPEG}/lib)
1204                 endif()
1205
1206                 if(WITH_IMAGE_OPENEXR)
1207                         set(OPENEXR ${LIBDIR}/openexr)
1208                         set(OPENEXR_INCLUDE_DIRS ${OPENEXR}/include/OpenEXR)
1209                         set(OPENEXR_LIBRARIES Half IlmImf Imath IlmThread Iex)
1210                         set(OPENEXR_LIBPATH ${OPENEXR}/lib)
1211                 endif()
1212
1213                 if(WITH_IMAGE_TIFF)
1214                         set(TIFF ${LIBDIR}/tiff)
1215                         set(TIFF_LIBRARY tiff)
1216                         set(TIFF_INCLUDE_DIR ${TIFF}/include)
1217                         set(TIFF_LIBPATH ${TIFF}/lib)
1218                 endif()
1219
1220                 if(WITH_JACK)
1221                         set(JACK ${LIBDIR}/jack)
1222                         set(JACK_INCLUDE_DIRS ${JACK}/include/jack ${JACK}/include)
1223                         set(JACK_LIBRARIES jack)
1224                         set(JACK_LIBPATH ${JACK}/lib)
1225
1226                         # TODO, gives linking errors, force off
1227                         set(WITH_JACK OFF)
1228                 endif()
1229
1230                 if(WITH_PYTHON)
1231                         # normally cached but not since we include them with blender
1232                         set(PYTHON_VERSION 3.2) #  CACHE STRING)
1233                         set(PYTHON_INCLUDE_DIR "${LIBDIR}/python/include/python${PYTHON_VERSION}")  # CACHE PATH)
1234                         set(PYTHON_LIBRARY "${LIBDIR}/python/lib/python32mw.lib")  # CACHE FILEPATH)
1235
1236                         # uncached vars
1237                         set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}")
1238                         set(PYTHON_LIBRARIES  "${PYTHON_LIBRARY}")
1239                 endif()
1240
1241                 if(WITH_BOOST)
1242                         set(BOOST ${LIBDIR}/boost)
1243                         set(BOOST_INCLUDE_DIR ${BOOST}/include)
1244                         if(WITH_MINGW64)
1245                                 set(BOOST_POSTFIX "mgw47-mt-s-1_49")
1246                                 set(BOOST_DEBUG_POSTFIX "mgw47-mt-sd-1_49")
1247                         else()
1248                                 set(BOOST_POSTFIX "mgw46-mt-s-1_49")
1249                                 set(BOOST_DEBUG_POSTFIX "mgw46-mt-sd-1_49")
1250                         endif()         
1251                         set(BOOST_LIBRARIES
1252                                 optimized boost_date_time-${BOOST_POSTFIX} boost_filesystem-${BOOST_POSTFIX}
1253                                 boost_regex-${BOOST_POSTFIX} boost_system-${BOOST_POSTFIX} boost_thread-${BOOST_POSTFIX}
1254                                 debug boost_date_time-${BOOST_DEBUG_POSTFIX} boost_filesystem-${BOOST_DEBUG_POSTFIX}
1255                                 boost_regex-${BOOST_DEBUG_POSTFIX} boost_system-${BOOST_DEBUG_POSTFIX} boost_thread-${BOOST_DEBUG_POSTFIX})
1256                         set(BOOST_LIBPATH ${BOOST}/lib)
1257                         set(BOOST_DEFINITIONS "-DBOOST_ALL_NO_LIB -DBOOST_THREAD_USE_LIB ")
1258                 endif()
1259                         
1260                 if(WITH_OPENIMAGEIO)
1261                         set(OPENIMAGEIO ${LIBDIR}/openimageio)
1262                         set(OPENIMAGEIO_INCLUDE_DIRS ${OPENIMAGEIO}/include)
1263                         set(OPENIMAGEIO_LIBRARIES OpenImageIO)
1264                         set(OPENIMAGEIO_LIBPATH ${OPENIMAGEIO}/lib)
1265                         set(OPENIMAGEIO_DEFINITIONS)
1266                 endif()
1267                 
1268                 if(WITH_OPENCOLORIO)
1269                         set(OPENCOLORIO ${LIBDIR}/opencolorio)
1270                         set(OPENCOLORIO_INCLUDE_DIRS ${OPENCOLORIO}/include)
1271                         set(OPENCOLORIO_LIBRARIES OpenColorIO)
1272                         set(OPENCOLORIO_LIBPATH ${OPENCOLORIO}/lib)
1273                         set(OPENCOLORIO_DEFINITIONS)
1274                 endif()
1275
1276                 set(PLATFORM_LINKFLAGS "-Xlinker --stack=2097152")
1277
1278                 ## DISABLE - causes linking errors 
1279                 ## for re-distrobution, so users dont need mingw installed
1280                 # set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -static-libgcc -static-libstdc++")
1281
1282         endif()
1283
1284 elseif(APPLE)
1285
1286         if(${CMAKE_OSX_DEPLOYMENT_TARGET} STREQUAL "10.5" OR ${CMAKE_OSX_DEPLOYMENT_TARGET} STRGREATER "10.5")
1287                 set(WITH_LIBS10.5 ON CACHE BOOL "Use 10.5 libs" FORCE) # valid also for 10.6/10.7
1288         endif()
1289
1290         if(${XCODE_VERSION} VERSION_LESS 4.3)
1291                 set(CMAKE_OSX_SYSROOT /Developer/SDKs/MacOSX${OSX_SYSTEM}.sdk CACHE PATH "" FORCE)  # use guaranteed existing sdk
1292         else()
1293                 # note: i don't use xcode-select path on purpose, cause also /Applications/Xcode.app would be allowed
1294                 # absolute pathes are more foolproof here !
1295                 set(OSX_SYSROOT_PREFIX /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform)
1296                 set(OSX_DEVELOPER_PREFIX /Developer/SDKs/MacOSX${OSX_SYSTEM}.sdk) # use guaranteed existing sdk
1297                 set(CMAKE_OSX_SYSROOT ${OSX_SYSROOT_PREFIX}/${OSX_DEVELOPER_PREFIX} CACHE PATH "" FORCE)
1298         endif() 
1299         
1300         if(WITH_LIBS10.5)
1301                 set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/darwin-9.x.universal)
1302         else()
1303                 if(CMAKE_OSX_ARCHITECTURES MATCHES i386)
1304                         set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/darwin-8.x.i386)
1305                 else()
1306                         set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/darwin-8.0.0-powerpc)
1307                 endif()
1308         endif()
1309
1310
1311         if(WITH_OPENAL)
1312                 find_package(OpenAL)
1313                 if(OPENAL_FOUND)
1314                         set(WITH_OPENAL ON)
1315                         set(OPENAL_INCLUDE_DIR "${LIBDIR}/openal/include")
1316                 else()
1317                         set(WITH_OPENAL OFF)
1318                 endif()
1319         endif()
1320
1321         if(WITH_JACK)
1322                 set(JACK /usr)
1323                 set(JACK_INCLUDE_DIRS ${JACK}/include/jack)
1324                 set(JACK_LIBRARIES jack)
1325                 set(JACK_LIBPATH ${JACK}/lib)
1326         endif()
1327
1328         if(WITH_CODEC_SNDFILE)
1329                 set(SNDFILE ${LIBDIR}/sndfile)
1330                 set(SNDFILE_INCLUDE_DIRS ${SNDFILE}/include)
1331                 set(SNDFILE_LIBRARIES sndfile FLAC ogg vorbis vorbisenc)
1332                 set(SNDFILE_LIBPATH ${SNDFILE}/lib ${FFMPEG}/lib)  # TODO, deprecate
1333         endif()
1334
1335         if(WITH_PYTHON)
1336                 if(NOT WITH_PYTHON_MODULE)
1337                         # we use precompiled libraries for py 3.2 and up by default
1338
1339                         # normally cached but not since we include them with blender
1340                         set(PYTHON_VERSION 3.2)
1341                         set(PYTHON_INCLUDE_DIR "${LIBDIR}/python/include/python${PYTHON_VERSION}")
1342                         # set(PYTHON_BINARY "${LIBDIR}/python/bin/python${PYTHON_VERSION}") # not used yet
1343                         set(PYTHON_LIBRARY python${PYTHON_VERSION})
1344                         set(PYTHON_LIBPATH "${LIBDIR}/python/lib/python${PYTHON_VERSION}")
1345                         # set(PYTHON_LINKFLAGS "-u _PyMac_Error")  # won't  build with this enabled
1346                 else()
1347                         # module must be compiled against Python framework
1348
1349                         # normally cached but not since we include them with blender
1350                         set(PYTHON_VERSION 3.2)
1351                         set(PYTHON_INCLUDE_DIR "/Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}/include/python${PYTHON_VERSION}m")
1352                         set(PYTHON_BINARY "/Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}/bin/python${PYTHON_VERSION}")
1353                         #set(PYTHON_LIBRARY python${PYTHON_VERSION})
1354                         set(PYTHON_LIBPATH "/Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}/lib/python${PYTHON_VERSION}/config-3.2m")
1355                         #set(PYTHON_LINKFLAGS "-u _PyMac_Error -framework Python")  # won't  build with this enabled
1356                 endif()
1357                 
1358                 # uncached vars
1359                 set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}")
1360                 set(PYTHON_LIBRARIES  "${PYTHON_LIBRARY}")
1361         endif()
1362
1363         if(WITH_INTERNATIONAL)
1364                 set(GETTEXT ${LIBDIR}/gettext)
1365                 set(GETTEXT_INCLUDE_DIRS "${GETTEXT}/include")
1366                 set(GETTEXT_LIBRARIES intl iconv)
1367                 set(GETTEXT_LIBPATH ${GETTEXT}/lib)
1368         endif()
1369
1370         if(WITH_FFTW3)
1371                 set(FFTW3 ${LIBDIR}/fftw3)
1372                 set(FFTW3_INCLUDE_DIRS ${FFTW3}/include)
1373                 set(FFTW3_LIBRARIES fftw3)
1374                 set(FFTW3_LIBPATH ${FFTW3}/lib)
1375         endif()
1376
1377         set(PNG_LIBRARIES png)
1378         set(JPEG_LIBRARIES jpeg)
1379
1380         set(ZLIB /usr)
1381         set(ZLIB_INCLUDE_DIRS "${ZLIB}/include")
1382         set(ZLIB_LIBRARIES z bz2)
1383
1384         set(FREETYPE ${LIBDIR}/freetype)
1385         set(FREETYPE_INCLUDE_DIRS ${FREETYPE}/include ${FREETYPE}/include/freetype2)
1386         set(FREETYPE_LIBPATH ${FREETYPE}/lib)
1387         set(FREETYPE_LIBRARY freetype)
1388
1389         if(WITH_IMAGE_OPENEXR)
1390                 set(OPENEXR ${LIBDIR}/openexr)
1391                 set(OPENEXR_INCLUDE_DIRS ${OPENEXR}/include/OpenEXR)
1392                 set(OPENEXR_LIBRARIES Iex Half IlmImf Imath IlmThread)
1393                 set(OPENEXR_LIBPATH ${OPENEXR}/lib)
1394         endif()
1395
1396         if(WITH_CODEC_FFMPEG)
1397                 set(FFMPEG ${LIBDIR}/ffmpeg)
1398                 set(FFMPEG_INCLUDE_DIRS ${FFMPEG}/include)
1399                 set(FFMPEG_LIBRARIES avcodec avdevice avformat avutil mp3lame swscale x264 xvidcore theora theoradec theoraenc vorbis vorbisenc vorbisfile ogg)
1400                 set(FFMPEG_LIBPATH ${FFMPEG}/lib)
1401                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__STDC_CONSTANT_MACROS")
1402         endif()
1403
1404         find_library(SYSTEMSTUBS_LIBRARY
1405                 NAMES
1406                 SystemStubs
1407                 PATHS
1408         )
1409         mark_as_advanced(SYSTEMSTUBS_LIBRARY)
1410         if(SYSTEMSTUBS_LIBRARY)
1411                 set(PLATFORM_LINKLIBS stdc++ SystemStubs)
1412         else()
1413                 set(PLATFORM_LINKLIBS stdc++)
1414         endif()
1415
1416         if(WITH_COCOA)
1417                 set(PLATFORM_CFLAGS "-pipe -funsigned-char -DGHOST_COCOA")
1418                 set(PLATFORM_LINKFLAGS "-fexceptions -framework CoreServices -framework Foundation -framework IOKit -framework AppKit -framework Cocoa -framework Carbon -framework AudioUnit -framework AudioToolbox -framework CoreAudio")
1419                 if(USE_QTKIT)
1420                         set(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -DUSE_QTKIT")
1421                         set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -framework QTKit")
1422                         if(CMAKE_OSX_ARCHITECTURES MATCHES i386)
1423                                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -framework QuickTime")
1424                                 #libSDL still needs 32bit carbon quicktime
1425                         endif()
1426                 elseif(WITH_CODEC_QUICKTIME)
1427                         set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -framework QuickTime")
1428                 endif()
1429
1430                 # XXX - SOME MAC DEV PLEASE TEST WITH THE SDK INSTALLED!
1431                 # ALSO SHOULD BE MOVED INTO OWN MODULE WHEN FUNCTIONAL
1432                 if(WITH_INPUT_NDOF)
1433                         # This thread it *should* work and check the framework - campbell
1434                         # http://www.cmake.org/pipermail/cmake/2005-December/007740.html
1435                         find_library(3D_CONNEXION_CLIENT_LIBRARY
1436                                 NAMES 3DconnexionClient
1437                         )
1438                         if(NOT 3D_CONNEXION_CLIENT_LIBRARY)
1439                                 set(WITH_INPUT_NDOF OFF)
1440                         endif()
1441
1442                         if(WITH_INPUT_NDOF)
1443                                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -weak_framework 3DconnexionClient")
1444                         endif()
1445                 endif()
1446
1447         else()
1448                 set(PLATFORM_CFLAGS "-pipe -funsigned-char")
1449                 set(PLATFORM_LINKFLAGS "-fexceptions -framework CoreServices -framework Foundation -framework IOKit -framework AppKit -framework Carbon -framework AGL -framework AudioUnit -framework AudioToolbox -framework CoreAudio -framework QuickTime")
1450                 set(WITH_INPUT_NDOF OFF)  # unsupported
1451         endif()
1452         
1453         if(WITH_PYTHON_MODULE)
1454                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} /Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}/python")# force cmake to link right framework
1455         endif()
1456         
1457         if(WITH_OPENCOLLADA)
1458                 set(OPENCOLLADA ${LIBDIR}/opencollada)
1459
1460                 set(OPENCOLLADA_INCLUDE_DIRS
1461                         ${LIBDIR}/opencollada/include/COLLADAStreamWriter
1462                         ${LIBDIR}/opencollada/include/COLLADABaseUtils
1463                         ${LIBDIR}/opencollada/include/COLLADAFramework
1464                         ${LIBDIR}/opencollada/include/COLLADASaxFrameworkLoader
1465                         ${LIBDIR}/opencollada/include/GeneratedSaxParser
1466                 )
1467
1468                 set(OPENCOLLADA_LIBPATH ${OPENCOLLADA}/lib)
1469                 set(OPENCOLLADA_LIBRARIES "OpenCOLLADASaxFrameworkLoader -lOpenCOLLADAFramework -lOpenCOLLADABaseUtils -lOpenCOLLADAStreamWriter -lMathMLSolver -lGeneratedSaxParser -lUTF -lxml2 -lbuffer -lftoa")
1470                 #pcre is bundled with openCollada
1471                 #set(PCRE ${LIBDIR}/pcre)
1472                 #set(PCRE_LIBPATH ${PCRE}/lib)
1473                 set(PCRE_LIBRARIES pcre)
1474                 #libxml2 is used
1475                 #set(EXPAT ${LIBDIR}/expat)
1476                 #set(EXPAT_LIBPATH ${EXPAT}/lib)
1477                 set(EXPAT_LIB)
1478         endif()
1479
1480         if(WITH_SDL)
1481                 set(SDL ${LIBDIR}/sdl)
1482                 set(SDL_INCLUDE_DIR ${SDL}/include)
1483                 set(SDL_LIBRARY SDL)
1484                 set(SDL_LIBPATH ${SDL}/lib)
1485         endif()
1486
1487         set(PNG "${LIBDIR}/png")
1488         set(PNG_INCLUDE_DIR "${PNG}/include")
1489         set(PNG_LIBPATH ${PNG}/lib)
1490
1491         set(JPEG "${LIBDIR}/jpeg")
1492         set(JPEG_INCLUDE_DIR "${JPEG}/include")
1493         set(JPEG_LIBPATH ${JPEG}/lib)
1494
1495         if(WITH_IMAGE_TIFF)
1496                 set(TIFF ${LIBDIR}/tiff)
1497                 set(TIFF_INCLUDE_DIR ${TIFF}/include)
1498                 set(TIFF_LIBRARY tiff)
1499                 set(TIFF_LIBPATH ${TIFF}/lib)
1500         endif()
1501
1502         if (WITH_INPUT_NDOF)
1503                 # linker needs "-weak_framework 3DconnexionClient"
1504         endif()
1505
1506         if(WITH_BOOST)
1507                 set(BOOST ${LIBDIR}/boost)
1508                 set(BOOST_INCLUDE_DIR ${BOOST}/include)
1509                 set(BOOST_LIBRARIES boost_date_time-mt boost_filesystem-mt boost_regex-mt boost_system-mt boost_thread-mt)
1510                 set(BOOST_LIBPATH ${BOOST}/lib)
1511                 set(BOOST_DEFINITIONS)
1512         endif()
1513
1514         if(WITH_OPENIMAGEIO)
1515                 set(OPENIMAGEIO ${LIBDIR}/openimageio)
1516                 set(OPENIMAGEIO_INCLUDE_DIRS ${OPENIMAGEIO}/include)
1517                 set(OPENIMAGEIO_LIBRARIES OpenImageIO ${PNG_LIBRARIES} ${JPEG_LIBRARIES} ${TIFF_LIBRARY} ${OPENEXR_LIBRARIES} ${ZLIB_LIBRARIES})
1518                 set(OPENIMAGEIO_LIBPATH ${OPENIMAGEIO}/lib ${JPEG_LIBPATH} ${PNG_LIBPATH} ${TIFF_LIBPATH} ${OPENEXR_LIBPATH} ${ZLIB_LIBPATH})
1519                 set(OPENIMAGEIO_DEFINITIONS "-DOIIO_STATIC_BUILD")
1520         endif()
1521
1522         if(WITH_OPENCOLORIO)
1523                 set(OPENCOLORIO ${LIBDIR}/opencolorio)
1524                 set(OPENCOLORIO_INCLUDE_DIRS ${OPENCOLORIO}/include)
1525                 set(OPENCOLORIO_LIBRARIES OpenColorIO tinyxml yaml-cpp)
1526                 set(OPENCOLORIO_LIBPATH ${OPENCOLORIO}/lib)
1527                 set(OPENCOLORIO_DEFINITIONS "-DOCIO_STATIC_BUILD")
1528         endif()
1529
1530         if(WITH_CYCLES_OSL)
1531                 set(CYCLES_OSL ${LIBDIR}/osl CACHE PATH "Path to OpenShadingLanguage installation")
1532         
1533                 message(STATUS "CYCLES_OSL = ${CYCLES_OSL}")
1534         
1535                 find_library(OSL_LIB_EXEC NAMES oslexec PATHS ${CYCLES_OSL}/lib)
1536                 find_library(OSL_LIB_COMP NAMES oslcomp PATHS ${CYCLES_OSL}/lib)
1537                 find_library(OSL_LIB_QUERY NAMES oslquery PATHS ${CYCLES_OSL}/lib)
1538                 # WARNING! depends on correct order of OSL libs linking
1539                 list(APPEND OSL_LIBRARIES ${OSL_LIB_COMP} ${OSL_LIB_EXEC} ${OSL_LIB_QUERY})
1540                 find_path(OSL_INCLUDES OSL/oslclosure.h PATHS ${CYCLES_OSL}/include)
1541                 find_program(OSL_COMPILER NAMES oslc PATHS ${CYCLES_OSL}/bin)
1542         
1543                 if(OSL_INCLUDES AND OSL_LIBRARIES AND OSL_COMPILER)
1544                         set(OSL_FOUND TRUE)
1545                         message(STATUS "OSL includes = ${OSL_INCLUDES}")
1546                         message(STATUS "OSL library = ${OSL_LIBRARIES}")
1547                         message(STATUS "OSL compiler = ${OSL_COMPILER}")
1548                 else()
1549                         message(STATUS "OSL not found")
1550                 endif()
1551         
1552                 include_directories(${OSL_INCLUDES})
1553         endif()
1554
1555         set(EXETYPE MACOSX_BUNDLE)
1556
1557         set(CMAKE_C_FLAGS_DEBUG "-fno-strict-aliasing -g")
1558         set(CMAKE_CXX_FLAGS_DEBUG "-fno-strict-aliasing -g")
1559         if(CMAKE_OSX_ARCHITECTURES MATCHES "i386")
1560                 set(CMAKE_CXX_FLAGS_RELEASE "-O2 -mdynamic-no-pic -ftree-vectorize -msse -msse2 -fvariable-expansion-in-unroller")
1561                 set(CMAKE_C_FLAGS_RELEASE "-O2 -mdynamic-no-pic -ftree-vectorize -msse -msse2 -fvariable-expansion-in-unroller")
1562         elseif(CMAKE_OSX_ARCHITECTURES MATCHES "x86_64")
1563                 set(CMAKE_CXX_FLAGS_RELEASE "-O2 -mdynamic-no-pic -ftree-vectorize -msse -msse2 -msse3 -mssse3 -fvariable-expansion-in-unroller")
1564                 set(CMAKE_C_FLAGS_RELEASE "-O2 -mdynamic-no-pic -ftree-vectorize -msse -msse2 -msse3 -mssse3 -fvariable-expansion-in-unroller")
1565         else()
1566                 set(CMAKE_C_FLAGS_RELEASE "-mdynamic-no-pic -fno-strict-aliasing")
1567                 set(CMAKE_CXX_FLAGS_RELEASE "-mdynamic-no-pic -fno-strict-aliasing")
1568         endif()
1569 endif()
1570
1571 #-----------------------------------------------------------------------------
1572 # Common.
1573
1574 if(APPLE OR WIN32)
1575         if(NOT EXISTS "${LIBDIR}/")
1576                 message(FATAL_ERROR "Apple and Windows require pre-compiled libs at: '${LIBDIR}'")
1577         endif()
1578 endif()
1579
1580 if(WITH_CYCLES)
1581         if(NOT WITH_OPENIMAGEIO)
1582                 message(FATAL_ERROR "Cycles reqires WITH_OPENIMAGEIO, the library may not have been found. Configure OIIO or disable WITH_CYCLES")
1583         endif()
1584         if(NOT WITH_BOOST)
1585                 message(FATAL_ERROR "Cycles reqires WITH_BOOST, the library may not have been found. Configure BOOST or disable WITH_CYCLES")
1586         endif()
1587 endif()
1588
1589
1590 # See TEST_SSE_SUPPORT() for how this is defined.
1591
1592 if(WITH_RAYOPTIMIZATION)
1593         if(SUPPORT_SSE_BUILD)
1594                 set(PLATFORM_CFLAGS " ${COMPILER_SSE_FLAG} ${PLATFORM_CFLAGS}")
1595                 add_definitions(-D__SSE__ -D__MMX__)
1596         endif()
1597         if(SUPPORT_SSE2_BUILD)
1598                 set(PLATFORM_CFLAGS " ${COMPILER_SSE2_FLAG} ${PLATFORM_CFLAGS}")
1599                 add_definitions(-D__SSE2__)
1600                 if(NOT SUPPORT_SSE_BUILD) # dont double up
1601                         add_definitions(-D__MMX__)
1602                 endif()
1603         endif()
1604 endif()
1605
1606
1607 # set the endian define
1608 if(MSVC)
1609         # for some reason this fails on msvc
1610         add_definitions(-D__LITTLE_ENDIAN__)
1611         
1612 # OSX-Note: as we do crosscompiling with specific set architecture,
1613 # endianess-detection and autosetting is counterproductive
1614 # so we just set endianess according CMAKE_OSX_ARCHITECTURES
1615
1616 elseif(CMAKE_OSX_ARCHITECTURES MATCHES i386 OR CMAKE_OSX_ARCHITECTURES MATCHES x86_64)
1617         add_definitions(-D__LITTLE_ENDIAN__)
1618 elseif(CMAKE_OSX_ARCHITECTURES MATCHES ppc OR CMAKE_OSX_ARCHITECTURES MATCHES ppc64)            
1619         add_definitions(-D__BIG_ENDIAN__)
1620         
1621 else()
1622         include(TestBigEndian)
1623         test_big_endian(_SYSTEM_BIG_ENDIAN)
1624         if(_SYSTEM_BIG_ENDIAN)
1625                 add_definitions(-D__BIG_ENDIAN__)
1626         else()
1627                 add_definitions(-D__LITTLE_ENDIAN__)
1628         endif()
1629         unset(_SYSTEM_BIG_ENDIAN)
1630 endif()
1631
1632
1633 if(WITH_IMAGE_OPENJPEG)
1634         if(WITH_SYSTEM_OPENJPEG)
1635                 # dealt with above
1636         else()
1637                 set(OPENJPEG_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/extern/libopenjpeg")
1638                 add_definitions(-DOPJ_STATIC)
1639         endif()
1640 endif()
1641
1642 if(WITH_IMAGE_REDCODE)
1643         set(REDCODE ${CMAKE_SOURCE_DIR}/extern)
1644         set(REDCODE_INC ${REDCODE})
1645 endif()
1646
1647 #-----------------------------------------------------------------------------
1648 # Blender WebPlugin
1649
1650 if(WITH_WEBPLUGIN)
1651         set(GECKO_DIR "${CMAKE_SOURCE_DIR}/../gecko-sdk/" CACHE PATH "Gecko SDK path")
1652         set(WEBPLUGIN_SANDBOX_MODE "apparmor" CACHE STRING "WEB Plugin sandbox mode, can be apparmor, privsep, none")
1653
1654         set(WITH_PLAYER ON)
1655 endif()
1656
1657
1658 #-----------------------------------------------------------------------------
1659 # Configure OpenGL.
1660 find_package(OpenGL)
1661 blender_include_dirs_sys("${OPENGL_INCLUDE_DIR}")
1662 # unset(OPENGL_LIBRARIES CACHE) # not compat with older cmake
1663 # unset(OPENGL_xmesa_INCLUDE_DIR CACHE) # not compat with older cmake
1664
1665 #-----------------------------------------------------------------------------
1666 # Configure OpenMP.
1667 if(WITH_OPENMP)
1668         find_package(OpenMP)
1669         if(OPENMP_FOUND)
1670                 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
1671                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
1672
1673                 if(APPLE AND ${CMAKE_GENERATOR} MATCHES "Xcode")
1674                         set(CMAKE_XCODE_ATTRIBUTE_ENABLE_OPENMP_SUPPORT "YES")
1675                 endif()
1676         else()
1677                 set(WITH_OPENMP OFF)
1678         endif()
1679
1680         mark_as_advanced(
1681                 OpenMP_C_FLAGS
1682                 OpenMP_CXX_FLAGS
1683         )
1684 endif()
1685
1686 #-----------------------------------------------------------------------------
1687 # Configure GLEW
1688
1689 if(WITH_SYSTEM_GLEW)
1690         find_package(GLEW)
1691
1692         if(NOT GLEW_FOUND)
1693                 message(FATAL_ERROR "GLEW is required to build blender, install it or disable WITH_SYSTEM_GLEW")
1694         endif()
1695
1696         mark_as_advanced(
1697                 GLEW_LIBRARY
1698                 GLEW_INCLUDE_PATH
1699         )
1700 else()
1701         # set(GLEW_LIBRARY "")  # unused
1702         set(GLEW_INCLUDE_PATH "${CMAKE_SOURCE_DIR}/extern/glew/include")
1703 endif()
1704
1705 #-----------------------------------------------------------------------------
1706 # Configure Python.
1707
1708 if(WITH_PYTHON_MODULE)
1709         add_definitions(-DPy_ENABLE_SHARED)
1710 endif()
1711
1712 #-----------------------------------------------------------------------------
1713 # Extra compile flags
1714
1715 if(CMAKE_COMPILER_IS_GNUCC)
1716
1717         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
1718         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_CAST_ALIGN -Wcast-align)
1719         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_DECLARATION_AFTER_STATEMENT -Werror=declaration-after-statement)
1720         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_IMPLICIT_FUNCTION_DECLARATION -Werror=implicit-function-declaration)
1721         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_RETURN_TYPE  -Werror=return-type)
1722         # system headers sometimes do this, disable for now, was: -Werror=strict-prototypes
1723         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_STRICT_PROTOTYPES  -Wstrict-prototypes)
1724         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_MISSING_PROTOTYPES -Wmissing-prototypes)
1725         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_CHAR_SUBSCRIPTS -Wno-char-subscripts)
1726         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
1727         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_POINTER_ARITH -Wpointer-arith)
1728         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNUSED_PARAMETER -Wunused-parameter)
1729         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_WRITE_STRINGS -Wwrite-strings)
1730         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_LOGICAL_OP -Wlogical-op)
1731         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNDEF -Wundef)
1732         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNINITIALIZED -Wuninitialized)
1733         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_INIT_SELF -Winit-self)  # needs -Wuninitialized
1734         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_NULL -Wnonnull)
1735
1736         # # this causes too many warnings, disable
1737         # ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNDEFINED -Wundef)
1738
1739         # disable because it gives warnings for printf() & friends.
1740         # ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_DOUBLE_PROMOTION -Wdouble-promotion -Wno-error=double-promotion)
1741
1742         if(NOT APPLE)
1743                 ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_ERROR_UNUSED_BUT_SET_VARIABLE -Wno-error=unused-but-set-variable)
1744         endif()
1745
1746         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ALL -Wall)
1747         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_INVALID_OFFSETOF -Wno-invalid-offsetof)
1748         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_SIGN_COMPARE -Wno-sign-compare)
1749         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_MISSING_DECLARATIONS -Wmissing-declarations)
1750         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_LOGICAL_OP -Wlogical-op)
1751         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNDEF -Wundef)
1752         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNINITIALIZED -Wuninitialized)
1753         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_INIT_SELF -Winit-self)  # needs -Wuninitialized
1754         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_NULL -Wnonnull)
1755
1756         # # this causes too many warnings, disable
1757         # ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNDEFINED -Wundef)
1758
1759         # flags to undo strict flags
1760         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_DEPRECATED_DECLARATIONS -Wno-deprecated-declarations)
1761         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_PARAMETER        -Wno-unused-parameter)
1762
1763         if(NOT APPLE)
1764                 ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_ERROR_UNUSED_BUT_SET_VARIABLE -Wno-error=unused-but-set-variable)
1765         endif()
1766
1767 elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
1768
1769         # strange, clang complains these are not supported, but then yses them.
1770         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
1771         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_AUTOLOGICAL_COMPARE -Wno-tautological-compare)
1772         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
1773         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_CHAR_SUBSCRIPTS -Wno-char-subscripts)
1774         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_STRICT_PROTOTYPES  -Wstrict-prototypes)
1775         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_MISSING_PROTOTYPES -Wmissing-prototypes)
1776
1777         ADD_CHECK_C_COMPILER_FLAG(CXX_WARNINGS C_WARN_ALL -Wall)
1778         ADD_CHECK_C_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_AUTOLOGICAL_COMPARE -Wno-tautological-compare)
1779         ADD_CHECK_C_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
1780         ADD_CHECK_C_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_CHAR_SUBSCRIPTS -Wno-char-subscripts)
1781         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.
1782         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_INVALID_OFFSETOF -Wno-invalid-offsetof)
1783
1784 elseif(CMAKE_C_COMPILER_ID MATCHES "Intel")
1785
1786         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
1787         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_POINTER_ARITH -Wpointer-arith)
1788         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
1789
1790         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ALL -Wall)
1791         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_INVALID_OFFSETOF -Wno-invalid-offsetof)
1792         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_SIGN_COMPARE -Wno-sign-compare)
1793
1794         # disable numbered, false positives
1795         set(C_WARNINGS "${C_WARNINGS} -wd188,186,144,913,556")
1796         set(CXX_WARNINGS "${CXX_WARNINGS} -wd188,186,144,913,556")
1797
1798 endif()
1799
1800 # MSVC2010 fails to links C++ libs right
1801 if(MSVC10)
1802         if(WITH_OPENCOLLADA)
1803                 message(WARNING "MSVC 2010 does not support OpenCollada, disabling WITH_OPENCOLLADA. To enable support use Use MSVC 2008")
1804         endif()
1805 endif()
1806
1807 # ensure python header is found since detection can fail, this could happen
1808 # with _any_ library but since we used a fixed python version this tends to
1809 # be most problematic.
1810 if(WITH_PYTHON)
1811         if(NOT EXISTS "${PYTHON_INCLUDE_DIR}/Python.h")
1812                 message(FATAL_ERROR "Missing: \"${PYTHON_INCLUDE_DIR}/Python.h\",\n"
1813                                                         "Set the cache entry 'PYTHON_INCLUDE_DIR' to point "
1814                                                         "to a valid python include path. Containing "
1815                                                         "Python.h for python version \"${PYTHON_VERSION}\"")
1816         endif()
1817
1818         if(WITH_PYTHON_INSTALL AND WITH_PYTHON_INSTALL_NUMPY)
1819                 # set but invalid
1820                 if(NOT ${PYTHON_NUMPY_PATH} STREQUAL "")
1821                         if(NOT EXISTS "${PYTHON_NUMPY_PATH}/numpy")
1822                                 message(WARNING "PYTHON_NUMPY_PATH is invalid, numpy not found in '${PYTHON_NUMPY_PATH}' "
1823                                                 "WITH_PYTHON_INSTALL_NUMPY option will be ignored when installing python")
1824                                 set(WITH_PYTHON_INSTALL_NUMPY OFF)
1825                         endif()
1826                 # not set, so initialize
1827                 else()
1828                         string(REPLACE "." ";" _PY_VER_SPLIT "${PYTHON_VERSION}")
1829                         list(GET _PY_VER_SPLIT 0 _PY_VER_MAJOR)
1830
1831                         # re-cache
1832                         unset(PYTHON_NUMPY_PATH CACHE)
1833                         find_path(PYTHON_NUMPY_PATH
1834                           NAMES
1835                             numpy
1836                           HINTS
1837                             "${PYTHON_LIBPATH}/python${PYTHON_VERSION}/"
1838                             "${PYTHON_LIBPATH}/python${_PY_VER_MAJOR}/"
1839                           PATH_SUFFIXES
1840                             site-packages
1841                             dist-packages
1842                            NO_DEFAULT_PATH
1843                         )
1844
1845                         if(NOT EXISTS "${PYTHON_NUMPY_PATH}")
1846                                 message(WARNING "'numpy' path could not be found in:\n"
1847                                                 "'${PYTHON_LIBPATH}/python${PYTHON_VERSION}/site-packages/numpy', "
1848                                                 "'${PYTHON_LIBPATH}/python${_PY_VER_MAJOR}/site-packages/numpy', "
1849                                                 "'${PYTHON_LIBPATH}/python${PYTHON_VERSION}/dist-packages/numpy', "
1850                                                 "'${PYTHON_LIBPATH}/python${_PY_VER_MAJOR}/dist-packages/numpy', "
1851                                                 "WITH_PYTHON_INSTALL_NUMPY option will be ignored when installing python")
1852                                 set(WITH_PYTHON_INSTALL_NUMPY OFF)
1853                         else()
1854                                 message(STATUS "numpy found at '${PYTHON_NUMPY_PATH}'")
1855                         endif()
1856
1857                         unset(_PY_VER_SPLIT)
1858                         unset(_PY_VER_MAJOR)
1859                 endif()
1860         endif()
1861 endif()
1862
1863
1864 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${PLATFORM_CFLAGS} ${C_WARNINGS}")
1865 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${PLATFORM_CFLAGS} ${CXX_WARNINGS}")
1866
1867 #-------------------------------------------------------------------------------
1868 # Global Defines
1869
1870 # better not set includes here but this debugging option is off by default.
1871 if(WITH_CXX_GUARDEDALLOC)
1872         include_directories(${CMAKE_SOURCE_DIR}/intern/guardedalloc)
1873         add_definitions(-DWITH_CXX_GUARDEDALLOC)
1874 endif()
1875
1876 if(WITH_ASSERT_ABORT)
1877         add_definitions(-DWITH_ASSERT_ABORT)
1878 endif()
1879
1880 # message(STATUS "Using CFLAGS: ${CMAKE_C_FLAGS}")
1881 # message(STATUS "Using CXXFLAGS: ${CMAKE_CXX_FLAGS}")
1882
1883 #-----------------------------------------------------------------------------
1884 # Libraries
1885
1886 add_subdirectory(source)
1887 add_subdirectory(intern)
1888 add_subdirectory(extern)
1889
1890
1891 #-----------------------------------------------------------------------------
1892 # Blender Application
1893 if(WITH_BLENDER)
1894         add_subdirectory(source/creator)
1895 endif()
1896
1897
1898 #-----------------------------------------------------------------------------
1899 # Blender Player
1900 if(WITH_PLAYER)
1901         add_subdirectory(source/blenderplayer)
1902 endif()
1903
1904 #-----------------------------------------------------------------------------
1905 # CPack for generating packages
1906 include(build_files/cmake/packaging.cmake)
1907
1908
1909 #-----------------------------------------------------------------------------
1910 # Print Final Configuration
1911
1912 if(FIRST_RUN)
1913         set(_config_msg "\n* Blender Configuration *")
1914         macro(info_cfg_option
1915                 _setting)
1916                 set(_msg "   * ${_setting}")
1917                 string(LENGTH "${_msg}" _len)
1918                 while("32" GREATER "${_len}")
1919                         set(_msg "${_msg} ")
1920                          math(EXPR _len "${_len} + 1")
1921                 endwhile()
1922
1923                 set(_config_msg "${_config_msg}\n${_msg}${${_setting}}")
1924         endmacro()
1925
1926         macro(info_cfg_text
1927                 _text)
1928                 set(_config_msg "${_config_msg}\n\n  ${_text}")
1929
1930
1931         endmacro()
1932
1933         info_cfg_text("Build Options:")
1934         info_cfg_option(WITH_GAMEENGINE)
1935         info_cfg_option(WITH_PLAYER)
1936         info_cfg_option(WITH_BULLET)
1937         info_cfg_option(WITH_IK_SOLVER)
1938         info_cfg_option(WITH_IK_ITASC)
1939         info_cfg_option(WITH_OPENCOLLADA)
1940         info_cfg_option(WITH_FFTW3)
1941         info_cfg_option(WITH_INTERNATIONAL)
1942         info_cfg_option(WITH_INPUT_NDOF)
1943         info_cfg_option(WITH_CYCLES)
1944         info_cfg_option(WITH_OPENCOLORIO)
1945
1946         info_cfg_text("Compiler Options:")
1947         info_cfg_option(WITH_BUILDINFO)
1948         info_cfg_option(WITH_OPENMP)
1949         info_cfg_option(WITH_RAYOPTIMIZATION)
1950
1951         info_cfg_text("System Options:")
1952         info_cfg_option(WITH_INSTALL_PORTABLE)
1953         info_cfg_option(WITH_X11_XF86VMODE)
1954         info_cfg_option(WITH_X11_XINPUT)
1955         info_cfg_option(WITH_MEM_JEMALLOC)
1956         info_cfg_option(WITH_SYSTEM_GLEW)
1957         info_cfg_option(WITH_SYSTEM_OPENJPEG)
1958
1959         info_cfg_text("Image Formats:")
1960         info_cfg_option(WITH_IMAGE_CINEON)
1961         info_cfg_option(WITH_IMAGE_DDS)
1962         info_cfg_option(WITH_IMAGE_HDR)
1963         info_cfg_option(WITH_IMAGE_OPENEXR)
1964         info_cfg_option(WITH_IMAGE_OPENJPEG)
1965         info_cfg_option(WITH_IMAGE_REDCODE)
1966         info_cfg_option(WITH_IMAGE_TIFF)
1967
1968         info_cfg_text("Audio:")
1969         info_cfg_option(WITH_OPENAL)
1970         info_cfg_option(WITH_SDL)
1971         info_cfg_option(WITH_JACK)
1972         info_cfg_option(WITH_CODEC_FFMPEG)
1973         info_cfg_option(WITH_CODEC_SNDFILE)
1974
1975         info_cfg_text("Compression:")
1976         info_cfg_option(WITH_LZMA)
1977         info_cfg_option(WITH_LZO)
1978
1979         info_cfg_text("Python:")
1980         info_cfg_option(WITH_PYTHON_INSTALL)
1981         info_cfg_option(WITH_PYTHON_INSTALL_NUMPY)
1982         info_cfg_option(WITH_PYTHON_MODULE)
1983         info_cfg_option(WITH_PYTHON_SAFETY)
1984
1985         info_cfg_text("Modifiers:")
1986         info_cfg_option(WITH_MOD_BOOLEAN)
1987         info_cfg_option(WITH_MOD_REMESH)
1988         info_cfg_option(WITH_MOD_DECIMATE)
1989         info_cfg_option(WITH_MOD_FLUID)
1990         info_cfg_option(WITH_MOD_OCEANSIM)
1991
1992         info_cfg_text("")
1993
1994         message("${_config_msg}")
1995 endif()