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