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