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